src/server/util/object.c

changeset 61
c858850f3d3a
parent 52
aced2245fb1c
child 83
28433f06d5ee
equal deleted inserted replaced
60:feb2f1e115c6 61:c858850f3d3a
33 #include "pool.h" 33 #include "pool.h"
34 #include "../daemon/func.h" 34 #include "../daemon/func.h"
35 35
36 36
37 37
38 httpd_object* object_new(char *name) { 38 httpd_object* object_new(pool_handle_t *pool, char *name) {
39 // TODO: Speicherverwaltung 39 // TODO: Speicherverwaltung
40 httpd_object *obj = malloc(sizeof(httpd_object)); 40 httpd_object *obj = pool_malloc(pool, sizeof(httpd_object));
41 obj->pool = pool;
41 obj->name = name; 42 obj->name = name;
42 obj->path = NULL; 43 obj->path = NULL;
43 44
44 // create directive table 45 // create directive table
45 obj->dt = calloc(sizeof(struct dtable), NUM_NSAPI_TYPES - 1); 46 obj->dt = pool_calloc(pool, NUM_NSAPI_TYPES - 1, sizeof(struct dtable));
46 obj->nd = NUM_NSAPI_TYPES - 1; 47 obj->nd = NUM_NSAPI_TYPES - 1;
47 48
48 return obj; 49 return obj;
49 } 50 }
50 51
51 void object_free(httpd_object *obj) { 52 void object_free(httpd_object *obj) {
52 free(obj->name); 53 //free(obj->name);
53 // TODO: free objects 54 //free(obj->dt);
54 free(obj->dt);
55 } 55 }
56 56
57 57
58 void object_add_directive(httpd_object *obj, directive *dir, int dt) { 58 void object_add_directive(httpd_object *obj, directive *dir, int dt) {
59 dtable *l = object_get_dtable(obj, dt); 59 dtable *l = object_get_dtable(obj, dt);
60 // allocate space for the new directive 60 // allocate space for the new directive
61 61
62 //l->dirs = realloc(l->dirs, (l->ndir+1)*sizeof(void*)); 62 //l->dirs = realloc(l->dirs, (l->ndir+1)*sizeof(void*));
63 /* TODO: aus irgend einem Grund funktioniert realloc nicht. warum?? */ 63 // TODO: use realloc
64 64
65 directive **drs = malloc((l->ndir+1)*sizeof(void*)); 65 directive **drs = pool_malloc(obj->pool, (l->ndir+1)*sizeof(void*));
66 for(int i=0;i<l->ndir;i++) { 66 for(int i=0;i<l->ndir;i++) {
67 drs[i] = l->dirs[i]; 67 drs[i] = l->dirs[i];
68 } 68 }
69 if(l->dirs != NULL) { 69 if(l->dirs != NULL) {
70 free(l->dirs); 70 pool_free(obj->pool, l->dirs);
71 } 71 }
72 l->dirs = drs; 72 l->dirs = drs;
73 73
74 // add directive 74 // add directive
75 l->dirs[l->ndir] = dir; 75 l->dirs[l->ndir] = dir;
93 } 93 }
94 os->obj[os->pos] = obj; 94 os->obj[os->pos] = obj;
95 os->pos++; 95 os->pos++;
96 } 96 }
97 97
98
99
100 // TODO: remove
101 httpd_objset* create_test_objset() {
102 httpd_objset *objset = malloc(sizeof(httpd_objset));
103 objset->obj = calloc(1, sizeof(httpd_object*));
104
105 httpd_object *obj = object_new("default");
106 objset->obj[0] = obj;
107 objset->pos = 1;
108
109 directive *d1 = malloc(sizeof(directive));
110 d1->func = get_function("test-nametrans");
111 d1->param = NULL;
112 object_add_directive(obj, d1, NSAPINameTrans);
113
114 directive *d2 = malloc(sizeof(directive));
115 d2->func = get_function("test-service");
116 d2->param = NULL;
117 object_add_directive(obj, d2, NSAPIService);
118
119 return objset;
120 }
121
122
123 void httpobjconf_add_object(HTTPObjectConfig *conf, httpd_object *obj) { 98 void httpobjconf_add_object(HTTPObjectConfig *conf, httpd_object *obj) {
124 conf->nobj++; 99 conf->nobj++;
125 conf->objects = realloc(conf->objects, conf->nobj * sizeof(void*)); 100 conf->objects = realloc(conf->objects, conf->nobj * sizeof(void*));
126 conf->objects[conf->nobj - 1] = obj; 101 conf->objects[conf->nobj - 1] = obj;
127 } 102 }

mercurial