Final changes to XML parser trace logging.
authorArt Cancro <ajc@citadel.org>
Mon, 12 Feb 2024 19:41:12 +0000 (14:41 -0500)
committerArt Cancro <ajc@citadel.org>
Mon, 12 Feb 2024 19:41:12 +0000 (14:41 -0500)
This is extremely inefficient code, but it will be ifdef'ed out
during normal use.  Like the rest of the protocol trace options,
they are only getting ifdef'ed into use while I am developing.

webcit-ng/server/caldav_reports.c

index 15a05dccf50c6e63de5d2237b434af6729ee365a..5883c73470bc7d1d306854e9aea75951ab7b478b 100644 (file)
@@ -37,6 +37,11 @@ void caldav_xml_start(void *data, const char *el, const char **attr) {
                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, "%sAttribute '%s' = '%s'", indent, attr[i], attr[i + 1]);
        }
@@ -58,7 +63,6 @@ void caldav_xml_start(void *data, const char *el, const char **attr) {
                crp->report_type = cr_freebusy_query;
        }
 
-       ++crp->tag_nesting_level;
 }
 
 
@@ -108,25 +112,28 @@ void caldav_xml_chardata(void *data, const XML_Char *s, int len) {
        memcpy(app, s, len);
        app[len] = 0;
 
+       if (crp->Chardata == NULL) {
+               crp->Chardata = NewStrBuf();
+       }
+
+       StrBufAppendBufPlain(crp->Chardata, app, len, 0);
+
 #ifdef DEBUG_XML_PARSE
        // logging
-       int i;
-       char indent[256];
-       indent[0] = 0;
-       for (i=0; i<crp->tag_nesting_level; ++i) {
-               strcat(indent, "··");
+       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%s", indent, app, len);
        // end logging
 #endif
 
-       if (crp->Chardata == NULL) {
-               crp->Chardata = NewStrBuf();
-       }
-
-       StrBufAppendBufPlain(crp->Chardata, app, len, 0);
        free(app);
-
        return;
 }