src/server/config/serverconfig.c

changeset 579
e10457d74fe1
parent 512
afcdb57e329d
equal deleted inserted replaced
578:eb48f716b31c 579:e10457d74fe1
39 39
40 #include <cx/buffer.h> 40 #include <cx/buffer.h>
41 #include <cx/utils.h> 41 #include <cx/utils.h>
42 42
43 ServerConfig* serverconfig_load(const char *file) { 43 ServerConfig* serverconfig_load(const char *file) {
44 CxMempool *mp = cxBasicMempoolCreate(512); 44 CxMempool *mp = cxMempoolCreateSimple(512);
45 if(!mp) { 45 if(!mp) {
46 return NULL; 46 return NULL;
47 } 47 }
48 48
49 ConfigParser2 parser; 49 ConfigParser2 parser;
52 parser.filename = file; 52 parser.filename = file;
53 parser.allow_hierarchy = true; 53 parser.allow_hierarchy = true;
54 parser.delim = ""; 54 parser.delim = "";
55 ConfigNode *root = serverconfig_load_file(&parser, file); 55 ConfigNode *root = serverconfig_load_file(&parser, file);
56 if(!root) { 56 if(!root) {
57 cxMempoolDestroy(mp); 57 cxMempoolFree(mp);
58 return NULL; 58 return NULL;
59 } 59 }
60 60
61 ServerConfig *scfg = cxMalloc(mp->allocator, sizeof(ServerConfig)); 61 ServerConfig *scfg = cxMalloc(mp->allocator, sizeof(ServerConfig));
62 if(!scfg) { 62 if(!scfg) {
63 cxMempoolDestroy(mp); 63 cxMempoolFree(mp);
64 return NULL; 64 return NULL;
65 } 65 }
66 scfg->root = root; 66 scfg->root = root;
67 scfg->mp = mp; 67 scfg->mp = mp;
68 scfg->tab = cx_str("\t"); 68 scfg->tab = cx_str("\t");
449 //test_print_config(&root_obj); 449 //test_print_config(&root_obj);
450 return root_obj; 450 return root_obj;
451 } 451 }
452 452
453 void serverconfig_free(ServerConfig *cfg) { 453 void serverconfig_free(ServerConfig *cfg) {
454 cxMempoolDestroy(cfg->mp); 454 cxMempoolFree(cfg->mp);
455 } 455 }
456 456
457 ConfigNode* serverconfig_get_node(ConfigNode *parent, ConfigNodeType type, cxstring name) { 457 ConfigNode* serverconfig_get_node(ConfigNode *parent, ConfigNodeType type, cxstring name) {
458 for(ConfigNode *node=parent->children_begin;node;node=node->next) { 458 for(ConfigNode *node=parent->children_begin;node;node=node->next) {
459 if(node->type == type && !cx_strcasecmp(cx_strcast(node->name), name)) { 459 if(node->type == type && !cx_strcasecmp(cx_strcast(node->name), name)) {

mercurial