[glom/gtkmm4v4] libepc: Remove ifdefed support for libsoup-2.2.



commit 06d2549e86b040914f45806cfd3b7f5faf656883
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Nov 1 14:54:57 2017 +0100

    libepc: Remove ifdefed support for libsoup-2.2.
    
    This code now simply requires libsoup-2.4.

 glom/libglom/libepc/consumer.c  |   80 ----------------
 glom/libglom/libepc/publisher.c |  191 ---------------------------------------
 2 files changed, 0 insertions(+), 271 deletions(-)
---
diff --git a/glom/libglom/libepc/consumer.c b/glom/libglom/libepc/consumer.c
index 1a1c076..3e5f06d 100644
--- a/glom/libglom/libepc/consumer.c
+++ b/glom/libglom/libepc/consumer.c
@@ -177,68 +177,6 @@ static guint signals[SIGNAL_LAST];
 
 G_DEFINE_TYPE (EpcConsumer, epc_consumer, G_TYPE_OBJECT);
 
-#ifdef HAVE_LIBSOUP22
-
-static void
-epc_consumer_authenticate_cb (SoupSession  *session G_GNUC_UNUSED,
-                              SoupMessage  *message,
-                              gchar        *auth_type G_GNUC_UNUSED,
-                              gchar        *auth_realm,
-                              gchar       **username,
-                              gchar       **password,
-                              gpointer      data)
-{
-  EpcConsumer *self = EPC_CONSUMER (data);
-
-  if (EPC_DEBUG_LEVEL (1))
-    g_debug ("%s: path=%s, realm=%s, username=%s, password=%s",
-             G_STRLOC, soup_message_get_uri (message)->path,
-             auth_realm, *username, *password);
-
-  g_free (*username);
-  g_free (*password);
-
-  *username = g_strdup (self->priv->username ? self->priv->username : "");
-  *password = g_strdup (self->priv->password ? self->priv->password : "");
-
-  if (EPC_DEBUG_LEVEL (1))
-    g_debug ("%s: path=%s, realm=%s, username=%s, password=%s",
-             G_STRLOC, soup_message_get_uri (message)->path,
-             auth_realm, *username, *password);
-}
-
-static void
-epc_consumer_reauthenticate_cb (SoupSession  *session,
-                                SoupMessage  *message,
-                                gchar        *auth_type,
-                                gchar        *auth_realm,
-                                gchar       **username,
-                                gchar       **password,
-                                gpointer      data)
-{
-  EpcConsumer *self = EPC_CONSUMER (data);
-  gboolean handled = FALSE;
-
-  if (EPC_DEBUG_LEVEL (1))
-    g_debug ("%s: path=%s, realm=%s, username=%s, password=%s, handled=%d",
-             G_STRLOC, soup_message_get_uri (message)->path,
-             auth_realm, *username, *password, handled);
-
-  g_signal_emit (self, signals[SIGNAL_AUTHENTICATE],
-                 0, auth_realm, &handled);
-
-  if (EPC_DEBUG_LEVEL (1))
-    g_debug ("%s: path=%s, realm=%s, username=%s, password=%s, handled=%d",
-             G_STRLOC, soup_message_get_uri (message)->path,
-             auth_realm, *username, *password, handled);
-
-  if (handled)
-    epc_consumer_authenticate_cb (session, message, auth_realm,
-                                  auth_type, username, password, data);
-}
-
-#else
-
 static void
 epc_consumer_authenticate_cb (SoupSession  *session G_GNUC_UNUSED,
                               SoupMessage  *message,
@@ -283,8 +221,6 @@ epc_consumer_authenticate_cb (SoupSession  *session G_GNUC_UNUSED,
     }
 }
 
-#endif
-
 static void
 epc_consumer_init (EpcConsumer *self)
 {
@@ -294,10 +230,6 @@ epc_consumer_init (EpcConsumer *self)
 
   g_signal_connect (self->priv->session, "authenticate",
                     G_CALLBACK (epc_consumer_authenticate_cb), self);
-#ifdef HAVE_LIBSOUP22
-  g_signal_connect (self->priv->session, "reauthenticate",
-                    G_CALLBACK (epc_consumer_reauthenticate_cb), self);
-#endif
 }
 
 static void
