Commit 96a55b3c 96a55b3c6c87103eb23d7e6f1d4be4c6ee6a29ec by Sergey Poznyakoff

(mu_mailbox_set_default_proto,mu_mailbox_get_default_proto): New functions.

(mu_mailbox_create): Append default_proto to the mailbox URL, if
the latter does not already contain one.
Update invocation of mu_registrar_lookup
1 parent 2b884091
...@@ -59,6 +59,30 @@ mailbox_folder_create (mu_folder_t *pfolder, const char *name) ...@@ -59,6 +59,30 @@ mailbox_folder_create (mu_folder_t *pfolder, const char *name)
59 return rc; 59 return rc;
60 } 60 }
61 61
62 static char *default_proto;
63
64 int
65 mu_mailbox_set_default_proto (const char *proto)
66 {
67 char *p;
68
69 if (mu_registrar_lookup (proto, MU_FOLDER_ATTRIBUTE_FILE, NULL, NULL))
70 return MU_ERR_NO_HANDLER;
71 p = strdup (proto);
72 if (!p)
73 return ENOMEM;
74 if (default_proto)
75 free (default_proto);
76 default_proto = p;
77 return 0;
78 }
79
80 const char *
81 mu_mailbox_get_default_proto ()
82 {
83 return default_proto ? default_proto : "/";
84 }
85
62 /* The Mailbox Factory. 86 /* The Mailbox Factory.
63 Create an iterator for registrar and see if any url scheme match, 87 Create an iterator for registrar and see if any url scheme match,
64 Then we call the mailbox's mu_url_create() to parse the URL. Last 88 Then we call the mailbox's mu_url_create() to parse the URL. Last
...@@ -71,7 +95,17 @@ mu_mailbox_create (mu_mailbox_t *pmbox, const char *name) ...@@ -71,7 +95,17 @@ mu_mailbox_create (mu_mailbox_t *pmbox, const char *name)
71 if (pmbox == NULL) 95 if (pmbox == NULL)
72 return MU_ERR_OUT_PTR_NULL; 96 return MU_ERR_OUT_PTR_NULL;
73 97
74 if (mu_registrar_lookup (name, &record, MU_FOLDER_ATTRIBUTE_FILE)) 98 if (!mu_is_proto (name) && default_proto)
99 {
100 char *tmp_name = alloca (strlen (default_proto) + strlen (name) + 1);
101 if (!tmp_name)
102 return ENOMEM;
103 strcpy (tmp_name, default_proto);
104 strcat (tmp_name, name);
105 name = tmp_name;
106 }
107
108 if (mu_registrar_lookup (name, MU_FOLDER_ATTRIBUTE_FILE, &record, NULL) == 0)
75 { 109 {
76 int (*m_init) (mu_mailbox_t) = NULL; 110 int (*m_init) (mu_mailbox_t) = NULL;
77 int (*u_init) (mu_url_t) = NULL; 111 int (*u_init) (mu_url_t) = NULL;
......