dav info prints simplified xml values

Sun, 29 Apr 2018 11:16:41 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 29 Apr 2018 11:16:41 +0200
changeset 373
dcc03142eb5f
parent 372
2e15ff88a0ab
child 374
38ae05d46f9a

dav info prints simplified xml values

dav/main.c file | annotate | diff | comparison | revisions
dav/tags.c file | annotate | diff | comparison | revisions
libidav/methods.c file | annotate | diff | comparison | revisions
libidav/webdav.h file | annotate | diff | comparison | revisions
libidav/xml.c file | annotate | diff | comparison | revisions
--- a/dav/main.c	Sun Apr 01 12:40:48 2018 +0200
+++ b/dav/main.c	Sun Apr 29 11:16:41 2018 +0200
@@ -1685,6 +1685,14 @@
     return count;
 }
 
+void print_xml_infostr(DavXmlNode *xml) {
+    if(xml->children) {
+        printf("<%s>...</%s>", xml->name, xml->name);
+    } else {
+        printf("<%s/>", xml->name);
+    }
+}
+
 int cmd_info(CmdArgs *a) {
     if(a->argc < 1) {
         fprintf(stderr, "Too few arguments\n");
@@ -1738,7 +1746,25 @@
                 sstr_t value = sstr(dav_xml_getstring(xval));
                 printf("  %s: %.*s\n", p.name, (int)value.length, value.ptr);
             } else {
-                printf("  %s: $xml\n", p.name);
+                // find some xml elements
+                printf("  %s: ", p.name);
+                DavXmlNode *x = xval->type == DAV_XML_ELEMENT ? xval : dav_xml_nextelm(xval);
+                for(int i=0;i<3;i++) {
+                    if(x) {
+                        if(i == 2) {
+                            printf(" ...");
+                            break;
+                        } else {
+                            print_xml_infostr(x);
+                        }
+                    } else {
+                        break;
+                    }
+                    x = dav_xml_nextelm(x);
+                }
+                printf("\n");
+                
+                
             }
         }
 
--- a/dav/tags.c	Sun Apr 01 12:40:48 2018 +0200
+++ b/dav/tags.c	Sun Apr 29 11:16:41 2018 +0200
@@ -297,9 +297,11 @@
 
 #else
 UcxList* parse_macos_taglist(const char *buf, size_t length) {
+    fprintf(stderr, "Error: macos tags not supported on this platform.\n");
     return NULL;
 }
 UcxBuffer* create_macos_taglist(UcxList *tags) {
+    fprintf(stderr, "Error: macos tags not supported on this platform.\n");
     return NULL;
 }
 #endif
--- a/libidav/methods.c	Sun Apr 01 12:40:48 2018 +0200
+++ b/libidav/methods.c	Sun Apr 29 11:16:41 2018 +0200
@@ -742,7 +742,7 @@
     CURLcode ret = dav_session_curl_perform_buf(sn, request, response, NULL);
     curl_slist_free_all(headers);
     
-    printf("proppatch: \n%.*s\n", request->size, request->space);
+    //printf("proppatch: \n%.*s\n", request->size, request->space);
     
     return ret;
 }
--- a/libidav/webdav.h	Sun Apr 01 12:40:48 2018 +0200
+++ b/libidav/webdav.h	Sun Apr 29 11:16:41 2018 +0200
@@ -312,6 +312,7 @@
 /* ------------------------ xml functions ------------------------ */
 char* dav_xml_getstring(DavXmlNode *node);
 DavBool dav_xml_isstring(DavXmlNode *node);
+DavXmlNode* dav_xml_nextelm(DavXmlNode *node);
 DavXmlNode* dav_text_node(DavSession *sn, char *text);
 
 DavXmlNode* dav_copy_node(DavXmlNode *node);
--- a/libidav/xml.c	Sun Apr 01 12:40:48 2018 +0200
+++ b/libidav/xml.c	Sun Apr 29 11:16:41 2018 +0200
@@ -198,6 +198,17 @@
     }
 }
 
+DavXmlNode* dav_xml_nextelm(DavXmlNode *node) {
+    node = node->next;
+    while(node) {
+        if(node->type == DAV_XML_ELEMENT) {
+            return node;
+        }
+        node = node->next;
+    }
+    return NULL;
+}
+
 DavXmlNode* dav_text_node(DavSession *sn, char *text) {
     UcxMempool *mp = sn->mp; 
     DavXmlNode *newxn = ucx_mempool_calloc(mp, 1, sizeof(DavXmlNode));

mercurial