Improved logging of XML parse
authorArt Cancro <ajc@citadel.org>
Sat, 10 Feb 2024 19:17:33 +0000 (14:17 -0500)
committerArt Cancro <ajc@citadel.org>
Sat, 10 Feb 2024 19:17:33 +0000 (14:17 -0500)
webcit-ng/server/caldav_reports.c
webcit-ng/server/webcit.h

index 1c95c380652d39abfd84dbf2ab745f627aba7fcd..e6a13cef009f3e0eaff57442ea878221d6ff9433 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,21 @@ 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);
        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")) {
@@ -61,12 +65,23 @@ void caldav_xml_start(void *data, const char *el, const char **attr) {
 // XML parser callback
 void caldav_xml_end(void *data, const char *el) {
        struct cr_parms *crp = (struct cr_parms *) 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, "  ");
+       }
        if (crp->Chardata != NULL) {
-               // syslog(LOG_DEBUG, "CALDAV CHARDATA     : %s", ChrPtr(crp->Chardata));
+               syslog(LOG_DEBUG, "%sCHARDATA: '%s'", indent, ChrPtr(crp->Chardata));
        }
-       // 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
index b5b8bb2e34a8ee823b5810d4dd9404ac039e1086..a773a32c57127eed94a3465b8ed08bed262b2149 100644 (file)
@@ -6,9 +6,10 @@
 // disclosure is subject to the GNU General Public License v3.
 
 // uncomment one or more of these to see raw http transactions
-#define DEBUG_HTTP
-#define REQUEST_BODY_TO_STDERR
+//#define DEBUG_HTTP
+//#define REQUEST_BODY_TO_STDERR
 //#define RESPONSE_BODY_TO_STDERR
+#define DEBUG_XML_PARSE
 
 #define SHOW_ME_VAPPEND_PRINTF