struct shared_storage *storage = (struct shared_storage *)_storage;
struct mailbox_list_settings list_set;
const char *driver, *p;
+ char *wildcardp;
bool have_username;
/* data must begin with the actual mailbox driver */
}
_storage->mailbox_is_file = storage->storage_class->mailbox_is_file;
- p = strchr(_storage->ns->prefix, '%');
- if (p == NULL) {
+ wildcardp = strchr(_storage->ns->prefix, '%');
+ if (wildcardp == NULL) {
*error_r = "Shared namespace prefix doesn't contain %";
return -1;
}
- storage->ns_prefix_pattern = p_strdup(_storage->pool, p);
- _storage->ns->prefix = p_strdup_until(_storage->ns->user->pool,
- _storage->ns->prefix, p);
+ storage->ns_prefix_pattern = p_strdup(_storage->pool, wildcardp);
+ *wildcardp = '\0';
have_username = FALSE;
for (p = storage->ns_prefix_pattern; *p != '\0'; p++) {
}
/* create the new namespace */
- ns = p_new(user->pool, struct mail_namespace, 1);
+ ns = i_new(struct mail_namespace, 1);
ns->type = NAMESPACE_SHARED;
ns->user = user;
- ns->prefix = p_strdup(user->pool, str_c(prefix));
+ ns->prefix = i_strdup(str_c(prefix));
ns->flags = NAMESPACE_FLAG_LIST | NAMESPACE_FLAG_HIDDEN |
NAMESPACE_FLAG_AUTOCREATED;
ns->sep = _storage->ns->sep;
}
}
+static void mail_namespace_free(struct mail_namespace *ns)
+{
+ i_free(ns->prefix);
+ i_free(ns);
+}
+
static struct mail_namespace *
namespace_add_env(const char *data, unsigned int num,
struct mail_user *user, enum mail_storage_flags flags,
struct mail_namespace *ns;
const char *sep, *type, *prefix, *driver, *error;
- ns = p_new(user->pool, struct mail_namespace, 1);
+ ns = i_new(struct mail_namespace, 1);
sep = getenv(t_strdup_printf("NAMESPACE_%u_SEP", num));
type = getenv(t_strdup_printf("NAMESPACE_%u_TYPE", num));
ns->type = NAMESPACE_PUBLIC;
else {
i_error("Unknown namespace type: %s", type);
+ mail_namespace_free(ns);
return NULL;
}
if (sep != NULL)
ns->sep = *sep;
- ns->prefix = p_strdup(user->pool, prefix);
+ ns->prefix = i_strdup(prefix);
ns->user = user;
if (ns->type == NAMESPACE_SHARED && strchr(ns->prefix, '%') != NULL) {
if (mail_storage_create(ns, driver, data, flags, lock_method,
&error) < 0) {
i_error("Namespace '%s': %s", ns->prefix, error);
+ mail_namespace_free(ns);
return NULL;
}
return ns;
}
if (namespaces != NULL) {
- if (!namespaces_check(namespaces))
+ if (!namespaces_check(namespaces)) {
+ while (namespaces != NULL) {
+ ns = namespaces;
+ namespaces = ns->next;
+ mail_namespace_free(ns);
+ }
return -1;
+ }
mail_user_add_namespace(user, namespaces);
if (hook_mail_namespaces_created != NULL) {
mail = t_strconcat("maildir:", mail, NULL);
}
- ns = p_new(user->pool, struct mail_namespace, 1);
+ ns = i_new(struct mail_namespace, 1);
ns->type = NAMESPACE_PRIVATE;
ns->flags = NAMESPACE_FLAG_INBOX | NAMESPACE_FLAG_LIST |
NAMESPACE_FLAG_SUBSCRIPTIONS;
- ns->prefix = "";
+ ns->prefix = i_strdup("");
ns->user = user;
if (mail_storage_create(ns, NULL, mail, flags, lock_method,
i_error("mail_location not set and "
"autodetection failed: %s", error);
}
+ mail_namespace_free(ns);
return -1;
}
user->namespaces = ns;
{
struct mail_namespace *ns;
- ns = p_new(user->pool, struct mail_namespace, 1);
+ ns = i_new(struct mail_namespace, 1);
ns->user = user;
- ns->prefix = "";
+ ns->prefix = i_strdup("");
ns->flags = NAMESPACE_FLAG_INBOX | NAMESPACE_FLAG_LIST |
NAMESPACE_FLAG_SUBSCRIPTIONS;
user->namespaces = ns;
void mail_namespaces_deinit(struct mail_namespace **_namespaces)
{
- struct mail_namespace *namespaces = *_namespaces;
+ struct mail_namespace *ns, *namespaces = *_namespaces;
*_namespaces = NULL;
while (namespaces != NULL) {
- if (namespaces->storage != NULL)
- mail_storage_destroy(&namespaces->storage);
+ ns = namespaces;
namespaces = namespaces->next;
+
+ if (ns->storage != NULL)
+ mail_storage_destroy(&ns->storage);
+ mail_namespace_free(ns);
+ }
+}
+
+void mail_namespace_destroy(struct mail_namespace *ns)
+{
+ struct mail_namespace **nsp;
+
+ /* remove from user's namespaces list */
+ for (nsp = &ns->user->namespaces; *nsp != NULL; nsp = &(*nsp)->next) {
+ if (*nsp == ns) {
+ *nsp = ns->next;
+ break;
+ }
}
+
+ if (ns->storage != NULL)
+ mail_storage_destroy(&ns->storage);
+ mail_namespace_free(ns);
}
const char *mail_namespace_fix_sep(struct mail_namespace *ns, const char *name)