summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2020-11-09 23:48:25 +0100
committerDaniel Stenberg <daniel@haxx.se>2020-11-10 01:01:56 +0100
commitc49d205ae021d9e02e0466905d4aac49665b2b19 (patch)
tree01bf4aeb2727962f3beeefe1cfa9a5f628d0583a
parent7ae59838f0b9af600f3936485ad45de86bd3435f (diff)
downloadcurl-bagder/http-proxy-keepon.tar.gz
http_proxy: use enum with state names for 'keepon'bagder/http-proxy-keepon
To make the code clearer, change the 'keepon' from an int to an enum with better state names. Reported-by: Niranjan Hasabnis Bug: https://curl.se/mail/lib-2020-11/0026.html Closes #6193
-rw-r--r--lib/http_proxy.c20
-rw-r--r--lib/urldata.h6
2 files changed, 15 insertions, 11 deletions
diff --git a/lib/http_proxy.c b/lib/http_proxy.c
index 6f5a7d6ab..61c4b9931 100644
--- a/lib/http_proxy.c
+++ b/lib/http_proxy.c
@@ -167,7 +167,7 @@ static CURLcode connect_init(struct connectdata *conn, bool reinit)
Curl_dyn_reset(&s->rcvbuf);
}
s->tunnel_state = TUNNEL_INIT;
- s->keepon = TRUE;
+ s->keepon = KEEPON_CONNECT;
s->cl = 0;
s->close_connection = FALSE;
return CURLE_OK;
@@ -339,7 +339,7 @@ static CURLcode CONNECT(struct connectdata *conn,
return CURLE_ABORTED_BY_CALLBACK;
if(result) {
- s->keepon = FALSE;
+ s->keepon = KEEPON_DONE;
break;
}
else if(gotbytes <= 0) {
@@ -353,11 +353,11 @@ static CURLcode CONNECT(struct connectdata *conn,
error = SELECT_ERROR;
failf(data, "Proxy CONNECT aborted");
}
- s->keepon = FALSE;
+ s->keepon = KEEPON_DONE;
break;
}
- if(s->keepon > TRUE) {
+ if(s->keepon == KEEPON_IGNORE) {
/* This means we are currently ignoring a response-body */
if(s->cl) {
@@ -365,7 +365,7 @@ static CURLcode CONNECT(struct connectdata *conn,
and make sure to break out of the loop when we're done! */
s->cl--;
if(s->cl <= 0) {
- s->keepon = FALSE;
+ s->keepon = KEEPON_DONE;
s->tunnel_state = TUNNEL_COMPLETE;
break;
}
@@ -383,7 +383,7 @@ static CURLcode CONNECT(struct connectdata *conn,
if(r == CHUNKE_STOP) {
/* we're done reading chunks! */
infof(data, "chunk reading DONE\n");
- s->keepon = FALSE;
+ s->keepon = KEEPON_DONE;
/* we did the full CONNECT treatment, go COMPLETE */
s->tunnel_state = TUNNEL_COMPLETE;
}
@@ -437,7 +437,7 @@ static CURLcode CONNECT(struct connectdata *conn,
/* If we get a 407 response code with content length
when we have no auth problem, we must ignore the
whole response-body */
- s->keepon = 2;
+ s->keepon = KEEPON_IGNORE;
if(s->cl) {
infof(data, "Ignore %" CURL_FORMAT_CURL_OFF_T
@@ -465,7 +465,7 @@ static CURLcode CONNECT(struct connectdata *conn,
if(r == CHUNKE_STOP) {
/* we're done reading chunks! */
infof(data, "chunk reading DONE\n");
- s->keepon = FALSE;
+ s->keepon = KEEPON_DONE;
/* we did the full CONNECT treatment, go to COMPLETE */
s->tunnel_state = TUNNEL_COMPLETE;
}
@@ -474,11 +474,11 @@ static CURLcode CONNECT(struct connectdata *conn,
/* without content-length or chunked encoding, we
can't keep the connection alive since the close is
the end signal so we bail out at once instead */
- s->keepon = FALSE;
+ s->keepon = KEEPON_DONE;
}
}
else
- s->keepon = FALSE;
+ s->keepon = KEEPON_DONE;
if(!s->cl)
/* we did the full CONNECT treatment, go to COMPLETE */
s->tunnel_state = TUNNEL_COMPLETE;
diff --git a/lib/urldata.h b/lib/urldata.h
index 4a2a97afc..a3c2b3cf3 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -802,7 +802,11 @@ struct proxy_info {
/* struct for HTTP CONNECT state data */
struct http_connect_state {
struct dynbuf rcvbuf;
- int keepon;
+ enum keeponval {
+ KEEPON_DONE,
+ KEEPON_CONNECT,
+ KEEPON_IGNORE
+ } keepon;
curl_off_t cl; /* size of content to read and ignore */
enum {
TUNNEL_INIT, /* init/default/no tunnel state */