src/server/daemon/config.c

changeset 419
f1d29785ad2d
parent 418
b7dcc9c4f270
child 420
0b42a35d6add
equal deleted inserted replaced
418:b7dcc9c4f270 419:f1d29785ad2d
73 InitConfig *cfg = initconfig_load(file); 73 InitConfig *cfg = initconfig_load(file);
74 if(cfg == NULL) { 74 if(cfg == NULL) {
75 log_ereport(LOG_FAILURE, "Cannot load init.conf"); 75 log_ereport(LOG_FAILURE, "Cannot load init.conf");
76 return 1; 76 return 1;
77 } 77 }
78 CxAllocator *mp = cfg->mp;
79 init_pool = pool_create(); 78 init_pool = pool_create();
80 79
81 ConfigNode *dir = cfg->root->children_begin; 80 ConfigNode *dir = cfg->root->children_begin;
82 while(dir) { 81 while(dir) {
83 if(dir->type != CONFIG_NODE_DIRECTIVE) { 82 if(dir->type != CONFIG_NODE_DIRECTIVE) {
836 } 835 }
837 836
838 return ret; 837 return ret;
839 } 838 }
840 839
841 static int convert_objconf(ServerConfiguration *scfg, ObjectConfig *cfg, HTTPObjectConfig *conf, cxmutstr file) { 840 static int convert_objconf(ServerConfiguration *scfg, ObjectConfig2 *cfg, HTTPObjectConfig *conf, cxmutstr file) {
842 pool_handle_t *pool = conf->pool; 841 pool_handle_t *pool = conf->pool;
843 842
844 CxList *objlist = cfg->objects;
845 CxIterator iter = cxListIterator(objlist, 0);
846 int i = 0; 843 int i = 0;
847 cx_foreach(ConfigObject*, cob, iter) { 844 for(ConfigNode *objnode=cfg->root->children_begin;objnode;objnode=objnode->next) {
845 if(objnode->type != CONFIG_NODE_OBJECT) {
846 continue;
847 }
848
848 // get name and ppath 849 // get name and ppath
850 cxmutstr cfg_name = cfg_param_get(objnode->args, cx_str("name"));
851 cxmutstr cfg_ppath = cfg_param_get(objnode->args, cx_str("ppath"));
852
849 char *name = NULL; 853 char *name = NULL;
850 char *ppath = NULL; 854 char *ppath = NULL;
851 if(cob->name.length > 0) { 855
852 name = cx_strdup_pool(pool, cob->name).ptr; 856 if(cfg_name.length > 0) {
857 name = cx_strdup_pool(pool, cfg_name).ptr;
853 if(!name) return -1; 858 if(!name) return -1;
854 } 859 }
855 if(cob->ppath.length > 0) { 860 if(cfg_ppath.length > 0) {
856 ppath = cx_strdup_pool(pool, cob->ppath).ptr; 861 ppath = cx_strdup_pool(pool, cfg_ppath).ptr;
857 if(!ppath) return -1; 862 if(!ppath) return -1;
858 } 863 }
859 864
860 // create and add object 865 // create and add object
861 httpd_object *obj = object_new(pool, name); 866 httpd_object *obj = object_new(pool, name);
862 if(!obj) return -1; 867 if(!obj) return -1;
863 obj->path = NULL; 868 obj->path = NULL;
864 869
865 conf->objects[i] = obj; 870 conf->objects[i] = obj;
866 871
872 // TODO: this doesn't work with If/Else... nodes
873 // and needs to be rewritten
867 // add directives 874 // add directives
868 for(int j=0;j<NUM_NSAPI_TYPES-1;j++) { 875 for(ConfigNode *dir=objnode->children_begin;dir;dir=dir->next) {
869 ConfigDirectiveList *dirs = cob->directives[j]; 876 if(dir->type != CONFIG_NODE_DIRECTIVE) {
870 while(dirs != NULL) { 877 continue;
871 ConfigDirective *cfgdir = dirs->directive;
872
873 directive *d = pool_malloc(pool, sizeof(directive));
874 if(!d) return -1;
875 if(cfgdir->condition) {
876 cxmutstr expr = cfgdir->condition->param_str;
877 d->cond = condition_from_str(pool, expr.ptr, expr.length);
878 } else {
879 d->cond = NULL;
880 }
881 d->param = pblock_create_pool(pool, 8);
882
883 // add params
884 ConfigParam *param = cfg_param_list(cfgdir->value, scfg->a);
885 while(param != NULL) {
886 pblock_nvlinsert(
887 param->name.ptr,
888 param->name.length,
889 param->value.ptr,
890 param->value.length,
891 d->param);
892 param = param->next;
893 }
894
895 // get function
896 char *func_name = pblock_findval("fn", d->param);
897 if(!func_name) {
898 log_ereport(LOG_MISCONFIG, "%s: Missing fn parameter", file.ptr);
899 return -1;
900 }
901 d->func = get_function(func_name);
902 if(!d->func) {
903 log_ereport(LOG_MISCONFIG, "func %s not found", func_name);
904 return -1;
905 }
906
907 dirs = dirs->next;
908
909 // add function to dtable
910 object_add_directive(obj, d, cfgdir->type_num);
911 } 878 }
912 } 879
880 directive *d = pool_malloc(pool, sizeof(directive));
881 if(!d) return -1;
882 d->param = pblock_create_pool(pool, 8);
883
884 // add params
885 ConfigParam *param = dir->args;
886 while(param != NULL) {
887 pblock_nvlinsert(
888 param->name.ptr,
889 param->name.length,
890 param->value.ptr,
891 param->value.length,
892 d->param);
893 param = param->next;
894 }
895
896 // get function
897 char *func_name = pblock_findval("fn", d->param);
898 if(!func_name) {
899 log_ereport(LOG_MISCONFIG, "%s: Missing fn parameter", file.ptr);
900 return -1;
901 }
902 d->func = get_function(func_name);
903 if(!d->func) {
904 log_ereport(LOG_MISCONFIG, "func %s not found", func_name);
905 return -1;
906 }
907
908 // add function to dtable
909 int dir_type = cfg_get_directive_type_num(cx_strcast(dir->name));
910 if(dir_type < 0) {
911 log_ereport(LOG_MISCONFIG, "unknown directive type %s", dir->name);
912 }
913 object_add_directive(obj, d, dir_type);
914 }
915
913 916
914 // next 917 // next
915 i++; 918 i++;
916 } 919 }
917 920
930 return NULL; 933 return NULL;
931 } 934 }
932 conf->pool = pool; 935 conf->pool = pool;
933 936
934 // load obj config file 937 // load obj config file
935 ObjectConfig *cfg = load_object_config(file.ptr); 938 ObjectConfig2 *cfg = objectconf_load(file.ptr);
936 if(!cfg) { 939 if(!cfg) {
937 return NULL; 940 return NULL;
938 } 941 }
939 942
940 // convert ObjectConfig to HTTPObjectConfig 943 // convert ObjectConfig to HTTPObjectConfig
941 944
942 // add objects 945 // add objects
943 conf->nobj = cfg->objects->size; 946 conf->nobj = serverconfig_children_count(cfg->root, CONFIG_NODE_OBJECT);
944 conf->objects = pool_calloc(pool, conf->nobj, sizeof(httpd_object*)); 947 conf->objects = pool_calloc(pool, conf->nobj, sizeof(httpd_object*));
945 if(conf->objects) { 948 if(conf->objects) {
946 ret = convert_objconf(scfg, cfg, conf, file); 949 ret = convert_objconf(scfg, cfg, conf, file);
947 } else { 950 } else {
948 ret = -1; 951 ret = -1;
949 } 952 }
950 953
951 free_object_config(cfg); 954 objectconf_free(cfg);
952 955
953 return !ret ? conf : NULL; 956 return !ret ? conf : NULL;
954 } 957 }
955 958
956 int mime_conf_load(ServerConfiguration *cfg, cxmutstr file) { 959 int mime_conf_load(ServerConfiguration *cfg, cxmutstr file) {

mercurial