1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

dirmngr: Extended the http_get_header function.

* dirmngr/http.c (send_request): Add arg 'skip'.  Adjust all callers.
--

GnuPG-bug-id: 6719
This commit is contained in:
Werner Koch 2023-10-02 12:53:41 +02:00
parent 52b7a60cf9
commit 53bdb7440c
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
6 changed files with 23 additions and 14 deletions

View File

@ -2845,18 +2845,27 @@ store_header (http_t hd, char *line)
/* Return the header NAME from the last response. The returned value /* Return the header NAME from the last response. The returned value
is valid as along as HD has not been closed and no other request * is valid as along as HD has not been closed and no other request
has been send. If the header was not found, NULL is returned. NAME * has been send. If the header was not found, NULL is returned. NAME
must be canonicalized, that is the first letter of each dash * must be canonicalized, that is the first letter of each dash
delimited part must be uppercase and all other letters lowercase. */ * delimited part must be uppercase and all other letters lowercase.
* SKIP gives the number of entries of the requested NAME to skip
* before returning; this can be used to enumerate headers with the
* same name (see store_header).
*/
const char * const char *
http_get_header (http_t hd, const char *name) http_get_header (http_t hd, const char *name, unsigned int skip)
{ {
header_t h; header_t h;
for (h=hd->headers; h; h = h->next) for (h=hd->headers; h; h = h->next)
if ( !strcmp (h->name, name) ) if (!strcmp (h->name, name))
{
if (skip)
skip--;
else
return h->value; return h->value;
}
return NULL; return NULL;
} }
@ -2979,7 +2988,7 @@ parse_response (http_t hd)
cookie->content_length_valid = 0; cookie->content_length_valid = 0;
if (!(hd->flags & HTTP_FLAG_IGNORE_CL)) if (!(hd->flags & HTTP_FLAG_IGNORE_CL))
{ {
s = http_get_header (hd, "Content-Length"); s = http_get_header (hd, "Content-Length", 0);
if (s) if (s)
{ {
cookie->content_length_valid = 1; cookie->content_length_valid = 1;

View File

@ -195,7 +195,7 @@ estream_t http_get_read_ptr (http_t hd);
estream_t http_get_write_ptr (http_t hd); estream_t http_get_write_ptr (http_t hd);
unsigned int http_get_status_code (http_t hd); unsigned int http_get_status_code (http_t hd);
const char *http_get_tls_info (http_t hd, const char *what); const char *http_get_tls_info (http_t hd, const char *what);
const char *http_get_header (http_t hd, const char *name); const char *http_get_header (http_t hd, const char *name, unsigned int skip);
const char **http_get_header_names (http_t hd); const char **http_get_header_names (http_t hd);
gpg_error_t http_verify_server_credentials (http_session_t sess); gpg_error_t http_verify_server_credentials (http_session_t sess);

View File

@ -1327,7 +1327,7 @@ send_request (ctrl_t ctrl, const char *request, const char *hostportstr,
{ {
xfree (request_buffer); xfree (request_buffer);
err = http_prepare_redirect (&redirinfo, http_get_status_code (http), err = http_prepare_redirect (&redirinfo, http_get_status_code (http),
http_get_header (http, "Location"), http_get_header (http, "Location", 0),
&request_buffer); &request_buffer);
if (err) if (err)
goto leave; goto leave;

View File

@ -180,7 +180,7 @@ ks_http_fetch (ctrl_t ctrl, const char *url, unsigned int flags,
{ {
xfree (request_buffer); xfree (request_buffer);
err = http_prepare_redirect (&redirinfo, http_get_status_code (http), err = http_prepare_redirect (&redirinfo, http_get_status_code (http),
http_get_header (http, "Location"), http_get_header (http, "Location", 0),
&request_buffer); &request_buffer);
if (err) if (err)
goto leave; goto leave;

View File

@ -227,7 +227,7 @@ do_ocsp_request (ctrl_t ctrl, ksba_ocsp_t ocsp,
case 301: case 301:
case 302: case 302:
{ {
const char *s = http_get_header (http, "Location"); const char *s = http_get_header (http, "Location", 0);
log_info (_("URL '%s' redirected to '%s' (%u)\n"), log_info (_("URL '%s' redirected to '%s' (%u)\n"),
url, s?s:"[none]", http_get_status_code (http)); url, s?s:"[none]", http_get_status_code (http));

View File

@ -463,7 +463,7 @@ main (int argc, char **argv)
log_fatal ("http_get_header_names failed: %s\n", log_fatal ("http_get_header_names failed: %s\n",
gpg_strerror (gpg_error_from_syserror ())); gpg_strerror (gpg_error_from_syserror ()));
for (i = 0; names[i]; i++) for (i = 0; names[i]; i++)
printf ("HDR: %s: %s\n", names[i], http_get_header (hd, names[i])); printf ("HDR: %s: %s\n", names[i], http_get_header (hd, names[i], 0));
xfree (names); xfree (names);
} }
fflush (stdout); fflush (stdout);
@ -489,7 +489,7 @@ main (int argc, char **argv)
case 301: case 301:
case 302: case 302:
case 307: case 307:
log_info ("Redirected to: %s\n", http_get_header (hd, "Location")); log_info ("Redirected to: %s\n", http_get_header (hd, "Location", 0));
break; break;
} }
http_close (hd, 0); http_close (hd, 0);