fixed put bugs

Mon, 19 Aug 2013 12:50:42 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 19 Aug 2013 12:50:42 +0200
changeset 21
78935b45e2ce
parent 20
6bb9479d9c64
child 22
e593f7e41be0

fixed put bugs

dav/Makefile file | annotate | diff | comparison | revisions
dav/config.c file | annotate | diff | comparison | revisions
dav/main.c file | annotate | diff | comparison | revisions
dav/webdav.c file | annotate | diff | comparison | revisions
dav/webdav.h file | annotate | diff | comparison | revisions
--- a/dav/Makefile	Sat Aug 17 14:57:17 2013 +0200
+++ b/dav/Makefile	Mon Aug 19 12:50:42 2013 +0200
@@ -28,9 +28,6 @@
 
 include ../$(CONF).mk
 
-DAV_CFLAGS = `curl-config --cflags` `pkg-config --cflags openssl libxml-2.0`
-DAV_LDFLAGS = `curl-config --libs` `pkg-config --libs openssl libxml-2.0` 
-
 SRC  = main.c
 SRC += utils.c
 SRC += webdav.c
--- a/dav/config.c	Sat Aug 17 14:57:17 2013 +0200
+++ b/dav/config.c	Mon Aug 19 12:50:42 2013 +0200
@@ -122,11 +122,23 @@
         node = node->next;
     }
     
-    if(repo->name) {
-        ucx_map_cstr_put(repos, repo->name, repo);
-    } else {
-        // TODO: free
+    if(!repo->name) {
+        fprintf(
+                stderr,
+                "Cannot load config.xml: missing name for repository.\n");
+        fprintf(stderr, "Abort.\n");
+        exit(-1);
     }
+    if(!repo->url) {
+        fprintf(
+                stderr,
+                "Cannot load config.xml: "
+                "missing url for repository '%s'.\n", repo->name);
+        fprintf(stderr, "Abort.\n");
+        exit(-1);
+    }
+    
+    ucx_map_cstr_put(repos, repo->name, repo);
 }
 
 void load_key(xmlNode *keynode) {
--- a/dav/main.c	Sat Aug 17 14:57:17 2013 +0200
+++ b/dav/main.c	Mon Aug 19 12:50:42 2013 +0200
@@ -590,10 +590,20 @@
         return -1;
     }
     
-    DavResource *res = dav_resource_new(sn, path);
+    DavResource *res = dav_query(sn, "get - from %s", path);
     if(!res) {
-        fprintf(stderr, "error\n");
-        return -1;
+        if(sn->error = DAV_NOT_FOUND) {
+            res = dav_resource_new(sn, path);
+        } else {
+            fprintf(stderr, "error\n");
+            return -1;
+        }
+    } else if(res->iscollection) {
+        // TODO: free res
+        char *newpath = util_concat_path(path, file);
+        free(path);
+        path = newpath;
+        res = dav_resource_new(sn, path);
     }
     
     AESEncrypter *enc = NULL;
@@ -602,14 +612,16 @@
     char *plain = cmd_getoption(a, "plain");
     if(!plain && (keyname || repo)) {
         kn = keyname ? keyname : repo->default_key;
-        Key *key = get_key(kn);
-        if(!key) {
-            fprintf(stderr, "Key %s not found!\nAbort.\n", kn);
-            // TODO: free
-            return -1;
-        }
-        if(keyname || repo->encrypt) {
-            enc = aes_encrypter_new(key, in, (dav_read_func)fread);
+        if(kn) {
+            Key *key = get_key(kn);
+            if(!key) {
+                fprintf(stderr, "Key %s not found!\nAbort.\n", kn);
+                // TODO: free
+                return -1;
+            }
+            if(keyname || repo->encrypt) {
+                enc = aes_encrypter_new(key, in, (dav_read_func)fread);
+            }
         }
     }
     if(enc) {
--- a/dav/webdav.c	Sat Aug 17 14:57:17 2013 +0200
+++ b/dav/webdav.c	Mon Aug 19 12:50:42 2013 +0200
@@ -47,6 +47,9 @@
     }
     context->sessions = NULL;
     context->namespaces = ucx_map_new(16);
+    context->http_proxy = NULL;
+    context->https_proxy = NULL;
+    context->no_proxy = NULL;
     if(!context->namespaces) {
         free(context);
         return NULL;
@@ -121,6 +124,24 @@
     }
     sn->context = context;
     sn->handle = curl_easy_init();
+    
+    // set proxy
+    if(sstrprefix(url, S("https"))) {
+        if(context->https_proxy) {
+            //printf("use https_proxy: %s\n", context->https_proxy);
+            curl_easy_setopt(sn->handle, CURLOPT_PROXY, context->https_proxy);
+        }
+    } else {
+        if(context->http_proxy) {
+            //printf("use http_proxy: %s\n", context->http_proxy);
+            curl_easy_setopt(sn->handle, CURLOPT_PROXY, context->http_proxy);
+        }
+    }
+    if(context->no_proxy) {
+        //printf("use no_proxy: %s\n", context->no_proxy);
+        curl_easy_setopt(sn->handle, CURLOPT_NOPROXY, context->no_proxy);
+    }
+    // set url
     curl_easy_setopt(sn->handle, CURLOPT_URL, base_url);
     
     sn->mp = ucx_mempool_new(1024);
--- a/dav/webdav.h	Sat Aug 17 14:57:17 2013 +0200
+++ b/dav/webdav.h	Mon Aug 19 12:50:42 2013 +0200
@@ -99,6 +99,9 @@
 struct DavContext {
     UcxMap  *namespaces;
     UcxList *sessions;
+    char    *http_proxy;
+    char    *https_proxy;
+    char    *no_proxy;
 };
 
 struct dav_content_data {

mercurial