mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-21 10:09: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:
parent
52b7a60cf9
commit
53bdb7440c
@ -2845,18 +2845,27 @@ store_header (http_t hd, char *line)
|
||||
|
||||
|
||||
/* 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
|
||||
has been send. If the header was not found, NULL is returned. NAME
|
||||
must be canonicalized, that is the first letter of each dash
|
||||
delimited part must be uppercase and all other letters lowercase. */
|
||||
* 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
|
||||
* must be canonicalized, that is the first letter of each dash
|
||||
* 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 *
|
||||
http_get_header (http_t hd, const char *name)
|
||||
http_get_header (http_t hd, const char *name, unsigned int skip)
|
||||
{
|
||||
header_t h;
|
||||
|
||||
for (h=hd->headers; h; h = h->next)
|
||||
if ( !strcmp (h->name, name) )
|
||||
return h->value;
|
||||
if (!strcmp (h->name, name))
|
||||
{
|
||||
if (skip)
|
||||
skip--;
|
||||
else
|
||||
return h->value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -2979,7 +2988,7 @@ parse_response (http_t hd)
|
||||
cookie->content_length_valid = 0;
|
||||
if (!(hd->flags & HTTP_FLAG_IGNORE_CL))
|
||||
{
|
||||
s = http_get_header (hd, "Content-Length");
|
||||
s = http_get_header (hd, "Content-Length", 0);
|
||||
if (s)
|
||||
{
|
||||
cookie->content_length_valid = 1;
|
||||
|
@ -195,7 +195,7 @@ estream_t http_get_read_ptr (http_t hd);
|
||||
estream_t http_get_write_ptr (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_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);
|
||||
gpg_error_t http_verify_server_credentials (http_session_t sess);
|
||||
|
||||
|
@ -1327,7 +1327,7 @@ send_request (ctrl_t ctrl, const char *request, const char *hostportstr,
|
||||
{
|
||||
xfree (request_buffer);
|
||||
err = http_prepare_redirect (&redirinfo, http_get_status_code (http),
|
||||
http_get_header (http, "Location"),
|
||||
http_get_header (http, "Location", 0),
|
||||
&request_buffer);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
@ -180,7 +180,7 @@ ks_http_fetch (ctrl_t ctrl, const char *url, unsigned int flags,
|
||||
{
|
||||
xfree (request_buffer);
|
||||
err = http_prepare_redirect (&redirinfo, http_get_status_code (http),
|
||||
http_get_header (http, "Location"),
|
||||
http_get_header (http, "Location", 0),
|
||||
&request_buffer);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
@ -227,7 +227,7 @@ do_ocsp_request (ctrl_t ctrl, ksba_ocsp_t ocsp,
|
||||
case 301:
|
||||
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"),
|
||||
url, s?s:"[none]", http_get_status_code (http));
|
||||
|
@ -463,7 +463,7 @@ main (int argc, char **argv)
|
||||
log_fatal ("http_get_header_names failed: %s\n",
|
||||
gpg_strerror (gpg_error_from_syserror ()));
|
||||
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);
|
||||
}
|
||||
fflush (stdout);
|
||||
@ -489,7 +489,7 @@ main (int argc, char **argv)
|
||||
case 301:
|
||||
case 302:
|
||||
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;
|
||||
}
|
||||
http_close (hd, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user