|| (!strcasecmp(el, CAL"param-filter"))
|| (!strcasecmp(el, CAL"is-not-defined"))
|| (!strcasecmp(el, CAL"text-match"))
+ || (!strcasecmp(el, CAL"time-range"))
)
&& (crp->filters) // Make sure we actually allocated an array
) {
// 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 start_at_level) {
+int caldav_apply_filters(void *cal, Array *filters, int apply_at_level) {
int f = 0; // filter number iterator
int qual = 1; // 0 for disqualify, 1 for qualify
int previous_level = -1;
+ int disregard_further_comp_filters = 0;
while ( (f<array_len(filters)) && (qual) ) {
while ( (t[num_tokens]=strtok_r(ft, "|", &ft)) && (num_tokens<10) ) {
++num_tokens;
}
- int level = atoi(t[0]);
- syslog(LOG_DEBUG, "caldav_apply_filters() filter=%d, level=%d, <%s>", f, level, array_get_element_at(filters, f) );
+ int this_rule_level = atoi(t[0]);
+ syslog(LOG_DEBUG, "caldav_apply_filters() filter=%d, level=%d, <%s>", f, this_rule_level, array_get_element_at(filters, f) );
// Handle the individual filters defined in RFC4791 9.7.1 through 9.7.5
- if (level < previous_level) {
+ if (apply_at_level < previous_level) {
syslog(LOG_DEBUG, "caldav: walking back down");
return(qual);
}
- else if (level < start_at_level) {
- syslog(LOG_DEBUG, "caldav: start_at_level=%d, level=%d, skipping this rule", start_at_level, level);
+ else if (this_rule_level != apply_at_level) {
+ syslog(LOG_DEBUG, "caldav: apply_at_level=%d, this_rule_level=%d, skipping this rule", apply_at_level, this_rule_level);
}
- else if (!strcasecmp(t[1], "comp-filter")) { // RFC4791 9.7.1 - filter by component
- syslog(LOG_DEBUG, "component filter at level %d", level);
+ else if ( (!strcasecmp(t[1], "comp-filter"))
+ && (!disregard_further_comp_filters)
+ ) { // RFC4791 9.7.1 - filter by component
+ syslog(LOG_DEBUG, "component filter at level %d", this_rule_level);
// Root element is NOT a component, but the root filter is "comp-filter" -- reject!
- if ( (!icalcomponent_isa_component(cal)) && (level == 0) ) {
+ if ( (!icalcomponent_isa_component(cal)) && (this_rule_level == 0) ) {
syslog(LOG_DEBUG, "caldav: root element is not a component, rejecting");
return(0);
}
// Current element is a component and the filter is "comp-filter" -- see if it matches the requested type
if ( (icalcomponent_isa_component(cal))
- //&& (level == 0)
&& (!strcasecmp(t[2], "name"))
) {
if (icalcomponent_isa(cal) == icalcomponent_string_to_kind(t[3]) ) {
syslog(LOG_DEBUG, "caldav: component at level %d is <%s>, looking for <%s>, recursing...",
- start_at_level,
+ apply_at_level,
icalcomponent_kind_to_string(icalcomponent_isa(cal)), t[3]
);
c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)
) {
++number_of_subcomponents;
- if (caldav_apply_filters(c, filters, level+1)) {
+ if (caldav_apply_filters(c, filters, apply_at_level+1)) {
syslog(LOG_DEBUG, "Subcomponent %d might match", number_of_subcomponents);
++number_of_matches;
}
}
if (number_of_matches > 0) { // something matched
qual = 1;
+ disregard_further_comp_filters = 1;
+
}
else if (number_of_subcomponents > 0) { // nothing matched
return(0); // but only fail if there *were* subcomponents.
}
else {
syslog(LOG_DEBUG, "caldav: component at level %d is <%s>, looking for <%s>, rejecting",
- start_at_level,
+ apply_at_level,
icalcomponent_kind_to_string(icalcomponent_isa(cal)),
t[3]
);
syslog(LOG_DEBUG, "text match filter FIXME not implemented yet");
}
+ else if (!strcasecmp(t[1], "time-range")) {
+ syslog(LOG_DEBUG, "time range filter \033[33mFIXME\033[0m not implemented yet");
+ }
+
++f;
}
- syslog(LOG_DEBUG, "caldav: we reached the end of level %d , returning %d", start_at_level, qual);
+ syslog(LOG_DEBUG, "caldav: we reached the end of level %d , returning %d", apply_at_level, qual);
return(qual);
}