src/server/webdav/webdav.c

Sat, 19 Jan 2013 21:52:21 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 19 Jan 2013 21:52:21 +0100
changeset 50
4d39adda7a38
parent 48
37a512d7b8f6
child 51
b28cf69f42e8
permissions
-rw-r--r--

propfind supports allprop

13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
44
3da1f7b6847f added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1fdbf4170ef4 Added webdav code
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
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "webdav.h"
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
34 #include "../ucx/string.h"
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
35 #include "../util/pool.h"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
36 #include "../util/pblock.h"
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
37 #include "../util/date.h"
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
39 #include "../daemon/protocol.h"
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
40
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 #include "davparser.h"
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 int webdav_service(pblock *pb, Session *sn, Request *rq) {
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
44 char *method = pblock_findkeyval(pb_key_method, rq->reqpb);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
45 if(method == NULL) {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
46 return REQ_ABORTED;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
47 }
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
48
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
49 if(!strcmp(method, "PROPFIND")) {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
50 return webdav_propfind(pb, sn, rq);
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
51 } else if(!strcmp(method, "PROPPATCH")) {
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
52 return webdav_proppatch(pb, sn, rq);
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
53 } else if(!strcmp(method, "PUT")) {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
54 return webdav_put(pb, sn, rq);
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
55 } else if(!strcmp(method, "DELETE")) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
56 return webdav_delete(pb, sn, rq);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
57 } else if(!strcmp(method, "MKCOL")) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
58 return webdav_mkcol(pb, sn, rq);
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
59 }
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
60
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
61 return REQ_NOACTION;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
62 }
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
63
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
64 int webdav_put(pblock *pb, Session *sn, Request *rq) {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
65 int length = 0;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
66
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
67 char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars);
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
68 char *ctlen = pblock_findkeyval(pb_key_content_length, rq->headers);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
69 if(ctlen) {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
70 length = atoi(ctlen);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
71 } else {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
72 /* invalid request */
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
73 printf("invalid request\n");
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
74 return REQ_ABORTED;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
75 }
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
76
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
77 printf("PUT length: %d\n", length);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
78
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
79 int status = 201;
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
80 FILE *out = fopen(ppath, "w");
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
81 if(out == NULL) {
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
82 fprintf(stderr, "fopen(%s, \"w\") failed\n", ppath);
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
83 protocol_status(sn, rq, 500, NULL);
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
84 return REQ_ABORTED;
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
85 }
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
86
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
87 if(length > 0) {
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
88 FILE *out = fopen(ppath, "w");
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
89 if(out == NULL) {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
90 fprintf(stderr, "fopen(%s, \"w\") failed\n", ppath);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
91 return REQ_ABORTED;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
92 }
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
93 setvbuf(out, NULL, _IONBF, 0);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
94
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
95 size_t len = (length > 4096) ? (4096) : (length);
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
96 char *buffer = malloc(len);
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
97
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
98 int r;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
99 int r2 = 0;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
100 while(r2 < length) {
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
101 r = netbuf_getbytes(sn->inbuf, buffer, len);
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
102 if(r == NETBUF_EOF) {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
103 break;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
104 }
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
105 fwrite(buffer, 1, r, out);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
106
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
107 r2 += r;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
108 }
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
109
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
110 free(buffer);
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
111 } else {
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
112
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
113 }
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
114 fclose(out);
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
115
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
116 protocol_status(sn, rq, status, NULL);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
117 pblock_removekey(pb_key_content_type, rq->srvhdrs);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
118 pblock_nninsert("content-length", 0, rq->srvhdrs);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
119 http_start_response(sn, rq);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
120
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
121 return REQ_PROCEED;
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
122 }
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
124 int webdav_delete(pblock *pb, Session *sn, Request *rq) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
125 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
126 char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
127
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
128 int status = 204;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
129
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
130 struct stat st;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
131 if(stat(ppath, &st) != 0) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
132 /* ERROR */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
133 status = 403; /* TODO: check errno */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
134 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
135
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
136 if(!strcmp(uri, "/")) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
137 status = 403;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
138 } else if((st.st_mode & S_IFDIR) == S_IFDIR) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
139 if(rmdir(ppath) != 0) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
140 /* ERROR */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
141 status = 403;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
142 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
143 } else {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
144 if(unlink(ppath) != 0) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
145 /* ERROR */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
146 status = 403; /* TODO: check errno */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
147 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
148 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
149
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
150 protocol_status(sn, rq, status, NULL);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
151 pblock_removekey(pb_key_content_type, rq->srvhdrs);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
152 pblock_nninsert("content-length", 0, rq->srvhdrs);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
153 http_start_response(sn, rq);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
154
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
155 return REQ_PROCEED;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
156 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
157
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
158 int webdav_mkcol(pblock *pb, Session *sn, Request *rq) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
159 char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
160
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
161 int status = 201;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
162 if(mkdir(ppath, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
163 status = 403;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
164 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
165
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
166 protocol_status(sn, rq, status, NULL);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
167 pblock_removekey(pb_key_content_type, rq->srvhdrs);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
168 pblock_nninsert("content-length", 0, rq->srvhdrs);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
169 http_start_response(sn, rq);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
170
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
171 return REQ_ABORTED;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
172 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
173
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
174 int webdav_copy(pblock *pb, Session *sn, Request *rq) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
175 return REQ_ABORTED;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
176 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
177
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
178 int webdav_move(pblock *pb, Session *sn, Request *rq) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
179 return REQ_ABORTED;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
180 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
181
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
182 int webdav_propfind(pblock *pb, Session *sn, Request *rq) {
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 /* TODO: clean up if errors occurs */
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 /* Get request body which contains the webdav XML request */
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 char *xml_body;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 size_t xml_len = 0;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 char *ctlen = pblock_findkeyval(pb_key_content_length, rq->headers);
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 if(ctlen) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 xml_len = atoi(ctlen);
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 } else {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 /* invalid request */
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
194 printf("invalid request\n");
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 return REQ_ABORTED;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 xml_body = pool_malloc(sn->pool, xml_len + 1);
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
199 if(xml_body == NULL) {
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
200 return REQ_ABORTED;
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
201 }
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 xml_body[xml_len] = 0;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 if(!xml_body) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 /* server error */
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
205 printf("server error\n");
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 return REQ_ABORTED;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
209 /* get request body */
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 int r = 0;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 char *xb = xml_body;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 size_t xl = xml_len;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 while((r = netbuf_getbytes(sn->inbuf, xb, xl)) != NETBUF_EOF) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 xb += r;
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
215 xl -= r;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
218 /*
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
219 * get requested properties and initialize some stuff
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
220 */
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 PropfindRequest *davrq = dav_parse_propfind(sn, rq, xml_body, xml_len);
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 davrq->sn = sn;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 davrq->rq = rq;
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
224 davrq->out = sbuf_new(512);
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 davrq->propertyBackend = create_property_backend();
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
226
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
227 /* write xml response header */
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 sbuf_puts(davrq->out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 sbuf_puts(davrq->out, "<D:multistatus xmlns:D=\"DAV:\">\n");
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
230
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
231 /* begin multistatus response */
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
232 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars);
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
234
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 struct stat st;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 if(stat(ppath, &st) != 0) {
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
237 perror("webdav_propfind: stat");
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
238 fprintf(stderr, " file: %s\n", ppath);
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
239
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
240 /* TODO: check errno only set status */
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
241 protocol_status(sn, rq, 404, NULL);
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
242 pblock_removekey(pb_key_content_type, rq->srvhdrs);
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
243 pblock_nninsert("content-length", 0, rq->srvhdrs);
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
244 //http_start_response(sn, rq);
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
245
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 return REQ_ABORTED;
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
247 }
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
248
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
249 /*
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
250 * if the requested webdav resource(file) is a directory, we create
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
251 * a response for every child
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
252 */
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 if(S_ISDIR(st.st_mode)) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 DIR *dir = opendir(ppath);
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 if(dir == NULL) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 protocol_status(sn, rq, 500, NULL);
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
257 printf("webdav_propfind: DIR is null\n");
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 return REQ_ABORTED;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 }
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
260
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 struct dirent *f;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 while((f = readdir(dir)) != NULL) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 if(strcmp(f->d_name, ".") == 0 || strcmp(f->d_name, "..") == 0) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 continue;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 }
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
266
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 sstr_t filename = sstr(f->d_name);
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
268 sstr_t _path = sstr(ppath);
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 sstr_t _uri = sstr(uri);
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
270 sstr_t ps;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
271 sstr_t us;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
272 ps.length = 0;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
273 ps.ptr = NULL;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
274 us.length = 0;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
275 us.ptr = NULL;
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
276 if(_path.ptr[_path.length - 1] != '/') {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
277 ps = sstrn("/", 1);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
278 }
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
279 if(_uri.ptr[_uri.length - 1] != '/') {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
280 us = sstrn("/", 1);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
281 }
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
282
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 sstr_t newuri;
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
284 newuri.length = filename.length + _uri.length + us.length;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 newuri.ptr = alloca(newuri.length + 1);
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
286 if(us.length == 1) {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
287 newuri = sstrncat(3, newuri, _uri, us, filename);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
288 } else {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
289 newuri = sstrncat(2, newuri, _uri, filename);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
290 }
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
291
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 sstr_t newpath;
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
293 newpath.length = _path.length + filename.length + ps.length;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 newpath.ptr = alloca(newpath.length + 1);
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
295 if(ps.length == 1) {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
296 newpath = sstrncat(3, newpath, _path, ps, filename);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
297 } else {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
298 newpath = sstrncat(2, newpath, _path, filename);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
299 }
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
300
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
301 /* child response */
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
302 dav_resource_response(davrq, newpath, newuri);
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 }
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
305
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
306 /* create the response for the requested resource */
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
307 dav_resource_response(davrq, sstr(ppath), sstr(uri));
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
308
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
309 /* end xml */
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 sbuf_puts(davrq->out, "</D:multistatus>\n");
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
311
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
312 /* send the xml response to the client */
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
313 protocol_status(sn, rq, 207, "Multi Status");
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 pblock_removekey(pb_key_content_type, rq->srvhdrs);
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 pblock_nvinsert("content-type", "text/xml", rq->srvhdrs);
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 pblock_nninsert("content-length", davrq->out->length, rq->srvhdrs);
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
317
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
318 //pblock_nvinsert("connection", "close", rq->srvhdrs);
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319 http_start_response(sn, rq);
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
320
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 net_write(sn->csd, davrq->out->ptr, davrq->out->length);
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
322
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
323
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
324 dav_free_propfind(davrq);
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
325
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 return REQ_PROCEED;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
329 int webdav_proppatch(pblock *pb, Session *sn, Request *rq) {
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
330 printf("webdav-proppatch\n");
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
331 /* TODO: clean up if errors occurs */
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
332 /* TODO: this is the same code as in propfind */
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
333 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
334 if(uri == NULL) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
335 /* TODO: error */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
336 return REQ_ABORTED;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
337 }
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
338
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
339 /* Get request body which contains the webdav XML request */
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
340 char *xml_body;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
341 size_t xml_len = 0;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
342
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
343 char *ctlen = pblock_findkeyval(pb_key_content_length, rq->headers);
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
344 if(ctlen) {
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
345 xml_len = atoi(ctlen);
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
346 } else {
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
347 /* invalid request */
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
348 printf("invalid request\n");
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
349 return REQ_ABORTED;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
350 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
351
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
352 xml_body = pool_malloc(sn->pool, xml_len + 1);
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
353 if(xml_body == NULL) {
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
354 return REQ_ABORTED;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
355 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
356 xml_body[xml_len] = 0;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
357 if(!xml_body) {
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
358 /* server error */
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
359 printf("server error\n");
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
360 return REQ_ABORTED;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
361 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
362
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
363 /* get request body */
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
364 int r = 0;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
365 char *xb = xml_body;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
366 size_t xl = xml_len;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
367 while((r = netbuf_getbytes(sn->inbuf, xb, xl)) != NETBUF_EOF) {
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
368 xb += r;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
369 xl -= r;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
370 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
371
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
372 /*
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
373 * parse the xml request and create the proppatch object
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
374 */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
375 ProppatchRequest *davrq = dav_parse_proppatch(sn, rq, xml_body, xml_len);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
376 davrq->sn = sn;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
377 davrq->rq = rq;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
378 davrq->out = sbuf_new(512);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
379 davrq->backend = create_property_backend();
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
380 davrq->propstat = propstat_create(sn->pool);
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
381
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
382 /* TODO: create prefixes for every namespace */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
383 XmlNs *ns = xmlnsmap_get(davrq->nsmap, "DAV:");
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
384 ns->prefix = "D";
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
385 ns->prelen = 1;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
386
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
387 /*
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
388 * begin multistatus response
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
389 *
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
390 * The webdav backend does the most work. The backend->proppatch function
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
391 * modifies the properties and adds status informations to the propstat
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
392 * member of the ProppatchRequest. All we have to do here is to create
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
393 * the xml response and send it to the client
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
394 */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
395
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
396 /* write xml response header */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
397 /* TODO: add possible xml namespaces */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
398 sbuf_puts(davrq->out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
399 sbuf_puts(davrq->out, "<D:multistatus xmlns:D=\"DAV:\">\n");
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
400
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
401 sbuf_puts(davrq->out, "<D:response>\n<D:href>");
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
402 sbuf_puts(davrq->out, uri);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
403 sbuf_puts(davrq->out, "</D:href>\n");
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
404
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
405 /* do proppatch operation */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
406 davrq->backend->proppatch(davrq->backend, davrq);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
407
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
408 propstat_write(davrq->propstat, davrq->out, 0);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
409
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
410 sbuf_puts(davrq->out, "</D:response>\n");
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
411 sbuf_puts(davrq->out, "</D:multistatus>\n");
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
412
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
413
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
414 /* send the xml response to the client */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
415 protocol_status(sn, rq, 207, "Multi Status");
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
416 pblock_removekey(pb_key_content_type, rq->srvhdrs);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
417 pblock_nvinsert("content-type", "text/xml", rq->srvhdrs);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
418 pblock_nninsert("content-length", davrq->out->length, rq->srvhdrs);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
419
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
420 //pblock_nvinsert("connection", "close", rq->srvhdrs);
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
421 http_start_response(sn, rq);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
422
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
423 net_write(sn->csd, davrq->out->ptr, davrq->out->length);
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
424
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
425 dav_free_proppatch(davrq);
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
426
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
427 return REQ_PROCEED;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
428 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
429
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
430 void dav_resource_response(PropfindRequest *davrq, sstr_t path, sstr_t uri) {
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
431 printf("dav_resource_response %s %s\n", sstrdup(path).ptr, sstrdup(uri).ptr);
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
432
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
433 sbuf_puts(davrq->out, "<D:response>\n");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
434 sbuf_puts(davrq->out, "<D:href>");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
435 sbuf_append(davrq->out, uri);
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
436 sbuf_puts(davrq->out, "</D:href>\n");
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
437
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
438 davrq->propertyBackend->propfind(davrq->propertyBackend, davrq, path.ptr);
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
439
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
440 if(davrq->prop) {
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
441 /*
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
442 * there are some properties written, so we close the
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
443 * prop and propstat tag
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
444 */
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
445 sbuf_puts(davrq->out, "</D:prop>\n");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
446 sbuf_puts(davrq->out, "<D:status>HTTP/1.1 200 OK</D:status>\n");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
447 sbuf_puts(davrq->out, "</D:propstat>\n");
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
448 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
449
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
450 if(davrq->notFoundProps != NULL) {
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
451 sbuf_puts(davrq->out, "<D:propstat>\n<D:prop>\n");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
452 DAV_FOREACH(elm, davrq->notFoundProps) {
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
453 DavProperty *prop = (DavProperty*)elm->data;
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
454 sbuf_puts(davrq->out, "<D:");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
455 sbuf_puts(davrq->out, prop->name);
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
456 sbuf_puts(davrq->out, " />\n");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
457 }
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
458 sbuf_puts(davrq->out, "</D:prop>\n");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
459 sbuf_puts(davrq->out, "<D:status>HTTP/1.1 404 Not Found</D:status>\n");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
460 sbuf_puts(davrq->out, "</D:propstat>\n");
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
461 }
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
462
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
463 sbuf_puts(davrq->out, "</D:response>\n");
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
464
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
465 /* reset */
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
466 davrq->prop = 0;
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
467 davrq->notFoundProps = NULL;
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
468 davrq->forbiddenProps = NULL;
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
469
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
470 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
471
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
472 void dav_propfind_add_str_prop(
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
473 PropfindRequest *davrq,
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
474 DavProperty* prop,
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
475 char *str,
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
476 size_t len)
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
477 {
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
478 if(!davrq->prop) {
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
479 sbuf_puts(davrq->out, "<D:propstat>\n<D:prop>\n");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
480 davrq->prop = 1;
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
481 }
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
482
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
483 sbuf_puts(davrq->out, "<D:");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
484 sbuf_puts(davrq->out, prop->name);
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
485 sbuf_puts(davrq->out, ">");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
486
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
487 sbuf_append(davrq->out, sstrn(str, len));
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
488
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
489 sbuf_puts(davrq->out, "</D:");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
490 sbuf_puts(davrq->out, prop->name);
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
491 sbuf_puts(davrq->out, ">\n");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
492 }
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
493
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
494 void dav_propfind_add_prop_error(
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
495 PropfindRequest *davrq,
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
496 DavProperty *prop,
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
497 int error)
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
498 {
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
499 // TODO: different errors
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
500 davrq->notFoundProps = ucx_dlist_append(davrq->notFoundProps, prop);
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
501 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
502
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
503
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
504
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
505
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
506 /* WebDAV Default Backend */
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
507 static DAVPropertyBackend dav_file_backend = {
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
508 dav_rq_propfind,
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
509 dav_rq_proppatch
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
510 };
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
511
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
512 DAVPropertyBackend* create_property_backend() {
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
513 return &dav_file_backend;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
514 }
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
515
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
516 void dav_rq_propfind(DAVPropertyBackend *b, PropfindRequest *rq ,char *path) {
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
517 struct stat st;
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
518 if(stat(path, &st) != 0) {
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
519 perror("dav_be_propfind");
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
520 fprintf(stderr, "Cannot get stat of file: %s\n", path);
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
521 }
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
522
50
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
523 if(rq->allprop) {
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
524 DavProperty prop;
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
525 prop.xmlns = "DAV:";
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
526
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
527 prop.name = "resourcetype";
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
528 if(S_ISDIR(st.st_mode)) {
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
529 dav_propfind_add_str_prop(rq, &prop, "<D:collection/>", 15);
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
530 } else {
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
531 dav_propfind_add_str_prop(rq, &prop, NULL, 0);
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
532 }
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
533
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
534 if(!S_ISDIR(st.st_mode)) {
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
535 prop.name = "getcontentlength";
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
536 char buf[32];
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
537 size_t n = snprintf(buf, 32, "%d", st.st_size);
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
538 dav_propfind_add_str_prop(rq, &prop, buf, n);
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
539 }
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
540
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
541 prop.name = "getlastmodified";
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
542 sstr_t s = date_format_http(st.st_mtim.tv_sec, rq->sn->pool);
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
543 dav_propfind_add_str_prop(rq, &prop, s.ptr, s.length);
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
544
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
545 prop.name = "creationdate";
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
546 s = date_format_iso8601(st.st_ctim.tv_sec, rq->sn->pool);
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
547 dav_propfind_add_str_prop(rq, &prop, s.ptr, s.length);
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
548
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
549 return;
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
550 }
4d39adda7a38 propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
551
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
552 DAV_FOREACH(elm, rq->properties) {
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
553 DavProperty *prop = (DavProperty*)elm->data;
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
554
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
555 char *s = prop->name;
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
556 if(!strcmp(s, "resourcetype")) {
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
557 if(S_ISDIR(st.st_mode)) {
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
558 dav_propfind_add_str_prop(rq, prop, "<D:collection/>", 15);
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
559 } else {
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
560 dav_propfind_add_str_prop(rq, prop, NULL, 0);
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
561 }
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
562 } else if(!strcmp(s, "getcontentlength") && !S_ISDIR(st.st_mode)) {
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
563 char buf[32];
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
564 size_t n = snprintf(buf, 32, "%d", st.st_size);
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
565 dav_propfind_add_str_prop(rq, prop, buf, n);
27
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
566 } else if(!strcmp(s, "getlastmodified")) {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
567 sstr_t s = date_format_http(st.st_mtim.tv_sec, rq->sn->pool);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
568 dav_propfind_add_str_prop(rq, prop, s.ptr, s.length);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
569 } else if(!strcmp(s, "creationdate")) {
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
570 sstr_t s = date_format_iso8601(st.st_ctim.tv_sec, rq->sn->pool);
05b7576dca2b added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
571 dav_propfind_add_str_prop(rq, prop, s.ptr, s.length);
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
572 } else {
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
573 dav_propfind_add_prop_error(rq, prop, 404);
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
574 }
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
575 }
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
576 }
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
577
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
578 void dav_rq_proppatch(DAVPropertyBackend *b, ProppatchRequest *rq) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
579 DAV_FOREACH(p, rq->setProps) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
580 XmlElement *prop = (XmlElement*)p->data;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
581 propstat_add(rq->propstat, 403, prop);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
582 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
583
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
584 DAV_FOREACH(p, rq->removeProps) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
585 XmlElement *prop = (XmlElement*)p->data;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
586 propstat_add(rq->propstat, 403, prop);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
587 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
588 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
589
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
590
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
591
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
592 /*---------------------------------- utils ----------------------------------*/
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
593
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
594 /* XmlNsMap */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
595
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
596 XmlNsMap* xmlnsmap_create(pool_handle_t *pool) {
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
597 XmlNsMap *map = malloc(sizeof(XmlNsMap));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
598 UcxMap *uxm = ucx_map_new(16);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
599 if(map == NULL || uxm == NULL) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
600 return NULL;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
601 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
602 map->map = uxm;
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
603 map->pool = pool;
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
604 return map;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
605 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
606
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
607 void xmlnsmap_free(XmlNsMap *map) {
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
608 ucx_map_free(map->map);
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
609 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
610
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
611 XmlNs* xmlnsmap_put(XmlNsMap *map, char *ns) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
612 XmlNs *xmlns = xmlnsmap_get(map, ns);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
613 if(xmlns != NULL) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
614 return xmlns;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
615 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
616
48
37a512d7b8f6 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
617 xmlns = pool_malloc(map->pool, sizeof(XmlNs));
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
618 if(xmlns == NULL) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
619 return NULL;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
620 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
621
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
622 xmlns->xmlns = ns;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
623 xmlns->nslen = strlen(ns);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
624
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
625 xmlns->prefix = NULL;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
626 xmlns->prelen = 0;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
627
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
628 ucx_map_cstr_put(map->map, ns, xmlns); /* TODO: check return value */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
629 return xmlns;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
630 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
631
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
632 XmlNs* xmlnsmap_get(XmlNsMap *map, char *ns) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
633 return ucx_map_cstr_get(map->map, ns);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
634 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
635
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
636
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
637 /* XmlElement */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
638
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
639 void xmlelm_add_child(XmlElement *parent, XmlElement *child) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
640 if(parent->ctlen == 0) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
641 parent->content = ucx_dlist_append(parent->content, child);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
642 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
643 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
644
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
645 void xmlelm_write(XmlElement *elm, sbuf_t *out, int wv) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
646 sbuf_append(out, sstrn("<", 1));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
647 sbuf_append(out, sstrn(elm->xmlns->prefix, elm->xmlns->prelen));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
648 sbuf_append(out, sstrn(":", 1));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
649 sbuf_append(out, elm->name);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
650
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
651 if(wv) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
652 if(elm->ctlen == 0) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
653 if(elm->content == NULL) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
654 sbuf_append(out, sstrn(" />", 3));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
655 } else {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
656 sbuf_append(out, sstrn(">", 1));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
657 DAV_FOREACH(pr, (UcxDlist*)elm->content) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
658 xmlelm_write((XmlElement*)pr->data, out, 1);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
659 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
660 sbuf_append(out, sstrn("</", 2));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
661 sbuf_append(out, sstrn(elm->xmlns->prefix, elm->xmlns->prelen));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
662 sbuf_append(out, sstrn(":", 1));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
663 sbuf_append(out, elm->name);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
664 sbuf_append(out, sstrn(">", 1));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
665 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
666 } else {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
667 sbuf_append(out, sstrn(" />", 3));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
668 sbuf_append(out, sstrn((char*)elm->content, elm->ctlen));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
669 sbuf_append(out, sstrn("</", 2));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
670 sbuf_append(out, sstrn(elm->xmlns->prefix, elm->xmlns->prelen));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
671 sbuf_append(out, sstrn(":", 1));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
672 sbuf_append(out, elm->name);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
673 sbuf_append(out, sstrn(">", 1));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
674 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
675 } else {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
676 sbuf_append(out, sstrn(" />", 3));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
677 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
678 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
679
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
680
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
681 /* PropstatMap */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
682
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
683 Propstat* propstat_create(pool_handle_t *pool) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
684 Propstat *propstat = (Propstat*)pool_malloc(pool, sizeof(Propstat));
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
685 propstat->map = ucx_map_new(8);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
686 propstat->okprop = NULL;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
687 propstat->pool = pool;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
688 return propstat;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
689 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
690
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
691 void propstat_add(Propstat *propstat, int status, XmlElement *prop) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
692 if(status == 200) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
693 propstat->okprop = ucx_dlist_append(propstat->okprop, prop);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
694 } else {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
695 UcxKey key;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
696 key.data = &status;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
697 key.len = sizeof(int);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
698
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
699 UcxDlist *list = ucx_map_get(propstat->map, key);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
700 list = ucx_dlist_append(list, prop);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
701
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
702 ucx_map_put(propstat->map, key, list);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
703 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
704 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
705
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
706 void propstat_write(Propstat *propstat, sbuf_t *out, int wv) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
707 if(propstat->okprop) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
708 sbuf_puts(out, "<D:propstat>\n<D:prop>\n");
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
709
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
710 DAV_FOREACH(prop, propstat->okprop) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
711 xmlelm_write((XmlElement*)prop->data, out, wv);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
712 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
713
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
714 sbuf_puts(out, "\n</D:prop>\n<D:status>HTTP/1.1 200 OK</D:status>\n");
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
715 sbuf_puts(out, "</D:propstat>\n");
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
716 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
717
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
718 UcxMapIterator iter = ucx_map_iterator(propstat->map);
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
719 UcxDlist *proplist;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
720 UCX_MAP_FOREACH(proplist, iter) {
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
721 if(proplist) {
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
722 sbuf_puts(out, "<D:propstat>\n<D:prop>\n");
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
723
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
724 DAV_FOREACH(prop, proplist) {
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
725 xmlelm_write((XmlElement*)prop->data, out, wv);
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
726 }
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
727
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
728 sbuf_puts(out, "\n</D:prop>\n<D:status>");
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
729
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
730 int status = *(int*)iter.cur->key.data;
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
731 if(status < 1000 && status > 0) {
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
732 char buf[5];
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
733 buf[4] = 0;
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
734 sprintf(buf, "%d ", status);
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
735 sbuf_puts(out, "HTTP/1.1 ");
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
736 sbuf_puts(out, buf);
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
737 sbuf_puts(out, (char*)protocol_status_message(status));
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
738 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
739
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
740 sbuf_puts(out, "</D:status>\n</D:propstat>\n");
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
741 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
742 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
743 }

mercurial