diff options
author | JP Rosevear <jpr@src.gnome.org> | 2000-08-25 04:12:06 +0800 |
---|---|---|
committer | JP Rosevear <jpr@src.gnome.org> | 2000-08-25 04:12:06 +0800 |
commit | 73a6d43a66a828b09e2c1b5a483405e6e0b5fa6a (patch) | |
tree | 5be6b34646e168f530ae5cf818a19d5b4be1bd73 /libical/src/test | |
parent | 37471a4d5261636aea1a330ed2c42db9e665a9f9 (diff) | |
download | gsoc2013-evolution-73a6d43a66a828b09e2c1b5a483405e6e0b5fa6a.tar.gz gsoc2013-evolution-73a6d43a66a828b09e2c1b5a483405e6e0b5fa6a.tar.zst gsoc2013-evolution-73a6d43a66a828b09e2c1b5a483405e6e0b5fa6a.zip |
Fix minor conflicts.
svn path=/trunk/; revision=5017
Diffstat (limited to 'libical/src/test')
-rw-r--r-- | libical/src/test/Makefile.am | 12 | ||||
-rw-r--r-- | libical/src/test/Makefile.in | 385 | ||||
-rw-r--r-- | libical/src/test/copycluster.c | 20 | ||||
-rw-r--r-- | libical/src/test/findobj.c | 5 | ||||
-rw-r--r-- | libical/src/test/icaltestparser.c | 5 | ||||
-rw-r--r-- | libical/src/test/regression.c | 324 | ||||
-rw-r--r-- | libical/src/test/storage.c | 117 | ||||
-rw-r--r-- | libical/src/test/stow.c | 708 |
8 files changed, 875 insertions, 701 deletions
diff --git a/libical/src/test/Makefile.am b/libical/src/test/Makefile.am index 81ffff8c39..bd76fca669 100644 --- a/libical/src/test/Makefile.am +++ b/libical/src/test/Makefile.am @@ -1,7 +1,7 @@ -noinst_PROGRAMS = usecases copycluster regression parser findobj storage stow +noinst_PROGRAMS = copycluster regression parser findobj storage stow testvcal recur testmime -LDADD = ../libical/libical.a ../libicalss/libicalss.a +LDADD = ../libical/libical.a ../libicalss/libicalss.a ../libicalvcal/libicalvcal.a INCLUDES = \ -I . \ -I $(srcdir) \ @@ -9,11 +9,15 @@ INCLUDES = \ -I $(srcdir)/../libical \ -I../libicalss \ -I $(srcdir)/../libicalss + -I../libicalvcal \ + -I $(srcdir)/../libicalvcal findobj_SOURCES = findobj.c -usecases_SOURCES = usecases.c copycluster_SOURCES = copycluster.c regression_SOURCES = regression.c parser_SOURCES = icaltestparser.c storage_SOURCES = storage.c -stow_SOURCES = stow.c
\ No newline at end of file +stow_SOURCES = stow.c +testvcal_SOURCES =testvcal.c +recur_SOURCES = recur.c +test_mime = testmime.c
\ No newline at end of file diff --git a/libical/src/test/Makefile.in b/libical/src/test/Makefile.in deleted file mode 100644 index 8a7cf257c3..0000000000 --- a/libical/src/test/Makefile.in +++ /dev/null @@ -1,385 +0,0 @@ -# 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 = : -host_alias = @host_alias@ -host_triplet = @host@ -AR = @AR@ -AS = @AS@ -CC = @CC@ -DLLTOOL = @DLLTOOL@ -LEX = @LEX@ -LIBTOOL = @LIBTOOL@ -LN_S = @LN_S@ -MAKEINFO = @MAKEINFO@ -OBJDUMP = @OBJDUMP@ -PACKAGE = @PACKAGE@ -RANLIB = @RANLIB@ -VERSION = @VERSION@ -YACC = @YACC@ - -noinst_PROGRAMS = usecases copycluster regression parser findobj storage stow - -LDADD = ../libical/libical.a ../libicalss/libicalss.a -INCLUDES = -I . -I $(srcdir) -I../libical -I $(srcdir)/../libical -I../libicalss -I $(srcdir)/../libicalss - - -findobj_SOURCES = findobj.c -usecases_SOURCES = usecases.c -copycluster_SOURCES = copycluster.c -regression_SOURCES = regression.c -parser_SOURCES = icaltestparser.c -storage_SOURCES = storage.c -stow_SOURCES = stow.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@ -usecases_OBJECTS = usecases.o -usecases_LDADD = $(LDADD) -usecases_DEPENDENCIES = ../libical/libical.a ../libicalss/libicalss.a -usecases_LDFLAGS = -copycluster_OBJECTS = copycluster.o -copycluster_LDADD = $(LDADD) -copycluster_DEPENDENCIES = ../libical/libical.a \ -../libicalss/libicalss.a -copycluster_LDFLAGS = -regression_OBJECTS = regression.o -regression_LDADD = $(LDADD) -regression_DEPENDENCIES = ../libical/libical.a ../libicalss/libicalss.a -regression_LDFLAGS = -parser_OBJECTS = icaltestparser.o -parser_LDADD = $(LDADD) -parser_DEPENDENCIES = ../libical/libical.a ../libicalss/libicalss.a -parser_LDFLAGS = -findobj_OBJECTS = findobj.o -findobj_LDADD = $(LDADD) -findobj_DEPENDENCIES = ../libical/libical.a ../libicalss/libicalss.a -findobj_LDFLAGS = -storage_OBJECTS = storage.o -storage_LDADD = $(LDADD) -storage_DEPENDENCIES = ../libical/libical.a ../libicalss/libicalss.a -storage_LDFLAGS = -stow_OBJECTS = stow.o -stow_LDADD = $(LDADD) -stow_DEPENDENCIES = ../libical/libical.a ../libicalss/libicalss.a -stow_LDFLAGS = -CFLAGS = @CFLAGS@ -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(LIBTOOL) --mode=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 -DEP_FILES = .deps/copycluster.P .deps/findobj.P .deps/icaltestparser.P \ -.deps/regression.P .deps/storage.P .deps/stow.P .deps/usecases.P -SOURCES = $(usecases_SOURCES) $(copycluster_SOURCES) $(regression_SOURCES) $(parser_SOURCES) $(findobj_SOURCES) $(storage_SOURCES) $(stow_SOURCES) -OBJECTS = $(usecases_OBJECTS) $(copycluster_OBJECTS) $(regression_OBJECTS) $(parser_OBJECTS) $(findobj_OBJECTS) $(storage_OBJECTS) $(stow_OBJECTS) - -all: all-redirect -.SUFFIXES: -.SUFFIXES: .S .c .lo .o .s -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOMAKE) --gnu src/test/Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) - 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: - -.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: - -.s.lo: - $(LIBTOOL) --mode=compile $(COMPILE) -c $< - -.S.lo: - $(LIBTOOL) --mode=compile $(COMPILE) -c $< - -mostlyclean-libtool: - -rm -f *.lo - -clean-libtool: - -rm -rf .libs _libs - -distclean-libtool: - -maintainer-clean-libtool: - -usecases: $(usecases_OBJECTS) $(usecases_DEPENDENCIES) - @rm -f usecases - $(LINK) $(usecases_LDFLAGS) $(usecases_OBJECTS) $(usecases_LDADD) $(LIBS) - -copycluster: $(copycluster_OBJECTS) $(copycluster_DEPENDENCIES) - @rm -f copycluster - $(LINK) $(copycluster_LDFLAGS) $(copycluster_OBJECTS) $(copycluster_LDADD) $(LIBS) - -regression: $(regression_OBJECTS) $(regression_DEPENDENCIES) - @rm -f regression - $(LINK) $(regression_LDFLAGS) $(regression_OBJECTS) $(regression_LDADD) $(LIBS) - -parser: $(parser_OBJECTS) $(parser_DEPENDENCIES) - @rm -f parser - $(LINK) $(parser_LDFLAGS) $(parser_OBJECTS) $(parser_LDADD) $(LIBS) - -findobj: $(findobj_OBJECTS) $(findobj_DEPENDENCIES) - @rm -f findobj - $(LINK) $(findobj_LDFLAGS) $(findobj_OBJECTS) $(findobj_LDADD) $(LIBS) - -storage: $(storage_OBJECTS) $(storage_DEPENDENCIES) - @rm -f storage - $(LINK) $(storage_LDFLAGS) $(storage_OBJECTS) $(storage_LDADD) $(LIBS) - -stow: $(stow_OBJECTS) $(stow_DEPENDENCIES) - @rm -f stow - $(LINK) $(stow_LDFLAGS) $(stow_OBJECTS) $(stow_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 = src/test - -distdir: $(DISTFILES) - here=`cd $(top_builddir) && pwd`; \ - top_distdir=`cd $(top_distdir) && pwd`; \ - distdir=`cd $(distdir) && pwd`; \ - cd $(top_srcdir) \ - && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu src/test/Makefile - @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 - -DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :) - --include $(DEP_FILES) - -mostlyclean-depend: - -clean-depend: - -distclean-depend: - -rm -rf .deps - -maintainer-clean-depend: - -%.o: %.c - @echo '$(COMPILE) -c $<'; \ - $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $< - @-cp .deps/$(*F).pp .deps/$(*F).P; \ - tr ' ' '\012' < .deps/$(*F).pp \ - | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ - >> .deps/$(*F).P; \ - rm .deps/$(*F).pp - -%.lo: %.c - @echo '$(LTCOMPILE) -c $<'; \ - $(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $< - @-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \ - < .deps/$(*F).pp > .deps/$(*F).P; \ - tr ' ' '\012' < .deps/$(*F).pp \ - | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ - >> .deps/$(*F).P; \ - rm -f .deps/$(*F).pp -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-libtool mostlyclean-tags mostlyclean-depend \ - mostlyclean-generic - -mostlyclean: mostlyclean-am - -clean-am: clean-noinstPROGRAMS clean-compile clean-libtool clean-tags \ - clean-depend clean-generic mostlyclean-am - -clean: clean-am - -distclean-am: distclean-noinstPROGRAMS distclean-compile \ - distclean-libtool distclean-tags distclean-depend \ - distclean-generic clean-am - -rm -f libtool - -distclean: distclean-am - -maintainer-clean-am: maintainer-clean-noinstPROGRAMS \ - maintainer-clean-compile maintainer-clean-libtool \ - maintainer-clean-tags maintainer-clean-depend \ - 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 mostlyclean-libtool distclean-libtool \ -clean-libtool maintainer-clean-libtool tags mostlyclean-tags \ -distclean-tags clean-tags maintainer-clean-tags distdir \ -mostlyclean-depend distclean-depend clean-depend \ -maintainer-clean-depend 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/src/test/copycluster.c b/libical/src/test/copycluster.c index b059130c13..11bd94c62d 100644 --- a/libical/src/test/copycluster.c +++ b/libical/src/test/copycluster.c @@ -27,7 +27,7 @@ #include <stdio.h> /* for printf */ #include "ical.h" -#include "icalcluster.h" +#include "icalfileset.h" #include <errno.h> #include <string.h> /* For strerror */ #include "icalrestriction.h" @@ -41,7 +41,7 @@ void usage(char* arg0) { int main(int c, char *argv[]){ - icalcluster *clusterin, *clusterout; + icalfileset *clusterin, *clusterout; icalcomponent *itr; int count=0; int tostdout = 0; @@ -55,7 +55,7 @@ int main(int c, char *argv[]){ tostdout = 1; } - clusterin = icalcluster_new(argv[1]); + clusterin = icalfileset_new(argv[1]); if (clusterin == 0){ printf("Could not open input cluster \"%s\"",argv[1]); @@ -64,7 +64,7 @@ int main(int c, char *argv[]){ } if (!tostdout){ - clusterout = icalcluster_new(argv[2]); + clusterout = icalfileset_new(argv[2]); if (clusterout == 0){ printf("Could not open output cluster \"%s\"\n",argv[2]); exit(1); @@ -72,10 +72,10 @@ int main(int c, char *argv[]){ } - for (itr = icalcluster_get_first_component(clusterin, + for (itr = icalfileset_get_first_component(clusterin, ICAL_ANY_COMPONENT); itr != 0; - itr = icalcluster_get_next_component(clusterin, + itr = icalfileset_get_next_component(clusterin, ICAL_ANY_COMPONENT)){ icalrestriction_check(itr); @@ -87,7 +87,7 @@ int main(int c, char *argv[]){ printf("--------------\n%s\n",icalcomponent_as_ical_string(itr)); } else { - icalcluster_add_component(clusterout, + icalfileset_add_component(clusterout, icalcomponent_new_clone(itr)); } @@ -101,11 +101,11 @@ int main(int c, char *argv[]){ printf("Transfered %d components\n",count); - icalcluster_free(clusterin); + icalfileset_free(clusterin); if (!tostdout){ - icalcluster_mark(clusterout); - icalcluster_free(clusterout); + icalfileset_mark(clusterout); + icalfileset_free(clusterout); } return 0; diff --git a/libical/src/test/findobj.c b/libical/src/test/findobj.c index e7ec59169a..c31101c33d 100644 --- a/libical/src/test/findobj.c +++ b/libical/src/test/findobj.c @@ -28,6 +28,7 @@ #include <stdio.h> /* for printf */ #include "ical.h" #include "icalcalendar.h" +#include "icaldirset.h" #include <errno.h> #include <string.h> /* For strerror */ #include "icalrestriction.h" @@ -41,7 +42,7 @@ void usage(char* arg0) { int main(int c, char *argv[]){ icalcalendar *cal; - icalstore *booked; + icaldirset *booked; icalcomponent *itr; if(c < 2 || c > 3){ @@ -59,7 +60,7 @@ int main(int c, char *argv[]){ booked = icalcalendar_get_booked(cal); - itr = icalstore_fetch(booked,argv[2]); + itr = icaldirset_fetch(booked,argv[2]); if(itr != 0){ diff --git a/libical/src/test/icaltestparser.c b/libical/src/test/icaltestparser.c index 98dbcff94f..71f91b641f 100644 --- a/libical/src/test/icaltestparser.c +++ b/libical/src/test/icaltestparser.c @@ -91,7 +91,6 @@ char* read_stream(char *s, size_t size, void *d) int main(int argc, char* argv[]) { - int lineno = 0; char* line; FILE* stream; icalcomponent *c; @@ -120,5 +119,5 @@ int main(int argc, char* argv[]) } while ( line != 0); - -} + return 0; + } diff --git a/libical/src/test/regression.c b/libical/src/test/regression.c index 7b1606d432..dc6a5301f1 100644 --- a/libical/src/test/regression.c +++ b/libical/src/test/regression.c @@ -34,11 +34,12 @@ #include <stdio.h> /* for printf */ #include <time.h> /* for time() */ #include "icalmemory.h" -#include "icalstore.h" -#include "icalcluster.h" #include "icalerror.h" #include "icalrestriction.h" #include "icalcalendar.h" +#include "icalgauge.h" +#include "icaldirset.h" +#include "icalfileset.h" /* This example creates and minipulates the ical object that appears * in rfc 2445, page 137 */ @@ -92,8 +93,8 @@ icalcomponent* create_simple_component() icalcomponent* calendar; struct icalperiodtype rtime; - rtime.start = icaltimetype_from_timet( time(0),0); - rtime.end = icaltimetype_from_timet( time(0),0); + rtime.start = icaltime_from_timet( time(0),0,0); + rtime.end = icaltime_from_timet( time(0),0,0); rtime.end.hour++; @@ -122,12 +123,12 @@ icalcomponent* create_new_component() icalcomponent* timezone; icalcomponent* tzc; icalcomponent* event; - struct icaltimetype atime = icaltimetype_from_timet( time(0),0); + struct icaltimetype atime = icaltime_from_timet( time(0),0,0); struct icalperiodtype rtime; icalproperty* property; - rtime.start = icaltimetype_from_timet( time(0),0); - rtime.end = icaltimetype_from_timet( time(0),0); + rtime.start = icaltime_from_timet( time(0),0,0); + rtime.end = icaltime_from_timet( time(0),0,0); rtime.end.hour++; @@ -331,11 +332,11 @@ icalcomponent* create_new_component_with_va_args() { icalcomponent* calendar; - struct icaltimetype atime = icaltimetype_from_timet( time(0),0); + struct icaltimetype atime = icaltime_from_timet( time(0),0,0); struct icalperiodtype rtime; - rtime.start = icaltimetype_from_timet( time(0),0); - rtime.end = icaltimetype_from_timet( time(0),0); + rtime.start = icaltime_from_timet( time(0),0,0); + rtime.end = icaltime_from_timet( time(0),0,0); rtime.end.hour++; @@ -524,9 +525,9 @@ void test_values() icalvalue_free(copy); - v = icalvalue_new_date(icaltimetype_from_timet( time(0),0)); + v = icalvalue_new_date(icaltime_from_timet( time(0),0,0)); printf("date 1: %s\n",icalvalue_as_ical_string(v)); - icalvalue_set_date(v,icaltimetype_from_timet( time(0)+3600,0)); + icalvalue_set_date(v,icaltime_from_timet( time(0)+3600,0,0)); printf("date 2: %s\n",icalvalue_as_ical_string(v)); copy = icalvalue_new_clone(v); @@ -662,6 +663,7 @@ void test_components() void test_memory() { size_t bufsize = 256; + int i; char *p; char S1[] = "1) When in the Course of human events, "; @@ -682,8 +684,7 @@ void test_memory() char *f, *b1, *b2, *b3, *b4, *b5, *b6, *b7, *b8; - #define BUFSIZE 1024 - +#define BUFSIZE 1024 f = icalmemory_new_buffer(bufsize); p = f; @@ -737,32 +738,61 @@ void test_memory() free(f); bufsize = 4; + f = icalmemory_new_buffer(bufsize); + + memset(f,0,bufsize); p = f; icalmemory_append_char(&f, &p, &bufsize, 'a'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'b'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'c'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'd'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'e'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'f'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'g'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'h'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'i'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'j'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'a'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'b'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'c'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'd'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'e'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'f'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'g'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'h'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'i'); + printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'j'); - printf("Char-by-Char buffer: %s\n", f); + + for(i=0; i<100; i++){ + f = icalmemory_tmp_buffer(bufsize); + + assert(f!=0); + memset(f,0,bufsize); + sprintf(f,"%d",i); + } } @@ -772,14 +802,14 @@ int test_store() icalcomponent *c, *gauge; icalerrorenum error; icalcomponent *next, *itr; - icalcluster* cluster; + icalfileset* cluster; struct icalperiodtype rtime; - icalstore *s = icalstore_new("store"); + icaldirset *s = icaldirset_new("store"); int i; - rtime.start = icaltimetype_from_timet( time(0),0); + rtime.start = icaltime_from_timet( time(0),0,0); - cluster = icalcluster_new("clusterin.vcd"); + cluster = icalfileset_new("clusterin.vcd"); if (cluster == 0){ printf("Failed to create cluster: %s\n",icalerror_strerror(icalerrno)); @@ -799,10 +829,10 @@ int test_store() rtime.end = rtime.start; rtime.end.hour++; - for (itr = icalcluster_get_first_component(cluster, + for (itr = icalfileset_get_first_component(cluster, ICAL_ANY_COMPONENT); itr != 0; - itr = icalcluster_get_next_component(cluster, + itr = icalfileset_get_next_component(cluster, ICAL_ANY_COMPONENT)){ icalcomponent *clone; icalproperty *p; @@ -847,7 +877,7 @@ int test_store() printf("\n----------\n%s\n---------\n",icalcomponent_as_ical_string(clone)); - error = icalstore_add_component(s,clone); + error = icaldirset_add_component(s,clone); assert(icalerrno == ICAL_NO_ERROR); @@ -877,15 +907,15 @@ int test_store() #if 0 - icalstore_select(s,gauge); + icaldirset_select(s,gauge); - for(c = icalstore_first(s); c != 0; c = icalstore_next(s)){ + for(c = icaldirset_first(s); c != 0; c = icaldirset_next(s)){ printf("Got one! (%d)\n", count++); if (c != 0){ printf("%s", icalcomponent_as_ical_string(c));; - if (icalstore_store(s2,c) == 0){ + if (icaldirset_store(s2,c) == 0){ printf("Failed to write!\n"); } icalcomponent_free(c); @@ -895,18 +925,18 @@ int test_store() } - icalstore_free(s2); + icaldirset_free(s2); #endif - for(c = icalstore_get_first_component(s); + for(c = icaldirset_get_first_component(s,ICAL_ANY_COMPONENT); c != 0; c = next){ - next = icalstore_get_next_component(s); + next = icaldirset_get_next_component(s,ICAL_ANY_COMPONENT); if (c != 0){ - /*icalstore_remove_component(s,c);*/ + /*icaldirset_remove_component(s,c);*/ printf("%s", icalcomponent_as_ical_string(c));; } else { printf("Failed to get component\n"); @@ -915,7 +945,7 @@ int test_store() } - icalstore_free(s); + icaldirset_free(s); return 0; } @@ -976,7 +1006,7 @@ int test_compare() printf("%s",icalcomponent_as_ical_string(gauge)); - printf("%d\n",icalstore_test(c,gauge)); + printf("%d\n",icalgauge_test(c,gauge)); return 0; } @@ -984,13 +1014,13 @@ int test_compare() void test_restriction() { icalcomponent *comp; - struct icaltimetype atime = icaltimetype_from_timet( time(0),0); + struct icaltimetype atime = icaltime_from_timet( time(0),0,0); int valid; struct icalperiodtype rtime; - rtime.start = icaltimetype_from_timet( time(0),0); - rtime.end = icaltimetype_from_timet( time(0),0); + rtime.start = icaltime_from_timet( time(0),0,0); + rtime.end = icaltime_from_timet( time(0),0,0); rtime.end.hour++; @@ -1097,11 +1127,11 @@ void test_restriction() void test_calendar() { icalcomponent *comp; - icalcluster *c; - icalstore *s; + icalfileset *c; + icaldirset *s; icalcalendar* calendar = icalcalendar_new("calendar"); icalerrorenum error; - struct icaltimetype atime = icaltimetype_from_timet( time(0),0); + struct icaltimetype atime = icaltime_from_timet( time(0),0,0); comp = icalcomponent_vanew( ICAL_VEVENT_COMPONENT, @@ -1125,13 +1155,13 @@ void test_calendar() s = icalcalendar_get_booked(calendar); - error = icalstore_add_component(s,comp); + error = icaldirset_add_component(s,comp); assert(error == ICAL_NO_ERROR); c = icalcalendar_get_properties(calendar); - error = icalcluster_add_component(c,icalcomponent_new_clone(comp)); + error = icalfileset_add_component(c,icalcomponent_new_clone(comp)); assert(error == ICAL_NO_ERROR); @@ -1170,6 +1200,19 @@ void test_recur() } +void test_recur_expansion() +{ + + icalvalue *v; + + v = icalvalue_new_from_string(ICAL_RECUR_VALUE, + "FREQ=YEARLY;UNTIL=123456T123456;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9;BYMINUTE=30"); + + printf("%s\n",icalvalue_as_ical_string(v)); + + icalrecurrencetype_test(); +} + void test_duration() { @@ -1278,19 +1321,213 @@ void test_requeststat() } +void test_time() +{ + struct icaltimetype ictt; + time_t tt,tt2; + icalvalue *v; + short day_of_week,start_day_of_week, day_of_year; + + + tt = time(0); + + printf("System time is: %s\n",ctime(&tt)); + + ictt = icaltime_from_timet(tt,0,0); + + v = icalvalue_new_datetime(ictt); + + printf("System time from libical: %s\n",icalvalue_as_ical_string(v)); + + tt2 = icaltime_as_timet(ictt); + printf("Converted back to libc: %s\n",ctime(&tt2)); + + + ictt.year++; + tt2 = icaltime_as_timet(ictt); + printf("Add a year: %s\n",ctime(&tt2)); + + ictt.month+=13; + tt2 = icaltime_as_timet(ictt); + printf("Add 13 months: %s\n",ctime(&tt2)); + + ictt.second+=90; + tt2 = icaltime_as_timet(ictt); + printf("Add 90 seconds: %s\n",ctime(&tt2)); + + ictt = icaltime_from_timet(tt,0,0); + + + day_of_week = icaltime_day_of_week(ictt); + start_day_of_week = icaltime_start_doy_of_week(ictt); + day_of_year = icaltime_day_of_year(ictt); + + printf("Today is day of week %d, day of year %d\n",day_of_week,day_of_year); + printf("Week started n doy of %d\n",start_day_of_week); + + +} + +void test_iterators() +{ + icalcomponent *c,*inner,*next; + icalcompiter i; + + c= icalcomponent_vanew( + ICAL_VCALENDAR_COMPONENT, + icalcomponent_vanew(ICAL_VEVENT_COMPONENT, + icalproperty_vanew_version("1"),0), + icalcomponent_vanew(ICAL_VEVENT_COMPONENT, + icalproperty_vanew_version("2"),0), + icalcomponent_vanew(ICAL_VEVENT_COMPONENT, + icalproperty_vanew_version("3"),0), + icalcomponent_vanew(ICAL_VEVENT_COMPONENT, + icalproperty_vanew_version("4"),0), + icalcomponent_vanew(ICAL_VTODO_COMPONENT, + icalproperty_vanew_version("5"),0), + icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, + icalproperty_vanew_version("6"),0), + icalcomponent_vanew(ICAL_VEVENT_COMPONENT, + icalproperty_vanew_version("7"),0), + icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, + icalproperty_vanew_version("8"),0), + icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, + icalproperty_vanew_version("9"),0), + icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, + icalproperty_vanew_version("10"),0), + 0); + + printf("1: "); + + /* List all of the VEVENTS */ + for(i = icalcomponent_begin_component(c,ICAL_VEVENT_COMPONENT); + icalcompiter_deref(&i)!= 0; icalcompiter_next(&i)){ + + icalcomponent *this = icalcompiter_deref(&i); + + icalproperty *p = + icalcomponent_get_first_property(this, + ICAL_VERSION_PROPERTY); + char* s = icalproperty_get_version(p); + + printf("%s ",s); + + } + + printf("\n2: "); + +#if 0 + for(inner = icalcomponent_get_first_component(c,ICAL_VEVENT_COMPONENT); + inner != 0; + inner = next){ + + next = icalcomponent_get_next_component(c,ICAL_VEVENT_COMPONENT); + + icalcomponent_remove_component(c,inner); + + icalcomponent_free(inner); + } +#endif + + /* Delete all of the VEVENTS */ + /* reset iterator */ + icalcomponent_get_first_component(c,ICAL_VEVENT_COMPONENT); + + while((inner=icalcomponent_get_current_component(c)) != 0 ){ + if(icalcomponent_isa(inner) == ICAL_VEVENT_COMPONENT){ + icalcomponent_remove_component(c,inner); + } else { + icalcomponent_get_next_component(c,ICAL_VEVENT_COMPONENT); + } + } + + + + /* List all remaining components */ + for(inner = icalcomponent_get_first_component(c,ICAL_ANY_COMPONENT); + inner != 0; + inner = icalcomponent_get_next_component(c,ICAL_ANY_COMPONENT)){ + + + icalproperty *p = + icalcomponent_get_first_property(inner,ICAL_VERSION_PROPERTY); + + char* s = icalproperty_get_version(p); + + printf("%s ",s); + } + + printf("\n3: "); + + + /* Remove all remaining components */ + for(inner = icalcomponent_get_first_component(c,ICAL_ANY_COMPONENT); + inner != 0; + inner = next){ + + icalcomponent *this; + icalproperty *p; + char* s; + next = icalcomponent_get_next_component(c,ICAL_ANY_COMPONENT); + + p=icalcomponent_get_first_property(inner,ICAL_VERSION_PROPERTY); + s = icalproperty_get_version(p); + printf("rem:%s ",s); + + icalcomponent_remove_component(c,inner); + + this = icalcomponent_get_current_component(c); + + if(this != 0){ + p=icalcomponent_get_first_property(this,ICAL_VERSION_PROPERTY); + s = icalproperty_get_version(p); + printf("next:%s; ",s); + } + + icalcomponent_free(inner); + } + + printf("\n4: "); + + + /* List all remaining components */ + for(inner = icalcomponent_get_first_component(c,ICAL_ANY_COMPONENT); + inner != 0; + inner = icalcomponent_get_next_component(c,ICAL_ANY_COMPONENT)){ + + icalproperty *p = + icalcomponent_get_first_property(inner,ICAL_VERSION_PROPERTY); + + char* s = icalproperty_get_version(p); + + printf("%s ",s); + } + + printf("\n"); +} + int main(int argc, char *argv[]) { + printf("\n------------Test Memory---------------\n"); + test_memory(); + +exit(0); + + + printf("\n------------Test Iterators-----------\n"); + test_iterators(); + + + printf("\n------------Test time----------------\n"); + test_time(); printf("\n------------Test Restriction---------------\n"); test_restriction(); - exit(0); - printf("\n------------Test request status-------\n"); test_requeststat(); - printf("\n------------Test strings---------------\n"); test_strings(); @@ -1303,9 +1540,6 @@ int main(int argc, char *argv[]) printf("\n------------Test Compare---------------\n"); test_compare(); - printf("\n------------Test Memory---------------\n"); - test_memory(); - printf("\n------------Test Values---------------\n"); test_values(); diff --git a/libical/src/test/storage.c b/libical/src/test/storage.c index f6d0dd69e5..d53001b574 100644 --- a/libical/src/test/storage.c +++ b/libical/src/test/storage.c @@ -34,14 +34,13 @@ #include <stdio.h> /* for printf */ #include <time.h> /* for time() */ #include "icalmemory.h" -#include "icalstore.h" -#include "icalcluster.h" +#include "icaldirset.h" +#include "icalfileset.h" #include "icalerror.h" #include "icalrestriction.h" #include "icalcalendar.h" -/* This example creates and minipulates the ical object that appears - * in rfc 2445, page 137 */ +#define OUTPUT_FILE "filesetout.ics" char str[] = "BEGIN:VCALENDAR\n\ PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\n\ @@ -106,29 +105,31 @@ END:VCALENDAR\n\ "; -void test_cluster() +void test_fileset() { - icalcluster *cin, *cout; + icalfileset *cout; int month = 0; int count=0; struct icaltimetype start, end; icalcomponent *c,*clone, *itr; - start = icaltimetype_from_timet( time(0),0); + start = icaltime_from_timet( time(0),0,0); end = start; end.hour++; - cout = icalcluster_new("clusterout.ics"); + cout = icalfileset_new(OUTPUT_FILE); assert(cout != 0); c = icalparser_parse_string(str2); assert(c != 0); - for(month = 1; month < 2; month++){ + /* Add data to the file */ + + for(month = 1; month < 10; month++){ icalcomponent *event; icalproperty *dtstart, *dtend; - cout = icalcluster_new("clusterout.ics"); + cout = icalfileset_new(OUTPUT_FILE); assert(cout != 0); start.month = month; @@ -147,10 +148,10 @@ void test_cluster() assert(dtend!=0); icalproperty_set_dtend(dtend,end); - icalcluster_add_component(cout,clone); - icalcluster_commit(cout); + icalfileset_add_component(cout,clone); + icalfileset_commit(cout); - icalcluster_free(cout); + icalfileset_free(cout); } @@ -158,13 +159,13 @@ void test_cluster() /* Print them out */ - cout = icalcluster_new("clusterout.ics"); + cout = icalfileset_new(OUTPUT_FILE); assert(cout != 0); - for (itr = icalcluster_get_first_component(cout, + for (itr = icalfileset_get_first_component(cout, ICAL_ANY_COMPONENT); itr != 0; - itr = icalcluster_get_next_component(cout, + itr = icalfileset_get_next_component(cout, ICAL_ANY_COMPONENT)){ icalcomponent *event; @@ -184,34 +185,34 @@ void test_cluster() /* Remove all of them */ - icalcluster_free(cout); + icalfileset_free(cout); - cout = icalcluster_new("clusterout.ics"); + cout = icalfileset_new(OUTPUT_FILE); assert(cout != 0); - for (itr = icalcluster_get_first_component(cout, + for (itr = icalfileset_get_first_component(cout, ICAL_ANY_COMPONENT); itr != 0; - itr = icalcluster_get_next_component(cout, + itr = icalfileset_get_next_component(cout, ICAL_ANY_COMPONENT)){ - icalcluster_remove_component(cout, itr); + icalfileset_remove_component(cout, itr); } - icalcluster_free(cout); + icalfileset_free(cout); /* Print them out again */ - cout = icalcluster_new("clusterout.ics"); + cout = icalfileset_new(OUTPUT_FILE); assert(cout != 0); count =0; - for (itr = icalcluster_get_first_component(cout, + for (itr = icalfileset_get_first_component(cout, ICAL_ANY_COMPONENT); itr != 0; - itr = icalcluster_get_next_component(cout, + itr = icalfileset_get_next_component(cout, ICAL_ANY_COMPONENT)){ icalcomponent *event; @@ -229,29 +230,29 @@ void test_cluster() } - icalcluster_free(cout); + icalfileset_free(cout); } -int test_store() +int test_dirset() { icalcomponent *c, *gauge; icalerrorenum error; - icalcomponent *next, *itr; - icalcluster* cluster; + icalcomponent *itr; + icalfileset* cluster; struct icalperiodtype rtime; - icalstore *s = icalstore_new("store"); + icaldirset *s = icaldirset_new("store"); int i; assert(s != 0); - rtime.start = icaltimetype_from_timet( time(0),0); + rtime.start = icaltime_from_timet( time(0),0,0); - cluster = icalcluster_new("clusterout.ics"); + cluster = icalfileset_new(OUTPUT_FILE); assert(cluster != 0); @@ -268,10 +269,10 @@ int test_store() rtime.end = rtime.start; rtime.end.hour++; - for (itr = icalcluster_get_first_component(cluster, + for (itr = icalfileset_get_first_component(cluster, ICAL_ANY_COMPONENT); itr != 0; - itr = icalcluster_get_next_component(cluster, + itr = icalfileset_get_next_component(cluster, ICAL_ANY_COMPONENT)){ icalcomponent *clone, *inner; icalproperty *p; @@ -316,7 +317,8 @@ int test_store() printf("\n----------\n%s\n---------\n",icalcomponent_as_ical_string(inner)); - error = icalstore_add_component(s,inner); + error = icaldirset_add_component(s, + icalcomponent_new_clone(itr)); assert(icalerrno == ICAL_NO_ERROR); @@ -346,15 +348,15 @@ int test_store() #if 0 - icalstore_select(s,gauge); + icaldirset_select(s,gauge); - for(c = icalstore_first(s); c != 0; c = icalstore_next(s)){ + for(c = icaldirset_first(s); c != 0; c = icaldirset_next(s)){ printf("Got one! (%d)\n", count++); if (c != 0){ printf("%s", icalcomponent_as_ical_string(c));; - if (icalstore_store(s2,c) == 0){ + if (icaldirset_store(s2,c) == 0){ printf("Failed to write!\n"); } icalcomponent_free(c); @@ -364,38 +366,43 @@ int test_store() } - icalstore_free(s2); + icaldirset_free(s2); #endif - for(c = icalstore_get_first_component(s); + for(c = icaldirset_get_first_component(s,ICAL_ANY_COMPONENT); c != 0; - c = next){ - - next = icalstore_get_next_component(s); + c = icaldirset_get_next_component(s,ICAL_ANY_COMPONENT)){ if (c != 0){ - /*icalstore_remove_component(s,c);*/ printf("%s", icalcomponent_as_ical_string(c));; } else { printf("Failed to get component\n"); } + } + + /* Remove all of the components */ + i=0; + while((c=icaldirset_get_current_component(s)) != 0 ){ + i++; + icaldirset_remove_component(s,c); } + - icalstore_free(s); + icaldirset_free(s); return 0; } void test_calendar() { icalcomponent *comp; - icalcluster *c; - icalstore *s; + icalfileset *c; + icaldirset *s; icalcalendar* calendar = icalcalendar_new("calendar"); icalerrorenum error; - struct icaltimetype atime = icaltimetype_from_timet( time(0),0); + struct icaltimetype atime = icaltime_from_timet( time(0),0,0); comp = icalcomponent_vanew( ICAL_VEVENT_COMPONENT, @@ -419,13 +426,13 @@ void test_calendar() s = icalcalendar_get_booked(calendar); - error = icalstore_add_component(s,comp); + error = icaldirset_add_component(s,comp); assert(error == ICAL_NO_ERROR); c = icalcalendar_get_properties(calendar); - error = icalcluster_add_component(c,icalcomponent_new_clone(comp)); + error = icalfileset_add_component(c,icalcomponent_new_clone(comp)); assert(error == ICAL_NO_ERROR); @@ -437,16 +444,14 @@ void test_calendar() int main(int argc, char *argv[]) { +/* printf("\n------------Test File Set---------------\n"); + test_fileset(); */ - printf("\n------------Test Cluster---------------\n"); - test_cluster(); + printf("\n------------Test Dir Set---------------\n"); + test_dirset(); #if 0 - printf("\n------------Test Store---------------\n"); - test_store(); - - printf("\n------------Test Calendar---------------\n"); test_calendar(); diff --git a/libical/src/test/stow.c b/libical/src/test/stow.c index d7629855c5..f742b417a5 100644 --- a/libical/src/test/stow.c +++ b/libical/src/test/stow.c @@ -33,35 +33,85 @@ #include <stdlib.h> #include <sys/utsname.h> /* for uname */ #include <sys/stat.h> /* for stat */ -#include <unistd.h> /* for stat, getpid */ +#include <unistd.h> /* for stat, getpid, getopt */ +#include <pwd.h> /* For getpwent */ +#include <sys/types.h> /* For getpwent */ +#include <ctype.h> /* for tolower */ #include "ical.h" #include "icalcalendar.h" - +#include "icalfileset.h" +#include "icalmime.h" char* program_name; #define TMPSIZE 2048 +#define SENDMAIL "/usr/lib/sendmail -t" enum options { - STORE_IN_DIR, + STORE_IN_FILE, STORE_IN_DB, - INPUT_IS_EMAIL, + INPUT_IS_MIME, INPUT_IS_ICAL, INPUT_FROM_STDIN, - INPUT_FROM_FILE + INPUT_FROM_FILE, + ERRORS_TO_STDOUT, + ERRORS_TO_ORGANIZER }; struct options_struct { enum options storage; enum options input_type; + enum options input_source; + enum options errors; char* input_file; - char* input_text; char* calid; - char* caldir; + char* output_file; +}; + + +enum file_type +{ + ERROR, + NO_FILE, + DIRECTORY, + REGULAR, + OTHER }; +enum file_type test_file(char *path) +{ + struct stat sbuf; + enum file_type type; + + errno = 0; + + /* Check if the path already exists and if it is a directory*/ + if (stat(path,&sbuf) != 0){ + + /* A file by the given name does not exist, or there was + another error */ + if(errno == ENOENT) + { + type = NO_FILE; + } else { + type = ERROR; + } + + } else { + /* A file by the given name exists, but is it a directory? */ + + if (S_ISDIR(sbuf.st_mode)){ + type = DIRECTORY; + } else if(S_ISREG(sbuf.st_mode)){ + type = REGULAR; + } else { + type = OTHER; + } + } + return type; +} char* lowercase(char* str) { @@ -79,23 +129,33 @@ char* lowercase(char* str) return new; } +#if 0 char* get_local_attendee(struct options_struct *opt) { char attendee[PATH_MAX]; - char* user = getenv("USER"); - struct utsname uts; + if(opt->calid){ - uname(&uts); + strncpy(attendee,opt->calid,PATH_MAX); - /* HACK nodename may not be a fully qualified domain name */ - snprintf(attendee,PATH_MAX,"%s@%s",user,uts.nodename); + } else { + + char* user = getenv("USER"); + struct utsname uts; + uname(&utget_option); + /* HACK nodename may not be a fully qualified domain name */ + snprintf(attendee,PATH_MAX,"%s@%s",user,uts.nodename); + } + return lowercase(attendee); } +#endif void usage(char *message) { + fprintf(stderr,"Usage: %s [-emdcn] [-i inputfile] [-o outputfile] [-u calid]\n",program_name); + } icalcomponent* get_first_real_component(icalcomponent *comp) @@ -140,20 +200,20 @@ char* make_mime(char* to, char* from, char* subject, uname(&uts); srand(time(0)<<getpid()); - sprintf(content_id,"%d-%d@%s",time(0),rand(),uts.nodename); - sprintf(boundary,"%d-%d-%s",time(0),rand(),uts.nodename); + sprintf(content_id,"%d-%d@%s",(int)time(0),rand(),uts.nodename); + sprintf(boundary,"%d-%d-%s",(int)time(0),rand(),uts.nodename); sprintf(mime_part_1,"Content-ID: %s\n\ Content-type: text/plain\n\ Content-Description: Text description of error message\n\n\ -%s\n\n%s", +%s\n\n--%s", content_id,text_message,boundary); if(ical_message != 0 && method != 0){ - sprintf(mime_part_2,"\nContent-ID: %s\n\ + sprintf(mime_part_2,"Content-ID: %s\n\ Content-type: text/calendar; method=%s\n\ -Content-Description: ICal component reply\n\n\ -%s\n\n%s--\n", +Content-Description: iCal component reply\n\n\ +%s\n\n--%s--", content_id,method,ical_message,boundary); } @@ -166,6 +226,7 @@ Content-Type: multipart/mixed; boundary=\"%s\"\n\ \n\ This is a multimedia message in MIME format\n\ \n\ +--%s %s ", to,from,subject,content_id,boundary,boundary, @@ -181,14 +242,39 @@ Content-Type: multipart/mixed; boundary=\"%s\"\n\ } /* The incoming component had fatal errors */ -void return_failure(icalcomponent* comp, char* message, struct options_struct *opt) +void return_failure(icalcomponent* comp, char* message, + struct options_struct *opt) { - + char* local_attendee = opt->calid; + FILE* p; - fputs(make_mime("Dest", "Source", "iMIP error", - message, "reply", - icalcomponent_as_ical_string(comp)),stdout); + icalcomponent *inner = get_first_real_component(comp); + + icalproperty *organizer_prop = icalcomponent_get_first_property(inner,ICAL_ORGANIZER_PROPERTY); + char *organizer = icalproperty_get_organizer(organizer_prop); + + organizer += 7; + if (opt->errors == ERRORS_TO_ORGANIZER){ + p = popen(SENDMAIL,"w"); + } else { + p = stdout; + } + + if(p == 0){ + fprintf(stderr, + "%s: fatal. Could not open pipe to sendmail (\"%s\") \n", + program_name,SENDMAIL); + exit(1); + } + + fputs(make_mime(organizer, local_attendee, "iMIP error", + message, "reply", + icalcomponent_as_ical_string(comp)),p); + + if (opt->errors == ERRORS_TO_ORGANIZER){ + pclose(p); + } } /* The program had a fatal error and could not process the incoming component*/ @@ -201,43 +287,124 @@ void return_error(icalcomponent* comp, char* message, struct options_struct *op } -char* check_component(icalcomponent* comp, struct options_struct *opt) +icalcomponent* make_reply(icalcomponent *comp, icalproperty *return_status, + struct options_struct *opt) + +{ + icalcomponent *reply, *rinner; + icalcomponent *inner = get_first_real_component(comp); + icalproperty *p=0; + char* local_attendee = opt->calid; + char attendee[TMPSIZE]; + + char prodid[TMPSIZE]; + + snprintf(attendee,TMPSIZE,"mailto:%s",local_attendee); + + snprintf(prodid,TMPSIZE,"-//Softwarestudio.org//%s version %s//EN",ICAL_PACKAGE,ICAL_VERSION); + + /* Create the base component */ + reply = icalcomponent_vanew( + ICAL_VCALENDAR_COMPONENT, + icalproperty_new_version(strdup("2.0")), + icalproperty_new_prodid(strdup(prodid)), + icalproperty_new_method(ICAL_METHOD_REPLY), + icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + icalproperty_new_clone( + icalcomponent_get_first_property(inner,ICAL_DTSTAMP_PROPERTY)), + icalproperty_new_clone( + icalcomponent_get_first_property(inner,ICAL_ORGANIZER_PROPERTY)), + icalproperty_new_clone( + icalcomponent_get_first_property(inner,ICAL_UID_PROPERTY)), + icalproperty_new_attendee(attendee), + 0), + 0); + + + /* Convert errors into request-status properties and transfers + them to the reply component */ + + icalcomponent_convert_errors(comp); + + rinner = get_first_real_component(reply); + + for(p = icalcomponent_get_first_property(inner, + ICAL_REQUESTSTATUS_PROPERTY); + p != 0; + p = icalcomponent_get_next_property(inner, + ICAL_REQUESTSTATUS_PROPERTY)){ + + icalcomponent_add_property(rinner,icalproperty_new_clone(p)); + } + + if(return_status != 0){ + icalcomponent_add_property(rinner, return_status); + } + + return reply; + +} + +int check_attendee(icalproperty *p, struct options_struct *opt){ + char* s = icalproperty_get_attendee(p); + char* lower_attendee = lowercase(s); + char* local_attendee = opt->calid; + + /* Check that attendee begins with "mailto:" */ + if (strncmp(lower_attendee,"mailto:",7) == 0){ + /* skip over the mailto: part */ + lower_attendee += 7; + + if(strcmp(lower_attendee,local_attendee) == 0){ + return 1; + } + + lower_attendee -= 7; + + free(lower_attendee); + } + + return 0; +} + +char static_component_error_str[PATH_MAX]; +char* check_component(icalcomponent* comp, icalproperty **return_status, + struct options_struct *opt) { - static char static_component_error_str[PATH_MAX]; char* component_error_str=0; icalcomponent* inner; int errors = 0; icalproperty *p; int found_attendee = 0; + *return_status = 0; + /* This do/while loop only executes once because it is being used to fake exceptions */ do { - /* Check that the root component is a VCALENDAR */ - if(icalcomponent_isa(comp) != ICAL_VCALENDAR_COMPONENT){ + /* Check that we actually got a component */ + if(comp == 0){ strcpy(static_component_error_str, - "Root component is not a VCALENDAR"); + "Did not find a component"); component_error_str = static_component_error_str; break; } - /* Check that the component passes iTIP restrictions */ - - errors = icalcomponent_count_errors(comp); - icalrestriction_check(comp); - - if(errors != icalcomponent_count_errors(comp)){ + /* Check that the root component is a VCALENDAR */ + if(icalcomponent_isa(comp) != ICAL_VCALENDAR_COMPONENT){ strcpy(static_component_error_str, - "The component does not conform to iTIP restrictions"); + "Root component is not a VCALENDAR"); component_error_str = static_component_error_str; break; } + /* Check that the component has a METHOD */ - if (!icalcomponent_get_first_property(comp,ICAL_METHOD_PROPERTY) == 0) + if (icalcomponent_get_first_property(comp,ICAL_METHOD_PROPERTY) == 0) { strcpy(static_component_error_str, "Component does not have a METHOD property"); @@ -245,208 +412,288 @@ char* check_component(icalcomponent* comp, struct options_struct *opt) break; } - /* Check for this user as an attendee */ + inner = get_first_real_component(comp); - inner = get_first_real_component(comp); + /* Check that the compopnent has an organizer */ + if(icalcomponent_get_first_property(inner,ICAL_ORGANIZER_PROPERTY) == 0){ + fprintf(stderr,"%s: fatal. Component does not have an ORGANIZER property\n",program_name); + + exit(1); + } + + + /* Check for this user as an attendee or organizer */ for(p = icalcomponent_get_first_property(inner,ICAL_ATTENDEE_PROPERTY); p != 0; p = icalcomponent_get_next_property(inner,ICAL_ATTENDEE_PROPERTY)){ - - char* s = icalproperty_get_attendee(p); - char* lower_attendee = lowercase(s); - char* local_attendee = get_local_attendee(opt); - - /* Check that attendee begins with "mailto:" */ - if (strncmp(lower_attendee,"mailto:",7) == 0){ - /* skip over the mailto: part */ - lower_attendee += 7; - - if(strcmp(lower_attendee,local_attendee) == 0){ - found_attendee = 1; - } - - lower_attendee -= 7; + + found_attendee += check_attendee(p,opt); + } - free(local_attendee); - free(lower_attendee); - - } + for(p = icalcomponent_get_first_property(inner,ICAL_ORGANIZER_PROPERTY); + p != 0; + p = icalcomponent_get_next_property(inner,ICAL_ORGANIZER_PROPERTY)){ + + found_attendee += check_attendee(p,opt); } - + if (found_attendee == 0){ - char* local_attendee = get_local_attendee(opt); + struct icalreqstattype rs; + char* rs_string; + memset(static_component_error_str,0,PATH_MAX); + snprintf(static_component_error_str,PATH_MAX, - "This target user (%s) is not listed as an attendee", - local_attendee ); + "This target user (%s) is not listed as an attendee or organizer", + opt->calid ); component_error_str = static_component_error_str; - free(local_attendee); + + rs.code = ICAL_3_7_INVCU_STATUS; + rs.desc = 0; + rs.debug = component_error_str; + rs_string = icalreqstattype_as_string(rs); + + *return_status = icalproperty_new_requeststatus(rs_string); break; } + + + /* Check that the component passes iTIP restrictions */ + + errors = icalcomponent_count_errors(comp); + icalrestriction_check(comp); + + if(errors != icalcomponent_count_errors(comp)){ + snprintf(static_component_error_str,PATH_MAX, + "The component does not conform to iTIP restrictions.\n Here is the original component; look at the X-LIC-ERROR properties\nfor details\n\n%s",icalcomponent_as_ical_string(comp)); + component_error_str = static_component_error_str; + break; + } + + + } while(0); return component_error_str; } + void get_options(int argc, char* argv[], struct options_struct *opt) { - opt->storage = STORE_IN_DIR; - opt->input_type = INPUT_FROM_STDIN; + int c; + extern char *optarg; + extern int optind, optopt; + int errflg=0; + + opt->storage = STORE_IN_FILE; + opt->input_source = INPUT_FROM_STDIN; + opt->input_type = INPUT_IS_ICAL; opt->input_file = 0; - opt->input_text = 0; + opt->errors = ERRORS_TO_ORGANIZER; opt->calid = 0; - opt->caldir = 0; -} - -char* check_options(struct options_struct *opt) -{ - return 0; -} - -void store_component(icalcomponent *comp, icalcalendar* cal, - struct options_struct *opt) -{ - - icalcluster *incoming = 0; - icalerrorenum error; - - incoming = icalcalendar_get_incoming(cal); + opt->output_file = 0; + + + while ((c = getopt(argc, argv, "nemu:o:d:b:c:i:")) != -1) { + switch (c) { + case 'e': { /* Input data is MIME encapsulated */ + opt->input_type = INPUT_IS_MIME; + break; + } + case 'm': { /* Input is iCal. Default*/ + opt->input_type = INPUT_IS_ICAL; + break; + } + case 'i': { /* Input comes from named file */ + opt->input_source = INPUT_FROM_FILE; + opt->input_file = strdup(optarg); + break; + } + case 'o': { /* Output goes to named file. Default*/ + opt->output_file = strdup(optarg); + opt->storage = STORE_IN_FILE; + break; + } + case 'd': { /* Output goes to database */ + fprintf(stderr,"%s: option -d is unimplmented\n",program_name); + opt->storage = STORE_IN_DB; + errflg++; + break; + } + case 'c': { + + break; + } + case 'u': { /* Set the calid for the output database or + file. Default is user name of user running + program */ + opt->calid = strdup(optarg); + break; + } + + case 'n': { /* Dump error to stdout. Default is to + send error to the organizer specified + in the iCal data */ + opt->errors = ERRORS_TO_STDOUT; + break; + } + + case ':': {/* Option given without an operand */ + fprintf(stderr, + "%s: Option -%c requires an operand\n", + program_name,optopt); + errflg++; + break; + } + case '?': { + errflg++; + } + + } + + if (errflg >0){ + usage(""); + exit(1); + } + } - if (incoming == 0){ - fprintf(stderr,"%s: Failed to get incoming component directory: %s\n", - program_name, icalerror_strerror(icalerrno)); - exit(1); - } + if(opt->calid == 0){ + /* If no calid specified, use username */ + char attendee[PATH_MAX]; + char* user = getenv("USER"); + struct utsname uts; + uname(&uts); + /* HACK nodename may not be a fully qualified domain name */ + snprintf(attendee,PATH_MAX,"%s@%s",user,uts.nodename); - error = icalcluster_add_component(incoming,comp); - - if (error != ICAL_NO_ERROR){ - fprintf(stderr,"%s: Failed to write incoming component: %s\n", - program_name, icalerror_strerror(icalerrno)); - exit(1); - } - - error = icalcluster_commit(incoming); - - if (error != ICAL_NO_ERROR){ - fprintf(stderr,"%s: Failed to commit incoming cluster: %s\n", - program_name, icalerror_strerror(icalerrno)); - exit(1); + opt->calid = lowercase(attendee); } - - return; -} - -enum file_type -{ - ERROR, - NO_FILE, - DIRECTORY, - REGULAR, - OTHER -}; -enum file_type test_file(char *path) -{ - struct stat sbuf; - enum file_type type; - - errno = 0; + if(opt->storage == STORE_IN_FILE && + opt->output_file ==0){ + char file[PATH_MAX]; + char* user = getenv("USER"); + struct passwd *pw; - /* Check if the path already exists and if it is a directory*/ - if (stat(path,&sbuf) != 0){ + if(!user){ + fprintf(stderr,"%s: Can't get username. Try explicitly specifing the output file with -o", program_name); + exit(1); + } - /* A file by the given name does not exist, or there was - another error */ - if(errno == ENOENT) - { - type = NO_FILE; - } else { - type = ERROR; + /* Find password entry for user */ + while( (pw = getpwent())!=0){ + if(strcmp(user,pw->pw_name)==0){ + break; + } + } + + if(pw==0){ + fprintf(stderr,"%s: Can't get get password entry for user \"%s\" Try explicitly specifing the output file with -o", + program_name,user); + exit(1); } - } else { - /* A file by the given name exists, but is it a directory? */ - - if (S_ISDIR(sbuf.st_mode)){ - type = DIRECTORY; - } else if(S_ISREG(sbuf.st_mode)){ - type = REGULAR; - } else { - type = OTHER; + if(pw->pw_dir==0){ + fprintf(stderr,"%s: User \"%s\" has no home directory. Try explicitly specifing the output file with -o", + program_name, user); + exit(1); } + + snprintf(file,PATH_MAX,"%s/.facs/%s",pw->pw_dir,opt->calid); + + opt->output_file = strdup(file); } - return type; -} -icalcalendar* get_calendar(icalcomponent* comp, struct options_struct *opt) -{ - - struct stat sbuf; - char calpath[PATH_MAX]; - char facspath[PATH_MAX]; - char* home = getenv("HOME"); - char* user = getenv("USER"); - enum file_type type; - icalcalendar* cal; + /* Now try to create the calendar directory if it does + not exist */ - snprintf(facspath,PATH_MAX,"%s/.facs",home); + if(opt->storage == STORE_IN_FILE ) { + char * p; + char* facspath = strdup(opt->output_file); + enum file_type type; - type = test_file(facspath); + /* Cut off the last slash to make it just a directoy */ - errno = 0; - if (type == NO_FILE){ + p = strrchr(facspath,'/'); - if(mkdir(facspath,0775) != 0){ - fprintf(stderr,"%s: Failed to create calendar store directory %s: %s\n", - program_name,facspath, strerror(errno)); - exit(1); - } else { - printf("%s: Creating calendar store directory %s\n",program_name,facspath); - } + if (p == 0){ + fprintf(stderr,"%s: Invalid calendar filename \"%s\"", + program_name,facspath); + exit(1); + } + + *p='\0'; + + type = test_file(facspath); - } else if(type==REGULAR || type == ERROR){ - fprintf(stderr,"%s: Cannot create calendar store directory %s\n", + errno = 0; + if (type == NO_FILE){ + + if(mkdir(facspath,0775) != 0){ + fprintf(stderr, + "%s: Failed to create calendar directory %s: %s\n", + program_name,facspath, strerror(errno)); + exit(1); + } else { + fprintf(stderr,"%s: Creating calendar directory %s\n", + program_name,facspath); + } + + } else if(type==REGULAR || type == ERROR){ + fprintf(stderr,"%s: Cannot create calendar directory %s\n", program_name,facspath); exit(1); - } + } + } +} +char* check_options(struct options_struct *opt) +{ + return 0; +} +void store_component(icalcomponent *comp, struct options_struct *opt) +{ + icalerrorenum error; - snprintf(calpath,PATH_MAX,"%s/%s",facspath,user); - type = test_file(calpath); + if(opt->storage == STORE_IN_FILE){ + icalfileset *fs = icalfileset_new(opt->output_file); - errno = 0; + if (fs == 0){ + fprintf(stderr, + "%s: Failed to get incoming component directory: %s\n", + program_name, icalerror_strerror(icalerrno)); + exit(1); + } - if (type == NO_FILE){ - if(mkdir(calpath,0775) != 0){ - fprintf(stderr,"%s: Failed to create calendar directory %s: %s\n", - program_name,calpath, strerror(errno)); - } else { - printf("%s: Creating calendar store directory %s\n",program_name,facspath); + error = icalfileset_add_component(fs,comp); + + if (error != ICAL_NO_ERROR){ + fprintf(stderr,"%s: Failed to write incoming component: %s\n", + program_name, icalerror_strerror(icalerrno)); + exit(1); } - } else if(type==REGULAR || type == ERROR){ - fprintf(stderr,"%s: Cannot create calendar directory %s\n", - program_name,calpath); + + error = icalfileset_commit(fs); + + if (error != ICAL_NO_ERROR){ + fprintf(stderr,"%s: Failed to commit incoming cluster: %s\n", + program_name, icalerror_strerror(icalerrno)); exit(1); - } - - cal = icalcalendar_new(calpath); + } + + icalfileset_free(fs); - if(cal == 0){ - fprintf(stderr,"%s: Failed to open calendar at %s: %s", - program_name,calpath,icalerror_strerror(icalerrno)); - exit(1); + return; + } else { + assert(0); } - - return cal; - } char* read_stream(char *s, size_t size, void *d) @@ -456,14 +703,14 @@ char* read_stream(char *s, size_t size, void *d) return c; } -icalcomponent* read_component(struct options_struct *opt) +icalcomponent* read_nonmime_component(struct options_struct *opt) { FILE *stream; icalcomponent *comp; icalparser* parser = icalparser_new(); char* line; - if(opt->input_type == INPUT_FROM_FILE){ + if(opt->input_source == INPUT_FROM_FILE){ stream = fopen(opt->input_file,"r"); if (stream == 0){ @@ -490,22 +737,89 @@ icalcomponent* read_component(struct options_struct *opt) } while ( line != 0); - if(opt->input_type == INPUT_FROM_FILE){ + if(opt->input_source == INPUT_FROM_FILE){ fclose(stream); } + return comp; } +icalcomponent* find_vcalendar(icalcomponent* comp) +{ + icalcomponent *c,*rtrn; + + for(c = icalcomponent_get_first_component(comp,ICAL_ANY_COMPONENT); + c != 0; + c = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)){ + + if(icalcomponent_isa(c) == ICAL_VCALENDAR_COMPONENT){ + icalcomponent_remove_component(comp,c); + return c; + } + + if((rtrn=find_vcalendar(c)) != 0){ + return rtrn; + } + } + + return 0; +} + +icalcomponent* read_mime_component(struct options_struct *opt) +{ + icalcomponent *comp,*mimecomp; + FILE* stream; + + if(opt->input_source == INPUT_FROM_FILE){ + stream = fopen(opt->input_file,"r"); + + if (stream == 0){ + perror("Can't open input file"); + exit(1); + } + + } else { + stream = stdin; + } + + assert(stream != 0); + + mimecomp = icalmime_parse(read_stream,(void*)stream); + + /* now find the iCal component embedded within the mime component */ + comp = find_vcalendar(mimecomp); + + + if(comp == 0){ + return 0; + } + + return comp; +} + +icalcomponent* read_component(struct options_struct *opt) +{ + if(opt->input_type == INPUT_IS_MIME){ + return read_mime_component(opt); + } else if (opt->input_type == INPUT_IS_ICAL){ + return read_nonmime_component(opt); + } else { + fprintf(stderr,"%s: Internal Error; unknown option for input_type\n", + program_name); + exit(1); + } +} + int main(int argc, char* argv[] ) { char* options_error_str; char* component_error_str; - icalcalendar* cal; icalcomponent* comp, *reply; struct options_struct opt; + icalproperty *return_status; - program_name = argv[0]; + program_name = strrchr(argv[0],'/'); get_options(argc, argv, &opt); @@ -516,17 +830,19 @@ int main(int argc, char* argv[] ) comp = read_component(&opt); - if ( (component_error_str = check_component(comp,&opt)) != 0){ - return_failure(comp, component_error_str, &opt); - exit(1); + if ( (component_error_str = + check_component(comp,&return_status,&opt)) != 0){ + reply = make_reply(comp,return_status,&opt); + return_failure(reply, component_error_str, &opt); + icalcomponent_free(reply); + exit(0); } - cal = get_calendar(comp,&opt); + store_component(comp,&opt); - store_component(comp,cal, &opt); - icalcomponent_free(comp); - icalcalendar_free(cal); + /* Don't free the component comp, since it is now part of the + store, and will be freed there */ exit(0); } |