-// Called by caldav_apply_filters() to apply ONE filter.
-// Returns 0 if the calendar item does not match the filter.
-// Returns 1 if the calendar item DOES match the filter.
-int caldav_apply_one_filter(void *cal, char *filter) {
- syslog(LOG_DEBUG, "applying filter: %s", filter);
-
- char this_filter[SIZ]; // we have to copy the filter string because we will destructively tokenize it
- safestrncpy(this_filter, filter, sizeof(this_filter));
-
- char *t[10] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } ;
- char *f = this_filter;
- int num_tokens = 0;
- while ( (t[num_tokens]=strtok_r(f, "|", &f)) && (num_tokens<10) ) {
- ++num_tokens;
- }
-
- // BEGIN experimental block -- see what happens when we cast to the wrong type
-
- //icalcomponent *foo_comp = (icalcomponent *) cal;
- //icalproperty *foo_prop = (icalproperty *) cal;
- //icalparameter *foo_param = (icalparameter *) cal;
-
- // END experimental block
-
- // Handle the individual filters defined in RFC4791 9.7.1 through 9.7.5
-
- if (!strcasecmp(t[1], "comp-filter")) { // RFC4791 9.7.1 - filter by component
- syslog(LOG_DEBUG, "component filter FIXME not implemented yet");
- if (icalcomponent_isa_component(cal)) {
- syslog(LOG_DEBUG, "\033[32m yes this is a component \033[0m");
- }
- else {
- syslog(LOG_DEBUG, "\033[31m no this is not a component \033[0m");
+// Recursive function to apply CalDAV FILTERS to a calendar item.
+// Returns zero if the calendar item was disqualified by a filter, nonzero if the calendar item still qualifies.
+int caldav_apply_filters(void *cal, Array *filters) {
+
+ int f = 0; // filter number iterator
+ int qual = 1; // 0 for disqualify, 1 for qualify
+
+ while ( (f<array_len(filters)) && (qual) ) {
+ syslog(LOG_DEBUG, "caldav_apply_filters(%d) %s", f, array_get_element_at(filters, f) );
+
+ // Tokenize the filter (a future performance hack would be to pre-tokenize instead of storing delimited strings)
+ char this_filter[SIZ];
+ safestrncpy(this_filter, array_get_element_at(filters, f), sizeof(this_filter));
+ char *t[10] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } ;
+ char *ft = this_filter;
+ int num_tokens = 0;
+ while ( (t[num_tokens]=strtok_r(ft, "|", &ft)) && (num_tokens<10) ) {
+ ++num_tokens;