aboutsummaryrefslogtreecommitdiffstats
path: root/dirmngr/ks-engine-hkp.c
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2015-12-04 11:32:20 +0000
committerJustus Winter <[email protected]>2015-12-04 12:02:56 +0000
commit6d64ef869dfbcb7aaa802b80ed648393147e40d8 (patch)
tree043dc98eb289f08a36b227ca5bcdd4942c07c960 /dirmngr/ks-engine-hkp.c
parentdirmngr: Really search all keyservers for patterns. (diff)
downloadgnupg-6d64ef869dfbcb7aaa802b80ed648393147e40d8.tar.gz
gnupg-6d64ef869dfbcb7aaa802b80ed648393147e40d8.zip
dirmngr: Stricter handling of http error codes.
* dirmngr/ks-action.c (ks_action_search): Only retry if the keyserver responded with a '404 Not Found'. * dirmngr/ks-engine-hkp.c (send_request): Return http status code. (ks_hkp_search): Likewise. (ks_hkp_{get,put}): Adapt call to 'send_request'. * dirmngr/ks-engine.h (ks_hkp_search): Update prototype. Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'dirmngr/ks-engine-hkp.c')
-rw-r--r--dirmngr/ks-engine-hkp.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/dirmngr/ks-engine-hkp.c b/dirmngr/ks-engine-hkp.c
index 0f2021cce..f38f29a6b 100644
--- a/dirmngr/ks-engine-hkp.c
+++ b/dirmngr/ks-engine-hkp.c
@@ -974,12 +974,13 @@ ks_hkp_housekeeping (time_t curtime)
R_FP. HOSTPORTSTR is only used for diagnostics. If HTTPHOST is
not NULL it will be used as HTTP "Host" header. If POST_CB is not
NULL a post request is used and that callback is called to allow
- writing the post data. */
+ writing the post data. If R_HTTP_STATUS is not NULL, the http
+ status code will be stored there. */
static gpg_error_t
send_request (ctrl_t ctrl, const char *request, const char *hostportstr,
const char *httphost, unsigned int httpflags,
gpg_error_t (*post_cb)(void *, http_t), void *post_cb_value,
- estream_t *r_fp)
+ estream_t *r_fp, unsigned int *r_http_status)
{
gpg_error_t err;
http_session_t session = NULL;
@@ -1050,6 +1051,9 @@ send_request (ctrl_t ctrl, const char *request, const char *hostportstr,
httpflags |= HTTP_FLAG_FORCE_TLS;
}
+ if (r_http_status)
+ *r_http_status = http_get_status_code (http);
+
switch (http_get_status_code (http))
{
case 200:
@@ -1158,10 +1162,12 @@ handle_send_request_error (gpg_error_t err, const char *request,
/* Search the keyserver identified by URI for keys matching PATTERN.
- On success R_FP has an open stream to read the data. */
+ On success R_FP has an open stream to read the data. If
+ R_HTTP_STATUS is not NULL, the http status code will be stored
+ there. */
gpg_error_t
ks_hkp_search (ctrl_t ctrl, parsed_uri_t uri, const char *pattern,
- estream_t *r_fp)
+ estream_t *r_fp, unsigned int *r_http_status)
{
gpg_error_t err;
KEYDB_SEARCH_DESC desc;
@@ -1248,7 +1254,7 @@ ks_hkp_search (ctrl_t ctrl, parsed_uri_t uri, const char *pattern,
/* Send the request. */
err = send_request (ctrl, request, hostport, httphost, httpflags,
- NULL, NULL, &fp);
+ NULL, NULL, &fp, r_http_status);
if (handle_send_request_error (err, request, &tries))
{
reselect = 1;
@@ -1381,7 +1387,7 @@ ks_hkp_get (ctrl_t ctrl, parsed_uri_t uri, const char *keyspec, estream_t *r_fp)
/* Send the request. */
err = send_request (ctrl, request, hostport, httphost, httpflags,
- NULL, NULL, &fp);
+ NULL, NULL, &fp, NULL);
if (handle_send_request_error (err, request, &tries))
{
reselect = 1;
@@ -1489,7 +1495,7 @@ ks_hkp_put (ctrl_t ctrl, parsed_uri_t uri, const void *data, size_t datalen)
/* Send the request. */
err = send_request (ctrl, request, hostport, httphost, 0,
- put_post_cb, &parm, &fp);
+ put_post_cb, &parm, &fp, NULL);
if (handle_send_request_error (err, request, &tries))
{
reselect = 1;