Author: jtn
Date: Wed Mar 16 01:37:03 2016
New Revision: 32250

URL: http://svn.gna.org/viewcvs/freeciv?rev=32250&view=rev
Log:
When downloading a file over HTTP (e.g. in the modpack installer),
treat HTTP 404 and the like as errors (using CURLOPT_FAILONERROR).
Also, report more of Curl's error text back to the caller.

See gna bug #24518.

Modified:
    trunk/utility/netfile.c

Modified: trunk/utility/netfile.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/netfile.c?rev=32250&r1=32249&r2=32250&view=diff
==============================================================================
--- trunk/utility/netfile.c     (original)
+++ trunk/utility/netfile.c     Wed Mar 16 01:37:03 2016
@@ -81,6 +81,8 @@
   CURLcode curlret;
   struct curl_slist *headers = NULL;
   static CURL *handle;
+  char errorbuf[CURL_ERROR_SIZE] = "";
+  bool ret = TRUE;
 
   handle = netfile_init_handle();
 
@@ -96,6 +98,8 @@
     curl_easy_setopt(handle, CURLOPT_WRITEDATA, fp);
   }
   curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
+  curl_easy_setopt(handle, CURLOPT_FAILONERROR, 1);
+  curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errorbuf);
 
   curlret = curl_easy_perform(handle);
 
@@ -103,17 +107,23 @@
 
   if (curlret != CURLE_OK) {
     if (cb != NULL) {
-      char buf[2048];
+      char buf[2048 + CURL_ERROR_SIZE];
 
       fc_snprintf(buf, sizeof(buf),
-                  _("Failed to fetch %s"), URL);
+                  /* TRANS: first %s is URL, second is Curl error message
+                   * (not in Freeciv translation domain) */
+                  _("Failed to fetch %s: %s"), URL,
+                  strlen(errorbuf) ? errorbuf : curl_easy_strerror(curlret));
       cb(buf, data);
     }
 
-    return FALSE;
-  }
-
-  return TRUE;
+    ret = FALSE;
+  }
+
+  /* Just in case next user of Curl handle doesn't reset it */
+  curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, NULL);
+
+  return ret;
 }
 
 /********************************************************************** 


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to