aboutsummaryrefslogtreecommitdiffstats
path: root/dirmngr
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2023-10-02 10:53:41 +0000
committerWerner Koch <[email protected]>2023-10-02 11:05:49 +0000
commit53bdb7440cbe18f73548169528167190d70998ed (patch)
treed945ed7ba3bad4d72f2140654dc89210e0ea3792 /dirmngr
parentcommon: Add new function b64decode. (diff)
downloadgnupg-53bdb7440cbe18f73548169528167190d70998ed.tar.gz
gnupg-53bdb7440cbe18f73548169528167190d70998ed.zip
dirmngr: Extended the http_get_header function.
* dirmngr/http.c (send_request): Add arg 'skip'. Adjust all callers. -- GnuPG-bug-id: 6719
Diffstat (limited to 'dirmngr')
-rw-r--r--dirmngr/http.c25
-rw-r--r--dirmngr/http.h2
-rw-r--r--dirmngr/ks-engine-hkp.c2
-rw-r--r--dirmngr/ks-engine-http.c2
-rw-r--r--dirmngr/ocsp.c2
-rw-r--r--dirmngr/t-http.c4
6 files changed, 23 insertions, 14 deletions
diff --git a/dirmngr/http.c b/dirmngr/http.c
index a44b0d244..32e6a6cb8 100644
--- a/dirmngr/http.c
+++ b/dirmngr/http.c
@@ -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;
diff --git a/dirmngr/http.h b/dirmngr/http.h
index 2994fdfad..28406694e 100644
--- a/dirmngr/http.h
+++ b/dirmngr/http.h
@@ -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);
diff --git a/dirmngr/ks-engine-hkp.c b/dirmngr/ks-engine-hkp.c
index a75cc1aee..75fe19987 100644
--- a/dirmngr/ks-engine-hkp.c
+++ b/dirmngr/ks-engine-hkp.c
@@ -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;
diff --git a/dirmngr/ks-engine-http.c b/dirmngr/ks-engine-http.c
index 48a734786..5091ddf27 100644
--- a/dirmngr/ks-engine-http.c
+++ b/dirmngr/ks-engine-http.c
@@ -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;
diff --git a/dirmngr/ocsp.c b/dirmngr/ocsp.c
index 483b6f32d..ad7ed962a 100644
--- a/dirmngr/ocsp.c
+++ b/dirmngr/ocsp.c
@@ -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));
diff --git a/dirmngr/t-http.c b/dirmngr/t-http.c
index f9c59783f..3cc4be23a 100644
--- a/dirmngr/t-http.c
+++ b/dirmngr/t-http.c
@@ -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);