Commit 36656d1f 36656d1f5af44810ca63fe3c97c7a56c0bc19173 by Sergey Poznyakoff

Fix hex (%XX) expansion in URLs.

* mailbox/url.c (url_parse0): Take three arguments.  Return in the
third one a boolean indicating whether to expand %XX notations in
the URL.  Do not decode absolute file names and pipes.
(mu_url_parse): Use this value to decide.
* movemail/movemail.c (main): In emacs mode: force UNIX mbox
format as a default.  Send debugging output to stderr.
* libmailutils/tests/url.at: Add new tests.
1 parent c42bddb0
......@@ -24,7 +24,7 @@ m4_pushdef([TESTURL],[
m4_pushdef([MU_TEST_GROUP],[Url])
m4_pushdef([MU_TEST_KEYWORDS],[url])
m4_pushdef([MU_TEST_COMMAND],[url-parse])
MU_GENERIC_TEST([$1],[$2],[$3],[],[$4],[$5])
MU_GENERIC_TEST([$1],[$2 url-m4_translit($3,[ ],[_])],[$3],[],[$4],[$5])
m4_popdef([MU_TEST_COMMAND])
m4_popdef([MU_TEST_KEYWORDS])
m4_popdef([MU_TEST_GROUP])
......@@ -774,4 +774,40 @@ query[1] <arg 1>
query[2] <arg 2>
]])
TESTURL([],[],
[/usr/sbin/sendmail],
[scheme <file>
user <>
passwd <>
auth <>
host <>
port 0
path </usr/sbin/sendmail>
])
TESTURL([],[],
[/var/spool/mail/gray%40gnu.org],
[scheme <file>
user <>
passwd <>
auth <>
host <>
port 0
path </var/spool/mail/gray%40gnu.org>
])
TESTURL([],[],
[| /bin/mailman request list%40dom],
[[scheme <prog>
user <>
passwd <>
auth <>
host <>
port 0
path </bin/mailman>
query[0] </bin/mailman>
query[1] <request>
query[2] <list%40dom>
]])
m4_popdef([TESTURL])
......
......@@ -40,7 +40,7 @@
#define AC2(a,b) a ## b
#define AC4(a,b,c,d) a ## b ## c ## d
static int url_parse0 (mu_url_t, char *, size_t *poff);
static int url_parse0 (mu_url_t, char *, size_t *poff, int *decode);
static int
parse_query (const char *query,
......@@ -286,7 +286,8 @@ mu_url_parse (mu_url_t url)
struct _mu_url u;
size_t pstart;
mu_secret_t newsec;
int want_decode;
if (!url || !url->name)
return EINVAL;
......@@ -301,7 +302,7 @@ mu_url_parse (mu_url_t url)
if (!n)
return ENOMEM;
err = url_parse0 (&u, n, &pstart);
err = url_parse0 (&u, n, &pstart, &want_decode);
if (!err)
{
......@@ -331,17 +332,18 @@ mu_url_parse (mu_url_t url)
though.
*/
#define UALLOC(X) \
if (u.X && u.X[0] && (url->X = mu_url_decode(u.X)) == 0) \
{ \
err = ENOMEM; \
goto CLEANUP; \
} \
else \
{ \
/* Set zero-length strings to NULL. */ \
u.X = NULL; \
}
#define UALLOC(X) \
if (u.X && u.X[0] && \
!(url->X = (want_decode ? mu_url_decode (u.X) : strdup (u.X)))) \
{ \
err = ENOMEM; \
goto CLEANUP; \
} \
else \
{ \
/* Set zero-length strings to NULL. */ \
u.X = NULL; \
}
UALLOC (scheme);
UALLOC (user);
......@@ -420,7 +422,7 @@ Is this required to be % quoted, though? I hope so!
*/
static int
url_parse0 (mu_url_t u, char *name, size_t *poff)
url_parse0 (mu_url_t u, char *name, size_t *poff, int *decode)
{
char *start = name;
char *p; /* pointer into name */
......@@ -432,11 +434,13 @@ url_parse0 (mu_url_t u, char *name, size_t *poff)
if (name[0] == '/')
{
u->scheme = "file";
*decode = 0;
}
else if (name[0] == '|')
{
int rc;
u->scheme = "prog";
*decode = 0;
rc = mu_argcv_get (name + 1, NULL, NULL, &u->qargc, &u->qargv);
if (rc == 0)
{
......@@ -448,6 +452,7 @@ url_parse0 (mu_url_t u, char *name, size_t *poff)
}
else
{
*decode = 1;
/* Parse out the SCHEME. */
p = strchr (name, ':');
if (p == NULL)
......
......@@ -759,6 +759,14 @@ main (int argc, char **argv)
return 1;
}
if (emacs_mode)
{
/* Undo the effect of configuration options that may affect
the interaction with Emacs. */
mu_registrar_set_default_record (mu_mbox_record);
mu_debug_default_printer = mu_debug_stderr_printer;
}
atexit (close_mailboxes);
source_name = argv[0];
......