[libsoup] Make SoupHSTSPolicy a private struct



commit 9a4bc84bb7572294ae74df246358181d07d4b37c
Author: Patrick Griffis <pgriffis igalia com>
Date:   Wed Oct 28 13:10:10 2020 -0500

    Make SoupHSTSPolicy a private struct

 libsoup/hsts/soup-hsts-enforcer-db.c | 14 ++++++-------
 libsoup/hsts/soup-hsts-policy.c      | 39 ++++++++++++++++++++++++++++++++++++
 libsoup/hsts/soup-hsts-policy.h      | 13 ++++++------
 tests/hsts-test.c                    |  8 ++++----
 4 files changed, 57 insertions(+), 17 deletions(-)
---
diff --git a/libsoup/hsts/soup-hsts-enforcer-db.c b/libsoup/hsts/soup-hsts-enforcer-db.c
index d6024452..4e5e7580 100644
--- a/libsoup/hsts/soup-hsts-enforcer-db.c
+++ b/libsoup/hsts/soup-hsts-enforcer-db.c
@@ -267,23 +267,23 @@ soup_hsts_enforcer_db_changed (SoupHSTSEnforcer *hsts_enforcer,
 
        if (old_policy && !new_policy) {
                query = sqlite3_mprintf (QUERY_DELETE,
-                                        old_policy->domain);
+                                        soup_hsts_policy_get_domain (old_policy));
                g_assert (query);
                exec_query_with_try_create_table (priv->db, query, NULL, NULL);
                sqlite3_free (query);
        }
 
        /* Insert the new policy or update the existing one. */
