[libsoup/carlosgc/message-flags: 4/7] Use the new SoupMessage flags API




commit bbb6044101a1354e97cb87f845c11cf89ca1cf10
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Fri Nov 6 14:00:36 2020 +0100

    Use the new SoupMessage flags API

 libsoup/auth/soup-auth-manager.c                 | 24 ++++++++++--------------
 libsoup/content-sniffer/soup-converter-wrapper.c |  3 +--
 libsoup/soup-session.c                           | 16 +++++++---------
 tests/auth-test.c                                | 19 ++++++-------------
 tests/connection-test.c                          |  4 +---
 tests/hsts-db-test.c                             |  2 +-
 tests/hsts-test.c                                |  2 +-
 7 files changed, 27 insertions(+), 43 deletions(-)
---
diff --git a/libsoup/auth/soup-auth-manager.c b/libsoup/auth/soup-auth-manager.c
index 40fae627..9b3bde9c 100644
--- a/libsoup/auth/soup-auth-manager.c
+++ b/libsoup/auth/soup-auth-manager.c
@@ -476,7 +476,7 @@ lookup_auth (SoupAuthManagerPrivate *priv, SoupMessage *msg)
        if (auth && soup_auth_is_ready (auth, msg))
                return auth;
 
-       if (soup_message_get_flags (msg) & SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE)
+       if (soup_message_query_flags (msg, SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE))
                return NULL;
 
        uri = soup_message_get_uri_for_auth (msg);
@@ -515,7 +515,7 @@ lookup_proxy_auth (SoupAuthManagerPrivate *priv, SoupMessage *msg)
        if (auth && soup_auth_is_ready (auth, msg))
                return auth;
 
-       if (soup_message_get_flags (msg) & SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE)
+       if (soup_message_query_flags (msg, SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE))
                return NULL;
 
        return priv->proxy_auth;
@@ -651,7 +651,7 @@ auth_got_headers (SoupMessage *msg, gpointer manager)
                }
        }
 
