From 9e52d4854215f97da297634959cc1e9212150c5b Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Tue, 17 Apr 2007 09:22:05 +0000 Subject: [PATCH] 2007-04-17 Murray Cumming * src/modest-defs.h: * src/modest-account-mgr.c: (modest_account_mgr_add_server_account): Added and used defines for the options key and value pair strings, that are used so far, though they do not seem to correspond to anything in our UI specs or ModestProtocol enum. * src/modest-account-mgr-helpers.h: * src/modest-account-mgr-helpers.c: (compare_option_strings_for_name), (modest_server_account_data_get_option_value), (modest_server_account_data_get_option_bool), (modest_account_mgr_get_server_account_option): Added helper functions for parsing the options GSList. pmo-trunk-r1570 --- ChangeLog2 | 17 ++++++ src/maemo/modest-account-settings-dialog.c | 8 +++ src/modest-account-mgr-helpers.c | 88 ++++++++++++++++++++++++++++ src/modest-account-mgr-helpers.h | 28 +++++++++ src/modest-account-mgr.c | 11 ++-- src/modest-defs.h | 10 ++++ 6 files changed, 157 insertions(+), 5 deletions(-) diff --git a/ChangeLog2 b/ChangeLog2 index 4708bdb..bd04df1 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,3 +1,20 @@ +2007-04-17 Murray Cumming + + * src/modest-defs.h: + * src/modest-account-mgr.c: + (modest_account_mgr_add_server_account): + Added and used defines for the options key and value pair strings, + that are used so far, though they do not seem to correspond to anything in our + UI specs or ModestProtocol enum. + + * src/modest-account-mgr-helpers.h: + * src/modest-account-mgr-helpers.c: + (compare_option_strings_for_name), + (modest_server_account_data_get_option_value), + (modest_server_account_data_get_option_bool), + (modest_account_mgr_get_server_account_option): + Added helper functions for parsing the options GSList. + 2007-04-16 Murray Cumming * src/modest-account-mgr-helpers.c: Clarified the documentation to say that the initial diff --git a/src/maemo/modest-account-settings-dialog.c b/src/maemo/modest-account-settings-dialog.c index e04aaf0..1e37ac5 100644 --- a/src/maemo/modest-account-settings-dialog.c +++ b/src/maemo/modest-account-settings-dialog.c @@ -807,6 +807,14 @@ void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialo easysetup_serversecurity_combo_box_fill ( EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto); + printf("debug: incoming options list=%p\n", incoming_account->options); + printf("debug: outgoing options list=%p\n", outgoing_account->options); + + gchar* debug = modest_server_account_data_get_option_value (incoming_account->options, MODEST_ACCOUNT_OPTION_SSL); + printf("debug: ssl option=X%sX\n", debug); + + gboolean bdebug = modest_server_account_data_get_option_bool (incoming_account->options, MODEST_ACCOUNT_OPTION_USE_LSUB); + printf("debug: ssl option=X%dX\n", bdebug); /* TODO: set port. */ diff --git a/src/modest-account-mgr-helpers.c b/src/modest-account-mgr-helpers.c index 3c839ca..9cfc252 100644 --- a/src/modest-account-mgr-helpers.c +++ b/src/modest-account-mgr-helpers.c @@ -47,6 +47,94 @@ modest_account_mgr_get_enabled (ModestAccountMgr *self, const gchar* name) return modest_account_mgr_get_bool (self, name, MODEST_ACCOUNT_ENABLED, FALSE); } +static gint +compare_option_strings_for_name (const gchar* a, const gchar* b) +{ + printf(" debug: compare_option_strings_for_name():a=%s, b=%s\n", a, b); + const gchar* sep = strchr(a, '='); + if (!sep) + return -1; + + gint len = sep - a; + if(len <= 0) + return -1; + + /* Get the part of the string before the =. + * Note that this allocation is inefficient just so we can do a strcmp. */ + gchar* name = g_malloc (len+1); + memcpy(name, a, len); + name[len] = 0; /* Null-termination. */ + + printf(" debug: name=%s\n", name); + + gint result = strcmp (name, b); + + g_free (name); + + return result; +} + +gchar* +modest_server_account_data_get_option_value (GSList* options_list, const gchar* option_name) +{ + if (!options_list) + return NULL; + + gchar *result = NULL; + GSList* option = g_slist_find_custom(options_list, option_name, (GCompareFunc)compare_option_strings_for_name); + if(option) { + /* Get the value part of the key=value pair: */ + const gchar* pair = (const gchar*)option->data; + + const gchar* sep = strchr(pair, '='); + if (sep) { + gint len = sep - pair; + if(len > 0) { + result = g_strdup(sep+1); + + /* Avoid returning an empty string instead of NULL. */ + if(result && strlen(result) == 0) { + g_free(result); + result = NULL; + } + } + } + } + + return result; +} + +gboolean +modest_server_account_data_get_option_bool (GSList* options_list, const gchar* option_name) +{ + if (!options_list) + return FALSE; + + gboolean result = FALSE; + GSList* option = g_slist_find_custom(options_list, option_name, (GCompareFunc)strcmp); + if(option) { + return TRUE; + } + + return result; +} + +gchar* +modest_account_mgr_get_server_account_option (ModestAccountMgr *self, + const gchar* account_name, const gchar* option_name) +{ + GSList *option_list = modest_account_mgr_get_list (self, account_name, MODEST_ACCOUNT_OPTIONS, + MODEST_CONF_VALUE_STRING, TRUE); + if (!option_list) + return NULL; + + gchar *result = modest_server_account_data_get_option_value (option_list, option_name); + + /* TODO: Should we free the items too, or just the list? */ + g_slist_free (option_list); + + return result; +} static ModestServerAccountData* modest_account_mgr_get_server_account_data (ModestAccountMgr *self, const gchar* name) diff --git a/src/modest-account-mgr-helpers.h b/src/modest-account-mgr-helpers.h index e649d04..1040209 100644 --- a/src/modest-account-mgr-helpers.h +++ b/src/modest-account-mgr-helpers.h @@ -136,6 +136,34 @@ gboolean modest_account_mgr_set_enabled (ModestAccountMgr *self, const gchar* na */ gboolean modest_account_mgr_get_enabled (ModestAccountMgr *self, const gchar* name); +/** + * modest_account_mgr_get_account_option: + * @self: a ModestAccountMgr instance + * @account_name: the account name to check + * @account_name: the option name to check + * + * Returns: The account option value. This must be freed with g_free(). + */ +gchar* modest_account_mgr_get_server_account_option (ModestAccountMgr *self, const gchar* account_name, const gchar* option_name); + +/** + * modest_server_account_data_get_option_value: + * @self: a ModestServerAccountData instance + * @account_name: the option name to check + * + * Returns: The account option value. This must be freed with g_free(). + */ +gchar* modest_server_account_data_get_option_value (GSList* options_list, const gchar* option_name); + +/** + * modest_server_account_data_get_option_bool: + * @self: a ModestServerAccountData instance + * @account_name: the option name to check + * + * Returns: Whether the account option is present. + */ +gboolean modest_server_account_data_get_option_bool (GSList* options_list, const gchar* option_name); + /** * modest_account_mgr_get_from_string diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index ceb8fe8..82dd892 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -407,19 +407,20 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self, supported */ key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_OPTIONS, TRUE); /* Enable subscriptions and check the mails in all folders */ - option_list = g_slist_append (option_list, "use_lsub"); - option_list = g_slist_append (option_list, "check_all"); + option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_USE_LSUB); + option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_CHECK_ALL); + /* Security options */ switch (security) { case MODEST_PROTOCOL_SECURITY_NONE: - option_list = g_slist_append (option_list, "use_ssl=never"); + option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_NEVER); break; case MODEST_PROTOCOL_SECURITY_SSL: case MODEST_PROTOCOL_SECURITY_TLS: - option_list = g_slist_append (option_list, "use_ssl=always"); + option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_ALWAYS); break; case MODEST_PROTOCOL_SECURITY_TLS_OP: - option_list = g_slist_append (option_list, "use_ssl=when-possible"); + option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE); break; default: g_warning ("Invalid security option"); diff --git a/src/modest-defs.h b/src/modest-defs.h index 1f4b7c0..9da8cd7 100644 --- a/src/modest-defs.h +++ b/src/modest-defs.h @@ -109,4 +109,14 @@ #define MODEST_ACCOUNT_OPTIONS "options" /* list */ #define MODEST_ACCOUNT_AUTH_MECH "auth_mech" /* string */ +/* Keys and values used in the text items in the options GSList: */ +#define MODEST_ACCOUNT_OPTION_SSL "use_ssl" +#define MODEST_ACCOUNT_OPTION_SSL_NEVER "never" +#define MODEST_ACCOUNT_OPTION_SSL_ALWAYS "always" +#define MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE "when-possible" + +#define MODEST_ACCOUNT_OPTION_USE_LSUB "use_lsub" +#define MODEST_ACCOUNT_OPTION_CHECK_ALL "check_all" + + #endif /*__MODEST_DEFS_H__*/ -- 1.7.9.5