-       if (new_policy && new_policy->expires) {
+       if (new_policy && soup_hsts_policy_get_expires (new_policy)) {
                gulong expires;
 
-               expires = (gulong)g_date_time_to_unix (new_policy->expires);
+               expires = (gulong)g_date_time_to_unix (soup_hsts_policy_get_expires (new_policy));
                query = sqlite3_mprintf (QUERY_INSERT,
-                                        new_policy->domain,
-                                        new_policy->domain,
-                                        new_policy->max_age,
+                                        soup_hsts_policy_get_domain (new_policy),
+                                        soup_hsts_policy_get_domain (new_policy),
+                                        soup_hsts_policy_get_max_age (new_policy),
                                         expires,
-                                        new_policy->include_subdomains);
+                                        soup_hsts_policy_includes_subdomains (new_policy));
                g_assert (query);
                exec_query_with_try_create_table (priv->db, query, NULL, NULL);
                sqlite3_free (query);
diff --git a/libsoup/hsts/soup-hsts-policy.c b/libsoup/hsts/soup-hsts-policy.c
index b1895981..0399db48 100644
--- a/libsoup/hsts/soup-hsts-policy.c
+++ b/libsoup/hsts/soup-hsts-policy.c
@@ -56,6 +56,13 @@
  * Since: 2.68
  **/
 
+struct _SoupHSTSPolicy {
+       char                 *domain;
+       unsigned long         max_age;
+       GDateTime            *expires;
+       gboolean              include_subdomains;
+};
+
 G_DEFINE_BOXED_TYPE (SoupHSTSPolicy, soup_hsts_policy, soup_hsts_policy_copy, soup_hsts_policy_free)
 
 /**
@@ -387,6 +394,38 @@ soup_hsts_policy_is_session_policy (SoupHSTSPolicy *policy)
        return !policy->expires;
 }
 
+/**
+ * soup_hsts_policy_get_expires:
+ * @policy: a #SoupHSTSPolicy
+ *
+ * Returns the expiration date for @policy.
+ *
+ * Returns: A #GDateTime or %NULL if unset
+ */
+GDateTime *
+soup_hsts_policy_get_expires (SoupHSTSPolicy *policy)
+{
+        g_return_val_if_fail (policy != NULL, NULL);
+
+        return policy->expires;
+}
+
+/**
+ * soup_hsts_policy_get_max_age:
+ * @policy: a #SoupHSTSPolicy
+ *
+ * Returns the max age for @policy.
+ *
+ * Returns: Max age in seconds
+ */
+gulong
+soup_hsts_policy_get_max_age (SoupHSTSPolicy *policy)
+{
+        g_return_val_if_fail (policy != NULL, 0);
+
+        return policy->max_age;
+}
+
 /**
  * soup_hsts_policy_free:
  * @policy: (transfer full): a #SoupHSTSPolicy
diff --git a/libsoup/hsts/soup-hsts-policy.h b/libsoup/hsts/soup-hsts-policy.h
index 4879f282..4ddc1451 100644
--- a/libsoup/hsts/soup-hsts-policy.h
+++ b/libsoup/hsts/soup-hsts-policy.h
@@ -10,12 +10,7 @@
 
 G_BEGIN_DECLS
 
-struct _SoupHSTSPolicy {
-       char                 *domain;
-       unsigned long         max_age;
-       GDateTime            *expires;
-       gboolean              include_subdomains;
-};
+typedef struct _SoupHSTSPolicy SoupHSTSPolicy;
 
 SOUP_AVAILABLE_IN_2_68
 GType           soup_hsts_policy_get_type (void);
@@ -55,6 +50,12 @@ gboolean      soup_hsts_policy_is_session_policy     (SoupHSTSPolicy *policy);
 SOUP_AVAILABLE_IN_2_68
 void            soup_hsts_policy_free                  (SoupHSTSPolicy *policy);
 
+SOUP_AVAILABLE_IN_ALL
+GDateTime       *soup_hsts_policy_get_expires           (SoupHSTSPolicy *policy);
+
+SOUP_AVAILABLE_IN_ALL
+gulong           soup_hsts_policy_get_max_age           (SoupHSTSPolicy *policy);
+
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (SoupHSTSPolicy, soup_hsts_policy_free)
 
 G_END_DECLS
diff --git a/tests/hsts-test.c b/tests/hsts-test.c
index 2a87293b..bc9a10d0 100644
--- a/tests/hsts-test.c
+++ b/tests/hsts-test.c
@@ -449,9 +449,9 @@ on_idna_test_enforcer_changed (SoupHSTSEnforcer *enforcer, SoupHSTSPolicy *old,
        /* If NULL, then instead of replacing we're adding a new
         * policy and somewhere we're failing to canonicalize a hostname. */
        g_assert_nonnull (old);
-       g_assert_cmpstr (old->domain, ==, new->domain);
+       g_assert_cmpstr (soup_hsts_policy_get_domain (old), ==, soup_hsts_policy_get_domain (new));
        /*  Domains should not have punycoded segments at this point. */
-       g_assert_false (g_hostname_is_ascii_encoded (old->domain));
+       g_assert_false (g_hostname_is_ascii_encoded (soup_hsts_policy_get_domain (old)));
 }
 
 static void
@@ -543,7 +543,7 @@ do_hsts_get_policies_test (void)
        g_assert_nonnull (policies);
        g_assert_cmpint (g_list_length (policies), ==, 1);
        policy = (SoupHSTSPolicy*)policies->data;
-       g_assert_cmpstr (policy->domain, ==, "gnome.org");
+       g_assert_cmpstr (soup_hsts_policy_get_domain (policy), ==, "gnome.org");
        g_list_free_full (policies, (GDestroyNotify)soup_hsts_policy_free);
 
        policy = soup_hsts_policy_new ("gnome.org", SOUP_HSTS_POLICY_MAX_AGE_PAST, FALSE);
@@ -553,7 +553,7 @@ do_hsts_get_policies_test (void)
        policies = soup_hsts_enforcer_get_policies (enforcer, TRUE);
        g_assert_cmpint (g_list_length (policies), ==, 1);
        policy = (SoupHSTSPolicy*)policies->data;
-       g_assert_cmpstr (policy->domain, ==, "freedesktop.org");
+       g_assert_cmpstr (soup_hsts_policy_get_domain (policy), ==, "freedesktop.org");
        g_list_free_full (policies, (GDestroyNotify)soup_hsts_policy_free);
        g_object_unref(enforcer);
 }


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