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