libidav/methods.c

changeset 171
254326cbc1bc
parent 170
cf054cded046
child 172
cd9f1e772fd0
--- a/libidav/methods.c	Thu Oct 15 15:36:26 2015 +0200
+++ b/libidav/methods.c	Thu Oct 15 16:16:44 2015 +0200
@@ -48,15 +48,11 @@
 {
     curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
     
-    // implement own redirection follower
-    long follow = 0;
-    curl_easy_getinfo(handle, CURLOPT_FOLLOWLOCATION, &follow);
-    curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 0L);
-    const int maxredirect = 16;
-    
     // always try to get information about possible children
     int depth = 1;
     
+    int maxretry = 2;
+    
     struct curl_slist *headers = NULL;
     CURLcode ret = 0;
     
@@ -70,22 +66,13 @@
     UcxMap *respheaders = ucx_map_new(32);
     util_capture_header(handle, respheaders);
     
-    for(int i=0;i<=maxredirect;i++) {
-        char *url = NULL;
-        curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
-        if(url) {
-            size_t ulen = strlen(url);
-            if(ulen > 0) {
-                if (depth == 1) {
-                    headers = curl_slist_append(headers, "Depth: 1");
-                } else {
-                    headers = curl_slist_append(headers, "Depth: 0");
-                }
-            } else {
-                return CURLE_URL_MALFORMAT;
-            }
+    for(int i=0;i<maxretry;i++) {
+        if (depth == 1) {
+            headers = curl_slist_append(headers, "Depth: 1");
+        } else if (depth == -1) {
+            headers = curl_slist_append(headers, "Depth: infinity");
         } else {
-            return CURLE_URL_MALFORMAT;
+            headers = curl_slist_append(headers, "Depth: 0");
         }
         headers = curl_slist_append(headers, "Content-Type: text/xml");
         curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
@@ -98,25 +85,18 @@
         headers = NULL;
         
         /*
-         * Handle three cases:
-         * 1. We get a Location header (it's a redirect)
-         *    => follow the URL we get from the server
-         * 2. We communicate with IIS and get a X-MSDAVEXT_Error: 589831
+         * Handle two cases:
+         * 1. We communicate with IIS and get a X-MSDAVEXT_Error: 589831
          *    => try with depth 0 next time, it's not a collection
-         * 3. Other cases
+         * 2. Other cases
          *    => the server handled our request and we can stop requesting
          */
-        char *location = NULL;
         char *msdavexterror;
-        curl_easy_getinfo(handle, CURLINFO_REDIRECT_URL, &location);
         msdavexterror = ucx_map_cstr_get(respheaders, "x-msdavext_error");
         int iishack =  depth == 1 &&
             msdavexterror && !strncmp(msdavexterror, "589831;", 7);
         
-        if(location) {
-            // redirect
-            curl_easy_setopt(handle, CURLOPT_URL, location);
-        } else if(iishack) {
+        if(iishack) {
             depth = 0;
         } else {
             break;
@@ -126,9 +106,6 @@
     ucx_map_free_content(respheaders, free);
     ucx_map_free(respheaders);
     
-    // reset followlocation option
-    curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, follow);
-    
     return ret;
 }
 

mercurial