UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2013 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 <ucx/string.h> 30 31 #include "../public/nsapi.h" 32 33 #include "object.h" 34 35 #include "pool.h" 36 #include "../daemon/func.h" 37 38 39 40 httpd_object* object_new(pool_handle_t *pool, char *name) { 41 // TODO: Speicherverwaltung 42 httpd_object *obj = pool_malloc(pool, sizeof(httpd_object)); 43 obj->pool = pool; 44 obj->name = name; 45 obj->path = NULL; 46 47 // create directive table 48 obj->dt = pool_calloc(pool, NUM_NSAPI_TYPES - 1, sizeof(struct dtable)); 49 obj->nd = NUM_NSAPI_TYPES - 1; 50 51 return obj; 52 } 53 54 void object_free(httpd_object *obj) { 55 //free(obj->name); 56 //free(obj->dt); 57 } 58 59 60 void object_add_directive(httpd_object *obj, directive *dir, int dt) { 61 dtable *l = object_get_dtable(obj, dt); 62 // allocate space for the new directive 63 64 //l->dirs = realloc(l->dirs, (l->ndir+1)*sizeof(void*)); 65 // TODO: use realloc 66 67 directive **drs = pool_malloc(obj->pool, (l->ndir+1)*sizeof(void*)); 68 for(int i=0;i<l->ndir;i++) { 69 drs[i] = l->dirs[i]; 70 } 71 if(l->dirs != NULL) { 72 pool_free(obj->pool, l->dirs); 73 } 74 l->dirs = drs; 75 76 // add directive 77 l->dirs[l->ndir] = dir; 78 l->ndir++; 79 } 80 81 82 /* objset functions */ 83 httpd_objset* objset_create(pool_handle_t *pool) { 84 httpd_objset *os = pool_malloc(pool, sizeof(httpd_objset)); 85 86 os->obj = pool_calloc(pool, 2, sizeof(void*)); 87 os->pos = 0; 88 89 return os; 90 } 91 92 void objset_add_object(pool_handle_t *p, httpd_objset *os, httpd_object *obj) { 93 if(os->pos != 0 && os->pos % 2 == 0) { 94 os->obj = pool_realloc(p, os->obj, (os->pos + 2) * sizeof(void*)); 95 } 96 os->obj[os->pos] = obj; 97 os->pos++; 98 } 99 100 void httpobjconf_add_object(HTTPObjectConfig *conf, httpd_object *obj) { 101 conf->nobj++; 102 conf->objects = realloc(conf->objects, conf->nobj * sizeof(void*)); 103 conf->objects[conf->nobj - 1] = obj; 104 } 105 106 107 void nsapi_context_next_stage(NSAPIContext *context) { 108 context->dtable_index = 0; 109 context->objset_index = -1; 110 context->last_req_code = REQ_NOACTION; 111 } 112 113 114 Condition* condition_from_str(pool_handle_t *pool, char *expr, size_t len) { 115 Condition *cond = pool_malloc(pool, sizeof(Condition)); 116 cond->expression = NULL; 117 cond->parent = NULL; 118 cond->index = 0; 119 120 printf("Expression: {"); 121 fwrite(expr, len, 1, stdout); 122 printf("}\n"); 123 124 cond->expression = expression_from_str(pool, expr, len); 125 126 return cond; 127 } 128 129 Expression* expression_from_str(pool_handle_t *pool, char *expr, size_t len) { 130 return NULL; 131 } 132 133 int condition_evaluate(Condition *condition, Session *sn, Request *rq) { 134 return 1; 135 } 136