From e87c3d5baaae937e0131095ae70ea8375c9b039c Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Tue, 17 Apr 2001 18:28:42 +0000 Subject: The perl script generated files changed between releases 2001-04-17 JP Rosevear * The perl script generated files changed between releases svn path=/trunk/; revision=9426 --- libical/configure.in | 1 + libical/src/libical/.cvsignore | 12 +- libical/src/libical/icalparameter.c | 382 +++++++++ libical/src/libical/icalparameter.c.in | 1246 ---------------------------- libical/src/libical/icalparameter.h | 69 ++ libical/src/libical/icalparameter.h.in | 57 -- libical/src/libical/icalproperty.c | 808 ++++++++++++++++++ libical/src/libical/icalproperty.c.in | 616 -------------- libical/src/libical/icalproperty.h | 116 +++ libical/src/libical/icalproperty.h.in | 57 -- libical/src/libical/icaltime.c | 11 +- libical/src/libical/icalvalue.c | 1197 +++++++++++++++++++++++++++ libical/src/libical/icalvalue.c.in | 1411 -------------------------------- libical/src/libical/icalvalue.h | 85 ++ libical/src/libical/icalvalue.h.in | 74 -- 15 files changed, 2669 insertions(+), 3473 deletions(-) create mode 100644 libical/src/libical/icalparameter.c delete mode 100644 libical/src/libical/icalparameter.c.in create mode 100644 libical/src/libical/icalparameter.h delete mode 100644 libical/src/libical/icalparameter.h.in create mode 100644 libical/src/libical/icalproperty.c delete mode 100644 libical/src/libical/icalproperty.c.in create mode 100644 libical/src/libical/icalproperty.h delete mode 100644 libical/src/libical/icalproperty.h.in create mode 100644 libical/src/libical/icalvalue.c delete mode 100644 libical/src/libical/icalvalue.c.in create mode 100644 libical/src/libical/icalvalue.h delete mode 100644 libical/src/libical/icalvalue.h.in diff --git a/libical/configure.in b/libical/configure.in index 112ac66ded..3b69f4d5ee 100644 --- a/libical/configure.in +++ b/libical/configure.in @@ -94,6 +94,7 @@ scripts/Makefile src/Makefile src/libical/Makefile src/libical/icalversion.h +src/libicalss/Makefile src/libicalvcal/Makefile src/python/Makefile src/test/Makefile diff --git a/libical/src/libical/.cvsignore b/libical/src/libical/.cvsignore index fd83172a6b..ef04480fde 100644 --- a/libical/src/libical/.cvsignore +++ b/libical/src/libical/.cvsignore @@ -12,11 +12,11 @@ y.output .libs .deps icalversion.h -icalproperty.h -icalvalue.h -icalvalue.c ical.h -icalparameter.h -icalparameter.c -icalproperty.c +icalderivedparameter.c +icalderivedparameter.h +icalderivedproperty.c +icalderivedproperty.h +icalderivedvalue.h +icalderivedvalue.c icalrestriction.c diff --git a/libical/src/libical/icalparameter.c b/libical/src/libical/icalparameter.c new file mode 100644 index 0000000000..156ecdb04b --- /dev/null +++ b/libical/src/libical/icalparameter.c @@ -0,0 +1,382 @@ +/* -*- Mode: C -*- + ====================================================================== + FILE: icalderivedparameters.{c,h} + CREATOR: eric 09 May 1999 + + $Id$ + $Locker$ + + + (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org + + This program is free software; you can redistribute it and/or modify + it under the terms of either: + + The LGPL as published by the Free Software Foundation, version + 2.1, available at: http://www.fsf.org/copyleft/lesser.html + + Or: + + The Mozilla Public License Version 1.0. You may obtain a copy of + the License at http://www.mozilla.org/MPL/ + + The original code is icalderivedparameters.{c,h} + + Contributions from: + Graham Davison (g.m.davison@computer.org) + + ======================================================================*/ +/*#line 29 "icalparameter.c.in"*/ +#ifdef HAVE_CONFIG_H +#include +#endif + + +#include "icalparameter.h" +#include "icalproperty.h" +#include "icalerror.h" +#include "icalmemory.h" +#include "icalparameterimpl.h" + +#include /* for malloc() */ +#include +#include /* for memset() */ + +/* In icalderivedparameter */ +icalparameter* icalparameter_new_from_value_string(icalparameter_kind kind,const char* val); + + +struct icalparameter_impl* icalparameter_new_impl(icalparameter_kind kind) +{ + struct icalparameter_impl* v; + + if ( ( v = (struct icalparameter_impl*) + malloc(sizeof(struct icalparameter_impl))) == 0) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return 0; + } + + strcpy(v->id,"para"); + + v->kind = kind; + v->size = 0; + v->string = 0; + v->x_name = 0; + v->parent = 0; + v->data = 0; + + return v; +} + +icalparameter* +icalparameter_new (icalparameter_kind kind) +{ + struct icalparameter_impl* v = icalparameter_new_impl(kind); + + return (icalparameter*) v; + +} + +void +icalparameter_free (icalparameter* parameter) +{ + struct icalparameter_impl * impl; + + impl = (struct icalparameter_impl*)parameter; + +/* HACK. This always triggers, even when parameter is non-zero + icalerror_check_arg_rv((parameter==0),"parameter");*/ + + +#ifdef ICAL_FREE_ON_LIST_IS_ERROR + icalerror_assert( (impl->parent ==0),"Tried to free a parameter that is still attached to a component. "); + +#else + if(impl->parent !=0){ + return; + } +#endif + + + if (impl->string != 0){ + free ((void*)impl->string); + } + + if (impl->x_name != 0){ + free ((void*)impl->x_name); + } + + memset(impl,0,sizeof(impl)); + + impl->parent = 0; + impl->id[0] = 'X'; + free(impl); +} + + + +icalparameter* +icalparameter_new_clone(icalparameter* param) +{ + struct icalparameter_impl *old; + struct icalparameter_impl *new; + + old = (struct icalparameter_impl *)param; + new = icalparameter_new_impl(old->kind); + + icalerror_check_arg_rz((param!=0),"param"); + + if (new == 0){ + return 0; + } + + memcpy(new,old,sizeof(struct icalparameter_impl)); + + if (old->string != 0){ + new->string = icalmemory_strdup(old->string); + if (new->string == 0){ + icalparameter_free(new); + return 0; + } + } + + if (old->x_name != 0){ + new->x_name = icalmemory_strdup(old->x_name); + if (new->x_name == 0){ + icalparameter_free(new); + return 0; + } + } + + return new; +} + +icalparameter* icalparameter_new_from_string(const char *str) +{ + char* eq; + char* cpy; + icalparameter_kind kind; + icalparameter *param; + + icalerror_check_arg_rz(str != 0,"str"); + + cpy = icalmemory_strdup(str); + + if (cpy == 0){ + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return 0; + } + + eq = strchr(cpy,'='); + + if(eq == 0){ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return 0; + } + + *eq = '\0'; + + eq++; + + kind = icalparameter_string_to_kind(cpy); + + if(kind == ICAL_NO_PARAMETER){ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return 0; + } + + param = icalparameter_new_from_value_string(kind,eq); + + if(kind == ICAL_X_PARAMETER){ + icalparameter_set_xname(param,cpy); + } + + free(cpy); + + return param; + +} + +char* +icalparameter_as_ical_string (icalparameter* parameter) +{ + struct icalparameter_impl* impl; + size_t buf_size = 1024; + char* buf; + char* buf_ptr; + char *out_buf; + const char *kind_string; + + icalerror_check_arg_rz( (parameter!=0), "parameter"); + + /* Create new buffer that we can append names, parameters and a + value to, and reallocate as needed. Later, this buffer will be + copied to a icalmemory_tmp_buffer, which is managed internally + by libical, so it can be given to the caller without fear of + the caller forgetting to free it */ + + buf = icalmemory_new_buffer(buf_size); + buf_ptr = buf; + impl = (struct icalparameter_impl*)parameter; + + if(impl->kind == ICAL_X_PARAMETER) { + + icalmemory_append_string(&buf, &buf_ptr, &buf_size, + icalparameter_get_xname(impl)); + + } else { + + kind_string = icalparameter_kind_to_string(impl->kind); + + if (impl->kind == ICAL_NO_PARAMETER || + impl->kind == ICAL_ANY_PARAMETER || + kind_string == 0) + { + icalerror_set_errno(ICAL_BADARG_ERROR); + return 0; + } + + + /* Put the parameter name into the string */ + icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string); + + } + + icalmemory_append_string(&buf, &buf_ptr, &buf_size, "="); + + if(impl->string !=0){ + icalmemory_append_string(&buf, &buf_ptr, &buf_size, impl->string); + } else if (impl->data != 0){ + const char* str = icalparameter_enum_to_string(impl->data); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, str); + } else { + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return 0; + } + + /* Now, copy the buffer to a tmp_buffer, which is safe to give to + the caller without worring about de-allocating it. */ + + out_buf = icalmemory_tmp_buffer(strlen(buf)); + strcpy(out_buf, buf); + + icalmemory_free_buffer(buf); + + return out_buf; + +} + + +int +icalparameter_is_valid (icalparameter* parameter); + + +icalparameter_kind +icalparameter_isa (icalparameter* parameter) +{ + if(parameter == 0){ + return ICAL_NO_PARAMETER; + } + + return ((struct icalparameter_impl *)parameter)->kind; +} + + +int +icalparameter_isa_parameter (void* parameter) +{ + struct icalparameter_impl *impl = (struct icalparameter_impl *)parameter; + + if (parameter == 0){ + return 0; + } + + if (strcmp(impl->id,"para") == 0) { + return 1; + } else { + return 0; + } +} + + +void +icalparameter_set_xname (icalparameter* param, const char* v) +{ + struct icalparameter_impl *impl = (struct icalparameter_impl*)param; + icalerror_check_arg_rv( (param!=0),"param"); + icalerror_check_arg_rv( (v!=0),"v"); + + if (impl->x_name != 0){ + free((void*)impl->x_name); + } + + impl->x_name = icalmemory_strdup(v); + + if (impl->x_name == 0){ + errno = ENOMEM; + } + +} + +const char* +icalparameter_get_xname (icalparameter* param) +{ + struct icalparameter_impl *impl = (struct icalparameter_impl*)param; + icalerror_check_arg_rz( (param!=0),"param"); + + return impl->x_name; +} + +void +icalparameter_set_xvalue (icalparameter* param, const char* v) +{ + struct icalparameter_impl *impl = (struct icalparameter_impl*)param; + + icalerror_check_arg_rv( (param!=0),"param"); + icalerror_check_arg_rv( (v!=0),"v"); + + if (impl->string != 0){ + free((void*)impl->string); + } + + impl->string = icalmemory_strdup(v); + + if (impl->string == 0){ + errno = ENOMEM; + } + +} + +const char* +icalparameter_get_xvalue (icalparameter* param) +{ + struct icalparameter_impl *impl = (struct icalparameter_impl*)param; + + icalerror_check_arg_rz( (param!=0),"param"); + + return impl->string; + +} + +void icalparameter_set_parent(icalparameter* param, + icalproperty* property) +{ + struct icalparameter_impl *impl = (struct icalparameter_impl*)param; + + icalerror_check_arg_rv( (param!=0),"param"); + + impl->parent = property; +} + +icalproperty* icalparameter_get_parent(icalparameter* param) +{ + struct icalparameter_impl *impl = (struct icalparameter_impl*)param; + + icalerror_check_arg_rz( (param!=0),"param"); + + return impl->parent; +} + + +/* Everything below this line is machine generated. Do not edit. */ +/* ALTREP */ diff --git a/libical/src/libical/icalparameter.c.in b/libical/src/libical/icalparameter.c.in deleted file mode 100644 index 6ffb9b27eb..0000000000 --- a/libical/src/libical/icalparameter.c.in +++ /dev/null @@ -1,1246 +0,0 @@ -/* -*- Mode: C -*- - ====================================================================== - FILE: icalderivedparameters.{c,h} - CREATOR: eric 09 May 1999 - - $Id: icalparameter.c.in,v 1.4 2001/02/09 07:09:46 jpr Exp $ - $Locker: $ - - - (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org - - This program is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: http://www.fsf.org/copyleft/lesser.html - - Or: - - The Mozilla Public License Version 1.0. You may obtain a copy of - the License at http://www.mozilla.org/MPL/ - - The original code is icalderivedparameters.{c,h} - - Contributions from: - Graham Davison (g.m.davison@computer.org) - - ======================================================================*/ -/*#line 29 "icalparameter.c.in"*/ -#ifdef HAVE_CONFIG_H -#include -#endif - - -#include "icalparameter.h" -#include "icalproperty.h" -#include "icalerror.h" -#include "icalmemory.h" - -#include /* for malloc() */ -#include -#include /* for memset() */ - -union icalparameter_impl_data { - int v_int; - int v_rsvp; - icalparameter_cutype v_cutype; - icalparameter_encoding v_encoding; - icalparameter_fbtype v_fbtype; - icalparameter_partstat v_partstat; - icalparameter_range v_range; - icalparameter_related v_related; - icalparameter_reltype v_reltype; - icalparameter_role v_role; - icalparameter_value v_value; - icalparameter_xlicerrortype v_xlicerrortype; - icalparameter_xliccomparetype v_xliccomparetype; -} data; - -struct icalparameter_impl -{ - icalparameter_kind kind; - char id[5]; - int size; - const char* string; - const char* x_name; - icalproperty* parent; - - union icalparameter_impl_data data; -}; - -struct icalparameter_impl* icalparameter_new_impl(icalparameter_kind kind) -{ - struct icalparameter_impl* v; - - if ( ( v = (struct icalparameter_impl*) - malloc(sizeof(struct icalparameter_impl))) == 0) { - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; - } - - strcpy(v->id,"para"); - - v->kind = kind; - v->size = 0; - v->string = 0; - v->x_name = 0; - v->parent = 0; - memset(&(v->data),0,sizeof(v->data)); - - return v; -} - -icalparameter* -icalparameter_new (icalparameter_kind kind) -{ - struct icalparameter_impl* v = icalparameter_new_impl(kind); - - return (icalparameter*) v; - -} - -icalparameter* -icalparameter_new_clone(icalparameter* param) -{ - struct icalparameter_impl *old; - struct icalparameter_impl *new; - - old = (struct icalparameter_impl *)param; - new = icalparameter_new_impl(old->kind); - - icalerror_check_arg_rz((param!=0),"param"); - - if (new == 0){ - return 0; - } - - memcpy(new,old,sizeof(struct icalparameter_impl)); - - if (old->string != 0){ - new->string = icalmemory_strdup(old->string); - if (new->string == 0){ - icalparameter_free(new); - return 0; - } - } - - if (old->x_name != 0){ - new->x_name = icalmemory_strdup(old->x_name); - if (new->x_name == 0){ - icalparameter_free(new); - return 0; - } - } - - return new; -} - -#if 1 -/* The following code is meant to replace most of the case-switch - statements, but it is still a work in progress */ -struct param_string_map { - icalparameter_kind kind; - int val; /* Actually, union of several types of enums */ - const char* str; -} param_string_map[] = -{ - {ICAL_CUTYPE_PARAMETER,ICAL_CUTYPE_INDIVIDUAL,"INDIVIDUAL"}, - {ICAL_CUTYPE_PARAMETER,ICAL_CUTYPE_GROUP,"GROUP"}, - {ICAL_CUTYPE_PARAMETER,ICAL_CUTYPE_RESOURCE,"RESOURCE"}, - {ICAL_CUTYPE_PARAMETER,ICAL_CUTYPE_ROOM,"ROOM"}, - {ICAL_CUTYPE_PARAMETER,ICAL_CUTYPE_UNKNOWN,"UNKNOWN"}, - {ICAL_FBTYPE_PARAMETER,ICAL_FBTYPE_FREE,"FREE"}, - {ICAL_FBTYPE_PARAMETER,ICAL_FBTYPE_BUSY,"BUSY"}, - {ICAL_FBTYPE_PARAMETER,ICAL_FBTYPE_BUSYUNAVAILABLE,"BUSYUNAVAILABLE"}, - {ICAL_FBTYPE_PARAMETER,ICAL_FBTYPE_BUSYTENTATIVE,"BUSYTENTATIVE"}, - {ICAL_PARTSTAT_PARAMETER,ICAL_PARTSTAT_NEEDSACTION,"NEEDS-ACTION"}, - {ICAL_PARTSTAT_PARAMETER,ICAL_PARTSTAT_ACCEPTED,"ACCEPTED"}, - {ICAL_PARTSTAT_PARAMETER,ICAL_PARTSTAT_DECLINED,"DECLINED"}, - {ICAL_PARTSTAT_PARAMETER,ICAL_PARTSTAT_TENTATIVE,"TENTATIVE"}, - {ICAL_PARTSTAT_PARAMETER,ICAL_PARTSTAT_DELEGATED,"DELEGATED"}, - {ICAL_PARTSTAT_PARAMETER,ICAL_PARTSTAT_COMPLETED,"COMPLETED"}, - {ICAL_PARTSTAT_PARAMETER,ICAL_PARTSTAT_INPROCESS,"INPROCESS"}, - {ICAL_RANGE_PARAMETER,ICAL_RANGE_THISANDPRIOR,"THISANDPRIOR"}, - {ICAL_RANGE_PARAMETER,ICAL_RANGE_THISANDFUTURE,"THISANDFUTURE"}, - {ICAL_RELATED_PARAMETER,ICAL_RELATED_START,"START"}, - {ICAL_RELATED_PARAMETER,ICAL_RELATED_END,"END"}, - {ICAL_RELTYPE_PARAMETER,ICAL_RELTYPE_PARENT,"PARENT"}, - {ICAL_RELTYPE_PARAMETER,ICAL_RELTYPE_CHILD,"CHILD"}, - {ICAL_RELTYPE_PARAMETER,ICAL_RELTYPE_SIBLING,"SIBLING"}, - {ICAL_ROLE_PARAMETER,ICAL_ROLE_CHAIR,"CHAIR"}, - {ICAL_ROLE_PARAMETER,ICAL_ROLE_REQPARTICIPANT,"REQ-PARTICIPANT"}, - {ICAL_ROLE_PARAMETER,ICAL_ROLE_OPTPARTICIPANT,"OPT-PARTICIPANT"}, - {ICAL_ROLE_PARAMETER,ICAL_ROLE_NONPARTICIPANT,"NON-PARTICIPANT"}, - {ICAL_RSVP_PARAMETER,ICAL_RSVP_PARAMETER,"TRUE"}, - {ICAL_RSVP_PARAMETER,ICAL_RSVP_PARAMETER,"FALSE"}, - {ICAL_VALUE_PARAMETER,ICAL_VALUE_BINARY,"BINARY"}, - {ICAL_VALUE_PARAMETER,ICAL_VALUE_BOOLEAN,"BOOLEAN"}, - {ICAL_VALUE_PARAMETER,ICAL_VALUE_DATE,"DATE"}, - {ICAL_VALUE_PARAMETER,ICAL_VALUE_DURATION,"DURATION"}, - {ICAL_VALUE_PARAMETER,ICAL_VALUE_FLOAT,"FLOAT"}, - {ICAL_VALUE_PARAMETER,ICAL_VALUE_INTEGER,"INTEGER"}, - {ICAL_VALUE_PARAMETER,ICAL_VALUE_PERIOD,"PERIOD"}, - {ICAL_VALUE_PARAMETER,ICAL_VALUE_RECUR,"RECUR"}, - {ICAL_VALUE_PARAMETER,ICAL_VALUE_TEXT,"TEXT"}, - {ICAL_VALUE_PARAMETER,ICAL_VALUE_TIME,"TIME"}, - {ICAL_VALUE_PARAMETER,ICAL_VALUE_URI,"URI"}, - {ICAL_VALUE_PARAMETER,ICAL_VALUE_XNAME,"ERROR"}, - {ICAL_XLICERRORTYPE_PARAMETER,ICAL_XLICERRORTYPE_COMPONENTPARSEERROR,"COMPONENT_PARSE_ERROR"}, - {ICAL_XLICERRORTYPE_PARAMETER,ICAL_XLICERRORTYPE_PROPERTYPARSEERROR,"PROPERTY_PARSE_ERROR"}, - {ICAL_XLICERRORTYPE_PARAMETER,ICAL_XLICERRORTYPE_PARAMETERNAMEPARSEERROR,"PARAMETER_NAME_PARSE_ERROR"}, - {ICAL_XLICERRORTYPE_PARAMETER,ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR,"PARAMETER_VALUE_PARSE_ERROR"}, - {ICAL_XLICERRORTYPE_PARAMETER,ICAL_XLICERRORTYPE_VALUEPARSEERROR,"VALUE_PARSE_ERROR"}, - {ICAL_XLICERRORTYPE_PARAMETER,ICAL_XLICERRORTYPE_INVALIDITIP,"INVALID_ITIP"}, - {ICAL_XLICERRORTYPE_PARAMETER,ICAL_XLICERRORTYPE_UNKVCALPROP,"UNKNOWN_VCAL_PROP_ERROR"}, - {ICAL_XLICERRORTYPE_PARAMETER,ICAL_XLICERRORTYPE_MIMEPARSEERROR,"MIME_PARSE_ERROR"}, - {ICAL_XLICCOMPARETYPE_PARAMETER,ICAL_XLICCOMPARETYPE_EQUAL,"EQUAL"}, - {ICAL_XLICCOMPARETYPE_PARAMETER,ICAL_XLICCOMPARETYPE_NOTEQUAL,"NOTEQUAL"}, - {ICAL_XLICCOMPARETYPE_PARAMETER,ICAL_XLICCOMPARETYPE_LESS,"LESS"}, - {ICAL_XLICCOMPARETYPE_PARAMETER,ICAL_XLICCOMPARETYPE_GREATER,"GREATER"}, - {ICAL_XLICCOMPARETYPE_PARAMETER,ICAL_XLICCOMPARETYPE_LESSEQUAL,"LESSEQUAL"}, - {ICAL_XLICCOMPARETYPE_PARAMETER,ICAL_XLICCOMPARETYPE_GREATEREQUAL,"GREATEREQUAL"}, - {ICAL_XLICCOMPARETYPE_PARAMETER,ICAL_XLICCOMPARETYPE_REGEX,"REGEX"}, - {ICAL_NO_PARAMETER,0,""}, - -}; - -void icalparameter_set_impl_data(icalparameter_kind kind, - union icalparameter_impl_data *data, - int value) -{ - - switch (kind){ - case ICAL_CUTYPE_PARAMETER: - data->v_cutype=value; break; - case ICAL_FBTYPE_PARAMETER: - data->v_fbtype=value; break; - case ICAL_PARTSTAT_PARAMETER: - data->v_partstat=value; break; - case ICAL_RANGE_PARAMETER: - data->v_range=value; break; - case ICAL_RELATED_PARAMETER: - data->v_related=value; break; - case ICAL_RELTYPE_PARAMETER: - data->v_reltype=value; break; - case ICAL_ROLE_PARAMETER: - data->v_role=value; break; - case ICAL_RSVP_PARAMETER: - data->v_rsvp=value; break; - case ICAL_VALUE_PARAMETER: - data->v_value=value; break; - case ICAL_XLICERRORTYPE_PARAMETER: - data->v_xlicerrortype=value; break; - case ICAL_XLICCOMPARETYPE_PARAMETER: - data->v_xliccomparetype=value; break; - default: - break; - } -} - -icalparameter* icalparameter_new_from_string_test(icalparameter_kind kind, char* val) -{ - int i =0; - icalparameter* param=0; - - icalerror_check_arg_rz((val!=0),"val"); - - switch(kind){ - - /* These are all string values parameters */ - case ICAL_SENTBY_PARAMETER: - case ICAL_TZID_PARAMETER: - case ICAL_X_PARAMETER: - case ICAL_FMTTYPE_PARAMETER: - case ICAL_LANGUAGE_PARAMETER: - case ICAL_MEMBER_PARAMETER: - case ICAL_DELEGATEDFROM_PARAMETER: - case ICAL_DELEGATEDTO_PARAMETER: - case ICAL_DIR_PARAMETER: - case ICAL_ALTREP_PARAMETER: - case ICAL_CN_PARAMETER: - { - struct icalparameter_impl *impl = icalparameter_new_impl(kind); - if (impl == 0) { - return 0; - } - ((struct icalparameter_impl*)param)->string = - icalmemory_strdup(val); - - return (icalparameter*) impl; - - } - - case ICAL_NO_PARAMETER: - case ICAL_ANY_PARAMETER: - { - } - - default: { - int found = 0; - /* All other types are enumerated */ - for(i = 0; param_string_map[i].kind != ICAL_NO_PARAMETER; i++){ - - if(kind == param_string_map[i].kind && - strcmp(val,param_string_map[i].str) == 0){ - - struct icalparameter_impl *impl = - icalparameter_new_impl(kind); - found = 1; - - icalparameter_set_impl_data(kind,&impl->data, - param_string_map[i].val); - - return (icalparameter*)impl; - } - } - - /* Didn't find the standard enumerated type, so it must be - an X parameter */ - if (found ==0) { - icalparameter *param = icalparameter_new(kind); - - icalparameter_set_xvalue(param,val); - - return param; - - } - } - } - - return 0; -} - -#endif - - -icalparameter* icalparameter_new_from_string(icalparameter_kind kind, char* val) -{ - - icalparameter* param=0; - - icalerror_check_arg_rz((val!=0),"val"); - - switch (kind) { - case ICAL_ALTREP_PARAMETER: - { - param = icalparameter_new_altrep(val); - - break; - } - case ICAL_CN_PARAMETER: - { - param = icalparameter_new_cn(val); - - break; - } - case ICAL_CUTYPE_PARAMETER: - { - if(strcmp(val,"INDIVIDUAL") == 0){ - param = icalparameter_new_cutype(ICAL_CUTYPE_INDIVIDUAL); - } - else if(strcmp(val,"GROUP") == 0){ - param = icalparameter_new_cutype(ICAL_CUTYPE_GROUP); - } - else if(strcmp(val,"RESOURCE") == 0){ - param = icalparameter_new_cutype(ICAL_CUTYPE_RESOURCE); - } - else if(strcmp(val,"ROOM") == 0){ - param = icalparameter_new_cutype(ICAL_CUTYPE_ROOM); - } - else if(strcmp(val,"UNKNOWN") == 0){ - param = icalparameter_new_cutype(ICAL_CUTYPE_UNKNOWN); - } - else { - param = icalparameter_new_cutype(ICAL_CUTYPE_XNAME); - icalparameter_set_xvalue(param,val); - } - break; - } - - case ICAL_DELEGATEDFROM_PARAMETER: - { - param = icalparameter_new_delegatedfrom(val); - - break; - } - case ICAL_DELEGATEDTO_PARAMETER: - { - param = icalparameter_new_delegatedto(val); - - break; - } - case ICAL_DIR_PARAMETER: - { - param = icalparameter_new_dir(val); - - break; - } - case ICAL_ENCODING_PARAMETER: - { - if(strcmp(val,"BIT8") == 0){ - param = icalparameter_new_encoding(ICAL_ENCODING_8BIT); - } - else if(strcmp(val,"BASE64") == 0){ - param = icalparameter_new_encoding(ICAL_ENCODING_BASE64); - } - else { - param = icalparameter_new_encoding(ICAL_ENCODING_XNAME); - icalparameter_set_xvalue(param,val); - } - break; - } - case ICAL_FBTYPE_PARAMETER: - { - if(strcmp(val,"FREE") == 0){ - param = icalparameter_new_fbtype(ICAL_FBTYPE_FREE); - } - else if(strcmp(val,"BUSY") == 0){ - param = icalparameter_new_fbtype(ICAL_FBTYPE_BUSY); - } - else if(strcmp(val,"BUSYUNAVAILABLE") == 0){ - param = icalparameter_new_fbtype(ICAL_FBTYPE_BUSYUNAVAILABLE); - } - else if(strcmp(val,"BUSYTENTATIVE") == 0){ - param = icalparameter_new_fbtype(ICAL_FBTYPE_BUSYTENTATIVE); - } - else { - param = icalparameter_new_fbtype(ICAL_FBTYPE_XNAME); - icalparameter_set_xvalue(param,val); - } - break; - } - case ICAL_FMTTYPE_PARAMETER: - { - param = icalparameter_new_fmttype(val); - break; - } - case ICAL_LANGUAGE_PARAMETER: - { - param = icalparameter_new_language(val); - - break; - } - case ICAL_MEMBER_PARAMETER: - { - param = icalparameter_new_member(val); - - break; - } - case ICAL_PARTSTAT_PARAMETER: - { - if(strcmp(val,"NEEDS-ACTION") == 0){ - param = icalparameter_new_partstat(ICAL_PARTSTAT_NEEDSACTION); - } - else if(strcmp(val,"ACCEPTED") == 0){ - param = icalparameter_new_partstat(ICAL_PARTSTAT_ACCEPTED); - } - else if(strcmp(val,"DECLINED") == 0){ - param = icalparameter_new_partstat(ICAL_PARTSTAT_DECLINED); - } - else if(strcmp(val,"TENTATIVE") == 0){ - param = icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE); - } - else if(strcmp(val,"DELEGATED") == 0){ - param = icalparameter_new_partstat(ICAL_PARTSTAT_DELEGATED); - } - else if(strcmp(val,"COMPLETED") == 0){ - param = icalparameter_new_partstat(ICAL_PARTSTAT_COMPLETED); - } - else if(strcmp(val,"INPROCESS") == 0){ - param = icalparameter_new_partstat(ICAL_PARTSTAT_INPROCESS); - } - else { - param = icalparameter_new_partstat(ICAL_PARTSTAT_XNAME); - icalparameter_set_xvalue(param,val); - } - break; - } - case ICAL_RANGE_PARAMETER: - { - if(strcmp(val,"THISANDFUTURE") == 0){ - param = icalparameter_new_range(ICAL_RANGE_THISANDFUTURE); - } - else if(strcmp(val,"THISANDPRIOR") == 0){ - param = icalparameter_new_range(ICAL_RANGE_THISANDPRIOR); - } - - break; - } - case ICAL_RELATED_PARAMETER: - { - if(strcmp(val,"START") == 0){ - param = icalparameter_new_related(ICAL_RELATED_START); - } - else if(strcmp(val,"END") == 0){ - param = icalparameter_new_related(ICAL_RELATED_END); - } - - break; - } - case ICAL_RELTYPE_PARAMETER: - { - if(strcmp(val,"PARENT") == 0){ - param = icalparameter_new_reltype(ICAL_RELTYPE_PARENT); - } - else if(strcmp(val,"CHILD") == 0){ - param = icalparameter_new_reltype(ICAL_RELTYPE_CHILD); - } - else if(strcmp(val,"SIBLING") == 0){ - param = icalparameter_new_reltype(ICAL_RELTYPE_SIBLING); - } - else { - param = icalparameter_new_reltype(ICAL_RELTYPE_XNAME); - icalparameter_set_xvalue(param,val); - } - break; - } - case ICAL_ROLE_PARAMETER: - { - if(strcmp(val,"CHAIR") == 0){ - param = icalparameter_new_role(ICAL_ROLE_CHAIR); - } - else if(strcmp(val,"REQ-PARTICIPANT") == 0){ - param = icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT); - } - else if(strcmp(val,"OPT-PARTICIPANT") == 0){ - param = icalparameter_new_role(ICAL_ROLE_OPTPARTICIPANT); - } - else if(strcmp(val,"NON-PARTICIPANT") == 0){ - param = icalparameter_new_role(ICAL_ROLE_NONPARTICIPANT); - } - else { - param = icalparameter_new_role(ICAL_ROLE_XNAME); - icalparameter_set_xvalue(param,val); - } - break; - } - case ICAL_RSVP_PARAMETER: - { - if(strcmp(val,"TRUE") == 0){ - param = icalparameter_new_rsvp(1); - } - else if(strcmp(val,"FALSE") == 0){ - param = icalparameter_new_rsvp(0); - } - - break; - } - case ICAL_SENTBY_PARAMETER: - { - param = icalparameter_new_sentby(val); - - break; - } - case ICAL_TZID_PARAMETER: - { - param = icalparameter_new_tzid(val); - - break; - } - case ICAL_VALUE_PARAMETER: - { - if(strcmp(val,"BINARY") == 0){ - param = icalparameter_new_value(ICAL_VALUE_BINARY); - } - else if(strcmp(val,"BOOLEAN") == 0){ - param = icalparameter_new_value(ICAL_VALUE_BOOLEAN); - } - else if(strcmp(val,"CAL-ADDRESS") == 0){ - param = icalparameter_new_value(ICAL_VALUE_CALADDRESS); - } - else if(strcmp(val,"DATE") == 0){ - param = icalparameter_new_value(ICAL_VALUE_DATE); - } - else if(strcmp(val,"DATE-TIME") == 0){ - param = icalparameter_new_value(ICAL_VALUE_DATETIME); - } - else if(strcmp(val,"DURATION") == 0){ - param = icalparameter_new_value(ICAL_VALUE_DURATION); - } - else if(strcmp(val,"FLOAT") == 0){ - param = icalparameter_new_value(ICAL_VALUE_FLOAT); - } - else if(strcmp(val,"INTEGER") == 0){ - param = icalparameter_new_value(ICAL_VALUE_INTEGER); - } - else if(strcmp(val,"PERIOD") == 0){ - param = icalparameter_new_value(ICAL_VALUE_PERIOD); - } - else if(strcmp(val,"RECUR") == 0){ - param = icalparameter_new_value(ICAL_VALUE_RECUR); - } - else if(strcmp(val,"TEXT") == 0){ - param = icalparameter_new_value(ICAL_VALUE_TEXT); - } - else if(strcmp(val,"TIME") == 0){ - param = icalparameter_new_value(ICAL_VALUE_TIME); - } - else if(strcmp(val,"URI") == 0){ - param = icalparameter_new_value(ICAL_VALUE_URI); - } - else if(strcmp(val,"UTC-OFFSET") == 0){ - param = icalparameter_new_value(ICAL_VALUE_UTCOFFSET); - } - else { - param = 0; - } - break; - } - case ICAL_XLICERRORTYPE_PARAMETER: - { - - if(strcmp(val,"COMPONENT_PARSE_ERROR") == 0){ - param = icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_COMPONENTPARSEERROR); - } - else if(strcmp(val,"PROPERTY_PARSE_ERROR") == 0){ - param = icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_PROPERTYPARSEERROR); - } - 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); - } - else if(strcmp(val,"INVALID_ITIP") == 0){ - param = icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_INVALIDITIP); - } - else if(strcmp(val,"MIME_PARSE_ERROR") == 0){ - param = icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_MIMEPARSEERROR); - } - else if(strcmp(val,"UNKNOWN_VCAL_PROP_ERROR") == 0){ - param = icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_UNKVCALPROP); - } - 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); - icalparameter_set_xvalue(param,val); - break; - } - - case ICAL_NO_PARAMETER: - default: - { - return 0; - } - - - } - - return param; -} - -void -icalparameter_free (icalparameter* parameter) -{ - struct icalparameter_impl * impl; - - impl = (struct icalparameter_impl*)parameter; - -/* HACK. This always triggers, even when parameter is non-zero - icalerror_check_arg_rv((parameter==0),"parameter");*/ - - -#ifdef ICAL_FREE_ON_LIST_IS_ERROR - icalerror_assert( (impl->parent ==0),"Tried to free a parameter that is still attached to a component. "); - -#else - if(impl->parent !=0){ - return; - } -#endif - - - if (impl->string != 0){ - free ((void*)impl->string); - } - - if (impl->x_name != 0){ - free ((void*)impl->x_name); - } - - memset(impl,0,sizeof(impl)); - - impl->parent = 0; - impl->id[0] = 'X'; - free(impl); -} - - -char no_parameter[]="Error: No Parameter"; -char* -icalparameter_as_ical_string (icalparameter* parameter) -{ - struct icalparameter_impl* impl; - size_t buf_size = 1024; - char* buf; - char* buf_ptr; - char *out_buf; - const char *kind_string; - - char tend[1024]; /* HACK . Should be using memory buffer ring */ - - icalerror_check_arg_rz( (parameter!=0), "parameter"); - - /* Create new buffer that we can append names, parameters and a - value to, and reallocate as needed. Later, this buffer will be - copied to a icalmemory_tmp_buffer, which is managed internally - by libical, so it can be given to the caller without fear of - the caller forgetting to free it */ - - buf = icalmemory_new_buffer(buf_size); - buf_ptr = buf; - impl = (struct icalparameter_impl*)parameter; - - if(impl->kind == ICAL_X_PARAMETER) { - - icalmemory_append_string(&buf, &buf_ptr, &buf_size, - icalparameter_get_xname(impl)); - - } else { - - kind_string = icalenum_parameter_kind_to_string(impl->kind); - - if (impl->kind == ICAL_NO_PARAMETER || - impl->kind == ICAL_ANY_PARAMETER || - kind_string == 0) - { - icalerror_set_errno(ICAL_BADARG_ERROR); - return 0; - } - - - /* Put the parameter name into the string */ - icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string); - - } - - icalmemory_append_string(&buf, &buf_ptr, &buf_size, "="); - - switch (impl->kind) { - case ICAL_CUTYPE_PARAMETER: - { - switch (impl->data.v_cutype) { - case ICAL_CUTYPE_INDIVIDUAL: { - strcpy(tend,"INDIVIDUAL");break; - } - case ICAL_CUTYPE_GROUP:{ - strcpy(tend,"GROUP");break; - } - case ICAL_CUTYPE_RESOURCE: { - strcpy(tend,"RESOURCE");break; - } - case ICAL_CUTYPE_ROOM:{ - strcpy(tend,"ROOM");break; - } - case ICAL_CUTYPE_UNKNOWN:{ - strcpy(tend,"UNKNOWN");break; - } - case ICAL_CUTYPE_XNAME:{ - if (impl->string == 0){ return no_parameter;} - strcpy(tend,impl->string);break; - } - default:{ - icalerror_set_errno(ICAL_BADARG_ERROR);break; - } - } - break; - - } - case ICAL_ENCODING_PARAMETER: - { - switch (impl->data.v_encoding) { - case ICAL_ENCODING_8BIT: { - strcpy(tend,"8BIT");break; - } - case ICAL_ENCODING_BASE64:{ - strcpy(tend,"BASE64");break; - } - default:{ - icalerror_set_errno(ICAL_BADARG_ERROR);break; - } - } - break; - } - - case ICAL_FBTYPE_PARAMETER: - { - switch (impl->data.v_fbtype) { - case ICAL_FBTYPE_FREE:{ - strcpy(tend,"FREE");break; - } - case ICAL_FBTYPE_BUSY: { - strcpy(tend,"BUSY");break; - } - case ICAL_FBTYPE_BUSYUNAVAILABLE:{ - strcpy(tend,"BUSYUNAVAILABLE");break; - } - case ICAL_FBTYPE_BUSYTENTATIVE:{ - strcpy(tend,"BUSYTENTATIVE");break; - } - case ICAL_FBTYPE_XNAME:{ - if (impl->string == 0){ return no_parameter;} - strcpy(tend,impl->string);break; - } - default:{ - icalerror_set_errno(ICAL_BADARG_ERROR);break; - } - } - break; - - } - case ICAL_PARTSTAT_PARAMETER: - { - switch (impl->data.v_partstat) { - case ICAL_PARTSTAT_NEEDSACTION: { - strcpy(tend,"NEEDS-ACTION");break; - } - case ICAL_PARTSTAT_ACCEPTED: { - strcpy(tend,"ACCEPTED");break; - } - case ICAL_PARTSTAT_DECLINED:{ - strcpy(tend,"DECLINED");break; - } - case ICAL_PARTSTAT_TENTATIVE:{ - strcpy(tend,"TENTATIVE");break; - } - case ICAL_PARTSTAT_DELEGATED:{ - strcpy(tend,"DELEGATED");break; - } - case ICAL_PARTSTAT_COMPLETED:{ - strcpy(tend,"COMPLETED");break; - } - case ICAL_PARTSTAT_INPROCESS:{ - strcpy(tend,"INPROCESS");break; - } - case ICAL_PARTSTAT_XNAME:{ - if (impl->string == 0){ return no_parameter;} - strcpy(tend,impl->string);break; - } - default:{ - icalerror_set_errno(ICAL_BADARG_ERROR);break; - } - } - break; - - } - case ICAL_RANGE_PARAMETER: - { - switch (impl->data.v_range) { - case ICAL_RANGE_THISANDPRIOR: { - strcpy(tend,"THISANDPRIOR");break; - } - case ICAL_RANGE_THISANDFUTURE: { - strcpy(tend,"THISANDFUTURE");break; - } - default:{ - icalerror_set_errno(ICAL_BADARG_ERROR);break; - } - } - break; - } - case ICAL_RELATED_PARAMETER: - { - switch (impl->data.v_related) { - case ICAL_RELATED_START: { - strcpy(tend,"START");break; - } - case ICAL_RELATED_END: { - strcpy(tend,"END");break; - } - default:{ - icalerror_set_errno(ICAL_BADARG_ERROR);break; - } - } - break; - } - case ICAL_RELTYPE_PARAMETER: - { - switch (impl->data.v_reltype) { - case ICAL_RELTYPE_PARENT: { - strcpy(tend,"PARENT");break; - } - case ICAL_RELTYPE_CHILD:{ - strcpy(tend,"CHILD");break; - } - case ICAL_RELTYPE_SIBLING:{ - strcpy(tend,"SIBLING");break; - } - case ICAL_RELTYPE_XNAME:{ - if (impl->string == 0){ return no_parameter;} - strcpy(tend,impl->string);break; - } - default:{ - icalerror_set_errno(ICAL_BADARG_ERROR);break; - } - } - break; - } - case ICAL_ROLE_PARAMETER: - { - switch (impl->data.v_role) { - case ICAL_ROLE_CHAIR: { - strcpy(tend,"CHAIR");break; - } - case ICAL_ROLE_REQPARTICIPANT: { - strcpy(tend,"REQ-PARTICIPANT");break; - } - case ICAL_ROLE_OPTPARTICIPANT: { - strcpy(tend,"OPT-PARTICIPANT");break; - } - case ICAL_ROLE_NONPARTICIPANT: { - strcpy(tend,"NON-PARTICIPANT");break; - } - case ICAL_ROLE_XNAME:{ - if (impl->string == 0){ return no_parameter;} - strcpy(tend,impl->string);break; - } - default:{ - icalerror_set_errno(ICAL_BADARG_ERROR);break; - } - } - break; - } - case ICAL_RSVP_PARAMETER: - { - switch (impl->data.v_rsvp) { - case 1: { - strcpy(tend,"TRUE");break; - } - case 0: { - strcpy(tend,"FALSE");break; - } - default:{ - icalerror_set_errno(ICAL_BADARG_ERROR);break; - } - } - break; - } - case ICAL_VALUE_PARAMETER: - { - switch (impl->data.v_value) { - case ICAL_VALUE_BINARY: { - strcpy(tend,"BINARY");break; - } - case ICAL_VALUE_BOOLEAN: { - strcpy(tend,"BOOLEAN");break; - } - case ICAL_VALUE_CALADDRESS: { - strcpy(tend,"CAL-ADDRESS");break; - } - case ICAL_VALUE_DATE: { - strcpy(tend,"DATE");break; - } - case ICAL_VALUE_DATETIME: { - strcpy(tend,"DATE-TIME");break; - } - case ICAL_VALUE_DURATION: { - strcpy(tend,"DURATION");break; - } - case ICAL_VALUE_FLOAT: { - strcpy(tend,"FLOAT");break; - } - case ICAL_VALUE_INTEGER: { - strcpy(tend,"INTEGER");break; - } - case ICAL_VALUE_PERIOD: { - strcpy(tend,"PERIOD");break; - } - case ICAL_VALUE_RECUR: { - strcpy(tend,"RECUR");break; - } - case ICAL_VALUE_TEXT: { - strcpy(tend,"TEXT");break; - } - case ICAL_VALUE_TIME: { - strcpy(tend,"TIME");break; - } - case ICAL_VALUE_URI: { - strcpy(tend,"URI");break; - } - case ICAL_VALUE_UTCOFFSET: { - strcpy(tend,"UTC-OFFSET");break; - } - case ICAL_VALUE_XNAME: { - if (impl->string == 0){ return no_parameter;} - strcpy(tend,impl->string);break; - } - default:{ - strcpy(tend,"ERROR"); - icalerror_set_errno(ICAL_BADARG_ERROR);break; - } - } - break; - } - - - case ICAL_XLICERRORTYPE_PARAMETER: - { - switch (impl->data.v_xlicerrortype) { - case ICAL_XLICERRORTYPE_COMPONENTPARSEERROR: - { - strcpy(tend,"COMPONENT_PARSE_ERROR");break; - } - case ICAL_XLICERRORTYPE_PROPERTYPARSEERROR: - { - strcpy(tend,"PROPERTY_PARSE_ERROR");break; - } - case ICAL_XLICERRORTYPE_PARAMETERNAMEPARSEERROR: - { - strcpy(tend,"PARAMETER_NAME_PARSE_ERROR");break; - } - case ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR: - { - strcpy(tend,"PARAMETER_VALUE_PARSE_ERROR");break; - } - case ICAL_XLICERRORTYPE_VALUEPARSEERROR: - { - strcpy(tend,"VALUE_PARSE_ERROR");break; - } - case ICAL_XLICERRORTYPE_INVALIDITIP: - { - strcpy(tend,"INVALID_ITIP");break; - } - case ICAL_XLICERRORTYPE_UNKVCALPROP: - { - strcpy(tend,"UNKNOWN_VCAL_PROP_ERROR");break; - } - case ICAL_XLICERRORTYPE_MIMEPARSEERROR: - { - strcpy(tend,"MIME_PARSE_ERROR");break; - } - } - break; - } - - case ICAL_XLICCOMPARETYPE_PARAMETER: - { - switch (impl->data.v_xliccomparetype) { - case ICAL_XLICCOMPARETYPE_EQUAL: - { - strcpy(tend,"EQUAL");break; - } - case ICAL_XLICCOMPARETYPE_NOTEQUAL: - { - strcpy(tend,"NOTEQUAL");break; - } - case ICAL_XLICCOMPARETYPE_LESS: - { - strcpy(tend,"LESS");break; - } - case ICAL_XLICCOMPARETYPE_GREATER: - { - strcpy(tend,"GREATER");break; - } - case ICAL_XLICCOMPARETYPE_LESSEQUAL: - { - strcpy(tend,"LESSEQUAL");break; - } - case ICAL_XLICCOMPARETYPE_GREATEREQUAL: - { - strcpy(tend,"GREATEREQUAL");break; - } - case ICAL_XLICCOMPARETYPE_REGEX: - { - strcpy(tend,"REGEX");break; - } - default:{ - icalerror_set_errno(ICAL_BADARG_ERROR);break; - } - break; - } - - break; - } - - - case ICAL_SENTBY_PARAMETER: - case ICAL_TZID_PARAMETER: - case ICAL_X_PARAMETER: - case ICAL_FMTTYPE_PARAMETER: - case ICAL_LANGUAGE_PARAMETER: - case ICAL_MEMBER_PARAMETER: - case ICAL_DELEGATEDFROM_PARAMETER: - case ICAL_DELEGATEDTO_PARAMETER: - case ICAL_DIR_PARAMETER: - case ICAL_ALTREP_PARAMETER: - case ICAL_CN_PARAMETER: - { - if (impl->string == 0){ return no_parameter;} - strcpy(tend,impl->string);break; - break; - } - - case ICAL_NO_PARAMETER: - case ICAL_ANY_PARAMETER: - { - /* These are actually handled before the case/switch - clause */ - } - - } - - icalmemory_append_string(&buf, &buf_ptr, &buf_size, tend); - - /* Now, copy the buffer to a tmp_buffer, which is safe to give to - the caller without worring about de-allocating it. */ - - - out_buf = icalmemory_tmp_buffer(strlen(buf)); - strcpy(out_buf, buf); - - icalmemory_free_buffer(buf); - - return out_buf; - -} - - -int -icalparameter_is_valid (icalparameter* parameter); - - -icalparameter_kind -icalparameter_isa (icalparameter* parameter) -{ - if(parameter == 0){ - return ICAL_NO_PARAMETER; - } - - return ((struct icalparameter_impl *)parameter)->kind; -} - - -int -icalparameter_isa_parameter (void* parameter) -{ - struct icalparameter_impl *impl = (struct icalparameter_impl *)parameter; - - if (parameter == 0){ - return 0; - } - - if (strcmp(impl->id,"para") == 0) { - return 1; - } else { - return 0; - } -} - - -void -icalparameter_set_xname (icalparameter* param, const char* v) -{ - struct icalparameter_impl *impl = (struct icalparameter_impl*)param; - icalerror_check_arg_rv( (param!=0),"param"); - icalerror_check_arg_rv( (v!=0),"v"); - - if (impl->x_name != 0){ - free((void*)impl->x_name); - } - - impl->x_name = icalmemory_strdup(v); - - if (impl->x_name == 0){ - errno = ENOMEM; - } - -} - -const char* -icalparameter_get_xname (icalparameter* param) -{ - struct icalparameter_impl *impl = (struct icalparameter_impl*)param; - icalerror_check_arg_rz( (param!=0),"param"); - - return impl->x_name; -} - -void -icalparameter_set_xvalue (icalparameter* param, const char* v) -{ - struct icalparameter_impl *impl = (struct icalparameter_impl*)param; - - icalerror_check_arg_rv( (param!=0),"param"); - icalerror_check_arg_rv( (v!=0),"v"); - - if (impl->string != 0){ - free((void*)impl->string); - } - - impl->string = icalmemory_strdup(v); - - if (impl->string == 0){ - errno = ENOMEM; - } - -} - -const char* -icalparameter_get_xvalue (icalparameter* param) -{ - struct icalparameter_impl *impl = (struct icalparameter_impl*)param; - - icalerror_check_arg_rz( (param!=0),"param"); - - return impl->string; - -} - -void icalparameter_set_parent(icalparameter* param, - icalproperty* property) -{ - struct icalparameter_impl *impl = (struct icalparameter_impl*)param; - - icalerror_check_arg_rv( (param!=0),"param"); - - impl->parent = property; -} - -icalproperty* icalparameter_get_parent(icalparameter* param) -{ - struct icalparameter_impl *impl = (struct icalparameter_impl*)param; - - icalerror_check_arg_rz( (param!=0),"param"); - - return impl->parent; -} - - -/* Everything below this line is machine generated. Do not edit. */ diff --git a/libical/src/libical/icalparameter.h b/libical/src/libical/icalparameter.h new file mode 100644 index 0000000000..3f3b59f049 --- /dev/null +++ b/libical/src/libical/icalparameter.h @@ -0,0 +1,69 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: icalparam.h + CREATOR: eric 20 March 1999 + + + $Id$ + $Locker$ + + + + (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org + + This program is free software; you can redistribute it and/or modify + it under the terms of either: + + The LGPL as published by the Free Software Foundation, version + 2.1, available at: http://www.fsf.org/copyleft/lesser.html + + Or: + + The Mozilla Public License Version 1.0. You may obtain a copy of + the License at http://www.mozilla.org/MPL/ + + The original code is icalparam.h + + ======================================================================*/ + +#ifndef ICALPARAM_H +#define ICALPARAM_H + +#include "icalderivedparameter.h" + +/* Declared in icalderivedparameter.h */ +/*typedef void icalparameter;*/ + +icalparameter* icalparameter_new(icalparameter_kind kind); +icalparameter* icalparameter_new_clone(icalparameter* p); + +/* Create from string of form "PARAMNAME=VALUE" */ +icalparameter* icalparameter_new_from_string(const char* value); + +/* Create from just the value, the part after the "=" */ +icalparameter* icalparameter_new_from_value_string(icalparameter_kind kind, const char* value); + +void icalparameter_free(icalparameter* parameter); + +char* icalparameter_as_ical_string(icalparameter* parameter); + +int icalparameter_is_valid(icalparameter* parameter); + +icalparameter_kind icalparameter_isa(icalparameter* parameter); + +int icalparameter_isa_parameter(void* param); + +/* Acess the name of an X parameer */ +void icalparameter_set_xname (icalparameter* param, const char* v); +const char* icalparameter_get_xname(icalparameter* param); +void icalparameter_set_xvalue (icalparameter* param, const char* v); +const char* icalparameter_get_xvalue(icalparameter* param); + +/* Convert enumerations */ + +const char* icalparameter_kind_to_string(icalparameter_kind kind); +icalparameter_kind icalparameter_string_to_kind(const char* string); + + + +#endif diff --git a/libical/src/libical/icalparameter.h.in b/libical/src/libical/icalparameter.h.in deleted file mode 100644 index c215fa0fdc..0000000000 --- a/libical/src/libical/icalparameter.h.in +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: C -*- */ -/*====================================================================== - FILE: icalparam.h - CREATOR: eric 20 March 1999 - - - $Id: icalparameter.h.in,v 1.1.1.2 2001/01/23 19:20:40 jpr Exp $ - $Locker: $ - - - - (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org - - This program is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: http://www.fsf.org/copyleft/lesser.html - - Or: - - The Mozilla Public License Version 1.0. You may obtain a copy of - the License at http://www.mozilla.org/MPL/ - - The original code is icalparam.h - - ======================================================================*/ - -#ifndef ICALPARAM_H -#define ICALPARAM_H - -#include "icalenums.h" - -typedef void icalparameter; - -icalparameter* icalparameter_new(icalparameter_kind kind); -icalparameter* icalparameter_new_clone(icalparameter* p); -icalparameter* icalparameter_new_from_string(icalparameter_kind kind, char* value); - -void icalparameter_free(icalparameter* parameter); - -char* icalparameter_as_ical_string(icalparameter* parameter); - -int icalparameter_is_valid(icalparameter* parameter); - -icalparameter_kind icalparameter_isa(icalparameter* parameter); - -int icalparameter_isa_parameter(void* param); - -/* Acess the name of an X parameer */ -void icalparameter_set_xname (icalparameter* param, const char* v); -const char* icalparameter_get_xname(icalparameter* param); -void icalparameter_set_xvalue (icalparameter* param, const char* v); -const char* icalparameter_get_xvalue(icalparameter* param); - - -/* Everything below this line is machine generated. Do not edit. */ diff --git a/libical/src/libical/icalproperty.c b/libical/src/libical/icalproperty.c new file mode 100644 index 0000000000..c5638827e5 --- /dev/null +++ b/libical/src/libical/icalproperty.c @@ -0,0 +1,808 @@ +/* -*- Mode: C -*- */ + +/*====================================================================== + FILE: icalproperty.c + CREATOR: eric 28 April 1999 + + $Id$ + + + (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org + + This program is free software; you can redistribute it and/or modify + it under the terms of either: + + The LGPL as published by the Free Software Foundation, version + 2.1, available at: http://www.fsf.org/copyleft/lesser.html + + Or: + + The Mozilla Public License Version 1.0. You may obtain a copy of + the License at http://www.mozilla.org/MPL/ + + The original code is icalproperty.c + +======================================================================*/ +/*#line 27 "icalproperty.c.in"*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "icalproperty.h" +#include "icalparameter.h" +#include "icalcomponent.h" +#include "pvl.h" +#include "icalenums.h" +#include "icalerror.h" +#include "icalmemory.h" +#include "icalparser.h" + +#include /* For icalmemory_strdup, rindex */ +#include +#include +#include +#include /* for printf */ +#include /* for va_list, va_start, etc. */ + +#define TMP_BUF_SIZE 1024 + +/* Private routines for icalproperty */ +void icalvalue_set_parent(icalvalue* value, + icalproperty* property); +icalproperty* icalvalue_get_parent(icalvalue* value); + +void icalparameter_set_parent(icalparameter* param, + icalproperty* property); +icalproperty* icalparameter_get_parent(icalparameter* value); + + +void icalproperty_set_x_name(icalproperty* prop, char* name); + +struct icalproperty_impl +{ + char id[5]; + icalproperty_kind kind; + char* x_name; + pvl_list parameters; + pvl_elem parameter_iterator; + icalvalue* value; + icalcomponent *parent; +}; + +void icalproperty_add_parameters(struct icalproperty_impl *prop,va_list args) +{ + + void* vp; + + struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; + + while((vp = va_arg(args, void*)) != 0) { + + if (icalvalue_isa_value(vp) != 0 ){ + } else if (icalparameter_isa_parameter(vp) != 0 ){ + + icalproperty_add_parameter((icalproperty*)impl, + (icalparameter*)vp); + } else { + assert(0); + } + + } + + +} + + +struct icalproperty_impl* +icalproperty_new_impl (icalproperty_kind kind) +{ + struct icalproperty_impl* prop; + + if ( ( prop = (struct icalproperty_impl*) + malloc(sizeof(struct icalproperty_impl))) == 0) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return 0; + } + + strcpy(prop->id,"prop"); + + prop->kind = kind; + prop->parameters = pvl_newlist(); + prop->parameter_iterator = 0; + prop->value = 0; + prop->x_name = 0; + prop->parent = 0; + + return prop; +} + + +icalproperty* +icalproperty_new (icalproperty_kind kind) +{ + if(kind == ICAL_NO_PROPERTY){ + return 0; + } + + return (icalproperty*)icalproperty_new_impl(kind); +} + + +icalproperty* +icalproperty_new_clone(icalproperty* prop) +{ + struct icalproperty_impl *old = (struct icalproperty_impl*)prop; + struct icalproperty_impl *new = icalproperty_new_impl(old->kind); + pvl_elem p; + + icalerror_check_arg_rz((prop!=0),"Prop"); + icalerror_check_arg_rz((old!=0),"old"); + icalerror_check_arg_rz((new!=0),"new"); + + if (old->value !=0) { + new->value = icalvalue_new_clone(old->value); + } + + if (old->x_name != 0) { + + new->x_name = icalmemory_strdup(old->x_name); + + if (new->x_name == 0) { + icalproperty_free(new); + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return 0; + } + } + + for(p=pvl_head(old->parameters);p != 0; p = pvl_next(p)){ + icalparameter *param = icalparameter_new_clone(pvl_data(p)); + + if (param == 0){ + icalproperty_free(new); + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return 0; + } + + pvl_push(new->parameters,param); + + } + + return new; + +} + +icalproperty* icalproperty_new_from_string(char* str) +{ + + size_t buf_size = 1024; + char* buf = icalmemory_new_buffer(buf_size); + char* buf_ptr = buf; + icalproperty *prop; + icalcomponent *comp; + int errors = 0; + + icalerror_check_arg_rz( (str!=0),"str"); + + /* Is this a HACK or a crafty reuse of code? */ + + icalmemory_append_string(&buf, &buf_ptr, &buf_size, "BEGIN:VCALENDAR\n"); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, str); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, "\n"); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, "END:VCALENDAR\n"); + + comp = icalparser_parse_string(buf); + + if(comp == 0){ + icalerror_set_errno(ICAL_PARSE_ERROR); + return 0; + } + + errors = icalcomponent_count_errors(comp); + + prop = icalcomponent_get_first_property(comp,ICAL_ANY_PROPERTY); + + icalcomponent_remove_property(comp,prop); + + icalcomponent_free(comp); + free(buf); + + if(errors > 0){ + icalproperty_free(prop); + return 0; + } else { + return prop; + } + +} + +void +icalproperty_free (icalproperty* prop) +{ + struct icalproperty_impl *p; + + icalparameter* param; + + icalerror_check_arg_rv((prop!=0),"prop"); + + p = (struct icalproperty_impl*)prop; + +#ifdef ICAL_FREE_ON_LIST_IS_ERROR + icalerror_assert( (p->parent ==0),"Tried to free a property that is still attached to a component. "); + +#else + if(p->parent !=0){ + return; + } +#endif + + if (p->value != 0){ + icalvalue_set_parent(p->value,0); + icalvalue_free(p->value); + } + + while( (param = pvl_pop(p->parameters)) != 0){ + icalparameter_free(param); + } + + pvl_free(p->parameters); + + if (p->x_name != 0) { + free(p->x_name); + } + + p->kind = ICAL_NO_PROPERTY; + p->parameters = 0; + p->parameter_iterator = 0; + p->value = 0; + p->x_name = 0; + p->id[0] = 'X'; + + free(p); + +} + + +char* +icalproperty_as_ical_string (icalproperty* prop) +{ + icalparameter *param; + + /* Create new buffer that we can append names, parameters and a + value to, and reallocate as needed. Later, this buffer will be + copied to a icalmemory_tmp_buffer, which is managed internally + by libical, so it can be given to the caller without fear of + the caller forgetting to free it */ + + const char* property_name = 0; + size_t buf_size = 1024; + char* buf = icalmemory_new_buffer(buf_size); + char* buf_ptr = buf; + icalvalue* value; + char *out_buf; + + char newline[] = "\n"; + + struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; + + icalerror_check_arg_rz( (prop!=0),"prop"); + + + /* Append property name */ + + if (impl->kind == ICAL_X_PROPERTY && impl->x_name != 0){ + property_name = impl->x_name; + } else { + property_name = icalproperty_kind_to_string(impl->kind); + } + + if (property_name == 0 ) { + icalerror_warn("Got a property of an unknown kind."); + icalmemory_free_buffer(buf); + return 0; + + } + + + icalmemory_append_string(&buf, &buf_ptr, &buf_size, property_name); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline); + + + + /* Determine what VALUE parameter to include. The VALUE parameters + are ignored in the normal parameter printing ( the block after + this one, so we need to do it here */ + { + const char* kind_string = 0; + + icalparameter *orig_val_param + = icalproperty_get_first_parameter(prop,ICAL_VALUE_PARAMETER); + + icalvalue *value = icalproperty_get_value(impl); + + icalvalue_kind orig_kind = ICAL_NO_VALUE; + + icalvalue_kind this_kind = ICAL_NO_VALUE; + + icalvalue_kind default_kind + = icalproperty_kind_to_value_kind(impl->kind); + + if(orig_val_param){ + orig_kind = (icalvalue_kind)icalparameter_get_value(orig_val_param); + } + + if(value != 0){ + this_kind = icalvalue_isa(value); + } + + + if(this_kind == default_kind && + orig_kind != ICAL_NO_VALUE){ + /* The kind is the default, so it does not need to be + included, but do it anyway, since it was explicit in + the property. But, use the default, not the one + specified in the property */ + + kind_string = icalvalue_kind_to_string(default_kind); + + } else if (this_kind != default_kind && this_kind != ICAL_NO_VALUE){ + /* Not the default, so it must be specified */ + kind_string = icalvalue_kind_to_string(this_kind); + } else { + /* Don'tinclude the VALUE parameter at all */ + } + + if(kind_string!=0){ + icalmemory_append_string(&buf, &buf_ptr, &buf_size, " ;"); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, "VALUE="); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline); + } + + + } + + /* Append parameters */ + for(param = icalproperty_get_first_parameter(prop,ICAL_ANY_PARAMETER); + param != 0; + param = icalproperty_get_next_parameter(prop,ICAL_ANY_PARAMETER)) { + + char* kind_string = icalparameter_as_ical_string(param); + icalparameter_kind kind = icalparameter_isa(param); + + if(kind==ICAL_VALUE_PARAMETER){ + continue; + } + + if (kind_string == 0 ) { + 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, newline); + + } + + /* Append value */ + + icalmemory_append_string(&buf, &buf_ptr, &buf_size, " :"); + + value = icalproperty_get_value(prop); + + if (value != 0){ + const char *str = icalvalue_as_ical_string(value); + icalerror_assert((str !=0),"Could not get string representation of a value"); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, str); + } else { + icalmemory_append_string(&buf, &buf_ptr, &buf_size,"ERROR: No Value"); + + } + + 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. */ + + + out_buf = icalmemory_tmp_buffer(strlen(buf)+1); + strcpy(out_buf, buf); + + icalmemory_free_buffer(buf); + + return out_buf; +} + + + +icalproperty_kind +icalproperty_isa (icalproperty* property) +{ + struct icalproperty_impl *p = (struct icalproperty_impl*)property; + + if(property != 0){ + return p->kind; + } + + return ICAL_NO_PROPERTY; +} + +int +icalproperty_isa_property (void* property) +{ + struct icalproperty_impl *impl = (struct icalproperty_impl*)property; + + icalerror_check_arg_rz( (property!=0), "property"); + + if (strcmp(impl->id,"prop") == 0) { + return 1; + } else { + return 0; + } +} + + +void +icalproperty_add_parameter (icalproperty* prop,icalparameter* parameter) +{ + struct icalproperty_impl *p = (struct icalproperty_impl*)prop; + + icalerror_check_arg_rv( (prop!=0),"prop"); + icalerror_check_arg_rv( (parameter!=0),"parameter"); + + pvl_push(p->parameters, parameter); + +} + +void +icalproperty_set_parameter (icalproperty* prop,icalparameter* parameter) +{ + icalparameter_kind kind; + + icalerror_check_arg_rv( (prop!=0),"prop"); + icalerror_check_arg_rv( (parameter!=0),"parameter"); + + kind = icalparameter_isa(parameter); + + icalproperty_remove_parameter(prop,kind); + + icalproperty_add_parameter(prop,parameter); +} + +void icalproperty_set_parameter_from_string(icalproperty* prop, + const char* name, const char* value) +{ + + icalparameter_kind kind; + icalparameter *param; + + icalerror_check_arg_rv( (prop!=0),"prop"); + icalerror_check_arg_rv( (name!=0),"name"); + icalerror_check_arg_rv( (value!=0),"value"); + + kind = icalparameter_string_to_kind(name); + + if(kind == ICAL_NO_PARAMETER){ + icalerror_set_errno(ICAL_BADARG_ERROR); + return; + } + + param = icalparameter_new_from_value_string(kind,value); + + if (param == 0){ + icalerror_set_errno(ICAL_BADARG_ERROR); + return; + } + + icalproperty_set_parameter(prop,param); + +} + +const char* icalproperty_get_parameter_as_string(icalproperty* prop, + const char* name) +{ + icalparameter_kind kind; + icalparameter *param; + char* str; + char* pv; + + icalerror_check_arg_rz( (prop!=0),"prop"); + icalerror_check_arg_rz( (name!=0),"name"); + + kind = icalparameter_string_to_kind(name); + + if(kind == ICAL_NO_PROPERTY){ + /* icalenum_string_to_parameter_kind will set icalerrno */ + return 0; + } + + param = icalproperty_get_first_parameter(prop,kind); + + if (param == 0){ + return 0; + } + + str = icalparameter_as_ical_string(param); + + pv = strchr(str,'='); + + if(pv == 0){ + icalerror_set_errno(ICAL_INTERNAL_ERROR); + return 0; + } + + return pv+1; + +} + +void +icalproperty_remove_parameter (icalproperty* prop, icalparameter_kind kind) +{ + pvl_elem p; + struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; + + icalerror_check_arg_rv((prop!=0),"prop"); + + for(p=pvl_head(impl->parameters);p != 0; p = pvl_next(p)){ + icalparameter* param = (icalparameter *)pvl_data (p); + if (icalparameter_isa(param) == kind) { + pvl_remove (impl->parameters, p); + icalparameter_free (param); + break; + } + } +} + + +int +icalproperty_count_parameters (icalproperty* prop) +{ + struct icalproperty_impl *p = (struct icalproperty_impl*)prop; + + if(prop != 0){ + return pvl_count(p->parameters); + } + + icalerror_set_errno(ICAL_USAGE_ERROR); + return -1; +} + + +icalparameter* +icalproperty_get_first_parameter (icalproperty* prop, icalparameter_kind kind) +{ + struct icalproperty_impl *p = (struct icalproperty_impl*)prop; + + icalerror_check_arg_rz( (prop!=0),"prop"); + + p->parameter_iterator = pvl_head(p->parameters); + + if (p->parameter_iterator == 0) { + return 0; + } + + for( p->parameter_iterator = pvl_head(p->parameters); + p->parameter_iterator !=0; + p->parameter_iterator = pvl_next(p->parameter_iterator)){ + + icalparameter *param = (icalparameter*)pvl_data(p->parameter_iterator); + + if(icalparameter_isa(param) == kind || kind == ICAL_ANY_PARAMETER){ + return param; + } + } + + return 0; +} + + +icalparameter* +icalproperty_get_next_parameter (icalproperty* prop, icalparameter_kind kind) +{ + struct icalproperty_impl *p = (struct icalproperty_impl*)prop; + + icalerror_check_arg_rz( (prop!=0),"prop"); + + if (p->parameter_iterator == 0) { + return 0; + } + + for( p->parameter_iterator = pvl_next(p->parameter_iterator); + p->parameter_iterator !=0; + p->parameter_iterator = pvl_next(p->parameter_iterator)){ + + icalparameter *param = (icalparameter*)pvl_data(p->parameter_iterator); + + if(icalparameter_isa(param) == kind || kind == ICAL_ANY_PARAMETER){ + return param; + } + } + + return 0; + +} + +void +icalproperty_set_value (icalproperty* prop, icalvalue* value) +{ + struct icalproperty_impl *p = (struct icalproperty_impl*)prop; + + icalerror_check_arg_rv((prop !=0),"prop"); + icalerror_check_arg_rv((value !=0),"value"); + + if (p->value != 0){ + icalvalue_set_parent(p->value,0); + icalvalue_free(p->value); + p->value = 0; + } + + p->value = value; + + icalvalue_set_parent(value,prop); +} + + +void icalproperty_set_value_from_string(icalproperty* prop,const char* str, + const char* type) +{ + icalvalue *oval,*nval; + icalvalue_kind kind = ICAL_NO_VALUE; + + icalerror_check_arg_rv( (prop!=0),"prop"); + icalerror_check_arg_rv( (str!=0),"str"); + icalerror_check_arg_rv( (type!=0),"type"); + + if(strcmp(type,"NO")==0){ + /* Get the type from the value the property already has, if it exists */ + oval = icalproperty_get_value(prop); + if(oval != 0){ + /* Use the existing value kind */ + kind = icalvalue_isa(oval); + } else { + /* Use the default kind for the property */ + kind = icalproperty_kind_to_value_kind(icalproperty_isa(prop)); + } + } else { + /* Use the given kind string */ + kind = icalvalue_string_to_kind(type); + } + + if(kind == ICAL_NO_VALUE){ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return; + } + + nval = icalvalue_new_from_string(kind, str); + + if(nval == 0){ + /* icalvalue_new_from_string sets errno */ + assert(icalerrno != ICAL_NO_ERROR); + return; + } + + icalproperty_set_value(prop,nval); + + +} + +icalvalue* +icalproperty_get_value (icalproperty* prop) +{ + struct icalproperty_impl *p = (struct icalproperty_impl*)prop; + + icalerror_check_arg_rz( (prop!=0),"prop"); + + return p->value; +} + +const char* icalproperty_get_value_as_string(icalproperty* prop) +{ + icalvalue *value; + + struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; + + icalerror_check_arg_rz( (prop!=0),"prop"); + + value = impl->value; + + return icalvalue_as_ical_string(value); +} + + +void icalproperty_set_x_name(icalproperty* prop, char* name) +{ + struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; + + icalerror_check_arg_rv( (name!=0),"name"); + icalerror_check_arg_rv( (prop!=0),"prop"); + + if (impl->x_name != 0) { + free(impl->x_name); + } + + impl->x_name = icalmemory_strdup(name); + + if(impl->x_name == 0){ + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + } + +} + +char* icalproperty_get_x_name(icalproperty* prop){ + + struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; + + icalerror_check_arg_rz( (prop!=0),"prop"); + + return impl->x_name; +} + + +/* From Jonathan Yue */ +char* icalproperty_get_name (icalproperty* prop) +{ + + const char* property_name = 0; + size_t buf_size = 256; + char* buf = icalmemory_new_buffer(buf_size); + char* buf_ptr = buf; + + struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; + + icalerror_check_arg_rz( (prop!=0),"prop"); + + if (impl->kind == ICAL_X_PROPERTY && impl->x_name != 0){ + property_name = impl->x_name; + } else { + property_name = icalproperty_kind_to_string(impl->kind); + } + + if (property_name == 0 ) { + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return 0; + + } else { + /* _append_string will automatically grow the buffer if + property_name is longer than the initial buffer size */ + icalmemory_append_string(&buf, &buf_ptr, &buf_size, property_name); + } + + /* Add the buffer to the temporary buffer ring -- the caller will + not have to free the memory. */ + icalmemory_add_tmp_buffer(buf); + + return buf; +} + + + + +void icalproperty_set_parent(icalproperty* property, + icalcomponent* component) +{ + struct icalproperty_impl *impl = (struct icalproperty_impl*)property; + + icalerror_check_arg_rv( (property!=0),"property"); + + impl->parent = component; +} + +icalcomponent* icalproperty_get_parent(icalproperty* property) +{ + struct icalproperty_impl *impl = (struct icalproperty_impl*)property; + + icalerror_check_arg_rz( (property!=0),"property"); + + return impl->parent; +} + + + + + + + +/* Everything below this line is machine generated. Do not edit. */ diff --git a/libical/src/libical/icalproperty.c.in b/libical/src/libical/icalproperty.c.in deleted file mode 100644 index 936db3f728..0000000000 --- a/libical/src/libical/icalproperty.c.in +++ /dev/null @@ -1,616 +0,0 @@ -/* -*- Mode: C -*- */ - -/*====================================================================== - FILE: icalproperty.c - CREATOR: eric 28 April 1999 - - $Id: icalproperty.c.in,v 1.4 2001/02/05 19:43:57 jpr Exp $ - - - (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org - - This program is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: http://www.fsf.org/copyleft/lesser.html - - Or: - - The Mozilla Public License Version 1.0. You may obtain a copy of - the License at http://www.mozilla.org/MPL/ - - The original code is icalproperty.c - -======================================================================*/ -/*#line 27 "icalproperty.c.in"*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "icalproperty.h" -#include "icalcomponent.h" -#include "pvl.h" -#include "icalenums.h" -#include "icalerror.h" -#include "icalmemory.h" - -#include /* For icalmemory_strdup, rindex */ -#include -#include -#include -#include /* for printf */ -#include /* for va_list, va_start, etc. */ - -#define TMP_BUF_SIZE 1024 - -/* Private routines for icalproperty */ -void icalvalue_set_parent(icalvalue* value, - icalproperty* property); -icalproperty* icalvalue_get_parent(icalvalue* value); - -void icalparameter_set_parent(icalparameter* param, - icalproperty* property); -icalproperty* icalparameter_get_parent(icalparameter* value); - - -void icalproperty_set_x_name(icalproperty* prop, char* name); - -struct icalproperty_impl -{ - char id[5]; - icalproperty_kind kind; - char* x_name; - pvl_list parameters; - pvl_elem parameter_iterator; - icalvalue* value; - icalcomponent *parent; -}; - -void icalproperty_add_parameters(struct icalproperty_impl *impl,va_list args) -{ - - void* vp; - - while((vp = va_arg(args, void*)) != 0) { - - if (icalvalue_isa_value(vp) != 0 ){ - } else if (icalparameter_isa_parameter(vp) != 0 ){ - - icalproperty_add_parameter((icalproperty*)impl, - (icalparameter*)vp); - } else { - assert(0); - } - - } - - -} - - -struct icalproperty_impl* -icalproperty_new_impl (icalproperty_kind kind) -{ - struct icalproperty_impl* prop; - - if ( ( prop = (struct icalproperty_impl*) - malloc(sizeof(struct icalproperty_impl))) == 0) { - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; - } - - strcpy(prop->id,"prop"); - - prop->kind = kind; - prop->parameters = pvl_newlist(); - prop->parameter_iterator = 0; - prop->value = 0; - prop->x_name = 0; - prop->parent = 0; - - return prop; -} - - -icalproperty* -icalproperty_new (icalproperty_kind kind) -{ - icalproperty *prop = (icalproperty*)icalproperty_new_impl(kind); - - return prop; -} - - -icalproperty* -icalproperty_new_clone(icalproperty* prop) -{ - struct icalproperty_impl *old = (struct icalproperty_impl*)prop; - struct icalproperty_impl *new = icalproperty_new_impl(old->kind); - pvl_elem p; - - icalerror_check_arg_rz((prop!=0),"Prop"); - icalerror_check_arg_rz((old!=0),"old"); - icalerror_check_arg_rz((new!=0),"new"); - - if (old->value !=0) { - new->value = icalvalue_new_clone(old->value); - } - - if (old->x_name != 0) { - - new->x_name = icalmemory_strdup(old->x_name); - - if (new->x_name == 0) { - icalproperty_free(new); - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; - } - } - - for(p=pvl_head(old->parameters);p != 0; p = pvl_next(p)){ - icalparameter *param = icalparameter_new_clone(pvl_data(p)); - - if (param == 0){ - icalproperty_free(new); - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; - } - - pvl_push(new->parameters,param); - - } - - return new; - -} - -/* This one works a little differently from the other *_from_string - routines; the string input is the name of the property, not the - data associated with the property, as it is in - icalvalue_from_string. All of the parsing associated with - properties is driven by routines in icalparse.c */ - -icalproperty* icalproperty_new_from_string(char* str) -{ - icalproperty_kind kind; - - icalerror_check_arg_rz( (str!=0),"str"); - - kind = icalenum_string_to_property_kind(str); - - if(kind == ICAL_X_PROPERTY){ - icalproperty *p = icalproperty_new(ICAL_X_PROPERTY); - icalproperty_set_x_name(p,str); - return p; - } else if (kind == ICAL_NO_PROPERTY){ - icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); - return 0; - } else { - return icalproperty_new(kind); - } -} - -void -icalproperty_free (icalproperty* prop) -{ - struct icalproperty_impl *p; - - icalparameter* param; - - icalerror_check_arg_rv((prop!=0),"prop"); - - p = (struct icalproperty_impl*)prop; - -#ifdef ICAL_FREE_ON_LIST_IS_ERROR - icalerror_assert( (p->parent ==0),"Tried to free a property that is still attached to a component. "); - -#else - if(p->parent !=0){ - return; - } -#endif - - if (p->value != 0){ - icalvalue_set_parent(p->value,0); - icalvalue_free(p->value); - } - - while( (param = pvl_pop(p->parameters)) != 0){ - icalparameter_free(param); - } - - pvl_free(p->parameters); - - if (p->x_name != 0) { - free(p->x_name); - } - - p->kind = ICAL_NO_PROPERTY; - p->parameters = 0; - p->parameter_iterator = 0; - p->value = 0; - p->x_name = 0; - p->id[0] = 'X'; - - free(p); - -} - - -char* -icalproperty_as_ical_string (icalproperty* prop) -{ - icalparameter *param; - - /* Create new buffer that we can append names, parameters and a - value to, and reallocate as needed. Later, this buffer will be - copied to a icalmemory_tmp_buffer, which is managed internally - by libical, so it can be given to the caller without fear of - the caller forgetting to free it */ - - const char* property_name = 0; - size_t buf_size = 1024; - char* buf = icalmemory_new_buffer(buf_size); - char* buf_ptr = buf; - icalvalue* value; - char *out_buf; - - char newline[] = "\n"; - - struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; - - icalerror_check_arg_rz( (prop!=0),"prop"); - - - /* Append property name */ - - if (impl->kind == ICAL_X_PROPERTY && impl->x_name != 0){ - property_name = impl->x_name; - } else { - property_name = icalenum_property_kind_to_string(impl->kind); - } - - if (property_name == 0 ) { - icalerror_warn("Got a property of an unknown kind."); - icalmemory_free_buffer(buf); - return 0; - - } - - - icalmemory_append_string(&buf, &buf_ptr, &buf_size, property_name); - icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline); - - - - /* Determine what VALUE parameter to include. The VALUE parameters - are ignored in the normal parameter printing ( the block after - this one, so we need to do it here */ - { - const char* kind_string = 0; - - icalparameter *orig_val_param - = icalproperty_get_first_parameter(prop,ICAL_VALUE_PARAMETER); - - icalvalue *value = icalproperty_get_value(impl); - - icalvalue_kind orig_kind = ICAL_NO_VALUE; - - icalvalue_kind this_kind = ICAL_NO_VALUE; - - icalvalue_kind default_kind - = icalenum_property_kind_to_value_kind(impl->kind); - - if(orig_val_param){ - orig_kind = (icalvalue_kind)icalparameter_get_value(orig_val_param); - } - - if(value != 0){ - this_kind = icalvalue_isa(value); - } - - - if(this_kind == default_kind && - orig_kind != ICAL_NO_VALUE){ - /* The kind is the default, so it does not need to be - included, but do it anyway, since it was explicit in - the property. But, use the default, not the one - specified in the property */ - - kind_string = icalenum_value_kind_to_string(default_kind); - - } else if (this_kind != default_kind && this_kind != ICAL_NO_VALUE){ - /* Not the default, so it must be specified */ - kind_string = icalenum_value_kind_to_string(this_kind); - } else { - /* Don'tinclude the VALUE parameter at all */ - } - - if(kind_string!=0){ - icalmemory_append_string(&buf, &buf_ptr, &buf_size, " ;"); - icalmemory_append_string(&buf, &buf_ptr, &buf_size, "VALUE="); - icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string); - icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline); - } - - - } - - /* Append parameters */ - for(param = icalproperty_get_first_parameter(prop,ICAL_ANY_PARAMETER); - param != 0; - param = icalproperty_get_next_parameter(prop,ICAL_ANY_PARAMETER)) { - - char* kind_string = icalparameter_as_ical_string(param); - icalparameter_kind kind = icalparameter_isa(param); - - if(kind==ICAL_VALUE_PARAMETER){ - continue; - } - - if (kind_string == 0 ) { - 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, newline); - - } - - /* Append value */ - - icalmemory_append_string(&buf, &buf_ptr, &buf_size, " :"); - - value = icalproperty_get_value(prop); - - if (value != 0){ - const char *str = icalvalue_as_ical_string(value); - icalerror_assert((str !=0),"Could not get string representation of a value"); - icalmemory_append_string(&buf, &buf_ptr, &buf_size, str); - } else { - icalmemory_append_string(&buf, &buf_ptr, &buf_size,"ERROR: No Value"); - - } - - 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. */ - - - out_buf = icalmemory_tmp_buffer(strlen(buf)+1); - strcpy(out_buf, buf); - - icalmemory_free_buffer(buf); - - return out_buf; -} - - - -icalproperty_kind -icalproperty_isa (icalproperty* property) -{ - struct icalproperty_impl *p = (struct icalproperty_impl*)property; - - if(property != 0){ - return p->kind; - } - - return ICAL_NO_PROPERTY; -} - -int -icalproperty_isa_property (void* property) -{ - struct icalproperty_impl *impl = (struct icalproperty_impl*)property; - - icalerror_check_arg_rz( (property!=0), "property"); - - if (strcmp(impl->id,"prop") == 0) { - return 1; - } else { - return 0; - } -} - - -void -icalproperty_add_parameter (icalproperty* prop,icalparameter* parameter) -{ - struct icalproperty_impl *p = (struct icalproperty_impl*)prop; - - icalerror_check_arg_rv( (prop!=0),"prop"); - icalerror_check_arg_rv( (parameter!=0),"parameter"); - - pvl_push(p->parameters, parameter); - -} - -void -icalproperty_set_parameter (icalproperty* prop,icalparameter* parameter) -{ - icalparameter_kind kind; - - kind = icalparameter_isa(parameter); - - icalproperty_remove_parameter(prop,kind); - - icalproperty_add_parameter(prop,parameter); -} - - -void -icalproperty_remove_parameter (icalproperty* prop, icalparameter_kind kind) -{ - pvl_elem p; - struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; - - icalerror_check_arg_rv((prop!=0),"prop"); - - for(p=pvl_head(impl->parameters);p != 0; p = pvl_next(p)){ - icalparameter* param = (icalparameter *)pvl_data (p); - if (icalparameter_isa(param) == kind) { - pvl_remove (impl->parameters, p); - icalparameter_free (param); - break; - } - } -} - - -int -icalproperty_count_parameters (icalproperty* prop) -{ - struct icalproperty_impl *p = (struct icalproperty_impl*)prop; - - if(prop != 0){ - return pvl_count(p->parameters); - } - - icalerror_set_errno(ICAL_USAGE_ERROR); - return -1; -} - - -icalparameter* -icalproperty_get_first_parameter (icalproperty* prop, icalparameter_kind kind) -{ - struct icalproperty_impl *p = (struct icalproperty_impl*)prop; - - icalerror_check_arg_rz( (prop!=0),"prop"); - - p->parameter_iterator = pvl_head(p->parameters); - - if (p->parameter_iterator == 0) { - return 0; - } - - for( p->parameter_iterator = pvl_head(p->parameters); - p->parameter_iterator !=0; - p->parameter_iterator = pvl_next(p->parameter_iterator)){ - - icalparameter *param = (icalparameter*)pvl_data(p->parameter_iterator); - - if(icalparameter_isa(param) == kind || kind == ICAL_ANY_PARAMETER){ - return param; - } - } - - return 0; -} - - -icalparameter* -icalproperty_get_next_parameter (icalproperty* prop, icalparameter_kind kind) -{ - struct icalproperty_impl *p = (struct icalproperty_impl*)prop; - - icalerror_check_arg_rz( (prop!=0),"prop"); - - if (p->parameter_iterator == 0) { - return 0; - } - - for( p->parameter_iterator = pvl_next(p->parameter_iterator); - p->parameter_iterator !=0; - p->parameter_iterator = pvl_next(p->parameter_iterator)){ - - icalparameter *param = (icalparameter*)pvl_data(p->parameter_iterator); - - if(icalparameter_isa(param) == kind || kind == ICAL_ANY_PARAMETER){ - return param; - } - } - - return 0; - -} - -void -icalproperty_set_value (icalproperty* prop, icalvalue* value) -{ - struct icalproperty_impl *p = (struct icalproperty_impl*)prop; - - icalerror_check_arg_rv((prop !=0),"prop"); - icalerror_check_arg_rv((value !=0),"value"); - - if (p->value != 0){ - icalvalue_set_parent(p->value,0); - icalvalue_free(p->value); - p->value = 0; - } - - p->value = value; - - icalvalue_set_parent(value,prop); -} - - -icalvalue* -icalproperty_get_value (icalproperty* prop) -{ - struct icalproperty_impl *p = (struct icalproperty_impl*)prop; - - icalerror_check_arg_rz( (prop!=0),"prop"); - - return p->value; -} - - -void icalproperty_set_x_name(icalproperty* prop, char* name) -{ - struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; - - icalerror_check_arg_rv( (name!=0),"name"); - icalerror_check_arg_rv( (prop!=0),"prop"); - - if (impl->x_name != 0) { - free(impl->x_name); - } - - impl->x_name = icalmemory_strdup(name); - - if(impl->x_name == 0){ - icalerror_set_errno(ICAL_ALLOCATION_ERROR); - } - -} - -char* icalproperty_get_x_name(icalproperty* prop){ - - struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; - - icalerror_check_arg_rz( (prop!=0),"prop"); - - return impl->x_name; -} - - -void icalproperty_set_parent(icalproperty* property, - icalcomponent* component) -{ - struct icalproperty_impl *impl = (struct icalproperty_impl*)property; - - icalerror_check_arg_rv( (property!=0),"property"); - - impl->parent = component; -} - -icalcomponent* icalproperty_get_parent(icalproperty* property) -{ - struct icalproperty_impl *impl = (struct icalproperty_impl*)property; - - icalerror_check_arg_rv( (property!=0),"property"); - - return impl->parent; -} - - -/* Everything below this line is machine generated. Do not edit. */ diff --git a/libical/src/libical/icalproperty.h b/libical/src/libical/icalproperty.h new file mode 100644 index 0000000000..6f5f1bfaef --- /dev/null +++ b/libical/src/libical/icalproperty.h @@ -0,0 +1,116 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: icalproperty.h + CREATOR: eric 20 March 1999 + + + $Id$ + $Locker$ + + + + (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org + + This program is free software; you can redistribute it and/or modify + it under the terms of either: + + The LGPL as published by the Free Software Foundation, version + 2.1, available at: http://www.fsf.org/copyleft/lesser.html + + Or: + + The Mozilla Public License Version 1.0. You may obtain a copy of + the License at http://www.mozilla.org/MPL/ + + The original code is icalparam.h + + ======================================================================*/ + + +#ifndef ICALPROPERTY_H +#define ICALPROPERTY_H + +#include + + +#include "icalderivedparameter.h" + +#include "icalvalue.h" +#include "icalrecur.h" + +/* Actually in icalderivedproperty.h: + typedef void icalproperty; */ + +#include "icalderivedproperty.h" /* To get icalproperty_kind enumerations */ + +icalproperty* icalproperty_new(icalproperty_kind kind); + +icalproperty* icalproperty_new_clone(icalproperty * prop); + +icalproperty* icalproperty_new_from_string(char* str); + +char* icalproperty_as_ical_string(icalproperty* prop); + +void icalproperty_free(icalproperty* prop); + +icalproperty_kind icalproperty_isa(icalproperty* property); +int icalproperty_isa_property(void* property); + +void icalproperty_add_parameter(icalproperty* prop,icalparameter* parameter); +void icalproperty_set_parameter(icalproperty* prop,icalparameter* parameter); +void icalproperty_set_parameter_from_string(icalproperty* prop, + const char* name, const char* value); +const char* icalproperty_get_parameter_as_string(icalproperty* prop, + const char* name); + +void icalproperty_remove_parameter(icalproperty* prop, + icalparameter_kind kind); + +int icalproperty_count_parameters(icalproperty* prop); + +/* Iterate through the parameters */ +icalparameter* icalproperty_get_first_parameter(icalproperty* prop, + icalparameter_kind kind); +icalparameter* icalproperty_get_next_parameter(icalproperty* prop, + icalparameter_kind kind); +/* Access the value of the property */ +void icalproperty_set_value(icalproperty* prop, icalvalue* value); +void icalproperty_set_value_from_string(icalproperty* prop,const char* value, const char* kind); + +icalvalue* icalproperty_get_value(icalproperty* prop); +const char* icalproperty_get_value_as_string(icalproperty* prop); + +/* Deal with X properties */ + +void icalproperty_set_x_name(icalproperty* prop, char* name); +char* icalproperty_get_x_name(icalproperty* prop); + +/* Return the name of the property -- the type name converted to a + string, or the value of _get_x_name if the type is and X property */ +char* icalproperty_get_name (icalproperty* prop); + +icalvalue_kind icalparameter_value_to_value_kind(icalparameter_value value); + +/* Convert kinds to string and get default value type */ + +icalvalue_kind icalproperty_kind_to_value_kind(icalproperty_kind kind); +icalvalue_kind icalproperty_value_kind_to_kind(icalvalue_kind kind); +const char* icalproperty_kind_to_string(icalproperty_kind kind); +icalproperty_kind icalproperty_string_to_kind(const char* string); + +icalproperty_method icalproperty_string_to_method(const char* str); +const char* icalproperty_method_to_string(icalproperty_method method); + + +const char* icalproperty_enum_to_string(int e); +int icalproperty_string_to_enum(const char* str); + +const char* icalproperty_status_to_string(icalproperty_status); +icalproperty_status icalproperty_string_to_status(const char* string); + +int icalproperty_enum_belongs_to_property(icalproperty_kind kind, int e); + + + + +#endif /*ICALPROPERTY_H*/ diff --git a/libical/src/libical/icalproperty.h.in b/libical/src/libical/icalproperty.h.in deleted file mode 100644 index be74b38d43..0000000000 --- a/libical/src/libical/icalproperty.h.in +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: C -*- - ====================================================================== - FILE: icalderivedproperties.{c,h} - CREATOR: eric 09 May 1999 - - $Id: icalproperty.h.in,v 1.1.1.2 2001/01/23 19:20:40 jpr Exp $ - - (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org - ======================================================================*/ - - -#ifndef ICALPROPERTY_H -#define ICALPROPERTY_H - -#include -#include "icalparameter.h" -#include "icalvalue.h" -#include "icalrecur.h" - -typedef void icalproperty; - -icalproperty* icalproperty_new(icalproperty_kind kind); - -icalproperty* icalproperty_new_clone(icalproperty * prop); - -icalproperty* icalproperty_new_from_string(char* str); - -char* icalproperty_as_ical_string(icalproperty* prop); - -void icalproperty_free(icalproperty* prop); - -icalproperty_kind icalproperty_isa(icalproperty* property); -int icalproperty_isa_property(void* property); - -void icalproperty_add_parameter(icalproperty* prop,icalparameter* parameter); -void icalproperty_set_parameter(icalproperty* prop,icalparameter* parameter); - -void icalproperty_remove_parameter(icalproperty* prop, - icalparameter_kind kind); - -int icalproperty_count_parameters(icalproperty* prop); - -/* Iterate through the parameters */ -icalparameter* icalproperty_get_first_parameter(icalproperty* prop, - icalparameter_kind kind); -icalparameter* icalproperty_get_next_parameter(icalproperty* prop, - icalparameter_kind kind); -/* Access the value of the property */ -void icalproperty_set_value(icalproperty* prop, icalvalue* value); -icalvalue* icalproperty_get_value(icalproperty* prop); - -/* Deal with X properties */ - -void icalproperty_set_x_name(icalproperty* prop, char* name); -char* icalproperty_get_x_name(icalproperty* prop); - -/* Everything below this line is machine generated. Do not edit. */ diff --git a/libical/src/libical/icaltime.c b/libical/src/libical/icaltime.c index 37ae194bd0..d29833f03f 100644 --- a/libical/src/libical/icaltime.c +++ b/libical/src/libical/icaltime.c @@ -170,7 +170,7 @@ time_t icaltime_as_timet(struct icaltimetype tt) stm.tm_isdst = -1; if(tt.is_utc == 1 || tt.is_date == 1){ - char* old_tz = set_tz("UTC"); + struct set_tz_save old_tz = set_tz("UTC"); t = mktime(&stm); unset_tz(old_tz); } else { @@ -248,20 +248,19 @@ int icaltime_utc_offset(struct icaltimetype ictt, const char* tzid) time_t tt = icaltime_as_timet(ictt); time_t offset_tt; struct tm gtm; - - char *tzstr = 0; + struct set_tz_save old_tz; if(tzid != 0){ - tzstr = set_tz(tzid); + old_tz = set_tz(tzid); } - + /* Mis-interpret a UTC broken out time as local time */ gtm = *(gmtime(&tt)); gtm.tm_isdst = localtime(&tt)->tm_isdst; offset_tt = mktime(>m); if(tzid != 0){ - unset_tz(tzstr); + unset_tz(old_tz); } return tt-offset_tt; diff --git a/libical/src/libical/icalvalue.c b/libical/src/libical/icalvalue.c new file mode 100644 index 0000000000..e7054bb80d --- /dev/null +++ b/libical/src/libical/icalvalue.c @@ -0,0 +1,1197 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: icalvalue.c + CREATOR: eric 02 May 1999 + + $Id$ + + + (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org + + This program is free software; you can redistribute it and/or modify + it under the terms of either: + + The LGPL as published by the Free Software Foundation, version + 2.1, available at: http://www.fsf.org/copyleft/lesser.html + + Or: + + The Mozilla Public License Version 1.0. You may obtain a copy of + the License at http://www.mozilla.org/MPL/ + + The original code is icalvalue.c + + Contributions from: + Graham Davison (g.m.davison@computer.org) + + +======================================================================*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "icalerror.h" +#include "icalmemory.h" +#include "icalparser.h" +#include "icalenums.h" +#include "icalvalueimpl.h" + +#include /* for malloc */ +#include /* for sprintf */ +#include /* For memset, others */ +#include /* For offsetof() macro */ +#include +#include /* for mktime */ +#include /* for atoi and atof */ +#include /* for SHRT_MAX */ + +#if _MAC_OS_ +#include "icalmemory_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); +void print_recur_to_string(char* str, struct icaltimetype *data); + + +struct icalvalue_impl* icalvalue_new_impl(icalvalue_kind kind){ + + struct icalvalue_impl* v; + + if ( ( v = (struct icalvalue_impl*) + malloc(sizeof(struct icalvalue_impl))) == 0) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return 0; + } + + strcpy(v->id,"val"); + + v->kind = kind; + v->size = 0; + v->parent = 0; + v->x_value = 0; + memset(&(v->data),0,sizeof(v->data)); + + return v; + +} + + + +icalvalue* +icalvalue_new (icalvalue_kind kind) +{ + return (icalvalue*)icalvalue_new_impl(kind); +} + +icalvalue* icalvalue_new_clone(icalvalue* value){ + + struct icalvalue_impl* new; + struct icalvalue_impl* old = (struct icalvalue_impl*)value; + + new = icalvalue_new_impl(old->kind); + + if (new == 0){ + return 0; + } + + + strcpy(new->id, old->id); + new->kind = old->kind; + new->size = old->size; + + switch (new->kind){ + + /* The contents of the attach value may or may not be owned by the + * library. */ + case ICAL_ATTACH_VALUE: + case ICAL_BINARY_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: + { + if (old->data.v_string != 0) { + new->data.v_string=icalmemory_strdup(old->data.v_string); + + if ( new->data.v_string == 0 ) { + return 0; + } + + } + break; + } + case ICAL_RECUR_VALUE: + { + if(old->data.v_recur != 0){ + new->data.v_recur = malloc(sizeof(struct icalrecurrencetype)); + + if(new->data.v_recur == 0){ + return 0; + } + + memcpy( new->data.v_recur, old->data.v_recur, + sizeof(struct icalrecurrencetype)); + } + break; + } + + default: + { + /* all of the other types are stored as values, not + pointers, so we can just copy the whole structure. */ + + new->data = old->data; + } + } + + return new; +} + +char* icalmemory_strdup_and_dequote(const char* str) +{ + const char* p; + char* out = (char*)malloc(sizeof(char) * strlen(str) +1); + char* pout; + + if (out == 0){ + return 0; + } + + pout = out; + + for (p = str; *p!=0; p++){ + + if( *p == '\\') + { + p++; + switch(*p){ + case 0: + { + *pout = '\0'; + break; + + } + case 'n': + { + *pout = '\n'; + break; + } + case 'N': + { + *pout = '\n'; + break; + } + case '\\': + case ',': + case ';': + { + *pout = *p; + break; + } + default: + { + *pout = ' '; + } + } + } else { + *pout = *p; + } + + pout++; + + } + + *pout = '\0'; + + return out; +} + +icalvalue* icalvalue_new_enum(icalvalue_kind kind, int x_type, const char* str) +{ + int e = icalproperty_string_to_enum(str); + struct icalvalue_impl *value; + + if(e != 0 && icalproperty_enum_belongs_to_property( + icalproperty_value_kind_to_kind(kind),e)) { + + value = icalvalue_new_impl(kind); + value->data.v_enum = e; + } else { + /* Make it an X value */ + value = icalvalue_new_impl(kind); + value->data.v_enum = x_type; + icalvalue_set_x(value,str); + } + + return value; +} + + +icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* str,icalproperty** error) +{ + + struct icalvalue_impl *value = 0; + + icalerror_check_arg_rz(str!=0,"str"); + + if (error != 0){ + *error = 0; + } + + switch (kind){ + + case ICAL_ATTACH_VALUE: + case ICAL_BINARY_VALUE: + case ICAL_BOOLEAN_VALUE: + { + /* HACK */ + value = 0; + + if (error != 0){ + char temp[TMP_BUF_SIZE]; + sprintf(temp,"%s Values are not implemented", + icalparameter_kind_to_string(kind)); + *error = icalproperty_vanew_xlicerror( + temp, + icalparameter_new_xlicerrortype( + ICAL_XLICERRORTYPE_VALUEPARSEERROR), + 0); + } + break; + } + + + case ICAL_TRANSP_VALUE: + value = icalvalue_new_enum(kind, ICAL_TRANSP_X,str); + break; + case ICAL_METHOD_VALUE: + value = icalvalue_new_enum(kind, ICAL_METHOD_X,str); + break; + case ICAL_STATUS_VALUE: + value = icalvalue_new_enum(kind, ICAL_STATUS_X,str); + break; + case ICAL_ACTION_VALUE: + value = icalvalue_new_enum(kind, ICAL_ACTION_X,str); + break; + case ICAL_CLASS_VALUE: + value = icalvalue_new_enum(kind, ICAL_CLASS_X,str); + break; + + + case ICAL_INTEGER_VALUE: + { + value = icalvalue_new_integer(atoi(str)); + break; + } + + case ICAL_FLOAT_VALUE: + { + value = icalvalue_new_float(atof(str)); + break; + } + + case ICAL_UTCOFFSET_VALUE: + { + value = icalparser_parse_value(kind,str,(icalcomponent*)0); + break; + } + + case ICAL_TEXT_VALUE: + { + char* dequoted_str = icalmemory_strdup_and_dequote(str); + value = icalvalue_new_text(dequoted_str); + free(dequoted_str); + break; + } + + + case ICAL_STRING_VALUE: + { + value = icalvalue_new_string(str); + break; + } + + case ICAL_CALADDRESS_VALUE: + { + value = icalvalue_new_caladdress(str); + break; + } + + case ICAL_URI_VALUE: + { + value = icalvalue_new_uri(str); + break; + } + + + case ICAL_GEO_VALUE: + { + value = 0; + /* HACK */ + + if (error != 0){ + char temp[TMP_BUF_SIZE]; + sprintf(temp,"GEO Values are not implemented"); + *error = icalproperty_vanew_xlicerror( + temp, + icalparameter_new_xlicerrortype( + ICAL_XLICERRORTYPE_VALUEPARSEERROR), + 0); + } + + /*icalerror_warn("Parsing GEO properties is unimplmeneted");*/ + + break; + } + + case ICAL_RECUR_VALUE: + { + struct icalrecurrencetype rt; + rt = icalrecurrencetype_from_string(str); + value = icalvalue_new_recur(rt); + break; + } + + case ICAL_TIME_VALUE: + case ICAL_DATE_VALUE: + case ICAL_DATETIME_VALUE: + case ICAL_DATETIMEDATE_VALUE: + { + struct icaltimetype tt; + tt = icaltime_from_string(str); + if(!icaltime_is_null_time(tt)){ + value = icalvalue_new_impl(kind); + value->data.v_time = tt; + } + break; + } + + case ICAL_DATETIMEPERIOD_VALUE: + { + struct icaltimetype tt; + struct icalperiodtype p; + tt = icaltime_from_string(str); + p = icalperiodtype_from_string(str); + + if(!icaltime_is_null_time(tt)){ + value = icalvalue_new_datetime(tt); + } else if (!icalperiodtype_is_null_period(p)){ + value = icalvalue_new_period(p); + } + + break; + } + + case ICAL_DURATION_VALUE: + { + struct icaldurationtype dur = icaldurationtype_from_string(str); + + if(icaldurationtype_is_null_duration(dur)){ + value = 0; + } else { + value = icalvalue_new_duration(dur); + } + + break; + } + + case ICAL_PERIOD_VALUE: + { + struct icalperiodtype p; + p = icalperiodtype_from_string(str); + + if(!icalperiodtype_is_null_period(p)){ + value = icalvalue_new_period(p); + } + break; + } + + case ICAL_TRIGGER_VALUE: + { + struct icaltriggertype tr = icaltriggertype_from_string(str); + value = icalvalue_new_trigger(tr); + break; + } + + default: + { + + if (error != 0 ){ + char temp[TMP_BUF_SIZE]; + + snprintf(temp,TMP_BUF_SIZE,"Unknown type for \'%s\'",str); + + *error = icalproperty_vanew_xlicerror( + temp, + icalparameter_new_xlicerrortype( + ICAL_XLICERRORTYPE_VALUEPARSEERROR), + 0); + } + + icalerror_warn("icalvalue_new_from_string got an unknown value type"); + value=0; + } + } + + + if (error != 0 && *error == 0 && value == 0){ + char temp[TMP_BUF_SIZE]; + + snprintf(temp,TMP_BUF_SIZE,"Failed to parse value: \'%s\'",str); + + *error = icalproperty_vanew_xlicerror( + temp, + icalparameter_new_xlicerrortype( + ICAL_XLICERRORTYPE_VALUEPARSEERROR), + 0); + } + + + return value; + +} + +icalvalue* icalvalue_new_from_string(icalvalue_kind kind,const char* str) +{ + return icalvalue_new_from_string_with_error(kind,str,(icalproperty*)0); +} + + + +void +icalvalue_free (icalvalue* value) +{ + struct icalvalue_impl* v = (struct icalvalue_impl*)value; + + icalerror_check_arg_rv((value != 0),"value"); + +#ifdef ICAL_FREE_ON_LIST_IS_ERROR + icalerror_assert( (v->parent ==0),"This value is still attached to a property"); + +#else + if(v->parent !=0){ + return; + } +#endif + + if(v->x_value != 0){ + free(v->x_value); + } + + switch (v->kind){ + case ICAL_BINARY_VALUE: + case ICAL_ATTACH_VALUE: { + /* HACK ugh. This will be tough to implement */ + } + case ICAL_TEXT_VALUE: + case ICAL_CALADDRESS_VALUE: + case ICAL_URI_VALUE: + { + if (v->data.v_string != 0) { + free((void*)v->data.v_string); + v->data.v_string = 0; + } + break; + } + case ICAL_RECUR_VALUE: + { + if(v->data.v_recur != 0){ + free((void*)v->data.v_recur); + v->data.v_recur = 0; + } + break; + } + + default: + { + /* Nothing to do */ + } + } + + v->kind = ICAL_NO_VALUE; + v->size = 0; + v->parent = 0; + memset(&(v->data),0,sizeof(v->data)); + v->id[0] = 'X'; + free(v); +} + +int +icalvalue_is_valid (icalvalue* value) +{ + /*struct icalvalue_impl* v = (struct icalvalue_impl*)value;*/ + + if(value == 0){ + return 0; + } + + return 1; +} + +char* icalvalue_binary_as_ical_string(icalvalue* value) { + + const char* data; + char* str; + icalerror_check_arg_rz( (value!=0),"value"); + + data = icalvalue_get_binary(value); + + str = (char*)icalmemory_tmp_buffer(60); + sprintf(str,"icalvalue_binary_as_ical_string is not implemented yet"); + + return str; +} + + +#define MAX_INT_DIGITS 12 /* Enough for 2^32 + sign*/ +char* icalvalue_int_as_ical_string(icalvalue* value) { + + int data; + char* str = (char*)icalmemory_tmp_buffer(MAX_INT_DIGITS); + + icalerror_check_arg_rz( (value!=0),"value"); + + data = icalvalue_get_integer(value); + + snprintf(str,MAX_INT_DIGITS,"%d",data); + + return str; +} + +char* icalvalue_utcoffset_as_ical_string(icalvalue* value) +{ + int data,h,m,s; + char sign; + char* str = (char*)icalmemory_tmp_buffer(9); + + icalerror_check_arg_rz( (value!=0),"value"); + + data = icalvalue_get_utcoffset(value); + + if (abs(data) == data){ + sign = '+'; + } else { + sign = '-'; + } + + h = data/3600; + m = (data - (h*3600))/ 60; + s = (data - (h*3600) - (m*60)); + + sprintf(str,"%c%02d%02d%02d",sign,abs(h),abs(m),abs(s)); + + return str; +} + +char* icalvalue_string_as_ical_string(icalvalue* value) { + + const char* data; + char* str = 0; + icalerror_check_arg_rz( (value!=0),"value"); + data = ((struct icalvalue_impl*)value)->data.v_string; + + str = (char*)icalmemory_tmp_buffer(strlen(data)+1); + + strcpy(str,data); + + return str; +} + + +char* icalvalue_recur_as_ical_string(icalvalue* value) +{ + struct icalvalue_impl *impl = (struct icalvalue_impl*)value; + struct icalrecurrencetype *recur = impl->data.v_recur; + + return icalrecurrencetype_as_string(recur); +} + +char* icalvalue_text_as_ical_string(icalvalue* value) { + + char *str; + char *str_p; + char *rtrn; + const char *p; + size_t buf_sz; + int line_length; + + line_length = 0; + + buf_sz = strlen(((struct icalvalue_impl*)value)->data.v_string)+1; + + str_p = str = (char*)icalmemory_new_buffer(buf_sz); + + if (str_p == 0){ + return 0; + } + + for(p=((struct icalvalue_impl*)value)->data.v_string; *p!=0; p++){ + + switch(*p){ + case '\n': { + icalmemory_append_string(&str,&str_p,&buf_sz,"\\n"); + line_length+=3; + break; + } + + case '\t': { + icalmemory_append_string(&str,&str_p,&buf_sz,"\\t"); + line_length+=3; + break; + } + case '\r': { + icalmemory_append_string(&str,&str_p,&buf_sz,"\\r"); + line_length+=3; + break; + } + case '\b': { + icalmemory_append_string(&str,&str_p,&buf_sz,"\\b"); + line_length+=3; + break; + } + case '\f': { + icalmemory_append_string(&str,&str_p,&buf_sz,"\\f"); + line_length+=3; + break; + } + + case ';': + case ',':{ + icalmemory_append_char(&str,&str_p,&buf_sz,'\\'); + icalmemory_append_char(&str,&str_p,&buf_sz,*p); + line_length+=3; + break; + } + + case '"':{ + icalmemory_append_char(&str,&str_p,&buf_sz,'\\'); + icalmemory_append_char(&str,&str_p,&buf_sz,*p); + line_length+=3; + break; + } + + default: { + icalmemory_append_char(&str,&str_p,&buf_sz,*p); + line_length++; + } + } + + if (line_length > 65 && *p == ' '){ + icalmemory_append_string(&str,&str_p,&buf_sz,"\n "); + line_length=0; + } + + + if (line_length > 75){ + icalmemory_append_string(&str,&str_p,&buf_sz,"\n "); + line_length=0; + } + + } + + /* Assume the last character is not a '\0' and add one. We could + check *str_p != 0, but that would be an uninitialized memory + read. */ + + + icalmemory_append_char(&str,&str_p,&buf_sz,'\0'); + + rtrn = icalmemory_tmp_copy(str); + + icalmemory_free_buffer(str); + + return rtrn; +} + + +char* icalvalue_attach_as_ical_string(icalvalue* value) { + + struct icalattachtype a; + char * str; + + icalerror_check_arg_rz( (value!=0),"value"); + + a = icalvalue_get_attach(value); + + if (a.binary != 0) { + return icalvalue_binary_as_ical_string(value); + } else if (a.base64 != 0) { + str = (char*)icalmemory_tmp_buffer(strlen(a.base64)+1); + strcpy(str,a.base64); + return str; + } else if (a.url != 0){ + return icalvalue_string_as_ical_string(value); + } else { + icalerrno = ICAL_MALFORMEDDATA_ERROR; + return 0; + } +} + + +char* icalvalue_duration_as_ical_string(icalvalue* value) { + + struct icaldurationtype data; + + icalerror_check_arg_rz( (value!=0),"value"); + data = icalvalue_get_duration(value); + + return icaldurationtype_as_ical_string(data); +} + +void print_time_to_string(char* str, struct icaltimetype *data) +{ + char temp[20]; + + if (data->is_utc == 1){ + sprintf(temp,"%02d%02d%02dZ",data->hour,data->minute,data->second); + } else { + sprintf(temp,"%02d%02d%02d",data->hour,data->minute,data->second); + } + + strcat(str,temp); +} + + +char* icalvalue_time_as_ical_string(icalvalue* value) { + + struct icaltimetype data; + char* str; + icalerror_check_arg_rz( (value!=0),"value"); + data = icalvalue_get_time(value); + + str = (char*)icalmemory_tmp_buffer(8); + + str[0] = 0; + print_time_to_string(str,&data); + + return str; +} + +void print_date_to_string(char* str, struct icaltimetype *data) +{ + char temp[20]; + + sprintf(temp,"%04d%02d%02d",data->year,data->month,data->day); + + strcat(str,temp); +} + +char* icalvalue_date_as_ical_string(icalvalue* value) { + + struct icaltimetype data; + char* str; + icalerror_check_arg_rz( (value!=0),"value"); + data = icalvalue_get_date(value); + + str = (char*)icalmemory_tmp_buffer(9); + + str[0] = 0; + print_date_to_string(str,&data); + + return str; +} + +void print_datetime_to_string(char* str, struct icaltimetype *data) +{ + print_date_to_string(str,data); + strcat(str,"T"); + print_time_to_string(str,data); + +} + +const char* icalvalue_datetime_as_ical_string(icalvalue* value) { + + struct icaltimetype data; + char* str; + icalvalue_kind kind = icalvalue_isa(value); + + icalerror_check_arg_rz( (value!=0),"value"); + + + if( !(kind == ICAL_DATETIMEDATE_VALUE || + kind == ICAL_DATE_VALUE || + kind == ICAL_DATETIME_VALUE || + kind == ICAL_TIME_VALUE)) + { + icalerror_set_errno(ICAL_BADARG_ERROR); + return 0; + } + + data = icalvalue_get_datetime(value); + + str = (char*)icalmemory_tmp_buffer(20); + + str[0] = 0; + + print_datetime_to_string(str,&data); + + return str; + +} + + +const char* icalvalue_datetimedate_as_ical_string(icalvalue* value) { + + struct icaltimetype data; + icalerror_check_arg_rz( (value!=0),"value"); + data = icalvalue_get_datetime(value); + + if (data.is_date == 1){ + return icalvalue_date_as_ical_string(value); + } else { + return icalvalue_datetime_as_ical_string(value); + } +} + + +char* icalvalue_float_as_ical_string(icalvalue* value) { + + float data; + char* str; + icalerror_check_arg_rz( (value!=0),"value"); + data = icalvalue_get_float(value); + + str = (char*)icalmemory_tmp_buffer(15); + + sprintf(str,"%f",data); + + return str; +} + +char* icalvalue_geo_as_ical_string(icalvalue* value) { + + struct icalgeotype data; + char* str; + icalerror_check_arg_rz( (value!=0),"value"); + + data = icalvalue_get_geo(value); + + str = (char*)icalmemory_tmp_buffer(25); + + sprintf(str,"%f;%f",data.lat,data.lon); + + return str; +} + +const char* icalvalue_datetimeperiod_as_ical_string(icalvalue* value) { + struct icaldatetimeperiodtype dtp = icalvalue_get_datetimeperiod(value); + + icalerror_check_arg_rz( (value!=0),"value"); + + if(!icaltime_is_null_time(dtp.time)){ + return icaltime_as_ical_string(dtp.time); + } else { + return icalperiodtype_as_ical_string(dtp.period); + } +} + +const char* icalvalue_period_as_ical_string(icalvalue* value) { + struct icalperiodtype data; + icalerror_check_arg_rz( (value!=0),"value"); + data = icalvalue_get_period(value); + + return icalperiodtype_as_ical_string(data); + +} + +char* icalvalue_trigger_as_ical_string(icalvalue* value) { + + struct icaltriggertype data; + + icalerror_check_arg_rz( (value!=0),"value"); + data = icalvalue_get_trigger(value); + + if(!icaltime_is_null_time(data.time)){ + return icaltime_as_ical_string(data.time); + } else { + return icaldurationtype_as_ical_string(data.duration); + } + +} + +const char* +icalvalue_as_ical_string (icalvalue* value) +{ + struct icalvalue_impl* v = (struct icalvalue_impl*)value; + + v=v; + + if(value == 0){ + return 0; + } + + switch (v->kind){ + + case ICAL_ATTACH_VALUE: + return icalvalue_attach_as_ical_string(value); + + case ICAL_BINARY_VALUE: + return icalvalue_binary_as_ical_string(value); + + case ICAL_BOOLEAN_VALUE: + case ICAL_INTEGER_VALUE: + return icalvalue_int_as_ical_string(value); + + case ICAL_UTCOFFSET_VALUE: + return icalvalue_utcoffset_as_ical_string(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); + + case ICAL_DATE_VALUE: + return icalvalue_date_as_ical_string(value); + case ICAL_DATETIME_VALUE: + return icalvalue_datetime_as_ical_string(value); + case ICAL_DATETIMEDATE_VALUE: + return icalvalue_datetimedate_as_ical_string(value); + case ICAL_DURATION_VALUE: + return icalvalue_duration_as_ical_string(value); + case ICAL_TIME_VALUE: + return icalvalue_time_as_ical_string(value); + + case ICAL_PERIOD_VALUE: + return icalvalue_period_as_ical_string(value); + case ICAL_DATETIMEPERIOD_VALUE: + return icalvalue_datetimeperiod_as_ical_string(value); + + case ICAL_FLOAT_VALUE: + return icalvalue_float_as_ical_string(value); + + case ICAL_GEO_VALUE: + return icalvalue_geo_as_ical_string(value); + + case ICAL_RECUR_VALUE: + return icalvalue_recur_as_ical_string(value); + + case ICAL_TRIGGER_VALUE: + return icalvalue_trigger_as_ical_string(value); + + case ICAL_ACTION_VALUE: + case ICAL_METHOD_VALUE: + case ICAL_STATUS_VALUE: + case ICAL_TRANSP_VALUE: + case ICAL_CLASS_VALUE: + if(v->x_value !=0){ + return icalmemory_tmp_copy(v->x_value); + } + + return icalproperty_enum_to_string(v->data.v_enum); + + case ICAL_X_VALUE: + return icalmemory_tmp_copy(v->x_value); + + case ICAL_NO_VALUE: + default: + { + return 0; + } + } +} + + +icalvalue_kind +icalvalue_isa (icalvalue* value) +{ + struct icalvalue_impl* v = (struct icalvalue_impl*)value; + + if(value == 0){ + return ICAL_NO_VALUE; + } + + return v->kind; +} + + +int +icalvalue_isa_value (void* value) +{ + struct icalvalue_impl *impl = (struct icalvalue_impl *)value; + + icalerror_check_arg_rz( (value!=0), "value"); + + if (strcmp(impl->id,"val") == 0) { + return 1; + } else { + return 0; + } +} + + +int icalvalue_is_time(icalvalue* a) { + icalvalue_kind kind = icalvalue_isa(a); + + if(kind == ICAL_DATETIMEDATE_VALUE || + kind == ICAL_DATETIME_VALUE || + kind == ICAL_DATE_VALUE || + kind == ICAL_TIME_VALUE ){ + return 1; + } + + return 0; + +} + +icalparameter_xliccomparetype +icalvalue_compare(icalvalue* a, icalvalue *b) +{ + struct icalvalue_impl *impla = (struct icalvalue_impl *)a; + struct icalvalue_impl *implb = (struct icalvalue_impl *)b; + + icalerror_check_arg_rz( (a!=0), "a"); + icalerror_check_arg_rz( (b!=0), "b"); + + /* Not the same type; they can only be unequal */ + if( ! (icalvalue_is_time(a) && icalvalue_is_time(b)) && + icalvalue_isa(a) != icalvalue_isa(b)){ + return ICAL_XLICCOMPARETYPE_NOTEQUAL; + } + + switch (icalvalue_isa(a)){ + + case ICAL_ATTACH_VALUE: + case ICAL_BINARY_VALUE: + + case ICAL_BOOLEAN_VALUE: + { + if (icalvalue_get_boolean(a) == icalvalue_get_boolean(b)){ + return ICAL_XLICCOMPARETYPE_EQUAL; + } else { + return ICAL_XLICCOMPARETYPE_NOTEQUAL; + } + } + + case ICAL_FLOAT_VALUE: + { + if (impla->data.v_float > implb->data.v_float){ + return ICAL_XLICCOMPARETYPE_GREATER; + } else if (impla->data.v_float < implb->data.v_float){ + return ICAL_XLICCOMPARETYPE_LESS; + } else { + return ICAL_XLICCOMPARETYPE_EQUAL; + } + } + + case ICAL_INTEGER_VALUE: + case ICAL_UTCOFFSET_VALUE: + { + if (impla->data.v_int > implb->data.v_int){ + return ICAL_XLICCOMPARETYPE_GREATER; + } else if (impla->data.v_int < implb->data.v_int){ + return ICAL_XLICCOMPARETYPE_LESS; + } else { + return ICAL_XLICCOMPARETYPE_EQUAL; + } + } + + case ICAL_DURATION_VALUE: + { + int a = icaldurationtype_as_int(impla->data.v_duration); + int b = icaldurationtype_as_int(implb->data.v_duration); + + if (a > b){ + return ICAL_XLICCOMPARETYPE_GREATER; + } else if (a < b){ + return ICAL_XLICCOMPARETYPE_LESS; + } else { + return ICAL_XLICCOMPARETYPE_EQUAL; + } + } + + + case ICAL_TEXT_VALUE: + case ICAL_URI_VALUE: + case ICAL_CALADDRESS_VALUE: + case ICAL_TRIGGER_VALUE: + case ICAL_DATE_VALUE: + case ICAL_DATETIME_VALUE: + case ICAL_DATETIMEDATE_VALUE: + case ICAL_TIME_VALUE: + case ICAL_DATETIMEPERIOD_VALUE: + { + int r; + + r = strcmp(icalvalue_as_ical_string(a), + icalvalue_as_ical_string(b)); + + if (r > 0) { + return ICAL_XLICCOMPARETYPE_GREATER; + } else if (r < 0){ + return ICAL_XLICCOMPARETYPE_LESS; + } else { + return ICAL_XLICCOMPARETYPE_EQUAL; + } + + + } + + case ICAL_METHOD_VALUE: + { + if (icalvalue_get_method(a) == icalvalue_get_method(b)){ + return ICAL_XLICCOMPARETYPE_EQUAL; + } else { + return ICAL_XLICCOMPARETYPE_NOTEQUAL; + } + + } + + case ICAL_STATUS_VALUE: + { + if (icalvalue_get_status(a) == icalvalue_get_status(b)){ + return ICAL_XLICCOMPARETYPE_EQUAL; + } else { + return ICAL_XLICCOMPARETYPE_NOTEQUAL; + } + + } + + case ICAL_PERIOD_VALUE: + case ICAL_GEO_VALUE: + case ICAL_RECUR_VALUE: + case ICAL_NO_VALUE: + default: + { + icalerror_warn("Comparison not implemented for value type"); + return ICAL_XLICCOMPARETYPE_REGEX+1; /* HACK */ + } + } + +} + +void icalvalue_set_parent(icalvalue* value, + icalproperty* property) +{ + struct icalvalue_impl* v = (struct icalvalue_impl*)value; + + v->parent = property; + +} + +icalproperty* icalvalue_get_parent(icalvalue* value) +{ + struct icalvalue_impl* v = (struct icalvalue_impl*)value; + + + return v->parent; +} + + + +/* The remaining interfaces are 'new', 'set' and 'get' for each of the value + types */ + + +/* Everything below this line is machine generated. Do not edit. */ diff --git a/libical/src/libical/icalvalue.c.in b/libical/src/libical/icalvalue.c.in deleted file mode 100644 index 0bbf7cd934..0000000000 --- a/libical/src/libical/icalvalue.c.in +++ /dev/null @@ -1,1411 +0,0 @@ -/* -*- Mode: C -*- */ -/*====================================================================== - FILE: icalvalue.c - CREATOR: eric 02 May 1999 - - $Id: icalvalue.c.in,v 1.4 2001/02/05 19:43:57 jpr Exp $ - - - (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org - - This program is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: http://www.fsf.org/copyleft/lesser.html - - Or: - - The Mozilla Public License Version 1.0. You may obtain a copy of - the License at http://www.mozilla.org/MPL/ - - The original code is icalvalue.c - - Contributions from: - Graham Davison (g.m.davison@computer.org) - - -======================================================================*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "icalerror.h" -#include "icalmemory.h" -#include "icalparser.h" -#include "icalenums.h" - -#include /* for malloc */ -#include /* for sprintf */ -#include /* For memset, others */ -#include /* For offsetof() macro */ -#include -#include /* for mktime */ -#include /* for atoi and atof */ -#include /* for SHRT_MAX */ - -#if _MAC_OS_ -#include "icalmemory_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); -void print_recur_to_string(char* str, struct icaltimetype *data); - -struct icalvalue_impl { - icalvalue_kind kind; /*this is the kind that is visible from the outside*/ - - char id[5]; - int size; - icalproperty* parent; - - union data { - struct icalattachtype v_attach; - /* void *v_binary; */ /* use v_attach */ - const char *v_string; - /*char *v_text;*/ - /*char *v_caladdress;*/ - /*char *v_uri;*/ - float v_float; - int v_int; - /*int v_boolean;*/ - /*int v_integer;*/ - struct icaldurationtype v_duration; - /*int v_utcoffset;*/ - - struct icalperiodtype v_period; - /*struct icalperiodtype v_datetimeperiod;*/ - struct icalgeotype v_geo; - /*time_t v_time;*/ - struct icaltimetype v_time; - /*struct icaltimetype v_date;*/ - /*struct icaltimetype v_datetime;*/ - /*struct icaltimetype v_datetimedate;*/ - - /* struct icalrecurrencetype was once included - directly ( not referenced ) in this union, but it - contributes 2000 bytes to every value, so now it is - a reference*/ - - struct icalrecurrencetype *v_recur; - struct icaltriggertype v_trigger; - icalproperty_method v_method; - icalproperty_status v_status; - - } data; -}; - -struct icalvalue_impl* icalvalue_new_impl(icalvalue_kind kind){ - - struct icalvalue_impl* v; - - if ( ( v = (struct icalvalue_impl*) - malloc(sizeof(struct icalvalue_impl))) == 0) { - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; - } - - strcpy(v->id,"val"); - - v->kind = kind; - v->size = 0; - v->parent = 0; - memset(&(v->data),0,sizeof(v->data)); - - return v; - -} - - - -icalvalue* -icalvalue_new (icalvalue_kind kind) -{ - return (icalvalue*)icalvalue_new_impl(kind); -} - -icalvalue* icalvalue_new_clone(icalvalue* value){ - - struct icalvalue_impl* new; - struct icalvalue_impl* old = (struct icalvalue_impl*)value; - - new = icalvalue_new_impl(old->kind); - - if (new == 0){ - return 0; - } - - - strcpy(new->id, old->id); - new->kind = old->kind; - new->size = old->size; - - switch (new->kind){ - - /* The contents of the attach value may or may not be owned by the - * library. */ - case ICAL_ATTACH_VALUE: - case ICAL_BINARY_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: - { - if (old->data.v_string != 0) { - new->data.v_string=icalmemory_strdup(old->data.v_string); - - if ( new->data.v_string == 0 ) { - return 0; - } - - } - break; - } - case ICAL_RECUR_VALUE: - { - if(old->data.v_recur != 0){ - new->data.v_recur = malloc(sizeof(struct icalrecurrencetype)); - - if(new->data.v_recur == 0){ - return 0; - } - - memcpy( new->data.v_recur, old->data.v_recur, - sizeof(struct icalrecurrencetype)); - } - break; - } - - default: - { - /* all of the other types are stored as values, not - pointers, so we can just copy the whole structure. */ - - new->data = old->data; - } - } - - return new; -} - -char* icalmemory_strdup_and_dequote(const char* str) -{ - const char* p; - char* out = (char*)malloc(sizeof(char) * strlen(str) +1); - char* pout; - - if (out == 0){ - return 0; - } - - pout = out; - - for (p = str; *p!=0; p++){ - - if( *p == '\\') - { - p++; - switch(*p){ - case 0: - { - *pout = '\0'; - break; - - } - case 'n': - { - *pout = '\n'; - break; - } - case 'N': - { - *pout = '\n'; - break; - } - case '\\': - case ',': - case ';': - { - *pout = *p; - break; - } - default: - { - *pout = ' '; - } - } - } else { - *pout = *p; - } - - pout++; - - } - - *pout = '\0'; - - return out; -} - -icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* str,icalproperty** error) -{ - - icalvalue *value = 0; - - icalerror_check_arg_rz(str!=0,"str"); - - if (error != 0){ - *error = 0; - } - - switch (kind){ - - case ICAL_ATTACH_VALUE: - { - /* HACK */ - value = 0; - - if (error != 0){ - char temp[TMP_BUF_SIZE]; - sprintf(temp,"ATTACH Values are not implemented"); - *error = icalproperty_vanew_xlicerror( - temp, - icalparameter_new_xlicerrortype( - ICAL_XLICERRORTYPE_VALUEPARSEERROR), - 0); - } - - icalerror_warn("Parsing ATTACH properties is unimplmeneted"); - break; - } - - case ICAL_BINARY_VALUE: - { - /* HACK */ - value = 0; - - if (error != 0){ - char temp[TMP_BUF_SIZE]; - sprintf(temp,"BINARY Values are not implemented"); - *error = icalproperty_vanew_xlicerror( - temp, - icalparameter_new_xlicerrortype( - ICAL_XLICERRORTYPE_VALUEPARSEERROR), - 0); - } - - icalerror_warn("Parsing BINARY values is unimplmeneted"); - break; - } - - case ICAL_BOOLEAN_VALUE: - { - /* HACK */ - value = 0; - - if (error != 0){ - char temp[TMP_BUF_SIZE]; - sprintf(temp,"BOOLEAN Values are not implemented"); - *error = icalproperty_vanew_xlicerror( - temp, - icalparameter_new_xlicerrortype( - ICAL_XLICERRORTYPE_VALUEPARSEERROR), - 0); - } - - icalerror_warn("Parsing BOOLEAN values is unimplmeneted"); - break; - } - - case ICAL_INTEGER_VALUE: - { - value = icalvalue_new_integer(atoi(str)); - break; - } - - case ICAL_FLOAT_VALUE: - { - value = icalvalue_new_float(atof(str)); - break; - } - - case ICAL_UTCOFFSET_VALUE: - { - value = icalparser_parse_value(kind,str,(icalcomponent*)0); - break; - } - - case ICAL_TEXT_VALUE: - { - char* dequoted_str = icalmemory_strdup_and_dequote(str); - value = icalvalue_new_text(dequoted_str); - free(dequoted_str); - break; - } - - - case ICAL_STRING_VALUE: - { - value = icalvalue_new_string(str); - break; - } - - case ICAL_CALADDRESS_VALUE: - { - value = icalvalue_new_caladdress(str); - break; - } - - case ICAL_URI_VALUE: - { - value = icalvalue_new_uri(str); - break; - } - - case ICAL_METHOD_VALUE: - { - icalproperty_method method = icalenum_string_to_method(str); - - if(method == ICAL_METHOD_NONE){ - value = 0; - } else { - value = icalvalue_new_method(method); - } - - break; - - } - - - case ICAL_STATUS_VALUE: - { - icalproperty_status status = icalenum_string_to_status(str); - - if(status == ICAL_STATUS_NONE){ - value = 0; - } else { - value = icalvalue_new_status(status); - } - - break; - - } - case ICAL_GEO_VALUE: - { - value = 0; - /* HACK */ - - if (error != 0){ - char temp[TMP_BUF_SIZE]; - sprintf(temp,"GEO Values are not implemented"); - *error = icalproperty_vanew_xlicerror( - temp, - icalparameter_new_xlicerrortype( - ICAL_XLICERRORTYPE_VALUEPARSEERROR), - 0); - } - - /*icalerror_warn("Parsing GEO properties is unimplmeneted");*/ - - break; - } - - case ICAL_RECUR_VALUE: - { - struct icalrecurrencetype rt; - rt = icalrecurrencetype_from_string(str); - value = icalvalue_new_recur(rt); - break; - } - - case ICAL_TIME_VALUE: - { - struct icaltimetype tt; - tt = icaltime_from_string(str); - value = icalvalue_new_time(tt); - break; - } - case ICAL_DATE_VALUE: - { - struct icaltimetype tt; - tt = icaltime_from_string(str); - value = icalvalue_new_date(tt); - break; - } - case ICAL_DATETIME_VALUE: - { - struct icaltimetype tt; - tt = icaltime_from_string(str); - value = icalvalue_new_datetime(tt); - break; - } - case ICAL_DATETIMEDATE_VALUE: - { - struct icaltimetype tt; - tt = icaltime_from_string(str); - value = icalvalue_new_datetimedate(tt); - break; - } - - case ICAL_DATETIMEPERIOD_VALUE: - case ICAL_DURATION_VALUE: - case ICAL_PERIOD_VALUE: - { - value = icalparser_parse_value(kind,str,error); - break; - } - - case ICAL_TRIGGER_VALUE: - { - struct icaltriggertype tr = icaltriggertype_from_string(str); - value = icalvalue_new_trigger(tr); - break; - } - - default: - { - - if (error != 0 ){ - char temp[TMP_BUF_SIZE]; - - snprintf(temp,TMP_BUF_SIZE,"Unknown type for \'%s\'",str); - - *error = icalproperty_vanew_xlicerror( - temp, - icalparameter_new_xlicerrortype( - ICAL_XLICERRORTYPE_VALUEPARSEERROR), - 0); - } - - icalerror_warn("icalvalue_new_from_string got an unknown value type"); - value=0; - } - } - - - if (error != 0 && *error == 0 && value == 0){ - char temp[TMP_BUF_SIZE]; - - snprintf(temp,TMP_BUF_SIZE,"Failed to parse value: \'%s\'",str); - - *error = icalproperty_vanew_xlicerror( - temp, - icalparameter_new_xlicerrortype( - ICAL_XLICERRORTYPE_VALUEPARSEERROR), - 0); - } - - - return value; - -} - -icalvalue* icalvalue_new_from_string(icalvalue_kind kind,const char* str) -{ - return icalvalue_new_from_string_with_error(kind,str,(icalproperty*)0); -} - - - -void -icalvalue_free (icalvalue* value) -{ - struct icalvalue_impl* v = (struct icalvalue_impl*)value; - - icalerror_check_arg_rv((value != 0),"value"); - -#ifdef ICAL_FREE_ON_LIST_IS_ERROR - icalerror_assert( (v->parent ==0),"This value is still attached to a property"); - -#else - if(v->parent !=0){ - return; - } -#endif - - - switch (v->kind){ - case ICAL_BINARY_VALUE: - case ICAL_ATTACH_VALUE: { - /* HACK ugh. This will be tough to implement */ - } - case ICAL_TEXT_VALUE: - case ICAL_CALADDRESS_VALUE: - case ICAL_URI_VALUE: - { - if (v->data.v_string != 0) { - free((void*)v->data.v_string); - v->data.v_string = 0; - } - break; - } - case ICAL_RECUR_VALUE: - { - if(v->data.v_recur != 0){ - free((void*)v->data.v_recur); - v->data.v_recur = 0; - } - break; - } - - default: - { - /* Nothing to do */ - } - } - - v->kind = ICAL_NO_VALUE; - v->size = 0; - v->parent = 0; - memset(&(v->data),0,sizeof(v->data)); - v->id[0] = 'X'; - free(v); -} - -int -icalvalue_is_valid (icalvalue* value) -{ - /*struct icalvalue_impl* v = (struct icalvalue_impl*)value;*/ - - if(value == 0){ - return 0; - } - - return 1; -} - -char* icalvalue_binary_as_ical_string(icalvalue* value) { - - const char* data; - char* str; - icalerror_check_arg_rz( (value!=0),"value"); - - data = icalvalue_get_binary(value); - - str = (char*)icalmemory_tmp_buffer(60); - sprintf(str,"icalvalue_binary_as_ical_string is not implemented yet"); - - return str; -} - - -#define MAX_INT_DIGITS 12 /* Enough for 2^32 + sign*/ -char* icalvalue_int_as_ical_string(icalvalue* value) { - - int data; - char* str = (char*)icalmemory_tmp_buffer(MAX_INT_DIGITS); - - icalerror_check_arg_rz( (value!=0),"value"); - - data = icalvalue_get_integer(value); - - snprintf(str,MAX_INT_DIGITS,"%d",data); - - return str; -} - -char* icalvalue_utcoffset_as_ical_string(icalvalue* value) -{ - int data,h,m,s; - char sign; - char* str = (char*)icalmemory_tmp_buffer(9); - - icalerror_check_arg_rz( (value!=0),"value"); - - data = icalvalue_get_utcoffset(value); - - if (abs(data) == data){ - sign = '+'; - } else { - sign = '-'; - } - - h = data/3600; - m = (data - (h*3600))/ 60; - s = (data - (h*3600) - (m*60)); - - sprintf(str,"%c%02d%02d%02d",sign,abs(h),abs(m),abs(s)); - - return str; -} - -char* icalvalue_string_as_ical_string(icalvalue* value) { - - const char* data; - char* str = 0; - icalerror_check_arg_rz( (value!=0),"value"); - data = ((struct icalvalue_impl*)value)->data.v_string; - - str = (char*)icalmemory_tmp_buffer(strlen(data)+1); - - strcpy(str,data); - - return str; -} - - -char* icalvalue_recur_as_ical_string(icalvalue* value) -{ - struct icalvalue_impl *impl = (struct icalvalue_impl*)value; - struct icalrecurrencetype *recur = impl->data.v_recur; - - return icalrecurrencetype_as_string(recur); -} - -char* icalvalue_text_as_ical_string(icalvalue* value) { - - char *str; - char *str_p; - char *rtrn; - const char *p; - size_t buf_sz; - int line_length; - - line_length = 0; - - buf_sz = strlen(((struct icalvalue_impl*)value)->data.v_string)+1; - - str_p = str = (char*)icalmemory_new_buffer(buf_sz); - - if (str_p == 0){ - return 0; - } - - for(p=((struct icalvalue_impl*)value)->data.v_string; *p!=0; p++){ - - switch(*p){ - case '\n': { - icalmemory_append_string(&str,&str_p,&buf_sz,"\\n"); - line_length+=3; - break; - } - - case '\t': { - icalmemory_append_string(&str,&str_p,&buf_sz,"\\t"); - line_length+=3; - break; - } - case '\r': { - icalmemory_append_string(&str,&str_p,&buf_sz,"\\r"); - line_length+=3; - break; - } - case '\b': { - icalmemory_append_string(&str,&str_p,&buf_sz,"\\b"); - line_length+=3; - break; - } - case '\f': { - icalmemory_append_string(&str,&str_p,&buf_sz,"\\f"); - line_length+=3; - break; - } - - case ';': - case ',':{ - icalmemory_append_char(&str,&str_p,&buf_sz,'\\'); - icalmemory_append_char(&str,&str_p,&buf_sz,*p); - line_length+=3; - break; - } - - case '"':{ - icalmemory_append_char(&str,&str_p,&buf_sz,'\\'); - icalmemory_append_char(&str,&str_p,&buf_sz,*p); - line_length+=3; - break; - } - - default: { - icalmemory_append_char(&str,&str_p,&buf_sz,*p); - line_length++; - } - } - - if (line_length > 65 && *p == ' '){ - icalmemory_append_string(&str,&str_p,&buf_sz,"\n "); - line_length=0; - } - - - if (line_length > 75){ - icalmemory_append_string(&str,&str_p,&buf_sz,"\n "); - line_length=0; - } - - } - - /* Assume the last character is not a '\0' and add one. We could - check *str_p != 0, but that would be an uninitialized memory - read. */ - - - icalmemory_append_char(&str,&str_p,&buf_sz,'\0'); - - rtrn = icalmemory_tmp_copy(str); - - icalmemory_free_buffer(str); - - return rtrn; -} - - -char* icalvalue_attach_as_ical_string(icalvalue* value) { - - struct icalattachtype a; - char * str; - - icalerror_check_arg_rz( (value!=0),"value"); - - a = icalvalue_get_attach(value); - - if (a.binary != 0) { - return icalvalue_binary_as_ical_string(value); - } else if (a.base64 != 0) { - str = (char*)icalmemory_tmp_buffer(strlen(a.base64)+1); - strcpy(str,a.base64); - return str; - } else if (a.url != 0){ - return icalvalue_string_as_ical_string(value); - } else { - icalerrno = ICAL_MALFORMEDDATA_ERROR; - return 0; - } -} - - -char* icalvalue_duration_as_ical_string(icalvalue* value) -{ - - struct icaldurationtype data; - - icalerror_check_arg_rz( (value!=0),"value"); - data = icalvalue_get_duration(value); - - return icaldurationtype_as_ical_string(data); - -} - -void print_time_to_string(char* str, struct icaltimetype *data) -{ - char temp[20]; - - if (data->is_utc == 1){ - sprintf(temp,"%02d%02d%02dZ",data->hour,data->minute,data->second); - } else { - sprintf(temp,"%02d%02d%02d",data->hour,data->minute,data->second); - } - - strcat(str,temp); -} - - -char* icalvalue_time_as_ical_string(icalvalue* value) { - - struct icaltimetype data; - char* str; - icalerror_check_arg_rz( (value!=0),"value"); - data = icalvalue_get_time(value); - - str = (char*)icalmemory_tmp_buffer(8); - - str[0] = 0; - print_time_to_string(str,&data); - - return str; -} - -void print_date_to_string(char* str, struct icaltimetype *data) -{ - char temp[20]; - - sprintf(temp,"%04d%02d%02d",data->year,data->month,data->day); - - strcat(str,temp); -} - -char* icalvalue_date_as_ical_string(icalvalue* value) { - - struct icaltimetype data; - char* str; - icalerror_check_arg_rz( (value!=0),"value"); - data = icalvalue_get_date(value); - - str = (char*)icalmemory_tmp_buffer(9); - - str[0] = 0; - print_date_to_string(str,&data); - - return str; -} - -void print_datetime_to_string(char* str, struct icaltimetype *data) -{ - print_date_to_string(str,data); - strcat(str,"T"); - print_time_to_string(str,data); - -} - -char* icalvalue_datetime_as_ical_string(icalvalue* value) { - - struct icaltimetype data; - char* str; - icalvalue_kind kind = icalvalue_isa(value); - - icalerror_check_arg_rz( (value!=0),"value"); - - - if( !(kind == ICAL_DATETIMEDATE_VALUE || - kind == ICAL_DATE_VALUE || - kind == ICAL_DATETIME_VALUE || - kind == ICAL_TIME_VALUE)) - { - icalerror_set_errno(ICAL_BADARG_ERROR); - return 0; - } - - data = icalvalue_get_datetime(value); - - str = (char*)icalmemory_tmp_buffer(20); - - str[0] = 0; - - print_datetime_to_string(str,&data); - - return str; - -} - - -char* icalvalue_datetimedate_as_ical_string(icalvalue* value) { - - struct icaltimetype data; - icalerror_check_arg_rz( (value!=0),"value"); - data = icalvalue_get_datetime(value); - - if (data.is_date == 1){ - return icalvalue_date_as_ical_string(value); - } else { - return icalvalue_datetime_as_ical_string(value); - } -} - - -char* icalvalue_float_as_ical_string(icalvalue* value) { - - float data; - char* str; - icalerror_check_arg_rz( (value!=0),"value"); - data = icalvalue_get_float(value); - - str = (char*)icalmemory_tmp_buffer(15); - - sprintf(str,"%f",data); - - return str; -} - -char* icalvalue_geo_as_ical_string(icalvalue* value) { - - struct icalgeotype data; - char* str; - icalerror_check_arg_rz( (value!=0),"value"); - - data = icalvalue_get_geo(value); - - str = (char*)icalmemory_tmp_buffer(25); - - sprintf(str,"%f;%f",data.lat,data.lon); - - return str; -} - -char* icalvalue_datetimeperiod_as_ical_string(icalvalue* value) { - struct icalvalue_impl* impl = (struct icalvalue_impl*)value; - struct icaldatetimeperiodtype dtp = icalvalue_get_datetimeperiod(value); - - icalerror_check_arg_rz( (value!=0),"value"); - - if(!icaltime_is_null_time(dtp.time)){ - return icaltime_as_ical_string(dtp.time); - } else { - return icalperiodtype_as_ical_string(dtp.period); - } -} - -char* icalvalue_period_as_ical_string(icalvalue* value) { - struct icalperiodtype data; - icalerror_check_arg_rz( (value!=0),"value"); - data = icalvalue_get_period(value); - - return icalperiodtype_as_ical_string(data); -} - -char* icalvalue_trigger_as_ical_string(icalvalue* value) -{ - - struct icaltriggertype data; - char* str; - - icalerror_check_arg_rz( (value!=0),"value"); - data = icalvalue_get_trigger(value); - - str = (char*)icalmemory_tmp_buffer(60); - - if(!icaltime_is_null_time(data.time)){ - return icaltime_as_ical_string(data.time); - } else { - return icaldurationtype_as_ical_string(data.duration); - } - -} - -const char* -icalvalue_as_ical_string (icalvalue* value) -{ - struct icalvalue_impl* v = (struct icalvalue_impl*)value; - - v=v; - - if(value == 0){ - return 0; - } - - switch (v->kind){ - - case ICAL_ATTACH_VALUE: - return icalvalue_attach_as_ical_string(value); - - case ICAL_BINARY_VALUE: - return icalvalue_binary_as_ical_string(value); - - case ICAL_BOOLEAN_VALUE: - case ICAL_INTEGER_VALUE: - return icalvalue_int_as_ical_string(value); - - case ICAL_UTCOFFSET_VALUE: - return icalvalue_utcoffset_as_ical_string(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); - - case ICAL_DATE_VALUE: - return icalvalue_date_as_ical_string(value); - case ICAL_DATETIME_VALUE: - return icalvalue_datetime_as_ical_string(value); - case ICAL_DATETIMEDATE_VALUE: - return icalvalue_datetimedate_as_ical_string(value); - case ICAL_DURATION_VALUE: - return icalvalue_duration_as_ical_string(value); - case ICAL_TIME_VALUE: - return icalvalue_time_as_ical_string(value); - - case ICAL_PERIOD_VALUE: - return icalvalue_period_as_ical_string(value); - case ICAL_DATETIMEPERIOD_VALUE: - return icalvalue_datetimeperiod_as_ical_string(value); - - case ICAL_FLOAT_VALUE: - return icalvalue_float_as_ical_string(value); - - case ICAL_GEO_VALUE: - return icalvalue_geo_as_ical_string(value); - - case ICAL_RECUR_VALUE: - return icalvalue_recur_as_ical_string(value); - - case ICAL_TRIGGER_VALUE: - return icalvalue_trigger_as_ical_string(value); - - case ICAL_METHOD_VALUE: - return icalenum_method_to_string(v->data.v_method); - - case ICAL_STATUS_VALUE: - return icalenum_status_to_string(v->data.v_status); - - - case ICAL_NO_VALUE: - default: - { - return 0; - } - } -} - - -icalvalue_kind -icalvalue_isa (icalvalue* value) -{ - struct icalvalue_impl* v = (struct icalvalue_impl*)value; - - if(value == 0){ - return ICAL_NO_VALUE; - } - - return v->kind; -} - - -int -icalvalue_isa_value (void* value) -{ - struct icalvalue_impl *impl = (struct icalvalue_impl *)value; - - icalerror_check_arg_rz( (value!=0), "value"); - - if (strcmp(impl->id,"val") == 0) { - return 1; - } else { - return 0; - } -} - - -int icalvalue_is_time(icalvalue* a) { - icalvalue_kind kind = icalvalue_isa(a); - - if(kind == ICAL_DATETIMEDATE_VALUE || - kind == ICAL_DATETIME_VALUE || - kind == ICAL_DATE_VALUE || - kind == ICAL_TIME_VALUE ){ - return 1; - } - - return 0; - -} - -icalparameter_xliccomparetype -icalvalue_compare(icalvalue* a, icalvalue *b) -{ - struct icalvalue_impl *impla = (struct icalvalue_impl *)a; - struct icalvalue_impl *implb = (struct icalvalue_impl *)b; - - icalerror_check_arg_rz( (a!=0), "a"); - icalerror_check_arg_rz( (b!=0), "b"); - - /* Not the same type; they can only be unequal */ - if( ! (icalvalue_is_time(a) && icalvalue_is_time(b)) && - icalvalue_isa(a) != icalvalue_isa(b)){ - return ICAL_XLICCOMPARETYPE_NOTEQUAL; - } - - switch (icalvalue_isa(a)){ - - case ICAL_ATTACH_VALUE: - case ICAL_BINARY_VALUE: - - case ICAL_BOOLEAN_VALUE: - { - if (icalvalue_get_boolean(a) == icalvalue_get_boolean(b)){ - return ICAL_XLICCOMPARETYPE_EQUAL; - } else { - return ICAL_XLICCOMPARETYPE_NOTEQUAL; - } - } - - case ICAL_FLOAT_VALUE: - { - if (impla->data.v_float > implb->data.v_float){ - return ICAL_XLICCOMPARETYPE_GREATER; - } else if (impla->data.v_float < implb->data.v_float){ - return ICAL_XLICCOMPARETYPE_LESS; - } else { - return ICAL_XLICCOMPARETYPE_EQUAL; - } - } - - case ICAL_INTEGER_VALUE: - case ICAL_UTCOFFSET_VALUE: - { - if (impla->data.v_int > implb->data.v_int){ - return ICAL_XLICCOMPARETYPE_GREATER; - } else if (impla->data.v_int < implb->data.v_int){ - return ICAL_XLICCOMPARETYPE_LESS; - } else { - return ICAL_XLICCOMPARETYPE_EQUAL; - } - } - - case ICAL_DURATION_VALUE: - { - int a = icaldurationtype_as_int(impla->data.v_duration); - int b = icaldurationtype_as_int(implb->data.v_duration); - - if (a > b){ - return ICAL_XLICCOMPARETYPE_GREATER; - } else if (a < b){ - return ICAL_XLICCOMPARETYPE_LESS; - } else { - return ICAL_XLICCOMPARETYPE_EQUAL; - } - } - - - case ICAL_TEXT_VALUE: - case ICAL_URI_VALUE: - case ICAL_CALADDRESS_VALUE: - case ICAL_TRIGGER_VALUE: - case ICAL_DATE_VALUE: - case ICAL_DATETIME_VALUE: - case ICAL_DATETIMEDATE_VALUE: - case ICAL_TIME_VALUE: - case ICAL_DATETIMEPERIOD_VALUE: - { - int r; - - r = strcmp(icalvalue_as_ical_string(a), - icalvalue_as_ical_string(b)); - - if (r > 0) { - return ICAL_XLICCOMPARETYPE_GREATER; - } else if (r < 0){ - return ICAL_XLICCOMPARETYPE_LESS; - } else { - return ICAL_XLICCOMPARETYPE_EQUAL; - } - - - } - - case ICAL_METHOD_VALUE: - { - if (icalvalue_get_method(a) == icalvalue_get_method(b)){ - return ICAL_XLICCOMPARETYPE_EQUAL; - } else { - return ICAL_XLICCOMPARETYPE_NOTEQUAL; - } - - } - - case ICAL_STATUS_VALUE: - { - if (icalvalue_get_status(a) == icalvalue_get_status(b)){ - return ICAL_XLICCOMPARETYPE_EQUAL; - } else { - return ICAL_XLICCOMPARETYPE_NOTEQUAL; - } - - } - - case ICAL_PERIOD_VALUE: - case ICAL_GEO_VALUE: - case ICAL_RECUR_VALUE: - case ICAL_NO_VALUE: - default: - { - icalerror_warn("Comparison not implemented for value type"); - return ICAL_XLICCOMPARETYPE_REGEX+1; /* HACK */ - } - } - -} - -void icalvalue_set_parent(icalvalue* value, - icalproperty* property) -{ - struct icalvalue_impl* v = (struct icalvalue_impl*)value; - - v->parent = property; - -} - -icalproperty* icalvalue_get_parent(icalvalue* value) -{ - struct icalvalue_impl* v = (struct icalvalue_impl*)value; - - - return v->parent; -} - - - -/* Recur is a special case, so it is not auto generated. */ -icalvalue* -icalvalue_new_recur (struct icalrecurrencetype v) -{ - struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_RECUR_VALUE); - - icalvalue_set_recur((icalvalue*)impl,v); - - return (icalvalue*)impl; -} - -void -icalvalue_set_recur(icalvalue* value, struct icalrecurrencetype v) -{ - struct icalvalue_impl* impl; - - icalerror_check_arg_rv( (value!=0),"value"); - icalerror_check_value_type(value, ICAL_RECUR_VALUE); - - impl = (struct icalvalue_impl*)value; - - if (impl->data.v_recur != 0){ - free(impl->data.v_recur); - impl->data.v_recur = 0; - } - - impl->data.v_recur = malloc(sizeof(struct icalrecurrencetype)); - - if (impl->data.v_recur == 0){ - icalerror_set_errno(ICAL_ALLOCATION_ERROR); - return; - } else { - memcpy(impl->data.v_recur, &v, sizeof(struct icalrecurrencetype)); - } - -} - -struct icalrecurrencetype -icalvalue_get_recur(icalvalue* value) -{ - icalerror_check_arg( (value!=0),"value"); - icalerror_check_value_type(value, ICAL_RECUR_VALUE); - - return *(((struct icalvalue_impl*)value)->data.v_recur); -} - - - - -icalvalue* -icalvalue_new_trigger (struct icaltriggertype v) -{ - struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_TRIGGER_VALUE); - - icalvalue_set_trigger((icalvalue*)impl,v); - - return (icalvalue*)impl; -} - -void -icalvalue_set_trigger(icalvalue* value, struct icaltriggertype v) -{ - struct icalvalue_impl* impl; - - icalerror_check_arg_rv( (value!=0),"value"); - - impl = (struct icalvalue_impl*)value; - - if(!icaltime_is_null_time(v.time)){ - icalvalue_set_datetime((icalvalue*)impl,v.time); - impl->kind = ICAL_DATETIME_VALUE; - } else { - icalvalue_set_duration((icalvalue*)impl,v.duration); - impl->kind = ICAL_DURATION_VALUE; - } - -} - -struct icaltriggertype -icalvalue_get_trigger(icalvalue* value) -{ - struct icalvalue_impl *impl = (struct icalvalue_impl*)value; - struct icaltriggertype tr; - - icalerror_check_arg( (value!=0),"value"); - icalerror_check_arg( (value!=0),"value"); - - if(impl->kind == ICAL_DATETIME_VALUE){ - tr.duration = icaldurationtype_from_int(0); - tr.time = impl->data.v_time; - } else if(impl->kind == ICAL_DURATION_VALUE){ - tr.time = icaltime_null_time(); - tr.duration = impl->data.v_duration; - } else { - tr.duration = icaldurationtype_from_int(0); - tr.time = icaltime_null_time(); - icalerror_set_errno(ICAL_BADARG_ERROR); - } - - return tr; -} - -/* DATE-TIME-PERIOD is a special case, and is not auto generated */ - -icalvalue* -icalvalue_new_datetimeperiod (struct icaldatetimeperiodtype v) -{ - struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_DATETIMEPERIOD_VALUE); - - icalvalue_set_datetimeperiod((icalvalue*)impl,v); - - return (icalvalue*)impl; -} - -void -icalvalue_set_datetimeperiod(icalvalue* value, struct icaldatetimeperiodtype v) -{ - struct icalvalue_impl* impl = (struct icalvalue_impl*)value; - - icalerror_check_arg_rv( (value!=0),"value"); - - icalerror_check_value_type(value, ICAL_DATETIMEPERIOD_VALUE); - - if(!icaltime_is_null_time(v.time)){ - if(!icaltime_is_valid_time(v.time)){ - icalerror_set_errno(ICAL_BADARG_ERROR); - return; - } - impl->kind = ICAL_DATETIME_VALUE; - icalvalue_set_datetime(impl,v.time); - } else if (!icalperiodtype_is_null_period(v.period)) { - if(!icalperiodtype_is_valid_period(v.period)){ - icalerror_set_errno(ICAL_BADARG_ERROR); - return; - } - impl->kind = ICAL_PERIOD_VALUE; - icalvalue_set_period(impl,v.period); - } else { - icalerror_set_errno(ICAL_BADARG_ERROR); - } -} - -struct icaldatetimeperiodtype -icalvalue_get_datetimeperiod(icalvalue* value) -{ - struct icaldatetimeperiodtype dtp; - - struct icalvalue_impl* impl = (struct icalvalue_impl*)value; - icalerror_check_arg( (value!=0),"value"); - icalerror_check_value_type(value, ICAL_DATETIMEPERIOD_VALUE); - - if(impl->kind == ICAL_DATETIME_VALUE){ - dtp.period = icalperiodtype_null_period(); - dtp.time = impl->data.v_time; - } else if(impl->kind == ICAL_PERIOD_VALUE) { - dtp.period = impl->data.v_period; - dtp.time = icaltime_null_time(); - } else { - dtp.period = icalperiodtype_null_period(); - dtp.time = icaltime_null_time(); - icalerror_set_errno(ICAL_BADARG_ERROR); - } - - return dtp; -} - - - - - -/* The remaining interfaces are 'new', 'set' and 'get' for each of the value - types */ - - -/* Everything below this line is machine generated. Do not edit. */ diff --git a/libical/src/libical/icalvalue.h b/libical/src/libical/icalvalue.h new file mode 100644 index 0000000000..6983c23275 --- /dev/null +++ b/libical/src/libical/icalvalue.h @@ -0,0 +1,85 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: icalvalue.h + CREATOR: eric 20 March 1999 + + + $Id$ + $Locker$ + + + + (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org + + This program is free software; you can redistribute it and/or modify + it under the terms of either: + + The LGPL as published by the Free Software Foundation, version + 2.1, available at: http://www.fsf.org/copyleft/lesser.html + + Or: + + The Mozilla Public License Version 1.0. You may obtain a copy of + the License at http://www.mozilla.org/MPL/ + + The original code is icalvalue.h + + ======================================================================*/ + +#ifndef ICALVALUE_H +#define ICALVALUE_H + +#include +#include "icalenums.h" +#include "icaltypes.h" +#include "icalrecur.h" +#include "icalduration.h" +#include "icalperiod.h" +#include "icalderivedproperty.h" /* For icalproperty_method, etc. */ +#include "icalderivedparameter.h" +#include "icalderivedvalue.h" + +/* Defined in icalderivedvalue.h */ +/*typedef void icalvalue;*/ + +icalvalue* icalvalue_new(icalvalue_kind kind); + +icalvalue* icalvalue_new_clone(icalvalue* value); + +icalvalue* icalvalue_new_from_string(icalvalue_kind kind, const char* str); + +void icalvalue_free(icalvalue* value); + +int icalvalue_is_valid(icalvalue* value); + +const char* icalvalue_as_ical_string(icalvalue* value); + +icalvalue_kind icalvalue_isa(icalvalue* value); + +int icalvalue_isa_value(void*); + +icalparameter_xliccomparetype icalvalue_compare(icalvalue* a, icalvalue *b); + + +/* Special, non autogenerated value accessors */ + +icalvalue* icalvalue_new_recur (struct icalrecurrencetype v); +void icalvalue_set_recur(icalvalue* value, struct icalrecurrencetype v); +struct icalrecurrencetype icalvalue_get_recur(icalvalue* value); + +icalvalue* icalvalue_new_trigger (struct icaltriggertype v); +void icalvalue_set_trigger(icalvalue* value, struct icaltriggertype v); +struct icaltriggertype icalvalue_get_trigger(icalvalue* value); + +icalvalue* icalvalue_new_datetimeperiod (struct icaldatetimeperiodtype v); +void icalvalue_set_datetimeperiod(icalvalue* value, + struct icaldatetimeperiodtype v); +struct icaldatetimeperiodtype icalvalue_get_datetimeperiod(icalvalue* value); + +/* Convert enumerations */ + +icalvalue_kind icalvalue_string_to_kind(const char* str); +const char* icalvalue_kind_to_string(icalvalue_kind kind); + + +#endif /*ICALVALUE_H*/ diff --git a/libical/src/libical/icalvalue.h.in b/libical/src/libical/icalvalue.h.in deleted file mode 100644 index 90daa49f79..0000000000 --- a/libical/src/libical/icalvalue.h.in +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C -*- */ -/*====================================================================== - FILE: icalvalue.h - CREATOR: eric 20 March 1999 - - - $Id: icalvalue.h.in,v 1.1.1.3 2001/02/05 19:16:24 jpr Exp $ - $Locker: $ - - - - (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org - - This program is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: http://www.fsf.org/copyleft/lesser.html - - Or: - - The Mozilla Public License Version 1.0. You may obtain a copy of - the License at http://www.mozilla.org/MPL/ - - The original code is icalvalue.h - - ======================================================================*/ - -#ifndef ICALVALUE_H -#define ICALVALUE_H - -#include -#include "icalenums.h" -#include "icaltypes.h" -#include "icalrecur.h" - -typedef void icalvalue; - -icalvalue* icalvalue_new(icalvalue_kind kind); - -icalvalue* icalvalue_new_clone(icalvalue* value); - -icalvalue* icalvalue_new_from_string(icalvalue_kind kind, const char* str); - -void icalvalue_free(icalvalue* value); - -int icalvalue_is_valid(icalvalue* value); - -const char* icalvalue_as_ical_string(icalvalue* value); - -icalvalue_kind icalvalue_isa(icalvalue* value); - -int icalvalue_isa_value(void*); - -icalparameter_xliccomparetype -icalvalue_compare(icalvalue* a, icalvalue *b); - - -/* Special, non autogenerated value accessors */ - -icalvalue* icalvalue_new_recur (struct icalrecurrencetype v); -void icalvalue_set_recur(icalvalue* value, struct icalrecurrencetype v); -struct icalrecurrencetype icalvalue_get_recur(icalvalue* value); - -icalvalue* icalvalue_new_trigger (struct icaltriggertype v); -void icalvalue_set_trigger(icalvalue* value, struct icaltriggertype v); -struct icaltriggertype icalvalue_get_trigger(icalvalue* value); - -icalvalue* icalvalue_new_datetimeperiod (struct icaldatetimeperiodtype v); -void icalvalue_set_datetimeperiod(icalvalue* value, - struct icaldatetimeperiodtype v); -struct icaldatetimeperiodtype icalvalue_get_datetimeperiod(icalvalue* value); - -/* Everything below this line is machine generated. Do not edit. */ -- cgit v1.2.3