Final changes to XML parser trace logging.
[citadel.git] / webcit-ng / server / caldav_reports.c
index 1c95c380652d39abfd84dbf2ab745f627aba7fcd..5883c73470bc7d1d306854e9aea75951ab7b478b 100644 (file)
@@ -1,10 +1,6 @@
-// This file contains functions which handle all of the CalDAV "REPORT" queries
-// specified in RFC4791 section 7.
-//
+// This file contains functions which handle all of the CalDAV "REPORT" queries specified in RFC4791 section 7.
 // Copyright (c) 2023-2024 by the citadel.org team
-//
-// This program is open source software.  Use, duplication, or
-// disclosure is subject to the GNU General Public License v3.
+// This program is open source software.  Use, duplication, or disclosure is subject to the GNU General Public License v3.
 
 #include "webcit.h"
 
@@ -31,13 +27,26 @@ struct cr_parms {
 // XML parser callback
 void caldav_xml_start(void *data, const char *el, const char **attr) {
        struct cr_parms *crp = (struct cr_parms *) data;
-       int i;
-
-       // syslog(LOG_DEBUG, "CALDAV ELEMENT START: <%s> %d", el, 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);
+       ++crp->tag_nesting_level;
+       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, "                    Attribute '%s' = '%s'", attr[i], attr[i + 1]);
+               syslog(LOG_DEBUG, "%sAttribute '%s' = '%s'", indent, attr[i], attr[i + 1]);
        }
+       // end logging
+#endif
 
        // RFC4791 7.8 "calendar-query" REPORT - Client will send a lot of search criteria.
        if (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:calendar-query")) {
@@ -54,19 +63,26 @@ void caldav_xml_start(void *data, const char *el, const char **attr) {
                crp->report_type = cr_freebusy_query;
        }
 
-       ++crp->tag_nesting_level;
 }
 
 
 // XML parser callback
 void caldav_xml_end(void *data, const char *el) {
        struct cr_parms *crp = (struct cr_parms *) data;
+
        --crp->tag_nesting_level;
 
-       if (crp->Chardata != NULL) {
-               // syslog(LOG_DEBUG, "CALDAV CHARDATA     : %s", ChrPtr(crp->Chardata));
+#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, "CALDAV ELEMENT END  : <%s> %d", el, crp->tag_nesting_level);
+       syslog(LOG_DEBUG, "%s</%s>", indent, el);
+       // end logging
+#endif
 
        if ((!strcasecmp(el, "DAV::href")) || (!strcasecmp(el, "DAV:href"))) {
                if (crp->Hrefs == NULL) {       // append crp->Chardata to crp->Hrefs
@@ -86,15 +102,38 @@ void caldav_xml_end(void *data, const char *el) {
 
 
 // XML parser callback
-void caldav_xml_chardata(void *data, const XML_Char * s, int len) {
+void caldav_xml_chardata(void *data, const XML_Char *s, int len) {
        struct cr_parms *crp = (struct cr_parms *) data;
 
+       char *app = malloc(len+1);
+       if (!app) {
+               return;
+       }
+       memcpy(app, s, len);
+       app[len] = 0;
+
        if (crp->Chardata == NULL) {
                crp->Chardata = NewStrBuf();
        }
 
-       StrBufAppendBufPlain(crp->Chardata, s, len, 0);
+       StrBufAppendBufPlain(crp->Chardata, app, len, 0);
+
+#ifdef DEBUG_XML_PARSE
+       // logging
+       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);
+       }
+       // end logging
+#endif
 
+       free(app);
        return;
 }