[Spice-commits] 3 commits - SpiceXPI/src

Marc-André Lureau elmarco at kemper.freedesktop.org
Tue Jan 29 05:38:24 PST 2013


 SpiceXPI/src/plugin/Makefile.am          |    2 
 SpiceXPI/src/plugin/glib-compat.c        |  188 +++++++++++++++++++++++++++++++
 SpiceXPI/src/plugin/glib-compat.h        |   49 ++++++++
 SpiceXPI/src/plugin/nsISpicec.idl        |    1 
 SpiceXPI/src/plugin/nsScriptablePeer.cpp |    9 +
 SpiceXPI/src/plugin/nsScriptablePeer.h   |    1 
 SpiceXPI/src/plugin/plugin.cpp           |   33 ++++-
 SpiceXPI/src/plugin/plugin.h             |    6 
 8 files changed, 280 insertions(+), 9 deletions(-)

New commits:
commit e518db3700ed23d3ccc7026b922b236158e501cc
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Mon Jan 28 19:02:17 2013 +0100

    xpi: add Proxy member
    
    Set SPICE_PROXY environment variable accordingly.

diff --git a/SpiceXPI/src/plugin/nsISpicec.idl b/SpiceXPI/src/plugin/nsISpicec.idl
index 001b387..ce4c677 100644
--- a/SpiceXPI/src/plugin/nsISpicec.idl
+++ b/SpiceXPI/src/plugin/nsISpicec.idl
@@ -65,6 +65,7 @@ interface nsISpicec : nsISupports {
     attribute string ColorDepth;
     attribute string DisableEffects;
     attribute string TrustStore;
+    attribute string Proxy;
 
     void connect();
     void show();
diff --git a/SpiceXPI/src/plugin/nsScriptablePeer.cpp b/SpiceXPI/src/plugin/nsScriptablePeer.cpp
index 622659c..249e7a3 100644
--- a/SpiceXPI/src/plugin/nsScriptablePeer.cpp
+++ b/SpiceXPI/src/plugin/nsScriptablePeer.cpp
@@ -88,6 +88,7 @@ NPIdentifier ScriptablePluginObject::m_id_set_language_strings;
 NPIdentifier ScriptablePluginObject::m_id_set_usb_filter;
 NPIdentifier ScriptablePluginObject::m_id_connect_status;
 NPIdentifier ScriptablePluginObject::m_id_plugin_instance;
+NPIdentifier ScriptablePluginObject::m_id_proxy;
 
 NPObject *AllocateScriptablePluginObject(NPP npp, NPClass *aClass)
 {
@@ -140,6 +141,7 @@ void ScriptablePluginObject::Init()
     m_id_set_usb_filter = NPN_GetStringIdentifier("SetUsbFilter");
     m_id_connect_status = NPN_GetStringIdentifier("ConnectedStatus");
     m_id_plugin_instance = NPN_GetStringIdentifier("PluginInstance");
+    m_id_proxy = NPN_GetStringIdentifier("Proxy");
     m_id_set = true;
 }
 
@@ -176,7 +178,8 @@ bool ScriptablePluginObject::HasProperty(NPIdentifier name)
            name == m_id_usb_listen_port ||
            name == m_id_usb_auto_share ||
            name == m_id_color_depth ||
-           name == m_id_disable_effects);
+           name == m_id_disable_effects ||
+           name == m_id_proxy);
 }
 
 bool ScriptablePluginObject::GetProperty(NPIdentifier name, NPVariant *result)
@@ -230,6 +233,8 @@ bool ScriptablePluginObject::GetProperty(NPIdentifier name, NPVariant *result)
         STRINGZ_TO_NPVARIANT(m_plugin->GetColorDepth(), *result);
     else if (name == m_id_disable_effects)
         STRINGZ_TO_NPVARIANT(m_plugin->GetDisableEffects(), *result);
+    else if (name == m_id_proxy)
+        STRINGZ_TO_NPVARIANT(m_plugin->GetProxy(), *result);
     else
         return false;
 
