From: Art Cancro Date: Mon, 26 Feb 2024 22:37:20 +0000 (-0500) Subject: XML is like violence: if it doesn't work, you're not using enough. X-Git-Tag: v999~36 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=747c2d11b3641e4dc4cc0033e96bb0266e074446 XML is like violence: if it doesn't work, you're not using enough. --- diff --git a/webcit-ng/server/caldav_reports.c b/webcit-ng/server/caldav_reports.c index ef9072829..76a0ee43d 100644 --- a/webcit-ng/server/caldav_reports.c +++ b/webcit-ng/server/caldav_reports.c @@ -274,10 +274,11 @@ 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 caldav_apply_filters(void *cal, Array *filters, int start_at_level) { int f = 0; // filter number iterator int qual = 1; // 0 for disqualify, 1 for qualify + int previous_level = -1; while ( (f, looking for <%s>, rejecting", + 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, icalcomponent_kind_to_string(icalcomponent_isa(cal)), t[3] ); + + // We have a match. Drill down into the subcomponents. + + icalcomponent *c = NULL; + int number_of_subcomponents = 0; + int number_of_matches = 0; + for ( c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT); + (c != 0); + c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT) + ) { + ++number_of_subcomponents; + if (caldav_apply_filters(c, filters, level+1)) { + syslog(LOG_DEBUG, "Subcomponent %d might match", number_of_subcomponents); + ++number_of_matches; + } + } + if (number_of_matches > 0) { // something matched + qual = 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, + icalcomponent_kind_to_string(icalcomponent_isa(cal)), + t[3] + ); return(0); } } @@ -338,6 +379,7 @@ int caldav_apply_filters(void *cal, Array *filters) { ++f; } + syslog(LOG_DEBUG, "caldav: we reached the end of level %d , returning %d", start_at_level, qual); return(qual); } @@ -404,7 +446,7 @@ void caldav_report(struct http_transaction *h, struct ctdlsession *c) { // If there was a filter stanza, run this calendar item through the filters. syslog(LOG_DEBUG, "Evaluating message \033[33m%ld\033[0m...", m); - qualify = caldav_apply_filters(cal, crp.filters); + qualify = caldav_apply_filters(cal, crp.filters, 0); syslog(LOG_DEBUG, "Message %ld %s\033[0m qualify", m, (qualify ? "\033[32mDOES" : "\033[31mDOES NOT")); syslog(LOG_DEBUG, ""); diff --git a/webcit-ng/server/webcit.h b/webcit-ng/server/webcit.h index 92738063b..03efc5e81 100644 --- a/webcit-ng/server/webcit.h +++ b/webcit-ng/server/webcit.h @@ -157,8 +157,6 @@ void caldav_xml_chardata(void *, const XML_Char *, int); StrBuf *fetch_ical(struct ctdlsession *, long); void cal_multiget_out(long, StrBuf *, StrBuf *, StrBuf *); void caldav_report_one_item(struct http_transaction *, struct ctdlsession *, StrBuf *, StrBuf *); -int caldav_apply_one_filter(void *, char *); -int caldav_apply_filters(void *, Array *); void caldav_report(struct http_transaction *, struct ctdlsession *); // ctdlclient.c