[librest/wip/teuf/fixes: 2/10] RestProxyCall: Make sure _sync reliably sets error_out



commit d6bd5d7b4c4b71e8c256729ae1954e3f27855a00
Author: Timm Bäder <mail baedert org>
Date:   Mon Jul 18 10:33:23 2016 +0200

    RestProxyCall: Make sure _sync reliably sets error_out
    
    Currently rest_proxy_call_sync (and everything else using
    prepare_message) might return FALSE without setting @error at all. Add
    two new error codes to indicate the possible problems and reliably
    set the error if something went wrong.

 rest/rest-proxy-call.c |   22 ++++++++++++++++++++--
 rest/rest-proxy.h      |    4 ++++
 2 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/rest/rest-proxy-call.c b/rest/rest-proxy-call.c
index 2cd867a..9384b5b 100644
--- a/rest/rest-proxy-call.c
+++ b/rest/rest-proxy-call.c
@@ -753,6 +753,10 @@ prepare_message (RestProxyCall *call, GError **error_out)
     {
         g_free (content);
         g_free (content_type);
+        g_set_error_literal (error_out,
+                             REST_PROXY_ERROR,
+                             REST_PROXY_ERROR_BINDING_REQUIRED,
+                             "URL is unbound");
         return NULL;
     }
 
@@ -775,6 +779,10 @@ prepare_message (RestProxyCall *call, GError **error_out)
 
     if (!set_url (call))
     {
+        g_set_error_literal (error_out,
+                             REST_PROXY_ERROR,
+                             REST_PROXY_ERROR_BINDING_REQUIRED,
+                             "URL is unbound");
         return NULL;
     }
 
@@ -786,8 +794,14 @@ prepare_message (RestProxyCall *call, GError **error_out)
 
     g_hash_table_unref (hash);
 
-    if (!message)
-      return NULL;
+    if (!message) {
+        g_set_error (error_out,
+                     REST_PROXY_ERROR,
+                     REST_PROXY_ERROR_URL_INVALID,
+                     "URL '%s' is not valid",
+                     priv->url);
+        return NULL;
+    }
 
   } else {
     SoupMultipart *mp;
@@ -822,6 +836,10 @@ prepare_message (RestProxyCall *call, GError **error_out)
     if (!set_url (call))
     {
         soup_multipart_free (mp);
+        g_set_error_literal (error_out,
+                             REST_PROXY_ERROR,
+                             REST_PROXY_ERROR_BINDING_REQUIRED,
+                             "URL is unbound");
         return NULL;
     }
 
diff --git a/rest/rest-proxy.h b/rest/rest-proxy.h
index d341403..d882dea 100644
--- a/rest/rest-proxy.h
+++ b/rest/rest-proxy.h
@@ -97,6 +97,8 @@ struct _RestProxyClass {
  * @REST_PROXY_ERROR_SSL: SSL
  * @REST_PROXY_ERROR_IO: Input/Output
  * @REST_PROXY_ERROR_FAILED: Failure
+ * @REST_PROXY_ERROR_URL_INVALID: Invalid URL
+ * @REST_PROXY_ERROR_BINDING_REQUIRED: URL requires binding
  * @REST_PROXY_ERROR_HTTP_MULTIPLE_CHOICES: HTTP/Multiple choices
  * @REST_PROXY_ERROR_HTTP_MOVED_PERMANENTLY: HTTP/Moved permanently
  * @REST_PROXY_ERROR_HTTP_FOUND: HTTP/Found
@@ -139,6 +141,8 @@ typedef enum {
   REST_PROXY_ERROR_SSL,
   REST_PROXY_ERROR_IO,
   REST_PROXY_ERROR_FAILED,
+  REST_PROXY_ERROR_URL_INVALID,
+  REST_PROXY_ERROR_BINDING_REQUIRED,
 
   REST_PROXY_ERROR_HTTP_MULTIPLE_CHOICES                = 300,
   REST_PROXY_ERROR_HTTP_MOVED_PERMANENTLY               = 301,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]