[grilo/mocking] net: Parse GRL_NET_MOCKED only once upon initialization



commit 0da1c1a88d47ecf7f3ca3fe989caef1ee836cf07
Author: Mathias Hasselmann <mathias openismus com>
Date:   Thu Oct 18 22:53:11 2012 +0200

    net: Parse GRL_NET_MOCKED only once upon initialization

 libs/net/grl-net-mock.c |   22 ++++++++++++++--------
 libs/net/grl-net-mock.h |    2 ++
 2 files changed, 16 insertions(+), 8 deletions(-)
---
diff --git a/libs/net/grl-net-mock.c b/libs/net/grl-net-mock.c
index c847e1d..a1007af 100644
--- a/libs/net/grl-net-mock.c
+++ b/libs/net/grl-net-mock.c
@@ -39,17 +39,12 @@
 static GKeyFile *config = NULL;
 static GRegex *ignored_parameters = NULL;
 static char *base_path = NULL;
+static gboolean enable_mocking = FALSE;
 
 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");
+  return enable_mocking;
 }
 
 gboolean
@@ -57,7 +52,7 @@ is_unthrottled (void)
 {
   /* Reusing the GRL_NET_MOCKED variable to ensure that throttling
    * only can be disabled in mocked sessions. */
-  const char *const env = g_getenv ("GRL_NET_MOCKED");
+  const char *const env = g_getenv (GRL_NET_MOCKED_VAR);
   return env && g_ascii_strcasecmp(env, "unthrottled") == 0;
 }
 
@@ -174,6 +169,17 @@ void init_mock_requester (GrlNetWc *self)
 
   config = g_key_file_new ();
 
+  env = g_getenv (GRL_NET_MOCKED_VAR);
+
+  enable_mocking = env
+          && strcmp(env, "0")
+          && g_ascii_strcasecmp(env, "no")
+          && g_ascii_strcasecmp(env, "off")
+          && g_ascii_strcasecmp(env, "false");
+
+  if (!enable_mocking)
+      return;
+
   env = g_getenv ("GRL_REQUEST_MOCK_FILE");
   if (env) {
     GRL_DEBUG ("Trying to load mock file %s", env);
diff --git a/libs/net/grl-net-mock.h b/libs/net/grl-net-mock.h
index c2935a9..cead55d 100644
--- a/libs/net/grl-net-mock.h
+++ b/libs/net/grl-net-mock.h
@@ -25,6 +25,8 @@
 
 #include "grl-net-wc.h"
 
+#define GRL_NET_MOCKED_VAR "GRL_NET_MOCKED"
+
 G_GNUC_INTERNAL
 gboolean is_mocked (void);
 



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