summaryrefslogtreecommitdiff
path: root/libmailutils/url/create.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-02-26 18:27:30 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2012-02-26 18:27:30 +0200
commitfb53814d3acb7a08cd849ffbbdbe86d8a374590c (patch)
tree54c9df9b74ecb6e869309399af32c8b03973cee2 /libmailutils/url/create.c
parent8c0c0bfc2d565c70d0af0dcd7f1baa271a638661 (diff)
downloadmailutils-fb53814d3acb7a08cd849ffbbdbe86d8a374590c.tar.gz
mailutils-fb53814d3acb7a08cd849ffbbdbe86d8a374590c.tar.bz2
Fix parsing local URLs.
* include/mailutils/url.h (MU_URL_PARSE_LOCAL): New flag. * libmailutils/tests/url-parse.c (parse_kwtab): New flag "local". * libmailutils/tests/url.at: Add new tests * libmailutils/url/create.c (_mu_url_ctx_parse_host): Skip parsing host part if MU_URL_PARSE_LOCAL is set. (_mu_url_create_internal): Initialize rc. If MU_URL_PARSE_SLASH is set and URL begins with "./" assume it is file. If either MU_URL_PARSE_SLASH or MU_URL_PARSE_PIPE are given and the URL is diagnosed as file or pipe, prever the scheme from hints.
Diffstat (limited to 'libmailutils/url/create.c')
-rw-r--r--libmailutils/url/create.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/libmailutils/url/create.c b/libmailutils/url/create.c
index 6027545b9..0c7347b4f 100644
--- a/libmailutils/url/create.c
+++ b/libmailutils/url/create.c
@@ -220,6 +220,9 @@ _mu_url_ctx_parse_host (struct mu_url_ctx *ctx, int has_host)
int rc;
mu_url_t url = ctx->url;
+ if (ctx->flags & MU_URL_PARSE_LOCAL)
+ return _mu_url_ctx_parse_path (ctx);
+
rc = getkn (ctx, "[:/;?");
if (rc)
return rc;
@@ -400,18 +403,16 @@ _mu_url_ctx_parse (struct mu_url_ctx *ctx)
static int
_mu_url_create_internal (struct mu_url_ctx *ctx, mu_url_t hint)
{
- int rc;
+ int rc = 0;
mu_url_t url = ctx->url;
-
+ const char *scheme = NULL;
+
if ((ctx->flags & MU_URL_PARSE_PIPE) && ctx->input[0] == '|')
{
struct mu_wordsplit ws;
size_t i;
- rc = str_assign (&url->scheme, "prog");
- if (rc)
- return rc;
- url->flags |= MU_URL_SCHEME;
+ scheme = "prog";
ctx->flags &= ~MU_URL_PARSE_HEXCODE;
if (mu_wordsplit (ctx->input + 1, &ws, MU_WRDSF_DEFFLAGS))
return errno;
@@ -431,12 +432,11 @@ _mu_url_create_internal (struct mu_url_ctx *ctx, mu_url_t hint)
mu_wordsplit_free (&ws);
url->flags |= MU_URL_QUERY;
}
- else if ((ctx->flags & MU_URL_PARSE_SLASH) && ctx->input[0] == '/')
+ else if ((ctx->flags & MU_URL_PARSE_SLASH) &&
+ (ctx->input[0] == '/' ||
+ (ctx->input[0] == '.' && ctx->input[1] == '/')))
{
- rc = str_assign (&url->scheme, "file");
- if (rc)
- return rc;
- url->flags |= MU_URL_SCHEME;
+ scheme = "file";
ctx->flags &= ~MU_URL_PARSE_HEXCODE;
rc = str_assign (&url->path, ctx->input);
if (rc == 0)
@@ -457,7 +457,17 @@ _mu_url_create_internal (struct mu_url_ctx *ctx, mu_url_t hint)
}
if (!(url->flags & MU_URL_SCHEME))
- return MU_ERR_URL_MISS_PARTS;
+ {
+ if (scheme)
+ {
+ rc = str_assign (&url->scheme, scheme);
+ if (rc)
+ return rc;
+ url->flags |= MU_URL_SCHEME;
+ }
+ else
+ return MU_ERR_URL_MISS_PARTS;
+ }
/* RFC 1738, section 2.1, lower the scheme case */
mu_strlower (url->scheme);

Return to:

Send suggestions and report system problems to the System administrator.