[glom/gtkmm4v4] libepc: Adapt to newer libsoup API.



commit c9cf8547f25d38dd47ae46578ac498683eb42394
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.

 configure.ac                       |    2 +-
 glom/libglom/libepc/consumer.c     |    2 +-
 glom/libglom/libepc/dispatcher.c   |    2 +-
 glom/libglom/libepc/dispatcher.h   |    2 +-
 glom/libglom/libepc/enums.c        |   63 -------------------
 glom/libglom/libepc/enums.h        |    4 -
 glom/libglom/libepc/publisher.c    |  120 ++++++++++++++++++++++++++----------
 glom/libglom/libepc/service-info.c |   10 ++--
 glom/libglom/libepc/service-info.h |   19 +-----
 glom/libglom/libepc/shell.c        |    8 ++-
 10 files changed, 106 insertions(+), 126 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 89857f4..ed04411 100644
--- a/configure.ac
+++ b/configure.ac
@@ -163,7 +163,7 @@ AS_IF([test "x$glom_enable_postgresql" = xyes],
 
 
 # Libraries used by libglom:
-REQUIRED_LIBGLOM_LIBS='giomm-2.56 >= 2.47.4 libxml++-4.0 >= 3.0.0 libxslt >= 1.1.10 pygobject-3.0 >= 2.29.0 
libgdamm-6.0 >= 4.99.10 libgda-6.0 >= 5.2.1 libgda-postgres-6.0 libgda-postgres-6.0 libgda-mysql-6.0 
libarchive >= 3.0 libsoup-2.4 >= 2.3'
+REQUIRED_LIBGLOM_LIBS='giomm-2.56 >= 2.47.4 libxml++-4.0 >= 3.0.0 libxslt >= 1.1.10 pygobject-3.0 >= 2.29.0 
libgdamm-6.0 >= 4.99.10 libgda-6.0 >= 5.2.1 libgda-postgres-6.0 libgda-postgres-6.0 libgda-mysql-6.0 
libarchive >= 3.0 libsoup-2.4 >= 2.48'
 
 # Libraries used by Glom:
 REQUIRED_GLOM_LIBS="$REQUIRED_LIBGLOM_LIBS gtkmm-4.0 >= 3.18.0 goocanvasmm-3.0 >= 1.90.11"
diff --git a/glom/libglom/libepc/consumer.c b/glom/libglom/libepc/consumer.c
index 22786c1..1a1c076 100644
--- a/glom/libglom/libepc/consumer.c
+++ b/glom/libglom/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/glom/libglom/libepc/dispatcher.c b/glom/libglom/libepc/dispatcher.c
index 0e8d266..160d58b 100644
--- a/glom/libglom/libepc/dispatcher.c
+++ b/glom/libglom/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/glom/libglom/libepc/dispatcher.h b/glom/libglom/libepc/dispatcher.h
index 3a0fb69..680bce9 100644
--- a/glom/libglom/libepc/dispatcher.h
+++ b/glom/libglom/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/glom/libglom/libepc/enums.c b/glom/libglom/libepc/enums.c
index 331e39e..cabbc8b 100644
--- a/glom/libglom/libepc/enums.c
+++ b/glom/libglom/libepc/enums.c
@@ -190,69 +190,6 @@ epc_auth_flags_to_string (EpcAuthFlags value)
 }
 
 #endif
