diff options
author | JP Rosevear <jpr@src.gnome.org> | 2001-01-24 03:20:44 +0800 |
---|---|---|
committer | JP Rosevear <jpr@src.gnome.org> | 2001-01-24 03:20:44 +0800 |
commit | fd279723663879e742e53d7b3503248f6af91791 (patch) | |
tree | 09233c88d6c42b5bb324be7c64a8f8c64ff02846 /libical/src | |
parent | 34bcd381ce1985cc762a896f15d427e368af95e5 (diff) | |
download | gsoc2013-evolution-fd279723663879e742e53d7b3503248f6af91791.tar.gz gsoc2013-evolution-fd279723663879e742e53d7b3503248f6af91791.tar.zst gsoc2013-evolution-fd279723663879e742e53d7b3503248f6af91791.zip |
This commit was generated by cvs2svn to compensate for changes in r7747,
which included commits to RCS files with non-trunk default branches.
svn path=/trunk/; revision=7748
Diffstat (limited to 'libical/src')
24 files changed, 758 insertions, 339 deletions
diff --git a/libical/src/libical/icalmime.c b/libical/src/libical/icalmime.c index 1aaf9c9aa9..17db8cdee1 100644 --- a/libical/src/libical/icalmime.c +++ b/libical/src/libical/icalmime.c @@ -32,6 +32,7 @@ #include "sspm.h" #include "stdlib.h" #include <string.h> /* For strdup */ +#include <stdio.h> /* for snprintf*/ #ifdef DMALLOC #include "dmalloc.h" diff --git a/libical/src/libical/icalparameter.h.in b/libical/src/libical/icalparameter.h.in index d3bd4c963c..c215fa0fdc 100644 --- a/libical/src/libical/icalparameter.h.in +++ b/libical/src/libical/icalparameter.h.in @@ -4,7 +4,7 @@ CREATOR: eric 20 March 1999 - $Id: icalparameter.h.in,v 1.1 2000/12/11 22:05:59 federico Exp $ + $Id: icalparameter.h.in,v 1.1.1.2 2001/01/23 19:20:40 jpr Exp $ $Locker: $ diff --git a/libical/src/libical/icalproperty.h.in b/libical/src/libical/icalproperty.h.in index cfc7704970..be74b38d43 100644 --- a/libical/src/libical/icalproperty.h.in +++ b/libical/src/libical/icalproperty.h.in @@ -3,7 +3,7 @@ FILE: icalderivedproperties.{c,h} CREATOR: eric 09 May 1999 - $Id: icalproperty.h.in,v 1.1 2000/12/11 22:05:59 federico Exp $ + $Id: icalproperty.h.in,v 1.1.1.2 2001/01/23 19:20:40 jpr Exp $ (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org ======================================================================*/ diff --git a/libical/src/libical/icalrecur.h b/libical/src/libical/icalrecur.h index fe82ff960c..a4880d7de1 100644 --- a/libical/src/libical/icalrecur.h +++ b/libical/src/libical/icalrecur.h @@ -26,7 +26,6 @@ #include <time.h> #include "icaltime.h" - /*********************************************************************** * Recurrance enumerations **********************************************************************/ @@ -65,7 +64,9 @@ enum { }; const char* icalrecur_recurrence_to_string(icalrecurrencetype_frequency kind); +icalrecurrencetype_frequency icalrecur_string_to_recurrence(const char* str); const char* icalrecur_weekday_to_string(icalrecurrencetype_weekday kind); +icalrecurrencetype_weekday icalrecur_string_to_weekday(const char* str); /********************** Recurrence type routines **************/ @@ -73,6 +74,15 @@ const char* icalrecur_weekday_to_string(icalrecurrencetype_weekday kind); /* See RFC 2445 Section 4.3.10, RECUR Value, for an explaination of the values and fields in struct icalrecurrencetype */ +#define ICAL_BY_SECOND_SIZE 61 +#define ICAL_BY_MINUTE_SIZE 61 +#define ICAL_BY_HOUR_SIZE 25 +#define ICAL_BY_DAY_SIZE 364 /* 7 days * 52 weeks */ +#define ICAL_BY_MONTHDAY_SIZE 32 +#define ICAL_BY_YEARDAY_SIZE 367 +#define ICAL_BY_WEEKNO_SIZE 54 +#define ICAL_BY_MONTH_SIZE 13 +#define ICAL_BY_SETPOS_SIZE 367 struct icalrecurrencetype { @@ -80,7 +90,7 @@ struct icalrecurrencetype /* until and count are mutually exclusive. */ - struct icaltimetype until; /* Hack. Must be time_t for general use */ + struct icaltimetype until; int count; short interval; @@ -93,24 +103,24 @@ struct icalrecurrencetype * value more than once. * Each of the lists is terminated with the value - * ICALRECURRENCE_ARRAY_MAX unless the the list is full. + * ICAL_RECURRENCE_ARRAY_MAX unless the the list is full. */ - short by_second[61]; - short by_minute[61]; - short by_hour[25]; - short by_day[8]; /* Encoded value, see below */ - short by_month_day[32]; - short by_year_day[367]; - short by_week_no[54]; - short by_month[13]; - short by_set_pos[367]; + short by_second[ICAL_BY_SECOND_SIZE]; + short by_minute[ICAL_BY_MINUTE_SIZE]; + short by_hour[ICAL_BY_HOUR_SIZE]; + short by_day[ICAL_BY_DAY_SIZE]; /* Encoded value, see below */ + short by_month_day[ICAL_BY_MONTHDAY_SIZE]; + short by_year_day[ ICAL_BY_YEARDAY_SIZE]; + short by_week_no[ICAL_BY_WEEKNO_SIZE]; + short by_month[ICAL_BY_MONTH_SIZE]; + short by_set_pos[ICAL_BY_SETPOS_SIZE]; }; void icalrecurrencetype_clear(struct icalrecurrencetype *r); -/* The 'day' element of icalrecurrencetype_weekday is encoded to allow +/* The 'day' element of the by_day array is encoded to allow representation of both the day of the week ( Monday, Tueday), but also the Nth day of the week ( First tuesday of the month, last thursday of the year) These routines decode the day values */ @@ -131,6 +141,13 @@ struct icaltimetype icalrecurrencetype_next_occurance( typedef void icalrecur_iterator; void icalrecurrencetype_test(); +/*********************************************************************** + * Recurrance rule parser +**********************************************************************/ + +struct icalrecurrencetype icalrecurrencetype_from_string(const char* str); +char* icalrecurrencetype_as_string(struct icalrecurrencetype *recur); + /********** recurrence routines ********************/ @@ -142,5 +159,10 @@ int icalrecur_iterator_count(icalrecur_iterator*); void icalrecur_iterator_free(icalrecur_iterator*); +/* Fills array up with at most 'count' time_t values, each + representing an occurrence time in seconds past the POSIX epoch */ +int icalrecur_expand_recurrence(char* rule, time_t start, + int count, time_t* array); + #endif diff --git a/libical/src/libical/icalvalue.h.in b/libical/src/libical/icalvalue.h.in index 7ad2c3e0f3..6e7770346a 100644 --- a/libical/src/libical/icalvalue.h.in +++ b/libical/src/libical/icalvalue.h.in @@ -4,7 +4,7 @@ CREATOR: eric 20 March 1999 - $Id: icalvalue.h.in,v 1.1 2000/12/11 22:06:03 federico Exp $ + $Id: icalvalue.h.in,v 1.1.1.2 2001/01/23 19:20:40 jpr Exp $ $Locker: $ diff --git a/libical/src/libical/sspm.h b/libical/src/libical/sspm.h index 417f83eefd..864a23a36f 100644 --- a/libical/src/libical/sspm.h +++ b/libical/src/libical/sspm.h @@ -116,7 +116,7 @@ struct sspm_action_map { }; char* sspm_major_type_string(enum sspm_major_type type); -char* sspm_minor_type_string(enum sspm_major_type type); +char* sspm_minor_type_string(enum sspm_minor_type type); char* sspm_encoding_string(enum sspm_encoding type); int sspm_parse_mime(struct sspm_part *parts, diff --git a/libical/src/libicalss/icalclassify.c b/libical/src/libicalss/icalclassify.c index e0ee710544..89761d8120 100644 --- a/libical/src/libicalss/icalclassify.c +++ b/libical/src/libicalss/icalclassify.c @@ -122,7 +122,7 @@ icalparameter_partstat icalclassify_find_attendee(icalcomponent *c, { icalproperty *p; char* lattendee = icalclassify_lowercase(attendee); - char* upn = index(lattendee,':'); + char* upn = strchr(lattendee,':'); icalcomponent *inner = icalcomponent_get_first_real_component(c); for(p = icalcomponent_get_first_property(inner,ICAL_ATTENDEE_PROPERTY); @@ -131,7 +131,7 @@ icalparameter_partstat icalclassify_find_attendee(icalcomponent *c, { const char* this_attendee = icalclassify_lowercase(icalproperty_get_attendee(p)); - char* this_upn = index(this_attendee,':'); + char* this_upn = strchr(this_attendee,':'); if(strcmp(this_upn,upn)==0){ diff --git a/libical/src/libicalss/icalcstp.c b/libical/src/libicalss/icalcstp.c index 2c86ddcc2c..53ee7bdeef 100644 --- a/libical/src/libicalss/icalcstp.c +++ b/libical/src/libicalss/icalcstp.c @@ -34,6 +34,8 @@ #include <sys/socket.h> /* For send(), others. */ #include <unistd.h> /* For alarm */ #include <errno.h> +#include <stdlib.h> /* for malloc */ +#include <string.h> enum cstps_state { NO_STATE, @@ -199,16 +201,43 @@ int line_is_response(char* line); int line_is_endofdata(char* line); int line_is_mime(char* line); -icalerrorenum prep_abort(struct icalcstps_impl* impl, char* data); -icalerrorenum prep_authenticate(struct icalcstps_impl* impl, char* data); -icalerrorenum prep_capability(struct icalcstps_impl* impl, char* data); -icalerrorenum prep_calidexpand(struct icalcstps_impl* impl, char* data); -icalerrorenum prep_continue(struct icalcstps_impl* impl, char* data); -icalerrorenum prep_disconnect(struct icalcstps_impl* impl, char* data); -icalerrorenum prep_identify(struct icalcstps_impl* impl, char* data); -icalerrorenum prep_starttls(struct icalcstps_impl* impl, char* data); -icalerrorenum prep_upnexpand(struct icalcstps_impl* impl, char* data); -icalerrorenum prep_sendata(struct icalcstps_impl* impl, char* data); +icalerrorenum prep_abort(struct icalcstps_impl* impl, char* data) +{ + return ICAL_NO_ERROR; +} +icalerrorenum prep_authenticate(struct icalcstps_impl* impl, char* data) +{ return ICAL_NO_ERROR; +} +icalerrorenum prep_capability(struct icalcstps_impl* impl, char* data) +{ return ICAL_NO_ERROR; +} +icalerrorenum prep_calidexpand(struct icalcstps_impl* impl, char* data) +{ + return ICAL_NO_ERROR; +} +icalerrorenum prep_continue(struct icalcstps_impl* impl, char* data) +{ + return ICAL_NO_ERROR; +} +icalerrorenum prep_disconnect(struct icalcstps_impl* impl, char* data) +{ + return ICAL_NO_ERROR; +} +icalerrorenum prep_identify(struct icalcstps_impl* impl, char* data) +{ + return ICAL_NO_ERROR; +} +icalerrorenum prep_starttls(struct icalcstps_impl* impl, char* data) +{ + return ICAL_NO_ERROR; +} +icalerrorenum prep_upnexpand(struct icalcstps_impl* impl, char* data) +{ + return ICAL_NO_ERROR; +} +icalerrorenum prep_sendata(struct icalcstps_impl* impl, char* data) +{ return ICAL_NO_ERROR; +} char* icalcstps_process_incoming(icalcstps* cstp, char* input) { @@ -227,7 +256,7 @@ char* icalcstps_process_incoming(icalcstps* cstp, char* input) return 0; } - i = (char*)index(" ",input_cpy); + i = (char*)strstr(" ",input_cpy); cmd_or_resp = input_cpy; @@ -266,7 +295,7 @@ char* icalcstps_process_incoming(icalcstps* cstp, char* input) error = prep_sendata(impl,data); } - + return 0; } /* Read data until we get a end of data marker */ @@ -308,11 +337,13 @@ void* icalcstpc_free(icalcstpc* cstpc); /* Get the next string to send to the server */ char* icalcstpc_next_output(icalcstpc* cstp) { + return 0; } /* process the next string to send to the server */ int icalcstpc_next_input(icalcstpc* cstp) { + return 0; } /* After icalcstpc_next_input returns a 0, there are responses @@ -330,45 +361,54 @@ icalerrorenum icalcstpc_abort(icalcstpc* cstp) impl->next_output = "ABORT"; + return ICAL_NO_ERROR; } icalerrorenum icalcstpc_authenticate(icalcstpc* cstp, char* mechanism, char* data, char* f(char*)) { + return ICAL_NO_ERROR; } icalerrorenum icalcstpc_capability(icalcstpc* cstp) { -} + return ICAL_NO_ERROR;} icalerrorenum icalcstpc_calidexpand(icalcstpc* cstp,char* calid) { + return ICAL_NO_ERROR; } icalerrorenum icalcstpc_continue(icalcstpc* cstp, unsigned int time) { + return ICAL_NO_ERROR; } icalerrorenum icalcstpc_disconnect(icalcstpc* cstp) { + return ICAL_NO_ERROR; } icalerrorenum icalcstpc_identify(icalcstpc* cstp, char* id) { + return ICAL_NO_ERROR; } icalerrorenum icalcstpc_starttls(icalcstpc* cstp, char* command, char* data, char * f(char*)) { + return ICAL_NO_ERROR; } icalerrorenum icalcstpc_upnexpand(icalcstpc* cstp,char* calid) { + return ICAL_NO_ERROR; } icalerrorenum icalcstpc_sendata(icalcstpc* cstp, unsigned int time, icalcomponent *comp) { + return ICAL_NO_ERROR; } diff --git a/libical/src/libicalss/icaldirset.c b/libical/src/libicalss/icaldirset.c index b377d54571..78b2373219 100644 --- a/libical/src/libicalss/icaldirset.c +++ b/libical/src/libicalss/icaldirset.c @@ -712,10 +712,14 @@ icalcomponent* icaldirset_get_next_component(icaldirset* store) /* If there is a gauge defined and the component does not pass the gauge, skip the rest of the loop */ + +#if 0 /* HACK */ if (impl->gauge != 0 && icalgauge_test(c,impl->gauge) == 0){ continue; } - +#else + assert(0); /* icalgauge_test needs to be fixed */ +#endif /* Either there is no gauge, or the component passed the gauge, so return it*/ diff --git a/libical/src/libicalss/icalfileset.c b/libical/src/libicalss/icalfileset.c index a7527ff3e0..52dbc0beda 100644 --- a/libical/src/libicalss/icalfileset.c +++ b/libical/src/libicalss/icalfileset.c @@ -31,6 +31,7 @@ #endif #include "icalfileset.h" +#include "icalgauge.h" #include <errno.h> #include <limits.h> /* For PATH_MAX */ #include <sys/stat.h> /* for stat */ @@ -39,43 +40,44 @@ #include <string.h> #include <fcntl.h> /* for fcntl */ #include <unistd.h> /* for fcntl */ - #include "icalfilesetimpl.h" +extern int errno; + int icalfileset_lock(icalfileset *cluster); int icalfileset_unlock(icalfileset *cluster); +icalerrorenum icalfileset_read_file(icalfileset* cluster, mode_t mode); +int icalfileset_filesize(icalfileset* cluster); icalerrorenum icalfileset_create_cluster(const char *path); icalfileset* icalfileset_new_impl() { struct icalfileset_impl* impl; - + if ( ( impl = (struct icalfileset_impl*) malloc(sizeof(struct icalfileset_impl))) == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); errno = ENOMEM; return 0; } - + + memset(impl,0,sizeof(struct icalfileset_impl)); + strcpy(impl->id,ICALFILESET_ID); - + return impl; } -char* read_from_file(char *s, size_t size, void *d) + +icalfileset* icalfileset_new(const char* path) { - char *c = fgets(s,size, (FILE*)d); - return c; + return icalfileset_new_open(path, O_RDWR|O_CREAT, 0664); } -icalfileset* icalfileset_new(const char* path) +icalfileset* icalfileset_new_open(const char* path, int flags, mode_t mode) { struct icalfileset_impl *impl = icalfileset_new_impl(); - struct stat sbuf; - int createclusterfile = 0; - icalerrorenum error = ICAL_NO_ERROR; - icalparser *parser; struct icaltimetype tt; off_t cluster_file_size; @@ -88,97 +90,131 @@ icalfileset* icalfileset_new(const char* path) return 0; } - /*impl->path = strdup(path); icalfileset_load does this */ - impl->changed = 0; + impl->path = strdup(path); - impl->cluster = 0; - - impl->path = 0; - impl->stream = 0; + cluster_file_size = icalfileset_filesize(impl); - /* Check if the path already exists and if it is a regular file*/ - if (stat(path,&sbuf) != 0){ - - /* A file by the given name does not exist, or there was - another error */ - cluster_file_size = 0; - if (errno == ENOENT) { - /* It was because the file does not exist */ - createclusterfile = 1; - } else { - /* It was because of another error */ - icalerror_set_errno(ICAL_FILE_ERROR); + if(cluster_file_size < 0){ + icalfileset_free(impl); + return 0; + } + + impl->fd = open(impl->path,flags, mode); + + if (impl->fd < 0){ + icalerror_set_errno(ICAL_FILE_ERROR); + icalfileset_free(impl); + return 0; + } + + icalfileset_lock(impl); + + if(cluster_file_size > 0 ){ + icalerrorenum error; + if((error = icalfileset_read_file(impl,mode))!= ICAL_NO_ERROR){ + icalfileset_free(impl); return 0; } - } else { - /* A file by the given name exists, but is it a regular file */ - - if (!S_ISREG(sbuf.st_mode)){ - /* Nope, not a directory */ - icalerror_set_errno(ICAL_FILE_ERROR); - return 0; - } else { - /* Lets assume that it is a file of the right type */ - cluster_file_size = sbuf.st_size; - createclusterfile = 0; - } } + + if(impl->cluster == 0){ + impl->cluster = icalcomponent_new(ICAL_XROOT_COMPONENT); + } - /* if cluster does not already exist, create it */ + return impl; +} + +char* icalfileset_read_from_file(char *s, size_t size, void *d) +{ - if (createclusterfile == 1) { - error = icalfileset_create_cluster(path); + char* p = s; + int fd = (int)d; - if (error != ICAL_NO_ERROR){ - icalerror_set_errno(error); - return 0; - } - } + /* Simulate fgets -- read single characters and stop at '\n' */ - impl->path = (char*)strdup(path); + for(p=s; p<s+size-1;p++){ + + if(read(fd,p,1) != 1 || *p=='\n'){ + break; + } + } - errno = 0; - impl->stream = fopen(impl->path,"r"); + *(++p) = '\0'; - if (impl->stream ==0 || errno != 0){ - impl->cluster = 0; - icalerror_set_errno(ICAL_FILE_ERROR); /* Redundant, actually */ + if(*s == 0){ return 0; + } else { + return s; } - icalfileset_lock(impl); - - if(cluster_file_size > 0){ - parser = icalparser_new(); - icalparser_set_gen_data(parser,impl->stream); - impl->cluster = icalparser_parse(parser,read_from_file); - icalparser_free(parser); +} - if (icalcomponent_isa(impl->cluster) != ICAL_XROOT_COMPONENT){ - /* The parser got a single component, so it did not put it in - an XROOT. */ - icalcomponent *cl = impl->cluster; - impl->cluster = icalcomponent_new(ICAL_XROOT_COMPONENT); - icalcomponent_add_component(impl->cluster,cl); - } - } else { +icalerrorenum icalfileset_read_file(icalfileset* cluster,mode_t mode) +{ - impl->cluster = icalcomponent_new(ICAL_XROOT_COMPONENT); - } + icalparser *parser; + int fd; + + struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; + + parser = icalparser_new(); + icalparser_set_gen_data(parser,(void*)impl->fd); + impl->cluster = icalparser_parse(parser,icalfileset_read_from_file); + icalparser_free(parser); - if (impl->cluster == 0){ + if (impl->cluster == 0 || icalerrno != ICAL_NO_ERROR){ icalerror_set_errno(ICAL_PARSE_ERROR); - return 0; + return ICAL_PARSE_ERROR; } - - if (error != ICAL_NO_ERROR){ - return 0; + + if (icalcomponent_isa(impl->cluster) != ICAL_XROOT_COMPONENT){ + /* The parser got a single component, so it did not put it in + an XROOT. */ + icalcomponent *cl = impl->cluster; + impl->cluster = icalcomponent_new(ICAL_XROOT_COMPONENT); + icalcomponent_add_component(impl->cluster,cl); } - - return impl; + + return ICAL_NO_ERROR; + } + +int icalfileset_filesize(icalfileset* cluster) +{ + struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; + int cluster_file_size; + struct stat sbuf; + + if (stat(impl->path,&sbuf) != 0){ + /* A file by the given name does not exist, or there was + another error */ + cluster_file_size = 0; + if (errno == ENOENT) { + /* It was because the file does not exist */ + return 0; + } else { + /* It was because of another error */ + icalerror_set_errno(ICAL_FILE_ERROR); + return -1; + } + } else { + /* A file by the given name exists, but is it a regular file? */ + + if (!S_ISREG(sbuf.st_mode)){ + /* Nope, not a regular file */ + icalerror_set_errno(ICAL_FILE_ERROR); + return -1; + } else { + /* Lets assume that it is a file of the right type */ + return sbuf.st_size; + } + } + + /*return -1; not reached*/ +} + void icalfileset_free(icalfileset* cluster) { struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; @@ -191,17 +227,17 @@ void icalfileset_free(icalfileset* cluster) impl->cluster=0; } + if(impl->fd > 0){ + icalfileset_unlock(impl); + close(impl->fd); + impl->fd = -1; + } + if(impl->path != 0){ free(impl->path); impl->path = 0; } - if(impl->stream != 0){ - icalfileset_unlock(impl); - fclose(impl->stream); - impl->stream = 0; - } - free(impl); } @@ -218,83 +254,69 @@ int icalfileset_lock(icalfileset *cluster) { struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; struct flock lock; - int fd; - - icalerror_check_arg_rz((impl->stream!=0),"impl->stream"); - - fd = fileno(impl->stream); + int rtrn; + icalerror_check_arg_rz((impl->fd>0),"impl->fd"); + errno = 0; lock.l_type = F_WRLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */ lock.l_start = 0; /* byte offset relative to l_whence */ lock.l_whence = SEEK_SET; /* SEEK_SET, SEEK_CUR, SEEK_END */ lock.l_len = 0; /* #bytes (0 means to EOF) */ - return (fcntl(fd, F_SETLKW, &lock)); + rtrn = fcntl(impl->fd, F_SETLKW, &lock); + + return rtrn; } int icalfileset_unlock(icalfileset *cluster) { struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; - int fd; struct flock lock; - icalerror_check_arg_rz((impl->stream!=0),"impl->stream"); - - fd = fileno(impl->stream); + icalerror_check_arg_rz((impl->fd>0),"impl->fd"); lock.l_type = F_WRLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */ lock.l_start = 0; /* byte offset relative to l_whence */ lock.l_whence = SEEK_SET; /* SEEK_SET, SEEK_CUR, SEEK_END */ lock.l_len = 0; /* #bytes (0 means to EOF) */ - return (fcntl(fd, F_UNLCK, &lock)); + return (fcntl(impl->fd, F_UNLCK, &lock)); } -icalerrorenum icalfileset_create_cluster(const char *path) -{ - - FILE* f; - - icalerror_clear_errno(); - - f = fopen(path,"w"); - - if (f == 0){ - icalerror_set_errno(ICAL_FILE_ERROR); - return ICAL_FILE_ERROR; - } - - - /* This used to write data to the file... */ - - - fclose(f); - - return ICAL_NO_ERROR; -} +#ifdef ICAL_SAFESAVES +int icalfileset_safe_saves=1; +#else +int icalfileset_safe_saves=0; +#endif icalerrorenum icalfileset_commit(icalfileset* cluster) { - FILE *f; - char tmp[PATH_MAX]; /* HACK Buffer overflow potential */ + char tmp[PATH_MAX]; char *str; icalcomponent *c; + off_t write_size=0; struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; - - icalerror_check_arg_re((impl!=0),"cluster",ICAL_BADARG_ERROR); + + icalerror_check_arg_re((impl!=0),"cluster",ICAL_BADARG_ERROR); + + icalerror_check_arg_re((impl->fd>0),"impl->fd is invalid", + ICAL_INTERNAL_ERROR) ; if (impl->changed == 0 ){ return ICAL_NO_ERROR; } -#ifdef ICAL_SAFESAVES - snprintf(tmp,PATH_MAX,"%s-tmp",impl->path); -#else - strcpy(tmp,impl->path); -#endif - - if ( (f = fopen(tmp,"w")) < 0 ){ + if(icalfileset_safe_saves == 1){ + snprintf(tmp,PATH_MAX,"cp %s %s.bak",impl->path,impl->path); + + if(system(tmp) < 0){ + icalerror_set_errno(ICAL_FILE_ERROR); + return ICAL_FILE_ERROR; + } + } + + if(lseek(impl->fd,SEEK_SET,0) < 0){ icalerror_set_errno(ICAL_FILE_ERROR); return ICAL_FILE_ERROR; } @@ -302,21 +324,26 @@ icalerrorenum icalfileset_commit(icalfileset* cluster) for(c = icalcomponent_get_first_component(impl->cluster,ICAL_ANY_COMPONENT); c != 0; c = icalcomponent_get_next_component(impl->cluster,ICAL_ANY_COMPONENT)){ + int sz; str = icalcomponent_as_ical_string(c); - if ( fwrite(str,sizeof(char),strlen(str),f) < strlen(str)){ - fclose(f); + sz=write(impl->fd,str,strlen(str)); + + if ( sz != strlen(str)){ + perror("write"); + icalerror_set_errno(ICAL_FILE_ERROR); return ICAL_FILE_ERROR; } + + write_size += sz; } - fclose(f); impl->changed = 0; - -#ifdef ICAL_SAFESAVES - rename(tmp,impl->path); /* HACK, should check for error here */ -#endif + + if(ftruncate(impl->fd,write_size) < 0){ + return ICAL_FILE_ERROR; + } return ICAL_NO_ERROR; @@ -333,18 +360,18 @@ void icalfileset_mark(icalfileset* cluster){ } icalcomponent* icalfileset_get_component(icalfileset* cluster){ - struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; + struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; - icalerror_check_arg_re((impl!=0),"cluster",ICAL_BADARG_ERROR); + icalerror_check_arg_re((impl!=0),"cluster",ICAL_BADARG_ERROR); - return impl->cluster; + return impl->cluster; } /* manipulate the components in the cluster */ icalerrorenum icalfileset_add_component(icalfileset *cluster, - icalcomponent* child) + icalcomponent* child) { struct icalfileset_impl* impl = (struct icalfileset_impl*)cluster; @@ -360,7 +387,7 @@ icalerrorenum icalfileset_add_component(icalfileset *cluster, } icalerrorenum icalfileset_remove_component(icalfileset *cluster, - icalcomponent* child) + icalcomponent* child) { struct icalfileset_impl* impl = (struct icalfileset_impl*)cluster; @@ -387,15 +414,23 @@ int icalfileset_count_components(icalfileset *cluster, return icalcomponent_count_components(impl->cluster,kind); } -icalerrorenum icalfileset_select(icalfileset* cluster, icalcomponent* gauge) +icalerrorenum icalfileset_select(icalfileset* set, icalgauge* gauge) { - assert(0); /* HACK, not implemented */ + struct icalfileset_impl* impl = (struct icalfileset_impl*)set; + + icalerror_check_arg_re(gauge!=0,"guage",ICAL_BADARG_ERROR); + + impl->gauge = gauge; + return ICAL_NO_ERROR; } -void icalfileset_clear(icalfileset* cluster) +void icalfileset_clear(icalfileset* gauge) { - assert(0); /* HACK, not implemented */ + struct icalfileset_impl* impl = (struct icalfileset_impl*)gauge; + + impl->gauge = 0; + } icalcomponent* icalfileset_fetch(icalfileset* store,const char* uid) @@ -534,7 +569,7 @@ icalcomponent* icalfileset_fetch_match(icalfileset* set, icalcomponent *comp) icalerrorenum icalfileset_modify(icalfileset* store, icalcomponent *old, - icalcomponent *new) + icalcomponent *new) { assert(0); /* HACK, not implemented */ return ICAL_NO_ERROR; @@ -555,18 +590,49 @@ icalcomponent* icalfileset_get_current_component (icalfileset* cluster) icalcomponent* icalfileset_get_first_component(icalfileset* cluster) { struct icalfileset_impl* impl = (struct icalfileset_impl*)cluster; + icalcomponent *c=0; icalerror_check_arg_rz((cluster!=0),"cluster"); - return icalcomponent_get_first_component(impl->cluster,ICAL_ANY_COMPONENT); + do { + if (c == 0){ + c = icalcomponent_get_first_component(impl->cluster, + ICAL_ANY_COMPONENT); + } else { + c = icalcomponent_get_next_component(impl->cluster, + ICAL_ANY_COMPONENT); + } + + if(c != 0 && (impl->gauge == 0 || + icalgauge_compare(impl->gauge,c) == 1)){ + return c; + } + + } while(c != 0); + + + return 0; } icalcomponent* icalfileset_get_next_component(icalfileset* cluster) { struct icalfileset_impl* impl = (struct icalfileset_impl*)cluster; + icalcomponent *c; icalerror_check_arg_rz((cluster!=0),"cluster"); + + do { + c = icalcomponent_get_next_component(impl->cluster, + ICAL_ANY_COMPONENT); - return icalcomponent_get_next_component(impl->cluster,ICAL_ANY_COMPONENT); + if(c != 0 && (impl->gauge == 0 || + icalgauge_compare(impl->gauge,c) == 1)){ + return c; + } + + } while(c != 0); + + + return 0; } diff --git a/libical/src/libicalss/icalfileset.h b/libical/src/libicalss/icalfileset.h index 4430f1dc74..3b4b87c34d 100644 --- a/libical/src/libicalss/icalfileset.h +++ b/libical/src/libicalss/icalfileset.h @@ -30,6 +30,12 @@ #define ICALFILESET_H #include "ical.h" +#include "icalgauge.h" +#include <sys/types.h> /* For open() flags and mode */ +#include <sys/stat.h> /* For open() flags and mode */ +#include <fcntl.h> /* For open() flags and mode */ + +extern int icalfileset_safe_saves; typedef void icalfileset; @@ -41,6 +47,11 @@ typedef void icalfileset; icalfileset* icalfileset_new(const char* path); + +/* Like _new, but takes open() flags for opening the file */ +icalfileset* icalfileset_new_open(const char* path, + int flags, mode_t mode); + void icalfileset_free(icalfileset* cluster); const char* icalfileset_path(icalfileset* cluster); @@ -61,7 +72,7 @@ int icalfileset_count_components(icalfileset* cluster, /* Restrict the component returned by icalfileset_first, _next to those that pass the gauge. _clear removes the gauge */ -icalerrorenum icalfileset_select(icalfileset* store, icalcomponent* gauge); +icalerrorenum icalfileset_select(icalfileset* store, icalgauge* gauge); void icalfileset_clear(icalfileset* store); /* Get and search for a component by uid */ diff --git a/libical/src/libicalss/icalfilesetimpl.h b/libical/src/libicalss/icalfilesetimpl.h index 767dceeadd..fcd3415121 100644 --- a/libical/src/libicalss/icalfilesetimpl.h +++ b/libical/src/libicalss/icalfilesetimpl.h @@ -30,6 +30,8 @@ #include "config.h" #endif +#include "icalgauge.h" + /* This definition is in its own file so it can be kept out of the main header file, but used by "friend classes" like icaldirset*/ @@ -37,10 +39,11 @@ struct icalfileset_impl { - char id[5]; /*fset*/ - char *path; - icalcomponent* cluster; - int changed; - FILE* stream; + char id[5]; /*fset*/ + char *path; + icalcomponent* cluster; + icalgauge* gauge; + int changed; + int fd; /* file descriptor */ }; diff --git a/libical/src/libicalss/icalgauge.c b/libical/src/libicalss/icalgauge.c index 0bbcd20bfc..b958ecfc9d 100644 --- a/libical/src/libicalss/icalgauge.c +++ b/libical/src/libicalss/icalgauge.c @@ -31,7 +31,6 @@ #include "icalgaugeimpl.h" #include <stdlib.h> - extern char* input_buffer; extern char* input_buffer_p; int ssparse(void); @@ -50,9 +49,9 @@ icalgauge* icalgauge_new_from_sql(char* sql) return 0; } - impl->select = icalcomponent_new(ICAL_XROOT_COMPONENT); - impl->from = icalcomponent_new(ICAL_XROOT_COMPONENT); - impl->where = icalcomponent_new(ICAL_XROOT_COMPONENT); + impl->select = pvl_newlist(); + impl->from = pvl_newlist(); + impl->where = pvl_newlist(); icalss_yy_gauge = impl; @@ -65,6 +64,38 @@ icalgauge* icalgauge_new_from_sql(char* sql) void icalgauge_free(icalgauge* gauge) { + struct icalgauge_impl *impl = (struct icalgauge_impl*)gauge; + struct icalgauge_where *w; + + assert(impl->select != 0); + assert(impl->where != 0); + assert(impl->from != 0); + + if(impl->select){ + while( (w=pvl_pop(impl->select)) != 0){ + if(w->value != 0){ + free(w->value); + } + free(w); + } + pvl_free(impl->select); + } + + if(impl->where){ + while( (w=pvl_pop(impl->where)) != 0){ + + if(w->value != 0){ + free(w->value); + } + free(w); + } + pvl_free(impl->where); + } + + if(impl->from){ + pvl_free(impl->from); + } + } /* Convert a VQUERY component into a gauge */ @@ -105,7 +136,7 @@ icalcomponent* icalgauge_make_gauge(icalcomponent* query); */ -int icalgauge_test_recurse(icalcomponent* comp, icalcomponent* gauge) +int icalgauge_compare_recurse(icalcomponent* comp, icalcomponent* gauge) { int pass = 1,localpass = 0; icalproperty *p; @@ -207,7 +238,7 @@ int icalgauge_test_recurse(icalcomponent* comp, icalcomponent* gauge) } if(child !=0){ - localpass = icalgauge_test_recurse(child,subgauge); + localpass = icalgauge_compare_recurse(child,subgauge); pass = pass && localpass; } else { pass = 0; @@ -217,29 +248,200 @@ int icalgauge_test_recurse(icalcomponent* comp, icalcomponent* gauge) return pass; } -/* guagecontainer is an XROOT component that holds several gauges. The - results of comparing against these gauges are ORed together in this - routine */ -int icalgauge_test(icalcomponent* comp, - icalcomponent* gaugecontainer) + +int icalgauge_compare(icalgauge* gauge,icalcomponent* comp) { - int pass = 0; - icalcomponent *gauge; + + struct icalgauge_impl *impl = (struct icalgauge_impl*)gauge; + icalcomponent *inner; + int local_pass = 0; + int last_clause = 1, this_clause = 1; + pvl_elem e; icalerror_check_arg_rz( (comp!=0), "comp"); icalerror_check_arg_rz( (gauge!=0), "gauge"); - for(gauge = icalcomponent_get_first_component(gaugecontainer, - ICAL_ANY_COMPONENT); - gauge != 0; - gauge = icalcomponent_get_next_component(gaugecontainer, - ICAL_ANY_COMPONENT)){ + inner = icalcomponent_get_first_real_component(comp); + + if(inner == 0){ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return 0; + } + + + /* Check that this component is one of the FROM types */ + local_pass = 0; + for(e = pvl_head(impl->from);e!=0;e=pvl_next(e)){ + icalcomponent_kind k = (icalcomponent_kind)pvl_data(e); - pass += icalgauge_test_recurse(comp, gauge); + if(k == icalcomponent_isa(inner)){ + local_pass=1; + } + } + + if(local_pass == 0){ + return 0; + } + + + /* Check each where clause against the component */ + for(e = pvl_head(impl->where);e!=0;e=pvl_next(e)){ + struct icalgauge_where *w = pvl_data(e); + icalcomponent *sub_comp; + icalvalue *v; + icalproperty *prop; + icalvalue_kind vk; + + if(w->prop == ICAL_NO_PROPERTY || w->value == 0){ + icalerror_set_errno(ICAL_INTERNAL_ERROR); + return 0; + } + + /* First, create a value from the gauge */ + vk = icalenum_property_kind_to_value_kind(w->prop); + + if(vk == ICAL_NO_VALUE){ + icalerror_set_errno(ICAL_INTERNAL_ERROR); + return 0; + } + + v = icalvalue_new_from_string(vk,w->value); + + if (v == 0){ + /* Keep error set by icalvalue_from-string*/ + return 0; + } + + /* Now find the corresponding property in the component, + descending into a sub-component if necessary */ + + if(w->comp == ICAL_NO_COMPONENT){ + sub_comp = inner; + } else { + sub_comp = icalcomponent_get_first_component(inner,w->comp); + if(sub_comp == 0){ + return 0; + } + } + + this_clause = 0; + local_pass = 0; + for(prop = icalcomponent_get_first_property(sub_comp,w->prop); + prop != 0; + prop = icalcomponent_get_next_property(sub_comp,w->prop)){ + icalvalue* prop_value; + icalgaugecompare relation; + + prop_value = icalproperty_get_value(prop); + + relation = (icalgaugecompare)icalvalue_compare(prop_value,v); + + if (relation == w->compare){ + local_pass++; + } else if (w->compare == ICALGAUGECOMPARE_LESSEQUAL && + ( relation == ICALGAUGECOMPARE_LESS || + relation == ICALGAUGECOMPARE_EQUAL)) { + local_pass++; + } else if (w->compare == ICALGAUGECOMPARE_GREATEREQUAL && + ( relation == ICALGAUGECOMPARE_GREATER || + relation == ICALGAUGECOMPARE_EQUAL)) { + local_pass++; + } else if (w->compare == ICALGAUGECOMPARE_NOTEQUAL && + ( relation == ICALGAUGECOMPARE_GREATER || + relation == ICALGAUGECOMPARE_LESS)) { + local_pass++; + } else { + local_pass = 0; + } + } + + this_clause = local_pass > 0 ? 1 : 0; + + /* Now look at the logic operator for this clause to see how + the value should be merge with the previous clause */ + + if(w->logic == ICALGAUGELOGIC_AND){ + last_clause = this_clause && last_clause; + } else if(w->logic == ICALGAUGELOGIC_AND) { + last_clause = this_clause || last_clause; + } else { + last_clause = this_clause; + } } - return pass>0; + return last_clause; } +void icalgauge_dump(icalcomponent* gauge) +{ + + pvl_elem *p; + struct icalgauge_impl *impl = (struct icalgauge_impl*)gauge; + + + printf("--- Select ---\n"); + for(p = pvl_head(impl->select);p!=0;p=pvl_next(p)){ + struct icalgauge_where *w = pvl_data(p); + + if(w->comp != ICAL_NO_COMPONENT){ + printf("%s ",icalenum_component_kind_to_string(w->comp)); + } + + if(w->prop != ICAL_NO_PROPERTY){ + printf("%s ",icalenum_property_kind_to_string(w->prop)); + } + + if (w->compare != ICALGAUGECOMPARE_NONE){ + printf("%d ",w->compare); + } + + + if (w->value!=0){ + printf("%s",w->value); + } + + + printf("\n"); + } + + printf("--- From ---\n"); + for(p = pvl_head(impl->from);p!=0;p=pvl_next(p)){ + icalcomponent_kind k = (icalcomponent_kind)pvl_data(p); + + printf("%s\n",icalenum_component_kind_to_string(k)); + } + + printf("--- Where ---\n"); + for(p = pvl_head(impl->where);p!=0;p=pvl_next(p)){ + struct icalgauge_where *w = pvl_data(p); + + if(w->logic != ICALGAUGELOGIC_NONE){ + printf("%d ",w->logic); + } + + if(w->comp != ICAL_NO_COMPONENT){ + printf("%s ",icalenum_component_kind_to_string(w->comp)); + } + + if(w->prop != ICAL_NO_PROPERTY){ + printf("%s ",icalenum_property_kind_to_string(w->prop)); + } + + if (w->compare != ICALGAUGECOMPARE_NONE){ + printf("%d ",w->compare); + } + + + if (w->value!=0){ + printf("%s",w->value); + } + + + printf("\n"); + } + + +} + diff --git a/libical/src/libicalss/icalgauge.h b/libical/src/libicalss/icalgauge.h index 2fbb3aab8c..1caf0ac7d1 100644 --- a/libical/src/libicalss/icalgauge.h +++ b/libical/src/libicalss/icalgauge.h @@ -37,7 +37,15 @@ void icalgauge_free(icalgauge* gauge); char* icalgauge_as_sql(icalcomponent* gauge); -int icalgauge_test(icalcomponent* comp, icalcomponent* gaugecontainer); +void icalgauge_dump(icalcomponent* gauge); +/* Return true is comp matches the gauge. The component must be in + cannonical form -- a VCALENDAR with one VEVENT, VTODO or VJOURNAL + sub component */ +int icalgauge_compare(icalgauge* g, icalcomponent* comp); + +/* Clone the component, but only return the properties specified in + the gauge */ +icalcomponent* icalgauge_new_clone(icalgauge* g, icalcomponent* comp); #endif /* ICALGAUGE_H*/ diff --git a/libical/src/libicalss/icalgaugeimpl.h b/libical/src/libicalss/icalgaugeimpl.h index 927d46ef0a..73a2813242 100644 --- a/libical/src/libicalss/icalgaugeimpl.h +++ b/libical/src/libicalss/icalgaugeimpl.h @@ -20,20 +20,44 @@ The Mozilla Public License Version 1.0. You may obtain a copy of the License at http://www.mozilla.org/MPL/ - The Original Code is eric. The Initial Developer of the Original - Code is Eric Busboom - - ======================================================================*/ #include "ical.h" +#include "pvl.h" + +typedef enum icalgaugecompare { + ICALGAUGECOMPARE_EQUAL=ICAL_XLICCOMPARETYPE_EQUAL, + ICALGAUGECOMPARE_LESS=ICAL_XLICCOMPARETYPE_LESS, + ICALGAUGECOMPARE_LESSEQUAL=ICAL_XLICCOMPARETYPE_LESSEQUAL, + ICALGAUGECOMPARE_GREATER=ICAL_XLICCOMPARETYPE_GREATER, + ICALGAUGECOMPARE_GREATEREQUAL=ICAL_XLICCOMPARETYPE_GREATEREQUAL, + ICALGAUGECOMPARE_NOTEQUAL=ICAL_XLICCOMPARETYPE_NOTEQUAL, + ICALGAUGECOMPARE_REGEX=ICAL_XLICCOMPARETYPE_REGEX, + ICALGAUGECOMPARE_NONE=0 +} icalgaugecompare; + +typedef enum icalgaugelogic { + ICALGAUGELOGIC_NONE, + ICALGAUGELOGIC_AND, + ICALGAUGELOGIC_OR +} icalgaugelogic; + + +struct icalgauge_where { + icalgaugelogic logic; + icalcomponent_kind comp; + icalproperty_kind prop; + icalgaugecompare compare; + char* value; +}; + struct icalgauge_impl { - icalcomponent* select; - icalcomponent* from; - icalcomponent* where; + pvl_list select; /*Of icalgaugecompare, using only prop and comp fields*/ + pvl_list from; /* List of component_kinds, as integers */ + pvl_list where; /* List of icalgaugecompare */ }; diff --git a/libical/src/libicalss/icalmessage.c b/libical/src/libicalss/icalmessage.c index 4f075ed6bb..e1e8d8015c 100644 --- a/libical/src/libicalss/icalmessage.c +++ b/libical/src/libicalss/icalmessage.c @@ -43,17 +43,17 @@ icalcomponent* icalmessage_get_inner(icalcomponent* comp) char* lowercase(const char* str) { char* p = 0; - char* new = icalmemory_strdup(str); + char* n = icalmemory_strdup(str); if(str ==0){ return 0; } - for(p = new; *p!=0; p++){ + for(p = n; *p!=0; p++){ *p = tolower(*p); } - return new; + return n; } icalproperty* icalmessage_find_attendee(icalcomponent* comp, const char* user) @@ -122,7 +122,7 @@ icalcomponent *icalmessage_new_reply_base(icalcomponent* c, icalproperty_new_method(ICAL_METHOD_REPLY), icalcomponent_vanew( ICAL_VEVENT_COMPONENT, - icalproperty_new_dtstamp(icaltime_from_timet(time(0),0,1)), + icalproperty_new_dtstamp(icaltime_from_timet(time(0),0)), 0), 0); @@ -136,7 +136,7 @@ icalcomponent *icalmessage_new_reply_base(icalcomponent* c, icalmessage_copy_properties(reply,c,ICAL_SUMMARY_PROPERTY); icalmessage_copy_properties(reply,c,ICAL_SEQUENCE_PROPERTY); - icalcomponent_set_dtstamp(reply,icaltime_from_timet(time(0),0,1)); + icalcomponent_set_dtstamp(reply,icaltime_from_timet(time(0),0)); if(msg != 0){ icalcomponent_add_property(inner,icalproperty_new_comment(msg)); @@ -220,21 +220,21 @@ icalcomponent* icalmessage_new_decline_reply(icalcomponent* c, } /* New is modified version of old */ -icalcomponent* icalmessage_new_counterpropose_reply(icalcomponent* old, - icalcomponent* new, +icalcomponent* icalmessage_new_counterpropose_reply(icalcomponent* oldc, + icalcomponent* newc, const char* user, const char* msg) { icalcomponent *reply; - icalerror_check_arg_rz(old,"old"); - icalerror_check_arg_rz(new,"new"); + icalerror_check_arg_rz(oldc,"oldc"); + icalerror_check_arg_rz(newc,"newc"); - reply = icalcomponent_new_clone(new); + reply = icalcomponent_new_clone(newc); icalcomponent_set_method(reply,ICAL_METHOD_COUNTER); - return new; + return newc; } diff --git a/libical/src/libicalss/icalmessage.h b/libical/src/libicalss/icalmessage.h index 7687db681e..24f1c9f243 100644 --- a/libical/src/libicalss/icalmessage.h +++ b/libical/src/libicalss/icalmessage.h @@ -38,8 +38,8 @@ icalcomponent* icalmessage_new_decline_reply(icalcomponent* c, const char* msg); /* New is modified version of old */ -icalcomponent* icalmessage_new_counterpropose_reply(icalcomponent* old, - icalcomponent* new, +icalcomponent* icalmessage_new_counterpropose_reply(icalcomponent* oldc, + icalcomponent* newc, const char* user, const char* msg); @@ -50,7 +50,6 @@ icalcomponent* icalmessage_new_delegate_reply(icalcomponent* c, const char* msg); - icalcomponent* icalmessage_new_cancel_event(icalcomponent* c, const char* user, const char* msg); diff --git a/libical/src/libicalss/icalset.c b/libical/src/libicalss/icalset.c index 2ffe0deff2..3edbe503c4 100644 --- a/libical/src/libicalss/icalset.c +++ b/libical/src/libicalss/icalset.c @@ -263,7 +263,7 @@ icalset* icalset_new_mysql(const char* path) void icalset_free(icalset* set) { struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->free))(impl.derived_impl); + (*(impl.fp->free))(impl.derived_impl); if(strcmp((char*)set,ICALSET_ID)) { free(set); @@ -279,7 +279,7 @@ const char* icalset_path(icalset* set) void icalset_mark(icalset* set) { struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->mark))(impl.derived_impl); + (*(impl.fp->mark))(impl.derived_impl); } icalerrorenum icalset_commit(icalset* set) @@ -315,7 +315,7 @@ icalerrorenum icalset_select(icalset* set, icalcomponent* gauge) void icalset_clear(icalset* set) { struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->clear))(impl.derived_impl); + (*(impl.fp->clear))(impl.derived_impl); } icalcomponent* icalset_fetch(icalset* set, const char* uid) diff --git a/libical/src/libicalss/icalspanlist.c b/libical/src/libicalss/icalspanlist.c index effab3dca2..cab6a81c68 100644 --- a/libical/src/libicalss/icalspanlist.c +++ b/libical/src/libicalss/icalspanlist.c @@ -265,9 +265,9 @@ struct icalperiodtype icalspanlist_next_free_time(icalspanlist* sl, period.start = t; if (s->is_busy == 0){ - period.end = icaltime_from_timet(s->start,0,0); + period.end = icaltime_from_timet(s->start,0); } else { - period.end = icaltime_from_timet(s->end,0,0); + period.end = icaltime_from_timet(s->end,0); } return period; @@ -286,12 +286,12 @@ struct icalperiodtype icalspanlist_next_free_time(icalspanlist* sl, ( rangett < s->end || s->end == s->start)){ if (rangett < s->start){ - period.start = icaltime_from_timet(s->start,0,0); + period.start = icaltime_from_timet(s->start,0); } else { - period.start = icaltime_from_timet(rangett,0,0); + period.start = icaltime_from_timet(rangett,0); } - period.end = icaltime_from_timet(s->end,0,0); + period.end = icaltime_from_timet(s->end,0); return period; } diff --git a/libical/src/libicalss/icalsslexer.l b/libical/src/libicalss/icalsslexer.l index 0054984c6d..848a9bc74f 100644 --- a/libical/src/libicalss/icalsslexer.l +++ b/libical/src/libicalss/icalsslexer.l @@ -6,7 +6,7 @@ DESCRIPTION: - $Id: icalsslexer.l,v 1.1 2000/12/11 22:06:17 federico Exp $ + $Id: icalsslexer.l,v 1.1.1.2 2001/01/23 19:20:41 jpr Exp $ $Locker: $ (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org @@ -84,12 +84,10 @@ WHERE { return WHERE; } ">=" { return GREATEREQUALS; } AND { return AND; } OR { return OR; } +\' { return QUOTE; } [ \t\n\r]+ ; ; { return EOL; } -[\*A-Za-z0-9\-\.]+ { sslval.v_string= icalmemory_tmp_copy(sstext); - return STRING; } - -'[^'\n]*' { +\'[\*A-Za-z0-9\-\.]+\' { int c = input(); unput(c); if(c!='\''){ @@ -100,6 +98,10 @@ OR { return OR; } } } +[\*A-Za-z0-9\-\.]+ { sslval.v_string= icalmemory_tmp_copy(sstext); + return STRING; } + + . { return yytext[0]; } %% diff --git a/libical/src/libicalss/icalssyacc.h b/libical/src/libicalss/icalssyacc.h index 43423f0d50..9a933dc735 100644 --- a/libical/src/libicalss/icalssyacc.h +++ b/libical/src/libicalss/icalssyacc.h @@ -6,16 +6,17 @@ typedef union { #define FROM 259 #define WHERE 260 #define COMMA 261 -#define EQUALS 262 -#define NOTEQUALS 263 -#define LESS 264 -#define GREATER 265 -#define LESSEQUALS 266 -#define GREATEREQUALS 267 -#define AND 268 -#define OR 269 -#define EOL 270 -#define END 271 +#define QUOTE 262 +#define EQUALS 263 +#define NOTEQUALS 264 +#define LESS 265 +#define GREATER 266 +#define LESSEQUALS 267 +#define GREATEREQUALS 268 +#define AND 269 +#define OR 270 +#define EOL 271 +#define END 272 extern YYSTYPE sslval; diff --git a/libical/src/libicalss/icalssyacc.y b/libical/src/libicalss/icalssyacc.y index e6efe5da1f..047b158e93 100644 --- a/libical/src/libicalss/icalssyacc.y +++ b/libical/src/libicalss/icalssyacc.y @@ -6,7 +6,7 @@ DESCRIPTION: - $Id: icalssyacc.y,v 1.1 2000/12/11 22:06:18 federico Exp $ + $Id: icalssyacc.y,v 1.1.1.2 2001/01/23 19:20:41 jpr Exp $ $Locker: $ (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org @@ -32,16 +32,17 @@ #include <limits.h> /* for SHRT_MAX*/ #include "ical.h" #include "pvl.h" +#include "icalgauge.h" #include "icalgaugeimpl.h" extern struct icalgauge_impl *icalss_yy_gauge; -void ssyacc_add_where(struct icalgauge_impl* impl, char* str1, - enum icalparameter_xliccomparetype compare , char* str2); +void ssyacc_add_where(struct icalgauge_impl* impl, char* prop, + icalgaugecompare compare , char* value); void ssyacc_add_select(struct icalgauge_impl* impl, char* str1); void ssyacc_add_from(struct icalgauge_impl* impl, char* str1); -void move_where(int w); +void set_logic(struct icalgauge_impl* impl,icalgaugelogic l); void sserror(char *s); /* Don't know why I need this.... */ @@ -54,7 +55,7 @@ void sserror(char *s); /* Don't know why I need this.... */ %token <v_string> STRING -%token SELECT FROM WHERE COMMA EQUALS NOTEQUALS LESS GREATER LESSEQUALS +%token SELECT FROM WHERE COMMA QUOTE EQUALS NOTEQUALS LESS GREATER LESSEQUALS %token GREATEREQUALS AND OR EOL END %% @@ -79,61 +80,114 @@ from_list: where_clause: /* Empty */ - | STRING EQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICAL_XLICCOMPARETYPE_EQUAL,$3); } + | STRING EQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_EQUAL,$3); } - | STRING NOTEQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICAL_XLICCOMPARETYPE_NOTEQUAL,$3); } - | STRING LESS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICAL_XLICCOMPARETYPE_LESS,$3); } - | STRING GREATER STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICAL_XLICCOMPARETYPE_GREATER,$3); } - | STRING LESSEQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICAL_XLICCOMPARETYPE_LESSEQUAL,$3); } - | STRING GREATEREQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICAL_XLICCOMPARETYPE_GREATEREQUAL,$3); } + | STRING NOTEQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_NOTEQUAL,$3); } + | STRING LESS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_LESS,$3); } + | STRING GREATER STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_GREATER,$3); } + | STRING LESSEQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_LESSEQUAL,$3); } + | STRING GREATEREQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_GREATEREQUAL,$3); } ; where_list: - where_clause {move_where(1);} - | where_list AND where_clause {move_where(2);} - | where_list OR where_clause {move_where(3);} + where_clause {set_logic(icalss_yy_gauge,ICALGAUGELOGIC_NONE);} + | where_list AND where_clause {set_logic(icalss_yy_gauge,ICALGAUGELOGIC_AND);} + | where_list OR where_clause {set_logic(icalss_yy_gauge,ICALGAUGELOGIC_OR);} ; %% void ssyacc_add_where(struct icalgauge_impl* impl, char* str1, - enum icalparameter_xliccomparetype compare , char* str2) + icalgaugecompare compare , char* value_str) { - icalproperty *p; - icalvalue *v; - icalproperty_kind kind; - - kind = icalenum_string_to_property_kind(str1); + + struct icalgauge_where *where; + char *compstr, *propstr, *c, *s,*l; - if(kind == ICAL_NO_PROPERTY){ - assert(0); + if ( (where = malloc(sizeof(struct icalgauge_where))) ==0){ + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return; } - p = icalproperty_new(kind); + memset(where,0,sizeof(struct icalgauge_where)); + where->logic = ICALGAUGELOGIC_NONE; + where->compare = ICALGAUGECOMPARE_NONE; + where->comp = ICAL_NO_COMPONENT; + where->prop = ICAL_NO_PROPERTY; - v = icalvalue_new_text(str2); + /* remove enclosing quotes */ + s = value_str; + if(*s == '\''){ + s++; + } + l = s+strlen(s)-1; + if(*l == '\''){ + *l=0; + } + + where->value = strdup(s); - if(v == 0){ - assert(0); + /* Is there a period in str1 ? If so, the string specified both a + component and a property*/ + if( (c = strrchr(str1,'.')) != 0){ + compstr = str1; + propstr = c+1; + *c = '\0'; + } else { + compstr = 0; + propstr = str1; + } + + + /* Handle the case where a component was specified */ + if(compstr != 0){ + where->comp = icalenum_string_to_component_kind(compstr); + } else { + where->comp = ICAL_NO_COMPONENT; } - icalproperty_set_value(p,v); + where->prop = icalenum_string_to_property_kind(propstr); - icalproperty_add_parameter(p,icalparameter_new_xliccomparetype(compare)); + where->compare = compare; - icalcomponent_add_property(impl->where,p); + if(where->value == 0){ + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + free(where->value); + return; + } + + pvl_push(impl->where,where); +} + +void set_logic(struct icalgauge_impl* impl,icalgaugelogic l) +{ + pvl_elem e = pvl_tail(impl->where); + struct icalgauge_where *where = pvl_data(e); + + where->logic = l; + } + + void ssyacc_add_select(struct icalgauge_impl* impl, char* str1) { - icalproperty *p; - icalproperty_kind pkind; - icalcomponent_kind ckind = ICAL_NO_COMPONENT; - char* c; - char* compstr; - char* propstr; + char *c, *compstr, *propstr; + struct icalgauge_where *where; + /* Uses only the prop and comp fields of the where structure */ + if ( (where = malloc(sizeof(struct icalgauge_where))) ==0){ + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return; + } + + memset(where,0,sizeof(struct icalgauge_where)); + where->logic = ICALGAUGELOGIC_NONE; + where->compare = ICALGAUGECOMPARE_NONE; + where->comp = ICAL_NO_COMPONENT; + where->prop = ICAL_NO_PROPERTY; + /* Is there a period in str1 ? If so, the string specified both a component and a property*/ if( (c = strrchr(str1,'.')) != 0){ @@ -148,50 +202,31 @@ void ssyacc_add_select(struct icalgauge_impl* impl, char* str1) /* Handle the case where a component was specified */ if(compstr != 0){ - ckind = icalenum_string_to_component_kind(compstr); - - if(ckind == ICAL_NO_COMPONENT){ - assert(0); - } + where->comp = icalenum_string_to_component_kind(compstr); } else { - ckind = ICAL_NO_COMPONENT; + where->comp = ICAL_NO_COMPONENT; } /* If the property was '*', then accept all properties */ if(strcmp("*",propstr) == 0) { - pkind = ICAL_ANY_PROPERTY; + where->prop = ICAL_ANY_PROPERTY; } else { - pkind = icalenum_string_to_property_kind(str1); + where->prop = icalenum_string_to_property_kind(propstr); } - if(pkind == ICAL_NO_PROPERTY){ - assert(0); + if(where->prop == ICAL_NO_PROPERTY){ + icalgauge_free(where); + icalerror_set_errno(ICAL_BADARG_ERROR); + return; } - - if(ckind == ICAL_NO_COMPONENT){ - p = icalproperty_new(pkind); - assert(p!=0); - icalcomponent_add_property(impl->select,p); - - } else { - icalcomponent *comp = - icalcomponent_new(ckind); - p = icalproperty_new(pkind); - - assert(p!=0); - - icalcomponent_add_property(comp,p); - icalcomponent_add_component(impl->select,comp); - - } + pvl_push(impl->select,where); } void ssyacc_add_from(struct icalgauge_impl* impl, char* str1) { - icalcomponent *c; icalcomponent_kind ckind; ckind = icalenum_string_to_component_kind(str1); @@ -200,15 +235,10 @@ void ssyacc_add_from(struct icalgauge_impl* impl, char* str1) assert(0); } - c = icalcomponent_new(ckind); - - icalcomponent_add_component(impl->from,c); + pvl_push(impl->from,(void*)ckind); } -void move_where(int w) -{ -} void sserror(char *s){ fprintf(stderr,"Parse error \'%s\'\n", s); diff --git a/libical/src/test/process.c b/libical/src/test/process.c index 42ae3b8037..56f1c65fb1 100644 --- a/libical/src/test/process.c +++ b/libical/src/test/process.c @@ -19,10 +19,6 @@ the License for the specific language governing rights and limitations under the License. - The Original Code is eric. The Initial Developer of the Original - Code is Eric Busboom - - ======================================================================*/ #include <stdio.h> /* for printf */ @@ -110,7 +106,6 @@ int main(int argc, char* argv[]) ical_class class; icalcomponent *match; icalcomponent *inner; - icalcomponent *p; icalcomponent *reply = 0; assert(c!=0); @@ -241,7 +236,6 @@ int main(int argc, char* argv[]) conflicts with this meeting. I am delegating my attendance to Bob. "); icalset_add_component(out,reply); - } else if (dtstart.hour%4 == 1) { /* Counter propose to next available time */ diff --git a/libical/src/test/recur.c b/libical/src/test/recur.c index 2967ee7977..546cacb007 100644 --- a/libical/src/test/recur.c +++ b/libical/src/test/recur.c @@ -23,10 +23,6 @@ the License for the specific language governing rights and limitations under the License. - The original author is Eric Busboom - The original code is usecases.c - - ======================================================================*/ #include "ical.h" @@ -48,23 +44,39 @@ int main(int argc, char *argv[]) struct icalrecurrencetype recur; icalrecur_iterator* ritr; time_t tt; + char* file; + + if (argc <= 1){ + file = "../../test-data/recur.txt"; + } else if (argc == 2){ + file = argv[1]; + } else { + fprintf(stderr,"usage: recur [input file]\n"); + exit(1); + } + + cin = icalfileset_new(file); + + if(cin == 0){ + fprintf(stderr,"recur: can't open file %s\n",file); + exit(1); + } - cin = icalfileset_new(argv[1]); - assert(cin != 0); for (itr = icalfileset_get_first_component(cin); itr != 0; itr = icalfileset_get_next_component(cin)){ desc = icalcomponent_get_first_property(itr,ICAL_DESCRIPTION_PROPERTY); - assert(desc !=0); - dtstart = icalcomponent_get_first_property(itr,ICAL_DTSTART_PROPERTY); - assert(dtstart !=0); - rrule = icalcomponent_get_first_property(itr,ICAL_RRULE_PROPERTY); - assert(rrule !=0); + if (desc == 0 || dtstart == 0 || rrule == 0){ + printf("\n******** Error in input component ********\n"); + printf("The following component is malformed:\n %s\n", + icalcomponent_as_ical_string(itr)); + continue; + } recur = icalproperty_get_rrule(rrule); start = icalproperty_get_dtstart(dtstart); |