1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*
* (c) Copyright 2016 Olliver Schinagl
* Author: Olliver Schinagl <oliver@schinagl.nl>
*
* SPDX-License-Identifier: AGPL-3.0+
*/
#include <engagement/plugin.h>
#include <libical/ical.h>
#include <libintl.h>
#include <stdio.h>
#include "gettext.h"
#ifdef __cplusplus
extern "C" {
#endif
char *line_gen_func(char *str, size_t size, void *data)
{
return fgets(str, (int)size, (FILE *)data);
}
bool ical_load(void)
{
icalparser *parser;
icalcomponent *comp, *cal, *event;
FILE *stream;
printf("Plugin loaded\n");
stream = fopen("test-data/large.ics", "r");
if (stream == NULL) {
fprintf(stderr, "Cannot open file for reading");
return 1;
}
parser = icalparser_new();
icalparser_set_gen_data(parser, stream);
comp = icalparser_parse(parser, line_gen_func);
for (event = icalcomponent_get_first_real_component(comp);
event != NULL;
event = icalcomponent_get_next_component(comp, ICAL_ANY_COMPONENT)) {
icalproperty *prop;
printf("\n---Event---\n%s", icalcomponent_as_ical_string(event));
for (prop = icalcomponent_get_first_property(event, ICAL_ANY_PROPERTY);
prop != NULL;
prop = icalcomponent_get_next_property(event, ICAL_ANY_PROPERTY)) {
icalparameter *param;
printf("prop: %s %d (%s) %s\n", icalproperty_as_ical_string(prop), icalproperty_count_parameters(prop), icalproperty_get_property_name(prop), icalvalue_as_ical_string(icalproperty_get_value(prop)));
for (param = icalproperty_get_first_parameter(prop, ICAL_ANY_PARAMETER);
param != NULL;
param = icalproperty_get_next_parameter(prop, ICAL_ANY_PARAMETER)) {
printf("param: %s\n", icalparameter_as_ical_string(param));
}
if (icalerrno != ICAL_NO_ERROR)
fprintf(stderr, "Error with parameter %s\n", icalerror_strerror(icalerrno));
}
if (icalerrno != ICAL_NO_ERROR)
fprintf(stderr, "Error with property %s\n", icalerror_strerror(icalerrno));
}
if (icalerrno != ICAL_NO_ERROR)
fprintf(stderr, "Error with component. %s\n", icalerror_strerror(icalerrno));
icalparser_free(parser);
fclose(stream);
return true;
}
bool ical_unload(void)
{
printf("Plugin unloaded\n");
return true;
}
struct plugin calendar_plugin = {
.magic = PLUGIN_MAGIC,
.type = PLUGIN_TYPE_CALENDAR,
.id = "connector-ical",
.version = {
.major = PLUGIN_VERSION_MAJOR,
.minor = PLUGIN_VERSION_MINOR,
.micro = 1,
},
.info = {
.name = N_("Caldav connector plugin"),
.summary = N_("Caldav connector plugin summary"),
.description = N_("Caldav connector plugin description"),
.help = N_("Caldav connector plugin help text"),
.author = N_("Olliver Schinagl"),
.email = "oliver@schinagl.nl",
.url = "http://git.schinagl.nl/engagement.git",
},
.load = &ical_load,
.unload = &ical_unload,
};
void __attribute__((constructor)) ical_create(void)
{
printf("Plugin created\n");
return;
}
void __attribute__((destructor)) ical_destroy(void)
{
printf("Plugin destroyed\n");
return;
}
PLUGIN_INIT(ical_plugin);
#ifdef __cplusplus
}
#endif
|