summaryrefslogtreecommitdiff
path: root/libmailutils/url
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-03-30 00:49:43 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-03-30 15:51:47 +0300
commitadca074d616ac562095a92e01f2b181e6d3593c8 (patch)
treef4c11a1c11fcb137cfada7643e6f284465a75c16 /libmailutils/url
parent827cb66a4c639139c3f11c7af26aa5149f25a7e0 (diff)
downloadmailutils-adca074d616ac562095a92e01f2b181e6d3593c8.tar.gz
mailutils-adca074d616ac562095a92e01f2b181e6d3593c8.tar.bz2
Implement IPv6 support.
* am/ipv6.m4: New file. * examples/sa.c: New file. * include/mailutils/cidr.h: New file. * include/mailutils/sockaddr.h: New file. * libmailutils/cidr/Makefile.am: New file. * libmailutils/cidr/fromsa.c: New file. * libmailutils/cidr/fromstr.c: New file. * libmailutils/cidr/match.c: New file. * libmailutils/cidr/tosa.c: New file. * libmailutils/cidr/tostr.c: New file. * libmailutils/sockaddr/Makefile.am: New file. * libmailutils/sockaddr/copy.c: New file. * libmailutils/sockaddr/create.c: New file. * libmailutils/sockaddr/free.c: New file. * libmailutils/sockaddr/fromnode.c: New file. * libmailutils/sockaddr/insert.c: New file. * libmailutils/sockaddr/ipaddr.c: New file. * libmailutils/sockaddr/str.c: New file. * libmailutils/sockaddr/unlink.c: New file. * libmailutils/sockaddr/url.c: New file. * libmailutils/tests/cidr.c: New file. * configure.ac: Call MU_ENABLE_IPV6. Build libmailutils/sockaddr and libmailutils/cidr. * examples/.gitignore: Add mblconv and sa * examples/Makefile.am: (noinst_PROGRAMS): Add sa. * examples/aclck.c: Use new ACL API. * examples/echosrv.c: Use new mserv API. * include/mailutils/Makefile.am (pkginclude_HEADERS): Add cidr.h and sockaddr.h * include/mailutils/acl.h (mu_acl_append, mu_acl_prepend) (mu_acl_insert): Change signatures. * include/mailutils/debug.h (mu_sockaddr_to_str): Remove proto. * include/mailutils/mailutils.h: Include cidr.h and sockaddr.h * include/mailutils/server.h (mu_ip_server_create): Change signature. (mu_ip_server_get_sockaddr): Likewise. (mu_m_server_set_default_address) (mu_m_server_get_default_address): Remove. * include/mailutils/stream.h (mu_tcp_stream_create_from_sa): New proto. * include/mailutils/types.hin (mu_cidr, mu_sockaddr): New structs. * include/mailutils/url.h (MU_URL_IPV6): New flag. (MU_URL_PARSE_DSLASH_OPTIONAL): New parse flag. * libmailutils/Makefile.am: Descend into cidr and sockaddr. Link in libcidr and libsockaddr. * libmailutils/diag/debug.c (mu_debug_log_begin): Flush mu_strerr. * libmailutils/diag/errors (MU_ERR_NONAME) (MU_ERR_BADFLAGS,MU_ERR_SOCKTYPE) (MU_ERR_FAMILY,MU_ERR_SERVICE): New errors. * libmailutils/server/acl.c: Rewrite API using mu_cidr. * libmailutils/server/ipsrv.c: Rewrite AI using mu_sockaddr. * libmailutils/server/msrv.c: Likewise. * libmailutils/stream/tcp.c: Likewise. * libmailutils/tests/.gitignore: Add cidr. * libmailutils/tests/Makefile.am (noinst_PROGRAMS): Add cidr. * libmailutils/tests/url-parse.c: Support command line options to tune the parsing. * libmailutils/tests/url.at: Pass options to url-parse. * libmailutils/url/create.c (getkn): Return meaningful error code. (_mu_url_ctx_parse_host): Accept IPv6 addresses. Set the MU_URL_IPV6 flag if one is given. (_mu_url_ctx_parse): Unless MU_URL_PARSE_DSLASH_OPTIONAL flag is given, request :// after scheme part. (mu_url_create): Add MU_URL_PARSE_DSLASH_OPTIONAL flag. * libmu_cfg/acl.c: Use new ACL API. * mu/acl.c: Likewise. * libproto/mailer/smtp.c (smtp_open): Use mu_tcp_stream_create_from_sa * libproto/pop/mbox.c (pop_open): Likewise. * mu/imap.c (com_connect): Likewise. * mu/pop.c (com_connect): Likewise. * testsuite/smtpsend.c (main): Likewise.
Diffstat (limited to 'libmailutils/url')
-rw-r--r--libmailutils/url/create.c57
1 files changed, 43 insertions, 14 deletions
diff --git a/libmailutils/url/create.c b/libmailutils/url/create.c
index e58064081..130b7a2bc 100644
--- a/libmailutils/url/create.c
+++ b/libmailutils/url/create.c
@@ -59,9 +59,9 @@ getkn (struct mu_url_ctx *ctx, char *delim)
size_t n;
if (*ctx->cur == 0)
- return -1;
+ return MU_ERR_PARSE;
n = strcspn (ctx->cur, delim);
- if (n > ctx->toksize)
+ if (n + 1 > ctx->toksize)
{
char *p = realloc (ctx->tokbuf, n + 1);
if (!p)
@@ -220,11 +220,28 @@ _mu_url_ctx_parse_host (struct mu_url_ctx *ctx, int has_host)
int rc;
mu_url_t url = ctx->url;
- rc = getkn (ctx, ":/;?");
+ rc = getkn (ctx, "[:/;?");
if (rc)
return rc;
- if (ctx->toklen)
+ if (*ctx->cur == '[')
+ {
+ /* Possibly IPv6 address */
+ rc = getkn (ctx, "]/;?");
+ if (rc)
+ return rc;
+ if (*ctx->cur == ']')
+ {
+ ctx->cur++;
+ rc = str_assign (&url->host, ctx->tokbuf + 1);
+ if (rc)
+ return rc;
+ url->flags |= MU_URL_HOST | MU_URL_IPV6;
+ has_host = 1;
+ }
+ }
+
+ if (!(url->flags & MU_URL_HOST) && ctx->toklen)
{
rc = str_assign (&url->host, ctx->tokbuf);
if (rc)
@@ -232,22 +249,20 @@ _mu_url_ctx_parse_host (struct mu_url_ctx *ctx, int has_host)
url->flags |= MU_URL_HOST;
has_host = 1;
}
-
+
if (*ctx->cur == ':')
{
- ctx->cur++;
has_host = 1;
-
- rc = getkn (ctx, "/;?");
+ ctx->cur++;
+ rc = getkn (ctx, ":/;?");
if (rc)
return rc;
-
rc = str_assign (&url->portstr, ctx->tokbuf);
if (rc)
return rc;
url->flags |= MU_URL_PORT;
}
-
+
if (*ctx->cur == '/')
{
if (has_host)
@@ -269,7 +284,9 @@ _mu_url_ctx_parse_cred (struct mu_url_ctx *ctx)
int rc, has_cred;
mu_url_t url = ctx->url;
const char *save = ctx->cur;
-
+
+ if (*ctx->cur == 0)
+ return 0;
rc = getkn (ctx, "@");
if (rc)
return rc;
@@ -343,12 +360,18 @@ _mu_url_ctx_parse (struct mu_url_ctx *ctx)
{
int rc;
mu_url_t url = ctx->url;
+ const char *save = ctx->cur;
/* Parse the scheme part */
+ if (*ctx->cur == ':')
+ return _mu_url_ctx_parse_cred (ctx);
+
rc = getkn (ctx, ":/");
if (rc)
return rc;
- if (*ctx->cur == ':')
+ if (*ctx->cur == ':'
+ && ((ctx->flags & MU_URL_PARSE_DSLASH_OPTIONAL)
+ || (ctx->cur[1] == '/' && ctx->cur[2] == '/')))
{
rc = str_assign (&url->scheme, ctx->tokbuf);
if (rc)
@@ -356,7 +379,12 @@ _mu_url_ctx_parse (struct mu_url_ctx *ctx)
url->flags |= MU_URL_SCHEME;
ctx->cur++;
}
-
+ else
+ {
+ ctx->cur = save;
+ return _mu_url_ctx_parse_cred (ctx);
+ }
+
if (*ctx->cur == 0)
return 0;
@@ -535,5 +563,6 @@ mu_url_create (mu_url_t *purl, const char *str)
MU_URL_PARSE_HIDEPASS |
MU_URL_PARSE_PORTSRV |
MU_URL_PARSE_PIPE |
- MU_URL_PARSE_SLASH, NULL);
+ MU_URL_PARSE_SLASH |
+ MU_URL_PARSE_DSLASH_OPTIONAL, NULL);
}

Return to:

Send suggestions and report system problems to the System administrator.