[gcr/wip/gcr4] gck: use the right namespace for GckUriData methods



commit 745eba242f37a27dc163d329e1b40330f5968e67
Author: Corentin Noël <corentin noel collabora com>
Date:   Wed Oct 6 18:35:29 2021 +0200

    gck: use the right namespace for GckUriData methods

 gck/gck-enumerator.c      |  2 +-
 gck/gck-modules.c         |  4 ++--
 gck/gck-uri.c             | 44 ++++++++++++--------------------------
 gck/gck-uri.h             |  4 ++--
 gck/test-gck-uri.c        | 54 +++++++++++++++++++++++------------------------
 gcr/gcr-pkcs11-importer.c |  4 ++--
 6 files changed, 47 insertions(+), 65 deletions(-)
---
diff --git a/gck/gck-enumerator.c b/gck/gck-enumerator.c
index 1647d8e..7819f10 100644
--- a/gck/gck-enumerator.c
+++ b/gck/gck-enumerator.c
@@ -686,7 +686,7 @@ created_enumerator (GckUriData *uri_data,
 {
        gchar *attrs, *uri;
        attrs = uri_data->attributes ? gck_attributes_to_string (uri_data->attributes) : NULL;
-       uri = uri_data ? gck_uri_build (uri_data, GCK_URI_FOR_TOKEN | GCK_URI_FOR_MODULE) : NULL;
+       uri = uri_data ? gck_uri_data_build (uri_data, GCK_URI_FOR_TOKEN | GCK_URI_FOR_MODULE) : NULL;
        g_debug ("for = %s, tokens = %s, objects = %s", type, uri, attrs);
        g_free (attrs);
        g_free (uri);
diff --git a/gck/gck-modules.c b/gck/gck-modules.c
index 2971451..7957204 100644
--- a/gck/gck-modules.c
+++ b/gck/gck-modules.c
@@ -233,7 +233,7 @@ tokens_for_uri (GList *modules,
        GckUriFlags flags;
 
        flags = GCK_URI_FOR_OBJECT_ON_TOKEN_AND_MODULE | GCK_URI_FOR_MODULE_WITH_VERSION;
-       uri_data = gck_uri_parse (uri, flags, error);
+       uri_data = gck_uri_data_parse (uri, flags, error);
        if (uri_data == NULL)
                return NULL;
 
@@ -420,7 +420,7 @@ gck_modules_enumerate_uri (GList *modules,
 
        g_return_val_if_fail (uri != NULL, NULL);
 
-       uri_data = gck_uri_parse (uri, GCK_URI_FOR_ANY, error);
+       uri_data = gck_uri_data_parse (uri, GCK_URI_FOR_ANY, error);
        if (uri_data == NULL)
                return NULL;
 
diff --git a/gck/gck-uri.c b/gck/gck-uri.c
index 91d32c3..0d92d09 100644
--- a/gck/gck-uri.c
+++ b/gck/gck-uri.c
@@ -118,22 +118,6 @@
  * Error domain for URI errors.
  */
 
-/**
- * GCK_URI_BAD_PREFIX:
- *
- * Use %GCK_URI_BAD_SCHEME instead.
- *
- * Deprecated: Since 3.2
- */
-
-/**
- * CKR_GCK_MODULE_PROBLEM:
- *
- * Use %GCK_ERROR_MODULE_PROBLEM instead.
- *
- * Deprecated: Since 3.4
- */
-
 #define URI_PREFIX "pkcs11:"
 #define N_URI_PREFIX 7
 
@@ -158,11 +142,11 @@ G_DEFINE_QUARK(gck-uri-error, gck_uri_error)
 GckUriData *
 gck_uri_data_new (void)
 {
-       return g_slice_new0 (GckUriData);
+       return g_new0 (GckUriData, 1);
 }
 
 /**
- * gck_uri_parse:
+ * gck_uri_data_parse:
  * @string: the URI to parse.
  * @flags: the context in which the URI will be used.
  * @error: a #GError, or %NULL.
@@ -177,7 +161,7 @@ gck_uri_data_new (void)
  *          freed with gck_uri_data_free()
  */
 GckUriData*
-gck_uri_parse (const gchar *string, GckUriFlags flags, GError **error)
+gck_uri_data_parse (const gchar *string, GckUriFlags flags, GError **error)
 {
        GckUriData *uri_data = NULL;
        GckBuilder builder;
@@ -243,7 +227,7 @@ gck_uri_parse (const gchar *string, GckUriFlags flags, GError **error)
 }
 
 /**
- * gck_uri_build:
+ * gck_uri_data_build:
  * @uri_data: the info to build the URI from.
  * @flags: The context that the URI is for
  *
@@ -253,7 +237,7 @@ gck_uri_parse (const gchar *string, GckUriFlags flags, GError **error)
  * Return value: a newly allocated string containing a PKCS\#11 URI.
  */
 gchar*
-gck_uri_build (GckUriData *uri_data, GckUriFlags flags)
+gck_uri_data_build (GckUriData *uri_data, GckUriFlags flags)
 {
        const GckAttribute *attr;
        P11KitUri *p11_uri = 0;
@@ -317,20 +301,18 @@ gck_uri_data_copy (GckUriData *uri_data)
 
 /**
  * gck_uri_data_free:
- * @uri_data: URI data to free.
+ * @uri_data: (transfer full): URI data to free.
  *
  * Free a #GckUriData.
  */
 void
 gck_uri_data_free (GckUriData *uri_data)
 {
-       if (uri_data) {
-               if (uri_data->attributes)
-                       gck_attributes_unref (uri_data->attributes);
-               if (uri_data->module_info)
-                       gck_module_info_free (uri_data->module_info);
-               if (uri_data->token_info)
-                       gck_token_info_free (uri_data->token_info);
-               g_slice_free (GckUriData, uri_data);
-       }
+       if (!uri_data)
+               return;
+
+       g_clear_pointer (&uri_data->attributes, gck_attributes_unref);
+       g_clear_pointer (&uri_data->module_info, gck_module_info_free);
+       g_clear_pointer (&uri_data->token_info, gck_token_info_free);
+       g_free (uri_data);
 }
diff --git a/gck/gck-uri.h b/gck/gck-uri.h
index ce48edf..c014f8e 100644
--- a/gck/gck-uri.h
+++ b/gck/gck-uri.h
@@ -58,10 +58,10 @@ GQuark              gck_uri_error_quark                     (void) G_GNUC_CONST;
 
 GckUriData*         gck_uri_data_new                        (void);
 
-gchar*              gck_uri_build                           (GckUriData *uri_data,
+gchar*              gck_uri_data_build                      (GckUriData *uri_data,
                                                              GckUriFlags flags);
 
-GckUriData*         gck_uri_parse                           (const gchar *string,
+GckUriData*         gck_uri_data_parse                      (const gchar *string,
                                                              GckUriFlags flags,
                                                              GError **error);
 
diff --git a/gck/test-gck-uri.c b/gck/test-gck-uri.c
index 57adee9..1254fc9 100644
--- a/gck/test-gck-uri.c
+++ b/gck/test-gck-uri.c
@@ -37,7 +37,7 @@ test_parse (void)
        GError *error = NULL;
        GckUriData *uri_data;
 
-       uri_data = gck_uri_parse ("pkcs11:", GCK_URI_FOR_MODULE, &error);
+       uri_data = gck_uri_data_parse ("pkcs11:", GCK_URI_FOR_MODULE, &error);
        g_assert_nonnull (uri_data);
        g_assert_no_error (error);
 
@@ -57,7 +57,7 @@ test_parse_bad_scheme (void)
        GError *error = NULL;
        GckUriData *uri_data;
 
-       uri_data = gck_uri_parse ("http:\\example.com\test", GCK_URI_FOR_ANY, &error);
+       uri_data = gck_uri_data_parse ("http:\\example.com\test", GCK_URI_FOR_ANY, &error);
        g_assert_null (uri_data);
        g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_SCHEME);
        g_error_free (error);
@@ -70,7 +70,7 @@ test_parse_with_label (void)
        GckUriData *uri_data;
        gchar *value;
 
-       uri_data = gck_uri_parse ("pkcs11:object=Test%20Label", GCK_URI_FOR_ANY, &error);
+       uri_data = gck_uri_data_parse ("pkcs11:object=Test%20Label", GCK_URI_FOR_ANY, &error);
        g_assert_nonnull (uri_data);
        g_assert_nonnull (uri_data->attributes);
 
@@ -91,7 +91,7 @@ test_parse_with_label_and_klass (void)
        gchar *value;
        gulong klass;
 
-       uri_data = gck_uri_parse ("pkcs11:object=Test%20Label;objecttype=cert", GCK_URI_FOR_ANY, &error);
+       uri_data = gck_uri_data_parse ("pkcs11:object=Test%20Label;objecttype=cert", GCK_URI_FOR_ANY, &error);
        g_assert_nonnull (uri_data);
        g_assert_nonnull (uri_data->attributes);
 
@@ -115,7 +115,7 @@ test_parse_with_id (void)
        const GckAttribute *attr;
        GckUriData *uri_data;
 
-       uri_data = gck_uri_parse ("pkcs11:id=%54%45%53%54%00", GCK_URI_FOR_OBJECT, &error);
+       uri_data = gck_uri_data_parse ("pkcs11:id=%54%45%53%54%00", GCK_URI_FOR_OBJECT, &error);
        g_assert_nonnull (uri_data);
        g_assert_nonnull (uri_data->attributes);
 
@@ -133,7 +133,7 @@ test_parse_with_bad_string_encoding (void)
        GError *error = NULL;
        GckUriData *uri_data;
 
-       uri_data = gck_uri_parse ("pkcs11:object=Test%", GCK_URI_FOR_OBJECT, &error);
+       uri_data = gck_uri_data_parse ("pkcs11:object=Test%", GCK_URI_FOR_OBJECT, &error);
        g_assert_null (uri_data);
        g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_ENCODING);
        g_error_free (error);
@@ -144,7 +144,7 @@ test_parse_with_bad_binary_encoding (void)
 {
        GError *error = NULL;
        GckUriData *uri_data;
-       uri_data = gck_uri_parse ("pkcs11:id=%%", GCK_URI_FOR_ANY, &error);
+       uri_data = gck_uri_data_parse ("pkcs11:id=%%", GCK_URI_FOR_ANY, &error);
        g_assert_null (uri_data);
        g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_ENCODING);
        g_error_free (error);
@@ -156,7 +156,7 @@ test_parse_with_token (void)
        GError *error = NULL;
        GckUriData *uri_data = NULL;
 
-       uri_data = gck_uri_parse ("pkcs11:token=Token%20Label;serial=3333;model=Deluxe;manufacturer=Me",
+       uri_data = gck_uri_data_parse ("pkcs11:token=Token%20Label;serial=3333;model=Deluxe;manufacturer=Me",
                                  GCK_URI_FOR_TOKEN, &error);
 
        g_assert_nonnull (uri_data);
@@ -174,7 +174,7 @@ test_parse_with_token_bad_encoding (void)
        GError *error = NULL;
        GckUriData *uri_data;
 
-       uri_data = gck_uri_parse ("pkcs11:token=Token%", GCK_URI_FOR_TOKEN, &error);
+       uri_data = gck_uri_data_parse ("pkcs11:token=Token%", GCK_URI_FOR_TOKEN, &error);
        g_assert_null (uri_data);
        g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_ENCODING);
        g_error_free (error);
@@ -186,7 +186,7 @@ test_parse_with_bad_syntax (void)
        GError *error = NULL;
        GckUriData *uri_data;
 
-       uri_data = gck_uri_parse ("pkcs11:token", GCK_URI_FOR_ANY, &error);
+       uri_data = gck_uri_data_parse ("pkcs11:token", GCK_URI_FOR_ANY, &error);
        g_assert_null (uri_data);
        g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_SYNTAX);
        g_error_free (error);
@@ -198,7 +198,7 @@ test_parse_with_library (void)
        GError *error = NULL;
        GckUriData *uri_data = NULL;
 
-       uri_data = gck_uri_parse ("pkcs11:library-description=The%20Library;library-manufacturer=Me",
+       uri_data = gck_uri_data_parse ("pkcs11:library-description=The%20Library;library-manufacturer=Me",
                                  GCK_URI_FOR_MODULE, &error);
 
        g_assert_nonnull (uri_data);
@@ -214,7 +214,7 @@ test_parse_with_library_bad_encoding (void)
        GError *error = NULL;
        GckUriData *uri_data;
 
-       uri_data = gck_uri_parse ("pkcs11:library-description=Library%", GCK_URI_FOR_MODULE, &error);
+       uri_data = gck_uri_data_parse ("pkcs11:library-description=Library%", GCK_URI_FOR_MODULE, &error);
        g_assert_null (uri_data);
        g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_ENCODING);
        g_error_free (error);
@@ -227,7 +227,7 @@ test_build_empty (void)
        gchar *uri;
 
        memset (&uri_data, 0, sizeof (uri_data));
-       uri = gck_uri_build (&uri_data, 0);
+       uri = gck_uri_data_build (&uri_data, 0);
        g_assert_cmpstr (uri, ==, "pkcs11:");
        g_free (uri);
 }
@@ -246,10 +246,10 @@ test_build_with_token_info (void)
        uri_data.token_info->manufacturer_id = g_strdup ("Me");
        uri_data.token_info->model = g_strdup ("Deluxe");
 
-       uri = gck_uri_build (&uri_data, GCK_URI_FOR_TOKEN);
+       uri = gck_uri_data_build (&uri_data, GCK_URI_FOR_TOKEN);
        g_assert_nonnull (uri);
 
-       check = gck_uri_parse (uri, GCK_URI_FOR_TOKEN, NULL);
+       check = gck_uri_data_parse (uri, GCK_URI_FOR_TOKEN, NULL);
        g_assert_nonnull (check);
        g_assert_nonnull (check->token_info);
 
@@ -277,7 +277,7 @@ test_build_with_token_null_info (void)
        uri_data.token_info = g_new0 (GckTokenInfo, 1);
        uri_data.token_info->label = g_strdup ("The Label");
 
-       uri = gck_uri_build (&uri_data, GCK_URI_FOR_TOKEN);
+       uri = gck_uri_data_build (&uri_data, GCK_URI_FOR_TOKEN);
        g_assert_nonnull (uri);
 
        g_assert_true (g_str_has_prefix (uri, "pkcs11:"));
@@ -299,7 +299,7 @@ test_build_with_token_empty_info (void)
        uri_data.token_info->label = g_strdup ("The Label");
        uri_data.token_info->serial_number = g_strdup ("");
 
-       uri = gck_uri_build (&uri_data, GCK_URI_FOR_TOKEN);
+       uri = gck_uri_data_build (&uri_data, GCK_URI_FOR_TOKEN);
        g_assert_nonnull (uri);
 
        g_assert_true (g_str_has_prefix (uri, "pkcs11:"));
@@ -327,12 +327,12 @@ test_build_with_attributes (void)
        gck_builder_add_data (&builder, CKA_ID, (const guchar *)"TEST", 5);
        uri_data.attributes = gck_attributes_ref_sink (gck_builder_end (&builder));
 
-       uri = gck_uri_build (&uri_data, GCK_URI_FOR_OBJECT);
+       uri = gck_uri_data_build (&uri_data, GCK_URI_FOR_OBJECT);
        g_assert_nonnull (uri);
 
        gck_attributes_unref (uri_data.attributes);
 
-       check = gck_uri_parse (uri, GCK_URI_FOR_ANY, NULL);
+       check = gck_uri_data_parse (uri, GCK_URI_FOR_ANY, NULL);
        g_assert_nonnull (check);
        g_assert_nonnull (check->attributes);
 
@@ -366,7 +366,7 @@ test_parse_private_key (void)
        GError *error = NULL;
        gulong klass;
 
-       uri_data = gck_uri_parse ("pkcs11:objecttype=private", GCK_URI_FOR_OBJECT, &error);
+       uri_data = gck_uri_data_parse ("pkcs11:objecttype=private", GCK_URI_FOR_OBJECT, &error);
        g_assert_nonnull (uri_data);
        g_assert_no_error (error);
 
@@ -385,7 +385,7 @@ test_parse_secret_key (void)
        GError *error = NULL;
        gulong klass;
 
-       uri_data = gck_uri_parse ("pkcs11:objecttype=secretkey", GCK_URI_FOR_OBJECT, &error);
+       uri_data = gck_uri_data_parse ("pkcs11:objecttype=secretkey", GCK_URI_FOR_OBJECT, &error);
        g_assert_nonnull (uri_data);
        g_assert_no_error (error);
 
@@ -405,7 +405,7 @@ test_parse_unknown_objecttype (void)
        GError *error = NULL;
        gulong klass;
 
-       uri_data = gck_uri_parse ("pkcs11:objecttype=unknown", GCK_URI_FOR_OBJECT, &error);
+       uri_data = gck_uri_data_parse ("pkcs11:objecttype=unknown", GCK_URI_FOR_OBJECT, &error);
        g_assert_nonnull (uri_data);
        g_assert_no_error (error);
 
@@ -428,7 +428,7 @@ test_build_objecttype_cert (void)
        gck_builder_add_ulong (&builder, CKA_CLASS, CKO_CERTIFICATE);
        uri_data->attributes = gck_attributes_ref_sink (gck_builder_end (&builder));
 
-       uri = gck_uri_build (uri_data, GCK_URI_FOR_OBJECT);
+       uri = gck_uri_data_build (uri_data, GCK_URI_FOR_OBJECT);
        g_assert_nonnull (uri);
        g_assert_true (strstr (uri, "object-type=cert") || strstr (uri, "type=cert"));
 
@@ -447,7 +447,7 @@ test_build_objecttype_private (void)
        gck_builder_add_ulong (&builder, CKA_CLASS, CKO_PRIVATE_KEY);
        uri_data->attributes = gck_attributes_ref_sink (gck_builder_end (&builder));
 
-       uri = gck_uri_build (uri_data, GCK_URI_FOR_OBJECT);
+       uri = gck_uri_data_build (uri_data, GCK_URI_FOR_OBJECT);
        g_assert_nonnull (uri);
        g_assert_true (strstr (uri, "object-type=private") || strstr (uri, "type=private"));
 
@@ -466,7 +466,7 @@ test_build_objecttype_public (void)
        gck_builder_add_ulong (&builder, CKA_CLASS, CKO_PUBLIC_KEY);
        uri_data->attributes = gck_attributes_ref_sink (gck_builder_end (&builder));
 
-       uri = gck_uri_build (uri_data, GCK_URI_FOR_OBJECT);
+       uri = gck_uri_data_build (uri_data, GCK_URI_FOR_OBJECT);
        g_assert_nonnull (uri);
        g_assert_true (strstr (uri, "object-type=public") ||
                       strstr (uri, "type=public"));
@@ -486,7 +486,7 @@ test_build_objecttype_secret (void)
        gck_builder_add_ulong (&builder, CKA_CLASS, CKO_SECRET_KEY);
        uri_data->attributes = gck_attributes_ref_sink (gck_builder_end (&builder));
 
-       uri = gck_uri_build (uri_data, GCK_URI_FOR_OBJECT);
+       uri = gck_uri_data_build (uri_data, GCK_URI_FOR_OBJECT);
        g_assert_nonnull (uri);
        g_assert_true (strstr (uri, "object-type=secret-key") ||
                       strstr (uri, "type=secret-key"));
@@ -505,7 +505,7 @@ test_build_with_library (void)
        uri_data->module_info = g_new0 (GckModuleInfo, 1);
        uri_data->module_info->library_description = g_strdup ("The Description");
 
-       uri = gck_uri_build (uri_data, GCK_URI_FOR_MODULE);
+       uri = gck_uri_data_build (uri_data, GCK_URI_FOR_MODULE);
        g_assert_nonnull (uri);
        g_assert_true (strstr (uri, "library-description=The%20Description"));
 
diff --git a/gcr/gcr-pkcs11-importer.c b/gcr/gcr-pkcs11-importer.c
index 57c4925..8b4a056 100644
--- a/gcr/gcr-pkcs11-importer.c
+++ b/gcr/gcr-pkcs11-importer.c
@@ -627,7 +627,7 @@ calculate_uri (GcrPkcs11Importer *self)
 
        data = gck_uri_data_new ();
        data->token_info = gck_slot_get_token_info (self->slot);
-       uri = gck_uri_build (data, GCK_URI_FOR_TOKEN);
+       uri = gck_uri_data_build (data, GCK_URI_FOR_TOKEN);
        data->token_info = NULL;
        gck_uri_data_free (data);
 
@@ -752,7 +752,7 @@ is_slot_importable (GckSlot *slot,
        }
 
        for (i = 0; token_blacklist[i] != NULL; i++) {
-               uri = gck_uri_parse (token_blacklist[i], GCK_URI_FOR_TOKEN | GCK_URI_FOR_MODULE, &error);
+               uri = gck_uri_data_parse (token_blacklist[i], GCK_URI_FOR_TOKEN | GCK_URI_FOR_MODULE, &error);
                if (uri == NULL) {
                        g_warning ("couldn't parse pkcs11 blacklist uri: %s", error->message);
                        g_clear_error (&error);


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