diff options
author | Seth Alves <alves@src.gnome.org> | 2000-04-19 02:17:07 +0800 |
---|---|---|
committer | Seth Alves <alves@src.gnome.org> | 2000-04-19 02:17:07 +0800 |
commit | 25e1b34aafe43ba6cf1040340a38dd38a90aad33 (patch) | |
tree | 0b4e666e45bf457edcc0095634f0ae6f429b8b5a /libical/src/libical | |
parent | bc17057ec598cd5f755fd66244c429ecc51cff01 (diff) | |
download | gsoc2013-evolution-25e1b34aafe43ba6cf1040340a38dd38a90aad33.tar gsoc2013-evolution-25e1b34aafe43ba6cf1040340a38dd38a90aad33.tar.gz gsoc2013-evolution-25e1b34aafe43ba6cf1040340a38dd38a90aad33.tar.bz2 gsoc2013-evolution-25e1b34aafe43ba6cf1040340a38dd38a90aad33.tar.lz gsoc2013-evolution-25e1b34aafe43ba6cf1040340a38dd38a90aad33.tar.xz gsoc2013-evolution-25e1b34aafe43ba6cf1040340a38dd38a90aad33.tar.zst gsoc2013-evolution-25e1b34aafe43ba6cf1040340a38dd38a90aad33.zip |
import of libical-0.16
svn path=/trunk/; revision=2484
Diffstat (limited to 'libical/src/libical')
24 files changed, 1899 insertions, 646 deletions
diff --git a/libical/src/libical/.cvsignore b/libical/src/libical/.cvsignore index 9dc64874d6..3bd9f3bca3 100644 --- a/libical/src/libical/.cvsignore +++ b/libical/src/libical/.cvsignore @@ -3,6 +3,9 @@ Makefile.in icalitipy.c icalitipy.h icalitipl.c +icallexer.c +icalyacc.c +icalyacc.h *.lo *.la .libs diff --git a/libical/src/libical/Makefile.am b/libical/src/libical/Makefile.am index 4e74c8c207..54c66b58ec 100644 --- a/libical/src/libical/Makefile.am +++ b/libical/src/libical/Makefile.am @@ -1,39 +1,85 @@ -lib_LTLIBRARIES = libical.la - -CFLAGS=-g - -libical_la_SOURCES = \ - ical.h \ - icalcomponent.c \ - icalcomponent.h \ - icalenums.c \ - icalenums.h \ - icalerror.c \ - icalerror.h \ - icalirip.h \ - icalitipy.y \ - icalitipl.l \ - icalmemory.c \ - icalmemory.h \ - icalparameter.c \ - icalparameter.h \ - icalparser.c \ - icalparser.h \ - icalproperty.c \ - icalproperty.h \ - icalrestriction.c \ - icalrestriction.h \ - icaltypes.c \ - icaltypes.h \ - icalvalue.c \ - icalvalue.h \ - icalvcal.h \ - locking.c \ - pvl.c \ +#AUTOMAKE_OPTIONS = no-dependencies + +#noinst_LTLIBRARIES = libical.la +lib_LIBRARIES = libical.a + +YFLAGS =-d -v -t + +libical_a_SOURCES = \ + ical.h \ + icalcomponent.c \ + icalcomponent.h \ + icalenums.c \ + icalenums.h \ + icalerror.c \ + icalerror.h \ + icalyacc.y \ + icallexer.l \ + icalmemory.c \ + icalmemory.h \ + icalparameter.c \ + icalparameter.h \ + icalparser.c \ + icalparser.h \ + icalproperty.c \ + icalproperty.h \ + icalrestriction.c \ + icalrestriction.h \ + icaltypes.c \ + icaltypes.h \ + icalvalue.c \ + icalvalue.h \ + icalvcal.h \ + pvl.c \ + pvl.h + +include_HEADERS=\ + ical.h \ + icalcomponent.h \ + icalenums.h \ + icalerror.h \ + icalmemory.h \ + icalparameter.h \ + icalparser.h \ + icalproperty.h \ + icalrestriction.h \ + icaltypes.h \ + icalvalue.h \ + icalvcal.h \ + icalversion.h \ pvl.h -EXTRA_DIST = .gdbinit base64.c filelock.c filelock.h -YFLAGS=-picalparser_yy -d -LFLAGS=-Picalparser_yy -olex.yy.c + +EXTRA_DIST = icallexer.c icalyacc.c icalyacc.h + +CONFIG_CLEAN_FILES = y.output *~ + +DESIGNDATA = ../../design-data +ICALSCRIPTS = ../../scripts +derived: icalproperty icalparameter icalvalue + +icalproperty: + $(ICALSCRIPTS)/mkderivedproperties.pl -i icalproperty.h -h $(DESIGNDATA)/prop-to-value.txt ${DESIGNDATA}/value-c-types.txt > icalproperty.newh + mv icalproperty.newh icalproperty.h + + $(ICALSCRIPTS)/mkderivedproperties.pl -i icalproperty.c -c $(DESIGNDATA)/prop-to-value.txt ${DESIGNDATA}/value-c-types.txt > icalproperty.newc + mv icalproperty.newc icalproperty.c + + +icalparameter: + $(ICALSCRIPTS)/mkderivedparameters.pl -i icalparameter.h -h $(DESIGNDATA)/param-c-types.txt > icalparameter.newh + mv icalparameter.newh icalparameter.h + + $(ICALSCRIPTS)/mkderivedparameters.pl -i icalparameter.c -c $(DESIGNDATA)/param-c-types.txt > icalparameter.newc + mv icalparameter.newc icalparameter.c + +icalvalue: + $(ICALSCRIPTS)/mkderivedvalues.pl -i icalvalue.h -h $(DESIGNDATA)/value-c-types.txt > icalvalue.newh + mv icalvalue.newh icalvalue.h + + $(ICALSCRIPTS)/mkderivedvalues.pl -i icalvalue.c -c $(DESIGNDATA)/value-c-types.txt > icalvalue.newc + mv icalvalue.newc icalvalue.c + + diff --git a/libical/src/libical/ical.h b/libical/src/libical/ical.h index cd5ca31dd5..d0f33cd1a1 100644 --- a/libical/src/libical/ical.h +++ b/libical/src/libical/ical.h @@ -25,6 +25,7 @@ #ifndef ICAL_H #define ICAL_H +#include "icalversion.h" #include "icalenums.h" #include "icalvalue.h" #include "icalparameter.h" @@ -36,7 +37,6 @@ #include "icalerror.h" #include "icalrestriction.h" - #endif /* !ICAL_H */ diff --git a/libical/src/libical/icalcomponent.c b/libical/src/libical/icalcomponent.c index a1a2535e7a..bd2b13189c 100644 --- a/libical/src/libical/icalcomponent.c +++ b/libical/src/libical/icalcomponent.c @@ -24,6 +24,11 @@ ======================================================================*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "ical.h" #include "pvl.h" /* "Pointer-to-void list" */ #include <stdlib.h> /* for malloc */ @@ -35,6 +40,8 @@ #include "icalmemory.h" #include "icalenums.h" +#define MAX_TMP 1024 + /* icalproperty functions that only components get to use */ void icalproperty_set_parent(icalproperty* property, @@ -85,7 +92,6 @@ icalcomponent_new_impl (icalcomponent_kind kind) if ( ( comp = (struct icalcomponent_impl*) malloc(sizeof(struct icalcomponent_impl))) == 0) { - errno = ENOMEM; icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } @@ -236,6 +242,12 @@ icalcomponent_as_ical_string (icalcomponent* component) char* tmp_buf; size_t buf_size = 1024; char* buf_ptr = 0; + +#ifdef ICAL_UNIX_NEWLINE + char newline[] = "\n"; +#else + char newline[] = "\r\n"; +#endif icalcomponent *c; icalproperty *p; @@ -255,7 +267,7 @@ icalcomponent_as_ical_string (icalcomponent* component) icalmemory_append_string(&buf, &buf_ptr, &buf_size, "BEGIN:"); icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string); - icalmemory_append_string(&buf, &buf_ptr, &buf_size, "\n"); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline); for(p = icalcomponent_get_first_property(component,ICAL_ANY_PROPERTY); @@ -281,7 +293,7 @@ icalcomponent_as_ical_string (icalcomponent* component) icalmemory_append_string(&buf, &buf_ptr, &buf_size, "END:"); icalmemory_append_string(&buf, &buf_ptr, &buf_size, icalenum_component_kind_to_string(kind)); - icalmemory_append_string(&buf, &buf_ptr, &buf_size, "\n"); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline); out_buf = icalmemory_tmp_copy(buf); free(buf); @@ -680,9 +692,79 @@ void icalcomponent_strip_errors(icalcomponent* component) icalcomponent_strip_errors(c); } +} + + +void icalcomponent_convert_errors(icalcomponent* component) +{ + icalproperty *p, *next_p; + icalcomponent *c; + + for(p = icalcomponent_get_first_property(component,ICAL_ANY_PROPERTY); + p != 0; + p = next_p){ + + next_p = icalcomponent_get_next_property(component,ICAL_ANY_PROPERTY); + + if(icalproperty_isa(p) == ICAL_XLICERROR_PROPERTY) + { + struct icalreqstattype rst; + char tmp[MAX_TMP]; + icalparameter *param = icalproperty_get_first_parameter + (p,ICAL_XLICERRORTYPE_PARAMETER); + + rst.code = ICAL_UNKNOWN_STATUS; + rst.desc = 0; + + switch(icalparameter_get_xlicerrortype(param)){ + + case ICAL_XLICERRORTYPE_PARAMETERNAMEPARSEERROR: { + rst.code = ICAL_3_2_INVPARAM_STATUS; + break; + } + case ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR: { + rst.code = ICAL_3_3_INVPARAMVAL_STATUS; + break; + } + case ICAL_XLICERRORTYPE_PROPERTYPARSEERROR: { + rst.code = ICAL_3_0_INVPROPNAME_STATUS; + break; + } + case ICAL_XLICERRORTYPE_VALUEPARSEERROR: { + rst.code = ICAL_3_1_INVPROPVAL_STATUS; + break; + } + case ICAL_XLICERRORTYPE_COMPONENTPARSEERROR: { + rst.code = ICAL_3_4_INVCOMP_STATUS; + break; + } + + default: { + } + } + if (rst.code != ICAL_UNKNOWN_STATUS){ + + rst.debug = icalproperty_get_xlicerror(p); + icalcomponent_add_property(component, + icalproperty_new_requeststatus( + icalreqstattype_as_string(rst) + ) + ); + + icalcomponent_remove_property(component,p); + } + } + } + for(c = icalcomponent_get_first_component(component,ICAL_ANY_COMPONENT); + c != 0; + c = icalcomponent_get_next_component(component,ICAL_ANY_COMPONENT)){ + + icalcomponent_convert_errors(c); + } } + icalcomponent* icalcomponent_get_parent(icalcomponent* component) { struct icalcomponent_impl *c = (struct icalcomponent_impl*)component; diff --git a/libical/src/libical/icalcomponent.h b/libical/src/libical/icalcomponent.h index 9e0e9f5a9f..8d9f22ca76 100644 --- a/libical/src/libical/icalcomponent.h +++ b/libical/src/libical/icalcomponent.h @@ -101,8 +101,12 @@ icalproperty** icalcomponent_get_component(icalcomponent* component, /* Working with embedded error properties */ int icalcomponent_count_errors(icalcomponent* component); + +/* Remove all X-LIC-ERROR properties*/ void icalcomponent_strip_errors(icalcomponent* component); +/* Convert some X-LIC-ERROR properties into RETURN-STATUS properties*/ +void icalcomponent_convert_errors(icalcomponent* component); /* Internal operations. You don't see these... */ icalcomponent* icalcomponent_get_parent(icalcomponent* component); diff --git a/libical/src/libical/icalenums.c b/libical/src/libical/icalenums.c index 70931d03d0..95f308eec6 100644 --- a/libical/src/libical/icalenums.c +++ b/libical/src/libical/icalenums.c @@ -24,6 +24,11 @@ ======================================================================*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "icalenums.h" struct icalproperty_kind_map { @@ -224,6 +229,7 @@ static struct icalvalue_kind_map value_map[] = { ICAL_TIME_VALUE, "TIME"}, { ICAL_URI_VALUE, "URI"}, { ICAL_UTCOFFSET_VALUE, "UTC-OFFSET"}, + { ICAL_METHOD_VALUE, "METHOD"}, /* Not an RFC2445 type */ { ICAL_GEO_VALUE, "FLOAT"}, /* Not an RFC2445 type */ { ICAL_ATTACH_VALUE, "XATTACH"}, /* Not an RFC2445 type */ { ICAL_DATETIMEDATE_VALUE, "XDATETIMEDATE"}, /* Not an RFC2445 type */ @@ -281,7 +287,8 @@ static struct icalcomponent_kind_map component_map[] = /* libical private components */ { ICAL_XLICINVALID_COMPONENT, "X-LIC-UNKNOWN" }, - { ICAL_XROOT_COMPONENT, "ROOT" }, + { ICAL_ANY_COMPONENT, "ANY" }, + { ICAL_XROOT_COMPONENT, "XROOT" }, /* End of list */ { ICAL_NO_COMPONENT, "" }, @@ -326,7 +333,7 @@ struct icalproperty_kind_value_map { static struct icalproperty_kind_value_map propval_map[] = { { ICAL_CALSCALE_PROPERTY, ICAL_TEXT_VALUE }, - { ICAL_METHOD_PROPERTY, ICAL_TEXT_VALUE }, + { ICAL_METHOD_PROPERTY, ICAL_METHOD_VALUE }, { ICAL_PRODID_PROPERTY, ICAL_TEXT_VALUE }, { ICAL_VERSION_PROPERTY, ICAL_TEXT_VALUE }, { ICAL_CATEGORIES_PROPERTY, ICAL_TEXT_VALUE }, @@ -481,7 +488,7 @@ struct { {ICAL_3_1_INVPROPVAL_STATUS, 3,1,"Invalid property value."}, {ICAL_3_2_INVPARAM_STATUS, 3,2,"Invalid property parameter."}, {ICAL_3_3_INVPARAMVAL_STATUS, 3,3,"Invalid property parameter value."}, - {ICAL_3_4_INVCOMP_STATUS, 3,4,"Invalid calendar component sequence."}, + {ICAL_3_4_INVCOMP_STATUS, 3,4,"Invalid calendar component."}, {ICAL_3_5_INVTIME_STATUS, 3,5,"Invalid date or time."}, {ICAL_3_6_INVRULE_STATUS, 3,6,"Invalid rule."}, {ICAL_3_7_INVCU_STATUS, 3,7,"Invalid Calendar User."}, @@ -496,9 +503,65 @@ struct { {ICAL_5_0_MAYBE_STATUS, 5,0,"Request MAY supported."}, {ICAL_5_1_UNAVAIL_STATUS, 5,1,"Service unavailable."}, {ICAL_5_2_NOSERVICE_STATUS, 5,2,"Invalid calendar service."}, - {ICAL_5_3_NOSCHED_STATUS, 5,3,"No scheduling support for user."} + {ICAL_5_3_NOSCHED_STATUS, 5,3,"No scheduling support for user."}, + {ICAL_UNKNOWN_STATUS, 0,0,"Error: Unknown request status"} }; + +char* icalenum_reqstat_desc(icalrequeststatus stat) +{ + + int i; + + for (i=0; status_map[i].kind != ICAL_UNKNOWN_STATUS; i++) { + if ( status_map[i].kind == stat) { + return status_map[i].str; + } + } + + return 0; +} + + +short icalenum_reqstat_major(icalrequeststatus stat) +{ + int i; + + for (i=0; status_map[i].kind != ICAL_UNKNOWN_STATUS; i++) { + if ( status_map[i].kind == stat) { + return status_map[i].major; + } + } + return -1; +} + +short icalenum_reqstat_minor(icalrequeststatus stat) +{ + int i; + + for (i=0; status_map[i].kind != ICAL_UNKNOWN_STATUS; i++) { + if ( status_map[i].kind == stat) { + return status_map[i].minor; + } + } + return -1; +} + + +icalrequeststatus icalenum_num_to_reqstat(short major, short minor) +{ + int i; + + for (i=0; status_map[i].kind != ICAL_UNKNOWN_STATUS; i++) { + if ( status_map[i].major == major && status_map[i].minor == minor) { + return status_map[i].kind; + } + } + return 0; +} + + + struct {icalproperty_method method; char* str;} method_map[] = { {ICAL_METHOD_PUBLISH,"PUBLISH"}, {ICAL_METHOD_REQUEST,"REQUEST"}, @@ -537,6 +600,11 @@ icalproperty_method icalenum_string_to_method(char* str) { int i; + while(*str == ' '){ + str++; + } + + for (i=0; method_map[i].method != ICAL_METHOD_NONE; i++) { if ( strcmp(method_map[i].str, str) == 0) { return method_map[i].method; diff --git a/libical/src/libical/icalenums.h b/libical/src/libical/icalenums.h index e60d230854..ff7cee486e 100644 --- a/libical/src/libical/icalenums.h +++ b/libical/src/libical/icalenums.h @@ -36,8 +36,8 @@ typedef enum icalcomponent_kind { ICAL_NO_COMPONENT, - ICAL_ANY_COMPONENT, /* Used in get_components to select all components*/ - ICAL_XROOT_COMPONENT, /* Root component returned by parser */ + ICAL_ANY_COMPONENT, /* Used to select all components*/ + ICAL_XROOT_COMPONENT, ICAL_XATTACH_COMPONENT, /* MIME attached data, returned by parser. */ ICAL_VEVENT_COMPONENT, ICAL_VTODO_COMPONENT, @@ -210,9 +210,10 @@ typedef enum icalvalue_kind { ICAL_FLOAT_VALUE, ICAL_GEO_VALUE, /* Non-Standard */ ICAL_INTEGER_VALUE, - ICAL_METHOD_VALUE, + ICAL_METHOD_VALUE, /* Non-Standard */ ICAL_PERIOD_VALUE, ICAL_RECUR_VALUE, + ICAL_STRING_VALUE, /* Non-Standard */ ICAL_TEXT_VALUE, ICAL_TIME_VALUE, ICAL_TRIGGER_VALUE, /* Non-Standard */ @@ -318,7 +319,8 @@ typedef enum icalparameter_role { typedef enum icalparameter_xlicerrortype { ICAL_XLICERRORTYPE_COMPONENTPARSEERROR, - ICAL_XLICERRORTYPE_PARAMETERPARSEERROR, + ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR, + ICAL_XLICERRORTYPE_PARAMETERNAMEPARSEERROR, ICAL_XLICERRORTYPE_PROPERTYPARSEERROR, ICAL_XLICERRORTYPE_VALUEPARSEERROR, ICAL_XLICERRORTYPE_INVALIDITIP @@ -396,6 +398,7 @@ char* icalenum_weekday_to_string(icalrecurrencetype_weekday kind); **********************************************************************/ typedef enum icalrequeststatus { + ICAL_UNKNOWN_STATUS, ICAL_2_0_SUCCESS_STATUS, ICAL_2_1_FALLBACK_STATUS, ICAL_2_2_IGPROP_STATUS, @@ -431,6 +434,10 @@ typedef enum icalrequeststatus { } icalrequeststatus; +char* icalenum_reqstat_desc(icalrequeststatus stat); +short icalenum_reqstat_major(icalrequeststatus stat); +short icalenum_reqstat_minor(icalrequeststatus stat); +icalrequeststatus icalenum_num_to_reqstat(short major, short minor); /*********************************************************************** * Conversion functions diff --git a/libical/src/libical/icalerror.c b/libical/src/libical/icalerror.c index d84c288d3a..fb9e152b16 100644 --- a/libical/src/libical/icalerror.c +++ b/libical/src/libical/icalerror.c @@ -25,6 +25,11 @@ ======================================================================*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "icalerror.h" icalerrorenum icalerrno; @@ -35,6 +40,15 @@ void icalerror_stop_here(void) foo++; /* Keep optimizers from removing routine */ } +void icalerror_crash_here(void) +{ + int *p=0; + *p = 1; + + assert( *p); +} + + void icalerror_clear_errno() { icalerrno = ICAL_NO_ERROR; diff --git a/libical/src/libical/icalerror.h b/libical/src/libical/icalerror.h index 429d680022..124699c21b 100644 --- a/libical/src/libical/icalerror.h +++ b/libical/src/libical/icalerror.h @@ -36,6 +36,8 @@ below */ void icalerror_stop_here(void); +void icalerror_crash_here(void); + #ifdef ICAL_ERRORS_ARE_FATAL #undef NDEBUG #endif diff --git a/libical/src/libical/icallexer.l b/libical/src/libical/icallexer.l new file mode 100644 index 0000000000..9026b9ae41 --- /dev/null +++ b/libical/src/libical/icallexer.l @@ -0,0 +1,282 @@ +%{ +/* -*- Mode: C -*- + ====================================================================== + FILE: icallexer.l + CREATOR: eric 10 June 1999 + + DESCRIPTION: + + $Id: icallexer.l,v 1.1 2000/04/18 18:17:04 alves Exp $ + $Locker: $ + + (C) COPYRIGHT 1999 Eric Busboom + http://www.softwarestudio.org + + The contents of this file are subject to the Mozilla Public License + Version 1.0 (the "License"); you may not use this file except in + compliance with the License. You may obtain a copy of the License at + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and + limitations under the License. + + The original author is Eric Busboom + The original code is icalitip.y + + + + ======================================================================*/ +#include "icalyacc.h" +#include "icalparser.h" +#include "icalenums.h" +#include "icalmemory.h" +#include "assert.h" + +#include <string.h> /* For strdup() */ + +int icalparser_flex_input(char* buf, int max_size); +void icalparser_clear_flex_input(); + + +#define ICAL_MAX_STR_CONST 1024 + +#undef YY_INPUT +#define YY_INPUT(b,r,ms) ( r= icalparser_flex_input(b,ms)) +#undef yywrap + +#undef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yyerror(msg) + +icalvalue_kind value_kind=ICAL_NO_VALUE; +void set_parser_value_state(); +extern int yydebug; + +void yyerror(char *s); + +void init_str_buf(); + +int last_state; + +char *str_buf; +char *str_buf_p; +size_t buf_sz; /* = ICAL_MAX_STR_CONST;*/ + + +%} + +crlf \x0D?\x0A +space [ ] +qsafechar [^\x00-\x1F\"] +safechar [^\x00-\x1F\"\:\;\,] +tsafechar [\x20-\x21\x23-\x2B\x2D-\x39\x3C-\x5B\x5D-\x7E] +valuechar [^\x00-\x08\x10-\x1F] +xname X-[a-zA-Z0-9\-]+ +xname2 [a-zA-Z0-9\-\ ] +paramtext {safechar}+ +value {valuechar}+ +quotedstring \"{qsafechar}+\" +digit [0-9] + +%array /* Make yytext an array. Slow, but handy. HACK */ + +%option caseless + +%s quoted_string +%s binary_value boolean_value uri_value time_value duration_value number_value period_value recur_value text_value utcoffset_value +%s enum_param_value string_param_value stringlist_param_value keyword line_start component seperator parameter end_of_value paramtext + + + +%% + +%{ +%} + + +<binary_value>{ +.* { yylval.v_string= icalmemory_tmp_copy(yytext); + return STRING;} +{crlf} { return EOL;} + +} + +<boolean_value>{ +. { return CHARACTER; } +{crlf} { return EOL;} + +} + +<uri_value>{ +.* { yylval.v_string= icalmemory_tmp_copy(yytext); + return STRING;} +{crlf} { return EOL;} + +} + + +<time_value>{ +{digit}* { yylval.v_string= icalmemory_tmp_copy(yytext); + return DIGITS; } +T { return TIME_CHAR; } +Z { return UTC_CHAR; } +{crlf} { return EOL;} +} + +<duration_value>{ +{digit}+ { yylval.v_string =icalmemory_tmp_copy(yytext); + return DIGITS; } +T { return TIME_CHAR; } +[\+\-PTWHMSD] { return yytext[0]; } +{crlf} { return EOL;} + +} + +<number_value>{ +[\+\-\.0-9]+ { yylval.v_int=atoi(yytext); return INTNUMBER; } +{crlf} { return EOL;} +} + +<period_value>{ +{digit}+ { yylval.v_string =icalmemory_tmp_copy(yytext) ; + return DIGITS; } +T { return TIME_CHAR; } +Z { return UTC_CHAR; } +[\/\+\-PWHMSD] { return yytext[0]; } +{crlf} { return EOL;} + +} + +<recur_value>{ +INTERVAL { return INTERVAL; } +COUNT { return COUNT; } +UNTIL { return UNTIL; } +FREQ { return FREQ; } +BYDAY { return BYDAY; } +BYHOUR { return BYHOUR; } +BYMINUTE { return BYMINUTE; } +BYMONTH { return BYMONTH; } +BYMONTHDAY { return BYMONTHDAY; } +BYSECOND { return BYSECOND; } +BYSETPOS { return BYSETPOS; } +BYWEEKNO { return BYWEEKNO; } +BYYEARDAY { return BYYEARDAY; } +DAILY { return DAILY; } +SECONDLY { return SECONDLY; } +MINUTELY { return MINUTELY; } +HOURLY { return HOURLY; } +MONTHLY { return MONTHLY; } +WEEKLY { return WEEKLY; } +YEARLY { return YEARLY; } +WKST { return WKST; } +MO { return MO; } +SA { return SA; } +SU { return SU; } +TU { return TU; } +WE { return WE; } +TH { return TH; } +FR { return FR; } += { return EQUALS; } +, { return COMMA; } +; { return SEMICOLON; } +[\-\+0-9]+ { yylval.v_string= icalmemory_tmp_copy(yytext); + return DIGITS; } +T { return TIME_CHAR; } +Z { return UTC_CHAR; } +{crlf} { return EOL;} +} + +<utcoffset_value>{ +{crlf} { return EOL;} +\-|\+ { return yytext[0]; } +{digit}{digit} { yylval.v_int=atoi(yytext); return INTNUMBER; } + +} + +<enum_param_value>{ +. { return CHARACTER; } +{crlf} { return EOL;} + +} + +<seperator>{ +, { BEGIN(last_state); return COMMA; } +} + + +%% + +int yywrap() +{ + return 1; +} + + +void set_parser_value_state(icalvalue_kind kind) +{ + + switch (kind){ + + case ICAL_ATTACH_VALUE: + case ICAL_BINARY_VALUE: + {BEGIN(binary_value);break;} + + case ICAL_BOOLEAN_VALUE: + case ICAL_INTEGER_VALUE: + case ICAL_FLOAT_VALUE: + {BEGIN(number_value);break;} + + case ICAL_UTCOFFSET_VALUE: + {BEGIN(utcoffset_value);break;} + + case ICAL_TEXT_VALUE: + {BEGIN(text_value); + init_str_buf(); + break;} + + case ICAL_CALADDRESS_VALUE: + case ICAL_URI_VALUE: + {BEGIN(uri_value);break;} + + case ICAL_DATE_VALUE: + case ICAL_DATETIME_VALUE: + case ICAL_DATETIMEDATE_VALUE: + case ICAL_DATETIMEPERIOD_VALUE: + case ICAL_TIME_VALUE: + {BEGIN(time_value);break;} + + case ICAL_DURATION_VALUE: + {BEGIN(duration_value);break;} + + case ICAL_PERIOD_VALUE: + {BEGIN(period_value);break;} + + case ICAL_GEO_VALUE: + case ICAL_QUERY_VALUE: + {BEGIN(text_value);break;} + + case ICAL_RECUR_VALUE: + {BEGIN(recur_value);break;} + + case ICAL_NO_VALUE: + { + /* The value is probably actually a component name */ + {BEGIN(component); break;} + } + default: + { + assert(1==0); + } + } +} + +void init_str_buf() +{ + str_buf = icalmemory_tmp_buffer(ICAL_MAX_STR_CONST); + str_buf_p = str_buf; + buf_sz = ICAL_MAX_STR_CONST; + + +} + diff --git a/libical/src/libical/icalmemory.c b/libical/src/libical/icalmemory.c index 7d99eb62b3..e89451fbce 100644 --- a/libical/src/libical/icalmemory.c +++ b/libical/src/libical/icalmemory.c @@ -35,14 +35,19 @@ * several buffers active simultaneously, which is handy when creating * string representations of components. */ - #define ICALMEMORY_C +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + #include "icalmemory.h" #include "icalerror.h" #include <stdio.h> /* for printf (debugging) */ #include <stdlib.h> /* for malloc, realloc */ +#include <string.h> /* for memset() */ #define BUFFER_RING_SIZE 25 #define MIN_BUFFER_SIZE 200 diff --git a/libical/src/libical/icalparameter.c b/libical/src/libical/icalparameter.c index ff9c76f79c..cf37eb07b2 100644 --- a/libical/src/libical/icalparameter.c +++ b/libical/src/libical/icalparameter.c @@ -28,6 +28,10 @@ ======================================================================*/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "ical.h" #include "icalerror.h" #include <stdlib.h> /* for malloc() */ @@ -68,7 +72,6 @@ struct icalparameter_impl* icalparameter_new_impl(icalparameter_kind kind) if ( ( v = (struct icalparameter_impl*) malloc(sizeof(struct icalparameter_impl))) == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); - errno = ENOMEM; return 0; } @@ -412,8 +415,11 @@ icalparameter* icalparameter_new_from_string(icalparameter_kind kind, char* val) else if(strcmp(val,"PROPERTY_PARSE_ERROR") == 0){ param = icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_PROPERTYPARSEERROR); } - else if(strcmp(val,"PARAMETER_PARSE_ERROR") == 0){ - param = icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_PARAMETERPARSEERROR); + else if(strcmp(val,"PARAMETER_NAME_PARSE_ERROR") == 0){ + param = icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_PARAMETERNAMEPARSEERROR); + } + else if(strcmp(val,"PARAMETER_VALUE_PARSE_ERROR") == 0){ + param = icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR); } else if(strcmp(val,"VALUE_PARSE_ERROR") == 0){ param = icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_VALUEPARSEERROR); @@ -423,6 +429,37 @@ icalparameter* icalparameter_new_from_string(icalparameter_kind kind, char* val) } break; } + + case ICAL_XLICCOMPARETYPE_PARAMETER: + { + + if(strcmp(val,"EQUAL") == 0){ + param = icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_EQUAL); + } + else if(strcmp(val,"NOTEQUAL") == 0){ + param = icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_NOTEQUAL); + } + else if(strcmp(val,"LESS") == 0){ + param = icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_LESS); + } + else if(strcmp(val,"GREATER") == 0){ + param = icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_GREATER); + } + else if(strcmp(val,"LESSEQUAL") == 0){ + param = icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_LESSEQUAL); + } + else if(strcmp(val,"GREATEREQUAL") == 0){ + param = icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_GREATEREQUAL); + } + else if(strcmp(val,"REGEX") == 0){ + param = icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_REGEX); + } else { + param = 0; + } + break; + } + + case ICAL_X_PARAMETER: { param = icalparameter_new(ICAL_FBTYPE_PARAMETER); @@ -767,7 +804,7 @@ icalparameter_as_ical_string (icalparameter* parameter) strcpy(tend,impl->string);break; } default:{ - strcpy(tend,"ERROR");break; + strcpy(tend,"ERROR"); icalerror_set_errno(ICAL_BADARG_ERROR);break; } } @@ -786,9 +823,13 @@ icalparameter_as_ical_string (icalparameter* parameter) { strcpy(tend,"PROPERTY_PARSE_ERROR");break; } - case ICAL_XLICERRORTYPE_PARAMETERPARSEERROR: + case ICAL_XLICERRORTYPE_PARAMETERNAMEPARSEERROR: + { + strcpy(tend,"PARAMETER_NAME_PARSE_ERROR");break; + } + case ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR: { - strcpy(tend,"PARAMETER_PARSE_ERROR");break; + strcpy(tend,"PARAMETER_VALUE_PARSE_ERROR");break; } case ICAL_XLICERRORTYPE_VALUEPARSEERROR: { @@ -1026,7 +1067,7 @@ char* icalparameter_get_altrep(icalparameter* param) void icalparameter_set_altrep(icalparameter* param, char* v) { - icalerror_check_arg_rz( (v!=0),"v"); + icalerror_check_arg_rv( (v!=0),"v"); icalerror_check_arg_rv( (param!=0), "param"); icalerror_clear_errno(); @@ -1062,7 +1103,7 @@ char* icalparameter_get_cn(icalparameter* param) void icalparameter_set_cn(icalparameter* param, char* v) { - icalerror_check_arg_rz( (v!=0),"v"); + icalerror_check_arg_rv( (v!=0),"v"); icalerror_check_arg_rv( (param!=0), "param"); icalerror_clear_errno(); @@ -1139,7 +1180,7 @@ char* icalparameter_get_delegatedfrom(icalparameter* param) void icalparameter_set_delegatedfrom(icalparameter* param, char* v) { - icalerror_check_arg_rz( (v!=0),"v"); + icalerror_check_arg_rv( (v!=0),"v"); icalerror_check_arg_rv( (param!=0), "param"); icalerror_clear_errno(); @@ -1175,7 +1216,7 @@ char* icalparameter_get_delegatedto(icalparameter* param) void icalparameter_set_delegatedto(icalparameter* param, char* v) { - icalerror_check_arg_rz( (v!=0),"v"); + icalerror_check_arg_rv( (v!=0),"v"); icalerror_check_arg_rv( (param!=0), "param"); icalerror_clear_errno(); @@ -1211,7 +1252,7 @@ char* icalparameter_get_dir(icalparameter* param) void icalparameter_set_dir(icalparameter* param, char* v) { - icalerror_check_arg_rz( (v!=0),"v"); + icalerror_check_arg_rv( (v!=0),"v"); icalerror_check_arg_rv( (param!=0), "param"); icalerror_clear_errno(); @@ -1329,7 +1370,7 @@ char* icalparameter_get_fmttype(icalparameter* param) void icalparameter_set_fmttype(icalparameter* param, char* v) { - icalerror_check_arg_rz( (v!=0),"v"); + icalerror_check_arg_rv( (v!=0),"v"); icalerror_check_arg_rv( (param!=0), "param"); icalerror_clear_errno(); @@ -1365,7 +1406,7 @@ char* icalparameter_get_language(icalparameter* param) void icalparameter_set_language(icalparameter* param, char* v) { - icalerror_check_arg_rz( (v!=0),"v"); + icalerror_check_arg_rv( (v!=0),"v"); icalerror_check_arg_rv( (param!=0), "param"); icalerror_clear_errno(); @@ -1401,7 +1442,7 @@ char* icalparameter_get_member(icalparameter* param) void icalparameter_set_member(icalparameter* param, char* v) { - icalerror_check_arg_rz( (v!=0),"v"); + icalerror_check_arg_rv( (v!=0),"v"); icalerror_check_arg_rv( (param!=0), "param"); icalerror_clear_errno(); @@ -1473,9 +1514,6 @@ icalparameter_range icalparameter_get_range(icalparameter* param) { icalerror_clear_errno(); icalerror_check_arg( (param!=0), "param"); - if ( ((struct icalparameter_impl*)param)->string != 0){ - return ICAL_PARTSTAT_XNAME; - } return ((struct icalparameter_impl*)param)->data.v_range; @@ -1514,9 +1552,6 @@ icalparameter_related icalparameter_get_related(icalparameter* param) { icalerror_clear_errno(); icalerror_check_arg( (param!=0), "param"); - if ( ((struct icalparameter_impl*)param)->string != 0){ - return ICAL_PARTSTAT_XNAME; - } return ((struct icalparameter_impl*)param)->data.v_related; @@ -1637,9 +1672,6 @@ int icalparameter_get_rsvp(icalparameter* param) { icalerror_clear_errno(); icalerror_check_arg( (param!=0), "param"); - if ( ((struct icalparameter_impl*)param)->string != 0){ - return ICAL_ROLE_XNAME; - } return ((struct icalparameter_impl*)param)->data.v_rsvp; @@ -1683,7 +1715,7 @@ char* icalparameter_get_sentby(icalparameter* param) void icalparameter_set_sentby(icalparameter* param, char* v) { - icalerror_check_arg_rz( (v!=0),"v"); + icalerror_check_arg_rv( (v!=0),"v"); icalerror_check_arg_rv( (param!=0), "param"); icalerror_clear_errno(); @@ -1719,7 +1751,7 @@ char* icalparameter_get_tzid(icalparameter* param) void icalparameter_set_tzid(icalparameter* param, char* v) { - icalerror_check_arg_rz( (v!=0),"v"); + icalerror_check_arg_rv( (v!=0),"v"); icalerror_check_arg_rv( (param!=0), "param"); icalerror_clear_errno(); @@ -1796,7 +1828,7 @@ char* icalparameter_get_x(icalparameter* param) void icalparameter_set_x(icalparameter* param, char* v) { - icalerror_check_arg_rz( (v!=0),"v"); + icalerror_check_arg_rv( (v!=0),"v"); icalerror_check_arg_rv( (param!=0), "param"); icalerror_clear_errno(); @@ -1827,9 +1859,6 @@ icalparameter_xlicerrortype icalparameter_get_xlicerrortype(icalparameter* param { icalerror_clear_errno(); icalerror_check_arg( (param!=0), "param"); - if ( ((struct icalparameter_impl*)param)->string != 0){ - return ICAL_VALUE_XNAME; - } return ((struct icalparameter_impl*)param)->data.v_xlicerrortype; @@ -1868,9 +1897,6 @@ icalparameter_xliccomparetype icalparameter_get_xliccomparetype(icalparameter* p { icalerror_clear_errno(); icalerror_check_arg( (param!=0), "param"); - if ( ((struct icalparameter_impl*)param)->string != 0){ - return ICAL_VALUE_XNAME; - } return ((struct icalparameter_impl*)param)->data.v_xliccomparetype; diff --git a/libical/src/libical/icalparser.c b/libical/src/libical/icalparser.c index b4c1822a68..8541ae4fab 100644 --- a/libical/src/libical/icalparser.c +++ b/libical/src/libical/icalparser.c @@ -16,25 +16,30 @@ 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 + The Initial Developer of the Original Code is Eric Busboom (C) COPYRIGHT 1999 The Software Studio. http://www.softwarestudio.org ======================================================================*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + #include "ical.h" #include "pvl.h" #include "icalparser.h" #include "icalmemory.h" -#include <string.h> /* For strncpy */ +#include <string.h> /* For strncpy & size_t */ #include <stdio.h> /* For FILE and fgets and sprintf */ #include <stdlib.h> /* for free */ extern icalvalue* icalparser_yy_value; void set_parser_value_state(icalvalue_kind kind); -int icalparser_yyparse(void); +int ical_yy_parse(void); char* icalparser_get_next_char(char c, char *str); char* icalparser_get_next_parameter(char* line,char** end); @@ -42,7 +47,77 @@ char* icalparser_get_next_value(char* line, char **end, icalvalue_kind kind); char* icalparser_get_prop_name(char* line, char** end); char* icalparser_get_param_name(char* line, char **end); -icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind, char* str, icalproperty **error); +#define TMP_BUF_SIZE 80 + +struct icalparser_impl +{ + int buffer_full; + size_t tmp_buf_size; + char temp[TMP_BUF_SIZE]; + icalcomponent *root_component; + icalcomponent *tail; + int version; + int level; + int lineno; + icalparser_state state; + pvl_list components; + + void *line_gen_data; + +}; + + +icalparser* icalparser_new() +{ + struct icalparser_impl* impl = 0; + + if ( ( impl = (struct icalparser_impl*) + malloc(sizeof(struct icalparser_impl))) == 0) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return 0; + } + + impl->root_component = 0; + impl->components = pvl_newlist(); + impl->level = 0; + impl->state = ICALPARSER_SUCCESS; + + impl->tmp_buf_size = TMP_BUF_SIZE; + impl->buffer_full = 0; + impl->lineno = 0; + + memset(impl->temp,0, TMP_BUF_SIZE); + + return (icalparser*)impl; +} + +void icalparser_free(icalparser* parser) +{ + struct icalparser_impl* impl = (struct icalparser_impl*)parser; + icalcomponent *c; + + if (impl->root_component != 0){ + icalcomponent_free(impl->root_component); + } + + while( (c=pvl_pop(impl->components)) != 0){ + icalcomponent_free(c); + } + + pvl_free(impl->components); +} + +void icalparser_set_gen_data(icalparser* parser, void* data) +{ + struct icalparser_impl* impl = (struct icalparser_impl*)parser; + + impl->line_gen_data = data; +} + + +icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind, + char* str, + icalproperty **error); @@ -114,7 +189,7 @@ void icalparser_clear_flex_input() /* Cal the flex parser to parse a complex value */ icalvalue* icalparser_parse_value(icalvalue_kind kind, - char* str, icalproperty** error) + char* str, icalproperty** error) { int r; input_buffer_p = input_buffer = str; @@ -122,7 +197,7 @@ icalvalue* icalparser_parse_value(icalvalue_kind kind, set_parser_value_state(kind); icalparser_yy_value = 0; - r = icalparser_yyparse(); + r = ical_yy_parse(); /* Error. Parse failed */ if( icalparser_yy_value == 0 || r != 0){ @@ -176,7 +251,7 @@ char* icalparser_get_param_name(char* line, char **end) next = icalparser_get_next_char('=',line); if (next == 0) { - return 0; + return 0; } str = make_segment(line,next); @@ -223,50 +298,50 @@ char* icalparser_get_next_value(char* line, char **end, icalvalue_kind kind) p = line; while(1){ - next = icalparser_get_next_char(',',p); + next = icalparser_get_next_char(',',p); - /* Unforunately, RFC2445 says that for the RECUR value, COMMA - can both seperate digits in a list, and it can seperate - multiple recurrence specifications. This is not a friendly - part of the spec. This weirdness tries to - distinguish the two uses. it is probably a HACK*/ + /* Unforunately, RFC2445 says that for the RECUR value, COMMA + can both seperate digits in a list, and it can seperate + multiple recurrence specifications. This is not a friendly + part of the spec. This weirdness tries to + distinguish the two uses. it is probably a HACK*/ - if( kind == ICAL_RECUR_VALUE ) { - if ( next != 0 && - (*end+length) > next+5 && - strncmp(next,"FREQ",4) == 0 - ) { - /* The COMMA was followed by 'FREQ', is it a real seperator*/ - /* Fall through */ - printf("%s\n",next); - } else if (next != 0){ - /* Not real, get the next COMMA */ - p = next+1; - next = 0; - continue; - } - } - - /* If the comma is preceeded by a '\', then it is a literal and - not a value seperator*/ + if( kind == ICAL_RECUR_VALUE ) { + if ( next != 0 && + (*end+length) > next+5 && + strncmp(next,"FREQ",4) == 0 + ) { + /* The COMMA was followed by 'FREQ', is it a real seperator*/ + /* Fall through */ + printf("%s\n",next); + } else if (next != 0){ + /* Not real, get the next COMMA */ + p = next+1; + next = 0; + continue; + } + } + + /* If the comma is preceeded by a '\', then it is a literal and + not a value seperator*/ - if ( (next!=0 && *(next-1) == '\\') || - (next!=0 && *(next-3) == '\\') - ) - /*second clause for '/' is on prev line. HACK may be out of bounds */ - { - p = next+1; - } else { - break; - } + if ( (next!=0 && *(next-1) == '\\') || + (next!=0 && *(next-3) == '\\') + ) + /*second clause for '/' is on prev line. HACK may be out of bounds */ + { + p = next+1; + } else { + break; + } } if (next == 0){ next = (char*)(size_t)line+length; - *end = next; + *end = next; } else { - *end = next+1; + *end = next+1; } if (next == line){ @@ -305,22 +380,18 @@ char* icalparser_get_next_parameter(char* line,char** end) } } -/* HACK. This is not threadsafe */ -int buffer_full=0; -size_t tmp_buf_size = 80; -char temp[80]; - - /* Get a single property line, from the property name through the final new line, and include any continuation lines */ -char* icalparser_get_line(char* (*line_gen_func)(char *s, size_t size, void *d), int *lineno) +char* icalparser_get_line(icalparser *parser, + char* (*line_gen_func)(char *s, size_t size, void *d)) { char *line; char *line_p; - size_t buf_size = tmp_buf_size; - + struct icalparser_impl* impl = (struct icalparser_impl*)parser; + size_t buf_size = impl->tmp_buf_size; + line_p = line = icalmemory_new_buffer(buf_size); line[0] = '\0'; @@ -328,43 +399,63 @@ char* icalparser_get_line(char* (*line_gen_func)(char *s, size_t size, void *d), /* The buffer is not clear, so transfer the data in it to the output. This may be left over from a previous call */ - if (temp[0] != '\0' ) { - if (temp[tmp_buf_size-1] == 0){ - buffer_full = 1; + if (impl->temp[0] != '\0' ) { + + /* If the last position in the temp buffer is occupied, + mark the buffer as full. The means we will do another + read later, because the line is not finished */ + if (impl->temp[impl->tmp_buf_size-1] == 0){ + impl->buffer_full = 1; } else { - buffer_full = 0; + impl->buffer_full = 0; } - icalmemory_append_string(&line,&line_p,&buf_size,temp); - temp[0] = '\0' ; + + /* Copy the temp to the output and clear the temp buffer. */ + icalmemory_append_string(&line,&line_p,&buf_size,impl->temp); + impl->temp[0] = '\0' ; } - temp[tmp_buf_size-1] = 1; /* Mark end of buffer */ + impl->temp[impl->tmp_buf_size-1] = 1; /* Mark end of buffer */ + + if ((*line_gen_func)(impl->temp,impl->tmp_buf_size,impl->line_gen_data) + ==0){/* Get more data */ + + /* If the first position is clear, it means we didn't get + any more data from the last call to line_ge_func*/ + if (impl->temp[0] == '\0'){ - if ((*line_gen_func)(temp,tmp_buf_size,0)==0){/* Get more data */ - if (temp[0] == '\0'){ if(line[0] != '\0'){ + /* There is data in the output, so fall trhough and process it*/ break; } else { + /* No data in output; return and signal that there + is no more input*/ free(line); return 0; } } } + + + /* If the output line ends in a '\n' and the temp buffer + begins with a ' ', then the buffer holds a continuation + line, so keep reading. */ - if ( line_p > line+1 && *(line_p-1) == '\n' && temp[0] == ' ') { - - /* If the output line ends in a '\n' and the temp buffer - begins with a ' ', then the buffer holds a continuation - line, so keep reading. */ + if ( line_p > line+1 && *(line_p-1) == '\n' && impl->temp[0] == ' ') { /* back up the pointer to erase the continuation characters */ line_p--; + if ( *(line_p-1) == '\r'){ + line_p--; + } + /* shift the temp buffer down to eliminate the leading space*/ - memmove(&(temp[0]),&(temp[1]),tmp_buf_size); - temp[tmp_buf_size-1] = temp[tmp_buf_size-2]; + memmove(&(impl->temp[0]),&(impl->temp[1]),impl->tmp_buf_size); + + impl->temp[impl->tmp_buf_size-1] = impl->temp[impl->tmp_buf_size-2]; - } else if ( buffer_full == 1 ) { + } else if ( impl->buffer_full == 1 ) { /* The buffer was filled on the last read, so read again */ @@ -377,10 +468,13 @@ char* icalparser_get_line(char* (*line_gen_func)(char *s, size_t size, void *d), } - /* Erase the final newline */ - if ( line_p > line+1 && *(line_p-1) == '\n') { - + /* Erase the final newline and/or carriage return*/ + if ( line_p > line+1 && *(line_p-1) == '\n') { *(line_p-1) = '\0'; + if ( *(line_p-2) == '\r'){ + *(line_p-2) = '\0'; + } + } else { *(line_p) = '\0'; } @@ -389,111 +483,6 @@ char* icalparser_get_line(char* (*line_gen_func)(char *s, size_t size, void *d), } -#if 0 -char* icalparser_old_get_line(char* (*line_gen_func)(char *s, size_t size, void *d), int *lineno) -{ - char *line, *output_line; - char *line_p; - char last_line = 0; - size_t buf_size = tmp_buf_size; - int break_flag = 0; - - line_p = line = icalmemory_new_buffer(buf_size); - - /* If the hold buffer is empty, read a line. Otherwise, use the data that - is still in 'temp'*/ - if (hold == 1){ - /* Do nothing */ - } else { - temp[tmp_buf_size-1] = 1; /* Mark end of buffer */ - (*line_gen_func)(temp,tmp_buf_size,0); - } - - /* Append the hold buffer or new line into the output */ - icalmemory_append_string(&line,&line_p,&buf_size,temp); - - if ( temp[tmp_buf_size-1] == 0 ) { /* Check if mark was overwritten */ - buffer_full = 1; - } else { - buffer_full = 0; - } - - /* Try to suck up any continuation lines */ - while(last_line == 0){ - - temp[tmp_buf_size-1] = 1; /* Mark end of buffer */ - if ((*line_gen_func)(temp,tmp_buf_size,0) == 0){ - /* No more lines -- we are finished */ - if (hold == 1) { - hold = 0; - break_flag = 1; - } else { - icalmemory_free_buffer(line); - return 0; - } - } else { - if ( temp[tmp_buf_size-1] == 0 ) { - buffer_full = 1; - } else { - buffer_full = 0; - } - } - - /* keep track of line numbers */ - if (lineno != 0){ - (*lineno)++; - } - - - /* Determine wether to copy the line to the output, or - save it in the hold buffer */ - - if ( line_p > line+1 && *(line_p-1) == '\n' && temp[0] == ' ') { - - /* If the last line ( in the 'line' string ) ends in a '\n' - and the current line begins with a ' ', then the current line - is a continuation line, so append it. */ - - /* back up the pointer to erase the continuation characters */ - line_p--; - icalmemory_append_string(&line,&line_p,&buf_size,&(temp[1])); - - hold = 0; - buffer_full= 0; - - } else if (buffer_full == 1) { - - /* The last line that was read filled up the read - buffer. Append it and read again */ - - icalmemory_append_string(&line,&line_p,&buf_size,temp); - - hold = 0; - - } else if (break_flag != 1 ){ - /* Nope -- the line was not a continuation line. - Save the line for the next call */ - - hold =1; - break; - } else { - break; - } - } - - /* Erase the final newline */ - if ( line_p > line+1 && *(line_p-1) == '\n') { - - *(line_p-1) = '\0'; - } - - output_line = icalmemory_tmp_copy(line); - icalmemory_free_buffer(line); - - return output_line; -} -#endif - void insert_error(icalcomponent* comp, char* text, char* message, icalparameter_xlicerrortype type) { @@ -513,389 +502,489 @@ void insert_error(icalcomponent* comp, char* text, 0)); } -icalcomponent* icalparser_parse(char* (*line_gen_func)(char *s, size_t size, void* d)) +icalcomponent* icalparser_parse(icalparser *parser, + char* (*line_gen_func)(char *s, size_t size, + void* d)) { - char *line = 0; + char* line; + icalcomponent *c=0; + icalcomponent *root_component=0; + + icalerror_check_arg_rz((parser !=0),"parser"); + + do{ + line = icalparser_get_line(parser, line_gen_func); + + if ((c = icalparser_add_line(parser,line)) != 0){ + if (root_component == 0){ + /* Just one component */ + icalparser_claim(parser); + root_component = c; + } else if(icalcomponent_isa(root_component) + != ICAL_XROOT_COMPONENT) { + /*Got a second component, so move the two components under + an XROOT container */ + icalcomponent *tempc; + tempc = icalcomponent_new(ICAL_XROOT_COMPONENT); + icalcomponent_add_component(tempc, root_component); + icalparser_claim(parser); + icalcomponent_add_component(tempc, c); + root_component = tempc; + } else { + /* Already have an XROOT container, so add the component + to it*/ + icalcomponent_add_component(root_component, c); + icalparser_claim(parser); + } + } + } while ( line != 0); + + return root_component; + +} + +icalcomponent* icalparser_add_line(icalparser* parser, + char* line) +{ char *p; char *str; char *end; - int lineno = 0; - int vcount = 0; - - icalcomponent *root_component = 0; - icalcomponent *tail = 0; icalproperty *prop; icalvalue *value; + icalvalue_kind value_kind = ICAL_NO_VALUE; - icalvalue_kind value_kind; - - pvl_list components = pvl_newlist(); - - do { - value_kind = ICAL_NO_VALUE; + struct icalparser_impl *impl = (struct icalparser_impl*)parser; + icalerror_check_arg_rz((parser != 0),"parser"); - /* Get a single property line, from a property name through a - newline */ - if (line!=0){ - free(line); - } - - line = icalparser_get_line(line_gen_func,&lineno); - if (line == 0){ - continue; - } + if (line == 0) + { + impl->state = ICALPARSER_ERROR; + return 0; + } - end = 0; + /* Begin by getting the property name at the start of the line. The + property name may end up being "BEGIN" or "END" in which case it + is not really a property, but the market for the start or end of + a component */ - str = icalparser_get_prop_name(line, &end); + end = 0; + str = icalparser_get_prop_name(line, &end); - if (str == 0){ - tail = pvl_data(pvl_tail(components)); + if (str == 0){ + /* Could not get a property name */ + icalcomponent *tail = pvl_data(pvl_tail(impl->components)); - if (tail){ - insert_error(tail,line, - "Got a data line, but could not find a property name or component begin tag", - ICAL_XLICERRORTYPE_COMPONENTPARSEERROR); - } - tail = 0; - continue; + if (tail){ + insert_error(tail,line, + "Got a data line, but could not find a property name or component begin tag", + ICAL_XLICERRORTYPE_COMPONENTPARSEERROR); } + tail = 0; + impl->state = ICALPARSER_ERROR; + return 0; + } -/********************************************************************** - * Handle begin and end of components - **********************************************************************/ + /********************************************************************** + * Handle begin and end of components + **********************************************************************/ - /* If the property name is BEGIN or END, we are actually - starting or ending a new component */ + /* If the property name is BEGIN or END, we are actually + starting or ending a new component */ - if(strcmp(str,"BEGIN") == 0){ - icalcomponent *c; ; + if(strcmp(str,"BEGIN") == 0){ + icalcomponent *c; - str = icalparser_get_next_value(end,&end, value_kind); + impl->level++; + str = icalparser_get_next_value(end,&end, value_kind); - c = icalcomponent_new_from_string(str); + c = icalcomponent_new_from_string(str); - if (c == 0){ - c = icalcomponent_new(ICAL_XLICINVALID_COMPONENT); - insert_error(c,str,"Parse error in component name", - ICAL_XLICERRORTYPE_COMPONENTPARSEERROR); - } + if (c == 0){ + c = icalcomponent_new(ICAL_XLICINVALID_COMPONENT); + insert_error(c,str,"Parse error in component name", + ICAL_XLICERRORTYPE_COMPONENTPARSEERROR); + } - pvl_push(components,c); + pvl_push(impl->components,c); - continue; - } else if (strcmp(str,"END") == 0 ) { + impl->state = ICALPARSER_BEGIN_COMP; + return 0; - str = icalparser_get_next_value(end,&end, value_kind); + } else if (strcmp(str,"END") == 0 ) { + icalcomponent* tail; - root_component = pvl_pop(components); + impl->level--; + str = icalparser_get_next_value(end,&end, value_kind); - tail = pvl_data(pvl_tail(components)); + impl->root_component = pvl_pop(impl->components); - if(tail != 0){ - icalcomponent_add_component(tail,root_component); - } + tail = pvl_data(pvl_tail(impl->components)); - tail = 0; - continue; + if(tail != 0){ + icalcomponent_add_component(tail,impl->root_component); } + tail = 0; - /* There is no point in continuing if we have not seen a - component yet */ - - if(pvl_data(pvl_tail(components)) == 0){ - continue; + /* Return the component if we are back to the 0th level */ + if (impl->level == 0){ + impl->state = ICALPARSER_SUCCESS; + return impl->root_component; + } else { + impl->state = ICALPARSER_END_COMP; + return 0; } + } + + + /* There is no point in continuing if we have not seen a + component yet */ + if(pvl_data(pvl_tail(impl->components)) == 0){ + impl->state = ICALPARSER_ERROR; + return 0; + } -/********************************************************************** - * Handle property names - **********************************************************************/ - /* At this point, the property name really is a property name, - (Not a component name) so make a new property and add it to - the component */ - prop = icalproperty_new_from_string(str); + /********************************************************************** + * Handle property names + **********************************************************************/ + /* At this point, the property name really is a property name, + (Not a component name) so make a new property and add it to + the component */ - if (prop != 0){ - tail = pvl_data(pvl_tail(components)); + prop = icalproperty_new_from_string(str); - icalcomponent_add_property(tail, prop); + if (prop != 0){ + icalcomponent *tail = pvl_data(pvl_tail(impl->components)); - /* Set the value kind for the default for this type of - property. This may be re-set by a VALUE parameter */ - value_kind = - icalenum_property_kind_to_value_kind( - icalproperty_isa(prop)); - } else { - icalcomponent* tail = pvl_data(pvl_tail(components)); + icalcomponent_add_property(tail, prop); + + /* Set the value kind for the default for this type of + property. This may be re-set by a VALUE parameter */ + value_kind = + icalenum_property_kind_to_value_kind( + icalproperty_isa(prop)); - insert_error(tail,str,"Parse error in property name", - ICAL_XLICERRORTYPE_PROPERTYPARSEERROR); + } else { + icalcomponent* tail = pvl_data(pvl_tail(impl->components)); + + insert_error(tail,str,"Parse error in property name", + ICAL_XLICERRORTYPE_PROPERTYPARSEERROR); - tail = 0; - continue; - } + tail = 0; + impl->state = ICALPARSER_ERROR; + return 0; + } -/********************************************************************** - * Handle parameter values - **********************************************************************/ + /********************************************************************** + * Handle parameter values + **********************************************************************/ - /* Now, add any parameters to the last property */ + /* Now, add any parameters to the last property */ - p = 0; - while(1) { + p = 0; + while(1) { - if (*(end-1) == ':'){ - /* if the last seperator was a ":" and the value is a - URL, icalparser_get_next_parameter will find the - ':' in the URL, so better break now. */ - break; - } + if (*(end-1) == ':'){ + /* if the last seperator was a ":" and the value is a + URL, icalparser_get_next_parameter will find the + ':' in the URL, so better break now. */ + break; + } - str = icalparser_get_next_parameter(end,&end); + str = icalparser_get_next_parameter(end,&end); - if (str != 0){ - char* name; - char* pvalue; - icalparameter *param = 0; - icalparameter_kind kind; - - tail = pvl_data(pvl_tail(components)); + if (str != 0){ + char* name; + char* pvalue; + + icalparameter *param = 0; + icalparameter_kind kind; + icalcomponent *tail = pvl_data(pvl_tail(impl->components)); - name = icalparser_get_param_name(str,&pvalue); + name = icalparser_get_param_name(str,&pvalue); - if (name == 0){ - insert_error(tail, str, "Can't parse parameter name", - ICAL_XLICERRORTYPE_PARAMETERPARSEERROR); - tail = 0; - break; - } + if (name == 0){ + /* 'tail' defined above */ + insert_error(tail, str, "Can't parse parameter name", + ICAL_XLICERRORTYPE_PARAMETERNAMEPARSEERROR); + tail = 0; + break; + } - kind = icalenum_string_to_parameter_kind(name); - if (kind != ICAL_NO_PARAMETER){ - param = icalparameter_new_from_string(kind,pvalue); - } else { + kind = icalenum_string_to_parameter_kind(name); - /* Error. Failed to parse the parameter*/ - insert_error(tail, str, "Can't parse parameter name", - ICAL_XLICERRORTYPE_PARAMETERPARSEERROR); - tail = 0; - continue; - } + if (kind != ICAL_NO_PARAMETER){ + param = icalparameter_new_from_string(kind,pvalue); + } else { + /* Error. Failed to parse the parameter*/ + /* 'tail' defined above */ + insert_error(tail, str, "Can't parse parameter name", + ICAL_XLICERRORTYPE_PARAMETERNAMEPARSEERROR); + tail = 0; + impl->state = ICALPARSER_ERROR; + return 0; + } - if (param == 0){ - insert_error(tail,str,"Can't parse parameter value", - ICAL_XLICERRORTYPE_PARAMETERPARSEERROR); + if (param == 0){ + /* 'tail' defined above */ + insert_error(tail,str,"Can't parse parameter value", + ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR); - tail = 0; - continue; - } + tail = 0; + impl->state = ICALPARSER_ERROR; + continue; + } - /* If it is a VALUE parameter, set the kind of value*/ - if (icalparameter_isa(param)==ICAL_VALUE_PARAMETER){ + /* If it is a VALUE parameter, set the kind of value*/ + if (icalparameter_isa(param)==ICAL_VALUE_PARAMETER){ - value_kind = (icalvalue_kind) - icalparameter_get_value(param); + value_kind = (icalvalue_kind) + icalparameter_get_value(param); - if (value_kind == ICAL_NO_VALUE){ + if (value_kind == ICAL_NO_VALUE){ - /* Ooops, could not parse the value of the - parameter ( it was not one of the defined - values ), so reset the value_kind */ + /* Ooops, could not parse the value of the + parameter ( it was not one of the defined + values ), so reset the value_kind */ - icalcomponent* tail - = pvl_data(pvl_tail(components)); + insert_error( + tail, str, + "Got a VALUE parameter with an unknown type", + ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR); + icalparameter_free(param); - insert_error( - tail, str, - "Got a VALUE parameter with an unknown type", - ICAL_XLICERRORTYPE_PARAMETERPARSEERROR); - icalparameter_free(param); + value_kind = + icalenum_property_kind_to_value_kind( + icalproperty_isa(prop)); - value_kind = - icalenum_property_kind_to_value_kind( - icalproperty_isa(prop)); - - icalparameter_free(param); - tail = 0; - continue; - } - } + icalparameter_free(param); + tail = 0; + impl->state = ICALPARSER_ERROR; + return 0; + } + } - /* Everything is OK, so add the parameter */ - icalproperty_add_parameter(prop,param); - tail = 0; + /* Everything is OK, so add the parameter */ + icalproperty_add_parameter(prop,param); + tail = 0; - } else { - /* If we did not get a param string, go on to looking - for a value */ - break; - } - } + } else { /* if ( str != 0) */ + /* If we did not get a param string, go on to looking + for a value */ + break; + } /* if ( str != 0) */ + + } /* while(1) */ -/********************************************************************** - * Handle values - **********************************************************************/ + /********************************************************************** + * Handle values + **********************************************************************/ - /* Look for values. If there are ',' characters in the values, - then there are multiple values, so clone the current - parameter and add one part of the value to each clone */ + /* Look for values. If there are ',' characters in the values, + then there are multiple values, so clone the current + parameter and add one part of the value to each clone */ - vcount=0; - while(1) { - str = icalparser_get_next_value(end,&end, value_kind); + vcount=0; + while(1) { + str = icalparser_get_next_value(end,&end, value_kind); - if (str != 0){ + if (str != 0){ - if (vcount > 0){ - /* Actually, only clone after the second value */ - icalproperty* clone = icalproperty_new_clone(prop); - tail = pvl_data(pvl_tail(components)); + if (vcount > 0){ + /* Actually, only clone after the second value */ + icalproperty* clone = icalproperty_new_clone(prop); + icalcomponent* tail = pvl_data(pvl_tail(impl->components)); - icalcomponent_add_property(tail, clone); - prop = clone; - tail = 0; - } + icalcomponent_add_property(tail, clone); + prop = clone; + tail = 0; + } - value = icalvalue_new_from_string(value_kind, str); + value = icalvalue_new_from_string(value_kind, str); - /* Don't add properties without value */ - if (value == 0){ - char temp[1024]; + /* Don't add properties without value */ + if (value == 0){ + char temp[200]; /* HACK */ - icalproperty_kind prop_kind = icalproperty_isa(prop); - tail = pvl_data(pvl_tail(components)); + icalproperty_kind prop_kind = icalproperty_isa(prop); + icalcomponent* tail = pvl_data(pvl_tail(impl->components)); - sprintf(temp,"Can't parse as %s value in %s property. Removing entire property", - icalenum_value_kind_to_string(value_kind), - icalenum_property_kind_to_string(prop_kind)); + sprintf(temp,"Can't parse as %s value in %s property. Removing entire property", + icalenum_value_kind_to_string(value_kind), + icalenum_property_kind_to_string(prop_kind)); - insert_error(tail, str, temp, - ICAL_XLICERRORTYPE_VALUEPARSEERROR); + insert_error(tail, str, temp, + ICAL_XLICERRORTYPE_VALUEPARSEERROR); - /* Remove the troublesome property */ - icalcomponent_remove_property(tail,prop); - icalproperty_free(prop); - prop = 0; - tail = 0; - break; + /* Remove the troublesome property */ + icalcomponent_remove_property(tail,prop); + icalproperty_free(prop); + prop = 0; + tail = 0; + impl->state = ICALPARSER_ERROR; + return 0; - } else { - vcount++; - icalproperty_set_value(prop, value); - } + } else { + vcount++; + icalproperty_set_value(prop, value); + } - } else { + } else { + if (vcount == 0){ + char temp[200]; /* HACK */ + icalproperty_kind prop_kind = icalproperty_isa(prop); + icalcomponent *tail = pvl_data(pvl_tail(impl->components)); + + sprintf(temp,"No value for %s property. Removing entire property", + icalenum_property_kind_to_string(prop_kind)); + + insert_error(tail, str, temp, + ICAL_XLICERRORTYPE_VALUEPARSEERROR); + + /* Remove the troublesome property */ + icalcomponent_remove_property(tail,prop); + icalproperty_free(prop); + prop = 0; + tail = 0; + impl->state = ICALPARSER_ERROR; + return 0; + } else { + break; } } + } - } while( !feof(stdin) && line !=0 ); + /**************************************************************** + * End of component parsing. + *****************************************************************/ - - if (pvl_data(pvl_tail(components)) == 0){ - /* A nice, clean exit */ - pvl_free(components); - free(line); - return root_component; + if (pvl_data(pvl_tail(impl->components)) == 0 && + impl->level == 0){ + impl->state = ICALPARSER_SUCCESS; + return impl->root_component; + } else { + impl->state = ICALPARSER_IN_PROGRESS; + return 0; } - /* Clear off any component that may be left in the list */ - /* This will happen if some components did not have an "END" tag*/ +} + +icalparser_state icalparser_get_state(icalparser* parser) +{ + struct icalparser_impl* impl = (struct icalparser_impl*) parser; + return impl->state; + +} + +icalcomponent* icalparser_claim(icalparser* parser) +{ + struct icalparser_impl* impl = (struct icalparser_impl*) parser; + icalcomponent *c = impl->root_component; + + impl->root_component = 0; + + return c; + +} + + +icalcomponent* icalparser_clean(icalparser* parser) +{ + struct icalparser_impl* impl = (struct icalparser_impl*) parser; + icalcomponent *tail = pvl_data(pvl_tail(impl->components)); - while((tail=pvl_data(pvl_tail(components))) != 0){ + icalerror_check_arg_rz((parser != 0 ),"parser"); + + /* We won't get a clean exit if some components did not have an + "END" tag. Clear off any component that may be left in the list */ + + + while((tail=pvl_data(pvl_tail(impl->components))) != 0){ insert_error(tail," ", "Missing END tag for this component. Closing component at end of input.", ICAL_XLICERRORTYPE_COMPONENTPARSEERROR); - root_component = pvl_pop(components); - tail=pvl_data(pvl_tail(components)); + impl->root_component = pvl_pop(impl->components); + tail=pvl_data(pvl_tail(impl->components)); if(tail != 0){ - icalcomponent_add_component(tail,root_component); + icalcomponent_add_component(tail,impl->root_component); } } - free(line); - return root_component; + return impl->root_component; + } -char* string_line_generator_pos=0; -char* string_line_generator_str; +struct slg_data { + char* pos; + char* str; +}; + char* string_line_generator(char *out, size_t buf_size, void *d) { char *n; - - if(string_line_generator_pos==0){ - string_line_generator_pos=string_line_generator_str; + size_t size; + struct slg_data* data = (struct slg_data*)d; + + if(data->pos==0){ + data->pos=data->str; } /* If the pointer is at the end of the string, we are done */ - if (*string_line_generator_pos ==0){ + if (*(data->pos)==0){ return 0; } - n = strchr(string_line_generator_pos,'\n'); + n = strchr(data->pos,'\n'); - /* If no newline, take the rest of the string, and leave the - pointer at the \0 */ - - if (n == 0) { - n = string_line_generator_pos + strlen(string_line_generator_pos); + if (n == 0){ + size = strlen(data->pos); } else { - n++; + n++; /* include newline in output */ + size = (n-data->pos); } - strncpy(out,string_line_generator_pos,(n-string_line_generator_pos)); - - *(out+(n-string_line_generator_pos)) = '\0'; - - string_line_generator_pos = n; - - return out; + if (size > buf_size-1){ + size = buf_size-1; + } -} -void _test_string_line_generator(char* str) -{ - char *line; - int lineno=0; - string_line_generator_str = str; - string_line_generator_pos = 0; - - while((line = icalparser_get_line(string_line_generator,&lineno))){ - printf("#%d: %s\n",lineno,line); - } + strncpy(out,data->pos,size); + *(out+size) = '\0'; - string_line_generator_pos = 0; - string_line_generator_str = 0; -} - + data->pos += size; + return out; +} icalcomponent* icalparser_parse_string(char* str) { - icalcomponent *c; - - string_line_generator_str = str; - string_line_generator_pos = 0; - c = icalparser_parse(string_line_generator); - string_line_generator_pos = 0; - string_line_generator_str = 0; - + struct slg_data d; + icalparser *p; + + d.pos = 0; + d.str = str; + + p = icalparser_new(); + icalparser_set_gen_data(p,&d); + c = icalparser_parse(p,string_line_generator); + icalparser_free(p); + return c; } diff --git a/libical/src/libical/icalparser.h b/libical/src/libical/icalparser.h index 9e47e38bfb..25c07eca9f 100644 --- a/libical/src/libical/icalparser.h +++ b/libical/src/libical/icalparser.h @@ -31,6 +31,16 @@ #include "ical.h" #include <stdio.h> /* For FILE* */ +typedef void* icalparser; +typedef enum icalparser_state { + ICALPARSER_ERROR, + ICALPARSER_SUCCESS, + ICALPARSER_BEGIN_COMP, + ICALPARSER_END_COMP, + ICALPARSER_IN_PROGRESS +} icalparser_state; + + /*********************************************************************** * Message oriented parsing. icalparser_parse takes a string that * holds the text ( in RFC 2445 format ) and returns a pointer to an @@ -38,29 +48,28 @@ * pointer to a function that returns one content line per invocation **********************************************************************/ -icalcomponent* icalparser_parse(char* (*line_gen_func)()); +icalcomponent* icalparser_parse(icalparser *parser, + char* (*line_gen_func)(char *s, size_t size, void *d)); -/* Parse directly from a string */ +/* A simple, and incorrect interface - can only return one component*/ icalcomponent* icalparser_parse_string(char* str); -/* icalparser_flex_input is the routine that is called from the macro - YYINPUT in the flex lexer. */ -int icalparser_flex_input(char* buf, int max_size); -void icalparser_clear_flex_input(); /*********************************************************************** * Line-oriented parsing. * * Create a new parser via icalparse_new_parser, then add ines one at - * a time with icalparse_add_line(). After adding the last line, call - * icalparse_close() to return the parsed component. + * a time with icalparse_add_line(). icalparser_add_line() will return + * non-zero when it has finished with a component. ***********************************************************************/ -/* These are not implemented yet */ -typedef void* icalparser; -icalparser icalparse_new_parser(); -void icalparse_add_line(icalparser* parser ); -icalcomponent* icalparse_close(icalparser* parser); +icalparser* icalparser_new(); +void icalparser_set_gen_data(icalparser* parser, void* data); +icalcomponent* icalparser_add_line(icalparser* parser, char* str ); +icalcomponent* icalparser_claim(icalparser* parser); +icalcomponent* icalparser_clean(icalparser* parser); +icalparser_state icalparser_get_state(icalparser* parser); +void icalparser_free(icalparser* parser); /*********************************************************************** * Parser support functions @@ -69,11 +78,17 @@ icalcomponent* icalparse_close(icalparser* parser); /* Use the flex/bison parser to turn a string into a value type */ icalvalue* icalparser_parse_value(icalvalue_kind kind, char* str, icalcomponent** errors); -char* icalparser_get_line(char* (*line_gen_func)(char *s, size_t size, void *d), int *lineno); - +/* Given a line generator function, return a single iCal content line.*/ +char* icalparser_get_line(icalparser* parser, char* (*line_gen_func)(char *s, size_t size, void *d)); -/* a line_gen_function that returns lines from a string */ +/* a line_gen_function that returns lines from a string. To use it, + set string_line_generator_str to point to the input string, and set + string_line_generator_pos to 0. These globals make the routine not + thead-safe. */ +extern char* string_line_generator_str; +extern char* string_line_generator_pos; +char* string_line_generator(char *out, size_t buf_size, void *d); #endif /* !ICALPARSE_H */ diff --git a/libical/src/libical/icalproperty.c b/libical/src/libical/icalproperty.c index 3dd761b1f8..c3fe7c9073 100644 --- a/libical/src/libical/icalproperty.c +++ b/libical/src/libical/icalproperty.c @@ -25,6 +25,10 @@ ======================================================================*/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <string.h> /* For strdup, rindex */ #include <assert.h> #include <stdlib.h> @@ -38,6 +42,8 @@ #include "icalerror.h" #include "icalmemory.h" +#define TMP_BUF_SIZE 1024 + /* Private routines for icalproperty */ void icalvalue_set_parent(icalvalue* value, icalproperty* property); @@ -89,7 +95,6 @@ icalproperty_new_impl (icalproperty_kind kind) if ( ( prop = (struct icalproperty_impl*) malloc(sizeof(struct icalproperty_impl))) == 0) { - errno = ENOMEM; icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } @@ -196,7 +201,7 @@ icalproperty_free (icalproperty* prop) icalparameter* param; - icalerror_check_arg_re((prop!=0),"prop",ICAL_BADARG_ERROR); + icalerror_check_arg_rv((prop!=0),"prop"); p = (struct icalproperty_impl*)prop; @@ -254,6 +259,12 @@ icalproperty_as_ical_string (icalproperty* prop) icalvalue* value; char *out_buf; +#ifdef ICAL_UNIX_NEWLINE + char newline[] = "\n"; +#else + char newline[] = "\r\n"; +#endif + struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; icalerror_check_arg_rz( (prop!=0),"prop"); @@ -275,7 +286,7 @@ icalproperty_as_ical_string (icalproperty* prop) icalmemory_append_string(&buf, &buf_ptr, &buf_size, property_name); - icalmemory_append_string(&buf, &buf_ptr, &buf_size, "\n"); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline); /* Append parameters */ for(param = icalproperty_get_first_parameter(prop,ICAL_ANY_PARAMETER); @@ -285,15 +296,15 @@ icalproperty_as_ical_string (icalproperty* prop) char* kind_string = icalparameter_as_ical_string(param); if (kind_string == 0 ) { - char temp[1024]; - sprintf(temp, "Got a parameter of unknown kind in %s property",property_name); + char temp[TMP_BUF_SIZE]; + snprintf(temp, TMP_BUF_SIZE,"Got a parameter of unknown kind in %s property",property_name); icalerror_warn(temp); continue; } icalmemory_append_string(&buf, &buf_ptr, &buf_size, " ;"); icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string); - icalmemory_append_string(&buf, &buf_ptr, &buf_size, "\n"); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline); } @@ -311,7 +322,7 @@ icalproperty_as_ical_string (icalproperty* prop) } - icalmemory_append_string(&buf, &buf_ptr, &buf_size, "\n"); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline); /* Now, copy the buffer to a tmp_buffer, which is safe to give to the caller without worring about de-allocating it. */ @@ -1740,7 +1751,7 @@ void icalproperty_set_requeststatus(icalproperty* prop, char* v) icalerror_check_arg_rv( (prop!=0),"prop"); - value = icalvalue_new_text(v); + value = icalvalue_new_string(v); icalproperty_set_value(prop,value); @@ -1753,7 +1764,7 @@ char* icalproperty_get_requeststatus(icalproperty* prop) value = icalproperty_get_value(prop); - return icalvalue_get_text(value); + return icalvalue_get_string(value); } /* EXDATE */ diff --git a/libical/src/libical/icalrestriction.c b/libical/src/libical/icalrestriction.c index 9393b3ea34..d5ffb784ef 100644 --- a/libical/src/libical/icalrestriction.c +++ b/libical/src/libical/icalrestriction.c @@ -18,9 +18,15 @@ ======================================================================*/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "icalenums.h" #include "icalrestriction.h" +#define TMP_BUF_SIZE 1024 + /* Define the structs for the restrictions. these data are filled out in machine generated code below */ @@ -48,7 +54,9 @@ icalrestriction_property_record icalrestriction_property_records[]; /* The each row gives the result of comparing a restriction against a count. The columns in each row represent 0,1,2+. '-1' indicates - 'invalid, 'don't care' or 'needs more analysis' */ + 'invalid, 'don't care' or 'needs more analysis' So, for + ICAL_RESTRICTION_ONE, if there is 1 of a property with that + restriction, it passes, but if there are 0 or 2+, it fails. */ char compare_map[ICAL_RESTRICTION_UNKNOWN+1][3] = { { 1, 1, 1},/*ICAL_RESTRICTION_NONE*/ @@ -129,9 +137,9 @@ int icalrestriction_check_component(icalproperty_method method, if (compare == 0){ - char temp[1024]; + char temp[TMP_BUF_SIZE]; - sprintf(temp, "Failed iTIP restrictions for property %s. Expected %s instances of the property and got %d", + snprintf(temp, TMP_BUF_SIZE,"Failed iTIP restrictions for property %s. Expected %s instances of the property and got %d", icalenum_property_kind_to_string(kind), restr_string_map[restr], count); diff --git a/libical/src/libical/icaltypes.c b/libical/src/libical/icaltypes.c index 14daa2915d..2800b4857f 100644 --- a/libical/src/libical/icaltypes.c +++ b/libical/src/libical/icaltypes.c @@ -24,15 +24,21 @@ The original code is icaltypes.c ======================================================================*/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include "icaltypes.h" #include "icalerror.h" +#include "icalmemory.h" #include <stdlib.h> /* for malloc */ #include <errno.h> /* for errno */ #include <string.h> /* for strdup */ #include <assert.h> #include <limits.h> /* for SHRT_MAX */ +#define TEMP_MAX 1024 + void* icalattachtype_get_data (struct icalattachtype* type); @@ -198,3 +204,83 @@ void icalrecurrencetype_clear(struct icalrecurrencetype *recur) recur->until.year = 0; recur->count = 0; } + + +struct icalreqstattype icalreqstattype_from_string(char* str) +{ + char *p1,*p2; + size_t len; + struct icalreqstattype stat; + int major, minor; + + icalerror_check_arg((str != 0),"str"); + + stat.code = ICAL_UNKNOWN_STATUS; + stat.debug = 0; + + stat.desc = 0; + + /* Get the status numbers */ + + sscanf(str, "%d.%d",&major, &minor); + + if (major <= 0 || minor < 0){ + icalerror_set_errno(ICAL_BADARG_ERROR); + return stat; + } + + stat.code = icalenum_num_to_reqstat(major, minor); + + if (stat.code == ICAL_UNKNOWN_STATUS){ + icalerror_set_errno(ICAL_BADARG_ERROR); + return stat; + } + + + p1 = strchr(str,';'); + + if (p1 == 0){ + icalerror_set_errno(ICAL_BADARG_ERROR); + return stat; + } + + /* Just ignore the second clause; it will be taken from inside the library + */ + + + + p2 = strchr(p1+1,';'); + if (p2 != 0 && *p2 != 0){ + stat.debug = p2+1; + } + + return stat; + +} + +char* icalreqstattype_as_string(struct icalreqstattype stat) +{ + char format[20]; + char *temp; + + temp = (char*)icalmemory_tmp_buffer(TEMP_MAX); + + icalerror_check_arg_rz((stat.code != ICAL_UNKNOWN_STATUS),"Status"); + + if (stat.desc == 0){ + stat.desc = icalenum_reqstat_desc(stat.code); + } + + if(stat.debug != 0){ + snprintf(temp,TEMP_MAX,"%d.%d;%s;%s", icalenum_reqstat_major(stat.code), + icalenum_reqstat_minor(stat.code), + stat.desc, stat.debug); + + } else { + snprintf(temp,TEMP_MAX,"%d.%d;%s", icalenum_reqstat_major(stat.code), + icalenum_reqstat_minor(stat.code), + stat.desc); + } + + return temp; +} diff --git a/libical/src/libical/icaltypes.h b/libical/src/libical/icaltypes.h index c33e8acd7d..77a67fae80 100644 --- a/libical/src/libical/icaltypes.h +++ b/libical/src/libical/icaltypes.h @@ -157,12 +157,26 @@ union icaltriggertype struct icaldurationtype duration; }; -struct icalrequestsstatustype { - short minor; - short major; +/* struct icalreqstattype. This struct contains two string pointers, +but don't try to free either of them. The "desc" string is a pointer +to a static table inside the library. Don't try to free it. The +"debug" string is a pointer into the string that the called passed +into to icalreqstattype_from_string. Don't try to free it either, and +don't use it after the original string has been freed. +BTW, you would get that original string from +*icalproperty_get_requeststatus() or icalvalue_get_text(), when +operating on a the value of a request_status property. */ + +struct icalreqstattype { + + icalrequeststatus code; + char* desc; + char* debug; }; +struct icalreqstattype icalreqstattype_from_string(char* str); +char* icalreqstattype_as_string(struct icalreqstattype); #endif /* !ICALTYPES_H */ diff --git a/libical/src/libical/icalvalue.c b/libical/src/libical/icalvalue.c index 1ed83a0c6e..ec332a0f04 100644 --- a/libical/src/libical/icalvalue.c +++ b/libical/src/libical/icalvalue.c @@ -28,6 +28,10 @@ ======================================================================*/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "ical.h" #include "icalerror.h" @@ -38,6 +42,7 @@ #include <stdlib.h> /* for malloc */ #include <stdio.h> /* for sprintf */ #include <string.h> /* For memset, others */ +#include <stddef.h> /* For offsetof() macro */ #include <errno.h> #include <time.h> /* for mktime */ #include <stdlib.h> /* for atoi and atof */ @@ -47,6 +52,8 @@ #include "strdup.h" #endif +#define TMP_BUF_SIZE 1024 + void print_datetime_to_string(char* str, struct icaltimetype *data); void print_date_to_string(char* str, struct icaltimetype *data); void print_time_to_string(char* str, struct icaltimetype *data); @@ -97,7 +104,6 @@ struct icalvalue_impl* icalvalue_new_impl(icalvalue_kind kind){ if ( ( v = (struct icalvalue_impl*) malloc(sizeof(struct icalvalue_impl))) == 0) { - errno = ENOMEM; icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } @@ -147,6 +153,7 @@ icalvalue* icalvalue_new_clone(icalvalue* value){ /* HACK ugh. I don't feel like impleenting this */ } + case ICAL_STRING_VALUE: case ICAL_TEXT_VALUE: case ICAL_CALADDRESS_VALUE: case ICAL_URI_VALUE: @@ -207,7 +214,7 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,char* str,ic value = 0; if (error != 0){ - char temp[1024]; + char temp[TMP_BUF_SIZE]; sprintf(temp,"ATTACH Values are not implemented"); *error = icalproperty_vanew_xlicerror( temp, @@ -226,7 +233,7 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,char* str,ic value = 0; if (error != 0){ - char temp[1024]; + char temp[TMP_BUF_SIZE]; sprintf(temp,"BINARY Values are not implemented"); *error = icalproperty_vanew_xlicerror( temp, @@ -245,7 +252,7 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,char* str,ic value = 0; if (error != 0){ - char temp[1024]; + char temp[TMP_BUF_SIZE]; sprintf(temp,"BOOLEAN Values are not implemented"); *error = icalproperty_vanew_xlicerror( temp, @@ -282,6 +289,13 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,char* str,ic break; } + + case ICAL_STRING_VALUE: + { + value = icalvalue_new_string(str); + break; + } + case ICAL_CALADDRESS_VALUE: { value = icalvalue_new_caladdress(str); @@ -298,6 +312,8 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,char* str,ic { icalproperty_method method = icalenum_string_to_method(str); value = icalvalue_new_method(method); + break; + } case ICAL_GEO_VALUE: { @@ -305,7 +321,7 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,char* str,ic /* HACK */ if (error != 0){ - char temp[1024]; + char temp[TMP_BUF_SIZE]; sprintf(temp,"GEO Values are not implemented"); *error = icalproperty_vanew_xlicerror( temp, @@ -337,15 +353,10 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,char* str,ic { if (error != 0 ){ - char temp[1024]; + char temp[TMP_BUF_SIZE]; - if (strlen(str) > 265) { - sprintf(temp,"Unknown type for \'%256s...\'",str); - } else { - sprintf(temp,"Unknown type for \'%s\'",str); + snprintf(temp,TMP_BUF_SIZE,"Unknown type for \'%s\'",str); - } - *error = icalproperty_vanew_xlicerror( temp, icalparameter_new_xlicerrortype( @@ -360,14 +371,9 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,char* str,ic if (error != 0 && *error == 0 && value == 0){ - char temp[1024]; + char temp[TMP_BUF_SIZE]; - if (strlen(str) > 265) { - sprintf(temp,"Failed to parse value: \'%256s...\'",str); - } else { - sprintf(temp,"Failed to parse value: \'%s\'",str); - - } + snprintf(temp,TMP_BUF_SIZE,"Failed to parse value: \'%s\'",str); *error = icalproperty_vanew_xlicerror( temp, @@ -529,20 +535,22 @@ char* icalvalue_recur_as_ical_string(icalvalue* value) struct icalvalue_impl *impl = (struct icalvalue_impl*)value; struct icalrecurrencetype *recur = impl->data.v_recur; - struct { char* str; short* array; short limit; } map[] = - { - {";BYSECOND=",recur->by_second,60}, - {";BYMINUTE=",recur->by_minute,60}, - {";BYHOUR=",recur->by_hour,24}, - {";BYDAY=",recur->by_day,7}, - {";BYMONTHDAY=",recur->by_month_day,31}, - {";BYYEARDAY=",recur->by_year_day,366}, - {";BYWEEKNO=",recur->by_week_no,52}, - {";BYMONTH=",recur->by_month,12}, - {";BYSETPOS=",recur->by_set_pos,366}, - {0,0,0}, - }; - + struct { char* str;size_t offset; short limit; } recurmap[] = + { + {";BYSECOND=",offsetof(struct icalrecurrencetype,by_second),60}, + {";BYMINUTE=",offsetof(struct icalrecurrencetype,by_minute),60}, + {";BYHOUR=",offsetof(struct icalrecurrencetype,by_hour),24}, + {";BYDAY=",offsetof(struct icalrecurrencetype,by_day),7}, + {";BYMONTHDAY=",offsetof(struct icalrecurrencetype,by_month_day),31}, + {";BYYEARDAY=",offsetof(struct icalrecurrencetype,by_year_day),366}, + {";BYWEEKNO=",offsetof(struct icalrecurrencetype,by_week_no),52}, + {";BYMONTH=",offsetof(struct icalrecurrencetype,by_month),12}, + {";BYSETPOS=",offsetof(struct icalrecurrencetype,by_set_pos),366}, + {0,0,0}, + }; + + + icalerror_check_arg_rz((value != 0),"value"); if(recur->freq == ICAL_NO_RECURRENCE){ @@ -577,14 +585,14 @@ char* icalvalue_recur_as_ical_string(icalvalue* value) icalmemory_append_string(&str,&str_p,&buf_sz, temp); } - for(j =0; map[j].str != 0; j++){ - short* array = map[j].array; - short limit = map[j].limit; + for(j =0; recurmap[j].str != 0; j++){ + short* array = (short*)(recurmap[j].offset+ (size_t)recur); + short limit = recurmap[j].limit; /* Skip unused arrays */ if( array[0] != ICAL_RECURRENCE_ARRAY_MAX ) { - icalmemory_append_string(&str,&str_p,&buf_sz,map[j].str); + icalmemory_append_string(&str,&str_p,&buf_sz,recurmap[j].str); for(i=0; i< limit && array[i] != ICAL_RECURRENCE_ARRAY_MAX; i++){ @@ -731,11 +739,11 @@ char* icalvalue_attach_as_ical_string(icalvalue* value) { void append_duration_segment(char** buf, char** buf_ptr, size_t* buf_size, char* sep, unsigned int value) { - char digits[256]; /* HACK: large hardcoded limit */ + char temp[TMP_BUF_SIZE]; - sprintf(digits,"%d",value); + sprintf(temp,"%d",value); - icalmemory_append_string(buf, buf_ptr, buf_size, digits); + icalmemory_append_string(buf, buf_ptr, buf_size, temp); icalmemory_append_string(buf, buf_ptr, buf_size, sep); } @@ -1025,6 +1033,7 @@ icalvalue_as_ical_string (icalvalue* value) case ICAL_TEXT_VALUE: return icalvalue_text_as_ical_string(value); + case ICAL_STRING_VALUE: case ICAL_URI_VALUE: case ICAL_CALADDRESS_VALUE: return icalvalue_string_as_ical_string(value); @@ -1155,7 +1164,7 @@ icalvalue_compare(icalvalue* a, icalvalue *b) case ICAL_DATE_VALUE: case ICAL_DATETIME_VALUE: case ICAL_DATETIMEDATE_VALUE: - case ICAL_DURATION_VALUE: + case ICAL_DURATION_VALUE: /* HACK. Not correct for DURATION */ case ICAL_TIME_VALUE: case ICAL_DATETIMEPERIOD_VALUE: { @@ -1216,7 +1225,9 @@ icalproperty* icalvalue_get_parent(icalvalue* value) -/* Recur is a special case, so it is not auto generated */ +/* Recur is a special case, so it is not auto generated. Well, + actually, it is auto-generated, but you will have to manually + remove the auto-generated version after each generation. */ icalvalue* icalvalue_new_recur (struct icalrecurrencetype v) { @@ -1762,89 +1773,74 @@ icalvalue_get_period(icalvalue* value) icalvalue* -icalvalue_new_text (char* v) +icalvalue_new_string (char* v) { - struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_TEXT_VALUE); + struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_STRING_VALUE); icalerror_check_arg_rz( (v!=0),"v"); - icalvalue_set_text((icalvalue*)impl,v); + icalvalue_set_string((icalvalue*)impl,v); return (icalvalue*)impl; } void -icalvalue_set_text(icalvalue* value, char* v) +icalvalue_set_string(icalvalue* value, char* v) { struct icalvalue_impl* impl; - char *p,*d; - + icalerror_check_arg_rv( (value!=0),"value"); icalerror_check_arg_rv( (v!=0),"v"); - icalerror_check_value_type(value, ICAL_TEXT_VALUE); + icalerror_check_value_type(value, ICAL_STRING_VALUE); impl = (struct icalvalue_impl*)value; - impl->data.v_string = malloc(strlen(v)+1); + impl->data.v_string = strdup(v); if (impl->data.v_string == 0){ errno = ENOMEM; - return; } - for(d=impl->data.v_string,p=v; *p!=0; p++){ +} - if (*p == '\\') { - p++; +char* +icalvalue_get_string(icalvalue* value) +{ + icalerror_check_arg( (value!=0),"value"); + icalerror_check_value_type(value, ICAL_STRING_VALUE); + + return ((struct icalvalue_impl*)value)->data.v_string; +} - if (p == 0){ - break; - } - switch(*p){ - case 'n': { - *d='\n';d++; - break; - } +icalvalue* +icalvalue_new_text (char* v) +{ + struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_TEXT_VALUE); + + icalerror_check_arg_rz( (v!=0),"v"); - case '\\': { - *d='\\';d++; - break; - } - - case 't': { - *d='\n';d++; - break; - } - case 'r': { - *d='\r';d++; - break; - } - case 'b': { - *d='\b';d++; - break; - } - case 'f': { - *d='\f';d++; - break; - } - - case ';': - case ',':{ - *d=*p;d++; - break; - } + icalvalue_set_text((icalvalue*)impl,v); - case '"':{ - *d='\"';d++; - break; - } - } - } else { - *d=*p;d++; - } + return (icalvalue*)impl; +} + +void +icalvalue_set_text(icalvalue* value, char* v) +{ + struct icalvalue_impl* impl; + + icalerror_check_arg_rv( (value!=0),"value"); + icalerror_check_arg_rv( (v!=0),"v"); + + icalerror_check_value_type(value, ICAL_TEXT_VALUE); + + impl = (struct icalvalue_impl*)value; + impl->data.v_string = strdup(v); + + if (impl->data.v_string == 0){ + errno = ENOMEM; } - *d='\0'; } diff --git a/libical/src/libical/icalvalue.h b/libical/src/libical/icalvalue.h index b5a2e6da9e..ec7457d6aa 100644 --- a/libical/src/libical/icalvalue.h +++ b/libical/src/libical/icalvalue.h @@ -131,6 +131,11 @@ icalvalue* icalvalue_new_recur(struct icalrecurrencetype v); struct icalrecurrencetype icalvalue_get_recur(icalvalue* value); void icalvalue_set_recur(icalvalue* value, struct icalrecurrencetype v); +/* STRING # Non-std */ +icalvalue* icalvalue_new_string(char* v); +char* icalvalue_get_string(icalvalue* value); +void icalvalue_set_string(icalvalue* value, char* v); + /* TEXT */ icalvalue* icalvalue_new_text(char* v); char* icalvalue_get_text(icalvalue* value); diff --git a/libical/src/libical/icalversion.h b/libical/src/libical/icalversion.h new file mode 100644 index 0000000000..3d5f132a3f --- /dev/null +++ b/libical/src/libical/icalversion.h @@ -0,0 +1,3 @@ + +#define ICAL_PACKAGE "libical" +#define ICAL_VERSION "0.16" diff --git a/libical/src/libical/icalversion.h.in b/libical/src/libical/icalversion.h.in new file mode 100644 index 0000000000..aaeeed6666 --- /dev/null +++ b/libical/src/libical/icalversion.h.in @@ -0,0 +1,3 @@ + +#define ICAL_PACKAGE "@PACKAGE@" +#define ICAL_VERSION "@VERSION@" diff --git a/libical/src/libical/icalyacc.y b/libical/src/libical/icalyacc.y new file mode 100644 index 0000000000..63fff212a2 --- /dev/null +++ b/libical/src/libical/icalyacc.y @@ -0,0 +1,480 @@ +%{ +/* -*- Mode: C -*- + ====================================================================== + FILE: icalitip.y + CREATOR: eric 10 June 1999 + + DESCRIPTION: + + $Id: icalyacc.y,v 1.1 2000/04/18 18:17:05 alves Exp $ + $Locker: $ + + (C) COPYRIGHT 1999 Eric Busboom + http://www.softwarestudio.org + + The contents of this file are subject to the Mozilla Public License + Version 1.0 (the "License"); you may not use this file except in + compliance with the License. You may obtain a copy of the License at + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and + limitations under the License. + + The original author is Eric Busboom + The original code is icalitip.y + + + + ================================b======================================*/ + +#include <stdlib.h> +#include <string.h> /* for strdup() */ +#include <limits.h> /* for SHRT_MAX*/ +#include "icalparser.h" +#include "ical.h" +#include "pvl.h" +#define YYERROR_VERBOSE +#define YYDEBUG 1 + + +icalvalue *icalparser_yy_value; /* Current Value */ + +/* Globals for UTCOFFSET values */ +int utc; +int utc_b; +int utcsign; + +/* Globals for DURATION values */ +struct icaldurationtype duration; + +/* Globals for RECUR values */ +struct icalrecurrencetype recur; +short skiplist[367]; +short skippos; + +void copy_list(short* array, size_t size); +void clear_recur(); +void add_prop(icalproperty_kind); +void icalparser_fill_date(struct tm* t, char* dstr); +void icalparser_fill_time(struct tm* t, char* tstr); +void set_value_type(icalvalue_kind kind); +void set_parser_value_state(); +struct icaltimetype fill_datetime(char* d, char* t); +void ical_yy_error(char *s); /* Don't know why I need this.... */ +/*int yylex(void); /* Or this. */ + + + +/* Set the state of the lexer so it will interpret values ( iCAL + VALUEs, that is, ) correctly. */ + +%} + +%union { + float v_float; + int v_int; + char* v_string; + + /* Renaming hack */ +#define yymaxdepth ical_yy_maxdepth +#define yyparse ical_yy_parse +#define yylex ical_yy_lex +#define yyerror ical_yy_error +#define yylval ical_yy_lval +#define yychar ical_yy_char +#define yydebug ical_yy_debug +#define yypact ical_yy_pact +#define yyr1 ical_yy_r1 +#define yyr2 ical_yy_r2 +#define yydef ical_yy_def +#define yychk ical_yy_chk +#define yypgo ical_yy_pgo +#define yyact ical_yy_act +#define yyexca ical_yy_exca +#define yyerrflag ical_yy_errflag +#define yynerrs ical_yy_nerrs +#define yyps ical_yy_ps +#define yypv ical_yy_pv +#define yys ical_yy_s +#define yy_yys ical_yy_yys +#define yystate ical_yy_state +#define yytmp ical_yy_tmp +#define yyv ical_yy_v +#define yy_yyv ical_yy_yyv +#define yyval ical_yy_val +#define yylloc ical_yy_lloc +#define yyreds ical_yy_reds +#define yytoks ical_yy_toks +#define yylhs ical_yy_yylhs +#define yylen ical_yy_yylen +#define yydefred ical_yy_yydefred +#define yydgoto ical_yy_yydgoto +#define yydefred ical_yy_yydefred +#define yydgoto ical_yy_yydgoto +#define yysindex ical_yy_yysindex +#define yyrindex ical_yy_yyrindex +#define yygindex ical_yy_yygindex +#define yytable ical_yy_yytable +#define yycheck ical_yy_yycheck +#define yyname ical_yy_yyname +#define yyrule ical_yy_yyrule + + + +} + +%token <v_string> DIGITS +%token <v_int> INTNUMBER +%token <v_float> FLOATNUMBER +%token <v_string> STRING +%token EOL EQUALS CHARACTER COLON COMMA SEMICOLON TIMESEPERATOR + +%token TRUE FALSE + +%token FREQ BYDAY BYHOUR BYMINUTE BYMONTH BYMONTHDAY BYSECOND BYSETPOS BYWEEKNO +%token BYYEARDAY DAILY MINUTELY MONTHLY SECONDLY WEEKLY HOURLY YEARLY +%token INTERVAL COUNT UNTIL WKST MO SA SU TU WE TH FR + +%token BIT8 ACCEPTED ADD AUDIO BASE64 BINARY BOOLEAN BUSY BUSYTENTATIVE +%token BUSYUNAVAILABLE CALADDRESS CANCEL CANCELLED CHAIR CHILD COMPLETED +%token CONFIDENTIAL CONFIRMED COUNTER DATE DATETIME DECLINECOUNTER DECLINED +%token DELEGATED DISPLAY DRAFT DURATION EMAIL END FINAL FLOAT FREE GREGORIAN +%token GROUP INDIVIDUAL INPROCESS INTEGER NEEDSACTION NONPARTICIPANT +%token OPAQUE OPTPARTICIPANT PARENT PERIOD PRIVATE PROCEDURE PUBLIC PUBLISH +%token RECUR REFRESH REPLY REQPARTICIPANT REQUEST RESOURCE ROOM SIBLING +%token START TENTATIVE TEXT THISANDFUTURE THISANDPRIOR TIME TRANSPAENT +%token UNKNOWN UTCOFFSET XNAME + +%token ALTREP CN CUTYPE DAYLIGHT DIR ENCODING EVENT FBTYPE FMTTYPE LANGUAGE +%token MEMBER PARTSTAT RANGE RELATED RELTYPE ROLE RSVP SENTBY STANDARD URI + +%token TIME_CHAR UTC_CHAR + + +%% + +value: + binary_value + | boolean_value + | date_value + | datetime_value + | duration_value + | period_value + | recur_value + | utcoffset_value + | error { + icalparser_yy_value = 0; + icalparser_clear_flex_input(); + yyclearin; + } + +binary_value: "unimplemented2" + +boolean_value: + TRUE + { icalparser_yy_value = icalvalue_new_boolean(1); } + | FALSE + { icalparser_yy_value = icalvalue_new_boolean(0); } + +date_value: DIGITS + { + struct icaltimetype stm; + + stm = fill_datetime($1,0); + + stm.hour = -1; + stm.minute = -1; + stm.second = -1; + stm.is_utc = 0; + stm.is_date = 1; + + icalparser_yy_value = icalvalue_new_date(stm); + } + +utc_char: + /*empty*/ {utc = 0;} + | UTC_CHAR {utc = 1;} + +/* This is used in the period_value, where there may be two utc characters per rule. */ +utc_char_b: + /*empty*/ {utc_b = 0;} + | UTC_CHAR {utc_b = 1;} + +datetime_value: + DIGITS TIME_CHAR DIGITS utc_char + { + struct icaltimetype stm; + stm = fill_datetime($1, $3); + stm.is_utc = utc; + stm.is_date = 0; + + icalparser_yy_value = + icalvalue_new_datetime(stm); + } + + +/* Duration */ + + +dur_date: dur_day + | dur_day dur_time + +dur_week: DIGITS 'W' + { + duration.weeks = atoi($1); + } + +dur_time: TIME_CHAR dur_hour + { + } + | TIME_CHAR dur_minute + { + } + | TIME_CHAR dur_second + { + } + +dur_hour: DIGITS 'H' + { + duration.hours = atoi($1); + } + | DIGITS 'H' dur_minute + { + duration.hours = atoi($1); + } + +dur_minute: DIGITS 'M' + { + duration.minutes = atoi($1); + } + | DIGITS 'M' dur_second + { + duration.minutes = atoi($1); + } + +dur_second: DIGITS 'S' + { + duration.seconds = atoi($1); + } + +dur_day: DIGITS 'D' + { + duration.days = atoi($1); + } + +dur_prefix: /* empty */ + { + } + | '+' + { + } + | '-' + { + } + +duration_value: dur_prefix 'P' dur_date + { + icalparser_yy_value = icalvalue_new_duration(duration); + memset(&duration,0, sizeof(duration)); + } + | dur_prefix 'P' dur_time + { + icalparser_yy_value = icalvalue_new_duration(duration); + memset(&duration,0, sizeof(duration)); + } + | dur_prefix 'P' dur_week + { + icalparser_yy_value = icalvalue_new_duration(duration); + memset(&duration,0, sizeof(duration)); + } + + +/* Period */ + +period_value: DIGITS TIME_CHAR DIGITS utc_char '/' DIGITS TIME_CHAR DIGITS utc_char_b + { + struct icalperiodtype p; + + p.start = fill_datetime($1,$3); + p.start.is_utc = utc; + p.start.is_date = 0; + + + p.end = fill_datetime($6,$8); + p.end.is_utc = utc_b; + p.end.is_date = 0; + + p.duration.days = -1; + p.duration.weeks = -1; + p.duration.hours = -1; + p.duration.minutes = -1; + p.duration.seconds = -1; + + icalparser_yy_value = icalvalue_new_period(p); + } + | DIGITS TIME_CHAR DIGITS utc_char '/' duration_value + { + struct icalperiodtype p; + + p.start = fill_datetime($1,$3); + p.start.is_utc = utc; + p.start.is_date = 0; + + p.end.year = -1; + p.end.month = -1; + p.end.day = -1; + p.end.hour = -1; + p.end.minute = -1; + p.end.second = -1; + + /* The duration_value rule setes the global 'duration' + variable, but it also creates a new value in + icalparser_yy_value. So, free that, then copy + 'duration' into the icalperiodtype struct. */ + + p.duration = icalvalue_get_duration(icalparser_yy_value); + icalvalue_free(icalparser_yy_value); + icalparser_yy_value = 0; + + icalparser_yy_value = icalvalue_new_period(p); + + } + + + +/* Recur */ + +recur_start: + FREQ EQUALS SECONDLY {clear_recur();recur.freq = ICAL_SECONDLY_RECURRENCE;} + | FREQ EQUALS MINUTELY {clear_recur();recur.freq = ICAL_MINUTELY_RECURRENCE;} + | FREQ EQUALS HOURLY {clear_recur();recur.freq = ICAL_HOURLY_RECURRENCE;} + | FREQ EQUALS DAILY {clear_recur();recur.freq = ICAL_DAILY_RECURRENCE;} + | FREQ EQUALS WEEKLY {clear_recur();recur.freq = ICAL_WEEKLY_RECURRENCE;} + | FREQ EQUALS MONTHLY {clear_recur();recur.freq = ICAL_MONTHLY_RECURRENCE;} + | FREQ EQUALS YEARLY {clear_recur();recur.freq = ICAL_YEARLY_RECURRENCE;} + ; + + +weekday: + SU { skiplist[skippos]=ICAL_SUNDAY_WEEKDAY; if( skippos<8) skippos++;} + | MO { skiplist[skippos]=ICAL_MONDAY_WEEKDAY;if( skippos<8) skippos++;} + | TU { skiplist[skippos]=ICAL_TUESDAY_WEEKDAY;if( skippos<8) skippos++;} + | WE { skiplist[skippos]=ICAL_WEDNESDAY_WEEKDAY;if( skippos<8) skippos++;} + | TH { skiplist[skippos]=ICAL_THURSDAY_WEEKDAY;if( skippos<8) skippos++;} + | FR { skiplist[skippos]=ICAL_FRIDAY_WEEKDAY;if( skippos<8) skippos++;} + | SA { skiplist[skippos]=ICAL_SATURDAY_WEEKDAY;if( skippos<8) skippos++;} + ; + + +weekday_list: + weekday + | DIGITS weekday { } /* HACK Incorectly handles int in BYDAY */ + | weekday_list COMMA weekday + + +recur_list: + DIGITS { skiplist[skippos] = atoi($1); skippos++;} + | recur_list COMMA DIGITS { skiplist[skippos] = atoi($3); if (skippos<367) skippos++;} + ; + +recur_skip: + INTERVAL EQUALS DIGITS {recur.interval = atoi($3);} + | WKST EQUALS SU {recur.week_start = ICAL_SUNDAY_WEEKDAY;} + | WKST EQUALS MO {recur.week_start = ICAL_MONDAY_WEEKDAY;} + | WKST EQUALS TU {recur.week_start = ICAL_TUESDAY_WEEKDAY;} + | WKST EQUALS WE {recur.week_start = ICAL_WEDNESDAY_WEEKDAY;} + | WKST EQUALS TH {recur.week_start = ICAL_THURSDAY_WEEKDAY;} + | WKST EQUALS FR {recur.week_start = ICAL_FRIDAY_WEEKDAY;} + | WKST EQUALS SA {recur.week_start = ICAL_SATURDAY_WEEKDAY;} + | BYSECOND EQUALS recur_list{copy_list(recur.by_second,60);} + | BYMINUTE EQUALS recur_list{copy_list(recur.by_minute,60);} + | BYHOUR EQUALS recur_list{copy_list(recur.by_hour,24);} + | BYDAY EQUALS weekday_list{copy_list(recur.by_day,7);} + | BYMONTH EQUALS recur_list{copy_list(recur.by_month,12);} + | BYMONTHDAY EQUALS recur_list{copy_list(recur.by_month_day,31);} + | BYYEARDAY EQUALS recur_list{copy_list(recur.by_year_day,366);} + | BYWEEKNO EQUALS recur_list{copy_list(recur.by_week_no,53);} + | BYSETPOS EQUALS recur_list{copy_list(recur.by_set_pos,366);} + | UNTIL EQUALS datetime_value + { recur.until = icalvalue_get_datetime(icalparser_yy_value); + icalvalue_free(icalparser_yy_value); icalparser_yy_value=0;} + | UNTIL EQUALS date_value + { recur.until = icalvalue_get_date(icalparser_yy_value); + icalvalue_free(icalparser_yy_value); icalparser_yy_value=0;} + | COUNT EQUALS DIGITS + { recur.count = atoi($3); } + ; + +recur_skip_list: + /* empty */ + | recur_skip_list SEMICOLON recur_skip + +recur_value: + recur_start recur_skip_list + { icalparser_yy_value = icalvalue_new_recur(recur); } + + + +/* UTC Offset */ + +plusminus: '+' { utcsign = 1; } + | '-' { utcsign = -1; } + +utcoffset_value: + plusminus INTNUMBER INTNUMBER + { + icalparser_yy_value = icalvalue_new_utcoffset( utcsign * ($2*3600) + ($3*60) ); + } + + | plusminus INTNUMBER INTNUMBER INTNUMBER + { + icalparser_yy_value = icalvalue_new_utcoffset(utcsign * ($2*3600) + ($3*60) +($4)); + } + + + +%% + + +void clear_recur() +{ + memset(&skiplist, ICAL_RECURRENCE_ARRAY_MAX_BYTE, sizeof(skiplist)); + skippos = 0; + + icalrecurrencetype_clear(&recur); +} + +void copy_list(short* array, size_t size) +{ + memcpy(array, skiplist, size*sizeof(short)); + memset(&skiplist,ICAL_RECURRENCE_ARRAY_MAX_BYTE, sizeof(skiplist)); + skippos = 0; +} + +struct icaltimetype fill_datetime(char* datestr, char* timestr) +{ + struct icaltimetype stm; + + memset(&stm,0,sizeof(stm)); + + if (datestr != 0){ + sscanf(datestr,"%4d%2d%2d",&(stm.year), &(stm.month), + &(stm.day)); + } + + if (timestr != 0){ + sscanf(timestr,"%2d%2d%2d", &(stm.hour), &(stm.minute), + &(stm.second)); + } + + return stm; + +} + +void yyerror(char* s) +{ + /*fprintf(stderr,"Parse error \'%s\'\n", s);*/ +} + diff --git a/libical/src/libical/pvl.c b/libical/src/libical/pvl.c index b88272a6a0..d5225a541e 100644 --- a/libical/src/libical/pvl.c +++ b/libical/src/libical/pvl.c @@ -17,6 +17,10 @@ limitations under the License. ======================================================================*/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "pvl.h" #include <errno.h> #include <assert.h> |