Count nesting level only for comp-filters
authorArt Cancro <ajc@citadel.org>
Tue, 27 Feb 2024 03:50:32 +0000 (22:50 -0500)
committerArt Cancro <ajc@citadel.org>
Tue, 27 Feb 2024 03:50:32 +0000 (22:50 -0500)
webcit-ng/server/caldav_reports.c
webcit-ng/server/webcit.h

index 6f6fde733b50bd00e3126a08d69ef1786ffae1ef..80d6627ba0da9eb70a49a41b63115b646c36efaf 100644 (file)
@@ -19,7 +19,7 @@ enum cr_type {
 // As we slog our way through the XML we learn what the client is asking for
 // and build up the contents of this data type.
 struct cr_params {
-       int tag_nesting_level;          // not needed, just kept for pretty-printing
+       int comp_filter_nesting_level;
        enum cr_type report_type;       // which RFC4791 section 7 REPORT are we generating
        StrBuf *Chardata;               // XML chardata in between tags is built up here
        StrBuf *Hrefs;                  // list of items requested by a `calendar-multiget` REPORT
@@ -34,22 +34,9 @@ void caldav_xml_start(void *data, const char *el, const char **attr) {
 
 #ifdef DEBUG_XML_PARSE
        // logging
-       int i;
-       char indent[256];
-       indent[0] = 0;
-       for (i=0; i<crp->tag_nesting_level; ++i) {
-               strcat(indent, "  ");
-       }
-       syslog(LOG_DEBUG, "%s<%s>", indent, el);
-#endif
-       ++crp->tag_nesting_level;
-#ifdef DEBUG_XML_PARSE
-       indent[0] = 0;
-       for (i=0; i<crp->tag_nesting_level; ++i) {
-               strcat(indent, "  ");
-       }
-       for (i = 0; attr[i] != NULL; i += 2) {
-               syslog(LOG_DEBUG, "%sAttribute '%s' = '%s'", indent, attr[i], attr[i + 1]);
+       syslog(LOG_DEBUG, "<%s>", el);
+       for (int i = 0; attr[i] != NULL; i += 2) {
+               syslog(LOG_DEBUG, "Attribute '%s' = '%s'", attr[i], attr[i + 1]);
        }
        // end logging
 #endif
@@ -72,7 +59,7 @@ void caldav_xml_start(void *data, const char *el, const char **attr) {
        // RFC4791 9.7 create a filter array if this query contains a "filter" stanza
        else if (!strcasecmp(el, CAL"filter")) {
                crp->filters = array_new(SIZ);
-               crp->filter_nest = crp->tag_nesting_level;
+               crp->filter_nest = crp->comp_filter_nesting_level;
        }
 
        // Handle the filters defined in RFC4791 9.7.1 through 9.7.5
@@ -86,9 +73,13 @@ void caldav_xml_start(void *data, const char *el, const char **attr) {
                        && (crp->filters)                       // Make sure we actually allocated an array
        ) {
 
+               if (!strcasecmp(el, CAL"comp-filter")) {
+                       ++crp->comp_filter_nesting_level;
+               }
+
                char newfilter[SIZ];
                int a = 0;
-               int len = snprintf(newfilter, SIZ, "%d|", crp->tag_nesting_level - crp->filter_nest - 1);
+               int len = snprintf(newfilter, SIZ, "%d|", crp->comp_filter_nesting_level - crp->filter_nest - 1);
                len += snprintf(&newfilter[len], SIZ-len, "%s", &el[CALLEN]);           // filter name without the namespace
                while (attr[a]) {
                        len += snprintf(&newfilter[len], SIZ-len, "|%s", attr[a++]);    // now save the attributes
@@ -103,20 +94,18 @@ void caldav_xml_start(void *data, const char *el, const char **attr) {
 void caldav_xml_end(void *data, const char *el) {
        struct cr_params *crp = (struct cr_params *) data;
 
-       --crp->tag_nesting_level;
-
 #ifdef DEBUG_XML_PARSE
        // logging
        int i;
-       char indent[256];
-       indent[0] = 0;
-       for (i=0; i<crp->tag_nesting_level; ++i) {
-               strcat(indent, "  ");
-       }
-       syslog(LOG_DEBUG, "%s</%s>", indent, el);
+       syslog(LOG_DEBUG, "</%s>", el);
        // end logging
 #endif
 
+       if (!strcasecmp(el, CAL"comp-filter")) {
+               --crp->comp_filter_nesting_level;
+       }
+
+
        if ((!strcasecmp(el, "DAV::href")) || (!strcasecmp(el, "DAV:href"))) {
                if (crp->Hrefs == NULL) {       // append crp->Chardata to crp->Hrefs
                        crp->Hrefs = NewStrBuf();
@@ -156,12 +145,7 @@ void caldav_xml_chardata(void *data, const XML_Char *s, int len) {
        string_trim(app);               // remove leading/trailing whitespace.  ok to mangle it because we've already appended.
        if (!IsEmptyStr(app)) {
                int i;
-               char indent[256];
-               indent[0] = 0;
-               for (i=0; i<crp->tag_nesting_level; ++i) {
-                       strcat(indent, "  ");
-               }
-               syslog(LOG_DEBUG, "%s%s", indent, app, len);
+               syslog(LOG_DEBUG, "%s", app, len);
        }
        // end logging
 #endif
index 03efc5e816eaeed44340d7d85ec176c62ca45733..4c5c1588a268ac82d5bd60a91c93c272c670ac52 100644 (file)
@@ -9,7 +9,7 @@
 //#define DEBUG_HTTP
 //#define REQUEST_BODY_TO_STDERR
 //#define RESPONSE_BODY_TO_STDERR
-//#define DEBUG_XML_PARSE
+#define DEBUG_XML_PARSE
 
 #define SHOW_ME_VAPPEND_PRINTF