src/server/webdav/webdav.c

Tue, 09 Jul 2013 20:56:01 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 09 Jul 2013 20:56:01 +0200
changeset 86
49bb6c8ceb2b
parent 85
b62e77d8e80c
child 87
bdec069d2239
permissions
-rw-r--r--

replaced usage of deprecated openldap functions

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

mercurial