1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <modest-account-mgr-priv.h>
32 #include <modest-defs.h>
34 #include <modest-conf.h>
37 _modest_account_mgr_account_from_key (const gchar *key, gboolean *is_account_key, gboolean *is_server_account)
39 const gchar* account_ns = MODEST_ACCOUNT_NAMESPACE "/";
40 const gchar* server_account_ns = MODEST_SERVER_ACCOUNT_NAMESPACE "/";
42 gchar *account = NULL;
44 /* determine whether it's an account or a server account,
45 * based on the prefix */
46 if (g_str_has_prefix (key, account_ns)) {
48 if (is_server_account)
49 *is_server_account = FALSE;
51 account = g_strdup (key + strlen (account_ns));
53 } else if (g_str_has_prefix (key, server_account_ns)) {
55 if (is_server_account)
56 *is_server_account = TRUE;
58 account = g_strdup (key + strlen (server_account_ns));
62 /* if there are any slashes left in the key, it's not
63 * the toplevel entry for an account
65 cursor = strstr(account, "/");
67 if (is_account_key && cursor)
68 *is_account_key = TRUE;
70 /* put a NULL where the first slash was */
79 /* must be freed by caller */
81 _modest_account_mgr_get_account_keyname (const gchar *account_name, const gchar * name, gboolean server_account)
86 namespace = server_account ? MODEST_SERVER_ACCOUNT_NAMESPACE : MODEST_ACCOUNT_NAMESPACE;
89 return g_strdup (namespace);
92 retval = g_strconcat (namespace, "/", account_name, "/", name, NULL);
94 retval = g_strconcat (namespace, "/", account_name, NULL);
96 /* special case: the key has some weird characters */
97 if (!modest_conf_key_is_valid (retval)) {
99 gchar *account_name_esc, *name_esc;
102 account_name_esc = account_name ? modest_conf_key_escape (account_name) : NULL;
103 name_esc = name ? modest_conf_key_escape (name) : NULL;
105 retval = _modest_account_mgr_get_account_keyname (account_name_esc, name_esc, server_account);
107 g_free (account_name_esc);