From: Art Cancro Date: Mon, 26 Feb 2024 23:00:19 +0000 (-0500) Subject: Refining XML rules X-Git-Tag: v999~35 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=9b800a70df384d28b050391002f53061ba824043 Refining XML rules --- diff --git a/webcit-ng/server/caldav_reports.c b/webcit-ng/server/caldav_reports.c index 76a0ee43d..0c281efb4 100644 --- a/webcit-ng/server/caldav_reports.c +++ b/webcit-ng/server/caldav_reports.c @@ -81,6 +81,7 @@ void caldav_xml_start(void *data, const char *el, const char **attr) { || (!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 ) { @@ -274,11 +275,12 @@ void caldav_report_one_item(struct http_transaction *h, struct ctdlsession *c, S // 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", 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] ); @@ -335,13 +338,15 @@ int caldav_apply_filters(void *cal, Array *filters, int start_at_level) { 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. @@ -350,7 +355,7 @@ int caldav_apply_filters(void *cal, Array *filters, int start_at_level) { } 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] ); @@ -376,10 +381,14 @@ int caldav_apply_filters(void *cal, Array *filters, int start_at_level) { 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); }