summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2011-04-09 23:32:39 +0200
committerXavier Claessens <xclaesse@gmail.com>2011-04-09 23:32:39 +0200
commitd7f33960a633b32f240d704b0eb19d1b9cefdb70 (patch)
tree3eb144c2aa856df5b77900d4034857cc94465fd8
parent512f01f37f829f3b4bda2746c72607c1a061209f (diff)
Use g_io_stream_splice() from GLib 2.28
-rw-r--r--configure.ac4
-rw-r--r--src/Makefile.am2
-rw-r--r--src/client-helpers.c1
-rw-r--r--src/client.c7
-rw-r--r--src/common.c243
-rw-r--r--src/common.h50
-rw-r--r--src/service.c8
7 files changed, 9 insertions, 306 deletions
diff --git a/configure.ac b/configure.ac
index 6a85b63..883ef02 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,7 +28,7 @@ IT_PROG_INTLTOOL([0.35.0])
PKG_CHECK_MODULES(SSH_CONTACT,
[
telepathy-glib >= 0.13.9
- glib-2.0 >= 2.24
+ glib-2.0 >= 2.28
gio-2.0
])
@@ -110,6 +110,8 @@ AM_CONDITIONAL(HAVE_VINAGRE, test "x$have_vinagre" = "xyes")
# -----------------------------------------------------------
+AC_DEFINE(TUBE_SERVICE, "x-ssh-contact", [Define the tube service name])
+
AC_OUTPUT([
Makefile
po/Makefile.in
diff --git a/src/Makefile.am b/src/Makefile.am
index 3492352..8b83295 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,12 +15,10 @@ bin_PROGRAMS = ssh-contact
libexec_PROGRAMS = ssh-contact-service
ssh_contact_SOURCES = \
- common.c common.h \
client-helpers.c client-helpers.h \
client.c
ssh_contact_service_SOURCES = \
- common.c common.h \
service.c
servicefiledir = $(datadir)/dbus-1/services
diff --git a/src/client-helpers.c b/src/client-helpers.c
index 2442b0a..a6b060e 100644
--- a/src/client-helpers.c
+++ b/src/client-helpers.c
@@ -21,7 +21,6 @@
#include "config.h"
#include "client-helpers.h"
-#include "common.h"
typedef struct
{
diff --git a/src/client.c b/src/client.c
index 8627c28..0464b76 100644
--- a/src/client.c
+++ b/src/client.c
@@ -28,7 +28,6 @@
#include <telepathy-glib/telepathy-glib.h>
#include "client-helpers.h"
-#include "common.h"
typedef struct
{
@@ -108,7 +107,7 @@ splice_cb (GObject *source_object,
ClientContext *context = user_data;
GError *error = NULL;
- if (!_g_io_stream_splice_finish (res, &error))
+ if (!g_io_stream_splice_finish (res, &error))
throw_error (context, error);
else
leave (context);
@@ -135,8 +134,8 @@ ssh_socket_connected_cb (GObject *source_object,
}
/* Splice tube and ssh connections */
- _g_io_stream_splice_async (G_IO_STREAM (context->tube_connection),
- G_IO_STREAM (context->ssh_connection), _G_IO_STREAM_SPLICE_NONE,
+ g_io_stream_splice_async (G_IO_STREAM (context->tube_connection),
+ G_IO_STREAM (context->ssh_connection), G_IO_STREAM_SPLICE_NONE,
G_PRIORITY_DEFAULT, NULL, splice_cb, context);
}
diff --git a/src/common.c b/src/common.c
deleted file mode 100644
index 54f18b3..0000000
--- a/src/common.c
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Copyright (C) 2010 Xavier Claessens <xclaesse@gmail.com>
- * Copyright (C) 2010 Collabora Ltd.
- *
- * This program 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.
- *
- * This program 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., 51 Franklin St, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#include "config.h"
-
-#include "common.h"
-
-typedef struct
-{
- GIOStream *stream1;
- GIOStream *stream2;
- _GIOStreamSpliceFlags flags;
- gint io_priority;
- GCancellable *cancellable;
- gulong cancelled_id;
- GCancellable *op1_cancellable;
- GCancellable *op2_cancellable;
- guint completed;
- GError *error;
-} SpliceContext;
-
-static void
-splice_context_free (SpliceContext *ctx)
-{
- g_object_unref (ctx->stream1);
- g_object_unref (ctx->stream2);
- if (ctx->cancellable != NULL)
- g_object_unref (ctx->cancellable);
- g_object_unref (ctx->op1_cancellable);
- g_object_unref (ctx->op2_cancellable);
- g_clear_error (&ctx->error);
- g_slice_free (SpliceContext, ctx);
-}
-
-static void
-splice_complete (GSimpleAsyncResult *simple,
- SpliceContext *ctx)
-{
- if (ctx->cancelled_id != 0)
- g_cancellable_disconnect (ctx->cancellable, ctx->cancelled_id);
- ctx->cancelled_id = 0;
-
- if (ctx->error != NULL)
- g_simple_async_result_set_from_error (simple, ctx->error);
- g_simple_async_result_complete (simple);
-}
-
-static void
-splice_close_cb (GObject *iostream,
- GAsyncResult *res,
- gpointer user_data)
-{
- GSimpleAsyncResult *simple = user_data;
- SpliceContext *ctx;
- GError *error = NULL;
-
- g_io_stream_close_finish (G_IO_STREAM (iostream), res, &error);
-
- ctx = g_simple_async_result_get_op_res_gpointer (simple);
- ctx->completed++;
-
- /* Keep the first error that occured */
- if (error != NULL && ctx->error == NULL)
- ctx->error = error;
- else
- g_clear_error (&error);
-
- /* If all operations are done, complete now */
- if (ctx->completed == 4)
- splice_complete (simple, ctx);
-
- g_object_unref (simple);
-}
-
-static void
-splice_cb (GObject *ostream,
- GAsyncResult *res,
- gpointer user_data)
-{
- GSimpleAsyncResult *simple = user_data;
- SpliceContext *ctx;
- GError *error = NULL;
-
- g_output_stream_splice_finish (G_OUTPUT_STREAM (ostream), res, &error);
-
- ctx = g_simple_async_result_get_op_res_gpointer (simple);
- ctx->completed++;
-
- /* ignore cancellation error if it was not requested by the user */
- if (error != NULL &&
- g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) &&
- (ctx->cancellable == NULL ||
- !g_cancellable_is_cancelled (ctx->cancellable)))
- g_clear_error (&error);
-
- /* Keep the first error that occured */
- if (error != NULL && ctx->error == NULL)
- ctx->error = error;
- else
- g_clear_error (&error);
-
- if (ctx->completed == 1 &&
- (ctx->flags & _G_IO_STREAM_SPLICE_WAIT_FOR_BOTH) == 0)
- {
- /* We don't want to wait for the 2nd operation to finish, cancel it */
- g_cancellable_cancel (ctx->op1_cancellable);
- g_cancellable_cancel (ctx->op2_cancellable);
- }
- else if (ctx->completed == 2)
- {
- if (ctx->cancellable == NULL ||
- !g_cancellable_is_cancelled (ctx->cancellable))
- {
- g_cancellable_reset (ctx->op1_cancellable);
- g_cancellable_reset (ctx->op2_cancellable);
- }
-
- /* Close the IO streams if needed */
- if ((ctx->flags & _G_IO_STREAM_SPLICE_CLOSE_STREAM1) != 0)
- g_io_stream_close_async (ctx->stream1, ctx->io_priority,
- ctx->op1_cancellable, splice_close_cb, g_object_ref (simple));
- else
- ctx->completed++;
-
- if ((ctx->flags & _G_IO_STREAM_SPLICE_CLOSE_STREAM2) != 0)
- g_io_stream_close_async (ctx->stream2, ctx->io_priority,
- ctx->op2_cancellable, splice_close_cb, g_object_ref (simple));
- else
- ctx->completed++;
-
- /* If all operations are done, complete now */
- if (ctx->completed == 4)
- splice_complete (simple, ctx);
- }
-
- g_object_unref (simple);
-}
-
-static void
-splice_cancelled_cb (GCancellable *cancellable,
- GSimpleAsyncResult *simple)
-{
- SpliceContext *ctx;
-
- ctx = g_simple_async_result_get_op_res_gpointer (simple);
- g_cancellable_cancel (ctx->op1_cancellable);
- g_cancellable_cancel (ctx->op2_cancellable);
-}
-
-void
-_g_io_stream_splice_async (GIOStream *stream1,
- GIOStream *stream2,
- _GIOStreamSpliceFlags flags,
- gint io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- GSimpleAsyncResult *simple;
- SpliceContext *ctx;
- GInputStream *istream;
- GOutputStream *ostream;
-
- if (cancellable != NULL && g_cancellable_is_cancelled (cancellable))
- {
- g_simple_async_report_error_in_idle (NULL, callback,
- user_data, G_IO_ERROR, G_IO_ERROR_CANCELLED,
- "Operation has been cancelled");
- return;
- }
-
- ctx = g_slice_new0 (SpliceContext);
- ctx->stream1 = g_object_ref (stream1);
- ctx->stream2 = g_object_ref (stream2);
- ctx->flags = flags;
- ctx->io_priority = io_priority;
- ctx->op1_cancellable = g_cancellable_new ();
- ctx->op2_cancellable = g_cancellable_new ();
- ctx->completed = 0;
-
- simple = g_simple_async_result_new (NULL, callback, user_data,
- _g_io_stream_splice_finish);
- g_simple_async_result_set_op_res_gpointer (simple, ctx,
- (GDestroyNotify) splice_context_free);
-
- if (cancellable != NULL)
- {
- ctx->cancellable = g_object_ref (cancellable);
- ctx->cancelled_id = g_cancellable_connect (cancellable,
- G_CALLBACK (splice_cancelled_cb), g_object_ref (simple),
- g_object_unref);
- }
-
- istream = g_io_stream_get_input_stream (stream1);
- ostream = g_io_stream_get_output_stream (stream2);
- g_output_stream_splice_async (ostream, istream, G_OUTPUT_STREAM_SPLICE_NONE,
- io_priority, ctx->op1_cancellable, splice_cb,
- g_object_ref (simple));
-
- istream = g_io_stream_get_input_stream (stream2);
- ostream = g_io_stream_get_output_stream (stream1);
- g_output_stream_splice_async (ostream, istream, G_OUTPUT_STREAM_SPLICE_NONE,
- io_priority, ctx->op2_cancellable, splice_cb,
- g_object_ref (simple));
-
- g_object_unref (simple);
-}
-
-gboolean
-_g_io_stream_splice_finish (GAsyncResult *result,
- GError **error)
-{
- GSimpleAsyncResult *simple;
-
- g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE);
-
- simple = G_SIMPLE_ASYNC_RESULT (result);
-
- if (g_simple_async_result_propagate_error (simple, error))
- return FALSE;
-
- g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
- _g_io_stream_splice_finish), FALSE);
-
- return TRUE;
-}
diff --git a/src/common.h b/src/common.h
deleted file mode 100644
index f05e3ab..0000000
--- a/src/common.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2010 Xavier Claessens <xclaesse@gmail.com>
- * Copyright (C) 2010 Collabora Ltd.
- *
- * This program 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.
- *
- * This program 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., 51 Franklin St, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifndef __COMMON_H__
-#define __COMMON_H__
-
-#include <gio/gio.h>
-
-#define TUBE_SERVICE "x-ssh-contact"
-
-G_BEGIN_DECLS
-
-typedef enum {
- _G_IO_STREAM_SPLICE_NONE = 0,
- _G_IO_STREAM_SPLICE_CLOSE_STREAM1 = (1 << 0),
- _G_IO_STREAM_SPLICE_CLOSE_STREAM2 = (1 << 1),
- _G_IO_STREAM_SPLICE_WAIT_FOR_BOTH = (1 << 2),
-} _GIOStreamSpliceFlags;
-
-void _g_io_stream_splice_async (GIOStream *stream1,
- GIOStream *stream2,
- _GIOStreamSpliceFlags flags,
- int io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-gboolean _g_io_stream_splice_finish (GAsyncResult *result,
- GError **error);
-
-G_END_DECLS
-
-#endif /* #ifndef __COMMON_H__*/
diff --git a/src/service.c b/src/service.c
index 1ca5975..f440f2f 100644
--- a/src/service.c
+++ b/src/service.c
@@ -25,8 +25,6 @@
#include <gio/gio.h>
#include <telepathy-glib/telepathy-glib.h>
-#include "common.h"
-
static GMainLoop *loop = NULL;
static GList *channel_list = NULL;
@@ -63,7 +61,7 @@ splice_cb (GObject *source_object,
{
GError *error = NULL;
- _g_io_stream_splice_finish (res, &error);
+ g_io_stream_splice_finish (res, &error);
session_complete (channel, error);
g_clear_error (&error);
}
@@ -101,8 +99,8 @@ accept_tube_cb (GObject *object,
sshd_connection = g_socket_connection_factory_create_connection (socket);
/* Splice tube and ssh connections */
- _g_io_stream_splice_async (G_IO_STREAM (tube_connection),
- G_IO_STREAM (sshd_connection), _G_IO_STREAM_SPLICE_NONE,
+ g_io_stream_splice_async (G_IO_STREAM (tube_connection),
+ G_IO_STREAM (sshd_connection), G_IO_STREAM_SPLICE_NONE,
G_PRIORITY_DEFAULT, NULL, splice_cb, channel);
OUT: