src/server/daemon/config.c

branch
webdav
changeset 366
47bc686fafe4
parent 339
f4a34b0869c7
child 367
1592224f6059
equal deleted inserted replaced
361:570026d3a685 366:47bc686fafe4
274 ConfigNode *scfgobj = elm->data; 274 ConfigNode *scfgobj = elm->data;
275 if(cfg_handle_resourcepool(serverconfig, scfgobj)) { 275 if(cfg_handle_resourcepool(serverconfig, scfgobj)) {
276 return NULL; 276 return NULL;
277 } 277 }
278 } 278 }
279
280 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("Dav"));
281 UCX_FOREACH(elm, list) {
282 ConfigNode *scfgobj = elm->data;
283 if(cfg_handle_dav(serverconfig, scfgobj)) {
284 return NULL;
285 }
286 }
279 287
280 // set VirtualServer for all listeners 288 // set VirtualServer for all listeners
281 UcxList *ls = serverconfig->listeners; 289 UcxList *ls = serverconfig->listeners;
282 while(ls) { 290 while(ls) {
283 HttpListener *listener = ls->data; 291 HttpListener *listener = ls->data;
666 ucx_map_sstr_put(cfg->host_vs, vs->host, vs); 674 ucx_map_sstr_put(cfg->host_vs, vs->host, vs);
667 675
668 return 0; 676 return 0;
669 } 677 }
670 678
679 int cfg_handle_dav(ServerConfiguration *cfg, ConfigNode *obj) {
680 UcxList *backends = NULL; // list of ConfigArg*
681 UcxAllocator a = util_pool_allocator(cfg->pool);
682 int init_error;
683
684 // get a list of all DavBackends
685 UCX_FOREACH(elm, obj->children) {
686 ConfigNode *node = elm->data;
687 if(!sstrcasecmp(node->name, SC("DavBackend"))) {
688 if(node->type == CONFIG_NODE_DIRECTIVE) {
689 if(ucx_list_size(node->args) == 1) {
690 ConfigArg *arg = node->args->data;
691 backends = ucx_list_append(backends, arg);
692 } else {
693 log_ereport(LOG_MISCONFIG, "DavBackend must have only one value");
694 ucx_list_free(backends);
695 return 1;
696 }
697 } else {
698 log_ereport(LOG_MISCONFIG, "DavBackend must be a directive");
699 ucx_list_free(backends);
700 return 1;
701 }
702 }
703 }
704
705 int ret = 0;
706 WebdavRepository *repository = pool_malloc(cfg->pool, sizeof(WebdavRepository));
707 repository->vfs = NULL;
708 repository->vfsInitData = NULL;
709 repository->davBackends = NULL;
710
711 // initialize backends
712 UCX_FOREACH(elm, backends) {
713 // the DavBackend value should contain the dav class name
714 ConfigArg *backendArg = elm->data;
715
716 WebdavType *dav = webdav_get_type((scstr_t){backendArg->value.ptr, backendArg->value.length});
717 if(!dav) {
718 log_ereport(LOG_MISCONFIG, "Unknown webdav backend type '%s'", backendArg->value.ptr);
719 ret = 1;
720 break;
721 }
722
723 // call backend init
724 // init_data can be NULL, errors will be indicated by init_error
725 void *init_data = webdav_init_backend(cfg, cfg->pool, dav, obj, &init_error);
726 if(init_error) {
727 log_ereport(LOG_FAILURE, "Failed to initialize webdav backend %s", backendArg->value.ptr);
728 ret = 1;
729 break;
730 }
731
732 WebdavBackendInitData *davInit = pool_malloc(cfg->pool, sizeof(WebdavBackendInitData));
733 if(!davInit) {
734 log_ereport(LOG_FAILURE, "Failed to initialize webdav backend %s: OOM", backendArg->value.ptr);
735 ret = 1;
736 break;
737 }
738 davInit->davType = dav;
739 davInit->davInitData = init_data;
740
741 repository->davBackends = ucx_list_append_a(&a, repository->davBackends, davInit);
742 }
743
744 // initialize vfs
745 scstr_t vfs_class = serverconfig_directive_value(obj, SC("VFS"));
746 if(vfs_class.length > 0) {
747 VfsType *vfs = vfs_get_type((scstr_t){vfs_class.ptr, vfs_class.length});
748 if(vfs) {
749 repository->vfs = vfs;
750 repository->vfsInitData = vfs_init_backend(cfg, cfg->pool, vfs, obj, &init_error);
751 ret = init_error;
752 } else {
753 log_ereport(LOG_FAILURE, "Unknown vfs type '%s'", vfs_class.ptr);
754 ret = 1;
755 }
756 }
757
758 scstr_t object = serverconfig_directive_value(obj, SC("Object"));
759 if(object.length > 0) {
760 repository->object = sstrdup_a(&a, object);
761 if(repository->object.length != object.length) {
762 // OOM
763 log_ereport(LOG_FAILURE, "Cannot create webdav repository: OOM");
764 ret = 1;
765 }
766 }
767
768 return ret;
769 }
671 770
672 static int convert_objconf(ServerConfiguration *scfg, ObjectConfig *cfg, HTTPObjectConfig *conf, sstr_t file) { 771 static int convert_objconf(ServerConfiguration *scfg, ObjectConfig *cfg, HTTPObjectConfig *conf, sstr_t file) {
673 pool_handle_t *pool = conf->pool; 772 pool_handle_t *pool = conf->pool;
674 773
675 UcxList *objlist = cfg->objects; 774 UcxList *objlist = cfg->objects;

mercurial