[Spice-commits] 5 commits - configure.ac SpiceXPI/src

Christophe Fergau teuf at kemper.freedesktop.org
Fri Apr 12 12:25:38 PDT 2013


 SpiceXPI/src/plugin/Makefile.am        |   42 ++++--
 SpiceXPI/src/plugin/controller-win.cpp |  229 +++++++++++++++++++++++++++++++++
 SpiceXPI/src/plugin/controller-win.h   |   93 +++++++++++++
 SpiceXPI/src/plugin/controller.cpp     |   15 ++
 SpiceXPI/src/plugin/npapi-plugin.syms  |    3 
 SpiceXPI/src/plugin/plugin.cpp         |   57 ++++++++
 SpiceXPI/src/plugin/resource.rc        |   34 ++++
 configure.ac                           |   25 +++
 8 files changed, 486 insertions(+), 12 deletions(-)

New commits:
commit d55537c24f73deca0346ab37d93bf5d4437f77b5
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Wed Feb 27 18:42:12 2013 +0100

    Add glib Windows logging
    
    As it's not very convenient to get logging output from the plugin
    while firefox is running, this commit adds a dumb glib logging
    implementation that writes the logging information to a file.
    As this is not efficient at all, it's disabled by default unless
    the SPICE_XPI_LOG_TO_FILE environment variable is set.

diff --git a/SpiceXPI/src/plugin/plugin.cpp b/SpiceXPI/src/plugin/plugin.cpp
index 2e59bfd..fdb4954 100644
--- a/SpiceXPI/src/plugin/plugin.cpp
+++ b/SpiceXPI/src/plugin/plugin.cpp
@@ -173,6 +173,51 @@ void NS_DestroyPluginInstance(nsPluginInstanceBase *aPlugin)
 //
 // nsPluginInstance class implementation
 //
+static void glib_log_to_file(const gchar *log_domain,
+                             GLogLevelFlags log_level,
+                             const gchar *message,
+                             gpointer user_data)
+{
+    FILE *log_file;
+
+    if ((log_level & G_LOG_LEVEL_MASK) > G_LOG_LEVEL_MESSAGE) {
+        return;
+    }
+
+    log_file = (FILE *)user_data;
+
+    if (log_domain != NULL) {
+        fwrite(log_domain, strlen(log_domain), 1, log_file);
+        fwrite(": ", 2, 1, log_file);
+    }
+    if (message != NULL) {
+        fwrite(message, strlen(message), 1, log_file);
+    }
+    fwrite("\r\n", 2, 1, log_file);
+    fflush(log_file);
+}
+
+static void glib_setup_logging(void)
+{
+#if defined(XP_WIN)
+    FILE *log_file;
+    gchar *log_filename;
+
+    if (!g_getenv("SPICE_XPI_LOG_TO_FILE"))
+        return;
+
+    log_filename = g_build_filename(g_get_tmp_dir(), "SPICEXPI.LOG", NULL);
+    log_file = fopen(log_filename, "w+");
+    if (log_file != NULL) {
+        g_log_set_default_handler(glib_log_to_file, log_file);
+    } else {
+        gchar *log_msg;
+        log_msg = g_strdup_printf("failed to open %s", log_filename);
+        g_free(log_msg);
+    }
+    g_free(log_filename);
+#endif
+}
 
 nsPluginInstance::nsPluginInstance(NPP aInstance):
     nsPluginInstanceBase(),
@@ -191,6 +236,7 @@ nsPluginInstance::nsPluginInstance(NPP aInstance):
 #if !GLIB_CHECK_VERSION(2, 35, 0)
     g_type_init();
 #endif
+    glib_setup_logging();
 
 #if defined(XP_WIN)
     m_external_controller = new SpiceControllerWin(this);
commit 8d706325f0c6445aa229438ae7d34c064c69be98
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Fri Mar 1 17:55:59 2013 +0100

    Add SpiceControllerWin class
    
    This class implements the controller interface for Windows/mingw.

diff --git a/SpiceXPI/src/plugin/Makefile.am b/SpiceXPI/src/plugin/Makefile.am
index bb50d21..93f4c2c 100644
--- a/SpiceXPI/src/plugin/Makefile.am
+++ b/SpiceXPI/src/plugin/Makefile.am
@@ -66,6 +66,8 @@ if OS_WINDOWS
 	$(LIBTOOL) --tag=RC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(WINDRES) $(RCFLAGS) -i $< -o $@
 
 npSpiceConsole_la_SOURCES +=			\
