[Pkg-gnupg-commit] [gnupg2] 206/241: http: Enhance parser to detect .onion addresses.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Wed Dec 9 20:32:17 UTC 2015
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch master
in repository gnupg2.
commit 17ac843871d5f350f26edff0187f94ced923f534
Author: Werner Koch <wk at gnupg.org>
Date: Wed Dec 2 10:12:32 2015 +0100
http: Enhance parser to detect .onion addresses.
* dirmngr/http.h (parsed_uri_s): Add flag 'onion'.
* dirmngr/http.c (do_parse_uri): Set that flag.
* dirmngr/t-http.c (main): Print flags.
Signed-off-by: Werner Koch <wk at gnupg.org>
---
dirmngr/http.c | 72 ++++++++++++++++++++++++++++++--------------------------
dirmngr/http.h | 1 +
dirmngr/t-http.c | 5 ++++
3 files changed, 45 insertions(+), 33 deletions(-)
diff --git a/dirmngr/http.c b/dirmngr/http.c
index d623f7e..6427951 100644
--- a/dirmngr/http.c
+++ b/dirmngr/http.c
@@ -1086,6 +1086,7 @@ do_parse_uri (parsed_uri_t uri, int only_local_part,
uri->is_http = 0;
uri->opaque = 0;
uri->v6lit = 0;
+ uri->onion = 0;
/* A quick validity check. */
if (strspn (p, VALID_URI_CHARS) != n)
@@ -1172,49 +1173,54 @@ do_parse_uri (parsed_uri_t uri, int only_local_part,
{
uri->opaque = 1;
uri->path = p;
+ if (is_onion_address (uri->path))
+ uri->onion = 1;
return 0;
}
} /* End global URI part. */
- /* Parse the pathname part */
- if (!p || !*p)
- return 0; /* We don't have a path. Okay. */
-
- /* TODO: Here we have to check params. */
-
- /* Do we have a query part? */
- if ((p2 = strchr (p, '?')))
- *p2++ = 0;
-
- uri->path = p;
- if ((n = remove_escapes (p)) < 0)
- return GPG_ERR_BAD_URI;
- if (n != strlen (p))
- return GPG_ERR_BAD_URI; /* Path includes a Nul. */
- p = p2 ? p2 : NULL;
-
- if (!p || !*p)
- return 0; /* We don't have a query string. Okay. */
-
- /* Now parse the query string. */
- tail = &uri->query;
- for (;;)
+ /* Parse the pathname part if any. */
+ if (p && *p)
{
- uri_tuple_t elem;
+ /* TODO: Here we have to check params. */
- if ((p2 = strchr (p, '&')))
- *p2++ = 0;
- if (!(elem = parse_tuple (p)))
- return GPG_ERR_BAD_URI;
- *tail = elem;
- tail = &elem->next;
+ /* Do we have a query part? */
+ if ((p2 = strchr (p, '?')))
+ *p2++ = 0;
- if (!p2)
- break; /* Ready. */
- p = p2;
+ uri->path = p;
+ if ((n = remove_escapes (p)) < 0)
+ return GPG_ERR_BAD_URI;
+ if (n != strlen (p))
+ return GPG_ERR_BAD_URI; /* Path includes a Nul. */
+ p = p2 ? p2 : NULL;
+
+ /* Parse a query string if any. */
+ if (p && *p)
+ {
+ tail = &uri->query;
+ for (;;)
+ {
+ uri_tuple_t elem;
+
+ if ((p2 = strchr (p, '&')))
+ *p2++ = 0;
+ if (!(elem = parse_tuple (p)))
+ return GPG_ERR_BAD_URI;
+ *tail = elem;
+ tail = &elem->next;
+
+ if (!p2)
+ break; /* Ready. */
+ p = p2;
+ }
+ }
}
+ if (is_onion_address (uri->host))
+ uri->onion = 1;
+
return 0;
}
diff --git a/dirmngr/http.h b/dirmngr/http.h
index 73a423c..64f55e1 100644
--- a/dirmngr/http.h
+++ b/dirmngr/http.h
@@ -52,6 +52,7 @@ struct parsed_uri_s
unsigned int use_tls:1; /* Whether TLS should be used. */
unsigned int opaque:1;/* Unknown scheme; PATH has the rest. */
unsigned int v6lit:1; /* Host was given as a literal v6 address. */
+ unsigned int onion:1; /* .onion address given. */
char *auth; /* username/password for basic auth. */
char *host; /* Host (converted to lowercase). */
unsigned short port; /* Port (always set if the host is set). */
diff --git a/dirmngr/t-http.c b/dirmngr/t-http.c
index 35858f6..63662a2 100644
--- a/dirmngr/t-http.c
+++ b/dirmngr/t-http.c
@@ -323,6 +323,11 @@ main (int argc, char **argv)
}
putchar ('\n');
}
+ printf ("Flags :%s%s%s%s\n",
+ uri->is_http? " http":"",
+ uri->opaque? " opaque":"",
+ uri->v6lit? " v6lit":"",
+ uri->onion? " onion":"");
printf ("TLS : %s\n",
uri->use_tls? "yes":
(my_http_flags&HTTP_FLAG_FORCE_TLS)? "forced" : "no");
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git
More information about the Pkg-gnupg-commit
mailing list