[gnome-user-share] main: Split up ObexPush and DAV into 2 binaries



commit d6eb26cca2c96a92f7420407229c0a332b4dc439
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Jun 13 11:34:14 2014 +0200

    main: Split up ObexPush and DAV into 2 binaries
    
    https://bugzilla.gnome.org/show_bug.cgi?id=731860

 autogen.sh                                   |    2 +-
 data/gnome-user-share-obexpush.desktop.in.in |    2 +-
 data/gnome-user-share-webdav.desktop.in.in   |    2 +-
 po/POTFILES.in                               |    3 +-
 src/Makefile.am                              |   51 ++++---
 src/obexpush.c                               |    2 +-
 src/{user_share.c => user_share-obexpush.c}  |  109 +-------------
 src/user_share-webdav.c                      |  210 ++++++++++++++++++++++++++
 src/user_share.h                             |   26 ---
 9 files changed, 251 insertions(+), 156 deletions(-)
---
diff --git a/autogen.sh b/autogen.sh
index 9e019e8..3782bd4 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -8,7 +8,7 @@ PKG_NAME="gnome-user-share"
 REQUIRED_AUTOMAKE_VERSION=1.6
 
 (test -f $srcdir/configure.ac \
-  && test -f $srcdir/src/user_share.c) || {
+  && test -f $srcdir/src/user_share-webdav.c) || {
     echo -n "**Error**: Directory "\`$srcdir\'" does not look like the"
     echo " top-level $PKG_NAME directory"
     exit 1
diff --git a/data/gnome-user-share-obexpush.desktop.in.in b/data/gnome-user-share-obexpush.desktop.in.in
index 2865d7c..e8cd1ac 100644
--- a/data/gnome-user-share-obexpush.desktop.in.in
+++ b/data/gnome-user-share-obexpush.desktop.in.in
@@ -4,7 +4,7 @@ _Comment=Launch Personal File Sharing if enabled
 _Keywords=share;files;bluetooth;obex;http;network;copy;send;
 AutostartCondition=GSETTINGS org.gnome.desktop.file-sharing bluetooth-obexpush-enabled
 Icon=folder-remote
-Exec= installdir@/gnome-user-share
+Exec= installdir@/gnome-user-share-obexpush
 Terminal=false
 Type=Application
 Categories=
diff --git a/data/gnome-user-share-webdav.desktop.in.in b/data/gnome-user-share-webdav.desktop.in.in
index 53c3c9a..025443b 100644
--- a/data/gnome-user-share-webdav.desktop.in.in
+++ b/data/gnome-user-share-webdav.desktop.in.in
@@ -4,7 +4,7 @@ _Comment=Launch Personal File Sharing if enabled
 _Keywords=share;files;bluetooth;obex;http;network;copy;send;
 AutostartCondition=GSETTINGS org.gnome.desktop.file-sharing enabled
 Icon=folder-remote
-Exec= installdir@/gnome-user-share
+Exec= installdir@/gnome-user-share-webdav
 Terminal=false
 Type=Application
 Categories=
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1f1f9d9..69045e3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -7,4 +7,5 @@ src/nautilus-share-bar.c
 src/share-extension.c
 src/http.c
 src/obexpush.c
-src/user_share.c
+src/user_share-webdav.c
+src/user_share-obexpush.c
diff --git a/src/Makefile.am b/src/Makefile.am
index ceca3e7..b853c88 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,47 +1,56 @@
-libexec_PROGRAMS= \
-       gnome-user-share
+libexec_PROGRAMS=                      \
+       gnome-user-share-webdav         \
+       gnome-user-share-obexpush
 
 noinst_LTLIBRARIES = libuser-share-common.la
 libuser_share_common_la_SOURCES = user_share-common.c user_share-common.h
 
-INCLUDES=      \
-       -DPREFIX=\""$(prefix)"\"                        \
-       -DBINDIR=\""$(bindir)"\"                        \
+INCLUDES=                                              \
+       -DPREFIX=\""$(prefix)"\"                        \
+       -DBINDIR=\""$(bindir)"\"                        \
        -DLIBEXECDIR=\""$(libexecdir)"\"                \
        -DUSER_SHARE_PROGRAM=\""$(libexecdir)/gnome-user-share"\" \
        -DGNOMELOCALEDIR=\""$(datadir)/locale"\"        \
        -DDATADIR=\""$(datadir)/gnome-user-share/"\"    \
        -DHTTPD_CONFIG_TEMPLATE=\""$(datadir)/gnome-user-share/dav_user_%s.conf"\"      \
-       -DHTTPD_PROGRAM=\""$(HTTPD)"\"  \
+       -DHTTPD_PROGRAM=\""$(HTTPD)"\"                  \
        -DHTTPD_MODULES_PATH=\""$(MODULES_PATH)"\"      \
-       -I$(top_srcdir)                                 \
-       -I$(top_builddir)                               \
+       -I$(top_srcdir)                                 \
+       -I$(top_builddir)                               \
        $(EXTENSION_CFLAGS)                             \
        $(USER_SHARE_CFLAGS)                            \
        $(X_CFLAGS)                                     \
        $(WARN_CFLAGS)
 
-gnome_user_share_SOURCES =     \
-       user_share.c            \
-       user_share.h            \
-       user_share-private.h    \
-       user_share-private.c    \
-       http.c                  \
-       http.h                  \
+gnome_user_share_webdav_SOURCES =      \
+       user_share-webdav.c             \
+       user_share-private.h            \
+       user_share-private.c            \
+       http.c                          \
+       http.h                          \
        $(NULL)
 
+gnome_user_share_webdav_LDADD =                \
+       libuser-share-common.la         \
+       $(USER_SHARE_LIBS)              \
+       $(SELINUX_LIBS)                 \
+       $(X_LIBS) $(X_PRE_LIBS) -lX11 $(X_EXTRA_LIBS)
+
 if USE_BLUETOOTH
-gnome_user_share_SOURCES +=    \
-       obexpush.c              \
+gnome_user_share_obexpush_SOURCES =    \
+       user_share-obexpush.c           \
+       user_share-private.h            \
+       user_share-private.c            \
+       obexpush.c                      \
        obexpush.h
 else
 EXTRA_DIST = obexpush.c obexpush.h
 endif
 
-gnome_user_share_LDADD =       \
-       libuser-share-common.la \
-       $(USER_SHARE_LIBS)      \
-       $(SELINUX_LIBS) \
+gnome_user_share_obexpush_LDADD =      \
+       libuser-share-common.la         \
+       $(USER_SHARE_LIBS)              \
+       $(SELINUX_LIBS)                 \
        $(X_LIBS) $(X_PRE_LIBS) -lX11 $(X_EXTRA_LIBS)
 
 nautilus_extensiondir = $(NAUTILUSDIR)
diff --git a/src/obexpush.c b/src/obexpush.c
index 3e0903f..6424bd2 100644
--- a/src/obexpush.c
+++ b/src/obexpush.c
@@ -34,7 +34,7 @@
 #include <libnotify/notify.h>
 #include <canberra-gtk.h>
 
-#include "user_share.h"
+#include "user_share-common.h"
 #include "user_share-private.h"
 
 #include "obexpush.h"
diff --git a/src/user_share.c b/src/user_share-obexpush.c
similarity index 73%
rename from src/user_share.c
rename to src/user_share-obexpush.c
index dd9366d..9b4d696 100644
--- a/src/user_share.c
+++ b/src/user_share-obexpush.c
@@ -31,7 +31,7 @@
 #include <glib-unix.h>
 #include <X11/Xlib.h>
 
-#include "user_share.h"
+#include "user_share-common.h"
 #include "user_share-private.h"
 #include "user_share-common.h"
 #include "http.h"
@@ -44,9 +44,7 @@
 #include <signal.h>
 #include <unistd.h>
 
-#ifdef HAVE_BLUETOOTH
 #include <bluetooth-client.h>
-#endif
 
 /* GNOME Session */
 #define GNOME_SESSION_DBUS_NAME      "org.gnome.SessionManager"
@@ -55,13 +53,11 @@
 
 static GSettings *settings = NULL;
 
-static guint disabled_timeout_tag = 0;
 static GDBusProxy *session_proxy = NULL;
 static gboolean has_console = TRUE;
 
 #define OBEX_ENABLED (has_console)
 
-#ifdef HAVE_BLUETOOTH
 static void
 obex_services_start (void)
 {
@@ -140,79 +136,14 @@ session_init (void)
                          NULL);
        has_console = is_session_active ();
 }
-#endif /* HAVE_BLUETOOTH */
 
 static void
-migrate_old_configuration (void)
-{
-       const char *old_config_dir;
-       const char *new_config_dir;
-
-       old_config_dir = g_build_filename (g_get_home_dir (), ".gnome2", "user-share", NULL);
-       new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
-       if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
-               g_rename (old_config_dir, new_config_dir);
-
-}
-
-static void
-require_password_changed (void)
-{
-       /* Need to restart to get new password setting */
-       if (http_get_pid () != 0) {
-               http_down ();
-               http_up ();
-       }
-}
-
-/* File sharing was disabled for some time, exit now */
-/* If we re-enable it in the ui, this will be restarted anyway */
-static gboolean
-disabled_timeout_callback (void)
-{
-       http_down ();
-
-#ifdef HAVE_BLUETOOTH
-       if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
-               _exit (0);
-#endif /* HAVE_BLUETOOTH */
-       return FALSE;
-}
-
-static void
-file_sharing_enabled_changed (void)
-{
-       gboolean enabled;
-
-       if (disabled_timeout_tag != 0) {
-               g_source_remove (disabled_timeout_tag);
-               disabled_timeout_tag = 0;
-       }
-
-       enabled = g_settings_get_boolean (settings,
-                                        FILE_SHARING_ENABLED);
-       if (enabled) {
-               if (http_get_pid () == 0) {
-                       http_up ();
-               }
-       } else {
-               http_down ();
-               disabled_timeout_tag = g_timeout_add_seconds (3,
-                                                             (GSourceFunc) disabled_timeout_callback,
-                                                             NULL);
-       }
-}
-
-#ifdef HAVE_BLUETOOTH
-static void
 file_sharing_bluetooth_obexpush_enabled_changed (void)
 {
        if (g_settings_get_boolean (settings,
                                   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
                obex_agent_down ();
-               if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE) {
-                       _exit (0);
-               }
+               _exit (0);
        } else if (OBEX_ENABLED) {
                obex_agent_up ();
        }
@@ -236,19 +167,13 @@ file_sharing_bluetooth_obexpush_notify_changed (void)
 {
        obex_agent_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
 }
-#endif /* HAVE_BLUETOOTH */
+
 static void
 setttings_changed (GSettings *settings,
                   gchar *path,
                   gpointer data)
 {
-       if (g_strcmp0 (FILE_SHARING_ENABLED, path) == 0)
-               file_sharing_enabled_changed ();
-
-       else if (g_strcmp0 (FILE_SHARING_REQUIRE_PASSWORD, path) == 0)
-               require_password_changed ();
-#ifdef HAVE_BLUETOOTH
-       else if (g_strcmp0 (FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED, path) == 0)
+       if (g_strcmp0 (FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED, path) == 0)
                file_sharing_bluetooth_obexpush_enabled_changed ();
 
        else if (g_strcmp0 (FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES, path) == 0)
@@ -256,7 +181,6 @@ setttings_changed (GSettings *settings,
 
        else if (g_strcmp0 (FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY, path) == 0)
                file_sharing_bluetooth_obexpush_notify_changed ();
-#endif /* HAVE_BLUETOOTH */
 }
 
 static gboolean
@@ -269,10 +193,7 @@ signal_handler (gpointer user_data)
 static int
 x_io_error_handler (Display *xdisplay)
 {
-       http_down ();
-#ifdef HAVE_BLUETOOTH
        obex_agent_down ();
-#endif
        _exit (2);
 }
 
@@ -325,49 +246,29 @@ main (int argc, char **argv)
                return 1;
        }
 
-       migrate_old_configuration ();
-
        settings = g_settings_new (GNOME_USER_SHARE_SCHEMAS);
-#ifdef HAVE_BLUETOOTH
-       if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
-           g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
-               return 1;
-#else
-       if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+       if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
                return 1;
-#endif /* HAVE_BLUETOOTH */
 
        x_fd = ConnectionNumber (xdisplay);
        XSetIOErrorHandler (x_io_error_handler);
 
-       if (http_init () == FALSE)
-               return 1;
-#ifdef HAVE_BLUETOOTH
        if (obex_agent_up () == FALSE)
                return 1;
-#endif
 
        g_signal_connect (settings, "changed", G_CALLBACK(setttings_changed), NULL);
 
-#ifdef HAVE_BLUETOOTH
        session_init ();
-#endif
 
        /* Initial setting */
-       file_sharing_enabled_changed ();
-#ifdef HAVE_BLUETOOTH
        file_sharing_bluetooth_obexpush_accept_files_changed ();
        file_sharing_bluetooth_obexpush_notify_changed ();
        file_sharing_bluetooth_obexpush_enabled_changed ();
-#endif /* HAVE_BLUETOOTH */
 
        gtk_main ();
 
        g_object_unref (settings);
-       http_down ();
-#ifdef HAVE_BLUETOOTH
        obex_agent_down ();
-#endif
 
        return 0;
 }
diff --git a/src/user_share-webdav.c b/src/user_share-webdav.c
new file mode 100644
index 0000000..e2e7c24
--- /dev/null
+++ b/src/user_share-webdav.c
@@ -0,0 +1,210 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Nautilus is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Nautilus 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
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *  Authors: Alexander Larsson <alexl redhat com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <glib-unix.h>
+#include <X11/Xlib.h>
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+#include "obexpush.h"
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+/* GNOME Session */
+#define GNOME_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define GNOME_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define GNOME_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GSettings *settings = NULL;
+
+static guint disabled_timeout_tag = 0;
+
+static void
+migrate_old_configuration (void)
+{
+       const char *old_config_dir;
+       const char *new_config_dir;
+
+       old_config_dir = g_build_filename (g_get_home_dir (), ".gnome2", "user-share", NULL);
+       new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+       if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+               g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (void)
+{
+       /* Need to restart to get new password setting */
+       if (http_get_pid () != 0) {
+               http_down ();
+               http_up ();
+       }
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (void)
+{
+       http_down ();
+       return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (void)
+{
+       gboolean enabled;
+
+       if (disabled_timeout_tag != 0) {
+               g_source_remove (disabled_timeout_tag);
+               disabled_timeout_tag = 0;
+       }
+
+       enabled = g_settings_get_boolean (settings,
+                                        FILE_SHARING_ENABLED);
+       if (enabled) {
+               if (http_get_pid () == 0) {
+                       http_up ();
+               }
+       } else {
+               http_down ();
+               disabled_timeout_tag = g_timeout_add_seconds (3,
+                                                             (GSourceFunc) disabled_timeout_callback,
+                                                             NULL);
+       }
+}
+
+static void
+setttings_changed (GSettings *settings,
+                  gchar *path,
+                  gpointer data)
+{
+       if (g_strcmp0 (FILE_SHARING_ENABLED, path) == 0)
+               file_sharing_enabled_changed ();
+       else if (g_strcmp0 (FILE_SHARING_REQUIRE_PASSWORD, path) == 0)
+               require_password_changed ();
+}
+
+static gboolean
+signal_handler (gpointer user_data)
+{
+       gtk_main_quit ();
+       return FALSE;
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+       http_down ();
+       _exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+       Display *xdisplay;
+       G_GNUC_UNUSED int x_fd;
+       Window selection_owner;
+       Atom xatom;
+
+       bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+       textdomain (GETTEXT_PACKAGE);
+
+       gtk_init (&argc, &argv);
+
+       if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+               g_warning ("gnome-user-share cannot be started as root for security reasons.");
+               return 1;
+       }
+
+       signal (SIGPIPE, SIG_IGN);
+       g_unix_signal_add (SIGINT, signal_handler, NULL);
+       g_unix_signal_add (SIGHUP, signal_handler, NULL);
+       g_unix_signal_add (SIGTERM, signal_handler, NULL);
+
+       xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+       if (xdisplay == NULL) {
+               g_warning ("Can't open display");
+               return 1;
+       }
+
+       xatom = XInternAtom (xdisplay, "_GNOME_USER_SHARE", FALSE);
+       selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+       if (selection_owner != None) {
+               /* There is an owner already, quit */
+               return 1;
+       }
+
+       selection_owner = XCreateSimpleWindow (xdisplay,
+                                              RootWindow (xdisplay, 0),
+                                              0, 0, 1, 1,
+                                              0, 0, 0);
+       XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+       if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+               /* Didn't get the selection */
+               return 1;
+       }
+
+       migrate_old_configuration ();
+
+       settings = g_settings_new (GNOME_USER_SHARE_SCHEMAS);
+       if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+               return 1;
+
+       x_fd = ConnectionNumber (xdisplay);
+       XSetIOErrorHandler (x_io_error_handler);
+
+       if (http_init () == FALSE)
+               return 1;
+
+       g_signal_connect (settings, "changed", G_CALLBACK(setttings_changed), NULL);
+
+       /* Initial setting */
+       file_sharing_enabled_changed ();
+
+       gtk_main ();
+
+       g_object_unref (settings);
+       http_down ();
+
+       return 0;
+}
+


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