From: Milan Crha Date: Fri, 24 Apr 2009 17:17:13 +0000 (+0200) Subject: Compare URLs only on protocol, user, host and port for smtp and pop3 X-Git-Tag: upstream/3.7.4~4075 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c649c92cceff4cd7fa1a20bdc7393f107014d0b4;p=platform%2Fupstream%2Fevolution-data-server.git Compare URLs only on protocol, user, host and port for smtp and pop3 ** Part of fix for bug #552583 * camel/providers/pop3/camel-pop3-provider.c: (pop3_url_hash), (pop3_url_equal), (camel_provider_module_init), (add_hash), (check_equal): * camel/providers/smtp/camel-smtp-provider.c: (smtp_url_hash), (smtp_url_equal), (camel_provider_module_init), (add_hash), (check_equal): Compare URLs only on protocol, user, host and port. --- diff --git a/camel/providers/pop3/ChangeLog b/camel/providers/pop3/ChangeLog index 44cfd1d..d3b7baa 100644 --- a/camel/providers/pop3/ChangeLog +++ b/camel/providers/pop3/ChangeLog @@ -1,3 +1,11 @@ +2009-04-24 Milan Crha + + ** Part of fix for bug #552583 + + * camel-pop3-provider.c: (pop3_url_hash), (pop3_url_equal), + (camel_provider_module_init), (add_hash), (check_equal): + Compare URLs only on protocol, user, host and port. + 2008-12-09 Milan Crha ** Fix for bug #552986 diff --git a/camel/providers/pop3/camel-pop3-provider.c b/camel/providers/pop3/camel-pop3-provider.c index b0170d4..afa3644 100644 --- a/camel/providers/pop3/camel-pop3-provider.c +++ b/camel/providers/pop3/camel-pop3-provider.c @@ -35,6 +35,8 @@ #include "camel-session.h" #include "camel-url.h" +static guint pop3_url_hash (gconstpointer key); +static gint pop3_url_equal (gconstpointer a, gconstpointer b); static CamelProviderConfEntry pop3_conf_entries[] = { { CAMEL_PROVIDER_CONF_SECTION_START, "storage", NULL, @@ -95,8 +97,8 @@ camel_provider_module_init(void) CamelServiceAuthType *auth; pop3_provider.object_types[CAMEL_PROVIDER_STORE] = camel_pop3_store_get_type(); - pop3_provider.url_hash = camel_url_hash; - pop3_provider.url_equal = camel_url_equal; + pop3_provider.url_hash = pop3_url_hash; + pop3_provider.url_equal = pop3_url_equal; pop3_provider.authtypes = camel_sasl_authtype_list (FALSE); auth = camel_sasl_authtype("LOGIN"); @@ -108,3 +110,50 @@ camel_provider_module_init(void) camel_provider_register(&pop3_provider); } + +static void +add_hash (guint *hash, char *s) +{ + if (s) + *hash ^= g_str_hash(s); +} + +static guint +pop3_url_hash (gconstpointer key) +{ + const CamelURL *u = (CamelURL *)key; + guint hash = 0; + + add_hash (&hash, u->user); + add_hash (&hash, u->host); + hash ^= u->port; + + return hash; +} + +static gint +check_equal (char *s1, char *s2) +{ + if (s1 == NULL) { + if (s2 == NULL) + return TRUE; + else + return FALSE; + } + + if (s2 == NULL) + return FALSE; + + return strcmp (s1, s2) == 0; +} + +static gint +pop3_url_equal (gconstpointer a, gconstpointer b) +{ + const CamelURL *u1 = a, *u2 = b; + + return check_equal (u1->protocol, u2->protocol) + && check_equal (u1->user, u2->user) + && check_equal (u1->host, u2->host) + && u1->port == u2->port; +} diff --git a/camel/providers/smtp/ChangeLog b/camel/providers/smtp/ChangeLog index ccb8c5a..ee503b9 100644 --- a/camel/providers/smtp/ChangeLog +++ b/camel/providers/smtp/ChangeLog @@ -1,3 +1,11 @@ +2009-04-24 Milan Crha + + ** Part of fix for bug #552583 + + * camel-smtp-provider.c: (smtp_url_hash), (smtp_url_equal), + (camel_provider_module_init), (add_hash), (check_equal): + Compare URLs only on protocol, user, host and port. + 2008-09-26 Milan Crha ** Part of fix for bug #553301 diff --git a/camel/providers/smtp/camel-smtp-provider.c b/camel/providers/smtp/camel-smtp-provider.c index 33c72ef..ad5985c 100644 --- a/camel/providers/smtp/camel-smtp-provider.c +++ b/camel/providers/smtp/camel-smtp-provider.c @@ -34,6 +34,9 @@ #include "camel-smtp-transport.h" #include "camel-url.h" +static guint smtp_url_hash (gconstpointer key); +static gint smtp_url_equal (gconstpointer a, gconstpointer b); + static CamelProvider smtp_provider = { "smtp", N_("SMTP"), @@ -56,12 +59,56 @@ camel_provider_module_init(void) smtp_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = camel_smtp_transport_get_type (); smtp_provider.authtypes = g_list_append (camel_sasl_authtype_list (TRUE), camel_sasl_authtype ("LOGIN")); smtp_provider.authtypes = g_list_append (smtp_provider.authtypes, camel_sasl_authtype ("POPB4SMTP")); - smtp_provider.url_hash = camel_url_hash; - smtp_provider.url_equal = camel_url_equal; + smtp_provider.url_hash = smtp_url_hash; + smtp_provider.url_equal = smtp_url_equal; smtp_provider.translation_domain = GETTEXT_PACKAGE; camel_provider_register(&smtp_provider); } +static void +add_hash (guint *hash, char *s) +{ + if (s) + *hash ^= g_str_hash(s); +} + +static guint +smtp_url_hash (gconstpointer key) +{ + const CamelURL *u = (CamelURL *)key; + guint hash = 0; + add_hash (&hash, u->user); + add_hash (&hash, u->host); + hash ^= u->port; + + return hash; +} +static gint +check_equal (char *s1, char *s2) +{ + if (s1 == NULL) { + if (s2 == NULL) + return TRUE; + else + return FALSE; + } + + if (s2 == NULL) + return FALSE; + + return strcmp (s1, s2) == 0; +} + +static gint +smtp_url_equal (gconstpointer a, gconstpointer b) +{ + const CamelURL *u1 = a, *u2 = b; + + return check_equal (u1->protocol, u2->protocol) + && check_equal (u1->user, u2->user) + && check_equal (u1->host, u2->host) + && u1->port == u2->port; +}