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 #ifndef OBJECT_H 30 #define OBJECT_H 31 32 #include "../public/nsapi.h" 33 #include "pool.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 // TODO: Enum auslagern in andere Datei? 40 enum RequestStage { 41 NSAPIAuthTrans = 0, 42 NSAPINameTrans, 43 NSAPIPathCheck, 44 NSAPIObjectType, 45 NSAPIService, 46 NSAPIError, 47 NSAPIAddLog, 48 REQ_FINISH, 49 NUM_NSAPI_TYPES 50 }; 51 typedef enum RequestStage RequestStage; 52 53 typedef struct Condition Condition; 54 typedef int8_t ConditionResult; 55 typedef struct Expression Expression; 56 typedef enum OperandType OperandType; 57 typedef enum Operator Operator; 58 typedef enum VarType VarType; 59 60 typedef struct NSAPIContext NSAPIContext; 61 typedef struct HTTPObjectConfig HTTPObjectConfig; 62 63 struct directive { 64 FuncStruct *func; 65 pblock *param; 66 Condition *cond; 67 }; 68 69 struct dtable { 70 directive **dirs; 71 int ndir; 72 }; 73 74 struct httpd_object { 75 pool_handle_t *pool; 76 char *name; 77 char *path; 78 dtable *dt; 79 int nd; 80 }; 81 82 struct httpd_objset { 83 httpd_object **obj; 84 int pos; 85 }; 86 87 struct Condition { 88 Condition *parent; 89 Expression *expression; 90 int index; // used by NSAPIContext to link expression with result 91 }; 92 93 struct Expression { 94 // TODO 95 int n; 96 }; 97 98 99 struct NSAPIContext{ 100 HTTPObjectConfig *conf; 101 102 ConditionResult **results; 103 int nres; 104 int nmaxres; 105 106 //httpd_objset *objset; 107 int last_req_code; 108 109 int objset_index; 110 int dtable_index; 111 }; 112 113 struct HTTPObjectConfig { 114 httpd_object **objects; 115 int nobj; 116 pool_handle_t *pool; 117 uint32_t ref; // reference counter 118 }; 119 120 /* 121 * creates a new httpd_object 122 */ 123 httpd_object* object_new(pool_handle_t *pool, char *name); 124 125 /* 126 * frees an httpd_object 127 */ 128 void object_free(httpd_object *obj); 129 130 /* 131 * adds a directive to the object with the type dt (enum RequestPhase) 132 */ 133 void object_add_directive(httpd_object *obj, directive *dir, int dt); 134 135 /* 136 * get a list of all directives with a specific type 137 */ 138 #define object_get_dtable(obj,type) &obj->dt[type]; 139 140 141 142 /* 143 * creates a new httpd_objset 144 */ 145 httpd_objset* objset_create(pool_handle_t *pool); 146 147 /* 148 * adds a object to the objset 149 */ 150 void objset_add_object(pool_handle_t *p, httpd_objset *os, httpd_object *obj); 151 152 153 /* 154 * creates a new HTTPObjectConfig 155 */ 156 // TODO 157 158 /* 159 * adds an object to the object configuration 160 */ 161 void httpobjconf_add_object(HTTPObjectConfig *conf, httpd_object *obj); 162 163 164 165 /* 166 * prepares the NSAPI context for the next request stage 167 */ 168 void nsapi_context_next_stage(NSAPIContext *context); 169 170 Condition* condition_from_str(pool_handle_t *pool, char *expr, size_t len); 171 Expression* expression_from_str(pool_handle_t *pool, char *expr, size_t len); 172 173 int condition_evaluate(Condition *condition, Session *sn, Request *rq); 174 175 176 #ifdef __cplusplus 177 } 178 #endif 179 180 #endif /* OBJECT_H */ 181 182