src/server/daemon/config.c

changeset 91
fac51f87def0
parent 88
73b3485e96f1
child 92
382bff43c6eb
equal deleted inserted replaced
90:279f343bbf6c 91:fac51f87def0
64 InitConfig *cfg = load_init_config(file); 64 InitConfig *cfg = load_init_config(file);
65 if(cfg == NULL) { 65 if(cfg == NULL) {
66 fprintf(stderr, "Cannot load init.conf\n"); 66 fprintf(stderr, "Cannot load init.conf\n");
67 return 1; 67 return 1;
68 } 68 }
69 UcxMempool *mp = cfg->parser.mp; 69 UcxAllocator *mp = cfg->parser.mp;
70 70
71 cfg_pool = pool_create(); // one pool for one Configuration 71 cfg_pool = pool_create(); // one pool for one Configuration
72 UcxDlist *dirs = cfg->directives; 72 UcxList *dirs = cfg->directives;
73 while(dirs != NULL) { 73 while(dirs != NULL) {
74 ConfigDirective *dir = dirs->data; 74 ConfigDirective *dir = dirs->data;
75 75
76 /* create NSAPI directive */ 76 /* create NSAPI directive */
77 directive *d = malloc(sizeof(directive)); 77 directive *d = malloc(sizeof(directive));
176 // horrible error 176 // horrible error
177 return NULL; 177 return NULL;
178 } 178 }
179 179
180 UcxList *list = ucx_map_sstr_get(serverconf->objects, sstrn("Runtime", 7)); 180 UcxList *list = ucx_map_sstr_get(serverconf->objects, sstrn("Runtime", 7));
181 UCX_FOREACH(UcxList*, list, elm) { 181 UCX_FOREACH(elm, list) {
182 ServerConfigObject *scfgobj = elm->data; 182 ServerConfigObject *scfgobj = elm->data;
183 if(cfg_handle_runtime(serverconfig, scfgobj)) { 183 if(cfg_handle_runtime(serverconfig, scfgobj)) {
184 // error 184 // error
185 return NULL; 185 return NULL;
186 } 186 }
187 } 187 }
188 188
189 list = ucx_map_sstr_get(serverconf->objects, sstrn("Threadpool", 10)); 189 list = ucx_map_sstr_get(serverconf->objects, sstrn("Threadpool", 10));
190 UCX_FOREACH(UcxList*, list, elm) { 190 UCX_FOREACH(elm, list) {
191 if(cfg_handle_threadpool(serverconfig, elm->data)) { 191 if(cfg_handle_threadpool(serverconfig, elm->data)) {
192 return NULL; 192 return NULL;
193 } 193 }
194 } 194 }
195 // check thread pool config 195 // check thread pool config
197 /* critical error */ 197 /* critical error */
198 return NULL; 198 return NULL;
199 } 199 }
200 200
201 list = ucx_map_sstr_get(serverconf->objects, sstrn("EventHandler", 12)); 201 list = ucx_map_sstr_get(serverconf->objects, sstrn("EventHandler", 12));
202 UCX_FOREACH(UcxList*, list, elm) { 202 UCX_FOREACH(elm, list) {
203 if(cfg_handle_eventhandler( 203 if(cfg_handle_eventhandler(
204 serverconfig, (ServerConfigObject*)elm->data)) { 204 serverconfig, (ServerConfigObject*)elm->data)) {
205 // error 205 // error
206 return NULL; 206 return NULL;
207 } 207 }
211 /* critical error */ 211 /* critical error */
212 return NULL; 212 return NULL;
213 } 213 }
214 214
215 list = ucx_map_sstr_get(serverconf->objects, sstrn("AccessLog", 9)); 215 list = ucx_map_sstr_get(serverconf->objects, sstrn("AccessLog", 9));
216 UCX_FOREACH(UcxList*, list, elm) { 216 UCX_FOREACH(elm, list) {
217 ServerConfigObject *scfgobj = elm->data; 217 ServerConfigObject *scfgobj = elm->data;
218 if(cfg_handle_accesslog(serverconfig, scfgobj)) { 218 if(cfg_handle_accesslog(serverconfig, scfgobj)) {
219 return NULL; 219 return NULL;
220 } 220 }
221 } 221 }
222 222
223 list = ucx_map_sstr_get(serverconf->objects, sstrn("AuthDB", 6)); 223 list = ucx_map_sstr_get(serverconf->objects, sstrn("AuthDB", 6));
224 UCX_FOREACH(UcxList*, list, elm) { 224 UCX_FOREACH(elm, list) {
225 ServerConfigObject *scfgobj = elm->data; 225 ServerConfigObject *scfgobj = elm->data;
226 if(cfg_handle_authdb(serverconfig, scfgobj)) { 226 if(cfg_handle_authdb(serverconfig, scfgobj)) {
227 return NULL; 227 return NULL;
228 } 228 }
229 } 229 }
230 230
231 list = ucx_map_sstr_get(serverconf->objects, sstrn("Listener", 8)); 231 list = ucx_map_sstr_get(serverconf->objects, sstrn("Listener", 8));
232 UCX_FOREACH(UcxList*, list, elm) { 232 UCX_FOREACH(elm, list) {
233 ServerConfigObject *scfgobj = elm->data; 233 ServerConfigObject *scfgobj = elm->data;
234 if(cfg_handle_listener(serverconfig, scfgobj)) { 234 if(cfg_handle_listener(serverconfig, scfgobj)) {
235 return NULL; 235 return NULL;
236 } 236 }
237 } 237 }
238 238
239 list = ucx_map_sstr_get(serverconf->objects, sstrn("VirtualServer", 13)); 239 list = ucx_map_sstr_get(serverconf->objects, sstrn("VirtualServer", 13));
240 UCX_FOREACH(UcxList*, list, elm) { 240 UCX_FOREACH(elm, list) {
241 ServerConfigObject *scfgobj = elm->data; 241 ServerConfigObject *scfgobj = elm->data;
242 if(cfg_handle_vs(serverconfig, scfgobj)) { 242 if(cfg_handle_vs(serverconfig, scfgobj)) {
243 return NULL; 243 return NULL;
244 } 244 }
245 } 245 }
288 } 288 }
289 289
290 int cfg_handle_runtime(ServerConfiguration *cfg, ServerConfigObject *obj) { 290 int cfg_handle_runtime(ServerConfiguration *cfg, ServerConfigObject *obj) {
291 sstr_t user = cfg_directivelist_get_str(obj->directives, sstr("User")); 291 sstr_t user = cfg_directivelist_get_str(obj->directives, sstr("User"));
292 if(user.ptr) { 292 if(user.ptr) {
293 cfg->user = sstrdup_pool(cfg->pool, user); 293 //cfg->user = sstrdup_pool(cfg->pool, user);
294 } 294 }
295 sstr_t tmp = cfg_directivelist_get_str(obj->directives, sstr("Temp")); 295 sstr_t tmp = cfg_directivelist_get_str(obj->directives, sstr("Temp"));
296 if(tmp.ptr) { 296 if(tmp.ptr) {
297 cfg->tmp = sstrdup_pool(cfg->pool, tmp); 297 cfg->tmp = sstrdup_pool(cfg->pool, tmp);
298 } else { 298 } else {
306 sstr_t base = sstr("config/"); 306 sstr_t base = sstr("config/");
307 sstr_t file; 307 sstr_t file;
308 file.length = base.length + mf.length; 308 file.length = base.length + mf.length;
309 file.ptr = alloca(file.length + 1); 309 file.ptr = alloca(file.length + 1);
310 file.ptr[file.length] = 0; 310 file.ptr[file.length] = 0;
311 file = sstrncat(2, file, base, mf); 311 file = sstrncat(file, 2, base, mf);
312 312
313 ConfigFile *f = cfgmgr_get_file(file); 313 ConfigFile *f = cfgmgr_get_file(file);
314 if(f == NULL) { 314 if(f == NULL) {
315 f = malloc(sizeof(ConfigFile)); 315 f = malloc(sizeof(ConfigFile));
316 f->data = NULL; 316 f->data = NULL;
608 sstr_t base = sstr("config/"); 608 sstr_t base = sstr("config/");
609 sstr_t file; 609 sstr_t file;
610 file.length = base.length + objfile.length + 1; 610 file.length = base.length + objfile.length + 1;
611 file.ptr = alloca(file.length); 611 file.ptr = alloca(file.length);
612 file.ptr[file.length] = 0; 612 file.ptr[file.length] = 0;
613 file = sstrncat(2, file, base, objfile); 613 file = sstrncat(file, 2, base, objfile);
614 614
615 // the file is managed by the configuration manager 615 // the file is managed by the configuration manager
616 ConfigFile *f = cfgmgr_get_file(file); 616 ConfigFile *f = cfgmgr_get_file(file);
617 if(f == NULL) { 617 if(f == NULL) {
618 f = malloc(sizeof(ConfigFile)); 618 f = malloc(sizeof(ConfigFile));
633 633
634 // load acl config file 634 // load acl config file
635 file.length = base.length + aclfile.length + 1; 635 file.length = base.length + aclfile.length + 1;
636 file.ptr = alloca(file.length); 636 file.ptr = alloca(file.length);
637 file.ptr[file.length] = 0; 637 file.ptr[file.length] = 0;
638 file = sstrncat(2, file, base, aclfile); 638 file = sstrncat(file, 2, base, aclfile);
639 639
640 ConfigFile *aclf = cfgmgr_get_file(file); 640 ConfigFile *aclf = cfgmgr_get_file(file);
641 if(aclf == NULL) { 641 if(aclf == NULL) {
642 aclf = malloc(sizeof(ConfigFile)); 642 aclf = malloc(sizeof(ConfigFile));
643 aclf->data = NULL; 643 aclf->data = NULL;
694 HTTPObjectConfig* load_obj_conf(char *file) { 694 HTTPObjectConfig* load_obj_conf(char *file) {
695 printf("load_obj_conf\n"); 695 printf("load_obj_conf\n");
696 696
697 // new conf function test 697 // new conf function test
698 ObjectConfig *cfg = load_object_config(file); 698 ObjectConfig *cfg = load_object_config(file);
699 UcxMempool *mp = cfg->parser.mp; 699 UcxAllocator *mp = cfg->parser.mp;
700 if(cfg == NULL) { 700 if(cfg == NULL) {
701 return NULL; 701 return NULL;
702 } 702 }
703 703
704 // create object config 704 // create object config
707 conf->pool = pool; 707 conf->pool = pool;
708 708
709 // convert ObjectConfig to HTTPObjectConfig 709 // convert ObjectConfig to HTTPObjectConfig
710 710
711 // add objects 711 // add objects
712 conf->nobj = ucx_dlist_size(cfg->objects); 712 conf->nobj = ucx_list_size(cfg->objects);
713 conf->objects = pool_calloc(pool, conf->nobj, sizeof(httpd_object*)); 713 conf->objects = pool_calloc(pool, conf->nobj, sizeof(httpd_object*));
714 714
715 UcxDlist *objlist = cfg->objects; 715 UcxList *objlist = cfg->objects;
716 int i = 0; 716 int i = 0;
717 while(objlist != NULL) { 717 while(objlist != NULL) {
718 ConfigObject *cob = objlist->data; 718 ConfigObject *cob = objlist->data;
719 719
720 // get name and ppath 720 // get name and ppath
733 733
734 conf->objects[i] = obj; 734 conf->objects[i] = obj;
735 735
736 // add directives 736 // add directives
737 for(int i=0;i<6;i++) { 737 for(int i=0;i<6;i++) {
738 UcxDlist *dirs = cob->directives[i]; 738 UcxList *dirs = cob->directives[i];
739 while(dirs != NULL) { 739 while(dirs != NULL) {
740 ConfigDirective *cfgdir = dirs->data; 740 ConfigDirective *cfgdir = dirs->data;
741 741
742 directive *d = pool_malloc(pool, sizeof(directive)); 742 directive *d = pool_malloc(pool, sizeof(directive));
743 if(cfgdir->condition) { 743 if(cfgdir->condition) {
790 mimemap->ref = 1; 790 mimemap->ref = 1;
791 UcxMap *map = ucx_map_new((mimecfg->ntypes * 3) / 2); 791 UcxMap *map = ucx_map_new((mimecfg->ntypes * 3) / 2);
792 mimemap->map = map; 792 mimemap->map = map;
793 793
794 // add ext type pairs 794 // add ext type pairs
795 UCX_FOREACH(UcxList*, mimecfg->directives, md) { 795 UCX_FOREACH(md, mimecfg->directives) {
796 MimeDirective *d = md->data; 796 MimeDirective *d = md->data;
797 // add the type for each extension to the map 797 // add the type for each extension to the map
798 UCX_FOREACH(UcxList*, d->exts, xl) { 798 UCX_FOREACH(xl, d->exts) {
799 sstr_t ext = sstr(xl->data); 799 sstr_t ext = sstr(xl->data);
800 sstr_t value = sstrdup(d->type); 800 sstr_t value = sstrdup(d->type);
801 ucx_map_sstr_put(map, ext, value.ptr); 801 ucx_map_sstr_put(map, ext, value.ptr);
802 } 802 }
803 } 803 }
834 834
835 int acl_conf_reload(ConfigFile *file, ServerConfiguration *cfg) { 835 int acl_conf_reload(ConfigFile *file, ServerConfiguration *cfg) {
836 ACLFile *aclfile = load_acl_file(file->file.ptr); 836 ACLFile *aclfile = load_acl_file(file->file.ptr);
837 837
838 ACLData *acldata = acl_data_new(); 838 ACLData *acldata = acl_data_new();
839 UCX_FOREACH(UcxList*, aclfile->namedACLs, elm) { 839 UCX_FOREACH(elm, aclfile->namedACLs) {
840 ACLConfig *ac = elm->data; 840 ACLConfig *ac = elm->data;
841 ACLList *acl = acl_config_convert(cfg, ac); 841 ACLList *acl = acl_config_convert(cfg, ac);
842 printf("put acl: %s\n", ac->id.ptr); 842 printf("put acl: %s\n", ac->id.ptr);
843 ucx_map_sstr_put(acldata->namedACLs, ac->id, acl); 843 ucx_map_sstr_put(acldata->namedACLs, ac->id, acl);
844 } 844 }
872 WSAce **eces = calloc(s, sizeof(WSAce*)); 872 WSAce **eces = calloc(s, sizeof(WSAce*));
873 int ai = 0; 873 int ai = 0;
874 int ei = 0; 874 int ei = 0;
875 875
876 // convert entries 876 // convert entries
877 UCX_FOREACH(UcxList*, acl->entries, elm) { 877 UCX_FOREACH(elm, acl->entries) {
878 ACEConfig *acecfg = elm->data; 878 ACEConfig *acecfg = elm->data;
879 879
880 // copy data 880 // copy data
881 WSAce *ace = malloc(sizeof(WSAce)); 881 WSAce *ace = malloc(sizeof(WSAce));
882 ace->access_mask = acecfg->access_mask; 882 ace->access_mask = acecfg->access_mask;
932 return 1; 932 return 1;
933 } 933 }
934 934
935 Keyfile *keyfile = keyfile_new(); 935 Keyfile *keyfile = keyfile_new();
936 936
937 UCX_FOREACH(UcxList*, conf->users, elm) { 937 UCX_FOREACH(elm, conf->users) {
938 KeyfileEntry *user = elm->data; 938 KeyfileEntry *user = elm->data;
939 keyfile_add_user( 939 keyfile_add_user(
940 keyfile, 940 keyfile,
941 user->name, 941 user->name,
942 user->hashtype, 942 user->hashtype,

mercurial