[libsoup/hsts] Add SoupHSTSEnforcer:hsts-enforced signal



commit a146a199d1163dc3b3f2983806ef05e219ce907a
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Fri Dec 14 15:01:17 2018 +0200

    Add SoupHSTSEnforcer:hsts-enforced signal
    
    After working on the HSTS feature for WebKit it became obvious
    that relying on the SoupMessage::uri property changes is far from
    ideal. So let's add a signal that will be emitted whenever the
    enforcer does its thing wih a SoupMessage.

 libsoup/soup-hsts-enforcer.c | 21 +++++++++++++++++++++
 libsoup/soup-hsts-enforcer.h |  3 +++
 2 files changed, 24 insertions(+)
---
diff --git a/libsoup/soup-hsts-enforcer.c b/libsoup/soup-hsts-enforcer.c
index 01a7bab9..033d363c 100644
--- a/libsoup/soup-hsts-enforcer.c
+++ b/libsoup/soup-hsts-enforcer.c
@@ -46,6 +46,7 @@ static void soup_hsts_enforcer_session_feature_init (SoupSessionFeatureInterface
 
 enum {
        CHANGED,
+       HSTS_ENFORCED,
        LAST_SIGNAL
 };
 
@@ -169,6 +170,25 @@ soup_hsts_enforcer_class_init (SoupHSTSEnforcerClass *hsts_enforcer_class)
                              G_TYPE_NONE, 2,
                              SOUP_TYPE_HSTS_POLICY | G_SIGNAL_TYPE_STATIC_SCOPE,
                              SOUP_TYPE_HSTS_POLICY | G_SIGNAL_TYPE_STATIC_SCOPE);
+
+       /**
+        * SoupHSTSEnforcer::hsts-enforced:
+        * @hsts_enforcer: the #SoupHSTSEnforcer
+        * @message: the message for which HSTS is being enforced
+        *
+        * Emitted when @hsts_enforcer has upgraded the protocol
+        * for @message to HTTPS as a result of matching its domain with
+        * a HSTS policy.
+        **/
+       signals[HSTS_ENFORCED] =
+               g_signal_new ("hsts-enforced",
+                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_SIGNAL_RUN_FIRST,
+                             G_STRUCT_OFFSET (SoupHSTSEnforcerClass, hsts_enforced),
+                             NULL, NULL,
+                             NULL,
+                             G_TYPE_NONE, 1,
+                             SOUP_TYPE_MESSAGE);
 }
 
 /**
@@ -514,6 +534,7 @@ preprocess_request (SoupHSTSEnforcer *enforcer, SoupMessage *msg)
                        g_signal_connect (msg, "starting",
                                          G_CALLBACK (on_sts_known_host_message_starting),
                                          enforcer);
+                       g_signal_emit (enforcer, signals[HSTS_ENFORCED], 0, msg);
                }
                g_free (canonicalized);
        } else if (scheme == SOUP_URI_SCHEME_HTTPS) {
diff --git a/libsoup/soup-hsts-enforcer.h b/libsoup/soup-hsts-enforcer.h
index 9e108fc7..e2f915b1 100644
--- a/libsoup/soup-hsts-enforcer.h
+++ b/libsoup/soup-hsts-enforcer.h
@@ -49,6 +49,9 @@ typedef struct {
                         SoupHSTSPolicy   *old_policy,
                         SoupHSTSPolicy   *new_policy);
 
+       void (*hsts_enforced) (SoupHSTSEnforcer *enforcer,
+                              SoupMessage      *message);
+
        /* Padding for future expansion */
        void (*_libsoup_reserved1) (void);
        void (*_libsoup_reserved2) (void);


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