cgi: provide constants for reason_bf
This commit is contained in:
parent
afc9c0ac26
commit
2e5110e731
4 changed files with 27 additions and 21 deletions
|
@ -246,26 +246,27 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
|
||||
case LWS_CALLBACK_HTTP_WRITEABLE:
|
||||
#ifdef LWS_WITH_CGI
|
||||
if (wsi->reason_bf & 1) {
|
||||
if (wsi->reason_bf & LWS_CB_REASON_AUX_BF__CGI) {
|
||||
if (lws_cgi_write_split_stdout_headers(wsi) < 0)
|
||||
return -1;
|
||||
|
||||
if (wsi->reason_bf & 8)
|
||||
wsi->reason_bf &= ~8;
|
||||
if (wsi->reason_bf & LWS_CB_REASON_AUX_BF__CGI_HEADERS)
|
||||
wsi->reason_bf &= ~LWS_CB_REASON_AUX_BF__CGI_HEADERS;
|
||||
else
|
||||
wsi->reason_bf &= ~1;
|
||||
wsi->reason_bf &= ~LWS_CB_REASON_AUX_BF__CGI;
|
||||
break;
|
||||
}
|
||||
|
||||
if (wsi->reason_bf & 4) {
|
||||
n = lws_write(wsi, (unsigned char *)"0\x0d\x0a\x0d\x0a", 5, LWS_WRITE_HTTP);
|
||||
if (wsi->reason_bf & LWS_CB_REASON_AUX_BF__CGI_CHUNK_END) {
|
||||
n = lws_write(wsi, (unsigned char *)"0\x0d\x0a\x0d\x0a",
|
||||
5, LWS_WRITE_HTTP);
|
||||
if (n < 0)
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if defined(LWS_WITH_HTTP_PROXY)
|
||||
if (wsi->reason_bf & 2) {
|
||||
if (wsi->reason_bf & LWS_CB_REASON_AUX_BF__PROXY) {
|
||||
char *px = buf + LWS_PRE;
|
||||
int lenx = sizeof(buf) - LWS_PRE;
|
||||
/*
|
||||
|
@ -275,8 +276,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
* is the smaller.
|
||||
*/
|
||||
|
||||
|
||||
wsi->reason_bf &= ~2;
|
||||
wsi->reason_bf &= ~LWS_CB_REASON_AUX_BF__PROXY;
|
||||
if (!lws_get_child(wsi))
|
||||
break;
|
||||
if (lws_http_client_read(lws_get_child(wsi), &px, &lenx) < 0)
|
||||
|
@ -292,7 +292,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
assert(lws_get_parent(wsi));
|
||||
if (!lws_get_parent(wsi))
|
||||
break;
|
||||
lws_get_parent(wsi)->reason_bf |= 2;
|
||||
lws_get_parent(wsi)->reason_bf |= LWS_CB_REASON_AUX_BF__PROXY;
|
||||
lws_callback_on_writable(lws_get_parent(wsi));
|
||||
break;
|
||||
|
||||
|
@ -364,7 +364,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
/* TBD stdin rx flow control */
|
||||
break;
|
||||
case LWS_STDOUT:
|
||||
wsi->reason_bf |= 1;
|
||||
wsi->reason_bf |= LWS_CB_REASON_AUX_BF__CGI;
|
||||
/* when writing to MASTER would not block */
|
||||
lws_callback_on_writable(wsi);
|
||||
break;
|
||||
|
@ -384,7 +384,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
case LWS_CALLBACK_CGI_TERMINATED:
|
||||
if (!wsi->cgi->explicitly_chunked && !wsi->cgi->content_length) {
|
||||
/* send terminating chunk */
|
||||
wsi->reason_bf |= 4;
|
||||
wsi->reason_bf |= LWS_CB_REASON_AUX_BF__CGI_CHUNK_END;
|
||||
lws_callback_on_writable(wsi);
|
||||
}
|
||||
return -1;
|
||||
|
|
|
@ -2781,11 +2781,11 @@ lws_cgi_write_split_stdout_headers(struct lws *wsi)
|
|||
return -1;
|
||||
|
||||
while (wsi->hdr_state != LHCS_PAYLOAD) {
|
||||
/* we have to separate header / finalize and
|
||||
/*
|
||||
* we have to separate header / finalize and
|
||||
* payload chunks, since they need to be
|
||||
* handled separately
|
||||
*/
|
||||
|
||||
switch (wsi->hdr_state) {
|
||||
|
||||
case LHCS_RESPONSE:
|
||||
|
@ -2794,8 +2794,9 @@ lws_cgi_write_split_stdout_headers(struct lws *wsi)
|
|||
if (lws_add_http_header_status(wsi, wsi->cgi->response_code, &p, end))
|
||||
return 1;
|
||||
if (!wsi->cgi->explicitly_chunked &&
|
||||
!wsi->cgi->content_length &&
|
||||
lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_TRANSFER_ENCODING,
|
||||
!wsi->cgi->content_length &&
|
||||
lws_add_http_header_by_token(wsi,
|
||||
WSI_TOKEN_HTTP_TRANSFER_ENCODING,
|
||||
(unsigned char *)"chunked", 7, &p, end))
|
||||
return 1;
|
||||
if (lws_add_http_header_by_token(wsi, WSI_TOKEN_CONNECTION,
|
||||
|
@ -2814,7 +2815,7 @@ lws_cgi_write_split_stdout_headers(struct lws *wsi)
|
|||
}
|
||||
|
||||
wsi->hdr_state = LHCS_DUMP_HEADERS;
|
||||
wsi->reason_bf |= 8;
|
||||
wsi->reason_bf |= LWS_CB_REASON_AUX_BF__CGI_HEADERS;
|
||||
lws_callback_on_writable(wsi);
|
||||
/* back to the loop for writeability again */
|
||||
return 0;
|
||||
|
@ -2839,7 +2840,7 @@ lws_cgi_write_split_stdout_headers(struct lws *wsi)
|
|||
lws_free_set_NULL(wsi->cgi->headers_buf);
|
||||
lwsl_debug("freed cgi headers\n");
|
||||
} else {
|
||||
wsi->reason_bf |= 8;
|
||||
wsi->reason_bf |= LWS_CB_REASON_AUX_BF__CGI_HEADERS;
|
||||
lws_callback_on_writable(wsi);
|
||||
}
|
||||
|
||||
|
|
|
@ -1326,6 +1326,11 @@ enum lws_callback_reasons {
|
|||
typedef int
|
||||
lws_callback_function(struct lws *wsi, enum lws_callback_reasons reason,
|
||||
void *user, void *in, size_t len);
|
||||
|
||||
#define LWS_CB_REASON_AUX_BF__CGI 1
|
||||
#define LWS_CB_REASON_AUX_BF__PROXY 2
|
||||
#define LWS_CB_REASON_AUX_BF__CGI_CHUNK_END 4
|
||||
#define LWS_CB_REASON_AUX_BF__CGI_HEADERS 8
|
||||
///@}
|
||||
|
||||
/*! \defgroup extensions
|
||||
|
|
|
@ -524,7 +524,7 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
|
|||
}
|
||||
|
||||
#ifndef LWS_NO_CLIENT
|
||||
if (pss->reason_bf & 2) {
|
||||
if (pss->reason_bf & LWS_CB_REASON_AUX_BF__PROXY) {
|
||||
char *px = buf + LWS_PRE;
|
||||
int lenx = sizeof(buf) - LWS_PRE;
|
||||
/*
|
||||
|
@ -535,7 +535,7 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
|
|||
*/
|
||||
|
||||
|
||||
pss->reason_bf &= ~2;
|
||||
pss->reason_bf &= ~LWS_CB_REASON_AUX_BF__PROXY;
|
||||
wsi1 = lws_get_child(wsi);
|
||||
if (!wsi1)
|
||||
break;
|
||||
|
@ -674,7 +674,7 @@ bail:
|
|||
if (!lws_get_parent(wsi))
|
||||
break;
|
||||
pss1 = lws_wsi_user(lws_get_parent(wsi));
|
||||
pss1->reason_bf |= 2;
|
||||
pss1->reason_bf |= LWS_CB_REASON_AUX_BF__PROXY;
|
||||
lws_callback_on_writable(lws_get_parent(wsi));
|
||||
break;
|
||||
case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ:
|
||||
|
|
Loading…
Add table
Reference in a new issue