- allow also non-ASCII account names
- all but NULL and '/' in names is allowed
pmo-trunk-r564
/* 'private'/'protected' functions */
static void modest_account_mgr_class_init (ModestAccountMgrClass * klass);
/* 'private'/'protected' functions */
static void modest_account_mgr_class_init (ModestAccountMgrClass * klass);
-static void modest_account_mgr_init (ModestAccountMgr * obj);
-static void modest_account_mgr_finalize (GObject * obj);
+static void modest_account_mgr_init (ModestAccountMgr * obj);
+static void modest_account_mgr_finalize (GObject * obj);
-static gchar *get_account_keyname (const gchar * accname, const gchar * name,
- gboolean server_account);
+static gchar *get_account_keyname (const gchar * accname, const gchar * name,
+ gboolean server_account);
/* list my signals */
enum {
/* list my signals */
enum {
ModestAccountMgrPrivate))
/* globals */
static GObjectClass *parent_class = NULL;
ModestAccountMgrPrivate))
/* globals */
static GObjectClass *parent_class = NULL;
static guint signals[LAST_SIGNAL] = {0};
static guint signals[LAST_SIGNAL] = {0};
static gchar*
account_from_key (const gchar *key, gboolean *is_account_key, gboolean *is_server_account)
{
static gchar*
account_from_key (const gchar *key, gboolean *is_account_key, gboolean *is_server_account)
{
gchar *cursor;
gchar *account = NULL;
gchar *cursor;
gchar *account = NULL;
- /* determine if it's an account or a server account,
+ /* determine whether it's an account or a server account,
* based on the prefix */
if (g_str_has_prefix (key, account_ns)) {
* based on the prefix */
if (g_str_has_prefix (key, account_ns)) {
/* put a NULL where the first slash was */
if (cursor)
*cursor = '\0';
/* put a NULL where the first slash was */
if (cursor)
*cursor = '\0';
g_return_val_if_fail (self, FALSE);
g_return_val_if_fail (name, FALSE);
g_return_val_if_fail (self, FALSE);
g_return_val_if_fail (name, FALSE);
-
- if (modest_account_mgr_account_exists (self, name, FALSE, err)) {
- g_printerr ("modest: account already exists\n");
- return FALSE;
- }
+ g_return_val_if_fail (strchr(name, '/') == NULL, FALSE);
+
+ priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
/*
* we create the account by adding an account 'dir', with the name <name>,
* and in that the 'display_name' string key
*/
/*
* we create the account by adding an account 'dir', with the name <name>,
* and in that the 'display_name' string key
*/
- priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
-
key = get_account_keyname (name, MODEST_ACCOUNT_DISPLAY_NAME, FALSE);
key = get_account_keyname (name, MODEST_ACCOUNT_DISPLAY_NAME, FALSE);
+ if (modest_account_mgr_account_exists (self, key, FALSE, err)) {
+ g_printerr ("modest: account already exists\n");
+ g_free (key);
+ return FALSE;
+ }
+
ok = modest_conf_set_string (priv->modest_conf, key, name, err);
g_free (key);
ok = modest_conf_set_string (priv->modest_conf, key, name, err);
g_free (key);
gboolean
modest_account_mgr_add_server_account (ModestAccountMgr * self,
gboolean
modest_account_mgr_add_server_account (ModestAccountMgr * self,
- const gchar * name, const gchar * hostname,
+ const gchar * name, const gchar *hostname,
const gchar * username, const gchar * password,
const gchar * proto)
{
const gchar * username, const gchar * password,
const gchar * proto)
{
g_return_val_if_fail (self, FALSE);
g_return_val_if_fail (name, FALSE);
g_return_val_if_fail (self, FALSE);
g_return_val_if_fail (name, FALSE);
+ g_return_val_if_fail (strchr(name, '/') == NULL, FALSE);
priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
-
- key = get_account_keyname (name, NULL, TRUE);
+
+ /* hostname */
+ key = get_account_keyname (name, MODEST_ACCOUNT_HOSTNAME, TRUE);
if (modest_conf_key_exists (priv->modest_conf, key, NULL)) {
g_printerr ("modest: server account '%s' already exists", name);
g_free (key);
return FALSE;
}
if (modest_conf_key_exists (priv->modest_conf, key, NULL)) {
g_printerr ("modest: server account '%s' already exists", name);
g_free (key);
return FALSE;
}
- /* hostname */
- key = get_account_keyname (name, MODEST_ACCOUNT_HOSTNAME, TRUE);
modest_conf_set_string (priv->modest_conf, key, null_means_empty(hostname), NULL);
g_free (key);
modest_conf_set_string (priv->modest_conf, key, null_means_empty(hostname), NULL);
g_free (key);
-/* strip the first /n/ character from each element */
-/* caller must make sure all elements are strings with
+/* strip the first /n/ character from each element
+ * caller must make sure all elements are strings with
* length >= n, and also that data can be freed.
* length >= n, and also that data can be freed.
strip_prefix_from_elements (GSList * lst, guint n)
{
strip_prefix_from_elements (GSList * lst, guint n)
{
- GSList *cursor = lst;
-
- while (cursor) {
- gchar *str = (gchar *) cursor->data;
- cursor->data = g_strdup (str + n);
- g_free (str);
- cursor = cursor->next;
+ while (lst) {
+ memmove (lst->data + n, lst->data,
+ strlen(lst->data) + 1);
+ lst = lst->next;
GError *err = NULL;
g_return_val_if_fail (self, NULL);
GError *err = NULL;
g_return_val_if_fail (self, NULL);
key = get_account_keyname (account_name, NULL, TRUE);
priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
key = get_account_keyname (account_name, NULL, TRUE);
priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
}
/* no restrictions, return everything */
}
/* no restrictions, return everything */
- if (type == MODEST_PROTOCOL_TYPE_ANY && !proto)
- return strip_prefix_from_elements (accounts, strlen(key)+1);
- /* +1 because we must remove the ending '/' as well */
+ if (type == MODEST_PROTOCOL_TYPE_ANY && !proto) {
+ strip_prefix_from_elements (accounts, strlen(key)+1);
+ return accounts;
+ /* +1 because we must remove the ending '/' as well */
+ }
/* otherwise, filter out the none-matching ones */
cursor = accounts;
/* otherwise, filter out the none-matching ones */
cursor = accounts;
- return strip_prefix_from_elements (accounts, strlen(key)+1);
/* +1 because we must remove the ending '/' as well */
/* +1 because we must remove the ending '/' as well */
+ strip_prefix_from_elements (accounts, strlen(key)+1);
+
+ return accounts;
+
accounts = modest_conf_list_subkeys (priv->modest_conf,
MODEST_ACCOUNT_NAMESPACE, err);
accounts = modest_conf_list_subkeys (priv->modest_conf,
MODEST_ACCOUNT_NAMESPACE, err);
- return strip_prefix_from_elements (accounts, prefix_len);
+ strip_prefix_from_elements (accounts, prefix_len);
+ return accounts;
-modest_account_mgr_get_account_data (ModestAccountMgr *self,
- const gchar* name)
+modest_account_mgr_get_account_data (ModestAccountMgr *self, const gchar* name)
{
ModestAccountData *data;
gchar *server_account;
{
ModestAccountData *data;
gchar *server_account;
data->enabled = modest_account_mgr_account_get_enabled (self, name);
/* store */
data->enabled = modest_account_mgr_account_get_enabled (self, name);
/* store */
- server_account = modest_account_mgr_get_string (self, name,
- MODEST_ACCOUNT_STORE_ACCOUNT,
- FALSE, NULL);
+ server_account = modest_account_mgr_get_string (self, name,
+ MODEST_ACCOUNT_STORE_ACCOUNT,
+ FALSE, NULL);
if (server_account) {
data->store_account =
modest_account_mgr_get_server_account_data (self,
if (server_account) {
data->store_account =
modest_account_mgr_get_server_account_data (self,
-modest_account_mgr_free_account_data (ModestAccountMgr *self,
- ModestAccountData *data)
+modest_account_mgr_free_account_data (ModestAccountMgr *self, ModestAccountData *data)
{
g_return_if_fail (self);
{
g_return_if_fail (self);
gchar *
modest_account_mgr_get_string (ModestAccountMgr *self, const gchar *name,
const gchar *key, gboolean server_account, GError **err) {
gchar *
modest_account_mgr_get_string (ModestAccountMgr *self, const gchar *name,
const gchar *key, gboolean server_account, GError **err) {
/* must be freed by caller */
static gchar *
/* must be freed by caller */
static gchar *
-get_account_keyname (const gchar * accname, const gchar * name, gboolean server_account)
+get_account_keyname (const gchar *account_name, const gchar * name, gboolean server_account)
- gchar *namespace, *account_name, *retval;
+ gchar *namespace;
+ gchar *retval;
namespace = server_account ? MODEST_SERVER_ACCOUNT_NAMESPACE : MODEST_ACCOUNT_NAMESPACE;
namespace = server_account ? MODEST_SERVER_ACCOUNT_NAMESPACE : MODEST_ACCOUNT_NAMESPACE;
return g_strdup (namespace);
return g_strdup (namespace);
-
- account_name = modest_conf_key_escape (NULL, accname);
- retval = g_strconcat (namespace, "/", accname, "/", name, NULL);
+ retval = g_strconcat (namespace, "/", account_name, "/", name, NULL);
- retval = g_strconcat (namespace, "/", accname, NULL);
+ retval = g_strconcat (namespace, "/", account_name, NULL);
+
+ /* special case: the key has some weird characters */
+ if (!modest_conf_key_is_valid (retval)) {
+
+ gchar *account_name_esc, *name_esc;
+ g_free (retval);
+
+ account_name_esc = account_name ? modest_conf_key_escape (account_name) : NULL;
+ name_esc = name ? modest_conf_key_escape (name) : NULL;
+
+ retval = get_account_keyname (account_name_esc, name_esc, server_account);
+ g_free (account_name_esc);
+ g_free (name_esc);
+ }
/**
* modest_account_mgr_add_account:
* @self: a ModestAccountMgr instance
/**
* modest_account_mgr_add_account:
* @self: a ModestAccountMgr instance
- * @name: the name of the account to create
+ * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
* @store_name: the store account (ie. POP/IMAP)
* @transport_name: the transport account (ie. sendmail/SMTP)
* @err: a GError ptr, or NULL to ignore.
* @store_name: the store account (ie. POP/IMAP)
* @transport_name: the transport account (ie. sendmail/SMTP)
* @err: a GError ptr, or NULL to ignore.
/**
* modest_account_mgr_add_server_account:
* @self: a ModestAccountMgr instance
/**
* modest_account_mgr_add_server_account:
* @self: a ModestAccountMgr instance
- * @name: name (id) of the account
+ * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
* @hostname: the hostname
* @username: the username
* @password: the password
* @hostname: the hostname
* @username: the username
* @password: the password
return gconf_unescape_key (key, strlen(key));
}
return gconf_unescape_key (key, strlen(key));
}
+gboolean
+modest_conf_key_is_valid (const gchar* key)
+{
+ return gconf_valid_key (key, NULL);
+}
+
+
gboolean modest_conf_key_exists (ModestConf* self, const gchar* key, GError **err);
gboolean modest_conf_key_exists (ModestConf* self, const gchar* key, GError **err);
+
+/**
+ * modest_conf_key_valid:
+ * @str: some key
+ *
+ * check whether @str is a valid key in the config system
+ * This is a *class* function, and therefore does not require a ModestConf
+ * instance
+ *
+ * Returns: TRUE if it is valid, FALSE otherwise
+ */
+gboolean modest_conf_key_is_valid (const gchar* str);
+
+
/**
* modest_conf_key_escape:
* @str: a string to escape
*
* returns an escaped version of @str, ie. something suitable as a key
* This is a *class* function, and therefore does not require a ModestConf
/**
* modest_conf_key_escape:
* @str: a string to escape
*
* returns an escaped version of @str, ie. something suitable as a key
* This is a *class* function, and therefore does not require a ModestConf
+ * instance. Note: this for is invidual elements in a key
*
* Returns: a newly allocated string with the escaped version
*/
*
* Returns: a newly allocated string with the escaped version
*/
*
* returns an unescaped version of @str. This is a *class* function, and
* therefore does not require a ModestConf instance
*
* returns an unescaped version of @str. This is a *class* function, and
* therefore does not require a ModestConf instance
+ * Note: this for is invidual elements in a key
*
* Returns: a newly allocated string with the unescaped version
*/
*
* Returns: a newly allocated string with the unescaped version
*/
/* ----------------------- Defines ---------------------- */
/* ----------------------- Defines ---------------------- */
-#define TEST_MODEST_ACCOUNT_NAME "modest-unit-tests-account"
+#define TEST_MODEST_ACCOUNT_NAME "modest-unit-tests-àccount"
/* ------------------ Global variables ------------------ */
/* ------------------ Global variables ------------------ */
static void
fx_setup_default_account_mgr ()
{
static void
fx_setup_default_account_mgr ()
{
ModestConf *conf = NULL;
g_type_init ();
ModestConf *conf = NULL;
g_type_init ();
/* Test 3*/
result = modest_account_mgr_add_account (account_mgr,
/* Test 3*/
result = modest_account_mgr_add_account (account_mgr,
- "ïnválid_accountñ_nÄméç",
+ "ïnválid//accountñ//nÄméç",
"store_account",
"transport_account",
NULL);
"store_account",
"transport_account",
NULL);
"FALSE when passing a NULL account name");
/* Test 6 */
"FALSE when passing a NULL account name");
/* Test 6 */
- result = modest_account_mgr_add_server_account (account_mgr,
- "ïnválid_accountñ_nÄméç",
- "hostname",
- "username",
- "password",
- "proto");
- fail_unless (!result,
- "modest_account_mgr_add_server_account does not return " \
- "FALSE when passing an invalid account name");
+ result = modest_account_mgr_add_server_account (account_mgr,
+ "ïnválid//accountñ//nÄméç",
+ "hostname",
+ "username",
+ "password",
+ "proto");
+ fail_unless (!result,
+ "modest_account_mgr_add_server_account does not return " \
+ "FALSE when passing an invalid account name");
/* Test 7 */
result = modest_account_mgr_remove_account (account_mgr,
/* Test 7 */
result = modest_account_mgr_remove_account (account_mgr,