mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
dirmngr: Support pseudo URI scheme "opaque".
* dirmngr/http.h (HTTP_PARSE_NO_SCHEME_CHECK): New. * dirmngr/http.c (http_parse_uri): Use this flag. Change all callers to use the new macro for better readability. (do_parse_uri): Add pseudo scheme "opaque". (uri_query_value): New. -- This scheme can be used to convey arbitrary strings in a parsed_uri_t object. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
44c8232b97
commit
72124fadaf
@ -1,8 +1,8 @@
|
|||||||
/* http.c - HTTP protocol handler
|
/* http.c - HTTP protocol handler
|
||||||
* Copyright (C) 1999, 2001, 2002, 2003, 2004, 2006, 2009, 2010,
|
* Copyright (C) 1999, 2001-2004, 2006, 2009, 2010,
|
||||||
* 2011 Free Software Foundation, Inc.
|
* 2011 Free Software Foundation, Inc.
|
||||||
* Copyright (C) 2014 Werner Koch
|
* Copyright (C) 1999, 2001-2004, 2006, 2009, 2010, 2011, 2014 Werner Koch
|
||||||
* Copyright (C) 2015-2017 g10 Code GmbH
|
* Copyright (C) 2015-2017, 2021 g10 Code GmbH
|
||||||
*
|
*
|
||||||
* This file is part of GnuPG.
|
* This file is part of GnuPG.
|
||||||
*
|
*
|
||||||
@ -1298,15 +1298,14 @@ parse_uri (parsed_uri_t *ret_uri, const char *uri,
|
|||||||
/*
|
/*
|
||||||
* Parse an URI and put the result into the newly allocated RET_URI.
|
* Parse an URI and put the result into the newly allocated RET_URI.
|
||||||
* On success the caller must use http_release_parsed_uri() to
|
* On success the caller must use http_release_parsed_uri() to
|
||||||
* releases the resources. If NO_SCHEME_CHECK is set, the function
|
* releases the resources. If the HTTP_PARSE_NO_SCHEME_CHECK flag is
|
||||||
* tries to parse the URL in the same way it would do for an HTTP
|
* set, the function tries to parse the URL in the same way it would
|
||||||
* style URI.
|
* do for an HTTP style URI. */
|
||||||
*/
|
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
|
http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
|
||||||
int no_scheme_check)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
return parse_uri (ret_uri, uri, no_scheme_check, 0);
|
return parse_uri (ret_uri, uri, !!(flags & HTTP_PARSE_NO_SCHEME_CHECK), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1356,8 +1355,9 @@ do_parse_uri (parsed_uri_t uri, int only_local_part,
|
|||||||
uri->off_host = 0;
|
uri->off_host = 0;
|
||||||
uri->off_path = 0;
|
uri->off_path = 0;
|
||||||
|
|
||||||
/* A quick validity check. */
|
/* A quick validity check unless we have the opaque scheme. */
|
||||||
if (strspn (p, VALID_URI_CHARS) != n)
|
if (strspn (p, VALID_URI_CHARS) != n
|
||||||
|
&& strncmp (p, "opaque:", 7))
|
||||||
return GPG_ERR_BAD_URI; /* Invalid characters found. */
|
return GPG_ERR_BAD_URI; /* Invalid characters found. */
|
||||||
|
|
||||||
if (!only_local_part)
|
if (!only_local_part)
|
||||||
@ -1389,6 +1389,12 @@ do_parse_uri (parsed_uri_t uri, int only_local_part,
|
|||||||
uri->use_tls = 1;
|
uri->use_tls = 1;
|
||||||
}
|
}
|
||||||
#endif /*USE_TLS*/
|
#endif /*USE_TLS*/
|
||||||
|
else if (!strcmp (uri->scheme, "opaque"))
|
||||||
|
{
|
||||||
|
uri->opaque = 1;
|
||||||
|
uri->path = p2;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
else if (!no_scheme_check)
|
else if (!no_scheme_check)
|
||||||
return GPG_ERR_INV_URI; /* Unsupported scheme */
|
return GPG_ERR_INV_URI; /* Unsupported scheme */
|
||||||
|
|
||||||
@ -3540,6 +3546,15 @@ uri_query_lookup (parsed_uri_t uri, const char *key)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
uri_query_value (parsed_uri_t url, const char *key)
|
||||||
|
{
|
||||||
|
struct uri_tuple_s *t;
|
||||||
|
t = uri_query_lookup (url, key);
|
||||||
|
return t? t->value : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Return true if both URI point to the same host for the purpose of
|
/* Return true if both URI point to the same host for the purpose of
|
||||||
* redirection check. A is the original host and B the host given in
|
* redirection check. A is the original host and B the host given in
|
||||||
|
@ -70,6 +70,7 @@ struct parsed_uri_s
|
|||||||
typedef struct parsed_uri_s *parsed_uri_t;
|
typedef struct parsed_uri_s *parsed_uri_t;
|
||||||
|
|
||||||
struct uri_tuple_s *uri_query_lookup (parsed_uri_t uri, const char *key);
|
struct uri_tuple_s *uri_query_lookup (parsed_uri_t uri, const char *key);
|
||||||
|
const char *uri_query_value (parsed_uri_t url, const char *key);
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
@ -150,8 +151,9 @@ void http_session_set_log_cb (http_session_t sess,
|
|||||||
void http_session_set_timeout (http_session_t sess, unsigned int timeout);
|
void http_session_set_timeout (http_session_t sess, unsigned int timeout);
|
||||||
|
|
||||||
|
|
||||||
|
#define HTTP_PARSE_NO_SCHEME_CHECK 1
|
||||||
gpg_error_t http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
|
gpg_error_t http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
|
||||||
int no_scheme_check);
|
unsigned int flags);
|
||||||
|
|
||||||
void http_release_parsed_uri (parsed_uri_t uri);
|
void http_release_parsed_uri (parsed_uri_t uri);
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ ks_action_help (ctrl_t ctrl, const char *url)
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
err = http_parse_uri (&parsed_uri, url, 1);
|
err = http_parse_uri (&parsed_uri, url, HTTP_PARSE_NO_SCHEME_CHECK);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
@ -313,7 +313,7 @@ ks_action_fetch (ctrl_t ctrl, const char *url, estream_t outfp)
|
|||||||
if (!url)
|
if (!url)
|
||||||
return gpg_error (GPG_ERR_INV_URI);
|
return gpg_error (GPG_ERR_INV_URI);
|
||||||
|
|
||||||
err = http_parse_uri (&parsed_uri, url, 1);
|
err = http_parse_uri (&parsed_uri, url, HTTP_PARSE_NO_SCHEME_CHECK);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -726,7 +726,8 @@ mark_host_dead (const char *name)
|
|||||||
parsed_uri_t parsed_uri = NULL;
|
parsed_uri_t parsed_uri = NULL;
|
||||||
int done = 0;
|
int done = 0;
|
||||||
|
|
||||||
if (name && *name && !http_parse_uri (&parsed_uri, name, 1))
|
if (name && *name
|
||||||
|
&& !http_parse_uri (&parsed_uri, name, HTTP_PARSE_NO_SCHEME_CHECK))
|
||||||
{
|
{
|
||||||
if (parsed_uri->v6lit)
|
if (parsed_uri->v6lit)
|
||||||
{
|
{
|
||||||
|
@ -322,7 +322,7 @@ ks_ldap_help (ctrl_t ctrl, parsed_uri_t uri)
|
|||||||
"\n"
|
"\n"
|
||||||
"The ldaps:// and ldapi:// schemes are also supported. If ldaps is used\n"
|
"The ldaps:// and ldapi:// schemes are also supported. If ldaps is used\n"
|
||||||
"then the server's certificate will be checked. If it is not valid, any\n"
|
"then the server's certificate will be checked. If it is not valid, any\n"
|
||||||
"operation will be aborted.\n"
|
"operation will be aborted. Note that ldaps means LDAP with STARTTLS\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Supported methods: search, get, put\n";
|
"Supported methods: search, get, put\n";
|
||||||
gpg_error_t err;
|
gpg_error_t err;
|
||||||
|
@ -2113,7 +2113,7 @@ make_keyserver_item (const char *uri, uri_item_t *r_item)
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
err = http_parse_uri (&item->parsed_uri, uri, 1);
|
err = http_parse_uri (&item->parsed_uri, uri, HTTP_PARSE_NO_SCHEME_CHECK);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
|
@ -381,7 +381,7 @@ main (int argc, char **argv)
|
|||||||
(void)no_crl;
|
(void)no_crl;
|
||||||
#endif /*HTTP_USE_GNUTLS*/
|
#endif /*HTTP_USE_GNUTLS*/
|
||||||
|
|
||||||
rc = http_parse_uri (&uri, *argv, 1);
|
rc = http_parse_uri (&uri, *argv, HTTP_PARSE_NO_SCHEME_CHECK);
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
log_error ("'%s': %s\n", *argv, gpg_strerror (rc));
|
log_error ("'%s': %s\n", *argv, gpg_strerror (rc));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user