src/server/webdav/xml.c

Thu, 16 Jan 2020 22:28:22 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 16 Jan 2020 22:28:22 +0100
branch
webdav
changeset 226
49adcbd7d473
parent 225
e4f3e1433098
child 232
499711b2a970
permissions
-rw-r--r--

msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once

211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2019 Olaf Wintermann. All rights reserved.
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
225
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
33 #include <ucx/string.h>
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
34 #include <ucx/map.h>
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
35
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
36 #include "../util/util.h"
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
37
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "xml.h"
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
225
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
40 /* ------------------------ utils ------------------------ */
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
41
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
42 /*
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
43 * generates a string key for an xml namespace
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
44 * format: prefix '\0' href
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
45 */
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
46 static sstr_t namespace_key(UcxAllocator *a, WSNamespace *ns) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
47 sstr_t key = sstrcat_a(a, 3,
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
48 ns->prefix ? sstr((char*)ns->prefix) : S("\0"),
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
49 S("\0"),
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
50 sstr((char*)ns->href));
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
51 return key;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
52 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
53
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
54
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
55 /* ------------------------ wsxml_iterator ------------------------ */
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
56
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
57 typedef struct StackElm {
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
58 WSXmlNode *node; // list of nodes
224
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
59 //WSXmlNode *parent; // if not NULL, call endcb after node->next is NULL
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
60 int endonly;
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
61 struct StackElm *next;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
62 } StackElm;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
64 #define STACK_PUSH(stack, elm) if(stack) { elm->next = stack; } stack = elm;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
66 int wsxml_iterator(
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
67 pool_handle_t *pool,
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
68 WSXmlNode *node,
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
69 wsxml_func begincb,
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
70 wsxml_func endcb,
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
71 void *udata)
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
72 {
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
73 if(!node) {
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
74 return 0;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
75 }
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
76
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
77 StackElm *stack = pool_malloc(pool, sizeof(StackElm));
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
78 if(!stack) {
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
79 return 1; // OOM
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
80 }
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
81 stack->next = NULL;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
82 stack->node = node;
224
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
83 stack->endonly = 0;
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
84 //stack->parent = NULL;
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
85
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
86 int ret = 0;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
87 int br = 0;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
88 while(stack) {
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
89 StackElm *cur = stack;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
90 WSXmlNode *xmlnode = cur->node; // get top stack element
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
91 stack = cur->next; // and remove it
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
92 cur->next = NULL;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
93
224
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
94 while(xmlnode && !cur->endonly) {
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
95 // element begin callback
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
96 if(begincb(xmlnode, udata)) {
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
97 br = 1;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
98 break; // I don't like break with labels - is this wrong?
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
99 }
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
100
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
101 if(xmlnode->children) {
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
102 // put the children on the stack
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
103 // the next stack iteration will process the children
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
104 StackElm *newelm = pool_malloc(pool, sizeof(StackElm));
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
105 if(!newelm) {
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
106 ret = 1;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
107 br = 1;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
108 break;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
109 }
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
110 newelm->next = NULL;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
111 newelm->node = xmlnode->children;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
112 // setting the parent will make sure endcb will be called
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
113 // for the current xmlnode after all children are processed
224
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
114 //newelm->parent = xmlnode;
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
115 newelm->endonly = 0;
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
116
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
117 // if xmlnode->next is not NULL, there are still nodes at
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
118 // this level, therefore we have to put these also on the
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
119 // stack
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
120 // this way, the remaining nodes are processed after all
224
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
121 // children and the end tag are processed
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
122 if(xmlnode->next) {
224
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
123 StackElm *nextelm = pool_malloc(pool, sizeof(StackElm));
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
124 if(!nextelm) {
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
125 ret = 1;
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
126 br = 1;
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
127 break;
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
128 }
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
129 nextelm->node = xmlnode->next;
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
130 nextelm->next = NULL;
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
131 nextelm->endonly = 0;
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
132 STACK_PUSH(stack, nextelm);
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
133 }
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
134
224
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
135 // we have to put the end tag of the current element
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
136 // on the stack to ensure endcb is called for the current
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
137 // element, after all children are processed
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
138 // reuse cur
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
139 cur->node = xmlnode;
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
140 cur->endonly = 1;
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
141 STACK_PUSH(stack, cur);
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
142
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
143 cur = NULL;
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
144
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
145 // now we can put the children on the stack
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
146 STACK_PUSH(stack, newelm);
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
147 // break, because we don't want to process xmlnode->next now
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
148 break;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
149 } else {
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
150 // no children means, the end callback can be called directly
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
151 // after the begin callback (no intermediate nodes)
224
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
152 cur->node = NULL;
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
153 if(endcb(xmlnode, udata)) {
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
154 br = 1;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
155 break;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
156 }
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
157 }
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
158
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
159 // continue with next node at this level
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
160 xmlnode = xmlnode->next;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
161 }
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
162 if(br) {
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
163 break; // break because of an error
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
164 }
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
165
224
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
166 if(cur && cur->node) {
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
167 //xmlNode *endNode = cur->parent ? cur->parent : cur->node;
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
168 xmlNode *endNode = cur->node;
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
169 if(endcb(endNode, udata)) {
0de1ec82628e add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
170 break;
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
171 }
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
172 pool_free(pool, cur);
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
173 }
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
174 }
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
175
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
176 // free all remaining elements
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
177 StackElm *elm = stack;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
178 while(elm) {
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
179 StackElm *next = elm->next;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
180 pool_free(pool, elm);
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
181 elm = next;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
182 }
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
183
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
184 return ret;
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
185 }
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
186
225
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
187 /* ------------------------ wsxml_get_namespaces ------------------------ */
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
188
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
189 typedef struct WSNsCollector {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
190 UcxAllocator *a;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
191 UcxMap *nsmap;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
192 WebdavNSList *def;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
193 int error;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
194 } WSNsCollector;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
195
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
196 static int nslist_node_begin(xmlNode *node, void *userdata) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
197 WSNsCollector *col = userdata;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
198 // namespace required for all elements
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
199 if(node->type == XML_ELEMENT_NODE && node->ns) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
200 // we create a list of unique prefix-href namespaces by putting
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
201 // all namespaces in a map
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
202 sstr_t nskey = namespace_key(col->a, node->ns);
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
203 if(!nskey.ptr) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
204 col->error = 1;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
205 return 1;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
206 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
207 if(ucx_map_sstr_put(col->nsmap, nskey, node->ns)) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
208 col->error = 1;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
209 return 1;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
210 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
211
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
212 // collect all namespace definitions for removing these namespaces
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
213 // from col->nsmap later
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
214 WSNamespace *def = node->nsDef;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
215 while(def) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
216 WebdavNSList *newdef = col->a->malloc(
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
217 col->a->pool, sizeof(WebdavNSList));
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
218 if(!newdef) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
219 col->error = 1;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
220 return 1;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
221 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
222 newdef->namespace = def;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
223 newdef->prev = NULL;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
224 newdef->next = NULL;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
225 // prepend newdef to the list
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
226 if(col->def) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
227 newdef->next = col->def;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
228 col->def->prev = newdef;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
229 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
230 col->def = newdef;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
231
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
232 // continue with next namespace definition
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
233 def = def->next;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
234 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
235 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
236 return 0;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
237 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
238
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
239 static int nslist_node_end(xmlNode *node, void *userdata) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
240 return 0;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
241 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
242
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
243 WebdavNSList* wsxml_get_required_namespaces(
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
244 pool_handle_t *pool,
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
245 WSXmlNode *node,
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
246 int *error)
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
247 {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
248 if(error) *error = 0;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
249
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
250 UcxAllocator a = util_pool_allocator(pool);
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
251 UcxMap *nsmap = ucx_map_new_a(&a, 16);
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
252 if(!nsmap) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
253 if(error) *error = 1;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
254 return NULL;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
255 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
256
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
257 WSNsCollector col;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
258 col.a = &a;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
259 col.nsmap = nsmap;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
260 col.def = NULL;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
261
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
262 // iterate over all xml elements
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
263 // this will fill the hashmap with all namespaces
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
264 // all namespace definitions are added to col.def
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
265 WebdavNSList *list = NULL;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
266 WebdavNSList *end = NULL;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
267 if(wsxml_iterator(pool, node, nslist_node_begin, nslist_node_end, &col)) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
268 if(error) *error = 1;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
269 } else {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
270 // remove all namespace definitions from the map
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
271 // what we get is a map that contains all missing namespace definitions
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
272 WebdavNSList *def = col.def;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
273 while(def) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
274 sstr_t nskey = namespace_key(&a, def->namespace);
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
275 if(!nskey.ptr) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
276 if(error) *error = 1;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
277 break;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
278 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
279 ucx_map_sstr_remove(nsmap, nskey);
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
280 def = def->next;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
281 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
282
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
283 // convert nsmap to a list
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
284 UcxMapIterator i = ucx_map_iterator(nsmap);
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
285 WSNamespace *ns;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
286 UCX_MAP_FOREACH(key, ns, i) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
287 WebdavNSList *newelm = pool_malloc(pool, sizeof(WebdavNSList));
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
288 if(!newelm) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
289 if(error) *error = 1;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
290 list = NULL;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
291 break;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
292 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
293 newelm->namespace = ns;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
294 newelm->next = NULL;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
295 newelm->prev = end; // NULL or the end of list
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
296 if(end) {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
297 end->next = newelm; // append new element
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
298 } else {
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
299 list = newelm; // start new list
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
300 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
301 end = newelm;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
302 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
303 }
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
304
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
305 ucx_map_free(nsmap);
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
306 return list;
e4f3e1433098 add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
307 }

mercurial