aboutsummaryrefslogtreecommitdiffstats
path: root/libical/src
diff options
context:
space:
mode:
Diffstat (limited to 'libical/src')
-rw-r--r--libical/src/libical/Makefile.am39
-rw-r--r--libical/src/libical/icalenums.c2
-rw-r--r--libical/src/libical/icalerror.c60
-rw-r--r--libical/src/libical/icalerror.h35
-rw-r--r--libical/src/libical/icalproperty.c.in62
-rw-r--r--libical/src/libical/icalrecur.c11
-rw-r--r--libical/src/libical/icaltime.c79
-rw-r--r--libical/src/libical/icaltime.h8
-rw-r--r--libical/src/libical/icaltypes.c1
-rw-r--r--libical/src/libical/icaltypes.h8
-rw-r--r--libical/src/libical/icalvalue.c.in286
-rw-r--r--libical/src/test/copycluster.c4
-rw-r--r--libical/src/test/regression.c254
13 files changed, 670 insertions, 179 deletions
diff --git a/libical/src/libical/Makefile.am b/libical/src/libical/Makefile.am
index a3b61d5677..0348ea9b4c 100644
--- a/libical/src/libical/Makefile.am
+++ b/libical/src/libical/Makefile.am
@@ -55,7 +55,9 @@ libical_la_SOURCES = \
pvl.h \
sspm.c \
sspm.h \
- vsnprintf.c
+ vsnprintf.c \
+ icallangbind.h \
+ icallangbind.c
libicalincludedir = $(includedir)
@@ -63,23 +65,24 @@ libicalinclude_HEADERS = ical.h
# ORDERING OF HEADERS IS SIGNIFICANT. Don't change this ordering. It
# is required to make the combined header ical.h properly
-COMBINEDHEADERS = \
- icalversion.h \
- $(srcdir)/icaltime.h \
- $(srcdir)/icalenums.h \
- $(srcdir)/icaltypes.h \
- $(srcdir)/icalrecur.h \
- icalvalue.h \
- icalparameter.h \
- icalproperty.h \
- $(srcdir)/pvl.h \
- $(srcdir)/icalcomponent.h \
- $(srcdir)/icalparser.h \
- $(srcdir)/icalmemory.h \
- $(srcdir)/icalerror.h \
- $(srcdir)/icalrestriction.h \
- $(srcdir)/sspm.h \
- $(srcdir)/icalmime.h
+COMBINEDHEADERS = \
+ $(top_builddir)/src/libical/icalversion.h \
+ $(top_srcdir)/src/libical/icaltime.h \
+ $(top_srcdir)/src/libical/icalenums.h \
+ $(top_srcdir)/src/libical/icaltypes.h \
+ $(top_srcdir)/src/libical/icalrecur.h \
+ $(top_srcdir)/src/libical/icalvalue.h \
+ $(top_srcdir)/src/libical/icalparameter.h \
+ $(top_srcdir)/src/libical/icalproperty.h \
+ $(top_srcdir)/src/libical/pvl.h \
+ $(top_srcdir)/src/libical/icalcomponent.h \
+ $(top_srcdir)/src/libical/icalparser.h \
+ $(top_srcdir)/src/libical/icalmemory.h \
+ $(top_srcdir)/src/libical/icalerror.h \
+ $(top_srcdir)/src/libical/icalrestriction.h \
+ $(top_srcdir)/src/libical/sspm.h \
+ $(top_srcdir)/src/libical/icalmime.h \
+ $(top_srcdir)/src/libical/icallangbind.h
BUILT_SOURCES = \
ical.h \
diff --git a/libical/src/libical/icalenums.c b/libical/src/libical/icalenums.c
index 92811eef93..78ca5d7ebe 100644
--- a/libical/src/libical/icalenums.c
+++ b/libical/src/libical/icalenums.c
@@ -403,7 +403,7 @@ static struct icalproperty_kind_value_map propval_map[] =
{ ICAL_RECURRENCEID_PROPERTY, ICAL_DATETIME_VALUE },
{ ICAL_EXDATE_PROPERTY, ICAL_DATETIME_VALUE },
{ ICAL_RDATE_PROPERTY, ICAL_DATETIME_VALUE },
- { ICAL_TRIGGER_PROPERTY, ICAL_TRIGGER_VALUE },
+ { ICAL_TRIGGER_PROPERTY, ICAL_DURATION_VALUE },
{ ICAL_DURATION_PROPERTY, ICAL_DURATION_VALUE },
/* CAP properties */
diff --git a/libical/src/libical/icalerror.c b/libical/src/libical/icalerror.c
index e9641efc6a..13c39dadbc 100644
--- a/libical/src/libical/icalerror.c
+++ b/libical/src/libical/icalerror.c
@@ -59,14 +59,66 @@ int icalerror_errors_are_fatal = 1;
int icalerror_errors_are_fatal = 0;
#endif
+struct icalerror_state {
+ icalerrorenum error;
+ icalerrorstate state;
+};
+
+struct icalerror_state error_state_map[] =
+{
+ { ICAL_BADARG_ERROR,ICAL_ERROR_DEFAULT},
+ { ICAL_NEWFAILED_ERROR,ICAL_ERROR_DEFAULT},
+ { ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_DEFAULT},
+ { ICAL_PARSE_ERROR,ICAL_ERROR_DEFAULT},
+ { ICAL_INTERNAL_ERROR,ICAL_ERROR_DEFAULT},
+ { ICAL_FILE_ERROR,ICAL_ERROR_DEFAULT},
+ { ICAL_ALLOCATION_ERROR,ICAL_ERROR_DEFAULT},
+ { ICAL_USAGE_ERROR,ICAL_ERROR_DEFAULT},
+ { ICAL_MULTIPLEINCLUSION_ERROR,ICAL_ERROR_DEFAULT},
+ { ICAL_TIMEDOUT_ERROR,ICAL_ERROR_DEFAULT},
+ { ICAL_UNKNOWN_ERROR,ICAL_ERROR_DEFAULT},
+ { ICAL_NO_ERROR,ICAL_ERROR_DEFAULT}
+
+};
+
+void icalerror_set_error_state( icalerrorenum error,
+ icalerrorstate state)
+{
+ int i;
+
+ for(i = ICAL_BADARG_ERROR; error_state_map[i].error!= ICAL_NO_ERROR;i++){
+ if(error_state_map[i].error == error){
+ error_state_map[i].state = state;
+ }
+ }
+}
+
+icalerrorstate icalerror_get_error_state( icalerrorenum error)
+{
+ int i;
+
+ for(i = ICAL_BADARG_ERROR; error_state_map[i].error!= ICAL_NO_ERROR;i++){
+ if(error_state_map[i].error == error){
+ return error_state_map[i].state;
+ }
+ }
+
+ return ICAL_ERROR_UNKNOWN;
+}
+
+
void icalerror_set_errno(icalerrorenum e) {
-
+ icalerrorstate es;
+
icalerrno = e;
- icalerror_stop_here();
+ es = icalerror_get_error_state(e);
- if(icalerror_errors_are_fatal == 1){
+ icalerror_stop_here();
+ if( (es == ICAL_ERROR_FATAL) ||
+ (es == ICAL_ERROR_DEFAULT && icalerror_errors_are_fatal == 1)){
+
fprintf(stderr,"libical: icalerrno_set_error: %s\n",icalerror_strerror(e));
#ifdef NDEBUG
icalerror_crash_here();
@@ -74,8 +126,6 @@ void icalerror_set_errno(icalerrorenum e) {
assert(0);
#endif
}
-
-
}
diff --git a/libical/src/libical/icalerror.h b/libical/src/libical/icalerror.h
index 85e054fd86..df71110ecb 100644
--- a/libical/src/libical/icalerror.h
+++ b/libical/src/libical/icalerror.h
@@ -65,33 +65,17 @@ void icalerror_crash_here(void);
#endif
/* Check & abort if check fails */
-#ifdef ICAL_ERRORS_ARE_FATAL
-#define icalerror_check_arg(test,arg) icalerror_stop_here();assert(test)
-#else
-#define icalerror_check_arg(test,arg)
-#endif
-/* Check & return void if check fails*/
+#define icalerror_check_arg(test,arg) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); }
-#ifdef ICAL_ERRORS_ARE_FATAL
-#define icalerror_check_arg_rv(test,arg) icalerror_stop_here();assert(test);
-#else
+/* Check & return void if check fails*/
#define icalerror_check_arg_rv(test,arg) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); return; }
-#endif
/* Check & return 0 if check fails*/
-#ifdef ICAL_ERRORS_ARE_FATAL
-#define icalerror_check_arg_rz(test,arg) icalerror_stop_here();assert(test);
-#else
#define icalerror_check_arg_rz(test,arg) if(!(test)) {icalerror_set_errno(ICAL_BADARG_ERROR); return 0;}
-#endif
-
/* Check & return an error if check fails*/
-#ifdef ICAL_ERRORS_ARE_FATAL
-#define icalerror_check_arg_re(test,arg,error) icalerror_stop_here();assert(test);
-#else
#define icalerror_check_arg_re(test,arg,error) if(!(test)) {icalerror_stop_here(); return error;}
-#endif
+
/* Warning messages */
@@ -138,7 +122,18 @@ extern icalerrorenum icalerrno;
extern int icalerror_errors_are_fatal;
void icalerror_clear_errno(void);
-void icalerror_set_errno(icalerrorenum e);
+void icalerror_set_errno(icalerrorenum);
+
+/* Make an individual error fatal or non-fatal. */
+typedef enum icalerrorstate {
+ ICAL_ERROR_FATAL, /* Not fata */
+ ICAL_ERROR_NONFATAL, /* Fatal */
+ ICAL_ERROR_DEFAULT, /* Use the value of icalerror_errors_are_fatal*/
+ ICAL_ERROR_UNKNOWN /* Asked state for an unknown error type */
+} icalerrorstate ;
+
+void icalerror_set_error_state( icalerrorenum error, icalerrorstate);
+icalerrorstate icalerror_get_error_state( icalerrorenum error);
char* icalerror_strerror(icalerrorenum e);
diff --git a/libical/src/libical/icalproperty.c.in b/libical/src/libical/icalproperty.c.in
index 80fefd58ab..936db3f728 100644
--- a/libical/src/libical/icalproperty.c.in
+++ b/libical/src/libical/icalproperty.c.in
@@ -4,7 +4,7 @@
FILE: icalproperty.c
CREATOR: eric 28 April 1999
- $Id: icalproperty.c.in,v 1.3 2001/01/23 20:22:33 jpr Exp $
+ $Id: icalproperty.c.in,v 1.4 2001/02/05 19:43:57 jpr Exp $
(C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
@@ -283,12 +283,72 @@ icalproperty_as_ical_string (icalproperty* prop)
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];
diff --git a/libical/src/libical/icalrecur.c b/libical/src/libical/icalrecur.c
index cfd8e2b33b..db3f7aefff 100644
--- a/libical/src/libical/icalrecur.c
+++ b/libical/src/libical/icalrecur.c
@@ -4,7 +4,6 @@
CREATOR: eric 16 May 2000
$Id$
-
$Locker$
@@ -355,6 +354,12 @@ struct icalrecurrencetype icalrecurrencetype_from_string(const char* str)
char *name, *value;
icalrecur_clause_name_and_value(&parser,&name,&value);
+ if(name == 0){
+ icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
+ icalrecurrencetype_clear(&parser.rt);
+ return parser.rt;
+ }
+
if (strcmp(name,"FREQ") == 0){
parser.rt.freq = icalrecur_string_to_recurrence(value);
} else if (strcmp(name,"COUNT") == 0){
@@ -392,7 +397,9 @@ struct icalrecurrencetype icalrecurrencetype_from_string(const char* str)
icalrecur_add_byrules(&parser,parser.rt.by_set_pos,
ICAL_BY_SETPOS_SIZE,value);
} else {
- /* error */
+ icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
+ icalrecurrencetype_clear(&parser.rt);
+ return parser.rt;
}
}
diff --git a/libical/src/libical/icaltime.c b/libical/src/libical/icaltime.c
index b0ea1fab0a..b3d9353f32 100644
--- a/libical/src/libical/icaltime.c
+++ b/libical/src/libical/icaltime.c
@@ -125,7 +125,7 @@ char* set_tz(const char* tzid)
return old_tz_copy; /* This will be zero if the TZ env var was not set */
}
-void unset_tz(char* tzstr)
+void unset_tz(struct set_tz_save savetz)
{
/* restore the original environment */
@@ -144,6 +144,7 @@ void unset_tz(char* tzstr)
saved_tz = tzstr;
}
+
time_t icaltime_as_timet(struct icaltimetype tt)
{
struct tm stm;
@@ -164,7 +165,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 {
@@ -242,11 +243,10 @@ 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 */
@@ -255,7 +255,7 @@ int icaltime_utc_offset(struct icaltimetype ictt, const char* tzid)
offset_tt = mktime(&gtm);
if(tzid != 0){
- unset_tz(tzstr);
+ unset_tz(old_tz);
}
return tt-offset_tt;
@@ -474,6 +474,19 @@ struct icaltimetype icaltime_null_time()
return t;
}
+
+
+int icaltime_is_valid_time(struct icaltimetype t){
+ if(t.is_utc > 1 || t.is_utc < 0 ||
+ t.year < 0 || t.year > 3000 ||
+ t.is_date > 1 || t.is_date < 0){
+ return 0;
+ } else {
+ return 1;
+ }
+
+}
+
int icaltime_is_null_time(struct icaltimetype t)
{
if (t.second +t.minute+t.hour+t.day+t.month+t.year == 0){
@@ -599,6 +612,7 @@ const char* icalperiodtype_as_ical_string(struct icalperiodtype p)
return buf;
}
+
time_t
icalperiodtype_duration (struct icalperiodtype period);
@@ -607,6 +621,35 @@ time_t
icalperiodtype_end (struct icalperiodtype period);
+struct icalperiodtype icalperiodtype_null_period() {
+ struct icalperiodtype p;
+ p.start = icaltime_null_time();
+ p.end = icaltime_null_time();
+ p.duration = icaldurationtype_null_duration();
+
+ return p;
+}
+int icalperiodtype_is_null_period(struct icalperiodtype p){
+
+ if(icaltime_is_null_time(p.start) &&
+ icaltime_is_null_time(p.end) &&
+ icaldurationtype_is_null_duration(p.duration)){
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+int icalperiodtype_is_valid_period(struct icalperiodtype p){
+ if(icaltime_is_valid_time(p.start) &&
+ (icaltime_is_valid_time(p.end) || icaltime_is_null_time(p.end)) )
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
/* From Russel Steinthal */
int icaldurationtype_as_int(struct icaldurationtype dur)
{
@@ -827,15 +870,33 @@ char* icaldurationtype_as_ical_string(struct icaldurationtype d)
#endif
+struct icaldurationtype icaldurationtype_null_duration()
+{
+ struct icaldurationtype d;
+
+ memset(&d,0,sizeof(struct icaldurationtype));
+
+ return d;
+}
+
+int icaldurationtype_is_null_duration(struct icaldurationtype d)
+{
+ if(icaldurationtype_as_int(d) == 0){
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
struct icaltimetype icaltime_add(struct icaltimetype t,
struct icaldurationtype d)
{
int dt = icaldurationtype_as_int(d);
-
+
t.second += dt;
-
+
t = icaltime_normalize(t);
-
+
return t;
}
diff --git a/libical/src/libical/icaltime.h b/libical/src/libical/icaltime.h
index d624041c29..165b88d943 100644
--- a/libical/src/libical/icaltime.h
+++ b/libical/src/libical/icaltime.h
@@ -5,7 +5,6 @@
$Id$
-
$Locker$
(C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
@@ -86,6 +85,7 @@ struct icaltimetype icaltime_as_zone(struct icaltimetype tt,
struct icaltimetype icaltime_null_time(void);
int icaltime_is_null_time(struct icaltimetype t);
+int icaltime_is_valid_time(struct icaltimetype t);
struct icaltimetype icaltime_normalize(struct icaltimetype t);
@@ -123,7 +123,8 @@ struct icaldurationtype icaldurationtype_from_int(int t);
struct icaldurationtype icaldurationtype_from_string(const char*);
int icaldurationtype_as_int(struct icaldurationtype duration);
char* icaldurationtype_as_ical_string(struct icaldurationtype d);
-
+struct icaldurationtype icaldurationtype_null_duration();
+int icaldurationtype_is_null_duration(struct icaldurationtype d);
struct icalperiodtype
{
@@ -134,6 +135,9 @@ struct icalperiodtype
struct icalperiodtype icalperiodtype_from_string (const char* str);
const char* icalperiodtype_as_ical_string(struct icalperiodtype p);
+struct icalperiodtype icalperiodtype_null_period();
+int icalperiodtype_is_null_period(struct icalperiodtype p);
+int icalperiodtype_is_valid_period(struct icalperiodtype p);
time_t icalperiodtype_duration(struct icalperiodtype period);
time_t icalperiodtype_end(struct icalperiodtype period);
diff --git a/libical/src/libical/icaltypes.c b/libical/src/libical/icaltypes.c
index 4afc8916bb..c6c388a978 100644
--- a/libical/src/libical/icaltypes.c
+++ b/libical/src/libical/icaltypes.c
@@ -4,7 +4,6 @@
CREATOR: eric 16 May 1999
$Id$
-
$Locker$
diff --git a/libical/src/libical/icaltypes.h b/libical/src/libical/icaltypes.h
index ef4f874064..7c0d2dd617 100644
--- a/libical/src/libical/icaltypes.h
+++ b/libical/src/libical/icaltypes.h
@@ -67,6 +67,14 @@ struct icalgeotype
float lon;
};
+
+struct icaldatetimeperiodtype
+{
+ struct icaltimetype time;
+ struct icalperiodtype period;
+};
+
+
struct icaltriggertype
{
struct icaltimetype time;
diff --git a/libical/src/libical/icalvalue.c.in b/libical/src/libical/icalvalue.c.in
index cdcd12ba83..0bbf7cd934 100644
--- a/libical/src/libical/icalvalue.c.in
+++ b/libical/src/libical/icalvalue.c.in
@@ -3,7 +3,7 @@
FILE: icalvalue.c
CREATOR: eric 02 May 1999
- $Id: icalvalue.c.in,v 1.3 2001/01/23 20:22:33 jpr Exp $
+ $Id: icalvalue.c.in,v 1.4 2001/02/05 19:43:57 jpr Exp $
(C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
@@ -57,45 +57,46 @@ 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;
- 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;
+ 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){
@@ -586,6 +587,7 @@ 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);
@@ -600,7 +602,9 @@ 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);
@@ -613,7 +617,9 @@ 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){
@@ -853,8 +859,21 @@ 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");
- data = icalvalue_get_date(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);
@@ -911,76 +930,24 @@ char* icalvalue_geo_as_ical_string(icalvalue* value) {
}
char* icalvalue_datetimeperiod_as_ical_string(icalvalue* value) {
+ struct icalvalue_impl* impl = (struct icalvalue_impl*)value;
+ struct icaldatetimeperiodtype dtp = icalvalue_get_datetimeperiod(value);
- struct icalperiodtype data;
- char* str;
icalerror_check_arg_rz( (value!=0),"value");
- data = icalvalue_get_datetimeperiod(value);
-
- str = (char*)icalmemory_tmp_buffer(60);
-
- if( data.end.second == -1){
- /* This is a DATE-TIME value, since there is no end value */
- icalvalue *v= icalvalue_new_datetime(data.start);
-
- strcpy(str,icalvalue_datetime_as_ical_string(v));
-
- free(v);
+ if(!icaltime_is_null_time(dtp.time)){
+ return icaltime_as_ical_string(dtp.time);
} else {
- icalvalue *v1 = icalvalue_new_datetime(data.start);
- icalvalue *v2 = icalvalue_new_datetime(data.end);
-
- sprintf(str,"%s/%s",
- icalvalue_datetime_as_ical_string(v1),
- icalvalue_datetime_as_ical_string(v2)
- );
-
- free(v1);
- free(v2);
-
+ return icalperiodtype_as_ical_string(dtp.period);
}
-
- return str;
}
char* icalvalue_period_as_ical_string(icalvalue* value) {
-
struct icalperiodtype data;
- char* str;
- icalvalue *s,*e;
-
icalerror_check_arg_rz( (value!=0),"value");
data = icalvalue_get_period(value);
- str = (char*)icalmemory_tmp_buffer(60);
-
- s = icalvalue_new_datetime(data.start);
-
- if (data.end.second != -1){
- /* use the end date */
- e = icalvalue_new_datetime(data.end);
-
- sprintf(str,"%s/%s",
- icalvalue_datetime_as_ical_string(s),
- icalvalue_datetime_as_ical_string(e)
- );
-
-
- } else {
- /* use the duration */
- e = icalvalue_new_duration(data.duration);
-
- sprintf(str,"%s/%s",
- icalvalue_datetime_as_ical_string(s),
- icalvalue_duration_as_ical_string(e)
- );
-
- }
-
- icalvalue_free(e);
- icalvalue_free(s);
- return str;
+ return icalperiodtype_as_ical_string(data);
}
char* icalvalue_trigger_as_ical_string(icalvalue* value)
@@ -1316,6 +1283,127 @@ icalvalue_get_recur(icalvalue* value)
+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 */
diff --git a/libical/src/test/copycluster.c b/libical/src/test/copycluster.c
index 11e648d861..fa87e25385 100644
--- a/libical/src/test/copycluster.c
+++ b/libical/src/test/copycluster.c
@@ -56,6 +56,10 @@ int main(int c, char *argv[]){
tostdout = 1;
}
+
+ icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR, ICAL_ERROR_NONFATAL);
+ icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL);
+
clusterin = icalfileset_new(argv[1]);
if (clusterin == 0){
diff --git a/libical/src/test/regression.c b/libical/src/test/regression.c
index 66307bb405..00c686d027 100644
--- a/libical/src/test/regression.c
+++ b/libical/src/test/regression.c
@@ -124,13 +124,13 @@ icalcomponent* create_new_component()
icalcomponent* tzc;
icalcomponent* event;
struct icaltimetype atime = icaltime_from_timet( time(0),0);
- struct icalperiodtype rtime;
+ struct icaldatetimeperiodtype rtime;
icalproperty* property;
- rtime.start = icaltime_from_timet( time(0),0);
- rtime.end = icaltime_from_timet( time(0),0);
-
- rtime.end.hour++;
+ rtime.period.start = icaltime_from_timet( time(0),0);
+ rtime.period.end = icaltime_from_timet( time(0),0);
+ rtime.period.end.hour++;
+ rtime.time = icaltime_null_time();
@@ -333,12 +333,12 @@ icalcomponent* create_new_component_with_va_args()
icalcomponent* calendar;
struct icaltimetype atime = icaltime_from_timet( time(0),0);
- struct icalperiodtype rtime;
+ struct icaldatetimeperiodtype rtime;
- rtime.start = icaltime_from_timet( time(0),0);
- rtime.end = icaltime_from_timet( time(0),0);
-
- rtime.end.hour++;
+ rtime.period.start = icaltime_from_timet( time(0),0);
+ rtime.period.end = icaltime_from_timet( time(0),0);
+ rtime.period.end.hour++;
+ rtime.time = icaltime_null_time();
calendar =
icalcomponent_vanew(
@@ -990,12 +990,12 @@ void test_restriction()
struct icaltimetype atime = icaltime_from_timet( time(0),0);
int valid;
- struct icalperiodtype rtime;
+ struct icaldatetimeperiodtype rtime;
- rtime.start = icaltime_from_timet( time(0),0);
- rtime.end = icaltime_from_timet( time(0),0);
-
- rtime.end.hour++;
+ rtime.period.start = icaltime_from_timet( time(0),0);
+ rtime.period.end = icaltime_from_timet( time(0),0);
+ rtime.period.end.hour++;
+ rtime.time = icaltime_null_time();
comp =
icalcomponent_vanew(
@@ -2832,21 +2832,29 @@ void test_file_locks()
assert(sec == final);
}
+/* For GNU libc, strcmp appears to be a macro, so using strcmp in assert results in incomprehansible assertion messages. This eliminates the problem */
+
+int ttstrcmp(const char* a, const char* b){
+ return strcmp(a,b);
+}
void test_trigger()
{
+ struct icaltriggertype tr;
+ struct icaldatetimeperiodtype dtp;
+ icalcomponent *c;
+ icalproperty *p;
+ char* str;
+
static const char test_icalcomp_str[] =
"BEGIN:VEVENT\n"
"TRIGGER;VALUE=DATE-TIME:19980403T120000\n"
"TRIGGER:-PT15M\n"
"TRIGGER:19980403T120000\n"
+"TRIGGER;VALUE=DURATION:-PT15M\n"
"END:VEVENT\r\n";
- icalcomponent *c;
- icalproperty *p;
- struct icaltriggertype tr;
-
c = icalparser_parse_string ((char *) test_icalcomp_str);
if (!c) {
@@ -2867,8 +2875,203 @@ void test_trigger()
printf("value=DURATION:%s\n", icaldurationtype_as_ical_string(tr.duration));
}
}
+
+ /* Trigger, as a DATETIME */
+ tr.duration = icaldurationtype_null_duration();
+ tr.time = icaltime_from_string("19970101T120000");
+ p = icalproperty_new_trigger(tr);
+ str = icalproperty_as_ical_string(p);
+
+ printf("%s\n",str);
+ assert(ttstrcmp("TRIGGER\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0);
+ icalproperty_free(p);
+
+ /* TRIGGER, as a DURATION */
+ tr.time = icaltime_null_time();
+ tr.duration = icaldurationtype_from_string("P3DT3H50M45S");
+ p = icalproperty_new_trigger(tr);
+ str = icalproperty_as_ical_string(p);
+
+ printf("%s\n",str);
+ assert(ttstrcmp("TRIGGER\n :P3DT3H50M45S\n",str) == 0);
+ icalproperty_free(p);
+
+ /* TRIGGER, as a DATETIME, VALUE=DATETIME*/
+ tr.duration = icaldurationtype_null_duration();
+ tr.time = icaltime_from_string("19970101T120000");
+ p = icalproperty_new_trigger(tr);
+ icalproperty_add_parameter(p,icalparameter_new_value( ICAL_VALUE_DATETIME));
+ str = icalproperty_as_ical_string(p);
+
+ printf("%s\n",str);
+ assert(ttstrcmp("TRIGGER\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0);
+ icalproperty_free(p);
+
+ /*TRIGGER, as a DURATION, VALUE=DATETIME */
+ tr.time = icaltime_null_time();
+ tr.duration = icaldurationtype_from_string("P3DT3H50M45S");
+ p = icalproperty_new_trigger(tr);
+ icalproperty_add_parameter(p,icalparameter_new_value( ICAL_VALUE_DATETIME ));
+
+ str = icalproperty_as_ical_string(p);
+
+ printf("%s\n",str);
+ assert(ttstrcmp("TRIGGER\n ;VALUE=DURATION\n :P3DT3H50M45S\n",str) == 0);
+ icalproperty_free(p);
+
+ /* TRIGGER, as a DATETIME, VALUE=DURATION*/
+ tr.duration = icaldurationtype_null_duration();
+ tr.time = icaltime_from_string("19970101T120000");
+ p = icalproperty_new_trigger(tr);
+ icalproperty_add_parameter(p,icalparameter_new_value( ICAL_VALUE_DURATION));
+ str = icalproperty_as_ical_string(p);
+
+ printf("%s\n",str);
+ assert(ttstrcmp("TRIGGER\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0);
+ icalproperty_free(p);
+
+ /*TRIGGER, as a DURATION, VALUE=DURATION */
+ tr.time = icaltime_null_time();
+ tr.duration = icaldurationtype_from_string("P3DT3H50M45S");
+ p = icalproperty_new_trigger(tr);
+ icalproperty_add_parameter(p,icalparameter_new_value( ICAL_VALUE_DURATION));
+
+ str = icalproperty_as_ical_string(p);
+
+ printf("%s\n",str);
+ assert(ttstrcmp("TRIGGER\n ;VALUE=DURATION\n :P3DT3H50M45S\n",str) == 0);
+ icalproperty_free(p);
+
+
+ /* TRIGGER, as a DATETIME, VALUE=BINARY */
+ tr.duration = icaldurationtype_null_duration();
+ tr.time = icaltime_from_string("19970101T120000");
+ p = icalproperty_new_trigger(tr);
+ icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY));
+ str = icalproperty_as_ical_string(p);
+
+ printf("%s\n",str);
+ assert(ttstrcmp("TRIGGER\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0);
+ icalproperty_free(p);
+
+ /*TRIGGER, as a DURATION, VALUE=BINARY */
+ tr.time = icaltime_null_time();
+ tr.duration = icaldurationtype_from_string("P3DT3H50M45S");
+ p = icalproperty_new_trigger(tr);
+ icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY));
+
+ str = icalproperty_as_ical_string(p);
+
+ printf("%s\n",str);
+ assert(ttstrcmp("TRIGGER\n ;VALUE=DURATION\n :P3DT3H50M45S\n",str) == 0);
+ icalproperty_free(p);
+
+
+
+}
+
+void test_rdate()
+{
+
+ struct icaldatetimeperiodtype dtp;
+ icalproperty *p;
+ char* str;
+ struct icaltimetype time = icaltime_from_string("19970101T120000");
+ struct icalperiodtype period;
+
+ period.start = icaltime_from_string("19970101T120000");
+ period.end = icaltime_null_time();
+ period.duration = icaldurationtype_from_string("PT3H10M15S");
+
+ /* RDATE, as DATE-TIME */
+ dtp.time = icaltime_from_string("19970101T120000");
+ dtp.period = icalperiodtype_null_period();
+ p = icalproperty_new_rdate(dtp);
+ str = icalproperty_as_ical_string(p);
+ printf("%s\n",str);
+ assert(ttstrcmp("RDATE\n :19970101T120000\n",str) == 0);
+ icalproperty_free(p);
+
+
+ /* RDATE, as PERIOD */
+ dtp.time = icaltime_null_time();
+ dtp.period = period;
+ p = icalproperty_new_rdate(dtp);
+
+ str = icalproperty_as_ical_string(p);
+ printf("%s\n",str);
+ assert(ttstrcmp("RDATE\n ;VALUE=PERIOD\n :19970101T120000/PT3H10M15S\n",str) == 0);
+ icalproperty_free(p);
+
+ /* RDATE, as DATE-TIME, VALUE=DATE-TIME */
+ dtp.time = icaltime_from_string("19970101T120000");
+ dtp.period = icalperiodtype_null_period();
+ p = icalproperty_new_rdate(dtp);
+ icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_DATETIME));
+ str = icalproperty_as_ical_string(p);
+ printf("%s\n",str);
+ assert(ttstrcmp("RDATE\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0);
+ icalproperty_free(p);
+
+
+ /* RDATE, as PERIOD, VALUE=DATE-TIME */
+ dtp.time = icaltime_null_time();
+ dtp.period = period;
+ p = icalproperty_new_rdate(dtp);
+ icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_DATETIME));
+ str = icalproperty_as_ical_string(p);
+ printf("%s\n",str);
+ assert(ttstrcmp("RDATE\n ;VALUE=PERIOD\n :19970101T120000/PT3H10M15S\n",str) == 0);
+ icalproperty_free(p);
+
+
+ /* RDATE, as DATE-TIME, VALUE=PERIOD */
+ dtp.time = icaltime_from_string("19970101T120000");
+ dtp.period = icalperiodtype_null_period();
+ p = icalproperty_new_rdate(dtp);
+ icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_PERIOD));
+ str = icalproperty_as_ical_string(p);
+ printf("%s\n",str);
+ assert(ttstrcmp("RDATE\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0);
+ icalproperty_free(p);
+
+
+ /* RDATE, as PERIOD, VALUE=PERIOD */
+ dtp.time = icaltime_null_time();
+ dtp.period = period;
+ p = icalproperty_new_rdate(dtp);
+ icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_PERIOD));
+ str = icalproperty_as_ical_string(p);
+ printf("%s\n",str);
+ assert(ttstrcmp("RDATE\n ;VALUE=PERIOD\n :19970101T120000/PT3H10M15S\n",str) == 0);
+ icalproperty_free(p);
+
+
+ /* RDATE, as DATE-TIME, VALUE=BINARY */
+ dtp.time = icaltime_from_string("19970101T120000");
+ dtp.period = icalperiodtype_null_period();
+ p = icalproperty_new_rdate(dtp);
+ icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY));
+ str = icalproperty_as_ical_string(p);
+ printf("%s\n",str);
+ assert(ttstrcmp("RDATE\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0);
+ icalproperty_free(p);
+
+
+ /* RDATE, as PERIOD, VALUE=BINARY */
+ dtp.time = icaltime_null_time();
+ dtp.period = period;
+ p = icalproperty_new_rdate(dtp);
+ icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY));
+ str = icalproperty_as_ical_string(p);
+ printf("%s\n",str);
+ assert(ttstrcmp("RDATE\n ;VALUE=PERIOD\n :19970101T120000/PT3H10M15S\n",str) == 0);
+ icalproperty_free(p);
+
+
}
+
int main(int argc, char *argv[])
{
int c;
@@ -3024,6 +3227,17 @@ int main(int argc, char *argv[])
test_trigger();
}
+ if(tmisc == 1 || tmisc == 4){
+
+ printf("\n------------Test Restriction---------------\n");
+ test_restriction();
+ }
+
+ if(tmisc == 1 || tmisc == 5){
+
+ printf("\n------------Test RDATE---------------\n");
+ test_rdate();
+ }
if(tmisc == 1){
@@ -3038,8 +3252,6 @@ int main(int argc, char *argv[])
printf("\n------------Test Iterators-----------\n");
test_iterators();
- printf("\n------------Test Restriction---------------\n");
- test_restriction();
printf("\n-----------Test request status-------\n");
test_requeststat();