[grilo] net: Make GRL_NET_MOCKED more intuitive



commit 1ff3504eff00b9654386a5448a80ffaae5d333fd
Author: Mathias Hasselmann <mathias openismus com>
Date:   Thu Oct 11 20:43:33 2012 +0200

    net: Make GRL_NET_MOCKED more intuitive

 libs/net/grl-net-mock.c |   12 ++++++++++++
 libs/net/grl-net-mock.h |    4 +---
 libs/net/grl-net-wc.c   |    8 ++++----
 3 files changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/libs/net/grl-net-mock.c b/libs/net/grl-net-mock.c
index c752e9c..6b8f57c 100644
--- a/libs/net/grl-net-mock.c
+++ b/libs/net/grl-net-mock.c
@@ -79,6 +79,18 @@ static GKeyFile *config = NULL;
 static GRegex *ignored_parameters = NULL;
 static char *base_path = NULL;
 
+gboolean
+is_mocked (void)
+{
+  const char *const env = g_getenv ("GRL_NET_MOCKED");
+
+  return env
+          && strcmp(env, "0")
+          && g_ascii_strcasecmp(env, "no")
+          && g_ascii_strcasecmp(env, "off")
+          && g_ascii_strcasecmp(env, "false");
+}
+
 void
 get_url_mocked (GrlNetWc *self,
                 const char *url,
diff --git a/libs/net/grl-net-mock.h b/libs/net/grl-net-mock.h
index 3b57fc6..da18b38 100644
--- a/libs/net/grl-net-mock.h
+++ b/libs/net/grl-net-mock.h
@@ -25,9 +25,7 @@
 
 #include "grl-net-wc.h"
 
-#define GRL_ENV_NET_MOCKED "GRL_NET_MOCKED"
-
-#define GRL_NET_IS_MOCKED (g_getenv (GRL_ENV_NET_MOCKED))
+gboolean is_mocked (void);
 
 void get_url_mocked (GrlNetWc *self,
                      const char *url,
diff --git a/libs/net/grl-net-wc.c b/libs/net/grl-net-wc.c
index 51170fe..36e681b 100644
--- a/libs/net/grl-net-wc.c
+++ b/libs/net/grl-net-wc.c
@@ -297,7 +297,7 @@ get_url_delayed (gpointer user_data)
     g_assert (c == d);
   }
 
-  if (GRL_NET_IS_MOCKED)
+  if (is_mocked ())
     get_url_mocked (c->self, c->url, c->headers, c->result, c->cancellable);
   else
     get_url_now (c->self, c->url, c->headers, c->result, c->cancellable);
@@ -326,7 +326,7 @@ get_url (GrlNetWc *self,
   g_get_current_time (&now);
 
   if ((now.tv_sec - priv->last_request.tv_sec) > priv->throttling) {
-    if (GRL_NET_IS_MOCKED)
+    if (is_mocked ())
       get_url_mocked (self, url, headers, result, cancellable);
     else
       get_url_now (self, url, headers, result, cancellable);
@@ -524,13 +524,13 @@ grl_net_wc_request_finish (GrlNetWc *self,
     goto end_func;
   }
 
-  if (GRL_NET_IS_MOCKED)
+  if (is_mocked ())
     get_content_mocked (self, op, content, length);
   else
     get_content(self, op, content, length);
 
 end_func:
-  if (GRL_NET_IS_MOCKED)
+  if (is_mocked ())
     free_mock_op_res (op);
   else
     free_op_res (op);



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