@@ -1015,13 +947,8 @@ epc_consumer_lookup (EpcConsumer  *self,
 
   if (SOUP_STATUS_IS_SUCCESSFUL (status))
     {
-#ifdef HAVE_LIBSOUP22
-      const gsize response_length = request->response.length;
-      gconstpointer response_data = request->response.body;
-#else
       const gsize response_length = request->response_body->length;
       gconstpointer response_data = request->response_body->data;
-#endif
 
       if (length)
         *length = response_length;
@@ -1219,17 +1146,10 @@ epc_consumer_list (EpcConsumer  *self,
                                             G_MARKUP_TREAT_CDATA_AS_TEXT,
                                             &state, NULL);
 
-#ifdef HAVE_LIBSOUP22
-      g_markup_parse_context_parse (context,
-                                    request->response.body,
-                                    request->response.length,
-                                    error);
-#else
       g_markup_parse_context_parse (context,
                                     request->response_body->data,
                                     request->response_body->length,
                                     error);
-#endif
 
       g_markup_parse_context_free (context);
     }
diff --git a/glom/libglom/libepc/publisher.c b/glom/libglom/libepc/publisher.c
index b4742d5..c2c0b61 100644
--- a/glom/libglom/libepc/publisher.c
+++ b/glom/libglom/libepc/publisher.c
@@ -33,20 +33,6 @@
 #include <libsoup/soup.h>
 #include <string.h>
 
-#ifdef HAVE_LIBSOUP22
-#include <libsoup/soup-address.h>
-#include <libsoup/soup-server.h>
-#include <libsoup/soup-server-auth.h>
-#include <libsoup/soup-server-message.h>
-
-#define SOUP_MEMORY_COPY SOUP_BUFFER_USER_OWNED
-#define SOUP_MEMORY_TAKE SOUP_BUFFER_SYSTEM_OWNED
-
-#define SoupServerCallback SoupServerCallbackFn
-#define SoupURI            SoupUri
-
-#endif
-
 #if GLIB_CHECK_VERSION(2,15,1)
 #include <gio/gio.h>
 #endif
@@ -177,13 +163,9 @@ struct _EpcAuthContext
   EpcPublisher   *publisher;
   const gchar    *key;
 
-#ifdef HAVE_LIBSOUP22
-  SoupServerAuth *auth;
-#else
   SoupMessage    *message;
   const char     *username;
   const char     *password;
-#endif
 
   /*< public >*/
 };
@@ -224,11 +206,7 @@ struct _EpcPublisherPrivate
   GMainLoop             *server_loop;
   SoupServer            *server;
 
-#ifdef HAVE_LIBSOUP22
-  SoupServerAuthContext  server_auth;
-#else
   SoupAuthDomain        *server_auth;
-#endif
 
   GHashTable            *clients;
 
@@ -378,23 +356,15 @@ epc_publisher_chunk_cb (SoupMessage *message,
       if (EPC_DEBUG_LEVEL (1))
         g_debug ("%s: writing %" G_GSIZE_FORMAT " bytes", G_STRLOC, length);
 
-#ifdef HAVE_LIBSOUP22
-      soup_message_add_chunk (message, SOUP_MEMORY_COPY, chunk, length);
-#else
       soup_message_body_append (message->response_body,
                                 SOUP_MEMORY_COPY, chunk, length);
-#endif
     }
   else
     {
       if (EPC_DEBUG_LEVEL (1))
         g_debug ("%s: done", G_STRLOC);
 
-#ifdef HAVE_LIBSOUP22
-      soup_message_add_final_chunk (message);
-#else
       soup_message_body_complete (message->response_body);
-#endif
     }
 }
 
