src/server/daemon/config.c

changeset 74
5bc6d078fb2c
parent 71
069c152f6272
child 75
6195c92262a2
equal deleted inserted replaced
71:069c152f6272 74:5bc6d078fb2c
654 UcxMempool *mp = cfg->parser.mp; 654 UcxMempool *mp = cfg->parser.mp;
655 if(cfg == NULL) { 655 if(cfg == NULL) {
656 return NULL; 656 return NULL;
657 } 657 }
658 658
659 /* create object config */ 659 // create object config
660 pool_handle_t *pool = pool_create(); 660 pool_handle_t *pool = pool_create();
661 HTTPObjectConfig *conf = pool_calloc(pool, sizeof(HTTPObjectConfig), 1); 661 HTTPObjectConfig *conf = pool_calloc(pool, sizeof(HTTPObjectConfig), 1);
662 conf->pool = pool; 662 conf->pool = pool;
663 663
664 /* convert ObjectConfig to HTTPObjectConfig */ 664 // convert ObjectConfig to HTTPObjectConfig
665 665
666 /* add objects */ 666 // add objects
667 conf->nobj = ucx_dlist_size(cfg->objects); 667 conf->nobj = ucx_dlist_size(cfg->objects);
668 conf->objects = pool_calloc(pool, 1, sizeof(httpd_object*)); 668 conf->objects = pool_calloc(pool, 1, sizeof(httpd_object*));
669 669
670 UcxDlist *objlist = cfg->objects; 670 UcxDlist *objlist = cfg->objects;
671 int i = 0; 671 int i = 0;
672 while(objlist != NULL) { 672 while(objlist != NULL) {
673 ConfigObject *cob = objlist->data; 673 ConfigObject *cob = objlist->data;
674 674
675 /* get name and ppath */ 675 // get name and ppath
676 char *name = NULL; 676 char *name = NULL;
677 char *ppath = NULL; 677 char *ppath = NULL;
678 if(cob->name.length > 0) { 678 if(cob->name.length > 0) {
679 name = sstrdup_pool(pool, cob->name).ptr; 679 name = sstrdup_pool(pool, cob->name).ptr;
680 } 680 }
681 if(cob->ppath.length > 0) { 681 if(cob->ppath.length > 0) {
682 ppath = sstrdup_pool(pool, cob->ppath).ptr; 682 ppath = sstrdup_pool(pool, cob->ppath).ptr;
683 } 683 }
684 684
685 /* create and add object */ 685 // create and add object
686 httpd_object *obj = object_new(pool, name); 686 httpd_object *obj = object_new(pool, name);
687 obj->path = NULL; 687 obj->path = NULL;
688 688
689 conf->objects[i] = obj; // TODO: beyond array bounds write 689 conf->objects[i] = obj; // TODO: beyond array bounds write
690 690
691 /* add directives */ 691 // add directives
692 for(int i=0;i<6;i++) { 692 for(int i=0;i<6;i++) {
693 UcxDlist *dirs = cob->directives[i]; 693 UcxDlist *dirs = cob->directives[i];
694 while(dirs != NULL) { 694 while(dirs != NULL) {
695 ConfigDirective *cfgdir = dirs->data; 695 ConfigDirective *cfgdir = dirs->data;
696 696
697 directive *d = pool_malloc(pool, sizeof(directive)); 697 directive *d = pool_malloc(pool, sizeof(directive));
698 d->cond = NULL; 698 d->cond = NULL;
699 d->param = pblock_create_pool(pool, 8); 699 d->param = pblock_create_pool(pool, 8);
700 700
701 /* add params */ 701 // add params
702 UcxList *param = cfg_param_list(cfgdir->value, mp); 702 UcxList *param = cfg_param_list(cfgdir->value, mp);
703 while(param != NULL) { 703 while(param != NULL) {
704 ConfigParam *p = param->data; 704 ConfigParam *p = param->data;
705 pblock_nvlinsert( 705 pblock_nvlinsert(
706 p->name.ptr, 706 p->name.ptr,
709 p->value.length, 709 p->value.length,
710 d->param); 710 d->param);
711 param = param->next; 711 param = param->next;
712 } 712 }
713 713
714 /* get function */ 714 // get function
715 char *func_name = pblock_findval("fn", d->param); 715 char *func_name = pblock_findval("fn", d->param);
716 d->func = get_function(func_name); 716 d->func = get_function(func_name);
717 717
718 dirs = dirs->next; 718 dirs = dirs->next;
719 719
720 /* add function to dtable */ 720 // add function to dtable
721 object_add_directive(obj, d, cfgdir->type_num); 721 object_add_directive(obj, d, cfgdir->type_num);
722 } 722 }
723 } 723 }
724 724
725 /* next */ 725 // next
726 i++; 726 i++;
727 objlist = objlist->next; 727 objlist = objlist->next;
728 } 728 }
729 729
730 free_object_config(cfg); 730 free_object_config(cfg);

mercurial