Author: jtn
Date: Wed Mar 16 01:47:54 2016
New Revision: 32254

URL: http://svn.gna.org/viewcvs/freeciv?rev=32254&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:
    branches/S2_5/utility/netfile.c

Modified: branches/S2_5/utility/netfile.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/utility/netfile.c?rev=32254&r1=32253&r2=32254&view=diff
==============================================================================
--- branches/S2_5/utility/netfile.c     (original)
+++ branches/S2_5/utility/netfile.c     Wed Mar 16 01:47:54 2016
@@ -62,6 +62,8 @@
   CURLcode curlret;
   struct curl_slist *headers = NULL;
   static CURL *handle;
+  char errorbuf[CURL_ERROR_SIZE] = "";
+  bool ret = TRUE;
 
   handle = netfile_init_handle();
 
@@ -70,6 +72,8 @@
   curl_easy_setopt(handle, CURLOPT_URL, URL);
   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);
 
@@ -77,17 +81,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