@@ -485,26 +455,14 @@ epc_publisher_untrack_client (EpcPublisher *self,
 }
 
 static void
-#ifdef HAVE_LIBSOUP22
-epc_publisher_handle_contents (SoupServerContext *context,
-                               SoupMessage       *message,
-                               gpointer           data)
-#else
 epc_publisher_handle_contents (SoupServer        *server,
                                SoupMessage       *message,
                                const gchar       *path,
                                GHashTable        *query G_GNUC_UNUSED,
                                SoupClientContext *context,
                                gpointer           data)
-#endif
 {
-#ifdef HAVE_LIBSOUP22
-  SoupServer *server = context->server;
-  SoupSocket *socket = context->sock;
-  const gchar *path = context->path;
-#else
   GSocket *socket = soup_client_context_get_gsocket (context);
-#endif
 
   EpcPublisher *self = EPC_PUBLISHER (data);
   EpcResource *resource = NULL;
@@ -514,11 +472,7 @@ epc_publisher_handle_contents (SoupServer        *server,
   if (EPC_DEBUG_LEVEL (1))
     g_debug ("%s: method=%s, path=%s", G_STRFUNC, message->method, path);
 
-#ifdef HAVE_LIBSOUP22
-  if (SOUP_METHOD_ID_GET != context->method_id)
-#else
   if (SOUP_METHOD_GET != message->method)
-#endif
     {
       soup_message_set_status (message, SOUP_STATUS_METHOD_NOT_ALLOWED);
       return;
@@ -555,11 +509,7 @@ epc_publisher_handle_contents (SoupServer        *server,
           g_signal_connect (message, "wrote-chunk", G_CALLBACK (epc_publisher_chunk_cb), contents);
           g_signal_connect (message, "wrote-headers", G_CALLBACK (epc_publisher_chunk_cb), contents);
 
-#ifdef HAVE_LIBSOUP22
-          soup_server_message_set_encoding (SOUP_SERVER_MESSAGE (message), SOUP_TRANSFER_CHUNKED);
-#else
           soup_message_headers_set_encoding (message->response_headers, SOUP_ENCODING_CHUNKED);
-#endif
           soup_message_set_status (message, SOUP_STATUS_OK);
         }
 
@@ -570,26 +520,14 @@ epc_publisher_handle_contents (SoupServer        *server,
 }
 
 static void
-#ifdef HAVE_LIBSOUP22
-epc_publisher_handle_list (SoupServerContext *context,
-                           SoupMessage       *message,
-                           gpointer           data)
-#else
 epc_publisher_handle_list (SoupServer        *server,
                            SoupMessage       *message,
                            const char        *path,
                            GHashTable        *query G_GNUC_UNUSED,
                            SoupClientContext *context,
                            gpointer           data)
-#endif
 {
-#ifdef HAVE_LIBSOUP22
-  SoupServer *server = context->server;
-  SoupSocket *socket = context->sock;
-  const gchar *path = context->path;
-#else
   GSocket *socket = soup_client_context_get_gsocket (context);
-#endif
 
   const gchar *pattern = NULL;
   EpcPublisher *self = data;
@@ -632,26 +570,14 @@ epc_publisher_handle_list (SoupServer        *server,
 }
 
 static void
-#ifdef HAVE_LIBSOUP22
-epc_publisher_handle_root (SoupServerContext *context,
-                           SoupMessage       *message,
-                           gpointer           data)
-#else
 epc_publisher_handle_root (SoupServer        *server,
                            SoupMessage       *message,
                            const char        *path,
                            GHashTable        *query G_GNUC_UNUSED,
                            SoupClientContext *context,
                            gpointer           data)
-#endif
 {
-#ifdef HAVE_LIBSOUP22
-  SoupServer *server = context->server;
-  SoupSocket *socket = context->sock;
-  const gchar *path = context->path;
-#else
   GSocket *socket = soup_client_context_get_gsocket (context);
-#endif
 
   EpcPublisher *self = data;
 
@@ -732,18 +658,11 @@ epc_publisher_handle_root (SoupServer        *server,
 }
 
 static void
-#ifdef HAVE_LIBSOUP22
-epc_auth_context_init (EpcAuthContext *context,
-                       EpcPublisher   *publisher,
-                       SoupMessage    *message,
-                       SoupServerAuth *auth)
-#else
 epc_auth_context_init (EpcAuthContext *context,
                        EpcPublisher   *publisher,
                        SoupMessage    *message,
                        const gchar    *username,
                        const gchar    *password)
-#endif
 {
   const SoupURI *uri = soup_message_get_uri (message);
 
@@ -751,13 +670,9 @@ epc_auth_context_init (EpcAuthContext *context,
   context->key = epc_publisher_get_key (uri->path);
   context->resource = NULL;
 
-#ifdef HAVE_LIBSOUP22
-  context->auth = auth;
-#else
   context->message  = message;
   context->username = username;
   context->password = password;
-#endif
 
   if (context->key)
     context->resource = g_hash_table_lookup (publisher->priv->resources, context->key);
@@ -765,40 +680,6 @@ epc_auth_context_init (EpcAuthContext *context,
     context->resource = publisher->priv->default_resource;
 }
 
-#ifdef HAVE_LIBSOUP22
-
-static gboolean
-epc_publisher_server_auth_cb (SoupServerAuthContext *auth_ctx G_GNUC_UNUSED,
-                              SoupServerAuth        *auth,
-                              SoupMessage           *message,
-                              gpointer               data)
-{
-  gboolean authorized = TRUE;
-  const char *user = NULL;
-  EpcAuthContext context;
-
-  g_rec_mutex_lock (&epc_publisher_lock);
-  epc_auth_context_init (&context, EPC_PUBLISHER (data), message, auth);
-
-  if (NULL != auth)
-    user = soup_server_auth_get_user (auth);
-
-  if (context.resource && context.resource->auth_handler)
-    authorized = context.resource->auth_handler (&context, user,
-                                                 context.resource->auth_user_data);
-
-  if (EPC_DEBUG_LEVEL (1))
-    g_debug ("%s: key=%s, resource=%p, auth_handler=%p, authorized=%d", G_STRLOC,
-             context.key, context.resource, context.resource ? context.resource->auth_handler : NULL,
-             authorized);
-
-  g_rec_mutex_unlock (&epc_publisher_lock);
-
-  return authorized;
-}
-
-#else
-
 static gboolean
 epc_publisher_auth_filter (SoupAuthDomain *domain G_GNUC_UNUSED,
                            SoupMessage    *message,
@@ -872,20 +753,12 @@ epc_publisher_generic_auth_cb (SoupAuthDomain *domain G_GNUC_UNUSED,
   return authorized;
 }
 
-#endif
-
 static void
 epc_publisher_init (EpcPublisher *self)
 {
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EPC_TYPE_PUBLISHER, EpcPublisherPrivate);
   self->priv->protocol = EPC_PROTOCOL_HTTPS;
 
-#ifdef HAVE_LIBSOUP22
-  self->priv->server_auth.types = SOUP_AUTH_TYPE_DIGEST;
-  self->priv->server_auth.callback = epc_publisher_server_auth_cb;
-  self->priv->server_auth.user_data = self;
-#endif
-
   self->priv->resources = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                  g_free, epc_resource_free);
   self->priv->clients = g_hash_table_new_full (g_direct_hash, g_direct_equal,
@@ -1136,16 +1009,11 @@ epc_publisher_compute_name (EpcPublisher *self)
 static void
 epc_publisher_remove_handlers (EpcPublisher *self)
 {
-#ifdef HAVE_LIBSOUP22
-  memset (&self->priv->server_auth.digest_info, 0,
-          sizeof self->priv->server_auth.digest_info);
-#else
   if (self->priv->server_auth)
     {
       soup_server_remove_auth_domain (self->priv->server, self->priv->server_auth);
       self->priv->server_auth = NULL;
     }
-#endif
 
   if (self->priv->server)
     {
@@ -1160,39 +1028,13 @@ epc_publisher_add_server_callback (EpcPublisher       *self,
                                    const gchar        *path,
                                    SoupServerCallback  callback)
 {
-#ifdef HAVE_LIBSOUP22
-  soup_server_add_handler (self->priv->server, path,
-                           &self->priv->server_auth,
-                           callback, NULL, self);
-#else
   soup_server_add_handler (self->priv->server, path,
                            callback, self, NULL);
-#endif
 }
 
 static void
 epc_publisher_install_handlers (EpcPublisher *self)
 {
-#ifdef HAVE_LIBSOUP22
-
-  memset (&self->priv->server_auth.digest_info, 0,
-          sizeof self->priv->server_auth.digest_info);
-
-  switch (self->priv->server_auth.types)
-    {
-      case SOUP_AUTH_TYPE_BASIC:
-        self->priv->server_auth.basic_info.realm = self->priv->service_name;
-        break;
-
-      case SOUP_AUTH_TYPE_DIGEST:
-        self->priv->server_auth.digest_info.realm = self->priv->service_name;
-        self->priv->server_auth.digest_info.allow_algorithms = SOUP_ALGORITHM_MD5;
-        self->priv->server_auth.digest_info.force_integrity = FALSE; /* not implemented */
-        break;
-    }
-
-#else
-
   g_assert (NULL == self->priv->server_auth);
 
   if (self->priv->auth_flags & EPC_AUTH_PASSWORD_TEXT_NEEDED)
@@ -1230,8 +1072,6 @@ epc_publisher_install_handlers (EpcPublisher *self)
 
   soup_server_add_auth_domain (self->priv->server, self->priv->server_auth);
 
-#endif
-
   epc_publisher_add_server_callback (self, self->priv->contents_path, epc_publisher_handle_contents);
   epc_publisher_add_server_callback (self, "/list", epc_publisher_handle_list);
   epc_publisher_add_server_callback (self, "/", epc_publisher_handle_root);
@@ -1365,13 +1205,7 @@ epc_publisher_real_set_auth_flags (EpcPublisher *self,
   if (self->priv->server)
     epc_publisher_remove_handlers (self);
 
-#ifdef HAVE_LIBSOUP22
-  self->priv->server_auth.types =
-    flags & EPC_AUTH_PASSWORD_TEXT_NEEDED ?
-    SOUP_AUTH_TYPE_BASIC : SOUP_AUTH_TYPE_DIGEST;
-#else
   self->priv->auth_flags = flags;
-#endif
 
   if (self->priv->server)
     epc_publisher_install_handlers (self);
@@ -2537,9 +2371,6 @@ epc_publisher_run_async (EpcPublisher  *self,
       /* 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
       self->priv->server_started = TRUE;
     }
 
@@ -2818,19 +2649,7 @@ epc_auth_context_get_password (const EpcAuthContext *context)
 {
   g_return_val_if_fail (NULL != context, NULL);
 
-#ifdef HAVE_LIBSOUP22
-
-  if (NULL != context->auth &&
-      SOUP_AUTH_TYPE_BASIC == context->auth->type)
-    return context->auth->basic.passwd;
-
-  return NULL;
-
-#else
-
   return context->password;
-
-#endif
 }
 
 /**
@@ -2852,19 +2671,9 @@ epc_auth_context_check_password (const EpcAuthContext *context,
   g_return_val_if_fail (NULL != context, FALSE);
   g_return_val_if_fail (NULL != password, FALSE);
 
-#ifdef HAVE_LIBSOUP22
-
-  return
-    NULL != context->auth &&
-    soup_server_auth_check_passwd (context->auth, (gchar*) password);
-
-#else
-
   return soup_auth_domain_check_password (context->publisher->priv->server_auth,
                                           context->message, context->username,
                                           password);
-
-#endif
 }
 
 /* vim: set sw=2 sta et spl=en spell: */


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