diff options
author | Frediano Ziglio <fziglio@redhat.com> | 2019-07-03 11:50:54 +0100 |
---|---|---|
committer | Frediano Ziglio <freddy77@gmail.com> | 2022-03-06 14:53:38 +0000 |
commit | cb6fa5ca297c28acd756cff5aad19c2bfefad577 (patch) | |
tree | 905122fd8a4775e0bb9bd7ab72f2b4fb97c37f0a | |
parent | afb858d6d5ce4fd0bc9295ef07a974c70b15122f (diff) |
SAVEwebdav
-rw-r--r-- | src/channel-webdav.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/channel-webdav.c b/src/channel-webdav.c index 38b0944..364baad 100644 --- a/src/channel-webdav.c +++ b/src/channel-webdav.c @@ -49,7 +49,9 @@ struct _SpiceWebdavChannelPrivate { SpiceVmcStream *stream; GCancellable *cancellable; +#ifdef USE_PHODAV GHashTable *clients; +#endif gboolean demuxing; struct _demux { @@ -181,10 +183,10 @@ static void output_queue_push(OutputQueue *q, const guint8 *buf, gsize size, #define MAX_MUX_SIZE G_MAXUINT16 +#ifdef USE_PHODAV typedef struct Client { guint refs; -#ifdef USE_PHODAV SpiceWebdavChannel *self; GIOStream *pipe; gint64 id; @@ -195,7 +197,6 @@ typedef struct Client guint16 size; guint8 buf[MAX_MUX_SIZE]; } mux; -#endif } Client; static void @@ -204,15 +205,12 @@ client_unref(Client *client) if (--client->refs > 0) return; -#ifdef USE_PHODAV g_object_unref(client->pipe); g_object_unref(client->cancellable); -#endif g_free(client); } -#ifdef USE_PHODAV static Client * client_ref(Client *client) { @@ -343,11 +341,9 @@ static void demux_to_client_cb(GObject *source, GAsyncResult *result, gpointer u demux_to_client_finish(client, fail); client_unref(client); } -#endif static void demux_to_client(Client *client) { -#ifdef USE_PHODAV SpiceWebdavChannelPrivate *c = client->self->priv; gsize size = c->demux.size; @@ -362,12 +358,10 @@ static void demux_to_client(Client *client) g_output_stream_write_all_async(g_io_stream_get_output_stream(client->pipe), c->demux.buf, size, G_PRIORITY_DEFAULT, c->cancellable, demux_to_client_cb, client_ref(client)); -#endif } static void start_client(SpiceWebdavChannel *self) { -#ifdef USE_PHODAV SpiceWebdavChannelPrivate *c = self->priv; Client *client; GIOStream *peer = NULL; @@ -411,8 +405,8 @@ fail: g_clear_object(&peer); g_clear_error(&error); client_unref(client); -#endif } +#endif static void data_read_cb(GObject *source_object, GAsyncResult *res, @@ -420,7 +414,6 @@ static void data_read_cb(GObject *source_object, { SpiceWebdavChannel *self = user_data; SpiceWebdavChannelPrivate *c; - Client *client; GError *error = NULL; gssize size; @@ -436,7 +429,8 @@ static void data_read_cb(GObject *source_object, c = self->priv; g_return_if_fail(size == c->demux.size); - client = g_hash_table_lookup(c->clients, &c->demux.client); +#ifdef USE_PHODAV + Client *client = g_hash_table_lookup(c->clients, &c->demux.client); if (client && g_output_stream_is_closed(g_io_stream_get_output_stream(client->pipe))) { CHANNEL_DEBUG(self, "found client %p, but it's already closed, removing", client); @@ -444,14 +438,18 @@ static void data_read_cb(GObject *source_object, client = NULL; } - if (client) + if (client) { demux_to_client(client); - else if (size > 0) { + return; + } + if (size > 0) { start_client(self); - } else { - c->demuxing = FALSE; - start_demux(self); + return; } +#endif + + c->demuxing = FALSE; + start_demux(self); } @@ -542,19 +540,21 @@ static void port_event(SpiceWebdavChannel *self, gint event) } else { g_cancellable_cancel(c->cancellable); c->demuxing = FALSE; +#ifdef USE_PHODAV g_hash_table_remove_all(c->clients); +#endif } } +#ifdef USE_PHODAV static void client_remove_unref(gpointer data) { Client *client = data; -#ifdef USE_PHODAV g_cancellable_cancel(client->cancellable); -#endif client_unref(client); } +#endif static void spice_webdav_channel_init(SpiceWebdavChannel *channel) { @@ -562,8 +562,10 @@ static void spice_webdav_channel_init(SpiceWebdavChannel *channel) channel->priv = c; c->stream = spice_vmc_stream_new(SPICE_CHANNEL(channel)); +#ifdef USE_PHODAV c->clients = g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, client_remove_unref); +#endif c->demux.buf = g_malloc0(MAX_MUX_SIZE); } @@ -583,7 +585,9 @@ static void spice_webdav_channel_dispose(GObject *object) g_cancellable_cancel(c->cancellable); g_clear_object(&c->cancellable); g_clear_object(&c->stream); +#ifdef USE_PHODAV g_hash_table_unref(c->clients); +#endif G_OBJECT_CLASS(spice_webdav_channel_parent_class)->dispose(object); } @@ -600,7 +604,9 @@ static void spice_webdav_channel_reset(SpiceChannel *channel, gboolean migrating g_cancellable_cancel(c->cancellable); c->demuxing = FALSE; +#ifdef USE_PHODAV g_hash_table_remove_all(c->clients); +#endif SPICE_CHANNEL_CLASS(spice_webdav_channel_parent_class)->channel_reset(channel, migrating); } |