Sun, 25 Sep 2022 10:36:28 +0200
change uid before most of the config is loaded
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> |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
35 | #include <ucx/buffer.h> |
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
|
36 | |
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 | #include "../util/util.h" |
319
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
38 | #include "../util/pool.h" |
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
|
39 | |
211
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #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
|
41 | |
232 | 42 | /***************************************************************************** |
43 | * Utility functions | |
44 | *****************************************************************************/ | |
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
|
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 | /* |
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 | * 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
|
48 | * 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
|
49 | */ |
232 | 50 | static sstr_t xml_namespace_key(UcxAllocator *a, WSNamespace *ns) { |
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
|
51 | 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
|
52 | 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
|
53 | 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
|
54 | 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
|
55 | 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
|
56 | } |
e4f3e1433098
add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
224
diff
changeset
|
57 | |
e4f3e1433098
add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
224
diff
changeset
|
58 | |
232 | 59 | /***************************************************************************** |
60 | * Public functions | |
61 | *****************************************************************************/ | |
62 | ||
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
|
63 | /* ------------------------ 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
|
64 | |
223
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
65 | typedef struct StackElm { |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
66 | WSXmlNode *node; // list of nodes |
224
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
67 | //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
|
68 | int endonly; |
223
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
69 | struct StackElm *next; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
70 | } StackElm; |
211
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | |
223
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
72 | #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
|
73 | |
223
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
74 | int wsxml_iterator( |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
75 | pool_handle_t *pool, |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
76 | WSXmlNode *node, |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
77 | wsxml_func begincb, |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
78 | wsxml_func endcb, |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
79 | void *udata) |
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 | if(!node) { |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
82 | return 0; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
83 | } |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
84 | |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
85 | StackElm *stack = pool_malloc(pool, sizeof(StackElm)); |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
86 | if(!stack) { |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
87 | return 1; // OOM |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
88 | } |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
89 | stack->next = NULL; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
90 | stack->node = node; |
224
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
91 | stack->endonly = 0; |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
92 | //stack->parent = NULL; |
223
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
93 | |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
94 | int ret = 0; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
95 | int br = 0; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
96 | while(stack) { |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
97 | StackElm *cur = stack; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
98 | WSXmlNode *xmlnode = cur->node; // get top stack element |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
99 | stack = cur->next; // and remove it |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
100 | cur->next = NULL; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
101 | |
224
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
102 | while(xmlnode && !cur->endonly) { |
223
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
103 | // element begin callback |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
104 | if(begincb(xmlnode, udata)) { |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
105 | br = 1; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
106 | 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
|
107 | } |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
108 | |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
109 | if(xmlnode->children) { |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
110 | // put the children on the stack |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
111 | // the next stack iteration will process the children |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
112 | StackElm *newelm = pool_malloc(pool, sizeof(StackElm)); |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
113 | if(!newelm) { |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
114 | ret = 1; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
115 | br = 1; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
116 | break; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
117 | } |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
118 | newelm->next = NULL; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
119 | newelm->node = xmlnode->children; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
120 | // 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
|
121 | // 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
|
122 | //newelm->parent = xmlnode; |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
123 | newelm->endonly = 0; |
223
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
124 | |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
125 | // 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
|
126 | // 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
|
127 | // stack |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
128 | // 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
|
129 | // children and the end tag are processed |
223
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
130 | if(xmlnode->next) { |
224
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
131 | StackElm *nextelm = pool_malloc(pool, sizeof(StackElm)); |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
132 | if(!nextelm) { |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
133 | ret = 1; |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
134 | br = 1; |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
135 | break; |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
136 | } |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
137 | nextelm->node = xmlnode->next; |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
138 | nextelm->next = NULL; |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
139 | nextelm->endonly = 0; |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
140 | STACK_PUSH(stack, nextelm); |
223
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
141 | } |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
142 | |
224
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
143 | // 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
|
144 | // 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
|
145 | // element, after all children are processed |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
146 | // reuse cur |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
147 | cur->node = xmlnode; |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
148 | cur->endonly = 1; |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
149 | STACK_PUSH(stack, cur); |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
150 | |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
151 | cur = NULL; |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
152 | |
223
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
153 | // now we can put the children on the stack |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
154 | STACK_PUSH(stack, newelm); |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
155 | // 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
|
156 | break; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
157 | } else { |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
158 | // 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
|
159 | // after the begin callback (no intermediate nodes) |
224
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
160 | cur->node = NULL; |
223
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
161 | if(endcb(xmlnode, udata)) { |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
162 | br = 1; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
163 | break; |
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 | } |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
166 | |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
167 | // continue with next node at this level |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
168 | xmlnode = xmlnode->next; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
169 | } |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
170 | if(br) { |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
171 | break; // break because of an error |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
172 | } |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
173 | |
224
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
174 | if(cur && cur->node) { |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
175 | //xmlNode *endNode = cur->parent ? cur->parent : cur->node; |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
176 | xmlNode *endNode = cur->node; |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
177 | if(endcb(endNode, udata)) { |
0de1ec82628e
add test for xml iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
178 | break; |
223
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
179 | } |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
180 | pool_free(pool, cur); |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
181 | } |
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 | // free all remaining elements |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
185 | StackElm *elm = stack; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
186 | while(elm) { |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
187 | StackElm *next = elm->next; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
188 | pool_free(pool, elm); |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
189 | elm = next; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
190 | } |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
191 | |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
192 | return ret; |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
193 | } |
bbaec8415c10
add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
194 | |
232 | 195 | /* ------------------- wsxml_get_required_namespaces ------------------- */ |
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
|
196 | |
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 | 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
|
198 | 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
|
199 | 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
|
200 | 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
|
201 | 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
|
202 | } 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
|
203 | |
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 | 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
|
205 | 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
|
206 | // 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
|
207 | 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
|
208 | // 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
|
209 | // all namespaces in a map |
232 | 210 | sstr_t nskey = xml_namespace_key(col->a, node->ns); |
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
|
211 | 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
|
212 | 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
|
213 | 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
|
214 | } |
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 | 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
|
216 | 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
|
217 | 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
|
218 | } |
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 | |
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 | // 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
|
221 | // 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
|
222 | 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
|
223 | 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
|
224 | 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
|
225 | 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
|
226 | 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
|
227 | 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
|
228 | 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
|
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 | 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
|
231 | 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
|
232 | 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
|
233 | // 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
|
234 | 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
|
235 | 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
|
236 | 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
|
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 | 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
|
239 | |
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 | // 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
|
241 | 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
|
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 | } |
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 | 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
|
245 | } |
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 | |
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 | 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
|
248 | 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
|
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 | |
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 | 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
|
252 | 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
|
253 | 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
|
254 | 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
|
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 | 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
|
257 | |
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 | 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
|
259 | 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
|
260 | 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
|
261 | 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
|
262 | 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
|
263 | } |
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 | |
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 | 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
|
266 | 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
|
267 | 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
|
268 | 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
|
269 | |
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 | // 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
|
271 | // 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
|
272 | // 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
|
273 | 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
|
274 | 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
|
275 | 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
|
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 | } 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
|
278 | // 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
|
279 | // 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
|
280 | 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
|
281 | while(def) { |
232 | 282 | sstr_t nskey = xml_namespace_key(&a, def->namespace); |
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
|
283 | 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
|
284 | 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
|
285 | 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
|
286 | } |
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 | 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
|
288 | 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
|
289 | } |
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 | |
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 | // 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
|
292 | 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
|
293 | 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
|
294 | 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
|
295 | 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
|
296 | 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
|
297 | 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
|
298 | 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
|
299 | 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
|
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 | 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
|
302 | 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
|
303 | 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
|
304 | 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
|
305 | 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
|
306 | } 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
|
307 | 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
|
308 | } |
e4f3e1433098
add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
224
diff
changeset
|
309 | 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
|
310 | } |
e4f3e1433098
add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
224
diff
changeset
|
311 | } |
e4f3e1433098
add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
224
diff
changeset
|
312 | |
e4f3e1433098
add function for getting all namespace definitions that are required for an element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
224
diff
changeset
|
313 | 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
|
314 | 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
|
315 | } |
232 | 316 | |
317 | ||
319
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
318 | static ssize_t buf_writefunc(void *buf, const char *s, size_t len) { |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
319 | int w = ucx_buffer_write(s, 1, len, buf); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
320 | return w == 0 ? IO_ERROR : w; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
321 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
322 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
323 | WSXmlData* wsxml_node2data( |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
324 | pool_handle_t *pool, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
325 | WSXmlNode *node) |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
326 | { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
327 | UcxBuffer *buf = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
328 | if(!buf) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
329 | return NULL; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
330 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
331 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
332 | int error = 0; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
333 | WebdavNSList *nslist = wsxml_get_required_namespaces(pool, node, &error); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
334 | if(error) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
335 | return NULL; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
336 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
337 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
338 | Writer writer; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
339 | char buffer[512]; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
340 | writer_init_with_stream(&writer, buf, buf_writefunc, buffer, 512); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
341 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
342 | WSXmlData *data = NULL; |
324
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
343 | if(!wsxml_write_nodes(pool, &writer, NULL, node) && !writer_flush(&writer)) { |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
344 | data = pool_malloc(pool, sizeof(WSXmlData)); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
345 | if(data) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
346 | data->data = pool_malloc(pool, buf->size + 1); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
347 | if(data->data) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
348 | memcpy(data->data, buf->space, buf->size); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
349 | data->data[buf->size] = '\0'; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
350 | data->length = buf->size; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
351 | data->namespaces = nslist; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
352 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
353 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
354 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
355 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
356 | ucx_buffer_free(buf); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
357 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
358 | return data; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
359 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
360 | |
319
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
361 | char* wsxml_nslist2string(pool_handle_t *pool, WebdavNSList *nslist) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
362 | if(!nslist) return NULL; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
363 | |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
364 | // get required string length |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
365 | size_t len = 0; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
366 | WebdavNSList *elm = nslist; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
367 | while(elm) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
368 | WSNamespace *ns = elm->namespace; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
369 | if(ns) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
370 | if(ns->prefix) len += strlen((const char*)ns->prefix); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
371 | if(ns->href) len += strlen((const char*)ns->href); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
372 | len += 2; // 1 char for ':', 1 char for \n or \0 |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
373 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
374 | elm = elm->next; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
375 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
376 | |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
377 | // alloc string |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
378 | char *str = pool_malloc(pool, len); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
379 | if(!str) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
380 | return NULL; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
381 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
382 | char *pos = str; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
383 | |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
384 | // copy namespace definitions to the string |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
385 | elm = nslist; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
386 | while(elm) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
387 | WSNamespace *ns = elm->namespace; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
388 | if(ns) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
389 | if(ns->prefix) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
390 | size_t prefixlen = strlen((const char*)ns->prefix); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
391 | memcpy(pos, ns->prefix, prefixlen); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
392 | pos[prefixlen] = ':'; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
393 | pos += prefixlen + 1; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
394 | } else { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
395 | pos[0] = ':'; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
396 | pos++; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
397 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
398 | if(ns->href) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
399 | size_t hreflen = strlen((const char*)ns->href); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
400 | memcpy(pos, ns->href, hreflen); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
401 | pos[hreflen] = elm->next ? '\n' : '\0'; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
402 | pos += hreflen + 1; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
403 | } else { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
404 | pos[0] = elm->next ? '\n' : '\0'; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
405 | pos++; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
406 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
407 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
408 | elm = elm->next; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
409 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
410 | |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
411 | return str; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
412 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
413 | |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
414 | WebdavNSList* wsxml_string2nslist(pool_handle_t *pool, char *nsliststr) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
415 | if(!nsliststr) return NULL; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
416 | size_t len = strlen(nsliststr); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
417 | WebdavNSList *list_start = NULL; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
418 | WebdavNSList *list_current = NULL; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
419 | |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
420 | char *prefix = nsliststr; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
421 | size_t prefix_start = 0; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
422 | size_t prefix_len = 0; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
423 | char *href = NULL; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
424 | size_t href_start = len; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
425 | size_t i; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
426 | for(i=0;i<=len;i++) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
427 | char c = nsliststr[i]; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
428 | if(c == '\n' || c == '\0') { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
429 | if(i > href_start) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
430 | WebdavNSList *elm = pool_malloc(pool, sizeof(WebdavNSList)); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
431 | if(!elm) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
432 | break; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
433 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
434 | elm->prev = list_current; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
435 | elm->next = NULL; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
436 | WSNamespace *ns = pool_malloc(pool, sizeof(WSNamespace)); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
437 | elm->namespace = ns; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
438 | if(!ns) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
439 | break; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
440 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
441 | memset(ns, 0, sizeof(WSNamespace)); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
442 | ns->prefix = prefix_len > 0 ? (xmlChar*)sstrdup_pool(pool, sstrn(prefix, prefix_len)).ptr : NULL; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
443 | ns->href = (xmlChar*)sstrdup_pool(pool, sstrn(href, i-href_start)).ptr; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
444 | if(list_current) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
445 | list_current->next = elm; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
446 | } else { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
447 | list_start = elm; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
448 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
449 | list_current = elm; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
450 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
451 | prefix_start = i + 1; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
452 | prefix = nsliststr + prefix_start; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
453 | prefix_len = 0; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
454 | href_start = len; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
455 | href = NULL; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
456 | } else if(!href && c == ':') { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
457 | prefix_len = i - prefix_start; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
458 | href_start = i + 1; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
459 | href = nsliststr + href_start; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
460 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
461 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
462 | |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
463 | if(i < len) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
464 | // error, cleanup |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
465 | while(list_start) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
466 | if(list_start->namespace) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
467 | WSNamespace *ns = list_start->namespace; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
468 | if(ns->prefix) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
469 | pool_free(pool, (char*)ns->prefix); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
470 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
471 | if(ns->href) { |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
472 | pool_free(pool, (char*)ns->href); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
473 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
474 | pool_free(pool, ns); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
475 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
476 | WebdavNSList *next = list_start->next; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
477 | pool_free(pool, list_start); |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
478 | list_start = next; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
479 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
480 | list_start = NULL; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
481 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
482 | |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
483 | return list_start; |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
484 | } |
a9b9344875aa
add WebdavNSList <-> string converting functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
485 | |
232 | 486 | /***************************************************************************** |
487 | * Non public functions | |
488 | *****************************************************************************/ | |
489 | ||
490 | typedef struct XmlWriter { | |
491 | /* | |
492 | * Memory pool for temp memory allocations | |
493 | */ | |
494 | pool_handle_t *pool; | |
495 | ||
496 | /* | |
497 | * Buffered output stream | |
498 | */ | |
499 | Writer *out; | |
500 | ||
501 | /* | |
502 | * Map for all previously defined namespaces | |
503 | * key: (char*) namespace prefix | |
504 | * value: WSNamespace* | |
505 | */ | |
506 | UcxMap *namespaces; | |
507 | ||
508 | /* | |
509 | * Should namespace definitions be created | |
510 | */ | |
511 | WSBool define_namespaces; | |
512 | } XmlWriter; | |
513 | ||
514 | /* | |
515 | * Serialize an XML text node | |
516 | * This replaces some special characters with entity refs | |
233
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
517 | * type: 0 = element text, 1 = attribute text |
232 | 518 | */ |
233
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
519 | static void xml_ser_text(Writer *out, int type, const char *text) { |
232 | 520 | size_t start = 0; |
521 | size_t i; | |
522 | sstr_t entityref = { NULL, 0 }; | |
523 | for(i=0;text[i]!='\0';i++) { | |
233
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
524 | char c = text[i]; |
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
525 | if(c == '&') { |
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
526 | entityref = S("&"); |
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
527 | } else if(type == 0) { |
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
528 | if(c == '<') { |
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
529 | entityref = S("<"); |
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
530 | } else if(c == '>') { |
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
531 | entityref = S(">"); |
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
532 | } |
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
533 | } else { |
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
534 | if(c == '\"') { |
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
535 | entityref = S("""); |
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
536 | } else if(c == '\'') { |
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
537 | entityref = S("'"); |
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
538 | } |
232 | 539 | } |
233
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
540 | |
232 | 541 | if(entityref.ptr) { |
542 | size_t len = i-start; | |
543 | if(len > 0) { | |
544 | writer_put(out, text+start, len); | |
545 | } | |
546 | writer_puts(out, entityref); | |
547 | entityref.ptr = NULL; | |
548 | entityref.length = 0; | |
549 | start = i+1; | |
550 | } | |
551 | } | |
552 | size_t len = i-start; | |
553 | if(len > 0) { | |
554 | writer_put(out, text+start, len); | |
555 | } | |
556 | } | |
557 | ||
558 | /* | |
559 | * Serialize an XML element node | |
560 | */ | |
561 | static void xml_ser_element(XmlWriter *xw, xmlNode *node) { | |
562 | Writer *out = xw->out; | |
563 | writer_putc(out, '<'); | |
564 | ||
565 | // write prefix and ':' | |
566 | if(node->ns && node->ns->prefix) { | |
567 | writer_puts(out, sstr((char*)node->ns->prefix)); | |
568 | writer_putc(out, ':'); | |
569 | } | |
570 | ||
571 | // node name | |
572 | writer_puts(out, sstr((char*)node->name)); | |
573 | ||
574 | // namespace definitions | |
575 | if(xw->define_namespaces) { | |
576 | xmlNs *nsdef = node->nsDef; | |
577 | while(nsdef) { | |
578 | // we define only namespaces without prefix or namespaces | |
579 | // with prefix, that are not already defined | |
580 | // xw->namespaces contains all namespace, that were defined | |
581 | // before xml serialization | |
582 | if(!nsdef->prefix) { | |
583 | writer_puts(out, S(" xmlns=\"")); | |
584 | writer_puts(out, sstr((char*)nsdef->href)); | |
585 | writer_putc(out, '"'); | |
586 | } else { | |
587 | WSNamespace *n = xw->namespaces ? | |
588 | ucx_map_cstr_get(xw->namespaces, (char*)nsdef->prefix) : | |
589 | NULL; | |
590 | if(!n) { | |
591 | writer_puts(out, S(" xmlns:")); | |
592 | writer_puts(out, sstr((char*)nsdef->prefix)); | |
593 | writer_puts(out, S("=\"")); | |
594 | writer_puts(out, sstr((char*)nsdef->href)); | |
595 | writer_putc(out, '"'); | |
596 | } | |
597 | } | |
598 | ||
599 | nsdef = nsdef->next; | |
600 | } | |
601 | } | |
602 | ||
603 | // attributes | |
604 | xmlAttr *attr = node->properties; | |
605 | while(attr) { | |
606 | // format: ' [<prefix>:]<name>="<value>"' | |
607 | writer_putc(out, ' '); | |
608 | // optional namespace | |
609 | if(attr->ns && attr->ns->prefix) { | |
610 | writer_puts(out, sstr((char*)attr->ns->prefix)); | |
611 | writer_putc(out, ':'); | |
612 | } | |
613 | // <name>=" | |
614 | writer_puts(out, sstr((char*)attr->name)); | |
615 | writer_puts(out, S("=\"")); | |
616 | // value | |
617 | xmlNode *value = attr->children; | |
618 | while(value) { | |
619 | if(value->content) { | |
233
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
620 | xml_ser_text(out, 1, (const char*)value->content); |
232 | 621 | } |
622 | value = value->next; | |
623 | } | |
624 | // trailing quote | |
625 | writer_putc(out, '"'); | |
626 | ||
627 | attr = attr->next; | |
628 | } | |
629 | ||
630 | if(node->children) { | |
631 | writer_putc(out, '>'); | |
632 | } else { | |
633 | writer_puts(out, S("/>")); | |
634 | } | |
635 | } | |
636 | ||
637 | static int xml_ser_node_begin(xmlNode *node, void *userdata) { | |
638 | XmlWriter *xw = userdata; | |
639 | switch(node->type) { | |
640 | case XML_ELEMENT_NODE: xml_ser_element(xw, node); break; | |
641 | case XML_ATTRIBUTE_NODE: break; | |
642 | case XML_TEXT_NODE: { | |
233
c5985d2fc19a
add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
643 | xml_ser_text(xw->out, 0, (const char*)node->content); |
232 | 644 | break; |
645 | } | |
646 | case XML_CDATA_SECTION_NODE: { | |
647 | break; | |
648 | } | |
649 | case XML_ENTITY_REF_NODE: break; | |
650 | case XML_ENTITY_NODE: break; | |
651 | case XML_PI_NODE: break; | |
652 | case XML_COMMENT_NODE: break; | |
653 | case XML_DOCUMENT_NODE: break; | |
654 | case XML_DOCUMENT_TYPE_NODE: break; | |
655 | case XML_DOCUMENT_FRAG_NODE: break; | |
656 | case XML_NOTATION_NODE: break; | |
657 | case XML_HTML_DOCUMENT_NODE: break; | |
658 | case XML_DTD_NODE: break; | |
659 | case XML_ELEMENT_DECL: break; | |
660 | case XML_ATTRIBUTE_DECL: break; | |
661 | case XML_ENTITY_DECL: break; | |
662 | case XML_NAMESPACE_DECL: break; | |
663 | case XML_XINCLUDE_START: break; | |
664 | case XML_XINCLUDE_END: break; | |
665 | default: break; | |
666 | } | |
667 | return 0; | |
668 | } | |
669 | ||
670 | static int xml_ser_node_end(xmlNode *node, void *userdata) { | |
671 | XmlWriter *xw = userdata; | |
672 | Writer *out = xw->out; | |
673 | if(node->type == XML_ELEMENT_NODE) { | |
674 | if(node->children) { | |
675 | writer_puts(xw->out, S("</")); | |
676 | // write prefix and ':' | |
677 | if(node->ns && node->ns->prefix) { | |
678 | writer_puts(out, sstr((char*)node->ns->prefix)); | |
679 | writer_putc(out, ':'); | |
680 | } | |
681 | // name and close tag | |
682 | writer_puts(out, sstr((char*)node->name)); | |
683 | writer_putc(out, '>'); | |
684 | ||
685 | } // element was already closed in xml_ser_node_begin | |
686 | } | |
687 | return 0; | |
688 | } | |
689 | ||
690 | ||
691 | static int xml_write_nodes( | |
692 | pool_handle_t *pool, | |
693 | Writer *out, | |
694 | UcxMap *nsdefs, | |
695 | WSBool createdefs, | |
696 | xmlNode *node) | |
697 | { | |
698 | XmlWriter xmlwriter; | |
699 | xmlwriter.pool = pool; | |
700 | xmlwriter.out = out; | |
701 | xmlwriter.namespaces = nsdefs; | |
702 | xmlwriter.define_namespaces = createdefs; | |
703 | ||
704 | // iterate over xml nodes | |
705 | // this includes node->children and node->next | |
706 | int err = wsxml_iterator( | |
707 | pool, | |
708 | node, | |
709 | xml_ser_node_begin, | |
710 | xml_ser_node_end, | |
711 | &xmlwriter); | |
712 | if(err) { | |
713 | return -1; | |
714 | } | |
715 | ||
716 | return out->error; | |
717 | } | |
718 | ||
719 | int wsxml_write_nodes( | |
720 | pool_handle_t *pool, | |
721 | Writer *out, | |
722 | UcxMap *nsdefs, | |
723 | xmlNode *node) | |
724 | { | |
725 | return xml_write_nodes(pool, out, nsdefs, TRUE, node); | |
726 | } | |
727 | ||
728 | int wsxml_write_nodes_without_nsdef( | |
729 | pool_handle_t *pool, | |
730 | Writer *out, | |
731 | xmlNode *node) | |
732 | { | |
733 | return xml_write_nodes(pool, out, NULL, FALSE, node); | |
734 | } |