summaryrefslogtreecommitdiffabout
path: root/libical/src/libicalss/icalclassify.c
Unidiff
Diffstat (limited to 'libical/src/libicalss/icalclassify.c') (more/less context) (ignore whitespace changes)
-rw-r--r--libical/src/libicalss/icalclassify.c132
1 files changed, 47 insertions, 85 deletions
diff --git a/libical/src/libicalss/icalclassify.c b/libical/src/libicalss/icalclassify.c
index c029309..61ddbd3 100644
--- a/libical/src/libicalss/icalclassify.c
+++ b/libical/src/libicalss/icalclassify.c
@@ -1,80 +1,80 @@
1/* -*- Mode: C -*- 1/* -*- Mode: C -*-
2 ====================================================================== 2 ======================================================================
3 FILE: icalclassify.c 3 FILE: icalclassify.c
4 CREATOR: ebusboom 23 aug 2000 4 CREATOR: ebusboom 23 aug 2000
5 5
6 $Id$ 6 $Id$
7 $Locker$ 7 $Locker$
8 8
9 (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org 9 (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
10 10
11 This program is free software; you can redistribute it and/or modify 11 This program is free software; you can redistribute it and/or modify
12 it under the terms of either: 12 it under the terms of either:
13 13
14 The LGPL as published by the Free Software Foundation, version 14 The LGPL as published by the Free Software Foundation, version
15 2.1, available at: http://www.fsf.org/copyleft/lesser.html 15 2.1, available at: http://www.fsf.org/copyleft/lesser.html
16 16
17 Or: 17 Or:
18 18
19 The Mozilla Public License Version 1.0. You may obtain a copy of 19 The Mozilla Public License Version 1.0. You may obtain a copy of
20 the License at http://www.mozilla.org/MPL/ 20 the License at http://www.mozilla.org/MPL/
21 21
22 22
23 ======================================================================*/ 23 ======================================================================*/
24 24
25#ifdef HAVE_CONFIG_H 25#ifdef HAVE_CONFIG_H
26#include "config.h" 26#include "config.h"
27#endif 27#endif
28 28
29#include "icalerror.h"
30#include "ical.h" 29#include "ical.h"
31#include "icalclassify.h" 30#include "icalclassify.h"
32#include "icalmemory.h" 31#include "icalmemory.h"
32
33#include <ctype.h> /* For tolower() */ 33#include <ctype.h> /* For tolower() */
34#include <string.h> /* for index() */ 34#include <string.h> /* for index() */
35#include <stdlib.h> /* for malloc and free */ 35#include <stdlib.h> /* for malloc and free */
36 36
37 37
38 38
39struct icalclassify_parts { 39struct icalclassify_parts {
40 icalcomponent *c; 40 icalcomponent *c;
41 icalcomponent_kind inner_kind; 41 icalcomponent_kind inner_kind;
42 icalproperty_method method; 42 icalproperty_method method;
43 char* organizer; 43 char* organizer;
44 icalparameter_partstat reply_partstat; 44 icalparameter_partstat reply_partstat;
45 char* reply_attendee; 45 char* reply_attendee;
46 char* uid; 46 char* uid;
47 int sequence; 47 int sequence;
48 struct icaltimetype dtstamp; 48 struct icaltimetype dtstamp;
49 struct icaltimetype recurrence_id; 49 struct icaltimetype recurrence_id;
50}; 50};
51 51
52 52
53char* icalclassify_lowercase(const char* str) 53char* icalclassify_lowercase(const char* str)
54{ 54{
55 char* p = 0; 55 char* p = 0;
56 char* new = icalmemory_strdup(str); 56 char* new = icalmemory_strdup(str);
57 57
58 if(str ==0){ 58 if(str ==0){
59 return 0; 59 return 0;
60 } 60 }
61 61
62 for(p = new; *p!=0; p++){ 62 for(p = new; *p!=0; p++){
63 *p = tolower(*p); 63 *p = tolower(*p);
64 } 64 }
65 65
66 return new; 66 return new;
67} 67}
68 68
69/* Return a set of components that intersect in time with comp. For 69/* Return a set of components that intersect in time with comp. For
70component X and Y to intersect: 70component X and Y to intersect:
71 X.DTSTART < Y.DTEND && X.DTEND > Y.DTSTART 71 X.DTSTART < Y.DTEND && X.DTEND > Y.DTSTART
72*/ 72*/
73 73
74 74
75icalcomponent* icalclassify_find_overlaps(icalset* set, icalcomponent* comp) 75icalcomponent* icalclassify_find_overlaps(icalset* set, icalcomponent* comp)
76{ 76{
77 icalcomponent *return_set; 77 icalcomponent *return_set;
78 icalcomponent *c; 78 icalcomponent *c;
79 struct icaltime_span span,compspan; 79 struct icaltime_span span,compspan;
80 80
@@ -101,111 +101,115 @@ icalcomponent* icalclassify_find_overlaps(icalset* set, icalcomponent* comp)
101 } 101 }
102 102
103 if (compspan.start < span.end && 103 if (compspan.start < span.end &&
104 compspan.end > span.start){ 104 compspan.end > span.start){
105 105
106 icalcomponent *clone = icalcomponent_new_clone(c); 106 icalcomponent *clone = icalcomponent_new_clone(c);
107 107
108 icalcomponent_add_component(return_set,clone); 108 icalcomponent_add_component(return_set,clone);
109 } 109 }
110 } 110 }
111 111
112 if(icalcomponent_count_components(return_set,ICAL_ANY_COMPONENT) !=0){ 112 if(icalcomponent_count_components(return_set,ICAL_ANY_COMPONENT) !=0){
113 return return_set; 113 return return_set;
114 } else { 114 } else {
115 icalcomponent_free(return_set); 115 icalcomponent_free(return_set);
116 return 0; 116 return 0;
117 } 117 }
118} 118}
119 119
120 120
121 121
122icalproperty* icalclassify_find_attendee(icalcomponent *c, 122icalproperty* icalclassify_find_attendee(icalcomponent *c,
123 const char* attendee) 123 const char* attendee)
124{ 124{
125 icalproperty *p; 125 icalproperty *p;
126 icalcomponent* inner; 126 icalcomponent* inner;
127 char* lattendee; 127 char* lattendee;
128 char* upn; 128 char* upn;
129 129
130 if(attendee == 0){ 130 if(attendee == 0){
131 return 0; 131 return 0;
132 } 132 }
133 133
134 lattendee = icalclassify_lowercase(attendee); 134 lattendee = icalclassify_lowercase(attendee);
135 upn = strchr(lattendee,':'); 135 upn = strchr(lattendee,':');
136 136
137 if (upn== 0){ 137 if (upn== 0){
138 upn = lattendee; 138 upn = lattendee;
139 } else { 139 } else {
140 upn++; /* skip the ";"*/ 140 upn++; /* skip the ";"*/
141 } 141 }
142 142
143 inner = icalcomponent_get_first_real_component(c); 143 inner = icalcomponent_get_first_real_component(c);
144 144
145 for(p = icalcomponent_get_first_property(inner,ICAL_ATTENDEE_PROPERTY); 145 for(p = icalcomponent_get_first_property(inner,ICAL_ATTENDEE_PROPERTY);
146 p != 0; 146 p != 0;
147 p = icalcomponent_get_next_property(inner,ICAL_ATTENDEE_PROPERTY)) 147 p = icalcomponent_get_next_property(inner,ICAL_ATTENDEE_PROPERTY))
148 { 148 {
149 const char* this_attendee 149 char* this_attendee
150 = icalclassify_lowercase(icalproperty_get_attendee(p)); 150 = icalclassify_lowercase(icalproperty_get_attendee(p));
151 char* this_upn = strchr(this_attendee,':'); 151 char* this_upn = strchr(this_attendee,':');
152 152
153 if(this_upn == 0){ 153 if(this_upn == 0){
154 continue; 154 continue;
155 } else { 155 } else {
156 this_upn++; 156 this_upn++;
157 } 157 }
158 158
159 if(strcmp(this_upn,upn)==0){ 159 if(strcmp(this_upn,upn)==0){
160 free(lattendee);
161 free(this_attendee);
160 return p; 162 return p;
161 } 163 }
162 164
165 free(this_attendee);
163 } 166 }
167 free(lattendee);
164 168
165 return 0; 169 return 0;
166 170
167} 171}
168 172
169void icalssutil_free_parts(struct icalclassify_parts *parts) 173void icalssutil_free_parts(struct icalclassify_parts *parts)
170{ 174{
171 if(parts == 0){ 175 if(parts == 0){
172 return; 176 return;
173 } 177 }
174 178
175 if(parts->organizer != 0){ 179 if(parts->organizer != 0){
176 free(parts->organizer); 180 free(parts->organizer);
177 } 181 }
178 182
179 if(parts->uid != 0){ 183 if(parts->uid != 0){
180 free(parts->uid); 184 free(parts->uid);
181 } 185 }
182 186
183 if(parts->reply_attendee){ 187 if(parts->reply_attendee){
184 free(parts->reply_attendee); 188 free(parts->reply_attendee);
185 } 189 }
186} 190}
187 191
188void icalssutil_get_parts(icalcomponent* c, 192void icalssutil_get_parts(icalcomponent* c,
189 struct icalclassify_parts* parts) 193 struct icalclassify_parts* parts)
190{ 194{
191 icalproperty *p; 195 icalproperty *p;
192 icalcomponent *inner; 196 icalcomponent *inner;
193 197
194 memset(parts,0,sizeof(struct icalclassify_parts)); 198 memset(parts,0,sizeof(struct icalclassify_parts));
195 199
196 parts->method = ICAL_METHOD_NONE; 200 parts->method = ICAL_METHOD_NONE;
197 parts->sequence = 0; 201 parts->sequence = 0;
198 parts->reply_partstat = ICAL_PARTSTAT_NONE; 202 parts->reply_partstat = ICAL_PARTSTAT_NONE;
199 203
200 if(c == 0){ 204 if(c == 0){
201 return; 205 return;
202 } 206 }
203 207
204 parts->c = c; 208 parts->c = c;
205 209
206 p = icalcomponent_get_first_property(c,ICAL_METHOD_PROPERTY); 210 p = icalcomponent_get_first_property(c,ICAL_METHOD_PROPERTY);
207 if(p!=0){ 211 if(p!=0){
208 parts->method = icalproperty_get_method(p); 212 parts->method = icalproperty_get_method(p);
209 } 213 }
210 214
211 inner = icalcomponent_get_first_real_component(c); 215 inner = icalcomponent_get_first_real_component(c);
@@ -239,97 +243,97 @@ void icalssutil_get_parts(icalcomponent* c,
239 243
240 if(parts->method==ICAL_METHOD_REPLY){ 244 if(parts->method==ICAL_METHOD_REPLY){
241 icalparameter *param; 245 icalparameter *param;
242 p = icalcomponent_get_first_property(inner,ICAL_ATTENDEE_PROPERTY); 246 p = icalcomponent_get_first_property(inner,ICAL_ATTENDEE_PROPERTY);
243 247
244 if(p!=0){ 248 if(p!=0){
245 249
246 param = icalproperty_get_first_parameter(p,ICAL_PARTSTAT_PARAMETER); 250 param = icalproperty_get_first_parameter(p,ICAL_PARTSTAT_PARAMETER);
247 251
248 if(param != 0){ 252 if(param != 0){
249 parts->reply_partstat = 253 parts->reply_partstat =
250 icalparameter_get_partstat(param); 254 icalparameter_get_partstat(param);
251 } 255 }
252 256
253 parts->reply_attendee = strdup(icalproperty_get_attendee(p)); 257 parts->reply_attendee = strdup(icalproperty_get_attendee(p));
254 } 258 }
255 259
256 } 260 }
257 261
258 262
259} 263}
260 264
261 265
262int icalssutil_is_rescheduled(icalcomponent* a,icalcomponent* b) 266int icalssutil_is_rescheduled(icalcomponent* a,icalcomponent* b)
263{ 267{
264 icalproperty *p1,*p2; 268 icalproperty *p1,*p2;
265 icalcomponent *i1,*i2; 269 icalcomponent *i1,*i2;
266 int i; 270 int i;
267 271
268 icalproperty_kind kind_array[] = { 272 icalproperty_kind kind_array[] = {
269 ICAL_DTSTART_PROPERTY, 273 ICAL_DTSTART_PROPERTY,
270 ICAL_DTEND_PROPERTY, 274 ICAL_DTEND_PROPERTY,
271 ICAL_DURATION_PROPERTY, 275 ICAL_DURATION_PROPERTY,
272 ICAL_DUE_PROPERTY, 276 ICAL_DUE_PROPERTY,
273 ICAL_RRULE_PROPERTY, 277 ICAL_RRULE_PROPERTY,
274 ICAL_RDATE_PROPERTY, 278 ICAL_RDATE_PROPERTY,
275 ICAL_EXRULE_PROPERTY, 279 ICAL_EXRULE_PROPERTY,
276 ICAL_EXDATE_PROPERTY, 280 ICAL_EXDATE_PROPERTY,
277 ICAL_NO_PROPERTY 281 ICAL_NO_PROPERTY
278 }; 282 };
279 283
280 i1 = icalcomponent_get_first_real_component(a); 284 i1 = icalcomponent_get_first_real_component(a);
281 i2 = icalcomponent_get_first_real_component(b); 285 i2 = icalcomponent_get_first_real_component(b);
282 286
283 for(i =0; kind_array[i] != ICAL_NO_PROPERTY; i++){ 287 for(i =0; kind_array[i] != ICAL_NO_PROPERTY; i++){
284 p1 = icalcomponent_get_first_property(i1,kind_array[i]); 288 p1 = icalcomponent_get_first_property(i1,kind_array[i]);
285 p2 = icalcomponent_get_first_property(i2,kind_array[i]); 289 p2 = icalcomponent_get_first_property(i2,kind_array[i]);
286 290
287 if( (p1!=0)^(p1!=0) ){ 291 if( (p1!=0)^(p2!=0) ){
288 /* Return true if the property exists in one component and not 292 /* Return true if the property exists in one component and not
289 the other */ 293 the other */
290 return 1; 294 return 1;
291 } 295 }
292 296
293 if(p1 && strcmp(icalproperty_as_ical_string(p1), 297 if(p1 && strcmp(icalproperty_as_ical_string(p1),
294 icalproperty_as_ical_string(p2)) != 0){ 298 icalproperty_as_ical_string(p2)) != 0){
295 return 1; 299 return 1;
296 } 300 }
297 } 301 }
298 302
299 return 0; 303 return 0;
300 304
301} 305}
302 306
303#define icalclassify_pre \ 307#define icalclassify_pre \
304 int rtrn =0; 308 int rtrn =0;
305 309
306#define icalclassify_post \ 310#define icalclassify_post \
307 return rtrn; 311 return rtrn;
308 312
309 313
310int icalclassify_publish_new(struct icalclassify_parts *comp, 314int icalclassify_publish_new(struct icalclassify_parts *comp,
311 struct icalclassify_parts *match, 315 struct icalclassify_parts *match,
312 const char* user) 316 const char* user)
313{ 317{
314 icalclassify_pre; 318 icalclassify_pre;
315 319
316 if(comp->method == ICAL_METHOD_PUBLISH && 320 if(comp->method == ICAL_METHOD_PUBLISH &&
317 match == 0 && comp->inner_kind != ICAL_VFREEBUSY_COMPONENT){ 321 match == 0 && comp->inner_kind != ICAL_VFREEBUSY_COMPONENT){
318 rtrn = 1; 322 rtrn = 1;
319 } 323 }
320 324
321 icalclassify_post; 325 icalclassify_post;
322 326
323} 327}
324 328
325int icalclassify_publish_update(struct icalclassify_parts *comp, 329int icalclassify_publish_update(struct icalclassify_parts *comp,
326 struct icalclassify_parts *match, 330 struct icalclassify_parts *match,
327 const char* user) 331 const char* user)
328{ 332{
329 icalclassify_pre; 333 icalclassify_pre;
330 334
331 if(comp->method == ICAL_METHOD_PUBLISH && 335 if(comp->method == ICAL_METHOD_PUBLISH &&
332 match !=0 && comp->inner_kind != ICAL_VFREEBUSY_COMPONENT){ 336 match !=0 && comp->inner_kind != ICAL_VFREEBUSY_COMPONENT){
333 rtrn = 1; 337 rtrn = 1;
334 } 338 }
335 339
@@ -501,292 +505,250 @@ int icalclassify_reply_decline(
501 icalclassify_pre; 505 icalclassify_pre;
502 506
503 attendee = icalclassify_find_attendee(match->c,comp->reply_attendee); 507 attendee = icalclassify_find_attendee(match->c,comp->reply_attendee);
504 508
505 509
506 if( attendee != 0 && 510 if( attendee != 0 &&
507 comp->reply_partstat == ICAL_PARTSTAT_DECLINED){ 511 comp->reply_partstat == ICAL_PARTSTAT_DECLINED){
508 rtrn = 1; 512 rtrn = 1;
509 } 513 }
510 icalclassify_post 514 icalclassify_post
511} 515}
512int icalclassify_reply_delegate( 516int icalclassify_reply_delegate(
513 struct icalclassify_parts *comp, 517 struct icalclassify_parts *comp,
514 struct icalclassify_parts *match, 518 struct icalclassify_parts *match,
515 const char* user) 519 const char* user)
516{ 520{
517 icalproperty* attendee; 521 icalproperty* attendee;
518 icalclassify_pre; 522 icalclassify_pre;
519 523
520 attendee = icalclassify_find_attendee(match->c,comp->reply_attendee); 524 attendee = icalclassify_find_attendee(match->c,comp->reply_attendee);
521 525
522 if( attendee != 0 && 526 if( attendee != 0 &&
523 comp->reply_partstat == ICAL_PARTSTAT_DELEGATED){ 527 comp->reply_partstat == ICAL_PARTSTAT_DELEGATED){
524 rtrn = 1; 528 rtrn = 1;
525 } 529 }
526 icalclassify_post 530 icalclassify_post
527} 531}
528int icalclassify_reply_crasher_accept( 532int icalclassify_reply_crasher_accept(
529 struct icalclassify_parts *comp, 533 struct icalclassify_parts *comp,
530 struct icalclassify_parts *match, 534 struct icalclassify_parts *match,
531 const char* user) 535 const char* user)
532{ 536{
533 icalproperty* attendee; 537 icalproperty* attendee;
534 icalclassify_pre; 538 icalclassify_pre;
535 539
536 attendee= icalclassify_find_attendee(match->c,comp->reply_attendee); 540 attendee= icalclassify_find_attendee(match->c,comp->reply_attendee);
537 541
538 if(attendee == 0 && 542 if(attendee == 0 &&
539 comp->reply_partstat == ICAL_PARTSTAT_ACCEPTED){ 543 comp->reply_partstat == ICAL_PARTSTAT_ACCEPTED){
540 rtrn = 1; 544 rtrn = 1;
541 } 545 }
542 icalclassify_post 546 icalclassify_post
543} 547}
544int icalclassify_reply_crasher_decline( 548int icalclassify_reply_crasher_decline(
545 struct icalclassify_parts *comp, 549 struct icalclassify_parts *comp,
546 struct icalclassify_parts *match, 550 struct icalclassify_parts *match,
547 const char* user) 551 const char* user)
548{ 552{
549 icalparameter_partstat partstat;
550 icalproperty* attendee; 553 icalproperty* attendee;
551 icalclassify_pre; 554 icalclassify_pre;
552 555
553 556
554 attendee = icalclassify_find_attendee(match->c,comp->reply_attendee); 557 attendee = icalclassify_find_attendee(match->c,comp->reply_attendee);
555 558
556 if(attendee == 0 && 559 if(attendee == 0 &&
557 comp->reply_partstat == ICAL_PARTSTAT_DECLINED){ 560 comp->reply_partstat == ICAL_PARTSTAT_DECLINED){
558 rtrn = 1; 561 rtrn = 1;
559 } 562 }
560 icalclassify_post 563 icalclassify_post
561} 564}
562int icalclassify_add_instance( 565int icalclassify_add_instance(
563 struct icalclassify_parts *comp, 566 struct icalclassify_parts *comp,
564 struct icalclassify_parts *match, 567 struct icalclassify_parts *match,
565 const char* user) 568 const char* user)
566{ 569{
567 icalclassify_pre 570 icalclassify_pre
568 if(comp->method == ICAL_METHOD_ADD){ 571 if(comp->method == ICAL_METHOD_ADD){
569 rtrn = 1; 572 rtrn = 1;
570 } 573 }
571 icalclassify_post 574 icalclassify_post
572} 575}
573int icalclassify_cancel_event( 576int icalclassify_cancel_event(
574 struct icalclassify_parts *comp, 577 struct icalclassify_parts *comp,
575 struct icalclassify_parts *match, 578 struct icalclassify_parts *match,
576 const char* user) 579 const char* user)
577{ 580{
578 icalclassify_pre 581 icalclassify_pre
579 if(comp->method == ICAL_METHOD_CANCEL){ 582 if(comp->method == ICAL_METHOD_CANCEL){
580 rtrn = 1; 583 rtrn = 1;
581 } 584 }
582 icalclassify_post 585 icalclassify_post
583} 586}
584int icalclassify_cancel_instance( 587int icalclassify_cancel_instance(
585 struct icalclassify_parts *comp, 588 struct icalclassify_parts *comp,
586 struct icalclassify_parts *match, 589 struct icalclassify_parts *match,
587 const char* user) 590 const char* user)
588{ 591{
589 icalclassify_pre 592 icalclassify_pre
590 if(comp->method == ICAL_METHOD_CANCEL){ 593 if(comp->method == ICAL_METHOD_CANCEL){
591 rtrn = 1; 594 rtrn = 1;
592 } 595 }
593 icalclassify_post 596 icalclassify_post
594} 597}
595int icalclassify_cancel_all( 598int icalclassify_cancel_all(
596 struct icalclassify_parts *comp, 599 struct icalclassify_parts *comp,
597 struct icalclassify_parts *match, 600 struct icalclassify_parts *match,
598 const char* user) 601 const char* user)
599{ 602{
600 icalclassify_pre 603 icalclassify_pre
601 if(comp->method == ICAL_METHOD_CANCEL){ 604 if(comp->method == ICAL_METHOD_CANCEL){
602 rtrn = 1; 605 rtrn = 1;
603 } 606 }
604 icalclassify_post 607 icalclassify_post
605} 608}
606int icalclassify_refesh( 609int icalclassify_refesh(
607 struct icalclassify_parts *comp, 610 struct icalclassify_parts *comp,
608 struct icalclassify_parts *match, 611 struct icalclassify_parts *match,
609 const char* user) 612 const char* user)
610{ 613{
611 icalclassify_pre 614 icalclassify_pre
612 if(comp->method == ICAL_METHOD_REFRESH){ 615 if(comp->method == ICAL_METHOD_REFRESH){
613 rtrn = 1; 616 rtrn = 1;
614 } 617 }
615 icalclassify_post 618 icalclassify_post
616} 619}
617int icalclassify_counter( 620int icalclassify_counter(
618 struct icalclassify_parts *comp, 621 struct icalclassify_parts *comp,
619 struct icalclassify_parts *match, 622 struct icalclassify_parts *match,
620 const char* user) 623 const char* user)
621{ 624{
622 icalclassify_pre 625 icalclassify_pre
623 if(comp->method == ICAL_METHOD_COUNTER){ 626 if(comp->method == ICAL_METHOD_COUNTER){
624 rtrn = 1; 627 rtrn = 1;
625 } 628 }
626 icalclassify_post 629 icalclassify_post
627} 630}
628int icalclassify_delinecounter( 631int icalclassify_delinecounter(
629 struct icalclassify_parts *comp, 632 struct icalclassify_parts *comp,
630 struct icalclassify_parts *match, 633 struct icalclassify_parts *match,
631 const char* user) 634 const char* user)
632{ 635{
633 icalclassify_pre 636 icalclassify_pre
634 637
635 if(comp->method == ICAL_METHOD_DECLINECOUNTER){ 638 if(comp->method == ICAL_METHOD_DECLINECOUNTER){
636 rtrn = 1; 639 rtrn = 1;
637 } 640 }
638 641
639 icalclassify_post 642 icalclassify_post
640} 643}
641 644
642struct icalclassify_map { 645struct icalclassify_map {
643 icalproperty_method method; 646 icalproperty_method method;
644 int (*fn)(struct icalclassify_parts *comp,struct icalclassify_parts *match, const char* user); 647 int (*fn)(struct icalclassify_parts *comp,struct icalclassify_parts *match, const char* user);
645 ical_class class; 648 icalproperty_xlicclass class;
646} icalclassify_map[] = 649} icalclassify_map[] =
647{ {ICAL_METHOD_PUBLISH,icalclassify_publish_new,ICAL_PUBLISH_NEW_CLASS}, 650{ {ICAL_METHOD_PUBLISH,icalclassify_publish_new,ICAL_XLICCLASS_PUBLISHNEW},
648 {ICAL_METHOD_PUBLISH,icalclassify_publish_update,ICAL_PUBLISH_UPDATE_CLASS}, 651 {ICAL_METHOD_PUBLISH,icalclassify_publish_update,ICAL_XLICCLASS_PUBLISHUPDATE},
649 {ICAL_METHOD_PUBLISH,icalclassify_publish_freebusy,ICAL_PUBLISH_FREEBUSY_CLASS}, 652 {ICAL_METHOD_PUBLISH,icalclassify_publish_freebusy,ICAL_XLICCLASS_PUBLISHFREEBUSY},
650 {ICAL_METHOD_REQUEST,icalclassify_request_delegate,ICAL_REQUEST_DELEGATE_CLASS}, 653 {ICAL_METHOD_REQUEST,icalclassify_request_delegate,ICAL_XLICCLASS_REQUESTDELEGATE},
651 {ICAL_METHOD_REQUEST,icalclassify_request_new,ICAL_REQUEST_NEW_CLASS}, 654 {ICAL_METHOD_REQUEST,icalclassify_request_new,ICAL_XLICCLASS_REQUESTNEW},
652 {ICAL_METHOD_REQUEST,icalclassify_request_update,ICAL_REQUEST_UPDATE_CLASS}, 655 {ICAL_METHOD_REQUEST,icalclassify_request_update,ICAL_XLICCLASS_REQUESTUPDATE},
653 {ICAL_METHOD_REQUEST,icalclassify_request_reschedule,ICAL_REQUEST_RESCHEDULE_CLASS}, 656 {ICAL_METHOD_REQUEST,icalclassify_request_reschedule,ICAL_XLICCLASS_REQUESTRESCHEDULE},
654 657
655 {ICAL_METHOD_REQUEST,icalclassify_request_new_organizer,ICAL_REQUEST_NEW_ORGANIZER_CLASS}, 658 {ICAL_METHOD_REQUEST,icalclassify_request_new_organizer,ICAL_XLICCLASS_REQUESTNEWORGANIZER},
656 {ICAL_METHOD_REQUEST,icalclassify_request_forward,ICAL_REQUEST_FORWARD_CLASS}, 659 {ICAL_METHOD_REQUEST,icalclassify_request_forward,ICAL_XLICCLASS_REQUESTFORWARD},
657 {ICAL_METHOD_REQUEST,icalclassify_request_status,ICAL_REQUEST_STATUS_CLASS}, 660 {ICAL_METHOD_REQUEST,icalclassify_request_status,ICAL_XLICCLASS_REQUESTSTATUS},
658 {ICAL_METHOD_REQUEST,icalclassify_request_freebusy,ICAL_REQUEST_FREEBUSY_CLASS}, 661 {ICAL_METHOD_REQUEST,icalclassify_request_freebusy,ICAL_XLICCLASS_REQUESTFREEBUSY},
659 662
660 {ICAL_METHOD_REPLY,icalclassify_reply_accept,ICAL_REPLY_ACCEPT_CLASS}, 663 {ICAL_METHOD_REPLY,icalclassify_reply_accept,ICAL_XLICCLASS_REPLYACCEPT},
661 {ICAL_METHOD_REPLY,icalclassify_reply_decline,ICAL_REPLY_DECLINE_CLASS}, 664 {ICAL_METHOD_REPLY,icalclassify_reply_decline,ICAL_XLICCLASS_REPLYDECLINE},
662 {ICAL_METHOD_REPLY,icalclassify_reply_delegate,ICAL_REPLY_DELEGATE_CLASS}, 665 {ICAL_METHOD_REPLY,icalclassify_reply_delegate,ICAL_XLICCLASS_REPLYDELEGATE},
663 {ICAL_METHOD_REPLY,icalclassify_reply_crasher_accept,ICAL_REPLY_CRASHER_ACCEPT_CLASS}, 666 {ICAL_METHOD_REPLY,icalclassify_reply_crasher_accept,ICAL_XLICCLASS_REPLYCRASHERACCEPT},
664 {ICAL_METHOD_REPLY,icalclassify_reply_crasher_decline,ICAL_REPLY_CRASHER_DECLINE_CLASS}, 667 {ICAL_METHOD_REPLY,icalclassify_reply_crasher_decline,ICAL_XLICCLASS_REPLYCRASHERDECLINE},
665 668
666 {ICAL_METHOD_ADD,icalclassify_add_instance,ICAL_ADD_INSTANCE_CLASS}, 669 {ICAL_METHOD_ADD,icalclassify_add_instance,ICAL_XLICCLASS_ADDINSTANCE},
667 670
668 {ICAL_METHOD_CANCEL,icalclassify_cancel_event,ICAL_CANCEL_EVENT_CLASS}, 671 {ICAL_METHOD_CANCEL,icalclassify_cancel_event,ICAL_XLICCLASS_CANCELEVENT},
669 {ICAL_METHOD_CANCEL,icalclassify_cancel_instance,ICAL_CANCEL_INSTANCE_CLASS}, 672 {ICAL_METHOD_CANCEL,icalclassify_cancel_instance,ICAL_XLICCLASS_CANCELINSTANCE},
670 {ICAL_METHOD_CANCEL,icalclassify_cancel_all,ICAL_CANCEL_ALL_CLASS}, 673 {ICAL_METHOD_CANCEL,icalclassify_cancel_all,ICAL_XLICCLASS_CANCELALL},
671 674
672 {ICAL_METHOD_REFRESH,icalclassify_refesh,ICAL_REFRESH_CLASS}, 675 {ICAL_METHOD_REFRESH,icalclassify_refesh,ICAL_XLICCLASS_REFRESH},
673 {ICAL_METHOD_COUNTER,icalclassify_counter,ICAL_COUNTER_CLASS}, 676 {ICAL_METHOD_COUNTER,icalclassify_counter,ICAL_XLICCLASS_COUNTER},
674 {ICAL_METHOD_DECLINECOUNTER,icalclassify_delinecounter,ICAL_DECLINECOUNTER_CLASS}, 677 {ICAL_METHOD_DECLINECOUNTER,icalclassify_delinecounter,ICAL_XLICCLASS_DECLINECOUNTER},
675 {ICAL_METHOD_NONE,0,ICAL_NO_CLASS} 678 {ICAL_METHOD_NONE,0,ICAL_XLICCLASS_NONE}
676}; 679};
677 680
678 681
679ical_class icalclassify(icalcomponent* c,icalcomponent* match, 682icalproperty_xlicclass icalclassify(icalcomponent* c,icalcomponent* match,
680 const char* user) 683 const char* user)
681{ 684{
682 icalcomponent *inner; 685 icalcomponent *inner;
683 icalproperty *p; 686 icalproperty *p;
684 icalproperty_method method; 687 icalproperty_method method;
685 ical_class class = ICAL_UNKNOWN_CLASS; 688 icalproperty_xlicclass class = ICAL_XLICCLASS_UNKNOWN;
686 689
687 int i; 690 int i;
688 691
689 struct icalclassify_parts comp_parts; 692 struct icalclassify_parts comp_parts;
690 struct icalclassify_parts match_parts; 693 struct icalclassify_parts match_parts;
691 694
692 inner = icalcomponent_get_first_real_component(c); 695 inner = icalcomponent_get_first_real_component(c);
693 696
694 if (inner == 0) { 697 if (inner == 0) {
695 return ICAL_NO_CLASS; 698 return ICAL_XLICCLASS_NONE;
696 } 699 }
697 700
698 icalssutil_get_parts(c,&comp_parts); 701 icalssutil_get_parts(c,&comp_parts);
699 icalssutil_get_parts(match,&match_parts); 702 icalssutil_get_parts(match,&match_parts);
700 703
701 /* Determine if the incoming component is obsoleted by the match */ 704 /* Determine if the incoming component is obsoleted by the match */
702 if(match != 0 && ( 705 if(match != 0 && (
703 comp_parts.method == ICAL_METHOD_REQUEST 706 comp_parts.method == ICAL_METHOD_REQUEST
704 )){ 707 )){
705 assert ( ! ((comp_parts.dtstamp.is_utc==1)^ 708 assert ( ! ((comp_parts.dtstamp.is_utc==1)^
706 (match_parts.dtstamp.is_utc==1))); 709 (match_parts.dtstamp.is_utc==1)));
707 710
708 if( comp_parts.sequence<match_parts.sequence && 711 if( comp_parts.sequence<match_parts.sequence &&
709 icaltime_compare(comp_parts.dtstamp,match_parts.dtstamp)>0) 712 icaltime_compare(comp_parts.dtstamp,match_parts.dtstamp)>0)
710 { 713 {
711 /* comp has a smaller sequence and a later DTSTAMP */ 714 /* comp has a smaller sequence and a later DTSTAMP */
712 return ICAL_MISSEQUENCED_CLASS; 715 class = ICAL_XLICCLASS_MISSEQUENCED;
716 goto CLEANUP;
713 } 717 }
714 718
715 if( (comp_parts.sequence<match_parts.sequence ) 719 if( (comp_parts.sequence<match_parts.sequence )
716 /*&&icaltime_compare(comp_parts.dtstamp,match_parts.dtstamp)<=0*/ 720 /*&&icaltime_compare(comp_parts.dtstamp,match_parts.dtstamp)<=0*/
717 || 721 ||
718 ( comp_parts.sequence == match_parts.sequence && 722 ( comp_parts.sequence == match_parts.sequence &&
719 icaltime_compare(comp_parts.dtstamp,match_parts.dtstamp)<=0)){ 723 icaltime_compare(comp_parts.dtstamp,match_parts.dtstamp)<=0)){
720 724
721 return ICAL_OBSOLETE_CLASS; 725 class = ICAL_XLICCLASS_OBSOLETE;
726 goto CLEANUP;
722 } 727 }
723 728
724 } 729 }
725 730
726 p = icalcomponent_get_first_property(c,ICAL_METHOD_PROPERTY); 731 p = icalcomponent_get_first_property(c,ICAL_METHOD_PROPERTY);
727 if (p == 0) { 732 if (p == 0) {
728 return ICAL_UNKNOWN_CLASS; 733 class = ICAL_XLICCLASS_UNKNOWN;
734 goto CLEANUP;
729 } 735 }
730 method = icalproperty_get_method(p); 736 method = icalproperty_get_method(p);
731 737
732 for (i =0; icalclassify_map[i].method != ICAL_METHOD_NONE; i++){ 738 for (i =0; icalclassify_map[i].method != ICAL_METHOD_NONE; i++){
733 if(icalclassify_map[i].method == method){ 739 if(icalclassify_map[i].method == method){
734 if( (*(icalclassify_map[i].fn))(&comp_parts,&match_parts,user)==1){ 740 if( (*(icalclassify_map[i].fn))(&comp_parts,&match_parts,user)==1){
735 class = icalclassify_map[i].class; 741 class = icalclassify_map[i].class;
736 break; 742 break;
737 } 743 }
738 } 744 }
739 } 745 }
740 746
747CLEANUP:
741 icalssutil_free_parts(&comp_parts); 748 icalssutil_free_parts(&comp_parts);
742 icalssutil_free_parts(&match_parts); 749 icalssutil_free_parts(&match_parts);
743 750
744 return class; 751 return class;
745 752
746} 753}
747 754
748struct class_map {
749 ical_class class;
750 char *str;
751} class_map[] = {
752 {ICAL_NO_CLASS,"No class"},
753 {ICAL_PUBLISH_NEW_CLASS,"New Publish"},
754 {ICAL_PUBLISH_UPDATE_CLASS,"Publish Update"},
755 {ICAL_PUBLISH_FREEBUSY_CLASS,"Publish freebusy"},
756 {ICAL_REQUEST_NEW_CLASS,"New request"},
757 {ICAL_REQUEST_UPDATE_CLASS,"Update"},
758 {ICAL_REQUEST_RESCHEDULE_CLASS,"Reschedule"},
759 {ICAL_REQUEST_DELEGATE_CLASS,"Delegate request"},
760 {ICAL_REQUEST_NEW_ORGANIZER_CLASS,"New Organizer"},
761 {ICAL_REQUEST_FORWARD_CLASS,"Forward"},
762 {ICAL_REQUEST_STATUS_CLASS,"Status request"},
763 {ICAL_REPLY_ACCEPT_CLASS,"Accept reply"},
764 {ICAL_REPLY_DECLINE_CLASS,"Decline reply"},
765 {ICAL_REPLY_DELEGATE_CLASS,"Delegation reply"},
766 {ICAL_REPLY_CRASHER_ACCEPT_CLASS,"Crasher's accept reply"},
767 {ICAL_REPLY_CRASHER_DECLINE_CLASS,"Crasher's decline reply"},
768 {ICAL_ADD_INSTANCE_CLASS,"Add instance"},
769 {ICAL_CANCEL_EVENT_CLASS,"Cancel event"},
770 {ICAL_CANCEL_INSTANCE_CLASS,"Cancel instance"},
771 {ICAL_CANCEL_ALL_CLASS,"Cancel all instances"},
772 {ICAL_REFRESH_CLASS,"Refresh"},
773 {ICAL_COUNTER_CLASS,"Counter"},
774 {ICAL_DECLINECOUNTER_CLASS,"Decline counter"},
775 {ICAL_MALFORMED_CLASS,"Malformed"},
776 {ICAL_OBSOLETE_CLASS,"Obsolete"},
777 {ICAL_MISSEQUENCED_CLASS,"Missequenced"},
778 {ICAL_UNKNOWN_CLASS,"Unknown"}
779};
780
781char* icalclassify_class_to_string(ical_class class)
782{
783 int i;
784
785 for (i = 0;class_map[i].class != ICAL_UNKNOWN_CLASS;i++){
786 if (class_map[i].class == class){
787 return class_map[i].str;
788 }
789 }
790
791 return "Unknown";
792}