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 OBJCONF_H 30 #define OBJCONF_H 31 32 #include "conf.h" 33 34 35 #include "serverconfig.h" 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 #define CFG_LEVEL_PREPEND(list, level) \ 42 cx_linked_list_prepend((void**)list, NULL, -1, offsetof(ConfigParserLevel, next), level) 43 44 typedef struct _conf_object { 45 ConfigLine *begin; 46 ConfigLine *end; 47 48 cxmutstr name; 49 cxmutstr ppath; 50 // directives 51 ConfigDirectiveList *directives[7]; 52 } ConfigObject; 53 54 /* 55 * representing a xml like level in the obj.conf tree 56 */ 57 typedef struct ConfigParserLevel ConfigParserLevel; 58 struct ConfigParserLevel { 59 ConfigTag *iftag; // last if tag 60 ConfigTag *tag; // root of this level 61 int levelnum; 62 ConfigParserLevel *next; 63 }; 64 65 typedef struct _obj_conf { 66 ConfigParser parser; 67 char *file; 68 //UcxDlist *lines; 69 //UcxList *conditions; 70 CxList *objects; 71 72 // private parser temp var 73 ConfigObject *obj; // add directives to this object 74 // private parser temp var 75 ConfigParserLevel *levels; // tree levels (stack) 76 77 } ObjectConfig; 78 79 // TODO: rename to ObjectConfig after old ObjectConfig is removed 80 typedef struct ObjectConfig2 { 81 CxMempool *mp; 82 ConfigNode *root; 83 } ObjectConfig2; 84 85 ObjectConfig2* objectconf_load(const char *file); 86 87 void objectconf_free(ObjectConfig2 *objconf); 88 89 int objectconf_validate_directive(ConfigParser2 *parser, ConfigNode *node); 90 91 int objectconf_validate_objbegin(ConfigParser2 *parser, ConfigNode *node); 92 93 int objectconf_validate_objend(ConfigParser2 *parser, ConfigNode *node); 94 95 96 97 ObjectConfig *load_object_config(char *file); 98 99 void free_object_config(ObjectConfig *conf); 100 101 int objconf_parse(void *p, ConfigLine *begin, ConfigLine *end, cxmutstr line); 102 103 int objconf_on_begin_tag(ObjectConfig *conf, ConfigTag *tag); 104 105 int objconf_on_end_tag(ObjectConfig *conf, cxmutstr tagname); 106 107 int objconf_on_directive(ObjectConfig *conf, ConfigDirective *dir); 108 109 110 #ifdef __cplusplus 111 } 112 #endif 113 114 #endif /* OBJCONF_H */ 115 116