X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-protocol-registry.c;h=c71b1f03c7dccf5c327d206558534570ca440dbb;hp=3aae13b5622c5d3a75802ff1f7c2f8f6add432a8;hb=HEAD;hpb=627c4af6ac85444cc3256fa568baf4a8d62178ae diff --git a/src/modest-protocol-registry.c b/src/modest-protocol-registry.c index 3aae13b..c71b1f0 100644 --- a/src/modest-protocol-registry.c +++ b/src/modest-protocol-registry.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -80,7 +81,7 @@ static void modest_protocol_registry_instance_init (ModestProtocolRegistry *ob static GHashTable * modest_protocol_registry_create_tag (ModestProtocolRegistry *obj, const gchar *tag); /* translation handlers */ -static gchar * translation_is_userdata (gpointer userdata, ...); +static gchar * translation_is_userdata (gpointer userdata, va_list args); typedef struct _ModestProtocolRegistryPrivate ModestProtocolRegistryPrivate; struct _ModestProtocolRegistryPrivate { @@ -154,7 +155,8 @@ modest_protocol_registry_instance_init (ModestProtocolRegistry *obj) priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (obj); - priv->tags_table = g_hash_table_new (g_str_hash, g_str_equal); + priv->tags_table = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, (GDestroyNotify) g_hash_table_unref); priv->priorities = g_hash_table_new (g_direct_hash, g_direct_equal); modest_protocol_registry_create_tag (obj, TAG_ALL_PROTOCOLS); @@ -163,6 +165,15 @@ modest_protocol_registry_instance_init (ModestProtocolRegistry *obj) static void modest_protocol_registry_finalize (GObject *obj) { + ModestProtocolRegistryPrivate *priv; + + priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (obj); + + /* Free hash tables */ + if (priv->tags_table) + g_hash_table_unref (priv->tags_table); + if (priv->priorities) + g_hash_table_unref (priv->priorities); G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -205,7 +216,7 @@ modest_protocol_registry_add (ModestProtocolRegistry *self, ModestProtocol *prot tag_table = g_hash_table_lookup (priv->tags_table, node->data); if (tag_table == NULL) tag_table = modest_protocol_registry_create_tag (self, node->data); - g_hash_table_insert (tag_table, GINT_TO_POINTER (modest_protocol_get_type_id (protocol)), protocol); + g_hash_table_insert (tag_table, GINT_TO_POINTER (modest_protocol_get_type_id (protocol)), g_object_ref (protocol)); } g_slist_free (tags_list); } @@ -288,7 +299,7 @@ modest_protocol_registry_get_pair_list_by_tag (ModestProtocolRegistry *self, con { ModestProtocolRegistryPrivate *priv; GHashTable *tag_table; - GSList *result; + GSList *result = NULL; g_return_val_if_fail (MODEST_IS_PROTOCOL_REGISTRY (self), NULL); priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (self); @@ -300,7 +311,7 @@ modest_protocol_registry_get_pair_list_by_tag (ModestProtocolRegistry *self, con g_hash_table_foreach (tag_table, (GHFunc) add_protocol_to_pair_list, &result); - return result; + return result; } static gboolean @@ -312,12 +323,17 @@ find_protocol_by_name (ModestProtocolType type_id, } ModestProtocol * -modest_protocol_registry_get_protocol_by_name (ModestProtocolRegistry *self, const gchar *tag, const gchar *name) +modest_protocol_registry_get_protocol_by_name (ModestProtocolRegistry *self, + const gchar *tag, + const gchar *name) { ModestProtocolRegistryPrivate *priv; GHashTable *tag_table; g_return_val_if_fail (MODEST_IS_PROTOCOL_REGISTRY (self), NULL); + g_return_val_if_fail (tag, NULL); + g_return_val_if_fail (name, NULL); + priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (self); tag_table = g_hash_table_lookup (priv->tags_table, tag); @@ -372,28 +388,28 @@ modest_protocol_registry_create_tag (ModestProtocolRegistry *self, const gchar * g_assert (tag != NULL); priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (self); - tag_table = g_hash_table_new (g_direct_hash, g_direct_equal); + tag_table = g_hash_table_new_full (g_direct_hash, g_direct_equal, + NULL, g_object_unref); g_hash_table_insert (priv->tags_table, g_strdup (tag), tag_table); return tag_table; } static gchar * -translation_is_userdata (gpointer userdata, ...) +translation_is_userdata (gpointer userdata, va_list args) { - va_list args, dest; + va_list dest; gchar *result; - va_start(args, userdata); - va_copy (dest, args); - result = g_strdup_printf (_(userdata), dest); - va_end (args); + G_VA_COPY (dest, args); + result = g_strdup_vprintf (_(userdata), dest); + va_end (dest); return result; } static gchar * -translation_is_userdata_no_param (gpointer userdata, ...) +translation_is_userdata_no_param (gpointer userdata, va_list args) { gchar *result; @@ -418,17 +434,20 @@ modest_protocol_registry_set_to_default (ModestProtocolRegistry *self) MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS, NULL); + g_object_unref (protocol); protocol = modest_account_protocol_new ("smtp", N_("SMTP Server"), 25, 465, - TNY_TYPE_CAMEL_TRANSPORT_ACCOUNT); + MODEST_TYPE_TRANSPORT_ACCOUNT_DECORATOR); smtp_protocol_type_id = modest_protocol_get_type_id (protocol); modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_CONNECT_ERROR, translation_is_userdata, "emev_ib_ui_smtp_server_invalid", NULL); + modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, translation_is_userdata, "emev_ib_ui_smtp_server_invalid", NULL); modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_AUTH_ERROR, translation_is_userdata, "emev_ni_ui_smtp_authentication_fail_error", NULL); modest_protocol_registry_add (self, protocol, 2, MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS, NULL); + g_object_unref (protocol); protocol = modest_account_protocol_new ("pop", _("mail_fi_emailtype_pop3"), 110, 995, @@ -438,14 +457,16 @@ modest_protocol_registry_set_to_default (ModestProtocolRegistry *self) modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_AUTH_ERROR, translation_is_userdata, "emev_ni_ui_pop3_msg_connect_error", NULL); modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, translation_is_userdata, "emev_ni_ui_pop3_msg_connect_error", NULL); modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, translation_is_userdata_no_param, "emev_ni_ui_pop3_msg_recv_error", NULL); + modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE_LOST_HEADER, translation_is_userdata, "emev_ni_ui_pop3_msg_recv_error", NULL); modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_SSL_PROTO_NAME, translation_is_userdata_no_param, "mcen_fi_advsetup_other_security_securepop3s", NULL); modest_protocol_registry_add (self, protocol, 3, MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS, MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS, MODEST_PROTOCOL_REGISTRY_HAS_LEAVE_ON_SERVER_PROTOCOLS, - MODEST_PROTOCOL_REGISTRY_STORE_FORBID_MESSAGE_ADD, + MODEST_PROTOCOL_REGISTRY_STORE_FORBID_INCOMING_XFERS, NULL); + g_object_unref (protocol); protocol = modest_account_protocol_new ("imap", _("mail_fi_emailtype_imap"), 143, 993, @@ -456,6 +477,7 @@ modest_protocol_registry_set_to_default (ModestProtocolRegistry *self) modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_AUTH_ERROR, translation_is_userdata, "emev_ni_ui_imap_connect_server_error", NULL); modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, translation_is_userdata, "emev_ni_ui_imap_connect_server_error", NULL); modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, translation_is_userdata, "emev_ni_ui_imap_message_not_available_in_server", NULL); + modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE_LOST_HEADER, translation_is_userdata, "emev_ni_ui_pop3_msg_recv_error", NULL); modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_SSL_PROTO_NAME, translation_is_userdata_no_param, "mcen_fi_advsetup_other_security_secureimap4s", NULL); account_options = tny_simple_list_new (); pair = tny_pair_new (MODEST_ACCOUNT_OPTION_USE_LSUB, ""); @@ -472,6 +494,7 @@ modest_protocol_registry_set_to_default (ModestProtocolRegistry *self) MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS, MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS, NULL); + g_object_unref (protocol); protocol = modest_account_protocol_new ("maildir", N_("Maildir"), 0, 0, @@ -485,6 +508,7 @@ modest_protocol_registry_set_to_default (ModestProtocolRegistry *self) MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS, MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS, NULL); + g_object_unref (protocol); protocol = modest_account_protocol_new ("mbox", N_("MBox"), 0, 0, @@ -498,6 +522,7 @@ modest_protocol_registry_set_to_default (ModestProtocolRegistry *self) MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS, MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS, NULL); + g_object_unref (protocol); protocol = modest_protocol_new ("none", N_("None")); modest_protocol_set (protocol, MODEST_PROTOCOL_SECURITY_ACCOUNT_OPTION, MODEST_ACCOUNT_OPTION_SSL_NEVER); @@ -505,6 +530,8 @@ modest_protocol_registry_set_to_default (ModestProtocolRegistry *self) modest_protocol_registry_add (self, protocol, 7, MODEST_PROTOCOL_REGISTRY_CONNECTION_PROTOCOLS, NULL); + g_object_unref (protocol); + protocol = modest_protocol_new ("ssl", N_("SSL")); modest_protocol_set (protocol, MODEST_PROTOCOL_SECURITY_ACCOUNT_OPTION, MODEST_ACCOUNT_OPTION_SSL_WRAPPED); ssl_connection_protocol_type_id = modest_protocol_get_type_id (protocol); @@ -513,6 +540,8 @@ modest_protocol_registry_set_to_default (ModestProtocolRegistry *self) MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS, MODEST_PROTOCOL_REGISTRY_USE_ALTERNATE_PORT, NULL); + g_object_unref (protocol); + protocol = modest_protocol_new ("tls", N_("TLS")); modest_protocol_set (protocol, MODEST_PROTOCOL_SECURITY_ACCOUNT_OPTION, MODEST_ACCOUNT_OPTION_SSL_TLS); tls_connection_protocol_type_id = modest_protocol_get_type_id (protocol); @@ -520,6 +549,8 @@ modest_protocol_registry_set_to_default (ModestProtocolRegistry *self) MODEST_PROTOCOL_REGISTRY_CONNECTION_PROTOCOLS, MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS, NULL); + g_object_unref (protocol); + protocol = modest_protocol_new ("tls-op", N_("TLS when possible")); modest_protocol_set (protocol, MODEST_PROTOCOL_SECURITY_ACCOUNT_OPTION, MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE); tlsop_connection_protocol_type_id = modest_protocol_get_type_id (protocol); @@ -527,12 +558,16 @@ modest_protocol_registry_set_to_default (ModestProtocolRegistry *self) MODEST_PROTOCOL_REGISTRY_CONNECTION_PROTOCOLS, MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS, NULL); + g_object_unref (protocol); + protocol = modest_protocol_new (MODEST_ACCOUNT_AUTH_MECH_VALUE_NONE, _("mcen_fi_advsetup_smtp_none")); none_auth_protocol_type_id = modest_protocol_get_type_id (protocol); modest_protocol_set (protocol, MODEST_PROTOCOL_AUTH_ACCOUNT_OPTION, MODEST_ACCOUNT_AUTH_PLAIN); modest_protocol_registry_add (self, protocol, 11, MODEST_PROTOCOL_REGISTRY_AUTH_PROTOCOLS, NULL); + g_object_unref (protocol); + protocol = modest_protocol_new (MODEST_ACCOUNT_AUTH_MECH_VALUE_PASSWORD, _("mcen_fi_advsetup_smtp_login")); password_auth_protocol_type_id = modest_protocol_get_type_id (protocol); modest_protocol_set (protocol, MODEST_PROTOCOL_AUTH_ACCOUNT_OPTION, MODEST_ACCOUNT_AUTH_PASSWORD); @@ -540,6 +575,8 @@ modest_protocol_registry_set_to_default (ModestProtocolRegistry *self) MODEST_PROTOCOL_REGISTRY_AUTH_PROTOCOLS, MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS, NULL); + g_object_unref (protocol); + protocol = modest_protocol_new (MODEST_ACCOUNT_AUTH_MECH_VALUE_CRAMMD5, _("mcen_fi_advsetup_smtp_cram_md5")); crammd5_auth_protocol_type_id = modest_protocol_get_type_id (protocol); modest_protocol_set (protocol, MODEST_PROTOCOL_AUTH_ACCOUNT_OPTION, MODEST_ACCOUNT_AUTH_CRAMMD5); @@ -547,35 +584,7 @@ modest_protocol_registry_set_to_default (ModestProtocolRegistry *self) MODEST_PROTOCOL_REGISTRY_AUTH_PROTOCOLS, MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS, NULL); - -#if 0 - /********** WARNING: Test code ( *********/ -#include "modest-testplugin-protocol.h" - protocol = (ModestProtocol *) - modest_testplugin_protocol_new ("testplugin", _("mcen_va_testplugin"), - 80, 443, - TNY_TYPE_CAMEL_IMAP_STORE_ACCOUNT); - modest_protocol_registry_add (self, protocol, 50, - MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS, - MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS, - MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS, - MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS, - MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS, - NULL); - - protocol = (ModestProtocol *) - modest_testplugin_protocol_new ("testplugin-transport", _("mcen_va_testplugin"), - 80, 443, - TNY_TYPE_CAMEL_TRANSPORT_ACCOUNT); - modest_protocol_registry_add (self, protocol, 51, - MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS, - MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS, - MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS, - NULL); - - /********* WARNING: Test code ( *********/ -#endif - + g_object_unref (protocol); /* set the custom auth mechs. We do this after creating all the protocols, because if we don't, then we * won't register the auth protocol type id's properly */