-       if (!(soup_message_get_flags (msg) & SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE)) {
+       if (!soup_message_query_flags (msg, SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE)) {
                SoupAuth *new_auth;
 
                new_auth = record_auth_for_uri (priv, soup_message_get_uri_for_auth (msg),
@@ -677,17 +677,13 @@ auth_got_body (SoupMessage *msg, gpointer manager)
        g_mutex_lock (&priv->lock);
        auth = lookup_auth (priv, msg);
        if (auth && soup_auth_is_ready (auth, msg)) {
-               if (SOUP_IS_CONNECTION_AUTH (auth)) {
-                       SoupMessageFlags flags;
-
-                       flags = soup_message_get_flags (msg);
-                       soup_message_set_flags (msg, flags & ~SOUP_MESSAGE_NEW_CONNECTION);
-               }
+               if (SOUP_IS_CONNECTION_AUTH (auth))
+                       soup_message_remove_flags (msg, SOUP_MESSAGE_NEW_CONNECTION);
 
                /* When not using cached credentials, update the Authorization header
                 * right before requeuing the message.
                 */
-               if (soup_message_get_flags (msg) & SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE)
+               if (soup_message_query_flags (msg, SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE))
                        update_authorization_header (msg, auth, FALSE);
 
                soup_session_requeue_message (priv->session, msg);
@@ -711,7 +707,7 @@ proxy_auth_got_headers (SoupMessage *msg, gpointer manager)
                        prior_auth_failed = TRUE;
        }
 
-       if (!(soup_message_get_flags (msg) & SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE))
+       if (!soup_message_query_flags (msg, SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE))
                auth = priv->proxy_auth ? g_object_ref (priv->proxy_auth) : NULL;
 
        if (!auth) {
@@ -720,7 +716,7 @@ proxy_auth_got_headers (SoupMessage *msg, gpointer manager)
                        g_mutex_unlock (&priv->lock);
                        return;
                }
-               if (!(soup_message_get_flags (msg) & SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE))
+               if (!soup_message_query_flags (msg, SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE))
                        priv->proxy_auth = g_object_ref (auth);
        }
 
@@ -745,7 +741,7 @@ proxy_auth_got_body (SoupMessage *msg, gpointer manager)
                /* When not using cached credentials, update the Authorization header
                 * right before requeuing the message.
                 */
-               if (soup_message_get_flags (msg) & SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE)
+               if (soup_message_query_flags (msg, SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE))
                        update_authorization_header (msg, auth, TRUE);
                soup_session_requeue_message (priv->session, msg);
        }
@@ -759,7 +755,7 @@ auth_msg_starting (SoupMessage *msg, gpointer manager)
         SoupAuthManagerPrivate *priv = soup_auth_manager_get_instance_private (manager);
        SoupAuth *auth;
 
-       if (soup_message_get_flags (msg) & SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE)
+       if (soup_message_query_flags (msg, SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE))
                return;
 
        g_mutex_lock (&priv->lock);
diff --git a/libsoup/content-sniffer/soup-converter-wrapper.c 
b/libsoup/content-sniffer/soup-converter-wrapper.c
index 72e459cc..b84e4a02 100644
--- a/libsoup/content-sniffer/soup-converter-wrapper.c
+++ b/libsoup/content-sniffer/soup-converter-wrapper.c
@@ -250,8 +250,7 @@ soup_converter_wrapper_real_convert (GConverter *converter,
                                      &my_error);
        if (result != G_CONVERTER_ERROR) {
                if (!priv->started) {
-                       SoupMessageFlags message_flags = soup_message_get_flags (priv->msg);
-                       soup_message_set_flags (priv->msg, message_flags | SOUP_MESSAGE_CONTENT_DECODED);
+                       soup_message_add_flags (priv->msg, SOUP_MESSAGE_CONTENT_DECODED);
                        priv->started = TRUE;
                }
 
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 8379cd48..e427ffa4 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -934,7 +934,7 @@ soup_session_append_queue_item (SoupSession        *session,
        host->num_messages++;
        g_mutex_unlock (&priv->conn_lock);
 
-       if (!(soup_message_get_flags (msg) & SOUP_MESSAGE_NO_REDIRECT)) {
+       if (!soup_message_query_flags (msg, SOUP_MESSAGE_NO_REDIRECT)) {
                soup_message_add_header_handler (
                        msg, "got_body", "Location",
                        G_CALLBACK (redirect_handler), item);
@@ -1380,7 +1380,7 @@ tunnel_connect (SoupMessageQueueItem *item)
 
        uri = soup_connection_get_remote_uri (item->conn);
        msg = soup_message_new_from_uri (SOUP_METHOD_CONNECT, uri);
-       soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
+       soup_message_add_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
 
        tunnel_item = soup_session_append_queue_item (session, msg,
                                                      item->async,
@@ -1546,11 +1546,11 @@ get_connection (SoupMessageQueueItem *item, gboolean *should_cleanup)
        soup_session_cleanup_connections (session, FALSE);
 
        need_new_connection =
-               (soup_message_get_flags (item->msg) & SOUP_MESSAGE_NEW_CONNECTION) ||
-               (!(soup_message_get_flags (item->msg) & SOUP_MESSAGE_IDEMPOTENT) &&
+               (soup_message_query_flags (item->msg, SOUP_MESSAGE_NEW_CONNECTION)) ||
+               (!soup_message_query_flags (item->msg, SOUP_MESSAGE_IDEMPOTENT) &&
                 !SOUP_METHOD_IS_IDEMPOTENT (soup_message_get_method (item->msg)));
        ignore_connection_limits =
-               (soup_message_get_flags (item->msg) & SOUP_MESSAGE_IGNORE_CONNECTION_LIMITS);
+                soup_message_query_flags (item->msg, SOUP_MESSAGE_IGNORE_CONNECTION_LIMITS);
 
        g_mutex_lock (&priv->conn_lock);
        host = get_host_for_message (session, item->msg);
@@ -2687,7 +2687,7 @@ expected_to_be_requeued (SoupSession *session, SoupMessage *msg)
                return !feature || !soup_message_disables_feature (msg, feature);
        }
 
-       if (!(soup_message_get_flags (msg) & SOUP_MESSAGE_NO_REDIRECT))
+       if (!soup_message_query_flags (msg, SOUP_MESSAGE_NO_REDIRECT))
                return soup_session_would_redirect (session, msg);
 
        return FALSE;
@@ -3978,7 +3978,6 @@ soup_session_websocket_connect_async (SoupSession          *session,
        SoupMessageQueueItem *item;
        GTask *task;
        GPtrArray *supported_extensions;
-       SoupMessageFlags flags;
 
        g_return_if_fail (SOUP_IS_SESSION (session));
        g_return_if_fail (SOUP_IS_MESSAGE (msg));
@@ -3992,8 +3991,7 @@ soup_session_websocket_connect_async (SoupSession          *session,
         * the case of web browsers, it MUST open a connection, send an opening
         * handshake, and read the server's handshake in response.
         */
-       flags = soup_message_get_flags (msg);
-       soup_message_set_flags (msg, flags | SOUP_MESSAGE_NEW_CONNECTION);
+       soup_message_add_flags (msg, SOUP_MESSAGE_NEW_CONNECTION);
 
        task = g_task_new (session, cancellable, callback, user_data);
        item = soup_session_append_queue_item (session, msg, TRUE,
diff --git a/tests/auth-test.c b/tests/auth-test.c
index 2d94c4ad..94a521ec 100644
--- a/tests/auth-test.c
+++ b/tests/auth-test.c
@@ -431,11 +431,9 @@ do_digest_nonce_test (SoupSession *session,
        gboolean got_401;
 
        msg = soup_message_new (SOUP_METHOD_GET, uri);
-       if (!use_auth_cache) {
-               SoupMessageFlags flags = soup_message_get_flags (msg);
+       if (!use_auth_cache)
+               soup_message_add_flags (msg, SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE);
 
-               soup_message_set_flags (msg, flags | SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE);
-       }
        if (expect_signal) {
                g_signal_connect (msg, "authenticate",
                                  G_CALLBACK (digest_nonce_authenticate),
@@ -1340,7 +1338,6 @@ do_message_do_not_use_auth_cache_test (void)
        SoupSession *session;
        SoupAuthManager *manager;
        SoupMessage *msg;
-       SoupMessageFlags flags;
        SoupURI *soup_uri;
        char *uri;
 
@@ -1362,8 +1359,7 @@ do_message_do_not_use_auth_cache_test (void)
        soup_uri_set_user (soup_uri, "user1");
        soup_uri_set_password (soup_uri, "realm1");
        msg = soup_message_new_from_uri (SOUP_METHOD_GET, soup_uri);
-       flags = soup_message_get_flags (msg);
-       soup_message_set_flags (msg, flags | SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE);
+       soup_message_add_flags (msg, SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE);
        soup_test_session_send_message (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_object_unref (msg);
@@ -1382,8 +1378,7 @@ do_message_do_not_use_auth_cache_test (void)
         * and we don't have the authenticate signal, it should respond with 401
         */
        msg = soup_message_new (SOUP_METHOD_GET, uri);
-       flags = soup_message_get_flags (msg);
-       soup_message_set_flags (msg, flags | SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE);
+       soup_message_add_flags (msg, SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE);
        soup_test_session_send_message (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_UNAUTHORIZED);
        g_object_unref (msg);
@@ -1421,7 +1416,6 @@ do_async_message_do_not_use_auth_cache_test (void)
        SoupMessage *msg;
        char *uri;
        SoupAuth *auth = NULL;
-       SoupMessageFlags flags;
 
        SOUP_TEST_SKIP_IF_NO_APACHE;
 
@@ -1433,8 +1427,7 @@ do_async_message_do_not_use_auth_cache_test (void)
        g_free (uri);
        g_signal_connect (msg, "authenticate",
                          G_CALLBACK (async_no_auth_cache_authenticate), &auth);
-       flags = soup_message_get_flags (msg);
-       soup_message_set_flags (msg, flags | SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE);
+       soup_message_add_flags (msg, SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE);
        g_signal_connect (msg, "finished",
                          G_CALLBACK (async_no_auth_cache_finished), NULL);
        soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL);
@@ -1518,7 +1511,7 @@ do_message_has_authorization_header_test (void)
        soup_auth_manager_clear_cached_credentials (manager);
        msg = soup_message_new ("GET", uri);
        soup_message_headers_replace (soup_message_get_request_headers (msg), "Authorization", token);
-       soup_message_set_flags (msg, soup_message_get_flags (msg) | SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE);
+       soup_message_add_flags (msg, SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE);
        soup_test_session_send_message (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_object_unref (msg);
diff --git a/tests/connection-test.c b/tests/connection-test.c
index 9f5e0a17..455308c4 100644
--- a/tests/connection-test.c
+++ b/tests/connection-test.c
@@ -463,7 +463,6 @@ static void
 do_max_conns_test_for_session (SoupSession *session)
 {
        SoupMessage *msgs[TEST_CONNS + 1];
-       SoupMessageFlags flags;
        int i;
 
        max_conns_loop = g_main_loop_new (NULL, TRUE);
@@ -492,8 +491,7 @@ do_max_conns_test_for_session (SoupSession *session)
 
        /* Message with SOUP_MESSAGE_IGNORE_CONNECTION_LIMITS should start */
        msgs[i] = soup_message_new_from_uri ("GET", base_uri);
-       flags = soup_message_get_flags (msgs[i]);
-       soup_message_set_flags (msgs[i], flags | SOUP_MESSAGE_IGNORE_CONNECTION_LIMITS);
+       soup_message_add_flags (msgs[i], SOUP_MESSAGE_IGNORE_CONNECTION_LIMITS);
        g_signal_connect (msgs[i], "finished",
                          G_CALLBACK (max_conns_message_complete), NULL);
        soup_session_send_async (session, msgs[i], G_PRIORITY_DEFAULT, NULL, NULL, NULL);
diff --git a/tests/hsts-db-test.c b/tests/hsts-db-test.c
index b6e7e364..f69d9267 100644
--- a/tests/hsts-db-test.c
+++ b/tests/hsts-db-test.c
@@ -67,7 +67,7 @@ session_get_uri (SoupSession *session, const char *uri, SoupStatus expected_stat
         GBytes *body;
 
        msg = soup_message_new ("GET", uri);
-       soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
+       soup_message_add_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
        body = soup_test_session_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, expected_status);
         g_bytes_unref (body);
diff --git a/tests/hsts-test.c b/tests/hsts-test.c
index c8b9342b..1dbd71cb 100644
--- a/tests/hsts-test.c
+++ b/tests/hsts-test.c
@@ -113,7 +113,7 @@ session_get_uri (SoupSession *session, const char *uri, SoupStatus expected_stat
        GBytes *body;
 
        msg = soup_message_new ("GET", uri);
-       soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
+       soup_message_add_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
        body = soup_test_session_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, expected_status);
        g_bytes_unref (body);


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