+	controller-win.cpp			\
+	controller-win.h			\
 	resource.rc				\
 	$(NULL)
 
diff --git a/SpiceXPI/src/plugin/controller-win.cpp b/SpiceXPI/src/plugin/controller-win.cpp
new file mode 100644
index 0000000..85180da
--- /dev/null
+++ b/SpiceXPI/src/plugin/controller-win.cpp
@@ -0,0 +1,229 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ *   The contents of this file are subject to the Mozilla Public License Version
+ *   1.1 (the "License"); you may not use this file except in compliance with
+ *   the License. You may obtain a copy of the License at
+ *   http://www.mozilla.org/MPL/
+ *
+ *   Software distributed under the License is distributed on an "AS IS" basis,
+ *   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ *   for the specific language governing rights and limitations under the
+ *   License.
+ *
+ *   Copyright 2009-2013, Red Hat Inc.
+ *   Based on mozilla.org's scriptable plugin example
+ *
+ *   The Original Code is mozilla.org code.
+ *
+ *   The Initial Developer of the Original Code is
+ *   Netscape Communications Corporation.
+ *   Portions created by the Initial Developer are Copyright (C) 1998
+ *   the Initial Developer. All Rights Reserved.
+ *
+ *   Contributor(s):
+ *   Uri Lublin
+ *   Martin Stransky
+ *   Peter Hatina
+ *   Christophe Fergeau
+ *
+ *   Alternatively, the contents of this file may be used under the terms of
+ *   either the GNU General Public License Version 2 or later (the "GPL"), or
+ *   the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ *   in which case the provisions of the GPL or the LGPL are applicable instead
+ *   of those above. If you wish to allow use of your version of this file only
+ *   under the terms of either the GPL or the LGPL, and not to allow others to
+ *   use your version of this file under the terms of the MPL, indicate your
+ *   decision by deleting the provisions above and replace them with the notice
+ *   and other provisions required by the GPL or the LGPL. If you do not delete
+ *   the provisions above, a recipient may use your version of this file under
+ *   the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "config.h"
+
+#include <aclapi.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <cerrno>
+#include <glib.h>
+#include <gio/gwin32outputstream.h>
+
+#include "rederrorcodes.h"
+#include "controller-win.h"
+#include "plugin.h"
+
+SpiceControllerWin::SpiceControllerWin(nsPluginInstance *aPlugin):
+    SpiceController(aPlugin)
+{
+    g_random_set_seed(time(NULL));
+}
+
+SpiceControllerWin::~SpiceControllerWin()
+{
+}
+
+int SpiceControllerWin::Connect()
+{
+    HANDLE hClientPipe;
+
+    hClientPipe = CreateFile(m_name.c_str(),
+                             GENERIC_READ |  GENERIC_WRITE,
+                             0, NULL,
+                             OPEN_EXISTING,
+                             SECURITY_SQOS_PRESENT | SECURITY_ANONYMOUS,
+                             NULL);
+    g_return_val_if_fail(hClientPipe != INVALID_HANDLE_VALUE, -1);
+
+    g_warning("Connection OK");
+    m_pipe = g_win32_output_stream_new(hClientPipe, TRUE);
+    return 0;
+}
+
+static int get_sid(HANDLE handle, PSID* ppsid, PSECURITY_DESCRIPTOR* ppsec_desc)
+{
+    DWORD ret = GetSecurityInfo(handle, SE_KERNEL_OBJECT, OWNER_SECURITY_INFORMATION,
+                                ppsid, NULL, NULL, NULL, ppsec_desc);
+    if (ret != ERROR_SUCCESS) {
+        return ret;
+    }
+    if (!IsValidSid(*ppsid)) {
+        return -1;
+    }
+    return 0;
+}
+
+//checks whether the handle owner is the current user.
+static bool is_same_user(HANDLE handle)
+{
+    PSECURITY_DESCRIPTOR psec_desc_handle = NULL;
+    PSECURITY_DESCRIPTOR psec_desc_user = NULL;
+    PSID psid_handle;
+    PSID psid_user;
+    bool ret;
+
+    ret = !get_sid(handle, &psid_handle, &psec_desc_handle) &&
+          !get_sid(GetCurrentProcess(), &psid_user, &psec_desc_user) &&
+          EqualSid(psid_handle, psid_user);
+    LocalFree(psec_desc_handle);
+    LocalFree(psec_desc_user);
+    return ret;
+}
+
+bool SpiceControllerWin::CheckPipe()
+{
+    void *hClientPipe;
+
+    g_return_val_if_fail(G_IS_WIN32_OUTPUT_STREAM(m_pipe), false);
+
+    hClientPipe = g_win32_output_stream_get_handle(G_WIN32_OUTPUT_STREAM(m_pipe));
+    // Verify the named-pipe-server owner is the current user.
+    if (hClientPipe != INVALID_HANDLE_VALUE) {
+        if (!is_same_user(hClientPipe)) {
+            g_critical("Closing pipe to spicec -- it is not safe");
+            g_object_unref(G_OBJECT(m_pipe));
+            m_pipe = NULL;
+            return false;
+        }
+    }
+
+    return true;
+}
+
+#define SPICE_CLIENT_REGISTRY_KEY TEXT("Software\\spice-space.org\\spicex")
+#define SPICE_XPI_DLL TEXT("npSpiceConsole.dll")
+#define RED_CLIENT_FILE_NAME TEXT("spicec.exe")
+#define CMDLINE_LENGTH 32768
+
+GStrv SpiceControllerWin::GetClientPath()
+{
+    LONG lret;
+    HKEY hkey;
+    DWORD dwType = REG_SZ;
+    TCHAR lpCommandLine[CMDLINE_LENGTH] = {0};
+    DWORD dwSize = sizeof(lpCommandLine);
+    GError *err = NULL;
+    gchar **args = NULL;
+
+    lret = RegOpenKeyEx(HKEY_CURRENT_USER, SPICE_CLIENT_REGISTRY_KEY,
+            0, KEY_READ, &hkey);
+    g_return_val_if_fail(lret == ERROR_SUCCESS, NULL);
+
+    lret = RegQueryValueEx(hkey, "client", NULL, &dwType,
+            (LPBYTE)lpCommandLine, &dwSize);
+    RegCloseKey(hkey);
+
+    /* The registry key contains the command to run as a string, the GSpawn
+     * API expects an array of strings. The awkward part is that the GSpawn
+     * API will then rebuild a commandline string from this array :-/ */
+    g_shell_parse_argv(lpCommandLine, NULL, &args, &err);
+    if (err != NULL)
+        g_warning("Failed to parse '%s': %s", lpCommandLine, err->message);
+
+    return args;
+}
+
+GStrv SpiceControllerWin::GetFallbackClientPath()
+{
+    HMODULE hModule;
+    gchar *module_path;
+    GStrv fallback_argv;
+
+    // we assume the Spice client binary is located in the same dir as the
+    // Firefox plugin
+    hModule = GetModuleHandle(SPICE_XPI_DLL);
+    g_return_val_if_fail(hModule != NULL, NULL);
+
+    module_path = g_win32_get_package_installation_directory_of_module(hModule);
+    g_return_val_if_fail(module_path != NULL, NULL);
+    fallback_argv = g_new0(char *, 3);
+    fallback_argv[0] = g_build_filename(module_path, RED_CLIENT_FILE_NAME, NULL);
+    fallback_argv[1] = g_strdup("--controller");
+    g_free(module_path);
+
+    return fallback_argv;
+}
+
+#define RED_CLIENT_PIPE_NAME TEXT("\\\\.\\pipe\\SpiceController-%lu")
+void SpiceControllerWin::SetupControllerPipe(GStrv &env)
+{
+    char *pipe_name;
+    pipe_name = g_strdup_printf(RED_CLIENT_PIPE_NAME, (unsigned long)g_random_int());
+    this->SetFilename(pipe_name);
+    env = g_environ_setenv(env, "SPICE_XPI_NAMEDPIPE", pipe_name, TRUE);
+    g_free(pipe_name);
+}
+
+void SpiceControllerWin::StopClient()
+{
+    if (m_pid_controller != NULL) {
+        //WaitForPid will take care of closing the handle
+        TerminateProcess(m_pid_controller, 0);
+        m_pid_controller = NULL;
+    }
+}
+
+
+uint32_t SpiceControllerWin::Write(const void *lpBuffer, uint32_t nBytesToWrite)
+{
+    GError *error = NULL;
+    gsize bytes_written;
+
+    g_return_val_if_fail(G_IS_OUTPUT_STREAM(m_pipe), 0);
+
+    g_output_stream_write_all(m_pipe, lpBuffer, nBytesToWrite,
+                              &bytes_written, NULL, &error);
+    if (error != NULL) {
+        g_warning("Error writing to controller pipe: %s", error->message);
+        g_clear_error(&error);
+        return -1;
+    }
+    if (bytes_written != nBytesToWrite) {
+        g_warning("Partial write (%"G_GSIZE_MODIFIER"u instead of %u",
+                  bytes_written, (unsigned int)nBytesToWrite);
+    }
+
+    return bytes_written;
+}
diff --git a/SpiceXPI/src/plugin/controller-win.h b/SpiceXPI/src/plugin/controller-win.h
new file mode 100644
index 0000000..fe09900
--- /dev/null
+++ b/SpiceXPI/src/plugin/controller-win.h
@@ -0,0 +1,93 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ *   The contents of this file are subject to the Mozilla Public License Version
+ *   1.1 (the "License"); you may not use this file except in compliance with
+ *   the License. You may obtain a copy of the License at
+ *   http://www.mozilla.org/MPL/
+ *
+ *   Software distributed under the License is distributed on an "AS IS" basis,
+ *   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ *   for the specific language governing rights and limitations under the
+ *   License.
+ *
+ *   Copyright 2009-2011, Red Hat Inc.
+ *   Copyright 2013, Red Hat Inc.
+ *   Based on mozilla.org's scriptable plugin example
+ *
+ *   The Original Code is mozilla.org code.
+ *
+ *   The Initial Developer of the Original Code is
+ *   Netscape Communications Corporation.
+ *   Portions created by the Initial Developer are Copyright (C) 1998
+ *   the Initial Developer. All Rights Reserved.
+ *
+ *   Contributor(s):
+ *   Uri Lublin
+ *   Martin Stransky
+ *   Peter Hatina
+ *   Christophe Fergeau
+ *
+ *   Alternatively, the contents of this file may be used under the terms of
+ *   either the GNU General Public License Version 2 or later (the "GPL"), or
+ *   the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ *   in which case the provisions of the GPL or the LGPL are applicable instead
+ *   of those above. If you wish to allow use of your version of this file only
+ *   under the terms of either the GPL or the LGPL, and not to allow others to
+ *   use your version of this file under the terms of the MPL, indicate your
+ *   decision by deleting the provisions above and replace them with the notice
+ *   and other provisions required by the GPL or the LGPL. If you do not delete
+ *   the provisions above, a recipient may use your version of this file under
+ *   the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef SPICE_CONTROLLER_WIN_H
+#define SPICE_CONTROLLER_WIN_H
+
+/*
+    Basic assumption:
+    ------------------
+    Cross platform compatible.
+    Easy to transform into remote process communication
+    Secured
+
+    chosen:
+        Unix - Unix Domain Sockets (easy to change into regular sockets for remote communication)
+        Windows - Named pipe (which allows remote access and is duplex
+            (rather than anonymous pipe which is local only and one way)
+*/
+
+#include <glib.h>
+#include <glib-object.h> /* for GStrv */
+#include <gio/gio.h>
+#include <string>
+extern "C" {
+#  include <stdint.h>
+#  include <limits.h>
+}
+
+#include <spice/controller_prot.h>
+#include "controller.h"
+
+class nsPluginInstance;
+
+class SpiceControllerWin: public SpiceController
+{
+public:
+    SpiceControllerWin(nsPluginInstance *aPlugin);
+    virtual ~SpiceControllerWin();
+
+    virtual void StopClient();
+    virtual uint32_t Write(const void *lpBuffer, uint32_t nBytesToWrite);
+    int Connect(int nRetries) { return SpiceController::Connect(nRetries); };
+
+private:
+    virtual int Connect();
+    virtual void SetupControllerPipe(GStrv &env);
+    virtual bool CheckPipe();
+    virtual GStrv GetClientPath(void);
+    virtual GStrv GetFallbackClientPath(void);
+};
+
+#endif // SPICE_CONTROLLER_WIN_H
diff --git a/SpiceXPI/src/plugin/controller.cpp b/SpiceXPI/src/plugin/controller.cpp
index ccef1d4..ac97ce1 100644
--- a/SpiceXPI/src/plugin/controller.cpp
+++ b/SpiceXPI/src/plugin/controller.cpp
@@ -97,6 +97,21 @@ int SpiceController::Connect(const int nRetries)
         g_usleep(sleep_time * G_USEC_PER_SEC);
         ++sleep_time;
     }
