diff options
author | Olliver Schinagl <oliver@schinagl.nl> | 2016-03-11 08:24:07 (GMT) |
---|---|---|
committer | Olliver Schinagl <oliver@schinagl.nl> | 2016-03-18 20:46:27 (GMT) |
commit | 6c119ae1e935646f7366f3f6d438a125dcbe1f98 (patch) | |
tree | 1fbb225e70bc4607a42e53aa9d382133a286dcea | |
parent | 24c187b0ba2939a80755a98fec8a625fc7d453f9 (diff) | |
download | engagement-6c119ae1e935646f7366f3f6d438a125dcbe1f98.zip engagement-6c119ae1e935646f7366f3f6d438a125dcbe1f98.tar.gz engagement-6c119ae1e935646f7366f3f6d438a125dcbe1f98.tar.bz2 |
Add preliminary ical experiments
This patch adds preliminary 'support' for iCalendar. Preliminary in the
sense that it opens a known file, and prints some output using printf.
This is just some experiments in parsing ics files.
Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/plugins/Makefile.am | 20 | ||||
-rw-r--r-- | src/plugins/calendar_ical.c | 117 |
5 files changed, 140 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 6b67627..ebbe6c0 100644 --- a/configure.ac +++ b/configure.ac @@ -116,6 +116,7 @@ src/Makefile src/bin/Makefile src/include/Makefile src/lib/Makefile +src/plugins/Makefile src/tests/Makefile doc/engagement.1 ]) diff --git a/po/POTFILES.in b/po/POTFILES.in index 7269d3e..9070164 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,3 +1,4 @@ src/bin/engagement.c src/bin/engagement_private.h src/lib/plugin.c +src/plugins/calendar_ical.c diff --git a/src/Makefile.am b/src/Makefile.am index b52407c..9b10f93 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ MAINTAINERCLEANFILES = Makefile.in -SUBDIRS = include lib bin tests +SUBDIRS = include lib plugins bin tests diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am new file mode 100644 index 0000000..b5e5002 --- /dev/null +++ b/src/plugins/Makefile.am @@ -0,0 +1,20 @@ +MAINTAINERCLEANFILES = Makefile.in + +AM_CPPFLAGS = \ +-I$(top_srcdir)/src/plugins \ +-I$(top_builddir)/src/plugins \ +-I$(top_srcdir)/src/include \ +-DPACKAGE_LIB_DIR=\"$(libdir)\" \ +-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" + +lib_LTLIBRARIES = libcalendar_example.la \ + libcalendar_ical.la libcalendar_caldav.la + +libcalendar_example_la_SOURCES = calendar_example.c +libcalendar_example_la_LIBADD = + +libcalendar_ical_la_SOURCES = calendar_ical.c +libcalendar_ical_la_LIBADD = @LIBICAL@ + +libcalendar_caldav_la_SOURCES = calendar_caldav.c +libcalendar_caldav_la_LIBADD = -lical # @LIBICAL@ diff --git a/src/plugins/calendar_ical.c b/src/plugins/calendar_ical.c new file mode 100644 index 0000000..58abb36 --- /dev/null +++ b/src/plugins/calendar_ical.c @@ -0,0 +1,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 |