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@gnupg.org>
This commit is contained in:
Werner Koch 2015-12-02 10:12:32 +01:00
parent 10cca02c4c
commit 17ac843871
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
3 changed files with 45 additions and 33 deletions

View File

@ -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;
}

View File

@ -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). */

View File

@ -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");