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



commit a1a3969e078e1e3eaf20e1344edf861485563101
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 2808128..bfc607b 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 e952a88..36adc66 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 45d0cdc..0120623 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -749,8 +749,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 aa3b2bf..2d3d430 100644
--- a/camel/providers/imapx/camel-imapx-utils.c
+++ b/camel/providers/imapx/camel-imapx-utils.c
@@ -463,8 +463,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);
 
@@ -490,11 +490,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]