src/server/webdav/multistatus.c

branch
webdav
changeset 226
49adcbd7d473
parent 223
bbaec8415c10
child 227
3c23855f7b46
equal deleted inserted replaced
225:e4f3e1433098 226:49adcbd7d473
76 } 76 }
77 ZERO(res, sizeof(MSResponse)); 77 ZERO(res, sizeof(MSResponse));
78 78
79 // set href 79 // set href
80 res->resource.href = pool_strdup(ms->sn->pool, path); 80 res->resource.href = pool_strdup(ms->sn->pool, path);
81 if(!res->resource.href) {
82 return NULL;
83 }
81 84
82 // add resource funcs 85 // add resource funcs
83 res->resource.addproperty = msresponse_addproperty; 86 res->resource.addproperty = msresponse_addproperty;
84 res->resource.close = msresponse_close; 87 res->resource.close = msresponse_close;
88
89 res->properties = ucx_map_new_a(session_get_allocator(ms->sn), 32);
90 if(!res->properties) {
91 return NULL;
92 }
85 93
86 res->multistatus = ms; 94 res->multistatus = ms;
87 res->errors = NULL; 95 res->errors = NULL;
88 res->resource.isclosed = 0; 96 res->resource.isclosed = 0;
89 res->closing = 0; 97 res->closing = 0;
134 "%s", 142 "%s",
135 "webdav: property '%s': nsdef must be null", 143 "webdav: property '%s': nsdef must be null",
136 property->name); 144 property->name);
137 return 1; 145 return 1;
138 } 146 }
147
148 // check if the property was already added to the resource
149 UcxAllocator *a = session_get_allocator(response->multistatus->sn);
150 sstr_t key = sstrcat_a(
151 a,
152 3,
153 sstr((char*)property->namespace->href),
154 S("\0"),
155 sstr((char*)property->name));
156 if(ucx_map_sstr_get(response->properties, key)) {
157 a->free(a->pool, key.ptr);
158 return 0;
159 }
160 if(ucx_map_sstr_put(response->properties, key, property)) {
161 return 1; // OOM
162 }
163 a->free(a->pool, key.ptr);
139 164
140 // add namespace of this property to the namespace map 165 // add namespace of this property to the namespace map
141 // the namespace map will be used for global namespace definitions 166 // the namespace map will be used for global namespace definitions
142 if(property->namespace->prefix) { 167 if(property->namespace->prefix) {
143 char *ns = ucx_map_cstr_get( 168 char *ns = ucx_map_cstr_get(
171 if(status != 200) { 196 if(status != 200) {
172 return msresponse_addproperror(response, property, status); 197 return msresponse_addproperror(response, property, status);
173 } 198 }
174 199
175 // add all namespaces used by this property to the nsdef list 200 // add all namespaces used by this property to the nsdef list
201 WebdavNSList *nslist = NULL;
176 if(property->vtype == WS_VALUE_XML_NODE) { 202 if(property->vtype == WS_VALUE_XML_NODE) {
177 // iterate over xml tree and collect all namespaces 203 // iterate over xml tree and collect all namespaces
178 204 int err = 0;
179 // TODO: implement 205 WebdavNSList *nsdef = wsxml_get_required_namespaces(
206 response->multistatus->sn->pool,
207 property->value.node,
208 &err);
209 if(err) {
210 return 1; // OOM
211 }
212 nslist = nsdef;
180 } else if(property->vtype == WS_VALUE_XML_DATA) { 213 } else if(property->vtype == WS_VALUE_XML_DATA) {
181 // xml data contains a list of all used namespaces 214 // xml data contains a list of all used namespaces
182 WebdavNSList *nslist = property->value.data->namespaces; 215 nslist = property->value.data->namespaces;
183 while(nslist) { 216 } // other value types don't contain xml namespaces
184 // only add the namespace to the definitions list, if it isn't 217
185 // property namespace, because the prop ns is already added 218 while(nslist) {
186 // to the element's def list or global definitions list 219 // only add the namespace to the definitions list, if it isn't a
187 if(strcmp( 220 // property namespace, because the prop ns is already added
221 // to the element's def list or global definitions list
222 if(strcmp(
223 (const char*)nslist->namespace->prefix,
224 (const char*)property->namespace->prefix))
225 {
226 // ns-prefix != property-prefix -> add ns to nsdef
227 if(webdav_property_add_nsdef(
228 property,
229 response->multistatus->sn->pool,
188 (const char*)nslist->namespace->prefix, 230 (const char*)nslist->namespace->prefix,
189 (const char*)property->namespace->prefix)) 231 (const char*)nslist->namespace->href))
190 { 232 {
191 // ns-prefix != property-prefix -> add ns to nsdef 233 return 1; // OOM
192 if(webdav_property_add_nsdef( 234 }
193 property, 235 }
194 response->multistatus->sn->pool, 236 nslist = nslist->next;
195 (const char*)nslist->namespace->prefix, 237 }
196 (const char*)nslist->namespace->href))
197 {
198 return 1; // OOM
199 }
200 }
201 nslist = nslist->next;
202 }
203 } // other value types don't contain xml namespaces
204 238
205 // add property to the list 239 // add property to the list
206 WebdavPList *listelm = pool_malloc( 240 WebdavPList *listelm = pool_malloc(
207 response->multistatus->sn->pool, 241 response->multistatus->sn->pool,
208 sizeof(WebdavPList)); 242 sizeof(WebdavPList));
286 WebdavOperation *op = response->multistatus->response.op; 320 WebdavOperation *op = response->multistatus->response.op;
287 if(webdav_op_propfiond_close_resource(op, res)) { 321 if(webdav_op_propfiond_close_resource(op, res)) {
288 ret = REQ_ABORTED; 322 ret = REQ_ABORTED;
289 } 323 }
290 324
325 // we don't need the properties anymore
326 ucx_map_free(response->properties);
327
291 response->resource.isclosed = TRUE; 328 response->resource.isclosed = TRUE;
292 response->closing = FALSE; 329 response->closing = FALSE;
293 return ret; 330 return ret;
294 } 331 }

mercurial