2 ======================================================================
4 CREATOR: eric 16 May 1999
6 $Id: icaltypes.c,v 1.18 2008-01-15 23:17:42 dothebart Exp $
10 (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org>
11 http://www.softwarestudio.org
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of either:
16 The LGPL as published by the Free Software Foundation, version
17 2.1, available at: http://www.fsf.org/copyleft/lesser.html
21 The Mozilla Public License Version 1.0. You may obtain a copy of
22 the License at http://www.mozilla.org/MPL/
24 The original code is icaltypes.c
26 ======================================================================*/
31 #include "icaltypes.h"
32 #include "icalerror.h"
33 #include "icalmemory.h"
34 #include <stdlib.h> /* for malloc and abs() */
35 #include <errno.h> /* for errno */
36 #include <string.h> /* for icalmemory_strdup */
40 #define snprintf _snprintf
41 #define strcasecmp stricmp
48 static pthread_mutex_t unk_token_mutex = PTHREAD_MUTEX_INITIALIZER;
51 static ical_unknown_token_handling unknownTokenHandling = ICAL_TREAT_AS_ERROR;
53 int icaltriggertype_is_null_trigger(struct icaltriggertype tr)
55 if(icaltime_is_null_time(tr.time) &&
56 icaldurationtype_is_null_duration(tr.duration)){
63 int icaltriggertype_is_bad_trigger(struct icaltriggertype tr)
65 if(icaldurationtype_is_bad_duration(tr.duration)){
72 struct icaltriggertype icaltriggertype_from_int(const int reltime)
74 struct icaltriggertype tr;
76 tr.time = icaltime_null_time();
77 tr.duration = icaldurationtype_from_int(reltime);
82 struct icaltriggertype icaltriggertype_from_string(const char* str)
86 struct icaltriggertype tr;
87 icalerrorstate es = ICAL_ERROR_DEFAULT;
90 tr.time= icaltime_null_time();
91 tr.duration = icaldurationtype_from_int(0);
93 /* Suppress errors so a failure in icaltime_from_string() does not cause an abort */
94 es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR);
95 if(str == 0) goto error;
96 icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL);
98 icalerror_set_errno(ICAL_NO_ERROR);
100 tr.time = icaltime_from_string(str);
102 if (icaltime_is_null_time(tr.time)){
104 tr.duration = icaldurationtype_from_string(str);
106 if (icaldurationtype_is_bad_duration(tr.duration)) goto error;
109 icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es);
110 icalerror_set_errno(e);
114 icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es);
115 icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
121 struct icalreqstattype icalreqstattype_from_string(const char* str)
124 struct icalreqstattype stat;
125 short major=0, minor=0;
127 icalerror_check_arg((str != 0),"str");
129 stat.code = ICAL_UNKNOWN_STATUS;
133 /* Get the status numbers */
135 sscanf(str, "%hd.%hd",&major, &minor);
137 if (major <= 0 || minor < 0){
138 icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
142 stat.code = icalenum_num_to_reqstat(major, minor);
144 if (stat.code == ICAL_UNKNOWN_STATUS){
145 icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
150 p1 = strchr(str,';');
153 /* icalerror_set_errno(ICAL_BADARG_ERROR);*/
157 /* Just ignore the second clause; it will be taken from inside the library
162 p2 = strchr(p1+1,';');
163 if (p2 != 0 && *p2 != 0){
171 const char* icalreqstattype_as_string(struct icalreqstattype stat)
174 buf = icalreqstattype_as_string_r(stat);
175 icalmemory_add_tmp_buffer(buf);
180 char* icalreqstattype_as_string_r(struct icalreqstattype stat)
184 icalerror_check_arg_rz((stat.code != ICAL_UNKNOWN_STATUS),"Status");
186 temp = (char*)icalmemory_new_buffer(TEMP_MAX);
189 stat.desc = icalenum_reqstat_desc(stat.code);
193 snprintf(temp,TEMP_MAX,"%d.%d;%s;%s", icalenum_reqstat_major(stat.code),
194 icalenum_reqstat_minor(stat.code),
195 stat.desc, stat.debug);
198 snprintf(temp,TEMP_MAX,"%d.%d;%s", icalenum_reqstat_major(stat.code),
199 icalenum_reqstat_minor(stat.code),
206 ical_unknown_token_handling ical_get_unknown_token_handling_setting(void)
208 ical_unknown_token_handling myHandling;
211 pthread_mutex_lock (&unk_token_mutex);
214 myHandling = unknownTokenHandling;
217 pthread_mutex_unlock (&unk_token_mutex);
223 void ical_set_unknown_token_handling_setting(ical_unknown_token_handling newSetting)
227 pthread_mutex_lock (&unk_token_mutex);
230 unknownTokenHandling = newSetting;
233 pthread_mutex_unlock (&unk_token_mutex);