crp->filters = array_new(SIZ);
}
- // RFC4791 9.7.1 CALDAV:comp-filter XML Element
- else if ( (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:comp-filter"))
- && (crp->filters)
- && (attr[0])
- && (attr[1])
+ // Handle the filters defined in RFC4791 9.7.1 through 9.7.5
+ else if ( ( (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:comp-filter"))
+ || (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:prop-filter"))
+ || (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:param-filter"))
+ || (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:is-not-defined"))
+ || (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:text-match"))
+ )
+ && (crp->filters) // Make sure we actually allocated an array
) {
char newfilter[SIZ];
- snprintf(newfilter, SIZ, "comp-filter|%s|%s", attr[0], attr[1]);
+ int a = 0;
+ int len = snprintf(newfilter, SIZ, &el[23]); // strip off "urn:ietf:params:xml:ns:caldav:" for our purposes
+ while (attr[a]) {
+ len += snprintf(&newfilter[len], SIZ-len, "|%s", attr[a++]); // now save the attributes
+ }
array_append(crp->filters, newfilter);
syslog(LOG_DEBUG, "%s", newfilter);
}
- // RFC4791 9.7.2 CALDAV:prop-filter XML Element
- else if (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:prop-filter")) {
- if (crp->filters) {
- char newfilter[SIZ];
- snprintf(newfilter, SIZ, "hi there");
- array_append(crp->filters, newfilter);
- }
- }
-
- // RFC4791 9.7.3 CALDAV:param-filter XML Element
- else if (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:param-filter")) {
- if (crp->filters) {
- char newfilter[SIZ];
- snprintf(newfilter, SIZ, "hi there");
- array_append(crp->filters, newfilter);
- }
- }
-
- // RFC4791 9.7.4 CALDAV:is-not-defined XML Element
- else if (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:is-not-defined")) {
- if (crp->filters) {
- char newfilter[SIZ];
- snprintf(newfilter, SIZ, "hi there");
- array_append(crp->filters, newfilter);
- }
- }
-
- // RFC4791 9.7.5 CALDAV:text-match XML Element
- else if (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:text-match")) {
- if (crp->filters) {
- char newfilter[SIZ];
- snprintf(newfilter, SIZ, "hi there");
- array_append(crp->filters, newfilter);
- }
- }
}
}
-void caldav_apply_filter(struct cr_params *crp, char *xml_body, long xml_length) {
- TRACE;
+// 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);
+ return(1);
+}
+
+
+// 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 index) {
+
+ // Apply *this* filter.
+ if (caldav_apply_one_filter(cal, array_get_element_at(filters, index)) == 0) {
+ return(0);
+ }
+
+ // If we get to this point, the current filter has passed, and we move on to the next one.
+ if (index < array_len(filters)-1) {
+ return(caldav_apply_filters(cal, filters, index+1));
+ }
+
+ // If we got this far, every filter passed, and the calendar item qualifies for output.
+ return(1);
}
// Does this calendar item qualify for output?
int qualify = 1;
- // FIXME put filters here
- if (crp.filters) {
- // apply the filters
- }
+ // If there was a filter stanza, run this calendar item through the filters.
+ qualify = caldav_apply_filters(cal, crp.filters, 0);
+ syslog(LOG_DEBUG, "Message %ld does%s qualify", m, (qualify ? "" : " NOT"));
// Did this calendar item match the query? If so, output it.
if (qualify) {