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