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) ...@@ -252,7 +252,7 @@ imap4d_append (struct imap4d_command *command, imap4d_tokbuf_t tok)
252 252
253 msg_text = imap4d_tokbuf_getarg (tok, i); 253 msg_text = imap4d_tokbuf_getarg (tok, i);
254 254
255 mboxname = namespace_getfullpath (mboxname, "/", NULL); 255 mboxname = namespace_getfullpath (mboxname, NULL);
256 if (!mboxname) 256 if (!mboxname)
257 return io_completion_response (command, RESP_NO, "Couldn't open mailbox"); 257 return io_completion_response (command, RESP_NO, "Couldn't open mailbox");
258 258
......
...@@ -232,7 +232,6 @@ imap4d_copy0 (imap4d_tokbuf_t tok, int isuid, char **err_text) ...@@ -232,7 +232,6 @@ imap4d_copy0 (imap4d_tokbuf_t tok, int isuid, char **err_text)
232 mu_list_t msglist; 232 mu_list_t msglist;
233 char *name; 233 char *name;
234 char *mailbox_name; 234 char *mailbox_name;
235 const char *delim = "/";
236 char *end; 235 char *end;
237 mu_mailbox_t cmbox = NULL; 236 mu_mailbox_t cmbox = NULL;
238 int arg = IMAP4_ARG_1 + !!isuid; 237 int arg = IMAP4_ARG_1 + !!isuid;
...@@ -256,7 +255,7 @@ imap4d_copy0 (imap4d_tokbuf_t tok, int isuid, char **err_text) ...@@ -256,7 +255,7 @@ imap4d_copy0 (imap4d_tokbuf_t tok, int isuid, char **err_text)
256 return RESP_BAD; 255 return RESP_BAD;
257 } 256 }
258 257
259 mailbox_name = namespace_getfullpath (name, delim, &ns); 258 mailbox_name = namespace_getfullpath (name, &ns);
260 259
261 if (!mailbox_name) 260 if (!mailbox_name)
262 { 261 {
......
...@@ -37,7 +37,6 @@ int ...@@ -37,7 +37,6 @@ int
37 imap4d_create (struct imap4d_command *command, imap4d_tokbuf_t tok) 37 imap4d_create (struct imap4d_command *command, imap4d_tokbuf_t tok)
38 { 38 {
39 char *name; 39 char *name;
40 const char *delim = "/";
41 int isdir = 0; 40 int isdir = 0;
42 int ns; 41 int ns;
43 int rc = RESP_OK; 42 int rc = RESP_OK;
...@@ -63,11 +62,11 @@ imap4d_create (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -63,11 +62,11 @@ imap4d_create (struct imap4d_command *command, imap4d_tokbuf_t tok)
63 The trailing delimiter will be removed by namespace normalizer, so 62 The trailing delimiter will be removed by namespace normalizer, so
64 test for it now. 63 test for it now.
65 */ 64 */
66 if (name[strlen (name) - 1] == delim[0]) 65 if (name[strlen (name) - 1] == MU_HIERARCHY_DELIMITER)
67 isdir = 1; 66 isdir = 1;
68 67
69 /* Allocates memory. */ 68 /* Allocates memory. */
70 name = namespace_getfullpath (name, delim, &ns); 69 name = namespace_getfullpath (name, &ns);
71 70
72 if (!name) 71 if (!name)
73 return io_completion_response (command, RESP_NO, "Cannot create mailbox"); 72 return io_completion_response (command, RESP_NO, "Cannot create mailbox");
...@@ -75,7 +74,7 @@ imap4d_create (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -75,7 +74,7 @@ imap4d_create (struct imap4d_command *command, imap4d_tokbuf_t tok)
75 /* It will fail if the mailbox already exists. */ 74 /* It will fail if the mailbox already exists. */
76 if (access (name, F_OK) != 0) 75 if (access (name, F_OK) != 0)
77 { 76 {
78 if (make_interdir (name, delim[0], MKDIR_PERMISSIONS)) 77 if (make_interdir (name, MU_HIERARCHY_DELIMITER, MKDIR_PERMISSIONS))
79 { 78 {
80 rc = RESP_NO; 79 rc = RESP_NO;
81 msg = "Cannot create mailbox"; 80 msg = "Cannot create mailbox";
......
...@@ -33,7 +33,6 @@ imap4d_delete (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -33,7 +33,6 @@ imap4d_delete (struct imap4d_command *command, imap4d_tokbuf_t tok)
33 { 33 {
34 int rc = RESP_OK; 34 int rc = RESP_OK;
35 const char *msg = "Completed"; 35 const char *msg = "Completed";
36 const char *delim = "/";
37 char *name; 36 char *name;
38 mu_mailbox_t tmpbox; 37 mu_mailbox_t tmpbox;
39 38
...@@ -49,7 +48,7 @@ imap4d_delete (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -49,7 +48,7 @@ imap4d_delete (struct imap4d_command *command, imap4d_tokbuf_t tok)
49 return io_completion_response (command, RESP_NO, "Already exist"); 48 return io_completion_response (command, RESP_NO, "Already exist");
50 49
51 /* Allocates memory. */ 50 /* Allocates memory. */
52 name = namespace_getfullpath (name, delim, NULL); 51 name = namespace_getfullpath (name, NULL);
53 if (!name) 52 if (!name)
54 return io_completion_response (command, RESP_NO, "Cannot remove"); 53 return io_completion_response (command, RESP_NO, "Cannot remove");
55 54
......
...@@ -325,7 +325,8 @@ imap4d_session_setup0 () ...@@ -325,7 +325,8 @@ imap4d_session_setup0 ()
325 325
326 if (modify_homedir) 326 if (modify_homedir)
327 { 327 {
328 char *expr = mu_tilde_expansion (modify_homedir, "/", real_homedir); 328 char *expr = mu_tilde_expansion (modify_homedir, MU_HIERARCHY_DELIMITER,
329 real_homedir);
329 struct mu_wordsplit ws; 330 struct mu_wordsplit ws;
330 const char *env[5]; 331 const char *env[5];
331 332
......
...@@ -350,10 +350,9 @@ extern mu_list_t namespace[NS_MAX]; ...@@ -350,10 +350,9 @@ extern mu_list_t namespace[NS_MAX];
350 350
351 extern int namespace_init_session (char *path); 351 extern int namespace_init_session (char *path);
352 extern void namespace_init (void); 352 extern void namespace_init (void);
353 extern char *namespace_getfullpath (const char *name, const char *delim, 353 extern char *namespace_getfullpath (const char *name, int *pns);
354 int *pns);
355 extern char *namespace_checkfullpath (const char *name, const char *pattern, 354 extern char *namespace_checkfullpath (const char *name, const char *pattern,
356 const char *delim, int *pns); 355 int *pns);
357 int imap4d_session_setup (char *username); 356 int imap4d_session_setup (char *username);
358 int imap4d_session_setup0 (void); 357 int imap4d_session_setup0 (void);
359 void imap4d_child_signal_setup (RETSIGTYPE (*handler) (int signo)); 358 void imap4d_child_signal_setup (RETSIGTYPE (*handler) (int signo));
...@@ -368,8 +367,7 @@ extern void imap4d_capability_init (void); ...@@ -368,8 +367,7 @@ extern void imap4d_capability_init (void);
368 extern int util_start (char *); 367 extern int util_start (char *);
369 extern int util_getstate (void); 368 extern int util_getstate (void);
370 extern int util_do_command (imap4d_tokbuf_t); 369 extern int util_do_command (imap4d_tokbuf_t);
371 extern char *util_tilde_expansion (const char *, const char *); 370 extern char *util_getfullpath (const char *);
372 extern char *util_getfullpath (const char *, const char *);
373 extern struct imap4d_command *util_getcommand (char *, 371 extern struct imap4d_command *util_getcommand (char *,
374 struct imap4d_command []); 372 struct imap4d_command []);
375 373
...@@ -397,9 +395,6 @@ extern int util_parse_ctime_date (const char *date, time_t *timep, ...@@ -397,9 +395,6 @@ extern int util_parse_ctime_date (const char *date, time_t *timep,
397 extern char *util_strcasestr (const char *haystack, const char *needle); 395 extern char *util_strcasestr (const char *haystack, const char *needle);
398 extern char *util_localname (void); 396 extern char *util_localname (void);
399 397
400 extern int util_wcard_match (const char *string, const char *pattern,
401 const char *delim);
402
403 void util_print_flags (mu_attribute_t attr); 398 void util_print_flags (mu_attribute_t attr);
404 int util_attribute_matches_flag (mu_attribute_t attr, const char *item); 399 int util_attribute_matches_flag (mu_attribute_t attr, const char *item);
405 int util_uidvalidity (mu_mailbox_t smbox, unsigned long *uidvp); 400 int util_uidvalidity (mu_mailbox_t smbox, unsigned long *uidvp);
......
...@@ -135,7 +135,6 @@ imap4d_list (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -135,7 +135,6 @@ imap4d_list (struct imap4d_command *command, imap4d_tokbuf_t tok)
135 { 135 {
136 char *ref; 136 char *ref;
137 char *wcard; 137 char *wcard;
138 const char *delim = "/";
139 138
140 if (imap4d_tokbuf_argc (tok) != 4) 139 if (imap4d_tokbuf_argc (tok) != 4)
141 return io_completion_response (command, RESP_BAD, "Invalid arguments"); 140 return io_completion_response (command, RESP_BAD, "Invalid arguments");
...@@ -147,9 +146,15 @@ imap4d_list (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -147,9 +146,15 @@ imap4d_list (struct imap4d_command *command, imap4d_tokbuf_t tok)
147 return the hierarchy. */ 146 return the hierarchy. */
148 if (*wcard == '\0') 147 if (*wcard == '\0')
149 { 148 {
149 if (*ref)
150 io_untagged_response (RESP_NONE, 150 io_untagged_response (RESP_NONE,
151 "LIST (\\NoSelect) \"%s\" \"%s\"", delim, 151 "LIST (\\NoSelect) \"%c\" \"%c\"",
152 (*ref) ? delim : ""); 152 MU_HIERARCHY_DELIMITER,
153 MU_HIERARCHY_DELIMITER);
154 else
155 io_untagged_response (RESP_NONE,
156 "LIST (\\NoSelect) \"%c\" \"\"",
157 MU_HIERARCHY_DELIMITER);
153 } 158 }
154 /* There is only one mailbox in the "INBOX" hierarchy ... INBOX. */ 159 /* There is only one mailbox in the "INBOX" hierarchy ... INBOX. */
155 else if (mu_c_strcasecmp (ref, "INBOX") == 0 160 else if (mu_c_strcasecmp (ref, "INBOX") == 0
...@@ -222,7 +227,7 @@ imap4d_list (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -222,7 +227,7 @@ imap4d_list (struct imap4d_command *command, imap4d_tokbuf_t tok)
222 } 227 }
223 228
224 /* Allocates. */ 229 /* Allocates. */
225 cwd = namespace_checkfullpath (ref, wcard, delim, NULL); 230 cwd = namespace_checkfullpath (ref, wcard, NULL);
226 if (!cwd) 231 if (!cwd)
227 { 232 {
228 free (ref); 233 free (ref);
...@@ -255,8 +260,9 @@ imap4d_list (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -255,8 +260,9 @@ imap4d_list (struct imap4d_command *command, imap4d_tokbuf_t tok)
255 failure; it is not relevant whether the user's real INBOX resides 260 failure; it is not relevant whether the user's real INBOX resides
256 on this or some other server. */ 261 on this or some other server. */
257 262
258 if (!*ref && (mu_imap_wildmatch (wcard, "INBOX", delim[0]) == 0 263 if (!*ref &&
259 || mu_imap_wildmatch (wcard, "inbox", delim[0]) == 0)) 264 (mu_imap_wildmatch (wcard, "INBOX", MU_HIERARCHY_DELIMITER) == 0
265 || mu_imap_wildmatch (wcard, "inbox", MU_HIERARCHY_DELIMITER) == 0))
260 io_untagged_response (RESP_NONE, "LIST (\\NoInferiors) NIL INBOX"); 266 io_untagged_response (RESP_NONE, "LIST (\\NoInferiors) NIL INBOX");
261 267
262 mu_folder_enumerate (folder, NULL, wcard, 0, 0, NULL, 268 mu_folder_enumerate (folder, NULL, wcard, 0, 0, NULL,
......
...@@ -37,7 +37,6 @@ imap4d_lsub (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -37,7 +37,6 @@ imap4d_lsub (struct imap4d_command *command, imap4d_tokbuf_t tok)
37 char *ref; 37 char *ref;
38 char *wcard; 38 char *wcard;
39 char *pattern; 39 char *pattern;
40 const char *delim = "/";
41 mu_property_t prop; 40 mu_property_t prop;
42 mu_iterator_t itr; 41 mu_iterator_t itr;
43 42
...@@ -64,9 +63,9 @@ imap4d_lsub (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -64,9 +63,9 @@ imap4d_lsub (struct imap4d_command *command, imap4d_tokbuf_t tok)
64 63
65 mu_iterator_current_kv (itr, (const void **)&name, (void**)&val); 64 mu_iterator_current_kv (itr, (const void **)&name, (void**)&val);
66 65
67 if (mu_imap_wildmatch (pattern, name, delim[0]) == 0) 66 if (mu_imap_wildmatch (pattern, name, MU_HIERARCHY_DELIMITER) == 0)
68 io_untagged_response (RESP_NONE, "LSUB () \"%s\" \"%s\"", 67 io_untagged_response (RESP_NONE, "LSUB () \"%c\" \"%s\"",
69 delim, name); 68 MU_HIERARCHY_DELIMITER, name);
70 } 69 }
71 } 70 }
72 else 71 else
......
...@@ -166,7 +166,7 @@ risky_pattern (const char *pattern, int delim) ...@@ -166,7 +166,7 @@ risky_pattern (const char *pattern, int delim)
166 166
167 char * 167 char *
168 namespace_checkfullpath (const char *name, const char *pattern, 168 namespace_checkfullpath (const char *name, const char *pattern,
169 const char *delim, int *nspace) 169 int *nspace)
170 { 170 {
171 struct namespace_info info; 171 struct namespace_info info;
172 const char *p; 172 const char *p;
...@@ -185,7 +185,7 @@ namespace_checkfullpath (const char *name, const char *pattern, ...@@ -185,7 +185,7 @@ namespace_checkfullpath (const char *name, const char *pattern,
185 name = p + 1; 185 name = p + 1;
186 } 186 }
187 187
188 path = util_getfullpath (name, delim); 188 path = util_getfullpath (name);
189 if (!path) 189 if (!path)
190 { 190 {
191 free (scheme); 191 free (scheme);
...@@ -226,7 +226,7 @@ namespace_checkfullpath (const char *name, const char *pattern, ...@@ -226,7 +226,7 @@ namespace_checkfullpath (const char *name, const char *pattern,
226 } 226 }
227 227
228 char * 228 char *
229 namespace_getfullpath (const char *name, const char *delim, int *nspace) 229 namespace_getfullpath (const char *name, int *nspace)
230 { 230 {
231 char *ret; 231 char *ret;
232 if (mu_c_strcasecmp (name, "INBOX") == 0 && auth_data->change_uid) 232 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) ...@@ -236,7 +236,7 @@ namespace_getfullpath (const char *name, const char *delim, int *nspace)
236 *nspace = NS_PRIVATE; 236 *nspace = NS_PRIVATE;
237 } 237 }
238 else 238 else
239 ret = namespace_checkfullpath (name, NULL, delim, nspace); 239 ret = namespace_checkfullpath (name, NULL, nspace);
240 return ret; 240 return ret;
241 } 241 }
242 242
......
...@@ -138,7 +138,7 @@ quota_check (mu_off_t size) ...@@ -138,7 +138,7 @@ quota_check (mu_off_t size)
138 138
139 total = used_size; 139 total = used_size;
140 140
141 mailbox_name = namespace_getfullpath ("INBOX", "/", NULL); 141 mailbox_name = namespace_getfullpath ("INBOX", NULL);
142 rc = mu_mailbox_create (&mbox, mailbox_name); 142 rc = mu_mailbox_create (&mbox, mailbox_name);
143 if (rc) 143 if (rc)
144 { 144 {
......
...@@ -110,7 +110,6 @@ imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -110,7 +110,6 @@ imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok)
110 int rc = RESP_OK; 110 int rc = RESP_OK;
111 const char *msg = "Completed"; 111 const char *msg = "Completed";
112 struct stat newst; 112 struct stat newst;
113 const char *delim = "/";
114 int ns; 113 int ns;
115 114
116 if (imap4d_tokbuf_argc (tok) != 4) 115 if (imap4d_tokbuf_argc (tok) != 4)
...@@ -123,7 +122,7 @@ imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -123,7 +122,7 @@ imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok)
123 return io_completion_response (command, RESP_NO, "Name Inbox is reservered"); 122 return io_completion_response (command, RESP_NO, "Name Inbox is reservered");
124 123
125 /* Allocates memory. */ 124 /* Allocates memory. */
126 newname = namespace_getfullpath (newname, delim, &ns); 125 newname = namespace_getfullpath (newname, &ns);
127 if (!newname) 126 if (!newname)
128 return io_completion_response (command, RESP_NO, "Permission denied"); 127 return io_completion_response (command, RESP_NO, "Permission denied");
129 128
...@@ -140,7 +139,7 @@ imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -140,7 +139,7 @@ imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok)
140 } 139 }
141 } 140 }
142 141
143 if (make_interdir (newname, delim[0], MKDIR_PERMISSIONS)) 142 if (make_interdir (newname, MU_HIERARCHY_DELIMITER, MKDIR_PERMISSIONS))
144 { 143 {
145 free (newname); 144 free (newname);
146 return io_completion_response (command, RESP_NO, "Cannot rename"); 145 return io_completion_response (command, RESP_NO, "Cannot rename");
...@@ -202,7 +201,7 @@ imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -202,7 +201,7 @@ imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok)
202 return io_completion_response (command, RESP_OK, "Rename successful"); 201 return io_completion_response (command, RESP_OK, "Rename successful");
203 } 202 }
204 203
205 oldname = namespace_getfullpath (oldname, delim, NULL); 204 oldname = namespace_getfullpath (oldname, NULL);
206 205
207 /* It must exist. */ 206 /* It must exist. */
208 /* FIXME: 1. What if odlname or newname is a remote mailbox? 207 /* FIXME: 1. What if odlname or newname is a remote mailbox?
......
...@@ -58,7 +58,7 @@ imap4d_select0 (struct imap4d_command *command, const char *mboxname, ...@@ -58,7 +58,7 @@ imap4d_select0 (struct imap4d_command *command, const char *mboxname,
58 58
59 if (strcmp (mboxname, "INBOX") == 0) 59 if (strcmp (mboxname, "INBOX") == 0)
60 flags |= MU_STREAM_CREAT; 60 flags |= MU_STREAM_CREAT;
61 mailbox_name = namespace_getfullpath (mboxname, "/", NULL); 61 mailbox_name = namespace_getfullpath (mboxname, NULL);
62 62
63 if (!mailbox_name) 63 if (!mailbox_name)
64 return io_completion_response (command, RESP_NO, "Couldn't open mailbox"); 64 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) ...@@ -69,7 +69,6 @@ imap4d_status (struct imap4d_command *command, imap4d_tokbuf_t tok)
69 { 69 {
70 char *name; 70 char *name;
71 char *mailbox_name; 71 char *mailbox_name;
72 const char *delim = "/";
73 mu_mailbox_t smbox = NULL; 72 mu_mailbox_t smbox = NULL;
74 int status; 73 int status;
75 int count = 0; 74 int count = 0;
...@@ -81,7 +80,7 @@ imap4d_status (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -81,7 +80,7 @@ imap4d_status (struct imap4d_command *command, imap4d_tokbuf_t tok)
81 80
82 name = imap4d_tokbuf_getarg (tok, IMAP4_ARG_1); 81 name = imap4d_tokbuf_getarg (tok, IMAP4_ARG_1);
83 82
84 mailbox_name = namespace_getfullpath (name, delim, NULL); 83 mailbox_name = namespace_getfullpath (name, NULL);
85 84
86 if (!mailbox_name) 85 if (!mailbox_name)
87 return io_completion_response (command, RESP_NO, "Error opening mailbox"); 86 return io_completion_response (command, RESP_NO, "Error opening mailbox");
......
...@@ -17,28 +17,21 @@ ...@@ -17,28 +17,21 @@
17 17
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 /* NOTE: Allocates Memory. */
21 /* Expand: ~ --> /home/user, and ~guest --> /home/guest. */
22 char *
23 util_tilde_expansion (const char *ref, const char *delim)
24 {
25 return mu_tilde_expansion (ref, delim, imap4d_homedir);
26 }
27
28 /* Get the absolute path. */ 20 /* Get the absolute path. */
29 /* NOTE: Path is allocated and must be free()d by the caller. */ 21 /* NOTE: Path is allocated and must be free()d by the caller. */
30 char * 22 char *
31 util_getfullpath (const char *name, const char *delim) 23 util_getfullpath (const char *name)
32 { 24 {
33 char *exp = util_tilde_expansion (name, delim); 25 char *exp = mu_tilde_expansion (name, MU_HIERARCHY_DELIMITER,
34 if (*exp != delim[0]) 26 imap4d_homedir);
27 if (*exp != MU_HIERARCHY_DELIMITER)
35 { 28 {
36 char *p, *s = 29 char *p, *s =
37 malloc (strlen (imap4d_homedir) + strlen (delim) + strlen (exp) + 1); 30 malloc (strlen (imap4d_homedir) + 1 + strlen (exp) + 1);
38 if (!s) 31 if (!s)
39 imap4d_bye (ERR_NO_MEM); 32 imap4d_bye (ERR_NO_MEM);
40 p = mu_stpcpy (s, imap4d_homedir); 33 p = mu_stpcpy (s, imap4d_homedir);
41 p = mu_stpcpy (p, (char*) delim); 34 *p++ = MU_HIERARCHY_DELIMITER;
42 strcpy (p, exp); 35 strcpy (p, exp);
43 free (exp); 36 free (exp);
44 exp = s; 37 exp = s;
......
...@@ -47,11 +47,14 @@ int mu_str_url_decode (char **ptr, const char *s); ...@@ -47,11 +47,14 @@ int mu_str_url_decode (char **ptr, const char *s);
47 /* ----------------------- */ 47 /* ----------------------- */
48 /* File & path names. */ 48 /* File & path names. */
49 /* ----------------------- */ 49 /* ----------------------- */
50
51 #define MU_HIERARCHY_DELIMITER '/'
52
50 char *mu_get_homedir (void); 53 char *mu_get_homedir (void);
51 char *mu_get_full_path (const char *file); 54 char *mu_get_full_path (const char *file);
52 char *mu_normalize_path (char *path); 55 char *mu_normalize_path (char *path);
53 char *mu_expand_path_pattern (const char *pattern, const char *username); 56 char *mu_expand_path_pattern (const char *pattern, const char *username);
54 char *mu_tilde_expansion (const char *ref, const char *delim, 57 char *mu_tilde_expansion (const char *ref, int delim,
55 const char *homedir); 58 const char *homedir);
56 int mu_readlink (const char *name, char **pbuf, size_t *psize, size_t *plen); 59 int mu_readlink (const char *name, char **pbuf, size_t *psize, size_t *plen);
57 int mu_unroll_symlink (const char *name, char **pout); 60 int mu_unroll_symlink (const char *name, char **pout);
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
31 /* NOTE: Allocates Memory. */ 31 /* NOTE: Allocates Memory. */
32 /* Expand: ~ --> /home/user and to ~guest --> /home/guest. */ 32 /* Expand: ~ --> /home/user and to ~guest --> /home/guest. */
33 char * 33 char *
34 mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) 34 mu_tilde_expansion (const char *ref, int delim, const char *homedir)
35 { 35 {
36 char *base = strdup (ref); 36 char *base = strdup (ref);
37 char *home = NULL; 37 char *home = NULL;
...@@ -52,9 +52,9 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) ...@@ -52,9 +52,9 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
52 memcpy (proto, base, proto_len); 52 memcpy (proto, base, proto_len);
53 proto[proto_len] = 0; 53 proto[proto_len] = 0;
54 /* Allow for extra pair of slashes after the protocol specifier */ 54 /* Allow for extra pair of slashes after the protocol specifier */
55 if (*p == delim[0]) 55 if (*p == delim)
56 p++; 56 p++;
57 if (*p == delim[0]) 57 if (*p == delim)
58 p++; 58 p++;
59 } 59 }
60 else 60 else
...@@ -63,7 +63,7 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) ...@@ -63,7 +63,7 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
63 if (*p == '~') 63 if (*p == '~')
64 { 64 {
65 p++; 65 p++;
66 if (*p == delim[0] || *p == '\0') 66 if (*p == delim || *p == '\0')
67 { 67 {
68 char *s; 68 char *s;
69 if (!homedir) 69 if (!homedir)
...@@ -88,7 +88,7 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) ...@@ -88,7 +88,7 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
88 struct mu_auth_data *auth; 88 struct mu_auth_data *auth;
89 char *s = p; 89 char *s = p;
90 char *name; 90 char *name;
91 while (*s && *s != delim[0]) 91 while (*s && *s != delim)
92 s++; 92 s++;
93 name = calloc (s - p + 1, 1); 93 name = calloc (s - p + 1, 1);
94 memcpy (name, p, s - p); 94 memcpy (name, p, s - p);
......
...@@ -503,7 +503,7 @@ mu_parse_config (const char *file, const char *progname, ...@@ -503,7 +503,7 @@ mu_parse_config (const char *file, const char *progname,
503 void *target_ptr) 503 void *target_ptr)
504 { 504 {
505 int rc; 505 int rc;
506 char *full_name = mu_tilde_expansion (file, "/", NULL); 506 char *full_name = mu_tilde_expansion (file, MU_HIERARCHY_DELIMITER, NULL);
507 if (full_name) 507 if (full_name)
508 { 508 {
509 if (access (full_name, R_OK) == 0) 509 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) ...@@ -326,7 +326,7 @@ mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file, int flags)
326 struct stat st; 326 struct stat st;
327 FILE *fp; 327 FILE *fp;
328 int rc; 328 int rc;
329 char *full_name = mu_tilde_expansion (file, "/", NULL); 329 char *full_name = mu_tilde_expansion (file, MU_HIERARCHY_DELIMITER, NULL);
330 330
331 if (stat (full_name, &st)) 331 if (stat (full_name, &st))
332 { 332 {
......
...@@ -345,7 +345,8 @@ attach_auth_ticket (mu_mailbox_t mbox) ...@@ -345,7 +345,8 @@ attach_auth_ticket (mu_mailbox_t mbox)
345 && mu_folder_get_authority (folder, &auth) == 0 345 && mu_folder_get_authority (folder, &auth) == 0
346 && auth) 346 && auth)
347 { 347 {
348 char *filename = mu_tilde_expansion (mu_ticket_file, "/", NULL); 348 char *filename = mu_tilde_expansion (mu_ticket_file,
349 MU_HIERARCHY_DELIMITER, NULL);
349 mu_wicket_t wicket; 350 mu_wicket_t wicket;
350 int rc; 351 int rc;
351 352
...@@ -420,7 +421,7 @@ mu_mailbox_create_default (mu_mailbox_t *pmbox, const char *mail) ...@@ -420,7 +421,7 @@ mu_mailbox_create_default (mu_mailbox_t *pmbox, const char *mail)
420 } 421 }
421 } 422 }
422 423
423 p = mu_tilde_expansion (mail, "/", NULL); 424 p = mu_tilde_expansion (mail, MU_HIERARCHY_DELIMITER, NULL);
424 if (tmp_mbox) 425 if (tmp_mbox)
425 free (tmp_mbox); 426 free (tmp_mbox);
426 tmp_mbox = p; 427 tmp_mbox = p;
......
...@@ -348,7 +348,7 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from) ...@@ -348,7 +348,7 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from)
348 else 348 else
349 days = DAYS_DEFAULT; 349 days = DAYS_DEFAULT;
350 350
351 file = mu_tilde_expansion ("~/.vacation", "/", NULL); 351 file = mu_tilde_expansion ("~/.vacation", MU_HIERARCHY_DELIMITER, NULL);
352 if (!file) 352 if (!file)
353 { 353 {
354 mu_sieve_error (mach, _("%lu: cannot build db file name"), 354 mu_sieve_error (mach, _("%lu: cannot build db file name"),
......
...@@ -32,7 +32,8 @@ ...@@ -32,7 +32,8 @@
32 static int 32 static int
33 get_ticket (mu_ticket_t *pticket) 33 get_ticket (mu_ticket_t *pticket)
34 { 34 {
35 char *filename = mu_tilde_expansion (mu_ticket_file, "/", NULL); 35 char *filename = mu_tilde_expansion (mu_ticket_file,
36 MU_HIERARCHY_DELIMITER, NULL);
36 mu_wicket_t wicket; 37 mu_wicket_t wicket;
37 int rc; 38 int rc;
38 39
......
...@@ -475,7 +475,7 @@ util_get_homedir () ...@@ -475,7 +475,7 @@ util_get_homedir ()
475 char * 475 char *
476 util_fullpath (const char *inpath) 476 util_fullpath (const char *inpath)
477 { 477 {
478 return mu_tilde_expansion (inpath, "/", NULL); 478 return mu_tilde_expansion (inpath, MU_HIERARCHY_DELIMITER, NULL);
479 } 479 }
480 480
481 char * 481 char *
......
...@@ -69,7 +69,7 @@ main (int argc, char **argv) ...@@ -69,7 +69,7 @@ main (int argc, char **argv)
69 69
70 name = getenv ("MH"); 70 name = getenv ("MH");
71 if (name) 71 if (name)
72 name = mu_tilde_expansion (name, "/", NULL); 72 name = mu_tilde_expansion (name, MU_HIERARCHY_DELIMITER, NULL);
73 else 73 else
74 { 74 {
75 char *home = mu_get_homedir (); 75 char *home = mu_get_homedir ();
......
...@@ -94,7 +94,7 @@ mh_read_profile () ...@@ -94,7 +94,7 @@ mh_read_profile ()
94 94
95 p = getenv ("MH"); 95 p = getenv ("MH");
96 if (p) 96 if (p)
97 p = mu_tilde_expansion (p, "/", NULL); 97 p = mu_tilde_expansion (p, MU_HIERARCHY_DELIMITER, NULL);
98 else 98 else
99 { 99 {
100 char *home = mu_get_homedir (); 100 char *home = mu_get_homedir ();
......
...@@ -390,8 +390,8 @@ mh_audit_open (char *name, mu_mailbox_t mbox) ...@@ -390,8 +390,8 @@ mh_audit_open (char *name, mu_mailbox_t mbox)
390 mu_url_t url; 390 mu_url_t url;
391 char *namep; 391 char *namep;
392 392
393 namep = mu_tilde_expansion (name, "/", NULL); 393 namep = mu_tilde_expansion (name, MU_HIERARCHY_DELIMITER, NULL);
394 if (strchr (namep, '/') == NULL) 394 if (strchr (namep, MU_HIERARCHY_DELIMITER) == NULL)
395 { 395 {
396 char *p = mh_safe_make_file_name (mu_folder_directory (), namep); 396 char *p = mh_safe_make_file_name (mu_folder_directory (), namep);
397 free (namep); 397 free (namep);
...@@ -487,7 +487,7 @@ mh_expand_name (const char *base, const char *name, int is_folder) ...@@ -487,7 +487,7 @@ mh_expand_name (const char *base, const char *name, int is_folder)
487 char *p = NULL; 487 char *p = NULL;
488 char *namep = NULL; 488 char *namep = NULL;
489 489
490 namep = mu_tilde_expansion (name, "/", NULL); 490 namep = mu_tilde_expansion (name, MU_HIERARCHY_DELIMITER, NULL);
491 if (namep[0] == '+') 491 if (namep[0] == '+')
492 memmove (namep, namep + 1, strlen (namep)); /* copy null byte as well */ 492 memmove (namep, namep + 1, strlen (namep)); /* copy null byte as well */
493 else if (strncmp (namep, "../", 3) == 0 || strncmp (namep, "./", 2) == 0) 493 else if (strncmp (namep, "../", 3) == 0 || strncmp (namep, "./", 2) == 0)
...@@ -536,7 +536,7 @@ mh_find_file (const char *name, char **resolved_name) ...@@ -536,7 +536,7 @@ mh_find_file (const char *name, char **resolved_name)
536 536
537 if (name[0] == '~') 537 if (name[0] == '~')
538 { 538 {
539 s = mu_tilde_expansion (name, "/", NULL); 539 s = mu_tilde_expansion (name, MU_HIERARCHY_DELIMITER, NULL);
540 *resolved_name = s; 540 *resolved_name = s;
541 if (access (s, R_OK) == 0) 541 if (access (s, R_OK) == 0)
542 return 0; 542 return 0;
......
...@@ -2961,7 +2961,8 @@ main (int argc, char **argv) ...@@ -2961,7 +2961,8 @@ main (int argc, char **argv)
2961 } 2961 }
2962 message = mh_file_to_message (NULL, 2962 message = mh_file_to_message (NULL,
2963 mu_tilde_expansion (input_file, 2963 mu_tilde_expansion (input_file,
2964 "/", NULL)); 2964 MU_HIERARCHY_DELIMITER,
2965 NULL));
2965 if (!message) 2966 if (!message)
2966 return 1; 2967 return 1;
2967 } 2968 }
......
...@@ -327,7 +327,7 @@ read_mts_profile () ...@@ -327,7 +327,7 @@ read_mts_profile ()
327 name = mh_expand_name (MHLIBDIR, "mtstailor", 0); 327 name = mh_expand_name (MHLIBDIR, "mtstailor", 0);
328 mts_profile = mh_read_property_file (name, 1); 328 mts_profile = mh_read_property_file (name, 1);
329 329
330 name = mu_tilde_expansion ("~/.mtstailor", "/", NULL); 330 name = mu_tilde_expansion ("~/.mtstailor", MU_HIERARCHY_DELIMITER, NULL);
331 local_profile = mh_read_property_file (name, 1); 331 local_profile = mh_read_property_file (name, 1);
332 332
333 mh_property_merge (mts_profile, local_profile); 333 mh_property_merge (mts_profile, local_profile);
......
...@@ -296,7 +296,7 @@ get_history_file_name () ...@@ -296,7 +296,7 @@ get_history_file_name ()
296 strcpy (hname, "~/.mu_"); 296 strcpy (hname, "~/.mu_");
297 strcat (hname, rl_readline_name); 297 strcat (hname, rl_readline_name);
298 strcat (hname, HISTFILE_SUFFIX); 298 strcat (hname, HISTFILE_SUFFIX);
299 filename = mu_tilde_expansion (hname, "/", NULL); 299 filename = mu_tilde_expansion (hname, MU_HIERARCHY_DELIMITER, NULL);
300 free(hname); 300 free(hname);
301 } 301 }
302 return filename; 302 return filename;
......
...@@ -141,7 +141,7 @@ mutool_wicket (int argc, char **argv) ...@@ -141,7 +141,7 @@ mutool_wicket (int argc, char **argv)
141 return 1; 141 return 1;
142 } 142 }
143 143
144 wicket_file = mu_tilde_expansion (wicket_file, "/", NULL); 144 wicket_file = mu_tilde_expansion (wicket_file, MU_HIERARCHY_DELIMITER, NULL);
145 if (!wicket_file) 145 if (!wicket_file)
146 { 146 {
147 mu_diag_funcall (MU_DIAG_ERROR, "mu_tilde_expansion", wicket_file, 147 mu_diag_funcall (MU_DIAG_ERROR, "mu_tilde_expansion", wicket_file,
......
...@@ -75,7 +75,8 @@ read_popbull_file (size_t *pnum) ...@@ -75,7 +75,8 @@ read_popbull_file (size_t *pnum)
75 { 75 {
76 int rc = 1; 76 int rc = 1;
77 FILE *fp; 77 FILE *fp;
78 char *filename = mu_tilde_expansion ("~/.popbull", "/", auth_data->dir); 78 char *filename = mu_tilde_expansion ("~/.popbull", MU_HIERARCHY_DELIMITER,
79 auth_data->dir);
79 80
80 if (!filename) 81 if (!filename)
81 return 1; 82 return 1;
...@@ -99,7 +100,8 @@ write_popbull_file (size_t num) ...@@ -99,7 +100,8 @@ write_popbull_file (size_t num)
99 { 100 {
100 int rc = 1; 101 int rc = 1;
101 FILE *fp; 102 FILE *fp;
102 char *filename = mu_tilde_expansion ("~/.popbull", "/", auth_data->dir); 103 char *filename = mu_tilde_expansion ("~/.popbull", MU_HIERARCHY_DELIMITER,
104 auth_data->dir);
103 105
104 if (!filename) 106 if (!filename)
105 return 1; 107 return 1;
......
...@@ -231,7 +231,7 @@ parser (int key, char *arg, struct argp_state *state) ...@@ -231,7 +231,7 @@ parser (int key, char *arg, struct argp_state *state)
231 case ARGP_KEY_ARG: 231 case ARGP_KEY_ARG:
232 if (script) 232 if (script)
233 argp_error (state, _("Only one SCRIPT can be specified")); 233 argp_error (state, _("Only one SCRIPT can be specified"));
234 script = mu_tilde_expansion (arg, "/", NULL); 234 script = mu_tilde_expansion (arg, MU_HIERARCHY_DELIMITER, NULL);
235 break; 235 break;
236 236
237 case ARGP_KEY_INIT: 237 case ARGP_KEY_INIT:
......