Skeleton code for time-range test (section 9.9)
authorArt Cancro <ajc@citadel.org>
Tue, 27 Feb 2024 16:16:56 +0000 (11:16 -0500)
committerArt Cancro <ajc@citadel.org>
Tue, 27 Feb 2024 16:16:56 +0000 (11:16 -0500)
After finally getting to the point where we are recursing up
through both the nested components and the nested queries in a
way that matches them properly, we are now able to start writing
the individual property and parameter queries defined in the RFC.

time-range (section 9.9) is the obvious first choice to implement
because it is the most useful.  Wrote and bound the skeleton
function to do this.

webcit-ng/server/caldav_reports.c

index 08972cb860b71cec655b5bd58da33c98fcc194e0..eac1e7e383c3c30c2a20d32d8313f93cafc243a9 100644 (file)
@@ -257,6 +257,21 @@ void caldav_report_one_item(struct http_transaction *h, struct ctdlsession *c, S
 }
 
 
+// Compare function for "time-range" tests (RFC4791 section 9.9)
+// Returns nonzero if the supplied icalcomponent occurs within the specified time range
+int caldav_time_range_filter_matches(icalcomponent *cal, char *start, char *end) {
+
+       TRACE;
+       syslog(LOG_DEBUG, "Does this %s fall between %s and %s ?",
+               icalcomponent_kind_to_string(icalcomponent_isa(cal)),
+               start,
+               end
+       );
+
+       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 apply_at_level) {
@@ -371,10 +386,24 @@ int caldav_apply_filters(void *cal, Array *filters, int apply_at_level) {
                        syslog(LOG_DEBUG, "text match filter at level %d FIXME not implemented yet", this_rule_level);
                }
 
-               else if (!strcasecmp(t[1], "time-range")) {
+               else if (!strcasecmp(t[1], "time-range")) {                     // RFC4791 9.9
                        syslog(LOG_DEBUG, "time range filter at level %d FIXME not implemented yet", this_rule_level);
-                       for (int i=0; i<num_tokens; ++i) {
-                               syslog(LOG_DEBUG, "token %2d : <%s>", i, t[i]);
+                       for (int i=2; (i+1)<num_tokens; i+=2) {
+                               char *tr_start = NULL;
+                               char *tr_end = NULL;
+                               if (!strcasecmp(t[i], "start")) {
+                                       tr_start = t[i+1];
+                               }
+                               else if (!strcasecmp(t[i], "end")) {
+                                       tr_end = t[i+1];
+                               }
+                               if (caldav_time_range_filter_matches(cal, tr_start, tr_end)) {
+                                       syslog(LOG_DEBUG, "time range matches");
+                               }
+                               else {
+                                       syslog(LOG_DEBUG, "time range does not match -- rejecting");
+                                       qual = 0;
+                               }
                        }
                }