libidav/config.c

changeset 796
81e0f67386a6
parent 795
05647e862a17
child 803
008cc66ff9d6
equal deleted inserted replaced
795:05647e862a17 796:81e0f67386a6
156 *error = ret; 156 *error = ret;
157 cxMempoolDestroy(cfg_mp); 157 cxMempoolDestroy(cfg_mp);
158 } 158 }
159 159
160 return config; 160 return config;
161 }
162
163 void dav_config_free(DavConfig *config) {
164 cxMempoolDestroy(config->mp);
161 } 165 }
162 166
163 CxBuffer* dav_config2buf(DavConfig *config) { 167 CxBuffer* dav_config2buf(DavConfig *config) {
164 xmlChar* xmlText = NULL; 168 xmlChar* xmlText = NULL;
165 int textLen = 0; 169 int textLen = 0;
776 } 780 }
777 } 781 }
778 782
779 return repo; 783 return repo;
780 } 784 }
785
786 int dav_config_keytype(DavCfgKeyType type) {
787 switch(type) {
788 default: break;
789 case DAV_KEY_TYPE_AES256: return DAV_KEY_AES256;
790 case DAV_KEY_TYPE_AES128: return DAV_KEY_AES128;
791 }
792 return 0;
793 }
794
795 int dav_config_register_keys(DavConfig *config, DavContext *ctx, dav_loadkeyfile_func loadkey) {
796 for(DavCfgKey *key=config->keys;key;key=key->next) {
797 char *file = cx_strdup_m(key->file.value).ptr;
798 cxmutstr keycontent = loadkey(file);
799 free(file);
800
801 // TODO: check key length
802
803 if(!keycontent.ptr) {
804 return 1;
805 }
806
807 DavKey *davkey = calloc(1, sizeof(DavKey));
808 davkey->name = cx_strdup_m(key->name.value).ptr;
809 davkey->type = dav_config_keytype(key->type);
810 davkey->data = keycontent.ptr;
811 davkey->length = keycontent.length;
812
813 dav_context_add_key(ctx, davkey);
814 }
815 return 0;
816 }

mercurial