@@ -316,6 +321,8 @@ bool ScriptablePluginObject::SetProperty(NPIdentifier name, const NPVariant *val
         m_plugin->SetColorDepth(str.c_str());
     else if (name == m_id_disable_effects)
         m_plugin->SetDisableEffects(str.c_str());
+    else if (name == m_id_proxy)
+        m_plugin->SetProxy(str.c_str());
     else
         return false;
 
diff --git a/SpiceXPI/src/plugin/nsScriptablePeer.h b/SpiceXPI/src/plugin/nsScriptablePeer.h
index 44bd53c..7488726 100644
--- a/SpiceXPI/src/plugin/nsScriptablePeer.h
+++ b/SpiceXPI/src/plugin/nsScriptablePeer.h
@@ -105,6 +105,7 @@ private:
     static NPIdentifier m_id_set_usb_filter;
     static NPIdentifier m_id_connect_status;
     static NPIdentifier m_id_plugin_instance;
+    static NPIdentifier m_id_proxy;
 };
 
 #define DECLARE_NPOBJECT_CLASS_WITH_BASE(_class, ctor)                        \
diff --git a/SpiceXPI/src/plugin/plugin.cpp b/SpiceXPI/src/plugin/plugin.cpp
index 8233885..fa04726 100644
--- a/SpiceXPI/src/plugin/plugin.cpp
+++ b/SpiceXPI/src/plugin/plugin.cpp
@@ -249,6 +249,7 @@ NPBool nsPluginInstance::init(NPWindow *aWindow)
     m_trust_store_file.clear();
     m_color_depth.clear();
     m_disable_effects.clear();
+    m_proxy.clear();
 
     m_fullscreen = PR_FALSE;
     m_smartcard = PR_FALSE;
@@ -544,6 +545,17 @@ void nsPluginInstance::SetDisableEffects(const char *aDisableEffects)
     m_disable_effects = aDisableEffects;
 }
 
