[evolution-data-server/evolution-data-server-3-12] [IMAPx] Use case-insensitive compares and hash table functions



commit c59531d9368ec997968b3fd9eba74295937e9c77
Author: Milan Crha <mcrha redhat com>
Date:   Wed Apr 23 15:06:44 2014 +0200

    [IMAPx] Use case-insensitive compares and hash table functions
    
    Almost all attributes, responses and commands in general are
    case-insensitive in IMAPx, thus even the code can "normalize"
    the respective strings to proper case, it's safer to use
    case-insensitive compares and equal-functions in hash tables
    where applicable.

 camel/providers/imapx/camel-imapx-list-response.c |   16 +++++-----------
 camel/providers/imapx/camel-imapx-mailbox.c       |    4 +---
 camel/providers/imapx/camel-imapx-server.c        |    4 ++--
 camel/providers/imapx/camel-imapx-utils.c         |   10 +++-------
 4 files changed, 11 insertions(+), 23 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-list-response.c 
b/camel/providers/imapx/camel-imapx-list-response.c
index f4ee92d..161129e 100644
--- a/camel/providers/imapx/camel-imapx-list-response.c
+++ b/camel/providers/imapx/camel-imapx-list-response.c
@@ -114,13 +114,9 @@ camel_imapx_list_response_init (CamelIMAPXListResponse *response)
        GHashTable *extended_items;
 
        /* Set of internalized attribute strings. */
-       attributes = g_hash_table_new (
-               (GHashFunc) g_str_hash,
-               (GEqualFunc) g_str_equal);
+       attributes = g_hash_table_new (camel_strcase_hash, camel_strcase_equal);
 
-       extended_items = g_hash_table_new_full (
-               (GHashFunc) g_str_hash,
-               (GEqualFunc) g_str_equal,
+       extended_items = g_hash_table_new_full (camel_strcase_hash, camel_strcase_equal,
                (GDestroyNotify) g_free,
                (GDestroyNotify) g_variant_unref);
 
@@ -263,13 +259,13 @@ imapx_list_response_parse_extended_item (CamelIMAPXInputStream *stream,
         *     IMAP parser makes this more difficult. */
 
        /* RFC 5258 "LIST-EXTENDED" */
-       if (g_strcmp0 (item_tag, "CHILDINFO") == 0) {
+       if (item_tag && g_ascii_strcasecmp (item_tag, "CHILDINFO") == 0) {
                item_value = imapx_list_response_parse_childinfo (
                        stream, response, cancellable, error);
                success = (item_value != NULL);
 
        /* RFC 5465 "NOTIFY" */
-       } else if (g_strcmp0 (item_tag, "OLDNAME") == 0) {
+       } else if (item_tag && g_ascii_strcasecmp (item_tag, "OLDNAME") == 0) {
                item_value = imapx_list_response_parse_oldname (
                        stream, response, cancellable, error);
                success = (item_value != NULL);
@@ -770,9 +766,7 @@ camel_imapx_list_response_dup_attributes (CamelIMAPXListResponse *response)
 
        g_return_val_if_fail (CAMEL_IS_IMAPX_LIST_RESPONSE (response), NULL);
 
-       hash_table = g_hash_table_new (
-               (GHashFunc) g_str_hash,
-               (GEqualFunc) g_str_equal);
+       hash_table = g_hash_table_new (camel_strcase_hash, camel_strcase_equal);
 
        g_hash_table_iter_init (&iter, response->priv->attributes);
 
diff --git a/camel/providers/imapx/camel-imapx-mailbox.c b/camel/providers/imapx/camel-imapx-mailbox.c
index dbe6313..3f4edd0 100644
--- a/camel/providers/imapx/camel-imapx-mailbox.c
+++ b/camel/providers/imapx/camel-imapx-mailbox.c
@@ -218,9 +218,7 @@ camel_imapx_mailbox_clone (CamelIMAPXMailbox *mailbox,
        /* Use camel_imapx_list_response_dup_attributes()
         * as a guide for cloning the mailbox attributes. */
 
-       clone->priv->attributes = g_hash_table_new (
-               (GHashFunc) g_str_hash,
-               (GEqualFunc) g_str_equal);
+       clone->priv->attributes = g_hash_table_new (camel_strcase_hash, camel_strcase_equal);
 
        g_mutex_lock (&mailbox->priv->property_lock);
 
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index f4b5273..3b2855d 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -748,8 +748,8 @@ static GHashTable *
 create_initial_untagged_handler_table (void)
 {
        GHashTable *uh = g_hash_table_new_full (
-               g_str_hash,
-               g_str_equal,
+               camel_strcase_hash,
+               camel_strcase_equal,
                g_free,
                NULL);
        guint32 ii = 0;
diff --git a/camel/providers/imapx/camel-imapx-utils.c b/camel/providers/imapx/camel-imapx-utils.c
index bef9ffa..e802f41 100644
--- a/camel/providers/imapx/camel-imapx-utils.c
+++ b/camel/providers/imapx/camel-imapx-utils.c
@@ -462,8 +462,8 @@ create_initial_capabilities_table (void)
         *      to free hash table
         */
        capa_htable = g_hash_table_new_full (
-               g_str_hash,
-               g_str_equal,
+               camel_strcase_hash,
+               camel_strcase_equal,
                g_free,
                NULL);
 
@@ -489,11 +489,7 @@ imapx_parse_capability (CamelIMAPXInputStream *stream,
 
        cinfo = g_malloc0 (sizeof (*cinfo));
 
-       cinfo->auth_types = g_hash_table_new_full (
-               (GHashFunc) g_str_hash,
-               (GEqualFunc) g_str_equal,
-               (GDestroyNotify) g_free,
-               (GDestroyNotify) NULL);
+       cinfo->auth_types = g_hash_table_new_full (camel_strcase_hash, camel_strcase_equal, g_free, NULL);
 
        /* FIXME: handle auth types */
        tok = camel_imapx_input_stream_token (


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