+    if (rc != 0) {
+        g_warning("error connecting");
+        g_assert(m_pipe == NULL);
+    }
+    if (!CheckPipe()) {
+        g_warning("Pipe validation failure");
+        g_warn_if_fail(m_pipe == NULL);
+    }
+    if (m_pipe == NULL) {
+        g_warning("failed to create pipe");
+#ifdef XP_WIN
+        rc = MAKE_HRESULT(1, FACILITY_CREATE_RED_PIPE, GetLastError());
+#endif
+        this->StopClient();
+    }
 
     return rc;
 }
diff --git a/SpiceXPI/src/plugin/plugin.cpp b/SpiceXPI/src/plugin/plugin.cpp
index cd17620..2e59bfd 100644
--- a/SpiceXPI/src/plugin/plugin.cpp
+++ b/SpiceXPI/src/plugin/plugin.cpp
@@ -66,7 +66,12 @@ extern "C" {
 #include <fstream>
 #include <set>
 
+#if defined(XP_UNIX)
 #include "controller-unix.h"
+#endif
+#if defined(XP_WIN)
+#include "controller-win.h"
+#endif
 #include "plugin.h"
 #include "nsScriptablePeer.h"
 
@@ -187,7 +192,13 @@ nsPluginInstance::nsPluginInstance(NPP aInstance):
     g_type_init();
 #endif
 
+#if defined(XP_WIN)
+    m_external_controller = new SpiceControllerWin(this);
+#elif defined(XP_UNIX)
     m_external_controller = new SpiceControllerUnix(this);
+#else
+#error "Unknown OS, no controller implementation"
+#endif
 }
 
 nsPluginInstance::~nsPluginInstance()
