libidav/xml.c

Wed, 02 Nov 2022 11:34:49 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 02 Nov 2022 11:34:49 +0100
changeset 739
bba6a6e221b4
parent 736
40be8db6fe45
child 747
efbd59642577
permissions
-rw-r--r--

use sys_* io functions in dav put

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
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
33 #include <ucx/utils.h>
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
34
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "xml.h"
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 static DavXmlNodeType convert_type(xmlElementType type) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 DavXmlNodeType ct;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 switch(type) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 default: ct = DAV_XML_NONE; break;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 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
42 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
43 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 return ct;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 }
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 typedef struct {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 xmlNode *node;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 DavXmlNode *parent;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 } ConvXmlElm;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 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
53 if(!node) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 return NULL;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 DavXmlNodeType newnt = convert_type(node->type);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 if(newnt == DAV_XML_NONE) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 return NULL;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 }
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 UcxMempool *mp = sn->mp;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 ConvXmlElm *ce = malloc(sizeof(ConvXmlElm));
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 ce->node = node;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 ce->parent = NULL;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 UcxList *stack = ucx_list_prepend(NULL, ce);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 DavXmlNode *ret = NULL;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 while(stack) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 ConvXmlElm *c = stack->data;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 stack = ucx_list_remove(stack, stack);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 xmlNode *n = c->node;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 DavXmlNode *prev = NULL;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 while(n) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 DavXmlNode *newxn = ucx_mempool_calloc(mp, 1, sizeof(DavXmlNode));
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 if(!ret) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 ret = newxn;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 newxn->type = convert_type(n->type);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 newxn->parent = c->parent;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 if(c->parent && !c->parent->children) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 c->parent->children = 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->prev = prev;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 if(prev) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 prev->next = newxn;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 }
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 if(newxn->type == DAV_XML_ELEMENT) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 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
93 if(n->ns && n->ns->href) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 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
95 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
520
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
97 xmlAttr *attr = n->properties;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
98 DavXmlAttr *newattr = NULL;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
99 DavXmlAttr *newattr_last = NULL;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
100 while(attr) {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
101 DavXmlAttr *na = ucx_mempool_calloc(mp, 1, sizeof(DavXmlAttr));
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
102 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
103 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
104 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
105 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
106 if(!newattr) {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
107 newattr = na;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
108 } else {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
109 newattr_last->next = na;
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 newattr_last = na;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
112
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
113 attr = attr->next;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
114 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
115 newxn->attributes = newattr;
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 if(n->children) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 ConvXmlElm *convc = malloc(sizeof(ConvXmlElm));
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 convc->node = n->children;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 convc->parent = newxn;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 stack = ucx_list_prepend(stack, convc);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 } else if(newxn->type == DAV_XML_TEXT) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 sstr_t content = sstrdup_a(mp->allocator, sstr((char*)n->content));
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 newxn->content = content.ptr;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 newxn->contentlength = content.length;
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
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 prev = newxn;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 n = n->next;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 }
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 free(c);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 return ret;
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 void dav_print_xml(DavXmlNode *node) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 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
141 printf("<%s", node->name);
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
142 DavXmlAttr *attr = node->attributes;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
143 while(attr) {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
144 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
145 attr = attr->next;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
146 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
147 putchar('>');
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 DavXmlNode *child = node->children;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 if(child) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 dav_print_xml(child);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 printf("</%s>", node->name);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 } else {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 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
157 fflush(stdout);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 if(node->next) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 dav_print_xml(node->next);
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 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
164 void dav_print_node(void *stream, write_func writef, UcxMap *nsmap, DavXmlNode *node) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
165 while(node) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
166 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
167 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
168 char *prefix = NULL;
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
169 if(node->namespace) {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
170 prefix = ucx_map_cstr_get(nsmap, node->namespace);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
171 if(!prefix) {
666
97061483d06e fix xml generation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 588
diff changeset
172 sstr_t newpre = ucx_sprintf("x%d", (int)nsmap->count+1);
97061483d06e fix xml generation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 588
diff changeset
173 // TODO: fix namespace declaration
97061483d06e fix xml generation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 588
diff changeset
174 //ucx_map_cstr_put(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
175 prefix = newpre.ptr;
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
176 ucx_fprintf(
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
177 stream,
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
178 writef,
588
0cfe006fcad2 fix dav_print_node
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
179 "<%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
180 prefix,
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
181 node->name,
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
182 prefix,
588
0cfe006fcad2 fix dav_print_node
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
183 node->namespace);
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
184 } else {
520
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
185 ucx_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
186 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
187 } else {
520
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
188 ucx_fprintf(stream, writef, "<%s", node->name);
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
189 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
190
520
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
191 DavXmlAttr *attr = node->attributes;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
192 while(attr) {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
193 ucx_fprintf(stream, writef, " %s=\"%s\"", attr->name, attr->value);
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
194 attr = attr->next;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
195 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
196 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
197
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
198 if(node->children) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
199 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
200 if(prefix) {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
201 ucx_fprintf(stream, writef, "</%s:%s>", prefix, node->name);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
202 } else {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
203 ucx_fprintf(stream, writef, "</%s>", node->name);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
204 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
205 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
206 } else if(node->type == DAV_XML_TEXT) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
207 writef(node->content, 1, node->contentlength, stream);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
208 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
209
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
210 node = node->next;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
211 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
212 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
213
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 /* ------------------------- public API ------------------------- */
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 char* dav_xml_getstring(DavXmlNode *node) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 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
218 return node->content;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 } else {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 return NULL;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223
338
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
224 DavBool dav_xml_isstring(DavXmlNode *node) {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
225 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
226 return TRUE;
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
227 } else {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
228 return FALSE;
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
229 }
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
230 }
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
231
373
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
232 DavXmlNode* dav_xml_nextelm(DavXmlNode *node) {
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
233 node = node->next;
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
234 while(node) {
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
235 if(node->type == DAV_XML_ELEMENT) {
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
236 return node;
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
237 }
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
238 node = node->next;
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
239 }
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
240 return NULL;
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
241 }
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
242
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
243 DavXmlNode* dav_text_node(DavSession *sn, const char *text) {
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 UcxMempool *mp = sn->mp;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 DavXmlNode *newxn = ucx_mempool_calloc(mp, 1, sizeof(DavXmlNode));
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 newxn->type = DAV_XML_TEXT;
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
247 sstr_t content = scstrdup_a(mp->allocator, scstr(text));
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 newxn->content = content.ptr;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 newxn->contentlength = content.length;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 return newxn;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252
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
253 DavXmlNode* dav_text_element(DavSession *sn, const char *ns, const char *name, const char *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
254 UcxMempool *mp = sn->mp;
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
255 DavXmlNode *newelm = ucx_mempool_calloc(mp, 1, sizeof(DavXmlNode));
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
256 newelm->type = DAV_XML_ELEMENT;
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
257 newelm->namespace = scstrdup_a(mp->allocator, scstr(ns)).ptr;
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
258 newelm->name = scstrdup_a(mp->allocator, scstr(name)).ptr;
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
259 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
260 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
261 }
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
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
263 static void dav_free_xml_node_a(UcxAllocator *a, 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
264 if(node->name) alfree(a, node->name);
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 if(node->namespace) alfree(a, node->namespace);
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
266 if(node->content) alfree(a, node->content);
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
267 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
268 while(attr) {
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 if(attr->name) alfree(a, attr->name);
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 if(attr->value) alfree(a, attr->value);
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 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
272 }
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
273 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
274 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
275 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
276 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
277 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
278 }
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
279 alfree(a, 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
280 }
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 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
283 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
284 }
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
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 void dav_free_xml_node(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
287 dav_free_xml_node_a(ucx_default_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
288 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
289
532
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
290 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
291 if(!attr) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
292 return NULL;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
293 }
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
294 DavXmlAttr *newattr = NULL;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
295 DavXmlAttr *prev = NULL;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
296 while(attr) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
297 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
298 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
299 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
300 if(prev) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
301 prev->next = n;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
302 } else {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
303 newattr = n;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
304 }
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
305 prev = n;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
306 attr = attr->next;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
307 }
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
308 return newattr;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
309 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
310
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
311 DavXmlNode* dav_copy_node(DavXmlNode *node) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
312 DavXmlNode *ret = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
313 DavXmlNode *prev = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
314 while(node) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
315 DavXmlNode *copy = calloc(1, sizeof(DavXmlNode));
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
316 copy->type = node->type;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
317 if(node->type == DAV_XML_ELEMENT) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
318 copy->namespace = strdup(node->namespace);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
319 copy->name = strdup(node->name);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
320 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
321 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
322 } else {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
323 copy->contentlength = node->contentlength;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
324 copy->content = malloc(node->contentlength+1);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
325 memcpy(copy->content, node->content, node->contentlength);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
326 copy->content[copy->contentlength] = 0;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
327 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
328 if(!ret) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
329 ret = copy;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
330 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
331 if(prev) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
332 prev->next = copy;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
333 copy->prev = prev;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
334 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
335 prev = copy;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
336 node = node->next;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
337 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
338 return ret;
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
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
341
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
342 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
343 DavXmlNode *node = calloc(1, sizeof(DavXmlNode));
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
344 node->type = DAV_XML_ELEMENT;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
345 node->namespace = strdup(ns);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
346 node->name = strdup(name);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
347 return node;
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 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
351 DavXmlNode *node = calloc(1, sizeof(DavXmlNode));
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
352 node->type = DAV_XML_ELEMENT;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
353 node->namespace = strdup(ns);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
354 node->name = strdup(name);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
355
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
356 DavXmlNode *textnode = dav_xml_createtextnode(text);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
357 node->children = textnode;
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 return node;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
360 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
362 DavXmlNode* dav_xml_createtextnode(const char *text) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
363 DavXmlNode *node = calloc(1, sizeof(DavXmlNode));
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
364 node->type = DAV_XML_TEXT;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
365 sstr_t content = sstrdup(sstr((char*)text));
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
366 node->content = content.ptr;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
367 node->contentlength = content.length;
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 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
372 DavXmlNode *last_child = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
373 DavXmlNode *c = node->children;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
374 while(c) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
375 last_child = c;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
376 c = c->next;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
377 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
378 if(last_child) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
379 last_child->next = child;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
380 child->prev = last_child;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
381 } else {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
382 node->children = child;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
383 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
384 }
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
385
520
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
386 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
387 DavXmlAttr *attr = calloc(1, sizeof(DavXmlAttr));
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
388 attr->name = strdup(name);
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
389 attr->value = strdup(value);
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
390
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
391 if(node->attributes) {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
392 DavXmlAttr *last;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
393 DavXmlAttr *end = node->attributes;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
394 while(end) {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
395 last = end;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
396 end = end->next;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
397 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
398 last->next = attr;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
399 } else {
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
400 node->attributes = attr;
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
401 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
402 }
da2b0cc44e4f adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
403
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
404 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
405 DavXmlAttr *attr = node->attributes;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
406 while(attr) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
407 if(!strcmp(attr->name, name)) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
408 return attr->value;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
409 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
410
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
411 attr = attr->next;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
412 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
413 return NULL;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
414 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 520
diff changeset
415
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
416 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
417 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
418 if(!doc) {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
419 return NULL;
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
420 }
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
421 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
422 if(!xml_root) {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
423 xmlFreeDoc(doc);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
424 return NULL;
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
425 }
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
426 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
427 xmlFreeDoc(doc);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
428 return x;
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
429 }

mercurial