[PATCHv2 11/22] webdav: move initialization to session

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

 



Use session accessors to initialize the webdav server
---
 gtk/channel-webdav.c     | 24 +++++-------------------
 gtk/spice-session-priv.h |  2 ++
 gtk/spice-session.c      | 23 +++++++++++++++++++++++
 3 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/gtk/channel-webdav.c b/gtk/channel-webdav.c
index dbb8730..94f3ef3 100644
--- a/gtk/channel-webdav.c
+++ b/gtk/channel-webdav.c
@@ -694,19 +694,14 @@ end:
     g_object_unref(gaddr);
 }
 
-static PhodavServer* webdav_server_new(SpiceSession *session)
+G_GNUC_INTERNAL
+PhodavServer* channel_webdav_server_new(SpiceSession *session)
 {
     PhodavServer *dav;
     SoupServer *server;
     SoupSocket *listener;
-    int i;
-
-    g_warn_if_fail(!session->priv->webdav);
 
     dav = phodav_server_new(0, spice_session_get_shared_dir(session));
-    session->priv->webdav = dav;
-    for (i = 0; i < sizeof(session->priv->webdav_magic); i++)
-        session->priv->webdav_magic[i] = g_random_int_range(0, 255);
 
     server = phodav_server_get_soup_server(dav);
     listener = soup_server_get_listener(server);
@@ -723,21 +718,12 @@ static PhodavServer* phodav_server_get(SpiceSession *session, gint *port)
     g_return_val_if_fail(SPICE_IS_SESSION(session), NULL);
 
 #ifdef USE_PHODAV
-    PhodavServer *self = NULL;
-    static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
-
-    g_static_mutex_lock(&mutex);
-    self = session->priv->webdav;
-    if (self == NULL) {
-        self = webdav_server_new(session);
-        phodav_server_run(self);
-    }
-    g_static_mutex_unlock(&mutex);
+    PhodavServer *server = spice_session_get_webdav_server(session);
 
     if (port)
-        *port = phodav_server_get_port(self);
+        *port = phodav_server_get_port(server);
 
-    return self;
+    return server;
 #else
     g_return_val_if_reached(NULL);
 #endif
diff --git a/gtk/spice-session-priv.h b/gtk/spice-session-priv.h
index 95fc078..98c3f72 100644
--- a/gtk/spice-session-priv.h
+++ b/gtk/spice-session-priv.h
@@ -178,6 +178,8 @@ gboolean spice_session_get_smartcard_enabled(SpiceSession *session);
 gboolean spice_session_get_usbredir_enabled(SpiceSession *session);
 
 const guint8* spice_session_get_webdav_magic(SpiceSession *session);
+PhodavServer *spice_session_get_webdav_server(SpiceSession *session);
+PhodavServer* channel_webdav_server_new(SpiceSession *session);
 guint spice_session_get_n_display_channels(SpiceSession *session);
 void spice_session_set_main_channel(SpiceSession *session, SpiceChannel *channel);
 gboolean spice_session_set_migration_session(SpiceSession *session, SpiceSession *mig_session);
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index 5c1966e..2e837f2 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -2379,6 +2379,29 @@ const guint8* spice_session_get_webdav_magic(SpiceSession *session)
     return session->priv->webdav_magic;
 }
 
+G_GNUC_INTERNAL
+PhodavServer* spice_session_get_webdav_server(SpiceSession *session)
+{
+    g_return_val_if_fail(SPICE_IS_SESSION(session), NULL);
+
+#ifdef USE_PHODAV
+    static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+    int i;
+
+    g_static_mutex_lock(&mutex);
+    if (!session->priv->webdav) {
+        for (i = 0; i < sizeof(session->priv->webdav_magic); i++)
+            session->priv->webdav_magic[i] = g_random_int_range(0, 255);
+
+        session->priv->webdav = channel_webdav_server_new(session);
+        phodav_server_run(session->priv->webdav);
+    }
+    g_static_mutex_unlock(&mutex);
+#endif
+
+    return session->priv->webdav;
+}
+
 /**
  * spice_session_is_for_migration:
  * @session: a Spice session
-- 
2.1.0

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]