diff --git a/configure.ac b/configure.ac
index 7f401ab..39a1f7e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,9 +41,9 @@ AC_CONFIG_SUBDIRS([spice-protocol])
 SPICE_PROTOCOL_CFLAGS='-I ${top_srcdir}/spice-protocol'
 AC_SUBST(SPICE_PROTOCOL_CFLAGS)
 
-PKG_CHECK_MODULES(GLIB, glib-2.0 gio-2.0 gthread-2.0)
-AC_SUBST(GLIB_CFLAGS)
-AC_SUBST(GLIB_LIBS)
+SPICE_XPI_REQUIRES="glib-2.0 gio-2.0 gthread-2.0"
+AS_IF([test "x$backend" = "xwindows"], [SPICE_XPI_REQUIRES="$SPICE_XPI_REQUIRES gio-windows-2.0"])
+PKG_CHECK_MODULES([GLIB],[$SPICE_XPI_REQUIRES])
 
 AC_ARG_ENABLE([xpi],
   [AS_HELP_STRING([--enable-xpi],
commit dcb89aaffb9b7f45cfbf760e2575a7cab57edce1
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Tue Feb 12 16:47:58 2013 +0100

    Only export needed symbols
    
    NPAPI plugins only need to have 3 symbols exported, make that
    explicit. This is also required when building Windows plugins
    as these symbols *must* be explicitly exported.

diff --git a/SpiceXPI/src/plugin/Makefile.am b/SpiceXPI/src/plugin/Makefile.am
index 3b7bd8d..bb50d21 100644
--- a/SpiceXPI/src/plugin/Makefile.am
+++ b/SpiceXPI/src/plugin/Makefile.am
@@ -8,7 +8,14 @@ plugindir=$(extensiondir)/plugins
 
 plugin_LTLIBRARIES = npSpiceConsole.la
 
-npSpiceConsole_la_LDFLAGS = -avoid-version -module -no-undefined
+EXTRA_DIST = ${srcdir}/npapi-plugin.syms
+
+npSpiceConsole_la_LDFLAGS = 				\
+	-avoid-version					\
+	-module						\
+	-no-undefined					\
+	-export-symbols ${srcdir}/npapi-plugin.syms	\
+	$(NULL)
 npSpiceConsole_la_CPPFLAGS =			\
 	-I$(top_srcdir)/common			\
 	-I$(srcdir)/npapi			\
diff --git a/SpiceXPI/src/plugin/npapi-plugin.syms b/SpiceXPI/src/plugin/npapi-plugin.syms
new file mode 100644
index 0000000..d7c247b
--- /dev/null
+++ b/SpiceXPI/src/plugin/npapi-plugin.syms
@@ -0,0 +1,3 @@
+NP_GetEntryPoints
+NP_Initialize
+NP_Shutdown
commit de800eebbfa876369ed38bc8a29962c3b308f9fa
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Thu Feb 7 15:39:28 2013 +0100

    Rename plugin binary from libnsISpicec to npSpiceConsole
    
    Windows Firefox expects the plugin filename to start with 'np'
    otherwise it won't pick it up as a plugin.

diff --git a/SpiceXPI/src/plugin/Makefile.am b/SpiceXPI/src/plugin/Makefile.am
index 9116ba7..3b7bd8d 100644
--- a/SpiceXPI/src/plugin/Makefile.am
+++ b/SpiceXPI/src/plugin/Makefile.am
@@ -6,10 +6,10 @@ SDK_INCLUDE_DIR = `pkg-config --variable=idldir libxul`
 
 plugindir=$(extensiondir)/plugins
 
-plugin_LTLIBRARIES = libnsISpicec.la
+plugin_LTLIBRARIES = npSpiceConsole.la
 
-libnsISpicec_la_LDFLAGS = -avoid-version -module -no-undefined
-libnsISpicec_la_CPPFLAGS =			\
+npSpiceConsole_la_LDFLAGS = -avoid-version -module -no-undefined
+npSpiceConsole_la_CPPFLAGS =			\
 	-I$(top_srcdir)/common			\
 	-I$(srcdir)/npapi			\
 	$(GLIB_CFLAGS)				\
@@ -17,11 +17,11 @@ libnsISpicec_la_CPPFLAGS =			\
 	-DG_LOG_DOMAIN=\"SpiceXPI\"		\
 	$(NULL)
 
-libnsISpicec_la_LIBADD =			\
+npSpiceConsole_la_LIBADD =			\
 	$(GLIB_LIBS)				\
 	$(NULL)
 
-libnsISpicec_la_SOURCES =			\
+npSpiceConsole_la_SOURCES =			\
 	$(top_srcdir)/common/common.h		\
 	$(top_srcdir)/common/rederrorcodes.h	\
 	glib-compat.c				\
@@ -48,7 +48,7 @@ libnsISpicec_la_SOURCES =			\
 	$(NULL)
 
 if OS_LINUX
-libnsISpicec_la_SOURCES +=			\
+npSpiceConsole_la_SOURCES +=			\
 	controller-unix.cpp			\
 	controller-unix.h			\
 	$(NULL)
@@ -58,7 +58,7 @@ if OS_WINDOWS
 .rc.lo:
 	$(LIBTOOL) --tag=RC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(WINDRES) $(RCFLAGS) -i $< -o $@
 
-libnsISpicec_la_SOURCES +=			\
+npSpiceConsole_la_SOURCES +=			\
 	resource.rc				\
 	$(NULL)
 
@@ -67,7 +67,7 @@ libnsISpicec_la_SOURCES +=			\
 endif
 
 if BUILD_XPI
-libnsISpicec_la_SOURCES +=			\
+npSpiceConsole_la_SOURCES +=			\
 	nsISpicec.h				\
 	$(NULL)
 
commit 4da6fe08c79abd2ec8a87b9c871c7e1119e0fb08
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Sat Mar 23 22:16:05 2013 +0100

    mingw: Add support for mingw build
    
    Based on a patch from Nerijus Baliunas <nerijus at users.sourceforge.net>

diff --git a/SpiceXPI/src/plugin/Makefile.am b/SpiceXPI/src/plugin/Makefile.am
index 2db218e..9116ba7 100644
--- a/SpiceXPI/src/plugin/Makefile.am
+++ b/SpiceXPI/src/plugin/Makefile.am
@@ -8,7 +8,7 @@ plugindir=$(extensiondir)/plugins
 
 plugin_LTLIBRARIES = libnsISpicec.la
 
-libnsISpicec_la_LDFLAGS = -avoid-version -module
+libnsISpicec_la_LDFLAGS = -avoid-version -module -no-undefined
 libnsISpicec_la_CPPFLAGS =			\
 	-I$(top_srcdir)/common			\
 	-I$(srcdir)/npapi			\
@@ -28,8 +28,6 @@ libnsISpicec_la_SOURCES =			\
 	glib-compat.h				\
 	controller.cpp				\
 	controller.h				\
-	controller-unix.cpp			\
-	controller-unix.h			\
 	npapi/npapi.h				\
 	npapi/npfunctions.h			\
 	npapi/npruntime.h			\
@@ -49,6 +47,25 @@ libnsISpicec_la_SOURCES =			\
 	pluginbase.h				\
 	$(NULL)
 
+if OS_LINUX
+libnsISpicec_la_SOURCES +=			\
+	controller-unix.cpp			\
+	controller-unix.h			\
+	$(NULL)
+endif
+
+if OS_WINDOWS
+.rc.lo:
+	$(LIBTOOL) --tag=RC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(WINDRES) $(RCFLAGS) -i $< -o $@
+
+libnsISpicec_la_SOURCES +=			\
+	resource.rc				\
+	$(NULL)
+
+.rc.$(OBJEXT):
+	$(AM_V_GEN)$(WINDRES) $(RCFLAGS) -i $< -o $@
+endif
+
 if BUILD_XPI
 libnsISpicec_la_SOURCES +=			\
 	nsISpicec.h				\
diff --git a/SpiceXPI/src/plugin/resource.rc b/SpiceXPI/src/plugin/resource.rc
new file mode 100644
index 0000000..8892b0a
--- /dev/null
+++ b/SpiceXPI/src/plugin/resource.rc
@@ -0,0 +1,34 @@
+1 VERSIONINFO
+ FILEVERSION 2,8,0,0
+ PRODUCTVERSION 2,8,0,0
+ FILEFLAGSMASK 0x17L
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "040904E4"
+        BEGIN
+            VALUE "CompanyName", "Fedora"
+            VALUE "FileDescription", "Spice XPI Plugin"
+            VALUE "FileVersion", "2, 8, 0, 0"
+            VALUE "InternalName", "SpiceXPI"
+            VALUE "LegalCopyright", "Fedora"
+            VALUE "OriginalFilename", "nsISpicec.dll"
+            VALUE "ProductName", "Spice XPI"
+            VALUE "ProductVersion", "2, 8, 0, 0"
+            VALUE "MIMEType", "application/x-spice"
+            VALUE "FileExtents", "qsc"
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x809, 1200
+    END
+END
diff --git a/configure.ac b/configure.ac
index 3ed0cfc..7f401ab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -13,9 +13,26 @@ AC_PROG_CXX
 AC_PROG_INSTALL
 AC_CANONICAL_HOST
 AC_PROG_LIBTOOL
+LT_LANG([Windows Resource])
 AM_PROG_CC_C_O
 
-AC_DEFINE([XP_UNIX], 1, [Building Linux plugin])
+AC_MSG_CHECKING([operating system])
+case $host in
+*-linux*)
+        AC_MSG_RESULT([Linux])
+        backend="linux"
+        AC_DEFINE([XP_UNIX], 1, [Building Linux plugin])
+        ;;
+*-mingw*)
+        AC_MSG_RESULT([Windows])
+        backend="windows"
+        AC_CHECK_TOOL([WINDRES], [windres], [no])
+        AC_DEFINE([XP_WIN], 1, [Building Windows plugin])
+        ;;
+esac
+
+AM_CONDITIONAL([OS_LINUX], [test "x$backend" = xlinux])
+AM_CONDITIONAL([OS_WINDOWS], [test "x$backend" = xwindows])
 
 dnl =========================================================================
 dnl Check deps


More information about the Spice-commits mailing list