summaryrefslogtreecommitdiffabout
path: root/libical/src/libicalss/icalclassify.c
Side-by-side diff
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
@@ -13,36 +13,36 @@
The LGPL as published by the Free Software Foundation, version
2.1, available at: http://www.fsf.org/copyleft/lesser.html
Or:
The Mozilla Public License Version 1.0. You may obtain a copy of
the License at http://www.mozilla.org/MPL/
======================================================================*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#include "icalerror.h"
#include "ical.h"
#include "icalclassify.h"
#include "icalmemory.h"
+
#include <ctype.h> /* For tolower() */
#include <string.h> /* for index() */
#include <stdlib.h> /* for malloc and free */
struct icalclassify_parts {
icalcomponent *c;
icalcomponent_kind inner_kind;
icalproperty_method method;
char* organizer;
icalparameter_partstat reply_partstat;
char* reply_attendee;
char* uid;
int sequence;
struct icaltimetype dtstamp;
@@ -133,47 +133,51 @@ icalproperty* icalclassify_find_attendee(icalcomponent *c,
lattendee = icalclassify_lowercase(attendee);
upn = strchr(lattendee,':');
if (upn== 0){
upn = lattendee;
} else {
upn++; /* skip the ";"*/
}
inner = icalcomponent_get_first_real_component(c);
for(p = icalcomponent_get_first_property(inner,ICAL_ATTENDEE_PROPERTY);
p != 0;
p = icalcomponent_get_next_property(inner,ICAL_ATTENDEE_PROPERTY))
{
- const char* this_attendee
+ char* this_attendee
= icalclassify_lowercase(icalproperty_get_attendee(p));
char* this_upn = strchr(this_attendee,':');
if(this_upn == 0){
continue;
} else {
this_upn++;
}
if(strcmp(this_upn,upn)==0){
+ free(lattendee);
+ free(this_attendee);
return p;
}
+ free(this_attendee);
}
+ free(lattendee);
return 0;
}
void icalssutil_free_parts(struct icalclassify_parts *parts)
{
if(parts == 0){
return;
}
if(parts->organizer != 0){
free(parts->organizer);
}
if(parts->uid != 0){
@@ -271,33 +275,33 @@ int icalssutil_is_rescheduled(icalcomponent* a,icalcomponent* b)
ICAL_DURATION_PROPERTY,
ICAL_DUE_PROPERTY,
ICAL_RRULE_PROPERTY,
ICAL_RDATE_PROPERTY,
ICAL_EXRULE_PROPERTY,
ICAL_EXDATE_PROPERTY,
ICAL_NO_PROPERTY
};
i1 = icalcomponent_get_first_real_component(a);
i2 = icalcomponent_get_first_real_component(b);
for(i =0; kind_array[i] != ICAL_NO_PROPERTY; i++){
p1 = icalcomponent_get_first_property(i1,kind_array[i]);
p2 = icalcomponent_get_first_property(i2,kind_array[i]);
- if( (p1!=0)^(p1!=0) ){
+ if( (p1!=0)^(p2!=0) ){
/* Return true if the property exists in one component and not
the other */
return 1;
}
if(p1 && strcmp(icalproperty_as_ical_string(p1),
icalproperty_as_ical_string(p2)) != 0){
return 1;
}
}
return 0;
}
#define icalclassify_pre \
@@ -533,33 +537,32 @@ int icalclassify_reply_crasher_accept(
icalproperty* attendee;
icalclassify_pre;
attendee= icalclassify_find_attendee(match->c,comp->reply_attendee);
if(attendee == 0 &&
comp->reply_partstat == ICAL_PARTSTAT_ACCEPTED){
rtrn = 1;
}
icalclassify_post
}
int icalclassify_reply_crasher_decline(
struct icalclassify_parts *comp,
struct icalclassify_parts *match,
const char* user)
{
- icalparameter_partstat partstat;
icalproperty* attendee;
icalclassify_pre;
attendee = icalclassify_find_attendee(match->c,comp->reply_attendee);
if(attendee == 0 &&
comp->reply_partstat == ICAL_PARTSTAT_DECLINED){
rtrn = 1;
}
icalclassify_post
}
int icalclassify_add_instance(
struct icalclassify_parts *comp,
struct icalclassify_parts *match,
const char* user)
@@ -629,164 +632,123 @@ int icalclassify_delinecounter(
struct icalclassify_parts *comp,
struct icalclassify_parts *match,
const char* user)
{
icalclassify_pre
if(comp->method == ICAL_METHOD_DECLINECOUNTER){
rtrn = 1;
}
icalclassify_post
}
struct icalclassify_map {
icalproperty_method method;
int (*fn)(struct icalclassify_parts *comp,struct icalclassify_parts *match, const char* user);
- ical_class class;
+ icalproperty_xlicclass class;
} icalclassify_map[] =
-{ {ICAL_METHOD_PUBLISH,icalclassify_publish_new,ICAL_PUBLISH_NEW_CLASS},
- {ICAL_METHOD_PUBLISH,icalclassify_publish_update,ICAL_PUBLISH_UPDATE_CLASS},
- {ICAL_METHOD_PUBLISH,icalclassify_publish_freebusy,ICAL_PUBLISH_FREEBUSY_CLASS},
- {ICAL_METHOD_REQUEST,icalclassify_request_delegate,ICAL_REQUEST_DELEGATE_CLASS},
- {ICAL_METHOD_REQUEST,icalclassify_request_new,ICAL_REQUEST_NEW_CLASS},
- {ICAL_METHOD_REQUEST,icalclassify_request_update,ICAL_REQUEST_UPDATE_CLASS},
- {ICAL_METHOD_REQUEST,icalclassify_request_reschedule,ICAL_REQUEST_RESCHEDULE_CLASS},
-
- {ICAL_METHOD_REQUEST,icalclassify_request_new_organizer,ICAL_REQUEST_NEW_ORGANIZER_CLASS},
- {ICAL_METHOD_REQUEST,icalclassify_request_forward,ICAL_REQUEST_FORWARD_CLASS},
- {ICAL_METHOD_REQUEST,icalclassify_request_status,ICAL_REQUEST_STATUS_CLASS},
- {ICAL_METHOD_REQUEST,icalclassify_request_freebusy,ICAL_REQUEST_FREEBUSY_CLASS},
-
- {ICAL_METHOD_REPLY,icalclassify_reply_accept,ICAL_REPLY_ACCEPT_CLASS},
- {ICAL_METHOD_REPLY,icalclassify_reply_decline,ICAL_REPLY_DECLINE_CLASS},
- {ICAL_METHOD_REPLY,icalclassify_reply_delegate,ICAL_REPLY_DELEGATE_CLASS},
- {ICAL_METHOD_REPLY,icalclassify_reply_crasher_accept,ICAL_REPLY_CRASHER_ACCEPT_CLASS},
- {ICAL_METHOD_REPLY,icalclassify_reply_crasher_decline,ICAL_REPLY_CRASHER_DECLINE_CLASS},
-
- {ICAL_METHOD_ADD,icalclassify_add_instance,ICAL_ADD_INSTANCE_CLASS},
-
- {ICAL_METHOD_CANCEL,icalclassify_cancel_event,ICAL_CANCEL_EVENT_CLASS},
- {ICAL_METHOD_CANCEL,icalclassify_cancel_instance,ICAL_CANCEL_INSTANCE_CLASS},
- {ICAL_METHOD_CANCEL,icalclassify_cancel_all,ICAL_CANCEL_ALL_CLASS},
-
- {ICAL_METHOD_REFRESH,icalclassify_refesh,ICAL_REFRESH_CLASS},
- {ICAL_METHOD_COUNTER,icalclassify_counter,ICAL_COUNTER_CLASS},
- {ICAL_METHOD_DECLINECOUNTER,icalclassify_delinecounter,ICAL_DECLINECOUNTER_CLASS},
- {ICAL_METHOD_NONE,0,ICAL_NO_CLASS}
+{ {ICAL_METHOD_PUBLISH,icalclassify_publish_new,ICAL_XLICCLASS_PUBLISHNEW},
+ {ICAL_METHOD_PUBLISH,icalclassify_publish_update,ICAL_XLICCLASS_PUBLISHUPDATE},
+ {ICAL_METHOD_PUBLISH,icalclassify_publish_freebusy,ICAL_XLICCLASS_PUBLISHFREEBUSY},
+ {ICAL_METHOD_REQUEST,icalclassify_request_delegate,ICAL_XLICCLASS_REQUESTDELEGATE},
+ {ICAL_METHOD_REQUEST,icalclassify_request_new,ICAL_XLICCLASS_REQUESTNEW},
+ {ICAL_METHOD_REQUEST,icalclassify_request_update,ICAL_XLICCLASS_REQUESTUPDATE},
+ {ICAL_METHOD_REQUEST,icalclassify_request_reschedule,ICAL_XLICCLASS_REQUESTRESCHEDULE},
+
+ {ICAL_METHOD_REQUEST,icalclassify_request_new_organizer,ICAL_XLICCLASS_REQUESTNEWORGANIZER},
+ {ICAL_METHOD_REQUEST,icalclassify_request_forward,ICAL_XLICCLASS_REQUESTFORWARD},
+ {ICAL_METHOD_REQUEST,icalclassify_request_status,ICAL_XLICCLASS_REQUESTSTATUS},
+ {ICAL_METHOD_REQUEST,icalclassify_request_freebusy,ICAL_XLICCLASS_REQUESTFREEBUSY},
+
+ {ICAL_METHOD_REPLY,icalclassify_reply_accept,ICAL_XLICCLASS_REPLYACCEPT},
+ {ICAL_METHOD_REPLY,icalclassify_reply_decline,ICAL_XLICCLASS_REPLYDECLINE},
+ {ICAL_METHOD_REPLY,icalclassify_reply_delegate,ICAL_XLICCLASS_REPLYDELEGATE},
+ {ICAL_METHOD_REPLY,icalclassify_reply_crasher_accept,ICAL_XLICCLASS_REPLYCRASHERACCEPT},
+ {ICAL_METHOD_REPLY,icalclassify_reply_crasher_decline,ICAL_XLICCLASS_REPLYCRASHERDECLINE},
+
+ {ICAL_METHOD_ADD,icalclassify_add_instance,ICAL_XLICCLASS_ADDINSTANCE},
+
+ {ICAL_METHOD_CANCEL,icalclassify_cancel_event,ICAL_XLICCLASS_CANCELEVENT},
+ {ICAL_METHOD_CANCEL,icalclassify_cancel_instance,ICAL_XLICCLASS_CANCELINSTANCE},
+ {ICAL_METHOD_CANCEL,icalclassify_cancel_all,ICAL_XLICCLASS_CANCELALL},
+
+ {ICAL_METHOD_REFRESH,icalclassify_refesh,ICAL_XLICCLASS_REFRESH},
+ {ICAL_METHOD_COUNTER,icalclassify_counter,ICAL_XLICCLASS_COUNTER},
+ {ICAL_METHOD_DECLINECOUNTER,icalclassify_delinecounter,ICAL_XLICCLASS_DECLINECOUNTER},
+ {ICAL_METHOD_NONE,0,ICAL_XLICCLASS_NONE}
};
-ical_class icalclassify(icalcomponent* c,icalcomponent* match,
+icalproperty_xlicclass icalclassify(icalcomponent* c,icalcomponent* match,
const char* user)
{
icalcomponent *inner;
icalproperty *p;
icalproperty_method method;
- ical_class class = ICAL_UNKNOWN_CLASS;
+ icalproperty_xlicclass class = ICAL_XLICCLASS_UNKNOWN;
int i;
struct icalclassify_parts comp_parts;
struct icalclassify_parts match_parts;
inner = icalcomponent_get_first_real_component(c);
if (inner == 0) {
- return ICAL_NO_CLASS;
+ return ICAL_XLICCLASS_NONE;
}
icalssutil_get_parts(c,&comp_parts);
icalssutil_get_parts(match,&match_parts);
/* Determine if the incoming component is obsoleted by the match */
if(match != 0 && (
comp_parts.method == ICAL_METHOD_REQUEST
)){
assert ( ! ((comp_parts.dtstamp.is_utc==1)^
(match_parts.dtstamp.is_utc==1)));
if( comp_parts.sequence<match_parts.sequence &&
icaltime_compare(comp_parts.dtstamp,match_parts.dtstamp)>0)
{
/* comp has a smaller sequence and a later DTSTAMP */
- return ICAL_MISSEQUENCED_CLASS;
+ class = ICAL_XLICCLASS_MISSEQUENCED;
+ goto CLEANUP;
}
if( (comp_parts.sequence<match_parts.sequence )
/*&&icaltime_compare(comp_parts.dtstamp,match_parts.dtstamp)<=0*/
||
( comp_parts.sequence == match_parts.sequence &&
icaltime_compare(comp_parts.dtstamp,match_parts.dtstamp)<=0)){
- return ICAL_OBSOLETE_CLASS;
+ class = ICAL_XLICCLASS_OBSOLETE;
+ goto CLEANUP;
}
}
p = icalcomponent_get_first_property(c,ICAL_METHOD_PROPERTY);
if (p == 0) {
- return ICAL_UNKNOWN_CLASS;
+ class = ICAL_XLICCLASS_UNKNOWN;
+ goto CLEANUP;
}
method = icalproperty_get_method(p);
for (i =0; icalclassify_map[i].method != ICAL_METHOD_NONE; i++){
if(icalclassify_map[i].method == method){
if( (*(icalclassify_map[i].fn))(&comp_parts,&match_parts,user)==1){
class = icalclassify_map[i].class;
break;
}
}
}
+CLEANUP:
icalssutil_free_parts(&comp_parts);
icalssutil_free_parts(&match_parts);
return class;
}
-struct class_map {
- ical_class class;
- char *str;
-} class_map[] = {
- {ICAL_NO_CLASS,"No class"},
- {ICAL_PUBLISH_NEW_CLASS,"New Publish"},
- {ICAL_PUBLISH_UPDATE_CLASS,"Publish Update"},
- {ICAL_PUBLISH_FREEBUSY_CLASS,"Publish freebusy"},
- {ICAL_REQUEST_NEW_CLASS,"New request"},
- {ICAL_REQUEST_UPDATE_CLASS,"Update"},
- {ICAL_REQUEST_RESCHEDULE_CLASS,"Reschedule"},
- {ICAL_REQUEST_DELEGATE_CLASS,"Delegate request"},
- {ICAL_REQUEST_NEW_ORGANIZER_CLASS,"New Organizer"},
- {ICAL_REQUEST_FORWARD_CLASS,"Forward"},
- {ICAL_REQUEST_STATUS_CLASS,"Status request"},
- {ICAL_REPLY_ACCEPT_CLASS,"Accept reply"},
- {ICAL_REPLY_DECLINE_CLASS,"Decline reply"},
- {ICAL_REPLY_DELEGATE_CLASS,"Delegation reply"},
- {ICAL_REPLY_CRASHER_ACCEPT_CLASS,"Crasher's accept reply"},
- {ICAL_REPLY_CRASHER_DECLINE_CLASS,"Crasher's decline reply"},
- {ICAL_ADD_INSTANCE_CLASS,"Add instance"},
- {ICAL_CANCEL_EVENT_CLASS,"Cancel event"},
- {ICAL_CANCEL_INSTANCE_CLASS,"Cancel instance"},
- {ICAL_CANCEL_ALL_CLASS,"Cancel all instances"},
- {ICAL_REFRESH_CLASS,"Refresh"},
- {ICAL_COUNTER_CLASS,"Counter"},
- {ICAL_DECLINECOUNTER_CLASS,"Decline counter"},
- {ICAL_MALFORMED_CLASS,"Malformed"},
- {ICAL_OBSOLETE_CLASS,"Obsolete"},
- {ICAL_MISSEQUENCED_CLASS,"Missequenced"},
- {ICAL_UNKNOWN_CLASS,"Unknown"}
-};
-
-char* icalclassify_class_to_string(ical_class class)
-{
- int i;
-
- for (i = 0;class_map[i].class != ICAL_UNKNOWN_CLASS;i++){
- if (class_map[i].class == class){
- return class_map[i].str;
- }
- }
-
- return "Unknown";
-}