+/* attribute string Proxy; */
+char *nsPluginInstance::GetProxy() const
+{
+    return stringCopy(m_proxy);
+}
+
+void nsPluginInstance::SetProxy(const char *aProxy)
+{
+    m_proxy = aProxy;
+}
+
 void nsPluginInstance::WriteToPipe(const void *data, uint32_t size)
 {
     m_external_controller.Write(data, size);
@@ -633,6 +645,8 @@ void nsPluginInstance::Connect()
 
         gchar **env = g_get_environ();
         env = g_environ_setenv(env, "SPICE_XPI_SOCKET", socket_file.c_str(), TRUE);
+        if (!m_proxy.empty())
+            env = g_environ_setenv(env, "SPICE_PROXY", m_proxy.c_str(), TRUE);
 
         execle("/usr/libexec/spice-xpi-client",
                "/usr/libexec/spice-xpi-client", NULL,
diff --git a/SpiceXPI/src/plugin/plugin.h b/SpiceXPI/src/plugin/plugin.h
index 6305dcc..b30d946 100644
--- a/SpiceXPI/src/plugin/plugin.h
+++ b/SpiceXPI/src/plugin/plugin.h
@@ -169,6 +169,10 @@ public:
     char *GetDisableEffects() const;
     void SetDisableEffects(const char *aDisableEffects);
 
+     /* attribute ing Proxy; */
+    char *GetProxy() const;
+    void SetProxy(const char *aProxy);
+
     NPObject *GetScriptablePeer();
     
 private:
@@ -213,6 +217,7 @@ private:
     std::map<std::string, std::string> m_language;
     std::string m_color_depth;
     std::string m_disable_effects;
+    std::string m_proxy;
     
     NPObject *m_scriptable_peer;
     std::string m_tmp_dir;
commit 1f0edd021b56462d58f594f60c9031f61dc67f40
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Mon Jan 28 18:42:00 2013 +0100

    xpi: use safer g_environ_setenv()
    
    Quoting GLib:
    
    Environment variable handling in UNIX is not thread-safe, and your
    program may crash if one thread calls g_setenv() while another thread
    is calling getenv(). (And note that many functions, such as gettext(),
    call getenv() internally.) This function is only safe to use at the
    very start of your program, before creating any other threads (or
    creating objects that create worker threads of their own).
    
    If you need to set up the environment for a child process, you can use
    g_get_environ() to get an environment array, modify that with
    g_environ_setenv() and g_environ_unsetenv(), and then pass that array
    directly to execvpe(), g_spawn_async(), or the like.

diff --git a/SpiceXPI/src/plugin/plugin.cpp b/SpiceXPI/src/plugin/plugin.cpp
index cb4bc8e..8233885 100644
--- a/SpiceXPI/src/plugin/plugin.cpp
+++ b/SpiceXPI/src/plugin/plugin.cpp
@@ -608,11 +608,6 @@ void nsPluginInstance::Connect()
 
     std::string socket_file(m_tmp_dir);
     socket_file += "/spice-xpi";
-    if (setenv("SPICE_XPI_SOCKET", socket_file.c_str(), 1))
-    {
-        g_critical("could not set SPICE_XPI_SOCKET env variable");
-        return;
-    }
 
     /* use a pipe for the children to wait until it gets tracked */
     int pipe_fds[2] = { -1, -1 };
@@ -636,13 +631,21 @@ void nsPluginInstance::Connect()
         close(pipe_fds[0]);
         pipe_fds[0] = -1;
 
-        execl("/usr/libexec/spice-xpi-client", "/usr/libexec/spice-xpi-client", NULL);
+        gchar **env = g_get_environ();
+        env = g_environ_setenv(env, "SPICE_XPI_SOCKET", socket_file.c_str(), TRUE);
+
+        execle("/usr/libexec/spice-xpi-client",
+               "/usr/libexec/spice-xpi-client", NULL,
+               env);
         g_message("failed to run spice-xpi-client, running spicec instead");
 
         // TODO: temporary fallback for backward compatibility
-        execl("/usr/bin/spicec", "/usr/bin/spicec", "--controller", NULL);
-        g_critical("ERROR failed to run spicec fallback");
+        execle("/usr/bin/spicec",
+               "/usr/bin/spicec", "--controller", NULL,
+               env);
 
+        g_critical("ERROR failed to run spicec fallback");
+        g_strfreev(env);
         exit(EXIT_FAILURE);
     }
     else
commit 5ea753946fb579dcc4a1dce1e4a0fe03ce4fb751
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Tue Jan 29 13:15:55 2013 +0100

    xpi: add a few g_environ functions from GLib >= 2.28

diff --git a/SpiceXPI/src/plugin/Makefile.am b/SpiceXPI/src/plugin/Makefile.am
index 08d89d7..7bc87df 100644
--- a/SpiceXPI/src/plugin/Makefile.am
+++ b/SpiceXPI/src/plugin/Makefile.am
@@ -35,6 +35,8 @@ libnsISpicec_la_LIBADD =			\
 libnsISpicec_la_SOURCES =			\
 	$(top_srcdir)/common/common.h		\
 	$(top_srcdir)/common/rederrorcodes.h	\
+	glib-compat.c				\
+	glib-compat.h				\
 	controller.cpp				\
 	controller.h				\
 	np_entry.cpp				\
diff --git a/SpiceXPI/src/plugin/glib-compat.c b/SpiceXPI/src/plugin/glib-compat.c
new file mode 100644
index 0000000..f360677
--- /dev/null
+++ b/SpiceXPI/src/plugin/glib-compat.c
@@ -0,0 +1,188 @@
+/* GLIB - Library of useful routines for C programming
+ * Copyright (C) 1995-1998  Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GLib Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#include <unistd.h>
+#include <string.h>
+
+#include "glib-compat.h"
+
+#if !GLIB_CHECK_VERSION (2,32,0)
+static gint
+g_environ_find (gchar       **envp,
+                const gchar  *variable)
+{
+  gint len, i;
+
+  if (envp == NULL)
+    return -1;
+
+  len = strlen (variable);
+
+  for (i = 0; envp[i]; i++)
+    {
+      if (strncmp (envp[i], variable, len) == 0 &&
+          envp[i][len] == '=')
+        return i;
+    }
+
+  return -1;
+}
+
+/**
+ * g_environ_getenv:
+ * @envp: (allow-none) (array zero-terminated=1) (transfer none): an environment
+ *     list (eg, as returned from g_get_environ()), or %NULL
+ *     for an empty environment list
+ * @variable: the environment variable to get, in the GLib file name
+ *     encoding
+ *
+ * Returns the value of the environment variable @variable in the
+ * provided list @envp.
+ *
+ * The name and value are in the GLib file name encoding.
+ * On UNIX, this means the actual bytes which might or might not
+ * be in some consistent character set and encoding. On Windows,
+ * it is in UTF-8. On Windows, in case the environment variable's
+ * value contains references to other environment variables, they
+ * are expanded.
+ *
+ * Return value: the value of the environment variable, or %NULL if
+ *     the environment variable is not set in @envp. The returned
+ *     string is owned by @envp, and will be freed if @variable is
+ *     set or unset again.
+ *
+ * Since: 2.32
+ */
+const gchar *
+g_environ_getenv (gchar       **envp,
+                  const gchar  *variable)
+{
+  gint index;
+
+  g_return_val_if_fail (variable != NULL, NULL);
+
+  index = g_environ_find (envp, variable);
+  if (index != -1)
+    return envp[index] + strlen (variable) + 1;
+  else
+    return NULL;
+}
+
+/**
+ * g_environ_setenv:
+ * @envp: (allow-none) (array zero-terminated=1) (transfer full): an environment
+ *     list that can be freed using g_strfreev() (e.g., as returned from g_get_environ()), or %NULL
+ *     for an empty environment list
+ * @variable: the environment variable to set, must not contain '='
+ * @value: the value for to set the variable to
+ * @overwrite: whether to change the variable if it already exists
+ *
+ * Sets the environment variable @variable in the provided list
+ * @envp to @value.
+ *
+ * Both the variable's name and value should be in the GLib
+ * file name encoding. On UNIX, this means that they can be
+ * arbitrary byte strings. On Windows, they should be in UTF-8.
+ *
+ * Return value: (array zero-terminated=1) (transfer full): the
+ *     updated environment list. Free it using g_strfreev().
+ *
+ * Since: 2.32
+ */
+gchar **
+g_environ_setenv (gchar       **envp,
+                  const gchar  *variable,
+                  const gchar  *value,
+                  gboolean      overwrite)
+{
+  gint index;
+
+  g_return_val_if_fail (variable != NULL, NULL);
+  g_return_val_if_fail (strchr (variable, '=') == NULL, NULL);
+
+  index = g_environ_find (envp, variable);
+  if (index != -1)
+    {
+      if (overwrite)
+        {
+          g_free (envp[index]);
+          envp[index] = g_strdup_printf ("%s=%s", variable, value);
+        }
+    }
+  else
+    {
+      gint length;
+
+      length = envp ? g_strv_length (envp) : 0;
+      envp = g_renew (gchar *, envp, length + 2);
+      envp[length] = g_strdup_printf ("%s=%s", variable, value);
+      envp[length + 1] = NULL;
+    }
+
+  return envp;
+}
+#endif /* !GLIB_CHECK_VERSION (2,32,0) */
+
+
+#if !GLIB_CHECK_VERSION (2,28,0)
+#ifndef G_OS_WIN32
+/* According to the Single Unix Specification, environ is not
+ * in any system header, although unistd.h often declares it.
+ */
+extern char **environ;
+
+gchar **
+g_get_environ (void)
+{
+  return g_strdupv (environ);
+}
+
+#else /* G_OS_WIN32 */
+
+gchar **
+g_get_environ (void)
+{
+  gunichar2 *strings;
+  gchar **result;
+  gint i, n;
+
+  strings = GetEnvironmentStringsW ();
+  for (n = 0, i = 0; strings[n]; i++)
+    n += wcslen (strings + n) + 1;
+
+  result = g_new (char *, i + 1);
+  for (n = 0, i = 0; strings[n]; i++)
+    {
+      result[i] = g_utf16_to_utf8 (strings + n, -1, NULL, NULL, NULL);
+      n += wcslen (strings + n) + 1;
+    }
+  FreeEnvironmentStringsW (strings);
+  result[i] = NULL;
+
+  return result;
+}
+#endif /* G_OS_WIN32 */
+#endif /* !GLIB_CHECK_VERSION (2,28,0) */
diff --git a/SpiceXPI/src/plugin/glib-compat.h b/SpiceXPI/src/plugin/glib-compat.h
new file mode 100644
index 0000000..0724417
--- /dev/null
+++ b/SpiceXPI/src/plugin/glib-compat.h
@@ -0,0 +1,49 @@
+/* GLIB - Library of useful routines for C programming
+ * Copyright (C) 1995-1998  Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GLib Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#ifndef GLIB_COMPAT_H_
+# define GLIB_COMPAT_H_
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#if !GLIB_CHECK_VERSION (2,32,0)
+const gchar *      g_environ_getenv          (gchar       **envp,
+                                              const gchar  *variable);
+gchar **           g_environ_setenv          (gchar       **envp,
+                                              const gchar  *variable,
+                                              const gchar  *value,
+                                              gboolean      overwrite);
+#endif
+
+#if !GLIB_CHECK_VERSION (2,28,0)
+gchar **           g_get_environ             (void);
+#endif
+
+G_END_DECLS
+
+#endif /* GLIB_COMPAT_H_ */
diff --git a/SpiceXPI/src/plugin/plugin.h b/SpiceXPI/src/plugin/plugin.h
index 38a8c82..6305dcc 100644
--- a/SpiceXPI/src/plugin/plugin.h
+++ b/SpiceXPI/src/plugin/plugin.h
@@ -58,6 +58,7 @@ extern "C" {
 #include "pluginbase.h"
 #include "controller.h"
 #include "common.h"
+#include "glib-compat.h"
 
 class nsPluginInstance: public nsPluginInstanceBase
 {


More information about the Spice-commits mailing list