dav/config.c

changeset 119
451607eeff05
parent 75
56962faf2b42
child 142
0c0ccb7f71ba
--- a/dav/config.c	Thu May 28 14:34:46 2015 +0200
+++ b/dav/config.c	Fri May 29 09:48:10 2015 +0200
@@ -136,82 +136,30 @@
     ucx_map_free(keys);
 }
 
-void load_repository(xmlNode *reponode) {
-    xmlNode *node = reponode->children;
+Repository* repository_new() {
     Repository *repo = calloc(1, sizeof(Repository));
     repo->encrypt_name = false;
     repo->encrypt_content = false;
     repo->decrypt_name = false;
     repo->decrypt_content = true;
     repo->ssl_version = CURL_SSLVERSION_DEFAULT;
+    return repo;
+}
+
+void load_repository(xmlNode *reponode) {
+    xmlNode *node = reponode->children;
+    Repository *repo = repository_new();
     while(node) {
         if(node->type == XML_ELEMENT_NODE) {
+            char *name = (char*)node->name;
             char *value = util_xml_get_text(node);
-            if(!value) {
-                // next
-            } else if(xstreq(node->name, "name")) {
-                repo->name = strdup(value);
-            } else if(xstreq(node->name, "url")) {
-                repo->url = strdup(value);
-            } else if(xstreq(node->name, "user")) {
-                repo->user = strdup(value);
-            } else if(xstreq(node->name, "password")) {
-                repo->password = util_base64decode(value);
-            } else if(xstreq(node->name, "default-key")) {
-                repo->default_key = strdup(value);
-            } else if(xstreq(node->name, "full-encryption")) {
-                if(util_getboolean(value)) {
-                    repo->encrypt_name = true;
-                    repo->encrypt_content = true;
-                    repo->decrypt_name = true;
-                    repo->decrypt_content = true;
-                }
-            } else if(xstreq(node->name, "content-encryption")) {
-                if(util_getboolean(value)) {
-                    repo->encrypt_content = true;
-                    repo->decrypt_content = true;
-                } else {
-                    repo->encrypt_content = false;
+            if(value) {
+                if(repo_add_config(repo, name, value)) {
+                    fprintf(
+                            stderr,
+                            "Unkown repository config element: %s\n",
+                            name);
                 }
-            } else if(xstreq(node->name, "decrypt-content")) {
-                repo->decrypt_content = util_getboolean(value);
-            } else if(xstreq(node->name, "decrypt-name")) {
-                repo->decrypt_name = util_getboolean(value);
-            } else if(xstreq(node->name, "ssl-version")) {
-                if(xstrEQ(value, "TLSv1")) {
-                    repo->ssl_version = CURL_SSLVERSION_TLSv1;
-                } else if(xstrEQ(value, "SSLv2")) {
-                    repo->ssl_version = CURL_SSLVERSION_SSLv2;
-                } else if(xstrEQ(value, "SSLv3")) {
-                    repo->ssl_version = CURL_SSLVERSION_SSLv3;
-                }
-#if LIBCURL_VERSION_MAJOR >= 7
-#if LIBCURL_VERSION_MINOR >= 34
-                else if(xstrEQ(value, "TLSv1.0")) {
-                    repo->ssl_version = CURL_SSLVERSION_TLSv1_0;
-                } else if(xstrEQ(value, "TLSv1.1")) {
-                    repo->ssl_version = CURL_SSLVERSION_TLSv1_1;
-                } else if(xstrEQ(value, "TLSv1.2")) {
-                    repo->ssl_version = CURL_SSLVERSION_TLSv1_2;
-                }
-#endif
-#endif
-                else {
-                    fprintf(stderr, "Unknown ssl version: %s\n", value);
-                }
-            } else if(xstreq(node->name, "encrypt") || xstreq(node->name, "store-key-property") || xstreq(node->name, "decrypt")) {
-                fprintf(stderr, "Error: config.xml contains deprecated elements\n");
-                fprintf(stderr, "The elements <encrypt>, <decrypt> and <store-key-property> are removed\n");
-                fprintf(stderr, "Use the following: \n\n");
-                fprintf(stderr, "<content-encryption>true</content-encryption>\n");
-                fprintf(stderr, "enables file content encryption and decryption\n\n");
-                fprintf(stderr, "<full-encryption>true</full-encryption>\n");
-                fprintf(stderr, "enables content and file name encryption/decryption\n\n");
-                fprintf(stderr, "<decrypt-content>$BOOL</decrypt-content>\n");
-                fprintf(stderr, "only enables/disables content decryption\n\n");
-                fprintf(stderr, "<decrypt-name>$BOOL</decrypt-name>\n");
-                fprintf(stderr, "only enables/disables name decryption\n\n");
-                exit(-1);
             }
         }
         node = node->next;
@@ -236,6 +184,63 @@
     ucx_map_cstr_put(repos, repo->name, repo);
 }
 
+int repo_add_config(Repository *repo, char *key, char *value) {
+    if(xstreq(key, "name")) {
+        repo->name = strdup(value);
+    } else if(xstreq(key, "url")) {
+        repo->url = strdup(value);
+    } else if(xstreq(key, "user")) {
+        repo->user = strdup(value);
+    } else if(xstreq(key, "password")) {
+        repo->password = util_base64decode(value);
+    } else if(xstreq(key, "default-key")) {
+        repo->default_key = strdup(value);
+    } else if(xstreq(key, "full-encryption")) {
+        if(util_getboolean(value)) {
+            repo->encrypt_name = true;
+            repo->encrypt_content = true;
+            repo->decrypt_name = true;
+            repo->decrypt_content = true;
+        }
+    } else if(xstreq(key, "content-encryption")) {
+        if(util_getboolean(value)) {
+            repo->encrypt_content = true;
+            repo->decrypt_content = true;
+        } else {
+            repo->encrypt_content = false;
+        }
+    } else if(xstreq(key, "decrypt-content")) {
+        repo->decrypt_content = util_getboolean(value);
+    } else if(xstreq(key, "decrypt-name")) {
+        repo->decrypt_name = util_getboolean(value);
+    } else if(xstreq(key, "ssl-version")) {
+        if(xstrEQ(value, "TLSv1")) {
+            repo->ssl_version = CURL_SSLVERSION_TLSv1;
+        } else if(xstrEQ(value, "SSLv2")) {
+            repo->ssl_version = CURL_SSLVERSION_SSLv2;
+        } else if(xstrEQ(value, "SSLv3")) {
+            repo->ssl_version = CURL_SSLVERSION_SSLv3;
+        }
+#if LIBCURL_VERSION_MAJOR >= 7
+#if LIBCURL_VERSION_MINOR >= 34
+        else if(xstrEQ(value, "TLSv1.0")) {
+            repo->ssl_version = CURL_SSLVERSION_TLSv1_0;
+        } else if(xstrEQ(value, "TLSv1.1")) {
+            repo->ssl_version = CURL_SSLVERSION_TLSv1_1;
+        } else if(xstrEQ(value, "TLSv1.2")) {
+            repo->ssl_version = CURL_SSLVERSION_TLSv1_2;
+        }
+#endif
+#endif
+        else {
+            fprintf(stderr, "Unknown ssl version: %s\n", value);
+        }
+    } else {
+        return -1;
+    }
+    return 0;
+}
+
 void load_proxy(xmlNode *proxynode, int type) {
     Proxy *proxy;
     const char *stype;
@@ -393,3 +398,4 @@
 Proxy* get_https_proxy() {
     return https_proxy;
 }
+

mercurial