-/* Generated by glib-mkenums from "./libepc/service-info.h" */
-
-#define __EPC_ADDRESS_FAMILY_IS_ENUM__ 1
-
-GType
-epc_address_family_get_type (void)
-{
-  static GType etype = G_TYPE_INVALID;
-
-  if (G_UNLIKELY (G_TYPE_INVALID == etype))
-    {
-      static const GEnumValue values[] =
-        {
-          { EPC_ADDRESS_UNSPEC, "EPC_ADDRESS_UNSPEC", "unspec" },
-          { EPC_ADDRESS_IPV4, "EPC_ADDRESS_IPV4", "ipv4" },
-          { EPC_ADDRESS_IPV6, "EPC_ADDRESS_IPV6", "ipv6" },
-          { 0, NULL, NULL }
-        };
-
-      etype = g_enum_register_static (g_intern_static_string ("EpcAddressFamily"), values);
-    }
-
-  return etype;
-}
-
-/**
- * epc_address_family_get_class:
- *
- * Retrieves the GEnumClass describing the EpcAddressFamily enum.
- *
- * Returns: The GEnumClass describing EpcAddressFamily.
- */
-GEnumClass*
-epc_address_family_get_class (void)
-{
-  static GEnumClass *enum_class = NULL;
-
-  if (G_UNLIKELY (NULL == enum_class))
-    enum_class = g_type_class_ref (epc_address_family_get_type ());
-
-  return enum_class;
-}
-
-#if __EPC_ADDRESS_FAMILY_IS_ENUM__
-
-/**
- * epc_address_family_to_string:
- * @value: a EpcAddressFamily value
- *
- * Retrieves the name of a EpcAddressFamily @value, or %NULL when @value is invalid.
- *
- * Returns: The string representation of @value, or %NULL.
- */
-const gchar*
-epc_address_family_to_string (EpcAddressFamily value)
-{
-  const GEnumValue *enum_value = g_enum_get_value (epc_address_family_get_class (), value);
-
-  g_return_val_if_fail (NULL != enum_value, NULL);
-  return enum_value->value_name;
-}
-
-#endif
 
 /* Generated data ends here */
 
diff --git a/glom/libglom/libepc/enums.h b/glom/libglom/libepc/enums.h
index c7b103c..7088af0 100644
--- a/glom/libglom/libepc/enums.h
+++ b/glom/libglom/libepc/enums.h
@@ -32,10 +32,6 @@ const gchar* epc_auth_flags_to_string (EpcAuthFlags value) G_GNUC_PURE;
 #include <libglom/libepc/service-info.h>
 #define EPC_TYPE_ADDRESS_FAMILY (epc_address_family_get_type())
 
-GType                 epc_address_family_get_type  (void) G_GNUC_CONST;
-GEnumClass*           epc_address_family_get_class (void) G_GNUC_CONST;
-const gchar* epc_address_family_to_string (EpcAddressFamily value) G_GNUC_PURE;
-
 G_END_DECLS
 
 #endif /* __EPC_ENUMS_H__ */
diff --git a/glom/libglom/libepc/publisher.c b/glom/libglom/libepc/publisher.c
index 7ccc204..b4742d5 100644
--- a/glom/libglom/libepc/publisher.c
+++ b/glom/libglom/libepc/publisher.c
@@ -399,21 +399,30 @@ epc_publisher_chunk_cb (SoupMessage *message,
 }
 
 static void
-epc_publisher_trace_client (const gchar *strfunc,
-                            const gchar *message,
-                            SoupSocket  *socket)
+epc_publisher_trace_client (const gchar *strfunc G_GNUC_UNUSED,
+                            const gchar *message G_GNUC_UNUSED,
+                            GSocket  *socket G_GNUC_UNUSED)
 {
-  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/glom/libglom/libepc/service-info.c b/glom/libglom/libepc/service-info.c
index 914d220..664ab5b 100644
--- a/glom/libglom/libepc/service-info.c
+++ b/glom/libglom/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/glom/libglom/libepc/service-info.h b/glom/libglom/libepc/service-info.h
index 76fa122..83ea608 100644
--- a/glom/libglom/libepc/service-info.h
+++ b/glom/libglom/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/glom/libglom/libepc/shell.c b/glom/libglom/libepc/shell.c
index d8dca49..bf61e30 100644
--- a/glom/libglom/libepc/shell.c
+++ b/glom/libglom/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]