[libepc] libepc: Adapt to newer libsoup API.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libepc] libepc: Adapt to newer libsoup API.
- Date: Wed, 1 Nov 2017 14:06:23 +0000 (UTC)
commit dede1ac89d720cf56f2a2aeb33f10ae1ec3ca3c4
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Nov 1 12:53:56 2017 +0100
libepc: Adapt to newer libsoup API.
Mainly to use GSocket instead of SoupSocket.
These changes are completely untested.
libepc/consumer.c | 2 +-
libepc/dispatcher.c | 2 +-
libepc/dispatcher.h | 2 +-
libepc/publisher.c | 116 ++++++++++++++++++++++++++++++++++++-------------
libepc/service-info.c | 10 ++--
libepc/service-info.h | 19 +-------
libepc/shell.c | 8 +++-
7 files changed, 103 insertions(+), 56 deletions(-)
---
diff --git a/libepc/consumer.c b/libepc/consumer.c
index c9ade7c..197f9ad 100644
--- a/libepc/consumer.c
+++ b/libepc/consumer.c
@@ -290,7 +290,7 @@ epc_consumer_init (EpcConsumer *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EPC_TYPE_CONSUMER, EpcConsumerPrivate);
self->priv->loop = g_main_loop_new (NULL, FALSE);
- self->priv->session = soup_session_async_new ();
+ self->priv->session = soup_session_new ();
g_signal_connect (self->priv->session, "authenticate",
G_CALLBACK (epc_consumer_authenticate_cb), self);
diff --git a/libepc/dispatcher.c b/libepc/dispatcher.c
index 673c4af..603a8b1 100644
--- a/libepc/dispatcher.c
+++ b/libepc/dispatcher.c
@@ -894,7 +894,7 @@ epc_dispatcher_reset (EpcDispatcher *self)
*/
void
epc_dispatcher_add_service (EpcDispatcher *self,
- EpcAddressFamily protocol,
+ GSocketFamily protocol,
const gchar *type,
const gchar *domain,
const gchar *host,
diff --git a/libepc/dispatcher.h b/libepc/dispatcher.h
index 8c7e8a2..4a29f3c 100644
--- a/libepc/dispatcher.h
+++ b/libepc/dispatcher.h
@@ -88,7 +88,7 @@ gboolean epc_dispatcher_run (EpcDispatcher
void epc_dispatcher_reset (EpcDispatcher *dispatcher);
void epc_dispatcher_add_service (EpcDispatcher *dispatcher,
- EpcAddressFamily protocol,
+ GSocketFamily protocol,
const gchar *type,
const gchar *domain,
const gchar *host,
diff --git a/libepc/publisher.c b/libepc/publisher.c
index 37443d6..72e792f 100644
--- a/libepc/publisher.c
+++ b/libepc/publisher.c
@@ -401,19 +401,28 @@ epc_publisher_chunk_cb (SoupMessage *message,
static void
epc_publisher_trace_client (const gchar *strfunc,
const gchar *message,
- SoupSocket *socket)
+ GSocket *socket)
{
- SoupAddress *addr = soup_socket_get_remote_address (socket);
+ /* TODO: Using sockaddr.
+
+ GError *err = NULL;
+ GSocketAddress *addr = g_socket_get_remote_address (socket, &err);
+ if (err) {
+ g_warning ("%s", err->message);
+ g_error_free (err);
+ return;
+ }
g_debug ("%s: %s: %s:%d", strfunc, message,
soup_address_get_physical (addr),
soup_address_get_port (addr));
+ */
}
static gboolean
epc_publisher_check_client (EpcPublisher *self,
SoupServer *server,
- SoupSocket *socket)
+ GSocket *socket)
{
if (server == self->priv->server)
return TRUE;
@@ -421,7 +430,12 @@ epc_publisher_check_client (EpcPublisher *self,
if (EPC_DEBUG_LEVEL (1))
epc_publisher_trace_client (G_STRFUNC, "stale client", socket);
- soup_socket_disconnect (socket);
+ GError *err = NULL;
+ g_socket_close (socket, &err);
+ if (err) {
+ g_warning ("%s", err->message);
+ g_clear_error (&err);
+ }
return FALSE;
}
@@ -429,7 +443,7 @@ epc_publisher_check_client (EpcPublisher *self,
G_GNUC_WARN_UNUSED_RESULT static gboolean
epc_publisher_track_client (EpcPublisher *self,
SoupServer *server,
- SoupSocket *socket)
+ GSocket *socket)
{
g_rec_mutex_lock (&epc_publisher_lock);
@@ -454,7 +468,7 @@ epc_publisher_track_client (EpcPublisher *self,
static void
epc_publisher_untrack_client (EpcPublisher *self,
SoupServer *server,
- SoupSocket *socket)
+ GSocket *socket)
{
if (epc_publisher_check_client (self, server, socket))
{
@@ -489,7 +503,7 @@ epc_publisher_handle_contents (SoupServer *server,
SoupSocket *socket = context->sock;
const gchar *path = context->path;
#else
- SoupSocket *socket = soup_client_context_get_socket (context);
+ GSocket *socket = soup_client_context_get_gsocket (context);
#endif
EpcPublisher *self = EPC_PUBLISHER (data);
@@ -574,7 +588,7 @@ epc_publisher_handle_list (SoupServer *server,
SoupSocket *socket = context->sock;
const gchar *path = context->path;
#else
- SoupSocket *socket = soup_client_context_get_socket (context);
+ GSocket *socket = soup_client_context_get_gsocket (context);
#endif
const gchar *pattern = NULL;
@@ -636,7 +650,7 @@ epc_publisher_handle_root (SoupServer *server,
SoupSocket *socket = context->sock;
const gchar *path = context->path;
#else
- SoupSocket *socket = soup_client_context_get_socket (context);
+ GSocket *socket = soup_client_context_get_gsocket (context);
#endif
EpcPublisher *self = data;
@@ -878,24 +892,63 @@ epc_publisher_init (EpcPublisher *self)
g_object_unref, NULL);
}
+static GSocket*
+get_listener (EpcPublisher *self)
+{
+ GSList *listeners = soup_server_get_listeners (self->priv->server);
+ g_return_val_if_fail (listeners, NULL);
+
+ return (GSocket*)listeners->data;
+}
+
static const gchar*
-epc_publisher_get_host (EpcPublisher *self,
- struct sockaddr **sockaddr,
- gint *addrlen)
+epc_publisher_get_host (EpcPublisher *self)
{
- SoupSocket *listener = soup_server_get_listener (self->priv->server);
- SoupAddress *address = soup_socket_get_local_address (listener);
+ GSocket *listener = get_listener (self);
+ g_return_val_if_fail (listener, NULL);
+
+ GError *err = NULL;
+ GSocketAddress *address = g_socket_get_local_address (listener, &err);
+ if (err) {
+ g_warning("%s", err->message);
+ return NULL;
+ }
+
+ GInetSocketAddress *inet = G_INET_SOCKET_ADDRESS (address);
+ g_return_val_if_fail (inet, NULL);
- if (sockaddr && addrlen)
- *sockaddr = soup_address_get_sockaddr (address, addrlen);
+ GInetAddress *ad = g_inet_socket_address_get_address (inet);
+ g_return_val_if_fail (ad, NULL);
- return soup_address_get_name (address);
+ return g_inet_address_to_string (ad);
}
static gint
epc_publisher_get_port (EpcPublisher *self)
{
- return soup_server_get_port (self->priv->server);
+ GSocket *listener = get_listener (self);
+ g_return_val_if_fail (listener, 0);
+
+ GError *err = NULL;
+ GSocketAddress *address = g_socket_get_local_address (listener, &err);
+ if (err) {
+ g_warning("%s", err->message);
+ return 0;
+ }
+
+ GInetSocketAddress *inet = G_INET_SOCKET_ADDRESS (address);
+ g_return_val_if_fail (inet, 0);
+
+ return g_inet_socket_address_get_port (inet);
+}
+
+static GSocketFamily
+epc_publisher_get_family (EpcPublisher *self)
+{
+ GSocket *listener = get_listener (self);
+ g_return_val_if_fail (listener, 0);
+
+ return g_socket_get_family (listener);
}
static const gchar*
@@ -960,10 +1013,9 @@ epc_publisher_announce (EpcPublisher *self)
gchar *service_sub_type;
const gchar *host;
- struct sockaddr *addr;
gchar *path_record;
- gint addrlen;
gint port;
+ GSocketFamily family;
g_return_if_fail (SOUP_IS_SERVER (self->priv->server));
@@ -976,8 +1028,9 @@ epc_publisher_announce (EpcPublisher *self)
/* compute service address */
- host = epc_publisher_get_host (self, &addr, &addrlen);
+ host = epc_publisher_get_host (self);
port = epc_publisher_get_port (self);
+ family = epc_publisher_get_family (self);
/* find all bookmark resources */
@@ -999,7 +1052,7 @@ epc_publisher_announce (EpcPublisher *self)
epc_dispatcher_reset (self->priv->dispatcher);
path_record = g_strconcat ("path=", self->priv->contents_path, NULL);
- epc_dispatcher_add_service (self->priv->dispatcher, addr->sa_family,
+ epc_dispatcher_add_service (self->priv->dispatcher, family,
service_type, self->priv->service_domain,
host, port, path_record, NULL);
g_free (path_record);
@@ -1029,7 +1082,7 @@ epc_publisher_announce (EpcPublisher *self)
path = epc_publisher_get_path (self, key);
path_record = g_strconcat ("path=", path, NULL);
- epc_dispatcher_add_service (dispatcher, addr->sa_family, bookmark_type,
+ epc_dispatcher_add_service (dispatcher, family, bookmark_type,
self->priv->service_domain, host, port,
path_record, NULL);
@@ -1186,7 +1239,7 @@ epc_publisher_install_handlers (EpcPublisher *self)
static void
epc_publisher_client_disconnected_cb (EpcPublisher *self,
- SoupSocket *socket)
+ GSocket *socket)
{
if (EPC_DEBUG_LEVEL (1))
epc_publisher_trace_client (G_STRFUNC, "disconnected", socket);
@@ -1196,7 +1249,7 @@ epc_publisher_client_disconnected_cb (EpcPublisher *self,
static void
epc_publisher_new_connection_cb (EpcPublisher *self,
- SoupSocket *socket)
+ GSocket *socket)
{
if (EPC_DEBUG_LEVEL (1))
epc_publisher_trace_client (G_STRFUNC, "new client", socket);
@@ -1262,7 +1315,8 @@ epc_publisher_create_server (EpcPublisher *self,
SOUP_SERVER_PORT, SOUP_ADDRESS_ANY_PORT,
NULL);
- g_signal_connect_swapped (soup_server_get_listener (self->priv->server), "new-connection",
+ /* TODO */
+ g_signal_connect_swapped (get_listener (self), "new-connection",
G_CALLBACK (epc_publisher_new_connection_cb), self);
epc_publisher_install_handlers (self);
@@ -1880,7 +1934,7 @@ epc_publisher_get_uri (EpcPublisher *self,
g_return_val_if_fail (EPC_IS_PUBLISHER (self), NULL);
- host = epc_publisher_get_host (self, NULL, NULL);
+ host = epc_publisher_get_host (self);
port = epc_publisher_get_port (self);
if (!host)
@@ -2480,7 +2534,9 @@ epc_publisher_run_async (EpcPublisher *self,
if (!self->priv->server_started)
{
- soup_server_run_async (self->priv->server);
+ /* TODO: No longer necessary?
+ soup_server_run_async (self->priv->server);
+ */
#ifdef HAVE_LIBSOUP22
g_object_unref (self->priv->server); /* work arround bug #494128 */
#endif
@@ -2495,7 +2551,7 @@ epc_publisher_disconnect_idle_cb (gpointer key,
gpointer value,
gpointer data)
{
- SoupSocket *socket = key;
+ GSocket *socket = key;
GSList **clients = data;
if (1 >= GPOINTER_TO_INT (value))
@@ -2542,7 +2598,7 @@ epc_publisher_quit (EpcPublisher *self)
epc_publisher_disconnect_idle_cb,
&idle_clients);
- g_slist_foreach (idle_clients, (GFunc) soup_socket_disconnect, NULL);
+ g_slist_foreach (idle_clients, (GFunc) g_socket_close, NULL);
g_slist_free (idle_clients);
g_rec_mutex_unlock (&epc_publisher_lock);
diff --git a/libepc/service-info.c b/libepc/service-info.c
index 004c746..ca690fe 100644
--- a/libepc/service-info.c
+++ b/libepc/service-info.c
@@ -285,19 +285,19 @@ epc_service_info_get_interface (const EpcServiceInfo *self)
* @info: a #EpcServiceInfo
*
* Retrieves the address family for contacting the service,
- * or #EPC_ADDRESS_UNSPEC when that information is not available.
+ * or #G_SOCKET_FAMILY_INVALID when that information is not available.
*
- * Returns: A #EpcAddressFamily.
+ * Returns: A #GSocketFamily.
*/
-EpcAddressFamily
+GSocketFamily
epc_service_info_get_address_family (const EpcServiceInfo *self)
{
- g_return_val_if_fail (NULL != self, EPC_ADDRESS_UNSPEC);
+ g_return_val_if_fail (NULL != self, G_SOCKET_FAMILY_INVALID);
if (self->address)
return avahi_proto_to_af (self->address->proto);
- return EPC_ADDRESS_UNSPEC;
+ return G_SOCKET_FAMILY_INVALID;
}
/**
diff --git a/libepc/service-info.h b/libepc/service-info.h
index 76fa122..83ea608 100644
--- a/libepc/service-info.h
+++ b/libepc/service-info.h
@@ -25,6 +25,7 @@
#include <avahi-common/address.h>
#include <avahi-common/strlst.h>
#include <glib-object.h>
+#include <gio/gio.h>
#include <sys/socket.h>
G_BEGIN_DECLS
@@ -34,22 +35,6 @@ G_BEGIN_DECLS
typedef struct _EpcServiceInfo EpcServiceInfo;
-/**
- * EpcAddressFamily:
- * @EPC_ADDRESS_UNSPEC: No preferences exist. Use all address families supported.
- * @EPC_ADDRESS_IPV4: Exclusively use IPv4 for addressing network services.
- * @EPC_ADDRESS_IPV6: Exclusively use IPv6 for addressing network services.
- *
- * The address family to use for contacting network services.
- */
-typedef enum
-{
- EPC_ADDRESS_UNSPEC = AF_UNSPEC,
- EPC_ADDRESS_IPV4 = AF_INET,
- EPC_ADDRESS_IPV6 = AF_INET6
-}
-EpcAddressFamily;
-
GType epc_service_info_get_type (void) G_GNUC_CONST;
EpcServiceInfo* epc_service_info_new (const gchar *type,
@@ -73,7 +58,7 @@ const gchar* epc_service_info_get_detail (const EpcServiceInfo *
const gchar *name);
const gchar* epc_service_info_get_interface (const EpcServiceInfo *info);
-EpcAddressFamily epc_service_info_get_address_family (const EpcServiceInfo *info);
+GSocketFamily epc_service_info_get_address_family (const EpcServiceInfo *info);
const AvahiAddress* epc_service_info_get_address (const EpcServiceInfo *info);
G_END_DECLS
diff --git a/libepc/shell.c b/libepc/shell.c
index c59deea..fe7c7de 100644
--- a/libepc/shell.c
+++ b/libepc/shell.c
@@ -62,8 +62,10 @@ static AvahiClient *epc_shell_avahi_client = NULL;
static gboolean epc_shell_restart_avahi_client_allowed = TRUE;
static GArray *epc_shell_watches = NULL;
+/*
static void (*epc_shell_threads_enter)(void) = NULL;
static void (*epc_shell_threads_leave)(void) = NULL;
+*/
static const EpcShellProgressHooks *epc_shell_progress_hooks = NULL;
static gpointer epc_shell_progress_user_data = NULL;
@@ -93,6 +95,7 @@ epc_shell_get_debug_level (void)
return level;
}
+/*
static void
epc_shell_exit (void)
{
@@ -114,6 +117,7 @@ epc_shell_exit (void)
epc_shell_threads_enter = NULL;
epc_shell_threads_leave = NULL;
}
+*/
static void
epc_shell_init (void)
@@ -122,13 +126,15 @@ epc_shell_init (void)
{
gnutls_global_init ();
avahi_set_allocator (avahi_glib_allocator ());
- g_atexit (epc_shell_exit);
+ /* deprecated: g_atexit (epc_shell_exit); */
epc_shell_avahi_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);
g_assert (NULL != epc_shell_avahi_poll);
+ /* TODO?
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ */
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]