Diffstat (limited to 'libical/src/libical/icalparameter.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libical/src/libical/icalparameter.c | 113 |
1 files changed, 58 insertions, 55 deletions
diff --git a/libical/src/libical/icalparameter.c b/libical/src/libical/icalparameter.c index 156ecdb..759306f 100644 --- a/libical/src/libical/icalparameter.c +++ b/libical/src/libical/icalparameter.c | |||
@@ -65,79 +65,74 @@ struct icalparameter_impl* icalparameter_new_impl(icalparameter_kind kind) | |||
65 | v->parent = 0; | 65 | v->parent = 0; |
66 | v->data = 0; | 66 | v->data = 0; |
67 | 67 | ||
68 | return v; | 68 | return v; |
69 | } | 69 | } |
70 | 70 | ||
71 | icalparameter* | 71 | icalparameter* |
72 | icalparameter_new (icalparameter_kind kind) | 72 | icalparameter_new (icalparameter_kind kind) |
73 | { | 73 | { |
74 | struct icalparameter_impl* v = icalparameter_new_impl(kind); | 74 | struct icalparameter_impl* v = icalparameter_new_impl(kind); |
75 | 75 | ||
76 | return (icalparameter*) v; | 76 | return (icalparameter*) v; |
77 | 77 | ||
78 | } | 78 | } |
79 | 79 | ||
80 | void | 80 | void |
81 | icalparameter_free (icalparameter* parameter) | 81 | icalparameter_free (icalparameter* param) |
82 | { | 82 | { |
83 | struct icalparameter_impl * impl; | ||
84 | |||
85 | impl = (struct icalparameter_impl*)parameter; | ||
86 | 83 | ||
87 | /* HACK. This always triggers, even when parameter is non-zero | 84 | /* HACK. This always triggers, even when parameter is non-zero |
88 | icalerror_check_arg_rv((parameter==0),"parameter");*/ | 85 | icalerror_check_arg_rv((parameter==0),"parameter");*/ |
89 | 86 | ||
90 | 87 | ||
91 | #ifdef ICAL_FREE_ON_LIST_IS_ERROR | 88 | #ifdef ICAL_FREE_ON_LIST_IS_ERROR |
92 | icalerror_assert( (impl->parent ==0),"Tried to free a parameter that is still attached to a component. "); | 89 | icalerror_assert( (param->parent ==0),"Tried to free a parameter that is still attached to a component. "); |
93 | 90 | ||
94 | #else | 91 | #else |
95 | if(impl->parent !=0){ | 92 | if(param->parent !=0){ |
96 | return; | 93 | return; |
97 | } | 94 | } |
98 | #endif | 95 | #endif |
99 | 96 | ||
100 | 97 | ||
101 | if (impl->string != 0){ | 98 | if (param->string != 0){ |
102 | free ((void*)impl->string); | 99 | free ((void*)param->string); |
103 | } | 100 | } |
104 | 101 | ||
105 | if (impl->x_name != 0){ | 102 | if (param->x_name != 0){ |
106 | free ((void*)impl->x_name); | 103 | free ((void*)param->x_name); |
107 | } | 104 | } |
108 | 105 | ||
109 | memset(impl,0,sizeof(impl)); | 106 | memset(param,0,sizeof(param)); |
110 | 107 | ||
111 | impl->parent = 0; | 108 | param->parent = 0; |
112 | impl->id[0] = 'X'; | 109 | param->id[0] = 'X'; |
113 | free(impl); | 110 | free(param); |
114 | } | 111 | } |
115 | 112 | ||
116 | 113 | ||
117 | 114 | ||
118 | icalparameter* | 115 | icalparameter* |
119 | icalparameter_new_clone(icalparameter* param) | 116 | icalparameter_new_clone(icalparameter* old) |
120 | { | 117 | { |
121 | struct icalparameter_impl *old; | ||
122 | struct icalparameter_impl *new; | 118 | struct icalparameter_impl *new; |
123 | 119 | ||
124 | old = (struct icalparameter_impl *)param; | ||
125 | new = icalparameter_new_impl(old->kind); | 120 | new = icalparameter_new_impl(old->kind); |
126 | 121 | ||
127 | icalerror_check_arg_rz((param!=0),"param"); | 122 | icalerror_check_arg_rz((old!=0),"param"); |
128 | 123 | ||
129 | if (new == 0){ | 124 | if (new == 0){ |
130 | return 0; | 125 | return 0; |
131 | } | 126 | } |
132 | 127 | ||
133 | memcpy(new,old,sizeof(struct icalparameter_impl)); | 128 | memcpy(new,old,sizeof(struct icalparameter_impl)); |
134 | 129 | ||
135 | if (old->string != 0){ | 130 | if (old->string != 0){ |
136 | new->string = icalmemory_strdup(old->string); | 131 | new->string = icalmemory_strdup(old->string); |
137 | if (new->string == 0){ | 132 | if (new->string == 0){ |
138 | icalparameter_free(new); | 133 | icalparameter_free(new); |
139 | return 0; | 134 | return 0; |
140 | } | 135 | } |
141 | } | 136 | } |
142 | 137 | ||
143 | if (old->x_name != 0){ | 138 | if (old->x_name != 0){ |
@@ -184,199 +179,207 @@ icalparameter* icalparameter_new_from_string(const char *str) | |||
184 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); | 179 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); |
185 | return 0; | 180 | return 0; |
186 | } | 181 | } |
187 | 182 | ||
188 | param = icalparameter_new_from_value_string(kind,eq); | 183 | param = icalparameter_new_from_value_string(kind,eq); |
189 | 184 | ||
190 | if(kind == ICAL_X_PARAMETER){ | 185 | if(kind == ICAL_X_PARAMETER){ |
191 | icalparameter_set_xname(param,cpy); | 186 | icalparameter_set_xname(param,cpy); |
192 | } | 187 | } |
193 | 188 | ||
194 | free(cpy); | 189 | free(cpy); |
195 | 190 | ||
196 | return param; | 191 | return param; |
197 | 192 | ||
198 | } | 193 | } |
199 | 194 | ||
195 | /** | ||
196 | * Return a string representation of the parameter according to RFC2445. | ||
197 | * | ||
198 | * param= param-name "=" param-value | ||
199 | * param-name= iana-token / x-token | ||
200 | * param-value= paramtext /quoted-string | ||
201 | * paramtext= *SAFE-SHARE | ||
202 | * quoted-string= DQUOTE *QSAFE-CHARE DQUOTE | ||
203 | * QSAFE-CHAR= any character except CTLs and DQUOTE | ||
204 | * SAFE-CHAR= any character except CTLs, DQUOTE. ";", ":", "," | ||
205 | */ | ||
200 | char* | 206 | char* |
201 | icalparameter_as_ical_string (icalparameter* parameter) | 207 | icalparameter_as_ical_string (icalparameter* param) |
202 | { | 208 | { |
203 | struct icalparameter_impl* impl; | ||
204 | size_t buf_size = 1024; | 209 | size_t buf_size = 1024; |
205 | char* buf; | 210 | char* buf; |
206 | char* buf_ptr; | 211 | char* buf_ptr; |
207 | char *out_buf; | 212 | char *out_buf; |
208 | const char *kind_string; | 213 | const char *kind_string; |
209 | 214 | ||
210 | icalerror_check_arg_rz( (parameter!=0), "parameter"); | 215 | icalerror_check_arg_rz( (param!=0), "parameter"); |
211 | 216 | ||
212 | /* Create new buffer that we can append names, parameters and a | 217 | /* Create new buffer that we can append names, parameters and a |
213 | value to, and reallocate as needed. Later, this buffer will be | 218 | value to, and reallocate as needed. Later, this buffer will be |
214 | copied to a icalmemory_tmp_buffer, which is managed internally | 219 | copied to a icalmemory_tmp_buffer, which is managed internally |
215 | by libical, so it can be given to the caller without fear of | 220 | by libical, so it can be given to the caller without fear of |
216 | the caller forgetting to free it */ | 221 | the caller forgetting to free it */ |
217 | 222 | ||
218 | buf = icalmemory_new_buffer(buf_size); | 223 | buf = icalmemory_new_buffer(buf_size); |
219 | buf_ptr = buf; | 224 | buf_ptr = buf; |
220 | impl = (struct icalparameter_impl*)parameter; | ||
221 | 225 | ||
222 | if(impl->kind == ICAL_X_PARAMETER) { | 226 | if(param->kind == ICAL_X_PARAMETER) { |
223 | 227 | ||
224 | icalmemory_append_string(&buf, &buf_ptr, &buf_size, | 228 | icalmemory_append_string(&buf, &buf_ptr, &buf_size, |
225 | icalparameter_get_xname(impl)); | 229 | icalparameter_get_xname(param)); |
226 | 230 | ||
227 | } else { | 231 | } else { |
228 | 232 | ||
229 | kind_string = icalparameter_kind_to_string(impl->kind); | 233 | kind_string = icalparameter_kind_to_string(param->kind); |
230 | 234 | ||
231 | if (impl->kind == ICAL_NO_PARAMETER || | 235 | if (param->kind == ICAL_NO_PARAMETER || |
232 | impl->kind == ICAL_ANY_PARAMETER || | 236 | param->kind == ICAL_ANY_PARAMETER || |
233 | kind_string == 0) | 237 | kind_string == 0) |
234 | { | 238 | { |
235 | icalerror_set_errno(ICAL_BADARG_ERROR); | 239 | icalerror_set_errno(ICAL_BADARG_ERROR); |
236 | return 0; | 240 | return 0; |
237 | } | 241 | } |
238 | 242 | ||
239 | 243 | ||
240 | /* Put the parameter name into the string */ | 244 | /* Put the parameter name into the string */ |
241 | icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string); | 245 | icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string); |
242 | 246 | ||
243 | } | 247 | } |
244 | 248 | ||
245 | icalmemory_append_string(&buf, &buf_ptr, &buf_size, "="); | 249 | icalmemory_append_string(&buf, &buf_ptr, &buf_size, "="); |
246 | 250 | ||
247 | if(impl->string !=0){ | 251 | if(param->string !=0){ |
248 | icalmemory_append_string(&buf, &buf_ptr, &buf_size, impl->string); | 252 | int qm = 0; |
249 | } else if (impl->data != 0){ | 253 | |
250 | const char* str = icalparameter_enum_to_string(impl->data); | 254 | /* Encapsulate the property in quotes if necessary */ |
255 | if (strpbrk(param->string, ";:,") != 0) { | ||
256 | icalmemory_append_char (&buf, &buf_ptr, &buf_size, '"'); | ||
257 | qm = 1; | ||
258 | } | ||
259 | icalmemory_append_string(&buf, &buf_ptr, &buf_size, param->string); | ||
260 | if (qm == 1) { | ||
261 | icalmemory_append_char (&buf, &buf_ptr, &buf_size, '"'); | ||
262 | } | ||
263 | } else if (param->data != 0){ | ||
264 | const char* str = icalparameter_enum_to_string(param->data); | ||
251 | icalmemory_append_string(&buf, &buf_ptr, &buf_size, str); | 265 | icalmemory_append_string(&buf, &buf_ptr, &buf_size, str); |
252 | } else { | 266 | } else { |
253 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); | 267 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); |
254 | return 0; | 268 | return 0; |
255 | } | 269 | } |
256 | 270 | ||
257 | /* Now, copy the buffer to a tmp_buffer, which is safe to give to | 271 | /* Now, copy the buffer to a tmp_buffer, which is safe to give to |
258 | the caller without worring about de-allocating it. */ | 272 | the caller without worring about de-allocating it. */ |
259 | 273 | ||
260 | out_buf = icalmemory_tmp_buffer(strlen(buf)); | 274 | out_buf = icalmemory_tmp_buffer(strlen(buf)); |
261 | strcpy(out_buf, buf); | 275 | strcpy(out_buf, buf); |
262 | 276 | ||
263 | icalmemory_free_buffer(buf); | 277 | icalmemory_free_buffer(buf); |
264 | 278 | ||
265 | return out_buf; | 279 | return out_buf; |
266 | 280 | ||
267 | } | 281 | } |
268 | 282 | ||
269 | 283 | ||
270 | int | 284 | int |
271 | icalparameter_is_valid (icalparameter* parameter); | 285 | icalparameter_is_valid (icalparameter* parameter); |
272 | 286 | ||
273 | 287 | ||
274 | icalparameter_kind | 288 | icalparameter_kind |
275 | icalparameter_isa (icalparameter* parameter) | 289 | icalparameter_isa (icalparameter* parameter) |
276 | { | 290 | { |
277 | if(parameter == 0){ | 291 | if(parameter == 0){ |
278 | return ICAL_NO_PARAMETER; | 292 | return ICAL_NO_PARAMETER; |
279 | } | 293 | } |
280 | 294 | ||
281 | return ((struct icalparameter_impl *)parameter)->kind; | 295 | return parameter->kind; |
282 | } | 296 | } |
283 | 297 | ||
284 | 298 | ||
285 | int | 299 | int |
286 | icalparameter_isa_parameter (void* parameter) | 300 | icalparameter_isa_parameter (void* parameter) |
287 | { | 301 | { |
288 | struct icalparameter_impl *impl = (struct icalparameter_impl *)parameter; | 302 | struct icalparameter_impl *impl = (struct icalparameter_impl *)parameter; |
289 | 303 | ||
290 | if (parameter == 0){ | 304 | if (parameter == 0){ |
291 | return 0; | 305 | return 0; |
292 | } | 306 | } |
293 | 307 | ||
294 | if (strcmp(impl->id,"para") == 0) { | 308 | if (strcmp(impl->id,"para") == 0) { |
295 | return 1; | 309 | return 1; |
296 | } else { | 310 | } else { |
297 | return 0; | 311 | return 0; |
298 | } | 312 | } |
299 | } | 313 | } |
300 | 314 | ||
301 | 315 | ||
302 | void | 316 | void |
303 | icalparameter_set_xname (icalparameter* param, const char* v) | 317 | icalparameter_set_xname (icalparameter* param, const char* v) |
304 | { | 318 | { |
305 | struct icalparameter_impl *impl = (struct icalparameter_impl*)param; | ||
306 | icalerror_check_arg_rv( (param!=0),"param"); | 319 | icalerror_check_arg_rv( (param!=0),"param"); |
307 | icalerror_check_arg_rv( (v!=0),"v"); | 320 | icalerror_check_arg_rv( (v!=0),"v"); |
308 | 321 | ||
309 | if (impl->x_name != 0){ | 322 | if (param->x_name != 0){ |
310 | free((void*)impl->x_name); | 323 | free((void*)param->x_name); |
311 | } | 324 | } |
312 | 325 | ||
313 | impl->x_name = icalmemory_strdup(v); | 326 | param->x_name = icalmemory_strdup(v); |
314 | 327 | ||
315 | if (impl->x_name == 0){ | 328 | if (param->x_name == 0){ |
316 | errno = ENOMEM; | 329 | errno = ENOMEM; |
317 | } | 330 | } |
318 | 331 | ||
319 | } | 332 | } |
320 | 333 | ||
321 | const char* | 334 | const char* |
322 | icalparameter_get_xname (icalparameter* param) | 335 | icalparameter_get_xname (icalparameter* param) |
323 | { | 336 | { |
324 | struct icalparameter_impl *impl = (struct icalparameter_impl*)param; | ||
325 | icalerror_check_arg_rz( (param!=0),"param"); | 337 | icalerror_check_arg_rz( (param!=0),"param"); |
326 | 338 | ||
327 | return impl->x_name; | 339 | return param->x_name; |
328 | } | 340 | } |
329 | 341 | ||
330 | void | 342 | void |
331 | icalparameter_set_xvalue (icalparameter* param, const char* v) | 343 | icalparameter_set_xvalue (icalparameter* param, const char* v) |
332 | { | 344 | { |
333 | struct icalparameter_impl *impl = (struct icalparameter_impl*)param; | ||
334 | |||
335 | icalerror_check_arg_rv( (param!=0),"param"); | 345 | icalerror_check_arg_rv( (param!=0),"param"); |
336 | icalerror_check_arg_rv( (v!=0),"v"); | 346 | icalerror_check_arg_rv( (v!=0),"v"); |
337 | 347 | ||
338 | if (impl->string != 0){ | 348 | if (param->string != 0){ |
339 | free((void*)impl->string); | 349 | free((void*)param->string); |
340 | } | 350 | } |
341 | 351 | ||
342 | impl->string = icalmemory_strdup(v); | 352 | param->string = icalmemory_strdup(v); |
343 | 353 | ||
344 | if (impl->string == 0){ | 354 | if (param->string == 0){ |
345 | errno = ENOMEM; | 355 | errno = ENOMEM; |
346 | } | 356 | } |
347 | 357 | ||
348 | } | 358 | } |
349 | 359 | ||
350 | const char* | 360 | const char* |
351 | icalparameter_get_xvalue (icalparameter* param) | 361 | icalparameter_get_xvalue (icalparameter* param) |
352 | { | 362 | { |
353 | struct icalparameter_impl *impl = (struct icalparameter_impl*)param; | ||
354 | |||
355 | icalerror_check_arg_rz( (param!=0),"param"); | 363 | icalerror_check_arg_rz( (param!=0),"param"); |
356 | 364 | ||
357 | return impl->string; | 365 | return param->string; |
358 | |||
359 | } | 366 | } |
360 | 367 | ||
361 | void icalparameter_set_parent(icalparameter* param, | 368 | void icalparameter_set_parent(icalparameter* param, |
362 | icalproperty* property) | 369 | icalproperty* property) |
363 | { | 370 | { |
364 | struct icalparameter_impl *impl = (struct icalparameter_impl*)param; | ||
365 | |||
366 | icalerror_check_arg_rv( (param!=0),"param"); | 371 | icalerror_check_arg_rv( (param!=0),"param"); |
367 | 372 | ||
368 | impl->parent = property; | 373 | param->parent = property; |
369 | } | 374 | } |
370 | 375 | ||
371 | icalproperty* icalparameter_get_parent(icalparameter* param) | 376 | icalproperty* icalparameter_get_parent(icalparameter* param) |
372 | { | 377 | { |
373 | struct icalparameter_impl *impl = (struct icalparameter_impl*)param; | ||
374 | |||
375 | icalerror_check_arg_rz( (param!=0),"param"); | 378 | icalerror_check_arg_rz( (param!=0),"param"); |
376 | 379 | ||
377 | return impl->parent; | 380 | return param->parent; |
378 | } | 381 | } |
379 | 382 | ||
380 | 383 | ||
381 | /* Everything below this line is machine generated. Do not edit. */ | 384 | /* Everything below this line is machine generated. Do not edit. */ |
382 | /* ALTREP */ | 385 | /* ALTREP */ |