aboutsummaryrefslogtreecommitdiffstats
path: root/libical/examples
diff options
context:
space:
mode:
authorJP Rosevear <jpr@src.gnome.org>2000-08-25 03:31:03 +0800
committerJP Rosevear <jpr@src.gnome.org>2000-08-25 03:31:03 +0800
commit8357d7b199e26e4d071b267a314447b22f2ddb3c (patch)
treef6ed518cd2056dacdc9833750137db05bb7fb7cb /libical/examples
parent695baf618d363f760ec81d109c6e6185e510b1e7 (diff)
downloadgsoc2013-evolution-8357d7b199e26e4d071b267a314447b22f2ddb3c.tar
gsoc2013-evolution-8357d7b199e26e4d071b267a314447b22f2ddb3c.tar.gz
gsoc2013-evolution-8357d7b199e26e4d071b267a314447b22f2ddb3c.tar.bz2
gsoc2013-evolution-8357d7b199e26e4d071b267a314447b22f2ddb3c.tar.lz
gsoc2013-evolution-8357d7b199e26e4d071b267a314447b22f2ddb3c.tar.xz
gsoc2013-evolution-8357d7b199e26e4d071b267a314447b22f2ddb3c.tar.zst
gsoc2013-evolution-8357d7b199e26e4d071b267a314447b22f2ddb3c.zip
Initial revision
svn path=/trunk/; revision=5011
Diffstat (limited to 'libical/examples')
-rw-r--r--libical/examples/Makefile.am13
-rw-r--r--libical/examples/Makefile.in301
-rw-r--r--libical/examples/access_components.c325
-rw-r--r--libical/examples/access_properties_and_parameters.c144
-rw-r--r--libical/examples/errors.c70
-rw-r--r--libical/examples/main.c9
-rw-r--r--libical/examples/parse_text.c73
7 files changed, 935 insertions, 0 deletions
diff --git a/libical/examples/Makefile.am b/libical/examples/Makefile.am
new file mode 100644
index 0000000000..f18663723d
--- /dev/null
+++ b/libical/examples/Makefile.am
@@ -0,0 +1,13 @@
+
+noinst_PROGRAMS = doesnothing
+
+LDADD = ../src/libical/libical.a ../src/libicalss/libicalss.a ../src/libicalvcal/libicalvcal.a
+INCLUDES = -I . -I../src/libical -I../src/libicalss -I../src/libicalvcal
+
+doesnothing_SOURCES = \
+ access_components.c \
+ access_properties_and_parameters.c \
+ errors.c \
+ main.c \
+ parse_text.c
+
diff --git a/libical/examples/Makefile.in b/libical/examples/Makefile.in
new file mode 100644
index 0000000000..74aabc1016
--- /dev/null
+++ b/libical/examples/Makefile.in
@@ -0,0 +1,301 @@
+# Makefile.in generated automatically by automake 1.4 from Makefile.am
+
+# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+
+SHELL = @SHELL@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+sbindir = @sbindir@
+libexecdir = @libexecdir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+sharedstatedir = @sharedstatedir@
+localstatedir = @localstatedir@
+libdir = @libdir@
+infodir = @infodir@
+mandir = @mandir@
+includedir = @includedir@
+oldincludedir = /usr/include
+
+DESTDIR =
+
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+
+top_builddir = ..
+
+ACLOCAL = @ACLOCAL@
+AUTOCONF = @AUTOCONF@
+AUTOMAKE = @AUTOMAKE@
+AUTOHEADER = @AUTOHEADER@
+
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+transform = @program_transform_name@
+
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+AR = @AR@
+CC = @CC@
+LEX = @LEX@
+LN_S = @LN_S@
+MAKEINFO = @MAKEINFO@
+PACKAGE = @PACKAGE@
+RANLIB = @RANLIB@
+VERSION = @VERSION@
+YACC = @YACC@
+
+noinst_PROGRAMS = doesnothing
+
+LDADD = ../src/libical/libical.a ../src/libicalss/libicalss.a ../src/libicalvcal/libicalvcal.a
+INCLUDES = -I . -I../src/libical -I../src/libicalss -I../src/libicalvcal
+
+doesnothing_SOURCES = access_components.c access_properties_and_parameters.c errors.c main.c parse_text.c
+
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = ../config.h
+CONFIG_CLEAN_FILES =
+PROGRAMS = $(noinst_PROGRAMS)
+
+
+DEFS = @DEFS@ -I. -I$(srcdir) -I..
+CPPFLAGS = @CPPFLAGS@
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@
+doesnothing_OBJECTS = access_components.o \
+access_properties_and_parameters.o errors.o main.o parse_text.o
+doesnothing_LDADD = $(LDADD)
+doesnothing_DEPENDENCIES = ../src/libical/libical.a \
+../src/libicalss/libicalss.a ../src/libicalvcal/libicalvcal.a
+doesnothing_LDFLAGS =
+CFLAGS = @CFLAGS@
+COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
+DIST_COMMON = Makefile.am Makefile.in
+
+
+DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
+
+TAR = gtar
+GZIP_ENV = --best
+SOURCES = $(doesnothing_SOURCES)
+OBJECTS = $(doesnothing_OBJECTS)
+
+all: all-redirect
+.SUFFIXES:
+.SUFFIXES: .S .c .o .s
+$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
+ cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps examples/Makefile
+
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ cd $(top_builddir) \
+ && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
+
+
+mostlyclean-noinstPROGRAMS:
+
+clean-noinstPROGRAMS:
+ -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS)
+
+distclean-noinstPROGRAMS:
+
+maintainer-clean-noinstPROGRAMS:
+
+.c.o:
+ $(COMPILE) -c $<
+
+.s.o:
+ $(COMPILE) -c $<
+
+.S.o:
+ $(COMPILE) -c $<
+
+mostlyclean-compile:
+ -rm -f *.o core *.core
+
+clean-compile:
+
+distclean-compile:
+ -rm -f *.tab.c
+
+maintainer-clean-compile:
+
+doesnothing: $(doesnothing_OBJECTS) $(doesnothing_DEPENDENCIES)
+ @rm -f doesnothing
+ $(LINK) $(doesnothing_LDFLAGS) $(doesnothing_OBJECTS) $(doesnothing_LDADD) $(LIBS)
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP)
+ list='$(SOURCES) $(HEADERS)'; \
+ unique=`for i in $$list; do echo $$i; done | \
+ awk ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ here=`pwd` && cd $(srcdir) \
+ && mkid -f$$here/ID $$unique $(LISP)
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS)'; \
+ unique=`for i in $$list; do echo $$i; done | \
+ awk ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
+ || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
+
+mostlyclean-tags:
+
+clean-tags:
+
+distclean-tags:
+ -rm -f TAGS ID
+
+maintainer-clean-tags:
+
+distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
+
+subdir = examples
+
+distdir: $(DISTFILES)
+ @for file in $(DISTFILES); do \
+ d=$(srcdir); \
+ if test -d $$d/$$file; then \
+ cp -pr $$d/$$file $(distdir)/$$file; \
+ else \
+ test -f $(distdir)/$$file \
+ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
+ || cp -p $$d/$$file $(distdir)/$$file || :; \
+ fi; \
+ done
+access_components.o: access_components.c ../src/libical/ical.h \
+ ../src/libical/icalversion.h ../src/libical/icalenums.h \
+ ../src/libical/icalvalue.h ../src/libical/icaltypes.h \
+ ../src/libical/icaltime.h ../src/libical/icalparameter.h \
+ ../src/libical/icalproperty.h ../src/libical/icalcomponent.h \
+ ../src/libical/pvl.h ../src/libical/icalparser.h \
+ ../src/libical/icalmemory.h ../src/libical/icalerror.h \
+ ../src/libical/icalrestriction.h ../src/libical/icalrecur.h
+access_properties_and_parameters.o: access_properties_and_parameters.c \
+ ../src/libical/ical.h ../src/libical/icalversion.h \
+ ../src/libical/icalenums.h ../src/libical/icalvalue.h \
+ ../src/libical/icaltypes.h ../src/libical/icaltime.h \
+ ../src/libical/icalparameter.h ../src/libical/icalproperty.h \
+ ../src/libical/icalcomponent.h ../src/libical/pvl.h \
+ ../src/libical/icalparser.h ../src/libical/icalmemory.h \
+ ../src/libical/icalerror.h ../src/libical/icalrestriction.h \
+ ../src/libical/icalrecur.h
+errors.o: errors.c ../src/libical/ical.h ../src/libical/icalversion.h \
+ ../src/libical/icalenums.h ../src/libical/icalvalue.h \
+ ../src/libical/icaltypes.h ../src/libical/icaltime.h \
+ ../src/libical/icalparameter.h ../src/libical/icalproperty.h \
+ ../src/libical/icalcomponent.h ../src/libical/pvl.h \
+ ../src/libical/icalparser.h ../src/libical/icalmemory.h \
+ ../src/libical/icalerror.h ../src/libical/icalrestriction.h \
+ ../src/libical/icalrecur.h
+main.o: main.c
+parse_text.o: parse_text.c ../src/libical/ical.h \
+ ../src/libical/icalversion.h ../src/libical/icalenums.h \
+ ../src/libical/icalvalue.h ../src/libical/icaltypes.h \
+ ../src/libical/icaltime.h ../src/libical/icalparameter.h \
+ ../src/libical/icalproperty.h ../src/libical/icalcomponent.h \
+ ../src/libical/pvl.h ../src/libical/icalparser.h \
+ ../src/libical/icalmemory.h ../src/libical/icalerror.h \
+ ../src/libical/icalrestriction.h ../src/libical/icalrecur.h
+
+info-am:
+info: info-am
+dvi-am:
+dvi: dvi-am
+check-am: all-am
+check: check-am
+installcheck-am:
+installcheck: installcheck-am
+install-exec-am:
+install-exec: install-exec-am
+
+install-data-am:
+install-data: install-data-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+install: install-am
+uninstall-am:
+uninstall: uninstall-am
+all-am: Makefile $(PROGRAMS)
+all-redirect: all-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
+installdirs:
+
+
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -rm -f Makefile $(CONFIG_CLEAN_FILES)
+ -rm -f config.cache config.log stamp-h stamp-h[0-9]*
+
+maintainer-clean-generic:
+mostlyclean-am: mostlyclean-noinstPROGRAMS mostlyclean-compile \
+ mostlyclean-tags mostlyclean-generic
+
+mostlyclean: mostlyclean-am
+
+clean-am: clean-noinstPROGRAMS clean-compile clean-tags clean-generic \
+ mostlyclean-am
+
+clean: clean-am
+
+distclean-am: distclean-noinstPROGRAMS distclean-compile distclean-tags \
+ distclean-generic clean-am
+
+distclean: distclean-am
+
+maintainer-clean-am: maintainer-clean-noinstPROGRAMS \
+ maintainer-clean-compile maintainer-clean-tags \
+ maintainer-clean-generic distclean-am
+ @echo "This command is intended for maintainers to use;"
+ @echo "it deletes files that may require special tools to rebuild."
+
+maintainer-clean: maintainer-clean-am
+
+.PHONY: mostlyclean-noinstPROGRAMS distclean-noinstPROGRAMS \
+clean-noinstPROGRAMS maintainer-clean-noinstPROGRAMS \
+mostlyclean-compile distclean-compile clean-compile \
+maintainer-clean-compile tags mostlyclean-tags distclean-tags \
+clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \
+check-am installcheck-am installcheck install-exec-am install-exec \
+install-data-am install-data install-am install uninstall-am uninstall \
+all-redirect all-am all installdirs mostlyclean-generic \
+distclean-generic clean-generic maintainer-clean-generic clean \
+mostlyclean distclean maintainer-clean
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/libical/examples/access_components.c b/libical/examples/access_components.c
new file mode 100644
index 0000000000..6b655b42f7
--- /dev/null
+++ b/libical/examples/access_components.c
@@ -0,0 +1,325 @@
+/* Access_component.c */
+
+#include "ical.h"
+
+#include <assert.h>
+#include <string.h> /* for strdup */
+#include <stdlib.h> /* for malloc */
+#include <stdio.h> /* for printf */
+#include <time.h> /* for time() */
+#include "icalmemory.h"
+
+/* Creating iCal Components
+
+ There are two ways to create new component in libical. You can
+ build the component from primitive parts, or you can create it
+ from a string.
+
+ There are two variations of the API for building the component from
+ primitive parts. In the first variation, you add each parameter and
+ value to a property, and then add each property to a
+ component. This results in a long series of function calls. This
+ style is show in create_new_component()
+
+ The second variation uses vargs lists to nest many primitive part
+ constructors, resulting in a compact, neatly formated way to create
+ components. This style is shown in create_new_component_with_va_args()
+
+
+
+*/
+
+icalcomponent* create_new_component()
+{
+
+ /* variable definitions */
+ icalcomponent* calendar;
+ icalcomponent* event;
+ struct icaltimetype atime = icaltime_from_timet( time(0),0,0);
+ struct icalperiodtype rtime;
+ icalproperty* property;
+
+ /* Define a time type that will use as data later. */
+ rtime.start = icaltime_from_timet( time(0),0,0);
+ rtime.end = icaltime_from_timet( time(0),0,0);
+ rtime.end.hour++;
+
+ /* Create calendar and add properties */
+
+ calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
+
+ /* Nearly every libical function call has the same general
+ form. The first part of the name defines the 'class' for the
+ function, and the first argument will be a pointer to a struct
+ of that class. So, icalcomponent_ functions will all take
+ icalcomponent* as their first argument. */
+
+ /* The next call creates a new proeprty and immediately adds it to the
+ 'calendar' component. */
+
+ icalcomponent_add_property(
+ calendar,
+ icalproperty_new_version(strdup("2.0"))
+ );
+
+ /* Note the use of strdup() in the previous and next call. All
+ properties constructors for properties with value types of
+ TEXT will take control of the string you pass into them. Since
+ the string '2.0' is a static string, we need to duplicate it in
+ new memory before giving it to the property */
+
+ /* Here is the short version of the memory rules:
+
+ If the routine name has "new" in it:
+ Caller owns the returned memory.
+ If you pass in a string, the routine takes the memory.
+
+ If the routine name has "add" in it:
+ The routine takes control of the component, property,
+ parameter or value memory.
+
+ If the routine returns a string ( "get" and "as_ical_string" )
+ The library owns the returned memory.
+
+ There are more rules, so refer to the documentation for more
+ details.
+
+ */
+
+ icalcomponent_add_property(
+ calendar,
+ icalproperty_new_prodid(strdup("-//RDU Software//NONSGML HandCal//EN"))
+ );
+
+ /* Add an event */
+
+ event = icalcomponent_new(ICAL_VEVENT_COMPONENT);
+
+ icalcomponent_add_property(
+ event,
+ icalproperty_new_dtstamp(atime)
+ );
+
+ /* In the previous call, atime is a struct, and it is passed in by value.
+ This is how all compound types of values are handled. */
+
+ icalcomponent_add_property(
+ event,
+ icalproperty_new_uid(strdup("guid-1.host1.com"))
+ );
+
+ /* add a property that has parameters */
+ property = icalproperty_new_organizer(strdup("mailto:mrbig@host.com"));
+
+ icalproperty_add_parameter(
+ property,
+ icalparameter_new_role(ICAL_ROLE_CHAIR)
+ );
+
+ icalcomponent_add_property(event,property);
+
+ /* In this style of component creation, you need to use an extra
+ call to add parameters to properties, but the form of this
+ operation is the same as adding a property to a component */
+
+ /* add another property that has parameters */
+ property = icalproperty_new_attendee(strdup("mailto:employee-A@host.com"));
+
+ icalproperty_add_parameter(
+ property,
+ icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT)
+ );
+
+ icalproperty_add_parameter(
+ property,
+ icalparameter_new_rsvp(1)
+ );
+
+ icalproperty_add_parameter(
+ property,
+ icalparameter_new_cutype(ICAL_CUTYPE_GROUP)
+ );
+
+ icalcomponent_add_property(event,property);
+
+
+ /* more properties */
+
+ icalcomponent_add_property(
+ event,
+ icalproperty_new_description(strdup("Project XYZ Review Meeting"))
+ );
+
+ icalcomponent_add_property(
+ event,
+ icalproperty_new_categories(strdup("MEETING"))
+ );
+
+ icalcomponent_add_property(
+ event,
+ icalproperty_new_class(strdup("PUBLIC"))
+ );
+
+ icalcomponent_add_property(
+ event,
+ icalproperty_new_created(atime)
+ );
+
+ icalcomponent_add_property(
+ event,
+ icalproperty_new_summary(strdup("XYZ Project Review"))
+ );
+
+ property = icalproperty_new_dtstart(atime);
+
+ icalproperty_add_parameter(
+ property,
+ icalparameter_new_tzid(strdup("US-Eastern"))
+ );
+
+ icalcomponent_add_property(event,property);
+
+
+ property = icalproperty_new_dtend(atime);
+
+ icalproperty_add_parameter(
+ property,
+ icalparameter_new_tzid(strdup("US-Eastern"))
+ );
+
+ icalcomponent_add_property(event,property);
+
+ icalcomponent_add_property(
+ event,
+ icalproperty_new_location(strdup("1CP Conference Room 4350"))
+ );
+
+ icalcomponent_add_component(calendar,event);
+
+ return calendar;
+}
+
+
+/* Now, create the same component as in the previous routine, but use
+the constructor style. */
+
+icalcomponent* create_new_component_with_va_args()
+{
+
+ /* This is a similar set up to the last routine */
+ icalcomponent* calendar;
+ struct icaltimetype atime = icaltime_from_timet( time(0),0,0);
+ struct icalperiodtype rtime;
+
+ rtime.start = icaltime_from_timet( time(0),0,0);
+ rtime.end = icaltime_from_timet( time(0),0,0);
+ rtime.end.hour++;
+
+ /* Some of these routines are the same as those in the previous
+ routine, but we've also added several 'vanew' routines. These
+ 'vanew' routines take a list of properties, parameters or
+ values and add each of them to the parent property or
+ component. */
+
+ calendar =
+ icalcomponent_vanew(
+ ICAL_VCALENDAR_COMPONENT,
+ icalproperty_new_version(strdup("2.0")),
+ icalproperty_new_prodid(strdup("-//RDU Software//NONSGML HandCal//EN")),
+ icalcomponent_vanew(
+ ICAL_VEVENT_COMPONENT,
+ icalproperty_new_dtstamp(atime),
+ icalproperty_new_uid(strdup("guid-1.host1.com")),
+ icalproperty_vanew_organizer(
+ strdup("mailto:mrbig@host.com"),
+ icalparameter_new_role(ICAL_ROLE_CHAIR),
+ 0
+ ),
+ icalproperty_vanew_attendee(
+ strdup("mailto:employee-A@host.com"),
+ icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT),
+ icalparameter_new_rsvp(1),
+ icalparameter_new_cutype(ICAL_CUTYPE_GROUP),
+ 0
+ ),
+ icalproperty_new_description(strdup("Project XYZ Review Meeting")),
+
+ /* Again, note the use of strdup to give libical
+ ownership of a static string. */
+
+ icalproperty_new_categories(strdup("MEETING")),
+ icalproperty_new_class(strdup("PUBLIC")),
+ icalproperty_new_created(atime),
+ icalproperty_new_summary(strdup("XYZ Project Review")),
+ icalproperty_vanew_dtstart(
+ atime,
+ icalparameter_new_tzid(strdup("US-Eastern")),
+ 0
+ ),
+ icalproperty_vanew_dtend(
+ atime,
+ icalparameter_new_tzid(strdup("US-Eastern")),
+ 0
+ ),
+ icalproperty_new_location(strdup("1CP Conference Room 4350")),
+ 0
+ ),
+ 0
+ );
+
+
+ /* Note that properties with no parameters can use the regular
+ 'new' constructor, while those with parameters use the 'vanew'
+ constructor. And, be sure that the last argument in the 'vanew'
+ call is a zero. Without, your program will probably crash. */
+
+ return calendar;
+}
+
+
+void find_sub_components(icalcomponent* comp)
+{
+ icalcomponent *c;
+
+ /* The second parameter to icalcomponent_get_first_component
+ indicates the type of component to search for. This will
+ iterate through all sub-components */
+ for(c = icalcomponent_get_first_component(comp,ICAL_ANY_COMPONENT);
+ c != 0;
+ c = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)){
+
+ do_something(c);
+ }
+
+ /* This will iterate only though VEVENT sub-components */
+
+ for(c = icalcomponent_get_first_component(comp,ICAL_VEVENT_COMPONENT);
+ c != 0;
+ c = icalcomponent_get_next_component(comp,ICAL_VEVENT_COMPONENT)){
+
+ do_something(c);
+ }
+
+}
+
+/* Ical components only have one internal iterator, so removing the
+ object that the iterator points to can cause problems. Here is the
+ right way to remove components */
+
+void remove_vevent_sub_components(icalcomponent* comp){
+
+ icalcomponent *c, *next;
+
+ for( c = icalcomponent_get_first_component(comp,ICAL_VEVENT_COMPONENT);
+ c != 0;
+ c = next)
+ {
+ next = icalcomponent_get_next_component(comp,ICAL_VEVENT_COMPONENT);
+
+ icalcomponent_remove_component(comp,c);
+
+ do_something(c);
+ }
+
+}
+
diff --git a/libical/examples/access_properties_and_parameters.c b/libical/examples/access_properties_and_parameters.c
new file mode 100644
index 0000000000..e19656f57f
--- /dev/null
+++ b/libical/examples/access_properties_and_parameters.c
@@ -0,0 +1,144 @@
+/* access_properties_and_parameters.c */
+
+#include "ical.h"
+
+/* Get a particular parameter out of a component. This routine will
+ return a list of strings of all attendees who are required. Note
+ that this routine assumes that the component that we pass in is a
+ VEVENT. */
+
+void get_required_attendees(icalcomponent* event)
+{
+ icalproperty* p;
+ icalparameter* parameter;
+ int c=0;
+
+ assert(event != 0);
+ assert(icalcomponent_isa(event) == ICAL_VEVENT_COMPONENT);
+
+ /* This loop iterates over all of the ATTENDEE properties in the
+ event */
+
+ /* The iteration routines save their state in the event
+ struct, so the are not thread safe unless you lock the whole
+ component. */
+
+ for(
+ p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY);
+ p != 0;
+ p = icalcomponent_get_next_property(event,ICAL_ATTENDEE_PROPERTY)
+ ) {
+
+ /* Get the first ROLE parameter in the property. There should
+ only be one, so we won't bother to iterate over them. But,
+ you can iterate over parameters just like with properties */
+
+ parameter = icalproperty_get_first_parameter(p,ICAL_ROLE_PARAMETER);
+
+ /* If the parameter indicates the participant is required, get
+ the attendees name and stick a copy of it into the output
+ array */
+
+ if ( icalparameter_get_role(parameter) == ICAL_ROLE_REQPARTICIPANT)
+ {
+ /* Remember, the caller does not own this string, so you
+ should strdup it if you want to change it. */
+ char *attendee = icalproperty_get_attendee(p);
+ }
+ }
+
+}
+
+/* Here is a similar example. If an attendee has a PARTSTAT of
+ NEEDSACTION or has no PARTSTAT parameter, change it to
+ TENTATIVE. */
+
+void update_attendees(icalcomponent* event)
+{
+ icalproperty* p;
+ icalparameter* parameter;
+
+ assert(event != 0);
+ assert(icalcomponent_isa(event) == ICAL_VEVENT_COMPONENT);
+
+ for(
+ p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY);
+ p != 0;
+ p = icalcomponent_get_next_property(event,ICAL_ATTENDEE_PROPERTY)
+ ) {
+
+ parameter = icalproperty_get_first_parameter(p,ICAL_PARTSTAT_PARAMETER);
+
+ if (parameter == 0) {
+
+ /* There was no PARTSTAT parameter, so add one. */
+ icalproperty_add_parameter(
+ p,
+ icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE)
+ );
+
+ } else if (icalparameter_get_partstat(parameter) == ICAL_PARTSTAT_NEEDSACTION) {
+ /* Remove the NEEDSACTION parameter and replace it with
+ TENTATIVE */
+
+ icalproperty_remove_parameter(p,ICAL_PARTSTAT_PARAMETER);
+
+ /* Don't forget to free it */
+ icalparameter_free(parameter);
+
+ /* Add a new one */
+ icalproperty_add_parameter(
+ p,
+ icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE)
+ );
+ }
+
+ }
+}
+
+/* Here are some examples of manipulating properties */
+
+void test_properties()
+{
+ icalproperty *prop;
+ icalparameter *param;
+ icalvalue *value;
+
+ icalproperty *clone;
+
+ /* Create a new property */
+ prop = icalproperty_vanew_comment(
+ strdup("Another Comment"),
+ icalparameter_new_cn("A Common Name 1"),
+ icalparameter_new_cn("A Common Name 2"),
+ icalparameter_new_cn("A Common Name 3"),
+ icalparameter_new_cn("A Common Name 4"),
+ 0);
+
+ /* Iterate through all of the parameters in the property */
+ for(param = icalproperty_get_first_parameter(prop,ICAL_ANY_PROPERTY);
+ param != 0;
+ param = icalproperty_get_next_parameter(prop,ICAL_ANY_PROPERTY)) {
+
+ printf("Prop parameter: %s\n",icalparameter_get_cn(param));
+ }
+
+ /* Get a string representation of the property's value */
+ printf("Prop value: %s\n",icalproperty_get_comment(prop));
+
+ /* Spit out the property in its RFC 2445 representation */
+ printf("As iCAL string:\n %s\n",icalproperty_as_ical_string(prop));
+
+ /* Make a copy of the property. Caller owns the memory */
+ clone = icalproperty_new_clone(prop);
+
+ /* Get a reference to the value within the clone property */
+ value = icalproperty_get_value(clone);
+
+ printf("Value: %s",icalvalue_as_ical_string(value));
+
+ /* Free the original and the clone */
+ icalproperty_free(clone);
+ icalproperty_free(prop);
+
+}
diff --git a/libical/examples/errors.c b/libical/examples/errors.c
new file mode 100644
index 0000000000..071a2de816
--- /dev/null
+++ b/libical/examples/errors.c
@@ -0,0 +1,70 @@
+/* errors.c */
+
+#include "ical.h"
+#include <stdio.h>
+
+void program_errors()
+{
+ /*Most routines will set icalerrno on errors. This is an
+ enumeration defined in icalerror.h */
+
+ icalcomponent *c;
+
+ icalerror_clear_errno();
+
+ c = icalcomponent_new(ICAL_VEVENT_COMPONENT);
+
+ if (icalerrno != ICAL_NO_ERROR){
+
+ fprintf(stderr,"Horrible libical error: %s\n",
+ icalerror_strerror(icalerrno));
+
+ }
+
+}
+
+void component_errors(icalcomponent *comp)
+{
+ int errors;
+ icalproperty *p;
+
+ /* presume that we just got this component from the parser */
+
+ errors = icalcomponent_count_errors(comp);
+
+ printf("This component has %d parsing errors\n");
+
+ /* Print out all of the parsing errors. This is not strictly
+ correct, because it does not descend into any sub-components,
+ as icalcomponent_count_errors() does. */
+
+ for(p = icalcomponent_get_first_property(comp,ICAL_XLICERROR_PROPERTY);
+ p != 0;
+ p = icalcomponent_get_next_property(comp,ICAL_XLICERROR_PROPERTY))
+ {
+
+ printf("-- The error is %s:\n",icalproperty_get_xlicerror(p));
+ }
+
+
+
+ /* Check the component for iTIP compilance, and add more
+ X-LIC-ERROR properties if it is non-compilant. */
+ icalrestriction_check(comp);
+
+
+ /* Count the new errors. */
+ if(errors != icalcomponent_count_errors(comp)){
+ printf(" -- The component also has iTIP restriction errors \n");
+ }
+
+ /* Since there are iTIP restriction errors, it may be impossible
+ to process this component as an iTIP request. In this case, the
+ X-LIC-ERROR proeprties should be expressed as REQUEST-STATUS
+ properties in the reply. This following routine makes this
+ conversion */
+
+
+ icalcomponent_convert_errors(comp);
+
+}
diff --git a/libical/examples/main.c b/libical/examples/main.c
new file mode 100644
index 0000000000..88d6621365
--- /dev/null
+++ b/libical/examples/main.c
@@ -0,0 +1,9 @@
+/* This is just to make the code in the example directory link properly. */
+
+main()
+{
+}
+
+
+int do_something(){
+}
diff --git a/libical/examples/parse_text.c b/libical/examples/parse_text.c
new file mode 100644
index 0000000000..2761e6f951
--- /dev/null
+++ b/libical/examples/parse_text.c
@@ -0,0 +1,73 @@
+/* parse_text.c
+
+ */
+#include <stdio.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include "ical.h"
+
+#include <stdlib.h>
+
+/* The icalparser_get_line routine will create a single *content* line
+out of one or more input lines. The content line is all of the
+properties and values for a single property, and it can span several
+input lines. So, icalparser_get_line will need to be able to get more
+data on its own. Read_string is a routine that does this. You can
+write your own version of read stream to get data from other types of
+files, sockets, etc. */
+
+char* read_stream(char *s, size_t size, void *d)
+{
+ char *c = fgets(s,size, (FILE*)d);
+
+ return c;
+
+}
+
+int parse_text(int argc, char* argv[])
+{
+
+ int lineno = 0;
+ char* line;
+ FILE* stream;
+ icalcomponent *c;
+
+ /* Create a new parser object */
+ icalparser *parser = icalparser_new();
+
+ stream = fopen(argv[1],"r");
+
+ assert(stream != 0);
+
+ /* Tell the parser what input routie it should use. */
+ icalparser_set_gen_data(parser,stream);
+
+ do{
+
+ /* Get a single content line by making one or more calls to
+ read_stream()*/
+ line = icalparser_get_line(parser,read_stream);
+
+ /* Now, add that line into the parser object. If that line
+ completes a component, c will be non-zero */
+ c = icalparser_add_line(parser,line);
+
+
+ if (c != 0){
+ printf("%s",icalcomponent_as_ical_string(c));
+
+ /* Tell the parser that the caller will take ownership of
+ this component */
+ icalparser_claim(parser);
+
+ printf("\n---------------\n");
+
+ icalcomponent_free(c);
+ }
+
+ } while ( line != 0);
+
+
+ icalparser_free(parser);
+}