src/server/webdav/multistatus.c

branch
webdav
changeset 227
3c23855f7b46
parent 226
49adcbd7d473
child 229
73cb1c98ef7d
equal deleted inserted replaced
226:49adcbd7d473 227:3c23855f7b46
115 WebdavResource *res, 115 WebdavResource *res,
116 WebdavProperty *property, 116 WebdavProperty *property,
117 int status) 117 int status)
118 { 118 {
119 MSResponse *response = (MSResponse*)res; 119 MSResponse *response = (MSResponse*)res;
120 Session *sn = response->multistatus->sn;
120 if(response->resource.isclosed) { 121 if(response->resource.isclosed) {
121 log_ereport( 122 log_ereport(
122 LOG_WARN, 123 LOG_WARN,
123 "%s", 124 "%s",
124 "webdav: cannot add property to closed response tag"); 125 "webdav: cannot add property to closed response tag");
133 "%s", 134 "%s",
134 "webdav: property '%s' has no namespace", 135 "webdav: property '%s' has no namespace",
135 property->name); 136 property->name);
136 return 1; 137 return 1;
137 } 138 }
138 if(property->nsdef) {
139 // error: nsdef MUST be NULL, only fill nsdef in this func
140 log_ereport(
141 LOG_FAILURE,
142 "%s",
143 "webdav: property '%s': nsdef must be null",
144 property->name);
145 return 1;
146 }
147 139
148 // check if the property was already added to the resource 140 // check if the property was already added to the resource
149 UcxAllocator *a = session_get_allocator(response->multistatus->sn); 141 UcxAllocator *a = session_get_allocator(sn);
150 sstr_t key = sstrcat_a( 142 sstr_t key = sstrcat_a(
151 a, 143 a,
152 3, 144 3,
153 sstr((char*)property->namespace->href), 145 sstr((char*)property->namespace->href),
154 S("\0"), 146 S("\0"),
160 if(ucx_map_sstr_put(response->properties, key, property)) { 152 if(ucx_map_sstr_put(response->properties, key, property)) {
161 return 1; // OOM 153 return 1; // OOM
162 } 154 }
163 a->free(a->pool, key.ptr); 155 a->free(a->pool, key.ptr);
164 156
165 // add namespace of this property to the namespace map
166 // the namespace map will be used for global namespace definitions
167 if(property->namespace->prefix) {
168 char *ns = ucx_map_cstr_get(
169 response->multistatus->namespaces,
170 (const char*)property->namespace->prefix);
171 if(!ns) {
172 // prefix is not in use -> we can add the namespace to the ns map
173 int err = ucx_map_cstr_put(
174 response->multistatus->namespaces,
175 (const char*)property->namespace->prefix,
176 property->namespace->href);
177 if(err) {
178 return 1; // OOM
179 }
180 } else if(strcmp((char*)property->namespace->href, ns)) {
181 // global namespace != local namespace
182 // therefore we need a namespace definition in this element
183
184 if(webdav_property_add_nsdef(
185 property,
186 response->multistatus->sn->pool,
187 (const char*)property->namespace->prefix,
188 (const char*)property->namespace->href))
189 {
190 return 1; // OOM
191 }
192 }
193 }
194
195 // error properties will be added to a separate list 157 // error properties will be added to a separate list
196 if(status != 200) { 158 if(status != 200) {
197 return msresponse_addproperror(response, property, status); 159 return msresponse_addproperror(response, property, status);
198 } 160 }
199 161
200 // add all namespaces used by this property to the nsdef list
201 WebdavNSList *nslist = NULL;
202 if(property->vtype == WS_VALUE_XML_NODE) {
203 // iterate over xml tree and collect all namespaces
204 int err = 0;
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;
213 } else if(property->vtype == WS_VALUE_XML_DATA) {
214 // xml data contains a list of all used namespaces
215 nslist = property->value.data->namespaces;
216 } // other value types don't contain xml namespaces
217
218 while(nslist) {
219 // only add the namespace to the definitions list, if it isn't a
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,
230 (const char*)nslist->namespace->prefix,
231 (const char*)nslist->namespace->href))
232 {
233 return 1; // OOM
234 }
235 }
236 nslist = nslist->next;
237 }
238
239 // add property to the list 162 // add property to the list
240 WebdavPList *listelm = pool_malloc( 163 if(webdav_plist_add(
241 response->multistatus->sn->pool, 164 sn->pool,
242 sizeof(WebdavPList)); 165 &response->plist_begin,
243 if(!listelm) { 166 &response->plist_end,
167 property))
168 {
244 return 1; 169 return 1;
245 } 170 }
246
247 listelm->property = property;
248 listelm->next = NULL;
249
250 if(response->plist_end) {
251 response->plist_end->next = listelm;
252 } else {
253 response->plist_begin = listelm;
254 }
255 response->plist_end = listelm;
256 return 0; 171 return 0;
257 } 172 }
258 173
259 int msresponse_addproperror( 174 int msresponse_addproperror(
260 MSResponse *response, 175 MSResponse *response,

mercurial