forked from UtrechtUniversity/davrods
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpropdb.c
More file actions
321 lines (285 loc) · 8.7 KB
/
propdb.c
File metadata and controls
321 lines (285 loc) · 8.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/**
* \file
* \brief Davrods property database.
* \author Chris Smeele
* \copyright Copyright (c) 2016, Utrecht University
*
* This file is part of Davrods.
*
* Davrods is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Davrods is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Davrods. If not, see <http://www.gnu.org/licenses/>.
*/
#include "propdb.h"
#include "prop.h"
#include "repo.h"
APLOG_USE_MODULE ( davrods);
struct dav_db
{
apr_pool_t *pool;
const dav_resource *resource;
size_t prop_iter;
};
static dav_error *dav_propdb_open (apr_pool_t *pool,
const dav_resource *resource, int ro, dav_db **pdb)
{
dav_error *error_p = NULL;
// Don't use pcalloc. dav will call propdb_close where we will free().
dav_db *db = malloc (sizeof(dav_db));
if (db)
{
db->pool = resource->pool;
db->resource = resource;
*pdb = db;
}
else
{
error_p = dav_new_error (pool, HTTP_INSUFFICIENT_STORAGE, DAV_ERR_LOCK_NO_DB, 0, "dav_propdb_open: Not enough memory");
}
return error_p;
}
static void dav_propdb_close (dav_db *db_p)
{
free (db_p);
}
static dav_error *dav_propdb_define_namespaces (dav_db *db, dav_xmlns_info *xi)
{
// TODO: Implementation, if needed.
ap_log_rerror (APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, db->resource->info->r,
"Unimplemented define namespaces request");
return NULL;
}
static void dav_append_prop (apr_pool_t *pool, const char *namespace,
const char *name, const char *value, apr_text_header *phdr)
{
const char *s;
if (strlen (value))
{
s = apr_psprintf (pool, "<%s%s>%s</%s%s>\n", namespace, name, value,
namespace, name);
}
else
{
s = apr_psprintf (pool, "<%s%s/>\n", namespace, name);
}
WHISPER("Outputting property XML: %s", s);
apr_text_append (pool, phdr, s);
}
static dav_error *dav_propdb_output_value (dav_db *db,
const dav_prop_name *name, dav_xmlns_info *xi, apr_text_header *phdr,
int *found)
{
WHISPER("PROP output request for prop name <%s,%s> of resource <%s>\n",
name->ns,
name->name,
db->resource->info->rods_path
);
*found = 0;
if (db->resource->exists)
{
if (strcmp (name->ns, "DAV:") == 0)
{
if (strcmp (name->name, "creationdate") == 0)
{
uint64_t timestamp = atoll (db->resource->info->stat->createTime);
char date_str [APR_RFC822_DATE_LEN] = { 0 };
int status = apr_rfc822_date (date_str, timestamp * 1000 * 1000);
dav_append_prop (db->pool, "D:", name->name,
status >= 0 ? date_str : "Thu, 01 Jan 1970 00:00:00 GMT",
phdr);
*found = 1;
}
else if (strcmp (name->name, "getcontentlength") == 0)
{
if (db->resource->collection)
{
WHISPER("404-ing Content length request for collection\n");
}
else
{
dav_append_prop (db->pool, "D:", name->name,
apr_psprintf (db->pool, "%" DAVRODS_SIZE_T_FMT,
db->resource->info->stat->objSize), phdr);
*found = 1;
}
}
else if (strcmp (name->name, "getetag") == 0)
{
const char *etag = davrods_hooks_repository.getetag (
db->resource);
if (etag && strlen (etag))
{
dav_append_prop (db->pool, "D:", name->name, etag, phdr);
*found = 1;
}
}
else if (strcmp (name->name, "getlastmodified") == 0)
{
uint64_t timestamp = atoll (db->resource->info->stat->modifyTime);
char date_str [APR_RFC822_DATE_LEN] = { 0 };
int status = apr_rfc822_date (date_str, timestamp * 1000 * 1000);
dav_append_prop (db->pool, "D:", name->name,
status >= 0 ? date_str : "Thu, 01 Jan 1970 00:00:00 GMT",
phdr);
*found = 1;
}
else if (strcmp (name->name, "checked-in") == 0)
{
}
else if (strcmp (name->name, "checked-out") == 0)
{
}
else
{
WHISPER("PROP request for unknown DAV: prop <%s>!\n", name->name);
}
}
else
{
WHISPER("404-ing Prop request for unsupported prop ns <%s>\n", name->ns);
}
}
else
{
/* WHISPER("404-ing PROP request for non-existent resource\n"); */
/* return NULL; */
// Let's assume this is a LOCKNULL resource.
// TODO: Check whether this is actually the case.
if (strcmp (name->ns, "DAV:") == 0)
{
if (strcmp (name->name, "creationdate") == 0)
{
dav_append_prop (db->pool, "D:", name->name,
"Thu, 01 Jan 1970 00:00:00 GMT", phdr);
*found = 1;
}
else if (strcmp (name->name, "getcontentlength") == 0)
{
dav_append_prop (db->pool, "D:", name->name,
apr_psprintf (db->pool, "%" DAVRODS_SIZE_T_FMT, 0), phdr);
*found = 1;
}
else if (strcmp (name->name, "getetag") == 0)
{
const char *etag = davrods_hooks_repository.getetag (
db->resource);
if (etag && strlen (etag))
{
dav_append_prop (db->pool, "D:", name->name, etag, phdr);
*found = 1;
}
}
else if (strcmp (name->name, "getlastmodified") == 0)
{
dav_append_prop (db->pool, "D:", name->name,
"Thu, 01 Jan 1970 00:00:00 GMT", phdr);
*found = 1;
}
else if (strcmp (name->name, "checked-in") == 0)
{
}
else if (strcmp (name->name, "checked-out") == 0)
{
}
}
else
{
return NULL;
}
}
return NULL;
}
static dav_error *dav_propdb_map_namespaces (dav_db *db,
const apr_array_header_t *namespaces, dav_namespace_map **mapping)
{
ap_log_rerror (APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, db->resource->info->r,
"Unimplemented map namespaces request");
int *pmap;
const char **puri;
int i;
for (i = namespaces->nelts, puri = (const char **) namespaces->elts; i -- > 0;
++ puri, ++ pmap)
{
WHISPER("- URI <%s>\n", *puri);
// TODO: Implementation, if needed.
}
return NULL;
}
static dav_error *dav_propdb_store (dav_db *db, const dav_prop_name *name,
const apr_xml_elem *elem, dav_namespace_map *mapping)
{
return dav_new_error (db->pool, HTTP_METHOD_NOT_ALLOWED, 0, 0,
"Property manipulation is not supported by this server.");
}
static dav_error *dav_propdb_remove (dav_db *db, const dav_prop_name *name)
{
return dav_new_error (db->pool, HTTP_METHOD_NOT_ALLOWED, 0, 0,
"Property manipulation is not supported by this server.");
}
static int dav_propdb_exists (dav_db *db, const dav_prop_name *name)
{
WHISPER("Prop exists <%s%s>? No.\n", name->ns, name->name);
// TODO: Implementation, if necessary.
return 0; // 0 = does not exist.
}
static dav_error *dav_propdb_next_name (dav_db *db, dav_prop_name *pname)
{
PING();
//if (db->resource->exists && db->prop_iter < DAVRODS_PROP_COUNT) {
// Don't care if a resource does not exist: It's probably a LOCKNULL resource.
if (db->prop_iter < DAVRODS_PROP_COUNT)
{
if (davrods_props [db->prop_iter].propid == DAV_PROPID_getcontentlength
&& db->resource->collection)
{
// This property is not available for collections, skip it.
db->prop_iter ++;
return dav_propdb_next_name (db, pname);
}
else
{
pname->ns = davrods_namespace_uris [davrods_props [db->prop_iter].ns];
pname->name = davrods_props [db->prop_iter].name;
db->prop_iter ++;
}
}
else
{
// This signifies the end of the property list.
pname->ns = pname->name = NULL;
}
return NULL;
}
static dav_error *dav_propdb_first_name (dav_db *db, dav_prop_name *pname)
{
db->prop_iter = 0;
return dav_propdb_next_name (db, pname);
}
static dav_error *dav_propdb_get_rollback (dav_db *db,
const dav_prop_name *name, dav_deadprop_rollback **prollback)
{
return dav_new_error (db->pool, HTTP_METHOD_NOT_ALLOWED, 0, 0,
"Property manipulation is not supported by this server.");
}
static dav_error * dav_propdb_apply_rollback (dav_db *db,
dav_deadprop_rollback *rollback)
{
return dav_new_error (db->pool, HTTP_METHOD_NOT_ALLOWED, 0, 0,
"Property manipulation is not supported by this server.");
}
const dav_hooks_db davrods_hooks_propdb = { dav_propdb_open, dav_propdb_close,
dav_propdb_define_namespaces, dav_propdb_output_value,
dav_propdb_map_namespaces, dav_propdb_store, dav_propdb_remove,
dav_propdb_exists, dav_propdb_first_name, dav_propdb_next_name,
dav_propdb_get_rollback, dav_propdb_apply_rollback,
NULL // An optional private context pointer. We don't need it.
};