Commit 7f325d5c 7f325d5c04a280e0711a09fef9eab86e128ace86 by Sergey Poznyakoff

Fix the use of the hierarchy delimiter.

* include/mailutils/util.h (MU_HIERARCHY_DELIMITER): New define.
(mu_tilde_expansion): Change signature.  Delimiter is an int.
* libmailutils/base/tilde.c: Likewise. All uses update.

* imap4d/namespace.c (namespace_checkfullpath)
(namespace_getfullpath): Remove delim argument. All uses updated.
* imap4d/util.c (util_getfullpath): Remove delim argument. All uses updated.
1 parent 5c16cf45
......@@ -252,7 +252,7 @@ imap4d_append (struct imap4d_command *command, imap4d_tokbuf_t tok)
msg_text = imap4d_tokbuf_getarg (tok, i);
mboxname = namespace_getfullpath (mboxname, "/", NULL);
mboxname = namespace_getfullpath (mboxname, NULL);
if (!mboxname)
return io_completion_response (command, RESP_NO, "Couldn't open mailbox");
......
......@@ -232,7 +232,6 @@ imap4d_copy0 (imap4d_tokbuf_t tok, int isuid, char **err_text)
mu_list_t msglist;
char *name;
char *mailbox_name;
const char *delim = "/";
char *end;
mu_mailbox_t cmbox = NULL;
int arg = IMAP4_ARG_1 + !!isuid;
......@@ -256,7 +255,7 @@ imap4d_copy0 (imap4d_tokbuf_t tok, int isuid, char **err_text)
return RESP_BAD;
}
mailbox_name = namespace_getfullpath (name, delim, &ns);
mailbox_name = namespace_getfullpath (name, &ns);
if (!mailbox_name)
{
......
......@@ -37,7 +37,6 @@ int
imap4d_create (struct imap4d_command *command, imap4d_tokbuf_t tok)
{
char *name;
const char *delim = "/";
int isdir = 0;
int ns;
int rc = RESP_OK;
......@@ -63,11 +62,11 @@ imap4d_create (struct imap4d_command *command, imap4d_tokbuf_t tok)
The trailing delimiter will be removed by namespace normalizer, so
test for it now.
*/
if (name[strlen (name) - 1] == delim[0])
if (name[strlen (name) - 1] == MU_HIERARCHY_DELIMITER)
isdir = 1;
/* Allocates memory. */
name = namespace_getfullpath (name, delim, &ns);
name = namespace_getfullpath (name, &ns);
if (!name)
return io_completion_response (command, RESP_NO, "Cannot create mailbox");
......@@ -75,7 +74,7 @@ imap4d_create (struct imap4d_command *command, imap4d_tokbuf_t tok)
/* It will fail if the mailbox already exists. */
if (access (name, F_OK) != 0)
{
if (make_interdir (name, delim[0], MKDIR_PERMISSIONS))
if (make_interdir (name, MU_HIERARCHY_DELIMITER, MKDIR_PERMISSIONS))
{
rc = RESP_NO;
msg = "Cannot create mailbox";
......
......@@ -33,7 +33,6 @@ imap4d_delete (struct imap4d_command *command, imap4d_tokbuf_t tok)
{
int rc = RESP_OK;
const char *msg = "Completed";
const char *delim = "/";
char *name;
mu_mailbox_t tmpbox;
......@@ -49,7 +48,7 @@ imap4d_delete (struct imap4d_command *command, imap4d_tokbuf_t tok)
return io_completion_response (command, RESP_NO, "Already exist");
/* Allocates memory. */
name = namespace_getfullpath (name, delim, NULL);
name = namespace_getfullpath (name, NULL);
if (!name)
return io_completion_response (command, RESP_NO, "Cannot remove");
......
......@@ -325,7 +325,8 @@ imap4d_session_setup0 ()
if (modify_homedir)
{
char *expr = mu_tilde_expansion (modify_homedir, "/", real_homedir);
char *expr = mu_tilde_expansion (modify_homedir, MU_HIERARCHY_DELIMITER,
real_homedir);
struct mu_wordsplit ws;
const char *env[5];
......
......@@ -350,10 +350,9 @@ extern mu_list_t namespace[NS_MAX];
extern int namespace_init_session (char *path);
extern void namespace_init (void);
extern char *namespace_getfullpath (const char *name, const char *delim,
int *pns);
extern char *namespace_getfullpath (const char *name, int *pns);
extern char *namespace_checkfullpath (const char *name, const char *pattern,
const char *delim, int *pns);
int *pns);
int imap4d_session_setup (char *username);
int imap4d_session_setup0 (void);
void imap4d_child_signal_setup (RETSIGTYPE (*handler) (int signo));
......@@ -368,8 +367,7 @@ extern void imap4d_capability_init (void);
extern int util_start (char *);
extern int util_getstate (void);
extern int util_do_command (imap4d_tokbuf_t);
extern char *util_tilde_expansion (const char *, const char *);
extern char *util_getfullpath (const char *, const char *);
extern char *util_getfullpath (const char *);
extern struct imap4d_command *util_getcommand (char *,
struct imap4d_command []);
......@@ -397,9 +395,6 @@ extern int util_parse_ctime_date (const char *date, time_t *timep,
extern char *util_strcasestr (const char *haystack, const char *needle);
extern char *util_localname (void);
extern int util_wcard_match (const char *string, const char *pattern,
const char *delim);
void util_print_flags (mu_attribute_t attr);
int util_attribute_matches_flag (mu_attribute_t attr, const char *item);
int util_uidvalidity (mu_mailbox_t smbox, unsigned long *uidvp);
......
......@@ -135,7 +135,6 @@ imap4d_list (struct imap4d_command *command, imap4d_tokbuf_t tok)
{
char *ref;
char *wcard;
const char *delim = "/";
if (imap4d_tokbuf_argc (tok) != 4)
return io_completion_response (command, RESP_BAD, "Invalid arguments");
......@@ -147,9 +146,15 @@ imap4d_list (struct imap4d_command *command, imap4d_tokbuf_t tok)
return the hierarchy. */
if (*wcard == '\0')
{
if (*ref)
io_untagged_response (RESP_NONE,
"LIST (\\NoSelect) \"%s\" \"%s\"", delim,
(*ref) ? delim : "");
"LIST (\\NoSelect) \"%c\" \"%c\"",
MU_HIERARCHY_DELIMITER,
MU_HIERARCHY_DELIMITER);
else
io_untagged_response (RESP_NONE,
"LIST (\\NoSelect) \"%c\" \"\"",
MU_HIERARCHY_DELIMITER);
}
/* There is only one mailbox in the "INBOX" hierarchy ... INBOX. */
else if (mu_c_strcasecmp (ref, "INBOX") == 0
......@@ -222,7 +227,7 @@ imap4d_list (struct imap4d_command *command, imap4d_tokbuf_t tok)
}
/* Allocates. */
cwd = namespace_checkfullpath (ref, wcard, delim, NULL);
cwd = namespace_checkfullpath (ref, wcard, NULL);
if (!cwd)
{
free (ref);
......@@ -255,8 +260,9 @@ imap4d_list (struct imap4d_command *command, imap4d_tokbuf_t tok)
failure; it is not relevant whether the user's real INBOX resides
on this or some other server. */
if (!*ref && (mu_imap_wildmatch (wcard, "INBOX", delim[0]) == 0
|| mu_imap_wildmatch (wcard, "inbox", delim[0]) == 0))
if (!*ref &&
(mu_imap_wildmatch (wcard, "INBOX", MU_HIERARCHY_DELIMITER) == 0
|| mu_imap_wildmatch (wcard, "inbox", MU_HIERARCHY_DELIMITER) == 0))
io_untagged_response (RESP_NONE, "LIST (\\NoInferiors) NIL INBOX");
mu_folder_enumerate (folder, NULL, wcard, 0, 0, NULL,
......
......@@ -37,7 +37,6 @@ imap4d_lsub (struct imap4d_command *command, imap4d_tokbuf_t tok)
char *ref;
char *wcard;
char *pattern;
const char *delim = "/";
mu_property_t prop;
mu_iterator_t itr;
......@@ -64,9 +63,9 @@ imap4d_lsub (struct imap4d_command *command, imap4d_tokbuf_t tok)
mu_iterator_current_kv (itr, (const void **)&name, (void**)&val);
if (mu_imap_wildmatch (pattern, name, delim[0]) == 0)
io_untagged_response (RESP_NONE, "LSUB () \"%s\" \"%s\"",
delim, name);
if (mu_imap_wildmatch (pattern, name, MU_HIERARCHY_DELIMITER) == 0)
io_untagged_response (RESP_NONE, "LSUB () \"%c\" \"%s\"",
MU_HIERARCHY_DELIMITER, name);
}
}
else
......
......@@ -166,7 +166,7 @@ risky_pattern (const char *pattern, int delim)
char *
namespace_checkfullpath (const char *name, const char *pattern,
const char *delim, int *nspace)
int *nspace)
{
struct namespace_info info;
const char *p;
......@@ -185,7 +185,7 @@ namespace_checkfullpath (const char *name, const char *pattern,
name = p + 1;
}
path = util_getfullpath (name, delim);
path = util_getfullpath (name);
if (!path)
{
free (scheme);
......@@ -226,7 +226,7 @@ namespace_checkfullpath (const char *name, const char *pattern,
}
char *
namespace_getfullpath (const char *name, const char *delim, int *nspace)
namespace_getfullpath (const char *name, int *nspace)
{
char *ret;
if (mu_c_strcasecmp (name, "INBOX") == 0 && auth_data->change_uid)
......@@ -236,7 +236,7 @@ namespace_getfullpath (const char *name, const char *delim, int *nspace)
*nspace = NS_PRIVATE;
}
else
ret = namespace_checkfullpath (name, NULL, delim, nspace);
ret = namespace_checkfullpath (name, NULL, nspace);
return ret;
}
......
......@@ -138,7 +138,7 @@ quota_check (mu_off_t size)
total = used_size;
mailbox_name = namespace_getfullpath ("INBOX", "/", NULL);
mailbox_name = namespace_getfullpath ("INBOX", NULL);
rc = mu_mailbox_create (&mbox, mailbox_name);
if (rc)
{
......
......@@ -110,7 +110,6 @@ imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok)
int rc = RESP_OK;
const char *msg = "Completed";
struct stat newst;
const char *delim = "/";
int ns;
if (imap4d_tokbuf_argc (tok) != 4)
......@@ -123,7 +122,7 @@ imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok)
return io_completion_response (command, RESP_NO, "Name Inbox is reservered");
/* Allocates memory. */
newname = namespace_getfullpath (newname, delim, &ns);
newname = namespace_getfullpath (newname, &ns);
if (!newname)
return io_completion_response (command, RESP_NO, "Permission denied");
......@@ -140,7 +139,7 @@ imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok)
}
}
if (make_interdir (newname, delim[0], MKDIR_PERMISSIONS))
if (make_interdir (newname, MU_HIERARCHY_DELIMITER, MKDIR_PERMISSIONS))
{
free (newname);
return io_completion_response (command, RESP_NO, "Cannot rename");
......@@ -202,7 +201,7 @@ imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok)
return io_completion_response (command, RESP_OK, "Rename successful");
}
oldname = namespace_getfullpath (oldname, delim, NULL);
oldname = namespace_getfullpath (oldname, NULL);
/* It must exist. */
/* FIXME: 1. What if odlname or newname is a remote mailbox?
......
......@@ -58,7 +58,7 @@ imap4d_select0 (struct imap4d_command *command, const char *mboxname,
if (strcmp (mboxname, "INBOX") == 0)
flags |= MU_STREAM_CREAT;
mailbox_name = namespace_getfullpath (mboxname, "/", NULL);
mailbox_name = namespace_getfullpath (mboxname, NULL);
if (!mailbox_name)
return io_completion_response (command, RESP_NO, "Couldn't open mailbox");
......
......@@ -69,7 +69,6 @@ imap4d_status (struct imap4d_command *command, imap4d_tokbuf_t tok)
{
char *name;
char *mailbox_name;
const char *delim = "/";
mu_mailbox_t smbox = NULL;
int status;
int count = 0;
......@@ -81,7 +80,7 @@ imap4d_status (struct imap4d_command *command, imap4d_tokbuf_t tok)
name = imap4d_tokbuf_getarg (tok, IMAP4_ARG_1);
mailbox_name = namespace_getfullpath (name, delim, NULL);
mailbox_name = namespace_getfullpath (name, NULL);
if (!mailbox_name)
return io_completion_response (command, RESP_NO, "Error opening mailbox");
......
......@@ -17,28 +17,21 @@
#include "imap4d.h"
/* NOTE: Allocates Memory. */
/* Expand: ~ --> /home/user, and ~guest --> /home/guest. */
char *
util_tilde_expansion (const char *ref, const char *delim)
{
return mu_tilde_expansion (ref, delim, imap4d_homedir);
}
/* Get the absolute path. */
/* NOTE: Path is allocated and must be free()d by the caller. */
char *
util_getfullpath (const char *name, const char *delim)
util_getfullpath (const char *name)
{
char *exp = util_tilde_expansion (name, delim);
if (*exp != delim[0])
char *exp = mu_tilde_expansion (name, MU_HIERARCHY_DELIMITER,
imap4d_homedir);
if (*exp != MU_HIERARCHY_DELIMITER)
{
char *p, *s =
malloc (strlen (imap4d_homedir) + strlen (delim) + strlen (exp) + 1);
malloc (strlen (imap4d_homedir) + 1 + strlen (exp) + 1);
if (!s)
imap4d_bye (ERR_NO_MEM);
p = mu_stpcpy (s, imap4d_homedir);
p = mu_stpcpy (p, (char*) delim);
*p++ = MU_HIERARCHY_DELIMITER;
strcpy (p, exp);
free (exp);
exp = s;
......
......@@ -47,11 +47,14 @@ int mu_str_url_decode (char **ptr, const char *s);
/* ----------------------- */
/* File & path names. */
/* ----------------------- */
#define MU_HIERARCHY_DELIMITER '/'
char *mu_get_homedir (void);
char *mu_get_full_path (const char *file);
char *mu_normalize_path (char *path);
char *mu_expand_path_pattern (const char *pattern, const char *username);
char *mu_tilde_expansion (const char *ref, const char *delim,
char *mu_tilde_expansion (const char *ref, int delim,
const char *homedir);
int mu_readlink (const char *name, char **pbuf, size_t *psize, size_t *plen);
int mu_unroll_symlink (const char *name, char **pout);
......
......@@ -31,7 +31,7 @@
/* NOTE: Allocates Memory. */
/* Expand: ~ --> /home/user and to ~guest --> /home/guest. */
char *
mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
mu_tilde_expansion (const char *ref, int delim, const char *homedir)
{
char *base = strdup (ref);
char *home = NULL;
......@@ -52,9 +52,9 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
memcpy (proto, base, proto_len);
proto[proto_len] = 0;
/* Allow for extra pair of slashes after the protocol specifier */
if (*p == delim[0])
if (*p == delim)
p++;
if (*p == delim[0])
if (*p == delim)
p++;
}
else
......@@ -63,7 +63,7 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
if (*p == '~')
{
p++;
if (*p == delim[0] || *p == '\0')
if (*p == delim || *p == '\0')
{
char *s;
if (!homedir)
......@@ -88,7 +88,7 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
struct mu_auth_data *auth;
char *s = p;
char *name;
while (*s && *s != delim[0])
while (*s && *s != delim)
s++;
name = calloc (s - p + 1, 1);
memcpy (name, p, s - p);
......
......@@ -503,7 +503,7 @@ mu_parse_config (const char *file, const char *progname,
void *target_ptr)
{
int rc;
char *full_name = mu_tilde_expansion (file, "/", NULL);
char *full_name = mu_tilde_expansion (file, MU_HIERARCHY_DELIMITER, NULL);
if (full_name)
{
if (access (full_name, R_OK) == 0)
......
......@@ -326,7 +326,7 @@ mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file, int flags)
struct stat st;
FILE *fp;
int rc;
char *full_name = mu_tilde_expansion (file, "/", NULL);
char *full_name = mu_tilde_expansion (file, MU_HIERARCHY_DELIMITER, NULL);
if (stat (full_name, &st))
{
......
......@@ -345,7 +345,8 @@ attach_auth_ticket (mu_mailbox_t mbox)
&& mu_folder_get_authority (folder, &auth) == 0
&& auth)
{
char *filename = mu_tilde_expansion (mu_ticket_file, "/", NULL);
char *filename = mu_tilde_expansion (mu_ticket_file,
MU_HIERARCHY_DELIMITER, NULL);
mu_wicket_t wicket;
int rc;
......@@ -420,7 +421,7 @@ mu_mailbox_create_default (mu_mailbox_t *pmbox, const char *mail)
}
}
p = mu_tilde_expansion (mail, "/", NULL);
p = mu_tilde_expansion (mail, MU_HIERARCHY_DELIMITER, NULL);
if (tmp_mbox)
free (tmp_mbox);
tmp_mbox = p;
......
......@@ -348,7 +348,7 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from)
else
days = DAYS_DEFAULT;
file = mu_tilde_expansion ("~/.vacation", "/", NULL);
file = mu_tilde_expansion ("~/.vacation", MU_HIERARCHY_DELIMITER, NULL);
if (!file)
{
mu_sieve_error (mach, _("%lu: cannot build db file name"),
......
......@@ -32,7 +32,8 @@
static int
get_ticket (mu_ticket_t *pticket)
{
char *filename = mu_tilde_expansion (mu_ticket_file, "/", NULL);
char *filename = mu_tilde_expansion (mu_ticket_file,
MU_HIERARCHY_DELIMITER, NULL);
mu_wicket_t wicket;
int rc;
......
......@@ -475,7 +475,7 @@ util_get_homedir ()
char *
util_fullpath (const char *inpath)
{
return mu_tilde_expansion (inpath, "/", NULL);
return mu_tilde_expansion (inpath, MU_HIERARCHY_DELIMITER, NULL);
}
char *
......
......@@ -69,7 +69,7 @@ main (int argc, char **argv)
name = getenv ("MH");
if (name)
name = mu_tilde_expansion (name, "/", NULL);
name = mu_tilde_expansion (name, MU_HIERARCHY_DELIMITER, NULL);
else
{
char *home = mu_get_homedir ();
......
......@@ -94,7 +94,7 @@ mh_read_profile ()
p = getenv ("MH");
if (p)
p = mu_tilde_expansion (p, "/", NULL);
p = mu_tilde_expansion (p, MU_HIERARCHY_DELIMITER, NULL);
else
{
char *home = mu_get_homedir ();
......
......@@ -390,8 +390,8 @@ mh_audit_open (char *name, mu_mailbox_t mbox)
mu_url_t url;
char *namep;
namep = mu_tilde_expansion (name, "/", NULL);
if (strchr (namep, '/') == NULL)
namep = mu_tilde_expansion (name, MU_HIERARCHY_DELIMITER, NULL);
if (strchr (namep, MU_HIERARCHY_DELIMITER) == NULL)
{
char *p = mh_safe_make_file_name (mu_folder_directory (), namep);
free (namep);
......@@ -487,7 +487,7 @@ mh_expand_name (const char *base, const char *name, int is_folder)
char *p = NULL;
char *namep = NULL;
namep = mu_tilde_expansion (name, "/", NULL);
namep = mu_tilde_expansion (name, MU_HIERARCHY_DELIMITER, NULL);
if (namep[0] == '+')
memmove (namep, namep + 1, strlen (namep)); /* copy null byte as well */
else if (strncmp (namep, "../", 3) == 0 || strncmp (namep, "./", 2) == 0)
......@@ -536,7 +536,7 @@ mh_find_file (const char *name, char **resolved_name)
if (name[0] == '~')
{
s = mu_tilde_expansion (name, "/", NULL);
s = mu_tilde_expansion (name, MU_HIERARCHY_DELIMITER, NULL);
*resolved_name = s;
if (access (s, R_OK) == 0)
return 0;
......
......@@ -2961,7 +2961,8 @@ main (int argc, char **argv)
}
message = mh_file_to_message (NULL,
mu_tilde_expansion (input_file,
"/", NULL));
MU_HIERARCHY_DELIMITER,
NULL));
if (!message)
return 1;
}
......
......@@ -327,7 +327,7 @@ read_mts_profile ()
name = mh_expand_name (MHLIBDIR, "mtstailor", 0);
mts_profile = mh_read_property_file (name, 1);
name = mu_tilde_expansion ("~/.mtstailor", "/", NULL);
name = mu_tilde_expansion ("~/.mtstailor", MU_HIERARCHY_DELIMITER, NULL);
local_profile = mh_read_property_file (name, 1);
mh_property_merge (mts_profile, local_profile);
......
......@@ -296,7 +296,7 @@ get_history_file_name ()
strcpy (hname, "~/.mu_");
strcat (hname, rl_readline_name);
strcat (hname, HISTFILE_SUFFIX);
filename = mu_tilde_expansion (hname, "/", NULL);
filename = mu_tilde_expansion (hname, MU_HIERARCHY_DELIMITER, NULL);
free(hname);
}
return filename;
......
......@@ -141,7 +141,7 @@ mutool_wicket (int argc, char **argv)
return 1;
}
wicket_file = mu_tilde_expansion (wicket_file, "/", NULL);
wicket_file = mu_tilde_expansion (wicket_file, MU_HIERARCHY_DELIMITER, NULL);
if (!wicket_file)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_tilde_expansion", wicket_file,
......
......@@ -75,7 +75,8 @@ read_popbull_file (size_t *pnum)
{
int rc = 1;
FILE *fp;
char *filename = mu_tilde_expansion ("~/.popbull", "/", auth_data->dir);
char *filename = mu_tilde_expansion ("~/.popbull", MU_HIERARCHY_DELIMITER,
auth_data->dir);
if (!filename)
return 1;
......@@ -99,7 +100,8 @@ write_popbull_file (size_t num)
{
int rc = 1;
FILE *fp;
char *filename = mu_tilde_expansion ("~/.popbull", "/", auth_data->dir);
char *filename = mu_tilde_expansion ("~/.popbull", MU_HIERARCHY_DELIMITER,
auth_data->dir);
if (!filename)
return 1;
......
......@@ -231,7 +231,7 @@ parser (int key, char *arg, struct argp_state *state)
case ARGP_KEY_ARG:
if (script)
argp_error (state, _("Only one SCRIPT can be specified"));
script = mu_tilde_expansion (arg, "/", NULL);
script = mu_tilde_expansion (arg, MU_HIERARCHY_DELIMITER, NULL);
break;
case ARGP_KEY_INIT:
......