153 writer_putc(out, '<'); |
153 writer_putc(out, '<'); |
154 writer_puts(out, sstr((char*)property->namespace->prefix)); |
154 writer_puts(out, sstr((char*)property->namespace->prefix)); |
155 writer_putc(out, ':'); |
155 writer_putc(out, ':'); |
156 writer_puts(out, sstr((char*)property->name)); |
156 writer_puts(out, sstr((char*)property->name)); |
157 |
157 |
158 // check if the namespace is already defined |
|
159 WSBool need_nsdef = TRUE; |
|
160 WSNamespace *ns = ucx_map_cstr_get( |
|
161 ms->namespaces, |
|
162 (char*)property->namespace->prefix); |
|
163 if(ns && !strcmp( |
|
164 (const char*)ns->href, |
|
165 (const char*)property->namespace->href)) |
|
166 { |
|
167 need_nsdef = FALSE; // prefix and href are the same, no need for nsdef |
|
168 } |
|
169 |
|
170 // send definition for the element's namespace |
|
171 if(need_nsdef) { |
|
172 send_nsdef(property->namespace, out); |
|
173 } |
|
174 |
|
175 // send additional namespace definitions required for the value |
158 // send additional namespace definitions required for the value |
176 WebdavNSList *def = nsdef; |
159 WebdavNSList *def = nsdef; |
177 while(def) { |
160 while(def) { |
178 send_nsdef(def->namespace, out); |
161 send_nsdef(def->namespace, out); |
179 def = def->next; |
162 def = def->next; |
415 (*end)->next = newelm; |
398 (*end)->next = newelm; |
416 } else { |
399 } else { |
417 *begin = newelm; |
400 *begin = newelm; |
418 } |
401 } |
419 *end = newelm; |
402 *end = newelm; |
|
403 return 0; |
|
404 } |
|
405 |
|
406 /* |
|
407 * should only be called from msresponse_addproperty |
|
408 * |
|
409 * Adds a property to the error list with the specified statuscode |
|
410 */ |
|
411 static int msresponse_addproperror( |
|
412 MSResponse *response, |
|
413 WebdavProperty *property, |
|
414 int statuscode) |
|
415 { |
|
416 pool_handle_t *pool = response->multistatus->sn->pool; |
|
417 UcxAllocator *a = session_get_allocator(response->multistatus->sn); |
|
418 |
|
419 response->resource.err++; |
|
420 |
|
421 // MSResponse contains a list of properties for each status code |
|
422 // at first find the list for this status code |
|
423 PropertyErrorList *errlist = NULL; |
|
424 PropertyErrorList *list = response->errors; |
|
425 PropertyErrorList *last = NULL; |
|
426 while(list) { |
|
427 if(list->status == statuscode) { |
|
428 errlist = list; |
|
429 break; |
|
430 } |
|
431 last = list; |
|
432 list = list->next; |
|
433 } |
|
434 |
|
435 if(!errlist) { |
|
436 // no list available for this statuscode |
|
437 PropertyErrorList *newelm = pool_malloc(pool, |
|
438 sizeof(PropertyErrorList)); |
|
439 if(!newelm) { |
|
440 return 1; |
|
441 } |
|
442 newelm->begin = NULL; |
|
443 newelm->end = NULL; |
|
444 newelm->next = NULL; |
|
445 newelm->status = statuscode; |
|
446 |
|
447 if(last) { |
|
448 last->next = newelm; |
|
449 } else { |
|
450 response->errors = newelm; |
|
451 } |
|
452 errlist = newelm; |
|
453 } |
|
454 |
|
455 // we have the list -> add the new element |
|
456 if(webdav_plist_add(pool, &errlist->begin, &errlist->end, property)) { |
|
457 return 1; |
|
458 } |
420 return 0; |
459 return 0; |
421 } |
460 } |
422 |
461 |
423 int msresponse_addproperty( |
462 int msresponse_addproperty( |
424 WebdavResource *res, |
463 WebdavResource *res, |
562 return 1; |
601 return 1; |
563 } |
602 } |
564 return 0; |
603 return 0; |
565 } |
604 } |
566 |
605 |
567 int msresponse_addproperror( |
|
568 MSResponse *response, |
|
569 WebdavProperty *property, |
|
570 int statuscode) |
|
571 { |
|
572 pool_handle_t *pool = response->multistatus->sn->pool; |
|
573 UcxAllocator *a = session_get_allocator(response->multistatus->sn); |
|
574 |
|
575 response->resource.err++; |
|
576 |
|
577 // MSResponse contains a list of properties for each status code |
|
578 // at first find the list for this status code |
|
579 PropertyErrorList *errlist = NULL; |
|
580 PropertyErrorList *list = response->errors; |
|
581 PropertyErrorList *last = NULL; |
|
582 while(list) { |
|
583 if(list->status == statuscode) { |
|
584 errlist = list; |
|
585 break; |
|
586 } |
|
587 last = list; |
|
588 list = list->next; |
|
589 } |
|
590 |
|
591 if(!errlist) { |
|
592 // no list available for this statuscode |
|
593 PropertyErrorList *newelm = pool_malloc(pool, |
|
594 sizeof(PropertyErrorList)); |
|
595 if(!newelm) { |
|
596 return 1; |
|
597 } |
|
598 newelm->begin = NULL; |
|
599 newelm->end = NULL; |
|
600 newelm->next = NULL; |
|
601 newelm->status = statuscode; |
|
602 |
|
603 if(last) { |
|
604 last->next = newelm; |
|
605 } else { |
|
606 response->errors = newelm; |
|
607 } |
|
608 errlist = newelm; |
|
609 } |
|
610 |
|
611 // we have the list -> add the new element |
|
612 if(webdav_plist_add(pool, &errlist->begin, &errlist->end, property)) { |
|
613 return 1; |
|
614 } |
|
615 return 0; |
|
616 } |
|
617 |
|
618 int msresponse_close(WebdavResource *res) { |
606 int msresponse_close(WebdavResource *res) { |
619 MSResponse *response = (MSResponse*)res; |
607 MSResponse *response = (MSResponse*)res; |
620 if(response->closing) { |
608 if(response->closing) { |
621 return 0; // close already in progress |
609 return 0; // close already in progress |
622 } |
610 } |
644 S("\0"), |
632 S("\0"), |
645 sstr((char*)pl->property->name)); |
633 sstr((char*)pl->property->name)); |
646 if(!ucx_map_sstr_get(response->properties, key)) { |
634 if(!ucx_map_sstr_get(response->properties, key)) { |
647 // property was not added to this response |
635 // property was not added to this response |
648 if(ms->proppatch) { |
636 if(ms->proppatch) { |
649 if(msresponse_addproperror(response, pl->property, 424)) { |
637 if(msresponse_addproperty(res, pl->property, 424)) { |
650 ret = REQ_ABORTED; |
638 ret = REQ_ABORTED; |
651 break; |
639 break; |
652 } |
640 } |
653 } else { |
641 } else { |
654 if(msresponse_addproperror(response, pl->property, 404)) { |
642 if(msresponse_addproperty(res, pl->property, 404)) { |
655 ret = REQ_ABORTED; |
643 ret = REQ_ABORTED; |
656 break; |
644 break; |
657 } |
645 } |
658 } |
646 } |
659 } |
647 } |
666 // if we have a single error prop, move all props with status 200 |
654 // if we have a single error prop, move all props with status 200 |
667 // to the error list |
655 // to the error list |
668 PropertyOkList *elm = response->plist_begin; |
656 PropertyOkList *elm = response->plist_begin; |
669 PropertyOkList *nextelm; |
657 PropertyOkList *nextelm; |
670 while(elm) { |
658 while(elm) { |
671 if(msresponse_addproperror(response, elm->property, 424)) { |
659 if(msresponse_addproperty(res, elm->property, 424)) { |
672 return 1; |
660 return 1; |
673 } |
661 } |
674 nextelm = elm->next; |
662 nextelm = elm->next; |
675 pool_free(response->multistatus->sn->pool, elm); |
663 pool_free(response->multistatus->sn->pool, elm); |
676 elm = nextelm; |
664 elm = nextelm; |