+2007-04-17 Murray Cumming <murrayc@murrayc.com>
+
+ * 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 <murrayc@murrayc.com>
* src/modest-account-mgr-helpers.c: Clarified the documentation to say that the initial
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. */
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)
*/
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
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");
#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__*/