libidav/xml.c

Thu, 28 Nov 2024 17:18:43 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 28 Nov 2024 17:18:43 +0100
changeset 848
b71598a22e11
parent 816
839fefbdedc7
permissions
-rw-r--r--

fix property set/remove list size checks

331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
404
5c08b8e14df8 updates copyright notice
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 373
diff changeset
4 * Copyright 2018 Olaf Wintermann. All rights reserved.
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
33 #include <cx/utils.h>
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
34 #include <cx/printf.h>
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
35
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "xml.h"
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 static DavXmlNodeType convert_type(xmlElementType type) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 DavXmlNodeType ct;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 switch(type) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 default: ct = DAV_XML_NONE; break;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 case XML_ELEMENT_NODE: ct = DAV_XML_ELEMENT; break;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 case XML_TEXT_NODE: ct = DAV_XML_TEXT;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 return ct;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 typedef struct {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 xmlNode *node;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 DavXmlNode *parent;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 } ConvXmlElm;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 DavXmlNode* dav_convert_xml(DavSession *sn, xmlNode *node) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 if(!node) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 return NULL;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 DavXmlNodeType newnt = convert_type(node->type);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 if(newnt == DAV_XML_NONE) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 return NULL;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
62 const CxAllocator *a = sn->mp->allocator;
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
64 ConvXmlElm ce;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
65 ce.node = node;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
66 ce.parent = NULL;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
67 CxList *stack = cxLinkedListCreate(cxDefaultAllocator, NULL, sizeof(ConvXmlElm));
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
68 if(!stack) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
69 return NULL;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
70 }
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
71 cxListInsert(stack, 0, &ce);
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 DavXmlNode *ret = NULL;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
75 while(cxListSize(stack) > 0) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
76 ConvXmlElm *c = cxListAt(stack, 0);
756
ea0e059bae72 fix UAF in dav xml converter
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
77 xmlNode *n = c->node;
ea0e059bae72 fix UAF in dav xml converter
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
78 DavXmlNode *c_parent = c->parent;
ea0e059bae72 fix UAF in dav xml converter
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
79 DavXmlNode *prev = NULL;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
80 cxListRemove(stack, 0);
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 while(n) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
82 DavXmlNode *newxn = cxCalloc(a, 1, sizeof(DavXmlNode));
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 if(!ret) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 ret = newxn;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 newxn->type = convert_type(n->type);
756
ea0e059bae72 fix UAF in dav xml converter
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
87 newxn->parent = c_parent;
ea0e059bae72 fix UAF in dav xml converter
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
88 if(c_parent && !c_parent->children) {
ea0e059bae72 fix UAF in dav xml converter
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
89 c_parent->children = newxn;
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 newxn->prev = prev;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 if(prev) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 prev->next = newxn;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 if(newxn->type == DAV_XML_ELEMENT) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 newxn->name = dav_session_strdup(sn, (char*)n->name);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 if(n->ns && n->ns->href) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 newxn->namespace = dav_session_strdup(sn, (char*)n->ns->href);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101
520
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
102 xmlAttr *attr = n->properties;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
103 DavXmlAttr *newattr = NULL;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
104 DavXmlAttr *newattr_last = NULL;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
105 while(attr) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
106 DavXmlAttr *na = cxCalloc(a, 1, sizeof(DavXmlAttr));
520
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
107 na->name = dav_session_strdup(sn, (char*)attr->name);
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
108 if(attr->children && attr->children->type == XML_TEXT_NODE) {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
109 na->value = dav_session_strdup(sn, (char*)attr->children->content);
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
110 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
111 if(!newattr) {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
112 newattr = na;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
113 } else {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
114 newattr_last->next = na;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
115 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
116 newattr_last = na;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
117
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
118 attr = attr->next;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
119 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
120 newxn->attributes = newattr;
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 if(n->children) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
123 ConvXmlElm convc;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
124 convc.node = n->children;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
125 convc.parent = newxn;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
126 cxListInsert(stack, 0, &convc);
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 } else if(newxn->type == DAV_XML_TEXT) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
129 cxmutstr content = cx_strdup_a(a, cx_str((char*)n->content));
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 newxn->content = content.ptr;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 newxn->contentlength = content.length;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 prev = newxn;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 n = n->next;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 return ret;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 void dav_print_xml(DavXmlNode *node) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 if(node->type == DAV_XML_ELEMENT) {
520
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
144 printf("<%s", node->name);
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
145 DavXmlAttr *attr = node->attributes;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
146 while(attr) {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
147 printf(" %s=\"%s\"", attr->name, attr->value);
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
148 attr = attr->next;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
149 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
150 putchar('>');
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 DavXmlNode *child = node->children;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 if(child) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 dav_print_xml(child);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 printf("</%s>", node->name);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 } else {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 fwrite(node->content, 1, node->contentlength, stdout);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 fflush(stdout);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 if(node->next) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 dav_print_xml(node->next);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
167 void dav_print_node(void *stream, cx_write_func writef, CxMap *nsmap, DavXmlNode *node) {
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
168 while(node) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
169 if(node->type == DAV_XML_ELEMENT) {
520
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
170 char *tagend = node->children ? ">" : " />";
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
171 char *prefix = NULL;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
172 char *prefix_fr = NULL;
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
173 if(node->namespace) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
174 prefix = cxMapGet(nsmap, cx_hash_key_str(node->namespace));
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
175 if(!prefix) {
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
176 cxmutstr newpre = cx_asprintf("x%zu", cxMapSize(nsmap)+1);
848
b71598a22e11 fix property set/remove list size checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
177 // TODO: fix
b71598a22e11 fix property set/remove list size checks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
178 //cxMapPut(nsmap, node->namespace, newpre.ptr);
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
179 prefix = newpre.ptr;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
180 prefix_fr = prefix;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
181 cx_fprintf(
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
182 stream,
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
183 writef,
588
0cfe006fcad2 fix dav_print_node
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
184 "<%s:%s xmlns:%s=\"%s\"",
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
185 prefix,
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
186 node->name,
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
187 prefix,
588
0cfe006fcad2 fix dav_print_node
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
188 node->namespace);
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
189 } else {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
190 cx_fprintf(stream, writef, "<%s:%s", prefix, node->name);
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
191 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
192 } else {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
193 cx_fprintf(stream, writef, "<%s", node->name);
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
194 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
195
520
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
196 DavXmlAttr *attr = node->attributes;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
197 while(attr) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
198 cx_fprintf(stream, writef, " %s=\"%s\"", attr->name, attr->value);
520
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
199 attr = attr->next;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
200 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
201 writef(tagend, 1, strlen(tagend), stream); // end xml tag
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
202
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
203 if(node->children) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
204 dav_print_node(stream, writef, nsmap, node->children);
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
205 if(prefix) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
206 cx_fprintf(stream, writef, "</%s:%s>", prefix, node->name);
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
207 } else {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
208 cx_fprintf(stream, writef, "</%s>", node->name);
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
209 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
210 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
211
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
212 if(prefix_fr) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
213 free(prefix_fr);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
214 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
215 } else if(node->type == DAV_XML_TEXT) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
216 writef(node->content, 1, node->contentlength, stream);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
217 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
218
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
219 node = node->next;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
220 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
221 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
222
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 /* ------------------------- public API ------------------------- */
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 char* dav_xml_getstring(DavXmlNode *node) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 if(node && node->type == DAV_XML_TEXT) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 return node->content;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 } else {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 return NULL;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232
338
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
233 DavBool dav_xml_isstring(DavXmlNode *node) {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
234 if(node && node->type == DAV_XML_TEXT && !node->next) {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
235 return TRUE;
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
236 } else {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
237 return FALSE;
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
238 }
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
239 }
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
240
373
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
241 DavXmlNode* dav_xml_nextelm(DavXmlNode *node) {
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
242 node = node->next;
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
243 while(node) {
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
244 if(node->type == DAV_XML_ELEMENT) {
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
245 return node;
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
246 }
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
247 node = node->next;
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
248 }
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
249 return NULL;
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
250 }
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
251
736
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
252 DavXmlNode* dav_text_node(DavSession *sn, const char *text) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
253 const CxAllocator *a = sn->mp->allocator;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
254 DavXmlNode *newxn = cxCalloc(a, 1, sizeof(DavXmlNode));
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 newxn->type = DAV_XML_TEXT;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
256 cxmutstr content = cx_strdup_a(a, cx_str(text));
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 newxn->content = content.ptr;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 newxn->contentlength = content.length;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 return newxn;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261
736
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
262 DavXmlNode* dav_text_element(DavSession *sn, const char *ns, const char *name, const char *text) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
263 const CxAllocator *a = sn->mp->allocator;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
264 DavXmlNode *newelm = cxCalloc(a, 1, sizeof(DavXmlNode));
736
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
265 newelm->type = DAV_XML_ELEMENT;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
266 newelm->namespace = cx_strdup_a(a, cx_str(ns)).ptr;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
267 newelm->name = cx_strdup_a(a, cx_str(name)).ptr;
736
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
268 newelm->children = dav_text_node(sn, text);
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
269 return newelm;
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
270 }
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
271
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
272 static void dav_free_xml_node_a(const CxAllocator *a, DavXmlNode *node) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
273 if(node->name) cxFree(a, node->name);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
274 if(node->namespace) cxFree(a, node->namespace);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
275 if(node->content) cxFree(a, node->content);
736
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
276 DavXmlAttr *attr = node->attributes;
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
277 while(attr) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
278 if(attr->name) cxFree(a, attr->name);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
279 if(attr->value) cxFree(a, attr->value);
736
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
280 attr = attr->next;
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
281 }
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
282 DavXmlNode *children = node->children;
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
283 while(children) {
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
284 DavXmlNode *next_ch = children->next;
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
285 dav_free_xml_node_a(a, children);
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
286 children = next_ch;
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
287 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
288 cxFree(a, node);
736
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
289 }
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
290
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
291 void dav_free_xml_node_sn(DavSession *sn, DavXmlNode *node) {
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
292 dav_free_xml_node_a(sn->mp->allocator, node);
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
293 }
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
294
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
295 void dav_free_xml_node(DavXmlNode *node) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
296 dav_free_xml_node_a(cxDefaultAllocator, node);
736
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 666
diff changeset
297 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
298
532
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
299 DavXmlAttr* dav_copy_xml_attr(DavXmlAttr *attr) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
300 if(!attr) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
301 return NULL;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
302 }
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
303 DavXmlAttr *newattr = NULL;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
304 DavXmlAttr *prev = NULL;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
305 while(attr) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
306 DavXmlAttr *n = calloc(1, sizeof(DavXmlAttr));
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
307 n->name = strdup(attr->name);
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
308 n->value = strdup(attr->value);
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
309 if(prev) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
310 prev->next = n;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
311 } else {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
312 newattr = n;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
313 }
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
314 prev = n;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
315 attr = attr->next;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
316 }
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
317 return newattr;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
318 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
319
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
320 DavXmlNode* dav_copy_node(DavXmlNode *node) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
321 DavXmlNode *ret = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
322 DavXmlNode *prev = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
323 while(node) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
324 DavXmlNode *copy = calloc(1, sizeof(DavXmlNode));
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
325 copy->type = node->type;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
326 if(node->type == DAV_XML_ELEMENT) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
327 copy->namespace = strdup(node->namespace);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
328 copy->name = strdup(node->name);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
329 copy->children = dav_copy_node(node->children);
532
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
330 copy->attributes = dav_copy_xml_attr(node->attributes);
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
331 } else {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
332 copy->contentlength = node->contentlength;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
333 copy->content = malloc(node->contentlength+1);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
334 memcpy(copy->content, node->content, node->contentlength);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
335 copy->content[copy->contentlength] = 0;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
336 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
337 if(!ret) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
338 ret = copy;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
339 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
340 if(prev) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
341 prev->next = copy;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
342 copy->prev = prev;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
343 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
344 prev = copy;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
345 node = node->next;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
346 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
347 return ret;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
348 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
349
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
350
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
351 DavXmlNode* dav_xml_createnode(const char *ns, const char *name) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
352 DavXmlNode *node = calloc(1, sizeof(DavXmlNode));
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
353 node->type = DAV_XML_ELEMENT;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
354 node->namespace = strdup(ns);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
355 node->name = strdup(name);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
356 return node;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
357 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
358
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
359 DavXmlNode* dav_xml_createnode_with_text(const char *ns, const char *name, const char *text) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
360 DavXmlNode *node = calloc(1, sizeof(DavXmlNode));
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
361 node->type = DAV_XML_ELEMENT;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
362 node->namespace = strdup(ns);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
363 node->name = strdup(name);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
364
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
365 DavXmlNode *textnode = dav_xml_createtextnode(text);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
366 node->children = textnode;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
367
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
368 return node;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
369 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
370
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
371 DavXmlNode* dav_xml_createtextnode(const char *text) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
372 DavXmlNode *node = calloc(1, sizeof(DavXmlNode));
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
373 node->type = DAV_XML_TEXT;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 736
diff changeset
374 cxmutstr content = cx_strdup(cx_str((char*)text));
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
375 node->content = content.ptr;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
376 node->contentlength = content.length;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
377 return node;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
378 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
379
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
380 void dav_xml_add_child(DavXmlNode *node, DavXmlNode *child) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
381 DavXmlNode *last_child = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
382 DavXmlNode *c = node->children;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
383 while(c) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
384 last_child = c;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
385 c = c->next;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
386 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
387 if(last_child) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
388 last_child->next = child;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
389 child->prev = last_child;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
390 } else {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
391 node->children = child;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
392 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
393 }
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
394
520
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
395 void dav_xml_add_attr(DavXmlNode *node, const char *name, const char *value) {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
396 DavXmlAttr *attr = calloc(1, sizeof(DavXmlAttr));
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
397 attr->name = strdup(name);
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
398 attr->value = strdup(value);
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
399
789
378b5ab86f77 add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 756
diff changeset
400 if(node->attributes) {
520
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
401 DavXmlAttr *end = node->attributes;
789
378b5ab86f77 add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 756
diff changeset
402 DavXmlAttr* last = end;
520
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
403 while(end) {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
404 last = end;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
405 end = end->next;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
406 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
407 last->next = attr;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
408 } else {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
409 node->attributes = attr;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
410 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
411 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
412
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
413 char* dav_xml_get_attr(DavXmlNode *node, const char *name) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
414 DavXmlAttr *attr = node->attributes;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
415 while(attr) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
416 if(!strcmp(attr->name, name)) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
417 return attr->value;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
418 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
419
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
420 attr = attr->next;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
421 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
422 return NULL;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
423 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
424
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
425 DavXmlNode* dav_parse_xml(DavSession *sn, const char *str, size_t len) {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
426 xmlDoc *doc = xmlReadMemory(str, len, NULL, NULL, 0);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
427 if(!doc) {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
428 return NULL;
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
429 }
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
430 xmlNode *xml_root = xmlDocGetRootElement(doc);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
431 if(!xml_root) {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
432 xmlFreeDoc(doc);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
433 return NULL;
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
434 }
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
435 DavXmlNode *x = dav_convert_xml(sn, xml_root);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
436 xmlFreeDoc(doc);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
437 return x;
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
438 }

mercurial