src/server/util/object.c

Fri, 24 Jul 2020 08:00:11 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 24 Jul 2020 08:00:11 +0200
branch
webdav
changeset 252
5653a9626cc0
parent 107
7e81699d1f77
child 261
f2c772336ecd
permissions
-rw-r--r--

prepare webdav copy

3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
44
3da1f7b6847f added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
137197831306 minimal request handling
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
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
92
382bff43c6eb fixed some includes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
29 #include <ucx/string.h>
382bff43c6eb fixed some includes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
30
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
31 #include "../public/nsapi.h"
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "object.h"
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
35 #include "pool.h"
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
36 #include "../daemon/func.h"
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
40 httpd_object* object_new(pool_handle_t *pool, char *name) {
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 // TODO: Speicherverwaltung
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
42 httpd_object *obj = pool_malloc(pool, sizeof(httpd_object));
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
43 obj->pool = pool;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 obj->name = name;
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
45 obj->path = NULL;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 // create directive table
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
48 obj->dt = pool_calloc(pool, NUM_NSAPI_TYPES - 1, sizeof(struct dtable));
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 obj->nd = NUM_NSAPI_TYPES - 1;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 return obj;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 void object_free(httpd_object *obj) {
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
55 //free(obj->name);
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
56 //free(obj->dt);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 void object_add_directive(httpd_object *obj, directive *dir, int dt) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 dtable *l = object_get_dtable(obj, dt);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 // allocate space for the new directive
12
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
63
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
64 //l->dirs = realloc(l->dirs, (l->ndir+1)*sizeof(void*));
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
65 // TODO: use realloc
12
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
66
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
67 directive **drs = pool_malloc(obj->pool, (l->ndir+1)*sizeof(void*));
12
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
68 for(int i=0;i<l->ndir;i++) {
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
69 drs[i] = l->dirs[i];
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
70 }
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
71 if(l->dirs != NULL) {
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
72 pool_free(obj->pool, l->dirs);
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
73 }
12
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
74 l->dirs = drs;
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
75
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 // add directive
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
77 l->dirs[l->ndir] = dir;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 l->ndir++;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
82 /* objset functions */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
83 httpd_objset* objset_create(pool_handle_t *pool) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
84 httpd_objset *os = pool_malloc(pool, sizeof(httpd_objset));
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
85
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
86 os->obj = pool_calloc(pool, 2, sizeof(void*));
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
87 os->pos = 0;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
88
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
89 return os;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
90 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
91
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
92 void objset_add_object(pool_handle_t *p, httpd_objset *os, httpd_object *obj) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
93 if(os->pos != 0 && os->pos % 2 == 0) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
94 os->obj = pool_realloc(p, os->obj, (os->pos + 2) * sizeof(void*));
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
95 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
96 os->obj[os->pos] = obj;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
97 os->pos++;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
98 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
99
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
100 void httpobjconf_add_object(HTTPObjectConfig *conf, httpd_object *obj) {
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
101 conf->nobj++;
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
102 conf->objects = realloc(conf->objects, conf->nobj * sizeof(void*));
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
103 conf->objects[conf->nobj - 1] = obj;
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
104 }
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
105
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
106
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
107 void nsapi_context_next_stage(NSAPIContext *context) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
108 context->dtable_index = 0;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
109 context->objset_index = -1;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
110 context->last_req_code = REQ_NOACTION;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
111 }
83
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
112
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
113
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
114 Condition* condition_from_str(pool_handle_t *pool, char *expr, size_t len) {
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
115 Condition *cond = pool_malloc(pool, sizeof(Condition));
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
116 cond->expression = NULL;
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
117 cond->parent = NULL;
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
118 cond->index = 0;
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
119
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
120 printf("Expression: {");
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
121 fwrite(expr, len, 1, stdout);
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
122 printf("}\n");
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
123
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
124 cond->expression = expression_from_str(pool, expr, len);
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
125
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
126 return cond;
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
127 }
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
128
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
129 Expression* expression_from_str(pool_handle_t *pool, char *expr, size_t len) {
107
7e81699d1f77 removed old webdav and expression code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 92
diff changeset
130 return NULL;
83
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
131 }
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
132
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
133 int condition_evaluate(Condition *condition, Session *sn, Request *rq) {
107
7e81699d1f77 removed old webdav and expression code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 92
diff changeset
134 return 1;
83
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
135 }

mercurial