56 return ms; |
56 return ms; |
57 } |
57 } |
58 |
58 |
59 int multistatus_send(Multistatus *ms, SYS_NETFD net) { |
59 int multistatus_send(Multistatus *ms, SYS_NETFD net) { |
60 char buffer[MULTISTATUS_BUFFER_LENGTH]; |
60 char buffer[MULTISTATUS_BUFFER_LENGTH]; |
|
61 // create a writer, that flushes the buffer when it is filled |
61 Writer writer; |
62 Writer writer; |
62 Writer *out = &writer; |
63 Writer *out = &writer; |
63 writer_init(out, net, buffer, MULTISTATUS_BUFFER_LENGTH); |
64 writer_init(out, net, buffer, MULTISTATUS_BUFFER_LENGTH); |
64 |
65 |
65 |
66 |
|
67 |
|
68 return 0; |
66 } |
69 } |
67 |
70 |
68 WebdavResource * multistatus_addresource( |
71 WebdavResource * multistatus_addresource( |
69 WebdavResponse *response, |
72 WebdavResponse *response, |
70 const char *path) |
73 const char *path) |
107 ms->first = res; |
110 ms->first = res; |
108 } |
111 } |
109 ms->current = res; |
112 ms->current = res; |
110 |
113 |
111 return (WebdavResource*)res; |
114 return (WebdavResource*)res; |
|
115 } |
|
116 |
|
117 static int oklist_add( |
|
118 pool_handle_t *pool, |
|
119 PropertyOkList **begin, |
|
120 PropertyOkList **end, |
|
121 WebdavProperty *property, |
|
122 WebdavNSList *nsdef) |
|
123 { |
|
124 PropertyOkList *newelm = pool_malloc(pool, sizeof(PropertyOkList)); |
|
125 if(!newelm) { |
|
126 return 1; |
|
127 } |
|
128 newelm->property = property; |
|
129 newelm->nsdef = nsdef; |
|
130 newelm->next = NULL; |
|
131 if(*end) { |
|
132 (*end)->next = newelm; |
|
133 } else { |
|
134 *begin = newelm; |
|
135 } |
|
136 *end = newelm; |
|
137 return 0; |
112 } |
138 } |
113 |
139 |
114 int msresponse_addproperty( |
140 int msresponse_addproperty( |
115 WebdavResource *res, |
141 WebdavResource *res, |
116 WebdavProperty *property, |
142 WebdavProperty *property, |
157 // error properties will be added to a separate list |
183 // error properties will be added to a separate list |
158 if(status != 200) { |
184 if(status != 200) { |
159 return msresponse_addproperror(response, property, status); |
185 return msresponse_addproperror(response, property, status); |
160 } |
186 } |
161 |
187 |
|
188 // add all namespaces used by this property to the nsdef list |
|
189 WebdavNSList *nslist = NULL; |
|
190 if(property->vtype == WS_VALUE_XML_NODE) { |
|
191 // iterate over xml tree and collect all namespaces |
|
192 int err = 0; |
|
193 nslist = wsxml_get_required_namespaces( |
|
194 response->multistatus->sn->pool, |
|
195 property->value.node, |
|
196 &err); |
|
197 if(err) { |
|
198 return 1; // OOM |
|
199 } |
|
200 } else if(property->vtype == WS_VALUE_XML_DATA) { |
|
201 // xml data contains a list of all used namespaces |
|
202 nslist = property->value.data->namespaces; |
|
203 } // other value types don't contain xml namespaces |
|
204 |
|
205 WebdavNSList *nsdef_begin = NULL; |
|
206 WebdavNSList *nsdef_end = NULL; |
|
207 while(nslist) { |
|
208 // only add the namespace to the definitions list, if it isn't a |
|
209 // property namespace, because the prop ns is already added |
|
210 // to the element's def list or global definitions list |
|
211 if(strcmp( |
|
212 (const char*)nslist->namespace->prefix, |
|
213 (const char*)property->namespace->prefix)) |
|
214 { |
|
215 // ns-prefix != property-prefix -> add ns to nsdef |
|
216 if(webdav_nslist_add( |
|
217 sn->pool, |
|
218 &nsdef_begin, |
|
219 &nsdef_end, |
|
220 nslist->namespace)) |
|
221 { |
|
222 return 1; // OOM |
|
223 } |
|
224 } |
|
225 nslist = nslist->next; |
|
226 } |
|
227 |
162 // add property to the list |
228 // add property to the list |
163 if(webdav_plist_add( |
229 if(oklist_add( |
164 sn->pool, |
230 sn->pool, |
165 &response->plist_begin, |
231 &response->plist_begin, |
166 &response->plist_end, |
232 &response->plist_end, |
167 property)) |
233 property, |
|
234 nsdef_begin)) |
168 { |
235 { |
169 return 1; |
236 return 1; |
170 } |
237 } |
171 return 0; |
238 return 0; |
172 } |
239 } |