|
1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
3 * |
|
4 * Copyright 2011 Olaf Wintermann. All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 * POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 |
|
29 #include "nsapi.h" |
|
30 |
|
31 #include "object.h" |
|
32 |
|
33 #include "func.h" |
|
34 |
|
35 |
|
36 |
|
37 httpd_object* object_new(char *name) { |
|
38 // TODO: Speicherverwaltung |
|
39 httpd_object *obj = malloc(sizeof(httpd_object)); |
|
40 obj->name = name; |
|
41 |
|
42 // create directive table |
|
43 obj->dt = calloc(sizeof(struct dtable), NUM_NSAPI_TYPES - 1); |
|
44 obj->nd = NUM_NSAPI_TYPES - 1; |
|
45 |
|
46 return obj; |
|
47 } |
|
48 |
|
49 void object_free(httpd_object *obj) { |
|
50 free(obj->name); |
|
51 // TODO: free objects |
|
52 free(obj->dt); |
|
53 } |
|
54 |
|
55 |
|
56 void object_add_directive(httpd_object *obj, directive *dir, int dt) { |
|
57 dtable *l = object_get_dtable(obj, dt); |
|
58 // allocate space for the new directive |
|
59 l->directive = realloc(l->directive, (l->ndir+1)*sizeof(directive*)); |
|
60 // add directive |
|
61 l->directive[l->ndir] = dir; |
|
62 l->ndir++; |
|
63 } |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 httpd_objset* create_test_objset() { |
|
69 httpd_objset *objset = malloc(sizeof(httpd_objset)); |
|
70 objset->obj = calloc(1, sizeof(httpd_object*)); |
|
71 |
|
72 httpd_object *obj = object_new("default"); |
|
73 objset->obj[0] = obj; |
|
74 objset->pos = 1; |
|
75 |
|
76 directive *d1 = malloc(sizeof(directive)); |
|
77 d1->func = get_function("test-nametrans"); |
|
78 d1->param = NULL; |
|
79 object_add_directive(obj, d1, NSAPINameTrans); |
|
80 |
|
81 directive *d2 = malloc(sizeof(directive)); |
|
82 d2->func = get_function("test-service"); |
|
83 d2->param = NULL; |
|
84 object_add_directive(obj, d2, NSAPIService); |
|
85 |
|
86 return objset; |
|
87 } |
|
88 |