Wed, 28 Oct 2015 17:59:34 +0100
using readdir_r instead of readdir
13 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
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 | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
31 | #include <string.h> | |
32 | ||
33 | #include "webdav.h" | |
91 | 34 | #include <ucx/list.h> |
35 | #include <ucx/string.h> | |
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
36 | #include "../util/pool.h" |
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
37 | #include "../util/pblock.h" |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
38 | #include "../util/date.h" |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
39 | #include "../util/util.h" |
13 | 40 | |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
41 | #include "../daemon/vfs.h" |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
42 | #include "../daemon/protocol.h" |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
43 | |
13 | 44 | #include "davparser.h" |
85
b62e77d8e80c
replaced propfind parser with new libxml2 parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
45 | #include "parser.h" |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
46 | #include "persistence.h" |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
47 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
48 | static UcxMap *pmgr_map; // char*, PersistenceManager |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
49 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
50 | int webdav_init(pblock *pb, Session *sn, Request *rq) { |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
51 | pmgr_map = ucx_map_new(8); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
52 | PersistenceManager *defaultmgr = create_property_backend(); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
53 | ucx_map_cstr_put(pmgr_map, "default", defaultmgr); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
54 | return REQ_PROCEED; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
55 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
56 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
57 | void webdav_add_persistence_manager(char *name, PersistenceManager *mgr) { |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
58 | if(!pmgr_map) { |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
59 | webdav_init(NULL, NULL, NULL); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
60 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
61 | ucx_map_cstr_put(pmgr_map, name, mgr); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
62 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
63 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
64 | int webdav_setcollection(pblock *pb, Session *sn, Request *rq) { |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
65 | //char *name = pblock_findkeyval(pb_key_name, pb); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
66 | char *db = pblock_findval("db", pb); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
67 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
68 | if(!db) { |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
69 | db = "default"; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
70 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
71 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
72 | // setup DavCollection |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
73 | DavCollection *dav = pool_malloc(sn->pool, sizeof(DavCollection)); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
74 | dav->mgr = ucx_map_cstr_get(pmgr_map, db); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
75 | rq->davCollection = dav; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
76 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
77 | return REQ_NOACTION; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
78 | } |
13 | 79 | |
80 | int webdav_service(pblock *pb, Session *sn, Request *rq) { | |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
81 | char *method = pblock_findkeyval(pb_key_method, rq->reqpb); |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
82 | if(method == NULL) { |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
83 | return REQ_ABORTED; |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
84 | } |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
85 | |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
86 | if(!strcmp(method, "PROPFIND")) { |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
87 | return webdav_propfind(pb, sn, rq); |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
88 | } else if(!strcmp(method, "PROPPATCH")) { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
89 | return webdav_proppatch(pb, sn, rq); |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
90 | } else if(!strcmp(method, "PUT")) { |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
91 | return webdav_put(pb, sn, rq); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
92 | } else if(!strcmp(method, "DELETE")) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
93 | return webdav_delete(pb, sn, rq); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
94 | } else if(!strcmp(method, "MKCOL")) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
95 | return webdav_mkcol(pb, sn, rq); |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
96 | } |
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 | return REQ_NOACTION; |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
99 | } |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
100 | |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
101 | int webdav_put(pblock *pb, Session *sn, Request *rq) { |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
102 | int length = 0; |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
103 | |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
104 | char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars); |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
105 | char *ctlen = pblock_findkeyval(pb_key_content_length, rq->headers); |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
106 | if(ctlen) { |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
107 | length = atoi(ctlen); |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
108 | } else { |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
109 | /* invalid request */ |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
110 | printf("invalid request\n"); |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
111 | return REQ_ABORTED; |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
112 | } |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
113 | |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
114 | printf("PUT length: %d\n", length); |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
115 | |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
116 | //int status = 201; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
117 | //FILE *out = fopen(ppath, "w"); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
118 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
119 | VFSContext *vfs = vfs_request_context(sn, rq); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
120 | SYS_FILE out = vfs_openWO(vfs, ppath); |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
121 | if(out == NULL) { |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
122 | fprintf(stderr, "vfs_openWO(%s, \"w\") failed\n", ppath); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
123 | //protocol_status(sn, rq, 500, NULL); |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
124 | return REQ_ABORTED; |
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
125 | } |
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
126 | |
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
127 | if(length > 0) { |
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
128 | size_t len = (length > 4096) ? (4096) : (length); |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
129 | char *buffer = pool_malloc(sn->pool, len); |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
130 | |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
131 | int r; |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
132 | int r2 = 0; |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
133 | while(r2 < length) { |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
134 | r = netbuf_getbytes(sn->inbuf, buffer, len); |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
135 | if(r == NETBUF_EOF) { |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
136 | break; |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
137 | } |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
138 | system_fwrite(out, buffer, r); |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
139 | |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
140 | r2 += r; |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
141 | } |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
142 | |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
143 | pool_free(sn->pool, buffer); |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
144 | } else { |
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
145 | |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
146 | } |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
147 | vfs_close(out); |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
148 | |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
149 | protocol_status(sn, rq, 201, NULL); |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
150 | pblock_removekey(pb_key_content_type, rq->srvhdrs); |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
151 | pblock_nninsert("content-length", 0, rq->srvhdrs); |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
152 | http_start_response(sn, rq); |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
153 | |
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
154 | return REQ_PROCEED; |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
155 | } |
13 | 156 | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
157 | 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
|
158 | 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
|
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 | |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
161 | VFSContext *vfs = vfs_request_context(sn, rq); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
162 | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
163 | int status = 204; |
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 | struct stat st; |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
166 | if(vfs_stat(vfs, ppath, &st)) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
167 | return REQ_ABORTED; |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
168 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
169 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
170 | if(!strcmp(uri, "/")) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
171 | status = 403; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
172 | } 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
|
173 | if(rmdir(ppath) != 0) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
174 | /* ERROR */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
175 | status = 403; |
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 | } else { |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
178 | if(vfs_unlink(vfs, ppath)) { |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
179 | /* ERROR */ |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
180 | return REQ_ABORTED; |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
181 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
182 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
183 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
184 | protocol_status(sn, rq, status, NULL); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
185 | 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
|
186 | pblock_nninsert("content-length", 0, rq->srvhdrs); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
187 | http_start_response(sn, rq); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
188 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
189 | return REQ_PROCEED; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
190 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
191 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
192 | 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
|
193 | 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
|
194 | |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
195 | VFSContext *vfs = vfs_request_context(sn, rq); |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
196 | if(vfs_mkdir(vfs, ppath)) { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
197 | return REQ_ABORTED; |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
198 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
199 | |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
200 | protocol_status(sn, rq, 201, NULL); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
201 | 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
|
202 | pblock_nninsert("content-length", 0, rq->srvhdrs); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
203 | http_start_response(sn, rq); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
204 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
205 | return REQ_ABORTED; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
206 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
207 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
208 | 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
|
209 | return REQ_ABORTED; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
210 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
211 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
212 | 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
|
213 | return REQ_ABORTED; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
214 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
215 | |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
216 | int webdav_propfind(pblock *pb, Session *sn, Request *rq) { |
13 | 217 | /* TODO: clean up if errors occurs */ |
218 | ||
219 | /* Get request body which contains the webdav XML request */ | |
220 | char *xml_body; | |
221 | size_t xml_len = 0; | |
222 | ||
223 | char *ctlen = pblock_findkeyval(pb_key_content_length, rq->headers); | |
224 | if(ctlen) { | |
225 | xml_len = atoi(ctlen); | |
226 | } else { | |
227 | /* invalid request */ | |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
228 | printf("invalid request\n"); |
13 | 229 | return REQ_ABORTED; |
230 | } | |
231 | ||
232 | xml_body = pool_malloc(sn->pool, xml_len + 1); | |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
233 | if(xml_body == NULL) { |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
234 | return REQ_ABORTED; |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
235 | } |
13 | 236 | xml_body[xml_len] = 0; |
237 | if(!xml_body) { | |
238 | /* server error */ | |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
239 | printf("server error\n"); |
13 | 240 | return REQ_ABORTED; |
241 | } | |
242 | ||
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
243 | /* get request body */ |
13 | 244 | int r = 0; |
245 | char *xb = xml_body; | |
246 | size_t xl = xml_len; | |
247 | while((r = netbuf_getbytes(sn->inbuf, xb, xl)) != NETBUF_EOF) { | |
248 | xb += r; | |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
249 | xl -= r; |
13 | 250 | } |
251 | ||
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
252 | /* |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
253 | * get requested properties and initialize some stuff |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
254 | */ |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
255 | DavCollection *collection = rq->davCollection; |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
85
diff
changeset
|
256 | if(!collection) { |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
85
diff
changeset
|
257 | collection = pool_malloc(sn->pool, sizeof(DavCollection)); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
85
diff
changeset
|
258 | collection->mgr = ucx_map_cstr_get(pmgr_map, "default"); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
85
diff
changeset
|
259 | } |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
260 | |
85
b62e77d8e80c
replaced propfind parser with new libxml2 parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
261 | PropfindRequest *davrq = dav_parse_propfind2(sn, rq, xml_body, xml_len); |
13 | 262 | davrq->sn = sn; |
263 | davrq->rq = rq; | |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
264 | davrq->out = sbuf_new(512); |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
265 | davrq->persistencemgr = collection->mgr; |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
266 | |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
267 | /* begin multistatus response */ |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
268 | char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); |
13 | 269 | char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars); |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
270 | davrq->uri = uri; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
271 | davrq->path = ppath; |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
272 | |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
273 | VFSContext *vfs = vfs_request_context(sn, rq); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
274 | |
13 | 275 | struct stat st; |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
276 | if(vfs_stat(vfs, ppath, &st) != 0) { |
13 | 277 | return REQ_ABORTED; |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
278 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
279 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
280 | // begin propfind |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
281 | davrq->isdir = S_ISDIR(st.st_mode); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
282 | davrq->persistencemgr->propfind_begin(davrq->persistencemgr, davrq); |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
283 | |
64
c7f5b062e622
added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
284 | // create the response for the requested resource |
c7f5b062e622
added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
285 | dav_resource_response(davrq, sstr(ppath), sstr(uri)); |
c7f5b062e622
added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
286 | |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
287 | /* |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
288 | * 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
|
289 | * a response for every child |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
290 | */ |
13 | 291 | if(S_ISDIR(st.st_mode)) { |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
292 | VFS_DIR dir = vfs_opendir(vfs, ppath); |
13 | 293 | if(dir == NULL) { |
294 | return REQ_ABORTED; | |
295 | } | |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
296 | |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
297 | VFS_ENTRY entry; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
298 | while(vfs_readdir(dir, &entry)) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
299 | sstr_t newpath = util_path_append(sn->pool, ppath, entry.name); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
300 | sstr_t newuri = util_path_append(sn->pool, uri, entry.name); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
301 | // child response |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
302 | dav_resource_response(davrq, newpath, newuri); |
13 | 303 | } |
304 | } | |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
305 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
306 | // end propfind |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
307 | davrq->persistencemgr->propfind_begin(davrq->persistencemgr, davrq); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
308 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
309 | // end xml |
13 | 310 | sbuf_puts(davrq->out, "</D:multistatus>\n"); |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
311 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
312 | //printf("%s\n", davrq->out->ptr); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
313 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
314 | // write xml response header |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
315 | sbuf_t *out = sbuf_new(256); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
316 | sbuf_puts(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
317 | sbuf_puts(out, "<D:multistatus"); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
318 | UcxMapIterator nsiter = ucx_map_iterator(davrq->nsmap->map); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
319 | XmlNs *ns; |
88 | 320 | UCX_MAP_FOREACH(key, ns, nsiter) { |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
321 | sbuf_puts(out, " xmlns:"); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
322 | sbuf_puts(out, ns->prefix); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
323 | sbuf_puts(out, "=\""); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
324 | sbuf_puts(out, ns->xmlns); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
325 | sbuf_puts(out, "\""); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
326 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
327 | sbuf_puts(out, ">\n"); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
328 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
329 | // send the xml response to the client |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
330 | protocol_status(sn, rq, 207, "Multi Status"); |
13 | 331 | pblock_removekey(pb_key_content_type, rq->srvhdrs); |
332 | pblock_nvinsert("content-type", "text/xml", rq->srvhdrs); | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
333 | pblock_nninsert( |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
334 | "content-length", |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
335 | out->length + davrq->out->length, |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
336 | rq->srvhdrs); |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
337 | |
13 | 338 | http_start_response(sn, rq); |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
339 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
340 | // write content |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
341 | size_t nr; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
342 | nr = net_write(sn->csd, out->ptr, out->length); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
343 | nr = 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
|
344 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
345 | sbuf_free(out); |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
346 | dav_free_propfind(davrq); |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
347 | |
13 | 348 | return REQ_PROCEED; |
349 | } | |
350 | ||
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
351 | 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
|
352 | printf("webdav-proppatch\n"); |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
353 | /* TODO: clean up if errors occurs */ |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
354 | /* 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
|
355 | 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
|
356 | if(uri == NULL) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
357 | /* TODO: error */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
358 | return REQ_ABORTED; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
359 | } |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
360 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
361 | // Get request body which contains the webdav XML request |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
362 | char *xml_body; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
363 | size_t xml_len = 0; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
364 | |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
365 | char *ctlen = pblock_findkeyval(pb_key_content_length, rq->headers); |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
366 | if(ctlen) { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
367 | xml_len = atoi(ctlen); |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
368 | } else { |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
369 | // invalid request |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
370 | printf("invalid request\n"); |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
371 | return REQ_ABORTED; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
372 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
373 | |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
374 | xml_body = pool_malloc(sn->pool, xml_len + 1); |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
375 | if(xml_body == NULL) { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
376 | return REQ_ABORTED; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
377 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
378 | xml_body[xml_len] = 0; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
379 | if(!xml_body) { |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
380 | // server error |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
381 | printf("server error\n"); |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
382 | return REQ_ABORTED; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
383 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
384 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
385 | // get request body |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
386 | int r = 0; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
387 | char *xb = xml_body; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
388 | size_t xl = xml_len; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
389 | while((r = netbuf_getbytes(sn->inbuf, xb, xl)) != NETBUF_EOF) { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
390 | xb += r; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
391 | xl -= r; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
392 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
393 | |
30
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 | * 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
|
396 | */ |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
397 | DavCollection *collection = rq->davCollection; |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
85
diff
changeset
|
398 | if(!collection) { |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
85
diff
changeset
|
399 | collection = pool_malloc(sn->pool, sizeof(DavCollection)); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
85
diff
changeset
|
400 | collection->mgr = ucx_map_cstr_get(pmgr_map, "default"); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
85
diff
changeset
|
401 | } |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
402 | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
403 | 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
|
404 | davrq->sn = sn; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
405 | davrq->rq = rq; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
406 | davrq->out = sbuf_new(512); |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
407 | davrq->backend = collection->mgr; |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
408 | davrq->propstat = propstat_create(sn->pool); |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
409 | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
410 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
411 | /* |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
412 | * begin multistatus response |
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 | * 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
|
415 | * 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
|
416 | * 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
|
417 | * 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
|
418 | */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
419 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
420 | /* write xml response header */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
421 | sbuf_puts(davrq->out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
422 | //sbuf_puts(davrq->out, "<D:multistatus xmlns:D=\"DAV:\">\n"); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
423 | sbuf_puts(davrq->out, "<D:multistatus"); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
424 | UcxMapIterator nsiter = ucx_map_iterator(davrq->nsmap->map); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
425 | XmlNs *ns; |
88 | 426 | UCX_MAP_FOREACH(key, ns, nsiter) { |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
427 | sbuf_puts(davrq->out, " xmlns:"); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
428 | sbuf_puts(davrq->out, ns->prefix); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
429 | sbuf_puts(davrq->out, "=\""); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
430 | sbuf_puts(davrq->out, ns->xmlns); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
431 | sbuf_puts(davrq->out, "\""); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
432 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
433 | sbuf_puts(davrq->out, ">\n"); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
434 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
435 | 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
|
436 | sbuf_puts(davrq->out, uri); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
437 | sbuf_puts(davrq->out, "</D:href>\n"); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
438 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
439 | /* do proppatch operation */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
440 | davrq->backend->proppatch(davrq->backend, davrq); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
441 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
442 | propstat_write(davrq->propstat, davrq->out, 0); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
443 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
444 | sbuf_puts(davrq->out, "</D:response>\n"); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
445 | sbuf_puts(davrq->out, "</D:multistatus>\n"); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
446 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
447 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
448 | /* send the xml response to the client */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
449 | protocol_status(sn, rq, 207, "Multi Status"); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
450 | 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
|
451 | 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
|
452 | 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
|
453 | |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
454 | //pblock_nvinsert("connection", "close", rq->srvhdrs); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
455 | http_start_response(sn, rq); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
456 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
457 | 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
|
458 | |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
459 | dav_free_proppatch(davrq); |
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
460 | |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
461 | return REQ_PROCEED; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
462 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
463 | |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
464 | 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
|
465 | 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
|
466 | |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
467 | sbuf_puts(davrq->out, "<D:response>\n"); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
468 | sbuf_puts(davrq->out, "<D:href>"); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
469 | sbuf_append(davrq->out, uri); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
470 | sbuf_puts(davrq->out, "</D:href>\n"); |
13 | 471 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
472 | if(davrq->persistencemgr->vfs_props) { |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
473 | // get some DAV properties from the file system |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
474 | dav_rq_propfind(davrq->persistencemgr, davrq, path.ptr); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
475 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
476 | davrq->persistencemgr->propfind(davrq->persistencemgr, davrq, path.ptr); |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
477 | |
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 | /* |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
480 | * there are some properties written, so we close the |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
481 | * prop and propstat tag |
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:prop>\n"); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
484 | 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
|
485 | sbuf_puts(davrq->out, "</D:propstat>\n"); |
13 | 486 | } |
487 | ||
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
488 | if(davrq->notFoundProps != NULL) { |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
489 | sbuf_puts(davrq->out, "<D:propstat>\n<D:prop>\n"); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
490 | DAV_FOREACH(elm, davrq->notFoundProps) { |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
491 | DavProperty *prop = (DavProperty*)elm->data; |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
492 | sbuf_put(davrq->out, '<'); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
493 | sbuf_puts(davrq->out, prop->xmlns->prefix); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
494 | sbuf_put(davrq->out, ':'); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
495 | |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
496 | sbuf_puts(davrq->out, prop->name); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
497 | sbuf_puts(davrq->out, " />\n"); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
498 | } |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
499 | sbuf_puts(davrq->out, "</D:prop>\n"); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
500 | 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
|
501 | sbuf_puts(davrq->out, "</D:propstat>\n"); |
13 | 502 | } |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
503 | |
13 | 504 | sbuf_puts(davrq->out, "</D:response>\n"); |
505 | ||
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
506 | /* reset */ |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
507 | davrq->prop = 0; |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
508 | davrq->notFoundProps = NULL; |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
509 | davrq->forbiddenProps = NULL; |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
510 | |
13 | 511 | } |
512 | ||
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
513 | void dav_propfind_add_str_prop( |
13 | 514 | PropfindRequest *davrq, |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
515 | DavProperty* prop, |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
516 | char *str, |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
517 | size_t len) |
13 | 518 | { |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
519 | if(!davrq->prop) { |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
520 | sbuf_puts(davrq->out, "<D:propstat>\n<D:prop>\n"); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
521 | davrq->prop = 1; |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
522 | } |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
523 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
524 | sbuf_put(davrq->out, '<'); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
525 | sbuf_puts(davrq->out, prop->xmlns->prefix); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
526 | sbuf_put(davrq->out, ':'); |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
527 | sbuf_puts(davrq->out, prop->name); |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
528 | sbuf_put(davrq->out, '>'); |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
529 | |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
530 | sbuf_append(davrq->out, sstrn(str, len)); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
531 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
532 | sbuf_puts(davrq->out, "</"); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
533 | sbuf_puts(davrq->out, prop->xmlns->prefix); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
534 | sbuf_put(davrq->out, ':'); |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
535 | sbuf_puts(davrq->out, prop->name); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
536 | sbuf_puts(davrq->out, ">\n"); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
537 | } |
13 | 538 | |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
539 | void dav_propfind_add_prop_error( |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
540 | PropfindRequest *davrq, |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
541 | DavProperty *prop, |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
542 | int error) |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
543 | { |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
544 | // TODO: different errors |
91 | 545 | davrq->notFoundProps = ucx_list_append(davrq->notFoundProps, prop); |
13 | 546 | } |
547 | ||
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
548 | |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
549 | |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
550 | |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
551 | /* WebDAV Default Backend */ |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
552 | static PersistenceManager dav_file_backend = { |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
553 | dav_rq_propfind_begin, |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
554 | dav_rq_propfind_end, |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
555 | dav_rq_propfind, |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
556 | dav_rq_proppatch, |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
557 | 0 |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
558 | }; |
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
559 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
560 | PersistenceManager* create_property_backend() { |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
561 | return &dav_file_backend; |
13 | 562 | } |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
563 | |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
564 | void dav_rq_propfind_begin(PersistenceManager *mgr, PropfindRequest *rq) { |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
565 | |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
566 | } |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
567 | |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
568 | void dav_rq_propfind_end(PersistenceManager *mgr, PropfindRequest *rq) { |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
569 | |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
570 | } |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
571 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
572 | void dav_rq_propfind(PersistenceManager *b, PropfindRequest *rq ,char *path) { |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
573 | struct stat st; |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
574 | if(stat(path, &st) != 0) { |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
575 | perror("dav_be_propfind"); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
576 | fprintf(stderr, "Cannot get stat of file: %s\n", path); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
577 | } |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
578 | |
50
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
579 | if(rq->allprop) { |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
580 | DavProperty prop; |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
581 | prop.xmlns = xmlnsmap_get(rq->nsmap, "DAV:"); |
50
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
582 | |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
583 | prop.name = "resourcetype"; |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
584 | if(S_ISDIR(st.st_mode)) { |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
585 | dav_propfind_add_str_prop(rq, &prop, "<D:collection/>", 15); |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
586 | } else { |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
587 | dav_propfind_add_str_prop(rq, &prop, NULL, 0); |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
588 | } |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
589 | |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
590 | if(!S_ISDIR(st.st_mode)) { |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
591 | prop.name = "getcontentlength"; |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
592 | char buf[32]; |
94
6b15a094d996
minor fixes in snprintf and build system
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
593 | size_t n = snprintf(buf, 32, "%jd", st.st_size); |
50
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
594 | dav_propfind_add_str_prop(rq, &prop, buf, n); |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
595 | } |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
596 | |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
597 | prop.name = "getlastmodified"; |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
598 | |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
599 | sstr_t s = date_format_http(st.st_mtime, rq->sn->pool); |
50
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
600 | 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
|
601 | |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
602 | prop.name = "creationdate"; |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
603 | s = date_format_iso8601(st.st_ctime, rq->sn->pool); |
50
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
604 | 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
|
605 | |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
606 | return; |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
607 | } |
4d39adda7a38
propfind supports allprop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
608 | |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
609 | DAV_FOREACH(elm, rq->properties) { |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
610 | DavProperty *prop = (DavProperty*)elm->data; |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
611 | |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
612 | char *s = prop->name; |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
613 | if(!strcmp(s, "resourcetype")) { |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
614 | if(S_ISDIR(st.st_mode)) { |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
615 | dav_propfind_add_str_prop(rq, prop, "<D:collection/>", 15); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
616 | } else { |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
617 | dav_propfind_add_str_prop(rq, prop, NULL, 0); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
618 | } |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
619 | } else if(!strcmp(s, "getcontentlength") && !S_ISDIR(st.st_mode)) { |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
620 | char buf[32]; |
94
6b15a094d996
minor fixes in snprintf and build system
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
621 | size_t n = snprintf(buf, 32, "%jd", st.st_size); |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
622 | dav_propfind_add_str_prop(rq, prop, buf, n); |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
623 | } else if(!strcmp(s, "getlastmodified")) { |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
624 | sstr_t s = date_format_http(st.st_mtime, rq->sn->pool); |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
625 | 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
|
626 | } else if(!strcmp(s, "creationdate")) { |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
627 | sstr_t s = date_format_iso8601(st.st_ctime, rq->sn->pool); |
27
05b7576dca2b
added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
628 | 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
|
629 | } else { |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
630 | dav_propfind_add_prop_error(rq, prop, 404); |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
631 | } |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
632 | } |
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
633 | } |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
634 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
635 | void dav_rq_proppatch(PersistenceManager *b, ProppatchRequest *rq) { |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
636 | DAV_FOREACH(p, rq->setProps) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
637 | XmlElement *prop = (XmlElement*)p->data; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
638 | propstat_add(rq->propstat, 403, prop); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
639 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
640 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
641 | DAV_FOREACH(p, rq->removeProps) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
642 | XmlElement *prop = (XmlElement*)p->data; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
643 | propstat_add(rq->propstat, 403, prop); |
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 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
646 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
647 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
648 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
649 | /*---------------------------------- utils ----------------------------------*/ |
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 | /* XmlNsMap */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
652 | |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
653 | XmlNsMap* xmlnsmap_create(pool_handle_t *pool) { |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
654 | XmlNsMap *map = pool_malloc(pool, sizeof(XmlNsMap)); |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
655 | UcxMap *uxm = ucx_map_new(16); // TODO: use pool for map |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
656 | if(map == NULL || uxm == NULL) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
657 | return NULL; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
658 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
659 | map->map = uxm; |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
660 | map->pool = pool; |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
661 | map->num = 0; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
662 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
663 | // create DAV: namespace |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
664 | XmlNs *ns = pool_malloc(map->pool, sizeof(XmlNs)); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
665 | ns->xmlns = "DAV:"; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
666 | ns->prefix = "D"; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
667 | ns->nslen = 4; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
668 | ns->prelen = 1; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
669 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
670 | ucx_map_cstr_put(uxm, "DAV:", ns); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
671 | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
672 | return map; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
673 | } |
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 | void xmlnsmap_free(XmlNsMap *map) { |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
676 | ucx_map_free(map->map); |
30
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 | XmlNs* xmlnsmap_put(XmlNsMap *map, char *ns) { |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
85
diff
changeset
|
680 | if(!ns) { |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
85
diff
changeset
|
681 | return NULL; |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
85
diff
changeset
|
682 | } |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
85
diff
changeset
|
683 | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
684 | XmlNs *xmlns = xmlnsmap_get(map, ns); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
685 | if(xmlns != NULL) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
686 | return xmlns; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
687 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
688 | |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
689 | 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
|
690 | if(xmlns == NULL) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
691 | return NULL; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
692 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
693 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
694 | sstr_t newns = sstrdup(sstr(ns)); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
695 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
696 | xmlns->xmlns = newns.ptr; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
697 | xmlns->nslen = newns.length; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
698 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
699 | xmlns->prefix = pool_calloc(map->pool, 1, 8); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
700 | xmlns->prelen = snprintf(xmlns->prefix, 7, "x%d", map->num); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
701 | |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
702 | ucx_map_cstr_put(map->map, ns, xmlns); // TODO: check return value |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
703 | map->num++; |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
704 | return xmlns; |
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 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
707 | XmlNs* xmlnsmap_get(XmlNsMap *map, char *ns) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
708 | 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
|
709 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
710 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
711 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
712 | /* XmlElement */ |
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 | 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
|
715 | if(parent->ctlen == 0) { |
91 | 716 | parent->content = ucx_list_append(parent->content, child); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
717 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
718 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
719 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
720 | void xmlelm_write(XmlElement *elm, Buffer *out, int wv) { |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
721 | sbuf_append(out, sstrn("<", 1)); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
722 | 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
|
723 | sbuf_append(out, sstrn(":", 1)); |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
724 | sbuf_append(out, sstr(elm->name)); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
725 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
726 | if(wv) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
727 | if(elm->ctlen == 0) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
728 | if(elm->content == NULL) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
729 | sbuf_append(out, sstrn(" />", 3)); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
730 | } else { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
731 | sbuf_append(out, sstrn(">", 1)); |
91 | 732 | DAV_FOREACH(pr, (UcxList*)elm->content) { |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
733 | xmlelm_write((XmlElement*)pr->data, out, 1); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
734 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
735 | sbuf_append(out, sstrn("</", 2)); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
736 | 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
|
737 | sbuf_append(out, sstrn(":", 1)); |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
738 | sbuf_append(out, sstr(elm->name)); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
739 | sbuf_append(out, sstrn(">", 1)); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
740 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
741 | } else { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
742 | sbuf_append(out, sstrn(" />", 3)); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
743 | 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
|
744 | sbuf_append(out, sstrn("</", 2)); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
745 | 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
|
746 | sbuf_append(out, sstrn(":", 1)); |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
747 | sbuf_append(out, sstr(elm->name)); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
748 | sbuf_append(out, sstrn(">", 1)); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
749 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
750 | } else { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
751 | sbuf_append(out, sstrn(" />", 3)); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
752 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
753 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
754 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
755 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
756 | /* PropstatMap */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
757 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
758 | Propstat* propstat_create(pool_handle_t *pool) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
759 | 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
|
760 | propstat->map = ucx_map_new(8); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
761 | propstat->okprop = NULL; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
762 | propstat->pool = pool; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
763 | return propstat; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
764 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
765 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
766 | 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
|
767 | if(status == 200) { |
91 | 768 | propstat->okprop = ucx_list_append(propstat->okprop, prop); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
769 | } else { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
770 | UcxKey key; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
771 | key.data = &status; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
772 | key.len = sizeof(int); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
773 | |
91 | 774 | UcxList *list = ucx_map_get(propstat->map, key); |
775 | list = ucx_list_append(list, prop); | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
776 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
777 | ucx_map_put(propstat->map, key, list); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
778 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
779 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
780 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
781 | void propstat_write(Propstat *propstat, Buffer *out, int wv) { |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
782 | if(propstat->okprop) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
783 | 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
|
784 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
785 | DAV_FOREACH(prop, propstat->okprop) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
786 | xmlelm_write((XmlElement*)prop->data, out, wv); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
787 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
788 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
789 | 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
|
790 | sbuf_puts(out, "</D:propstat>\n"); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
791 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
792 | |
31 | 793 | UcxMapIterator iter = ucx_map_iterator(propstat->map); |
91 | 794 | UcxList *proplist; |
88 | 795 | UCX_MAP_FOREACH(key, proplist, iter) { |
31 | 796 | if(proplist) { |
797 | 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
|
798 | |
31 | 799 | DAV_FOREACH(prop, proplist) { |
800 | xmlelm_write((XmlElement*)prop->data, out, wv); | |
801 | } | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
802 | |
31 | 803 | 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
|
804 | |
31 | 805 | int status = *(int*)iter.cur->key.data; |
806 | if(status < 1000 && status > 0) { | |
807 | char buf[5]; | |
808 | buf[4] = 0; | |
809 | sprintf(buf, "%d ", status); | |
810 | sbuf_puts(out, "HTTP/1.1 "); | |
811 | sbuf_puts(out, buf); | |
812 | 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
|
813 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
814 | |
31 | 815 | 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
|
816 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
817 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
818 | } |