Diffstat (limited to 'libical/src/libical/icaltypes.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libical/src/libical/icaltypes.c | 140 |
1 files changed, 23 insertions, 117 deletions
diff --git a/libical/src/libical/icaltypes.c b/libical/src/libical/icaltypes.c index 8c67deb..19719f8 100644 --- a/libical/src/libical/icaltypes.c +++ b/libical/src/libical/icaltypes.c | |||
@@ -22,220 +22,126 @@ | |||
22 | 22 | ||
23 | The original code is icaltypes.c | 23 | The original code is icaltypes.c |
24 | 24 | ||
25 | ======================================================================*/ | 25 | ======================================================================*/ |
26 | #ifdef HAVE_CONFIG_H | 26 | #ifdef HAVE_CONFIG_H |
27 | #include "config.h" | 27 | #include "config.h" |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | #include "icaltypes.h" | 30 | #include "icaltypes.h" |
31 | #include "icalerror.h" | 31 | #include "icalerror.h" |
32 | #include "icalmemory.h" | 32 | #include "icalmemory.h" |
33 | #include <stdlib.h> /* for malloc and abs() */ | 33 | #include <stdlib.h> /* for malloc and abs() */ |
34 | #include <errno.h> /* for errno */ | 34 | #include <errno.h> /* for errno */ |
35 | #include <string.h> /* for icalmemory_strdup */ | 35 | #include <string.h> /* for icalmemory_strdup */ |
36 | #include <assert.h> | 36 | #include <assert.h> |
37 | 37 | ||
38 | int snprintf(char *str, size_t n, char const *fmt, ...); | 38 | #ifdef WIN32 |
39 | #define snprintf _snprintf | ||
40 | #define strcasecmp stricmp | ||
41 | #endif | ||
39 | 42 | ||
40 | #define TEMP_MAX 1024 | 43 | #define TEMP_MAX 1024 |
41 | 44 | ||
42 | void* | ||
43 | icalattachtype_get_data (struct icalattachtype* type); | ||
44 | 45 | ||
45 | struct icalattachtype* | 46 | int icaltriggertype_is_null_trigger(struct icaltriggertype tr) |
46 | icalattachtype_new() | ||
47 | { | 47 | { |
48 | struct icalattachtype* v; | 48 | if(icaltime_is_null_time(tr.time) && |
49 | 49 | icaldurationtype_is_null_duration(tr.duration)){ | |
50 | if ( ( v = (struct icalattachtype*) | 50 | return 1; |
51 | malloc(sizeof(struct icalattachtype))) == 0) { | ||
52 | errno = ENOMEM; | ||
53 | return 0; | ||
54 | } | 51 | } |
55 | 52 | ||
56 | v->refcount = 1; | 53 | return 0; |
57 | |||
58 | v->binary = 0; | ||
59 | v->owns_binary = 0; | ||
60 | v->base64 = 0; | ||
61 | //fprintf(stderr,"setting base 64 to 0 \n"); | ||
62 | |||
63 | v->owns_base64 = 0; | ||
64 | |||
65 | v->url = 0; | ||
66 | |||
67 | return v; | ||
68 | } | 54 | } |
69 | |||
70 | |||
71 | void | ||
72 | icalattachtype_free(struct icalattachtype* v) | ||
73 | { | ||
74 | icalerror_check_arg( (v!=0),"v"); | ||
75 | 55 | ||
76 | v->refcount--; | 56 | int icaltriggertype_is_bad_trigger(struct icaltriggertype tr) |
77 | |||
78 | if (v->refcount <= 0){ | ||
79 | |||
80 | if (v->base64 != 0 && v->owns_base64 != 0){ | ||
81 | int val = v->base64 ; | ||
82 | if ( val < 255 ) { | ||
83 | fprintf(stderr,"Possible error in attachment processing (%d)\nPocssible solution: Remove attachment from file.\n",val ); | ||
84 | } | ||
85 | free(v->base64); | ||
86 | } | ||
87 | |||
88 | if (v->binary != 0 && v->owns_binary != 0){ | ||
89 | free(v->binary); | ||
90 | } | ||
91 | |||
92 | if (v->url != 0){ | ||
93 | free(v->url); | ||
94 | } | ||
95 | |||
96 | free(v); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | void icalattachtype_add_reference(struct icalattachtype* v) | ||
101 | { | ||
102 | icalerror_check_arg( (v!=0),"v"); | ||
103 | v->refcount++; | ||
104 | } | ||
105 | |||
106 | void icalattachtype_set_url(struct icalattachtype* v, char* url) | ||
107 | { | 57 | { |
108 | icalerror_check_arg( (v!=0),"v"); | 58 | if(icaldurationtype_is_bad_duration(tr.duration)){ |
109 | 59 | return 1; | |
110 | if (v->url != 0){ | ||
111 | free (v->url); | ||
112 | } | 60 | } |
113 | 61 | ||
114 | v->url = icalmemory_strdup(url); | 62 | return 0; |
115 | |||
116 | /* HACK This routine should do something if icalmemory_strdup returns NULL */ | ||
117 | |||
118 | } | ||
119 | |||
120 | char* icalattachtype_get_url(struct icalattachtype* v) | ||
121 | { | ||
122 | icalerror_check_arg( (v!=0),"v"); | ||
123 | return v->url; | ||
124 | } | ||
125 | |||
126 | void icalattachtype_set_base64(struct icalattachtype* v, char* base64, | ||
127 | int owns) | ||
128 | { | ||
129 | //fprintf(stderr,"1setbase64 %d \n", base64 ); | ||
130 | icalerror_check_arg( (v!=0),"v"); | ||
131 | //fprintf(stderr,"setbase64 %d \n", base64 ); | ||
132 | v->base64 = base64; | ||
133 | v->owns_base64 = !(owns != 0 ); | ||
134 | |||
135 | } | ||
136 | |||
137 | char* icalattachtype_get_base64(struct icalattachtype* v) | ||
138 | { | ||
139 | icalerror_check_arg( (v!=0),"v"); | ||
140 | return v->base64; | ||
141 | } | 63 | } |
142 | 64 | ||
143 | void icalattachtype_set_binary(struct icalattachtype* v, char* binary, | 65 | struct icaltriggertype icaltriggertype_from_int(const int reltime) |
144 | int owns) | ||
145 | { | 66 | { |
146 | icalerror_check_arg( (v!=0),"v"); | 67 | struct icaltriggertype tr; |
147 | 68 | ||
148 | v->binary = binary; | 69 | tr.time= icaltime_null_time(); |
149 | v->owns_binary = !(owns != 0 ); | 70 | tr.duration = icaldurationtype_from_int(reltime); |
150 | 71 | ||
72 | return tr; | ||
151 | } | 73 | } |
152 | 74 | ||
153 | void* icalattachtype_get_binary(struct icalattachtype* v) | ||
154 | { | ||
155 | icalerror_check_arg( (v!=0),"v"); | ||
156 | return v->binary; | ||
157 | } | ||
158 | |||
159 | int icaltriggertype_is_null_trigger(struct icaltriggertype tr) | ||
160 | { | ||
161 | if(icaltime_is_null_time(tr.time) && | ||
162 | icaldurationtype_is_null_duration(tr.duration)){ | ||
163 | return 1; | ||
164 | } | ||
165 | |||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | struct icaltriggertype icaltriggertype_from_string(const char* str) | 75 | struct icaltriggertype icaltriggertype_from_string(const char* str) |
170 | { | 76 | { |
171 | 77 | ||
172 | 78 | ||
173 | struct icaltriggertype tr, null_tr; | 79 | struct icaltriggertype tr, null_tr; |
174 | icalerrorstate es; | 80 | icalerrorstate es; |
175 | icalerrorenum e; | 81 | icalerrorenum e; |
176 | 82 | ||
177 | tr.time= icaltime_null_time(); | 83 | tr.time= icaltime_null_time(); |
178 | tr.duration = icaldurationtype_from_int(0); | 84 | tr.duration = icaldurationtype_from_int(0); |
179 | 85 | ||
180 | null_tr = tr; | 86 | null_tr = tr; |
181 | 87 | ||
182 | if(str == 0) goto error; | 88 | if(str == 0) goto error; |
183 | 89 | ||
184 | /* Surpress errors so a failure in icaltime_from_string() does not cause an abort */ | 90 | /* Suppress errors so a failure in icaltime_from_string() does not cause an abort */ |
185 | es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR); | 91 | es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR); |
186 | icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL); | 92 | icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL); |
187 | e = icalerrno; | 93 | e = icalerrno; |
188 | icalerror_set_errno(ICAL_NO_ERROR); | 94 | icalerror_set_errno(ICAL_NO_ERROR); |
189 | 95 | ||
190 | tr.time = icaltime_from_string(str); | 96 | tr.time = icaltime_from_string(str); |
191 | 97 | ||
192 | if (icaltime_is_null_time(tr.time)){ | 98 | if (icaltime_is_null_time(tr.time)){ |
193 | 99 | ||
194 | tr.duration = icaldurationtype_from_string(str); | 100 | tr.duration = icaldurationtype_from_string(str); |
195 | 101 | ||
196 | if(icaldurationtype_as_int(tr.duration) == 0) goto error; | 102 | if (icaldurationtype_is_bad_duration(tr.duration)) goto error; |
197 | } | 103 | } |
198 | 104 | ||
199 | icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); | 105 | icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); |
200 | icalerror_set_errno(e); | 106 | icalerror_set_errno(e); |
201 | return tr; | 107 | return tr; |
202 | 108 | ||
203 | error: | 109 | error: |
204 | icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); | 110 | icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); |
205 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); | 111 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); |
206 | return null_tr; | 112 | return tr; |
207 | 113 | ||
208 | } | 114 | } |
209 | 115 | ||
210 | 116 | ||
211 | struct icalreqstattype icalreqstattype_from_string(const char* str) | 117 | struct icalreqstattype icalreqstattype_from_string(const char* str) |
212 | { | 118 | { |
213 | const char *p1,*p2; | 119 | const char *p1,*p2; |
214 | struct icalreqstattype stat; | 120 | struct icalreqstattype stat; |
215 | int major, minor; | 121 | short major=0, minor=0; |
216 | 122 | ||
217 | icalerror_check_arg((str != 0),"str"); | 123 | icalerror_check_arg((str != 0),"str"); |
218 | 124 | ||
219 | stat.code = ICAL_UNKNOWN_STATUS; | 125 | stat.code = ICAL_UNKNOWN_STATUS; |
220 | stat.debug = 0; | 126 | stat.debug = 0; |
221 | stat.desc = 0; | 127 | stat.desc = 0; |
222 | 128 | ||
223 | /* Get the status numbers */ | 129 | /* Get the status numbers */ |
224 | 130 | ||
225 | sscanf(str, "%d.%d",&major, &minor); | 131 | sscanf(str, "%hd.%hd",&major, &minor); |
226 | 132 | ||
227 | if (major <= 0 || minor < 0){ | 133 | if (major <= 0 || minor < 0){ |
228 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); | 134 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); |
229 | return stat; | 135 | return stat; |
230 | } | 136 | } |
231 | 137 | ||
232 | stat.code = icalenum_num_to_reqstat(major, minor); | 138 | stat.code = icalenum_num_to_reqstat(major, minor); |
233 | 139 | ||
234 | if (stat.code == ICAL_UNKNOWN_STATUS){ | 140 | if (stat.code == ICAL_UNKNOWN_STATUS){ |
235 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); | 141 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); |
236 | return stat; | 142 | return stat; |
237 | } | 143 | } |
238 | 144 | ||
239 | 145 | ||
240 | p1 = strchr(str,';'); | 146 | p1 = strchr(str,';'); |
241 | 147 | ||