mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
clean internal refactor
- Mainly symbol length reduction - Whitespace clean - Code refactor for linear flow - Audit @Context for API docs vs changes Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
ddd79cbbb5
commit
54806b1541
24 changed files with 535 additions and 560 deletions
|
@ -21,18 +21,18 @@ lws_client_connect_2(struct lws *wsi)
|
|||
/* proxy? */
|
||||
|
||||
if (context->http_proxy_port) {
|
||||
plen = sprintf((char *)context->service_buffer,
|
||||
plen = sprintf((char *)context->serv_buf,
|
||||
"CONNECT %s:%u HTTP/1.0\x0d\x0a"
|
||||
"User-agent: libwebsockets\x0d\x0a",
|
||||
lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS),
|
||||
wsi->u.hdr.ah->c_port);
|
||||
|
||||
if (context->proxy_basic_auth_token[0])
|
||||
plen += sprintf((char *)context->service_buffer + plen,
|
||||
plen += sprintf((char *)context->serv_buf + plen,
|
||||
"Proxy-authorization: basic %s\x0d\x0a",
|
||||
context->proxy_basic_auth_token);
|
||||
|
||||
plen += sprintf((char *)context->service_buffer + plen,
|
||||
plen += sprintf((char *)context->serv_buf + plen,
|
||||
"\x0d\x0a");
|
||||
|
||||
ads = context->http_proxy_address;
|
||||
|
@ -160,7 +160,7 @@ lws_client_connect_2(struct lws *wsi)
|
|||
goto oom4;
|
||||
}
|
||||
|
||||
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT;
|
||||
wsi->mode = LWSCM_WSCL_WAITING_CONNECT;
|
||||
|
||||
lws_libev_accept(wsi, wsi->sock);
|
||||
if (insert_wsi_socket_into_fds(context, wsi)) {
|
||||
|
@ -219,7 +219,6 @@ lws_client_connect_2(struct lws *wsi)
|
|||
}
|
||||
|
||||
if (connect(wsi->sock, v, n) == -1 || LWS_ERRNO == LWS_EISCONN) {
|
||||
|
||||
if (LWS_ERRNO == LWS_EALREADY ||
|
||||
LWS_ERRNO == LWS_EINPROGRESS ||
|
||||
LWS_ERRNO == LWS_EWOULDBLOCK
|
||||
|
@ -263,7 +262,7 @@ lws_client_connect_2(struct lws *wsi)
|
|||
goto failed;
|
||||
wsi->u.hdr.ah->c_port = context->http_proxy_port;
|
||||
|
||||
n = send(wsi->sock, (char *)context->service_buffer, plen,
|
||||
n = send(wsi->sock, (char *)context->serv_buf, plen,
|
||||
MSG_NOSIGNAL);
|
||||
if (n < 0) {
|
||||
lwsl_debug("ERROR writing to proxy socket\n");
|
||||
|
@ -273,7 +272,7 @@ lws_client_connect_2(struct lws *wsi)
|
|||
lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE,
|
||||
AWAITING_TIMEOUT);
|
||||
|
||||
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY;
|
||||
wsi->mode = LWSCM_WSCL_WAITING_PROXY_REPLY;
|
||||
|
||||
return wsi;
|
||||
}
|
||||
|
@ -291,15 +290,13 @@ lws_client_connect_2(struct lws *wsi)
|
|||
lws_set_timeout(wsi, PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE,
|
||||
AWAITING_TIMEOUT);
|
||||
|
||||
wsi->mode = LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE;
|
||||
wsi->mode = LWSCM_WSCL_ISSUE_HANDSHAKE;
|
||||
pfd.fd = wsi->sock;
|
||||
pfd.revents = LWS_POLLIN;
|
||||
|
||||
n = lws_service_fd(context, &pfd);
|
||||
|
||||
if (n < 0)
|
||||
goto failed;
|
||||
|
||||
if (n) /* returns 1 on failure after closing wsi */
|
||||
return NULL;
|
||||
|
||||
|
@ -308,6 +305,7 @@ lws_client_connect_2(struct lws *wsi)
|
|||
oom4:
|
||||
lws_free(wsi->u.hdr.ah);
|
||||
lws_free(wsi);
|
||||
|
||||
return NULL;
|
||||
|
||||
failed:
|
||||
|
@ -358,7 +356,7 @@ lws_client_connect(struct lws_context *context, const char *address,
|
|||
|
||||
wsi->ietf_spec_revision = ietf_version_or_minus_one;
|
||||
wsi->user_space = NULL;
|
||||
wsi->state = WSI_STATE_CLIENT_UNCONNECTED;
|
||||
wsi->state = LWSS_CLIENT_UNCONNECTED;
|
||||
wsi->protocol = NULL;
|
||||
wsi->pending_timeout = NO_PENDING_TIMEOUT;
|
||||
|
||||
|
@ -411,7 +409,7 @@ lws_client_connect(struct lws_context *context, const char *address,
|
|||
* connection.
|
||||
*/
|
||||
|
||||
if (lws_ext_callback_for_each_extension_type(context, wsi,
|
||||
if (lws_ext_cb_all_exts(context, wsi,
|
||||
LWS_EXT_CALLBACK_CAN_PROXY_CLIENT_CONNECTION,
|
||||
(void *)address, port) > 0) {
|
||||
lwsl_client("lws_client_connect: ext handling conn\n");
|
||||
|
@ -420,7 +418,7 @@ lws_client_connect(struct lws_context *context, const char *address,
|
|||
PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE,
|
||||
AWAITING_TIMEOUT);
|
||||
|
||||
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT;
|
||||
wsi->mode = LWSCM_WSCL_WAITING_EXTENSION_CONNECT;
|
||||
return wsi;
|
||||
}
|
||||
lwsl_client("lws_client_connect: direct conn\n");
|
||||
|
|
|
@ -37,10 +37,10 @@ int lws_client_rx_sm(struct lws *wsi, unsigned char c)
|
|||
wsi->u.ws.rsv = (c & 0x70);
|
||||
wsi->u.ws.final = !!((c >> 7) & 1);
|
||||
switch (wsi->u.ws.opcode) {
|
||||
case LWS_WS_OPCODE_07__TEXT_FRAME:
|
||||
case LWS_WS_OPCODE_07__BINARY_FRAME:
|
||||
case LWSWSOPC_TEXT_FRAME:
|
||||
case LWSWSOPC_BINARY_FRAME:
|
||||
wsi->u.ws.frame_is_binary = wsi->u.ws.opcode ==
|
||||
LWS_WS_OPCODE_07__BINARY_FRAME;
|
||||
LWSWSOPC_BINARY_FRAME;
|
||||
break;
|
||||
}
|
||||
wsi->lws_rx_parse_state = LWS_RXPS_04_FRAME_HDR_LEN;
|
||||
|
@ -176,28 +176,28 @@ int lws_client_rx_sm(struct lws *wsi, unsigned char c)
|
|||
break;
|
||||
|
||||
case LWS_RXPS_07_COLLECT_FRAME_KEY_1:
|
||||
wsi->u.ws.frame_masking_nonce_04[0] = c;
|
||||
wsi->u.ws.mask_nonce[0] = c;
|
||||
if (c)
|
||||
wsi->u.ws.all_zero_nonce = 0;
|
||||
wsi->lws_rx_parse_state = LWS_RXPS_07_COLLECT_FRAME_KEY_2;
|
||||
break;
|
||||
|
||||
case LWS_RXPS_07_COLLECT_FRAME_KEY_2:
|
||||
wsi->u.ws.frame_masking_nonce_04[1] = c;
|
||||
wsi->u.ws.mask_nonce[1] = c;
|
||||
if (c)
|
||||
wsi->u.ws.all_zero_nonce = 0;
|
||||
wsi->lws_rx_parse_state = LWS_RXPS_07_COLLECT_FRAME_KEY_3;
|
||||
break;
|
||||
|
||||
case LWS_RXPS_07_COLLECT_FRAME_KEY_3:
|
||||
wsi->u.ws.frame_masking_nonce_04[2] = c;
|
||||
wsi->u.ws.mask_nonce[2] = c;
|
||||
if (c)
|
||||
wsi->u.ws.all_zero_nonce = 0;
|
||||
wsi->lws_rx_parse_state = LWS_RXPS_07_COLLECT_FRAME_KEY_4;
|
||||
break;
|
||||
|
||||
case LWS_RXPS_07_COLLECT_FRAME_KEY_4:
|
||||
wsi->u.ws.frame_masking_nonce_04[3] = c;
|
||||
wsi->u.ws.mask_nonce[3] = c;
|
||||
if (c)
|
||||
wsi->u.ws.all_zero_nonce = 0;
|
||||
|
||||
|
@ -223,7 +223,7 @@ int lws_client_rx_sm(struct lws *wsi, unsigned char c)
|
|||
else
|
||||
wsi->u.ws.rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING +
|
||||
(wsi->u.ws.rx_user_buffer_head++)] =
|
||||
c ^ wsi->u.ws.frame_masking_nonce_04[
|
||||
c ^ wsi->u.ws.mask_nonce[
|
||||
(wsi->u.ws.frame_mask_index++) & 3];
|
||||
|
||||
if (--wsi->u.ws.rx_packet_length == 0) {
|
||||
|
@ -258,9 +258,9 @@ spill:
|
|||
*/
|
||||
|
||||
switch (wsi->u.ws.opcode) {
|
||||
case LWS_WS_OPCODE_07__CLOSE:
|
||||
case LWSWSOPC_CLOSE:
|
||||
/* is this an acknowledgement of our close? */
|
||||
if (wsi->state == WSI_STATE_AWAITING_CLOSE_ACK) {
|
||||
if (wsi->state == LWSS_AWAITING_CLOSE_ACK) {
|
||||
/*
|
||||
* fine he has told us he is closing too, let's
|
||||
* finish our close
|
||||
|
@ -279,11 +279,11 @@ spill:
|
|||
&wsi->u.ws.rx_user_buffer[
|
||||
LWS_SEND_BUFFER_PRE_PADDING],
|
||||
wsi->u.ws.rx_user_buffer_head, LWS_WRITE_CLOSE);
|
||||
wsi->state = WSI_STATE_RETURNED_CLOSE_ALREADY;
|
||||
wsi->state = LWSS_RETURNED_CLOSE_ALREADY;
|
||||
/* close the connection */
|
||||
return -1;
|
||||
|
||||
case LWS_WS_OPCODE_07__PING:
|
||||
case LWSWSOPC_PING:
|
||||
lwsl_info("received %d byte ping, sending pong\n",
|
||||
wsi->u.ws.rx_user_buffer_head);
|
||||
|
||||
|
@ -306,7 +306,7 @@ spill:
|
|||
if (wsi->u.ws.ping_payload_buf &&
|
||||
wsi->u.ws.ping_payload_alloc <
|
||||
wsi->u.ws.rx_user_buffer_head)
|
||||
lws_free2(wsi->u.ws.ping_payload_buf);
|
||||
lws_free_set_NULL(wsi->u.ws.ping_payload_buf);
|
||||
|
||||
/* if no buffer, allocate it */
|
||||
if (!wsi->u.ws.ping_payload_buf) {
|
||||
|
@ -332,7 +332,7 @@ ping_drop:
|
|||
handled = 1;
|
||||
break;
|
||||
|
||||
case LWS_WS_OPCODE_07__PONG:
|
||||
case LWSWSOPC_PONG:
|
||||
lwsl_info("client receied pong\n");
|
||||
lwsl_hexdump(&wsi->u.ws.rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
|
||||
wsi->u.ws.rx_user_buffer_head);
|
||||
|
@ -341,9 +341,9 @@ ping_drop:
|
|||
callback_action = LWS_CALLBACK_CLIENT_RECEIVE_PONG;
|
||||
break;
|
||||
|
||||
case LWS_WS_OPCODE_07__CONTINUATION:
|
||||
case LWS_WS_OPCODE_07__TEXT_FRAME:
|
||||
case LWS_WS_OPCODE_07__BINARY_FRAME:
|
||||
case LWSWSOPC_CONTINUATION:
|
||||
case LWSWSOPC_TEXT_FRAME:
|
||||
case LWSWSOPC_BINARY_FRAME:
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -360,7 +360,7 @@ ping_drop:
|
|||
LWS_SEND_BUFFER_PRE_PADDING];
|
||||
eff_buf.token_len = wsi->u.ws.rx_user_buffer_head;
|
||||
|
||||
if (lws_ext_callback_for_each_active(wsi,
|
||||
if (lws_ext_cb_wsi_active_exts(wsi,
|
||||
LWS_EXT_CALLBACK_EXTENDED_PAYLOAD_RX,
|
||||
&eff_buf, 0) <= 0) { /* not handle or fail */
|
||||
|
||||
|
@ -386,7 +386,7 @@ ping_drop:
|
|||
LWS_SEND_BUFFER_PRE_PADDING];
|
||||
eff_buf.token_len = wsi->u.ws.rx_user_buffer_head;
|
||||
|
||||
if (lws_ext_callback_for_each_active(wsi,
|
||||
if (lws_ext_cb_wsi_active_exts(wsi,
|
||||
LWS_EXT_CALLBACK_PAYLOAD_RX,
|
||||
&eff_buf, 0) < 0) /* fail */
|
||||
return -1;
|
||||
|
|
86
lib/client.c
86
lib/client.c
|
@ -26,11 +26,11 @@ int lws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len)
|
|||
unsigned int n;
|
||||
|
||||
switch (wsi->mode) {
|
||||
case LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY:
|
||||
case LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE:
|
||||
case LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY:
|
||||
case LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT:
|
||||
case LWS_CONNMODE_WS_CLIENT:
|
||||
case LWSCM_WSCL_WAITING_PROXY_REPLY:
|
||||
case LWSCM_WSCL_ISSUE_HANDSHAKE:
|
||||
case LWSCM_WSCL_WAITING_SERVER_REPLY:
|
||||
case LWSCM_WSCL_WAITING_EXTENSION_CONNECT:
|
||||
case LWSCM_WS_CLIENT:
|
||||
for (n = 0; n < len; n++)
|
||||
if (lws_client_rx_sm(wsi, *(*buf)++)) {
|
||||
lwsl_debug("client_rx_sm failed\n");
|
||||
|
@ -46,13 +46,13 @@ int lws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len)
|
|||
int lws_client_socket_service(struct lws_context *context,
|
||||
struct lws *wsi, struct lws_pollfd *pollfd)
|
||||
{
|
||||
char *p = (char *)&context->service_buffer[0];
|
||||
char *p = (char *)&context->serv_buf[0];
|
||||
unsigned char c;
|
||||
int n, len;
|
||||
|
||||
switch (wsi->mode) {
|
||||
|
||||
case LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT:
|
||||
case LWSCM_WSCL_WAITING_CONNECT:
|
||||
|
||||
/*
|
||||
* we are under PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE
|
||||
|
@ -68,7 +68,7 @@ int lws_client_socket_service(struct lws_context *context,
|
|||
/* either still pending connection, or changed mode */
|
||||
return 0;
|
||||
|
||||
case LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY:
|
||||
case LWSCM_WSCL_WAITING_PROXY_REPLY:
|
||||
|
||||
/* handle proxy hung up on us */
|
||||
|
||||
|
@ -81,8 +81,8 @@ int lws_client_socket_service(struct lws_context *context,
|
|||
return 0;
|
||||
}
|
||||
|
||||
n = recv(wsi->sock, (char *)context->service_buffer,
|
||||
sizeof(context->service_buffer), 0);
|
||||
n = recv(wsi->sock, (char *)context->serv_buf,
|
||||
sizeof(context->serv_buf), 0);
|
||||
if (n < 0) {
|
||||
|
||||
if (LWS_ERRNO == LWS_EAGAIN) {
|
||||
|
@ -95,12 +95,12 @@ int lws_client_socket_service(struct lws_context *context,
|
|||
return 0;
|
||||
}
|
||||
|
||||
context->service_buffer[13] = '\0';
|
||||
if (strcmp((char *)context->service_buffer, "HTTP/1.0 200 ") &&
|
||||
strcmp((char *)context->service_buffer, "HTTP/1.1 200 ")
|
||||
context->serv_buf[13] = '\0';
|
||||
if (strcmp((char *)context->serv_buf, "HTTP/1.0 200 ") &&
|
||||
strcmp((char *)context->serv_buf, "HTTP/1.1 200 ")
|
||||
) {
|
||||
lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS);
|
||||
lwsl_err("ERROR proxy: %s\n", context->service_buffer);
|
||||
lwsl_err("ERROR proxy: %s\n", context->serv_buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ int lws_client_socket_service(struct lws_context *context,
|
|||
|
||||
/* fallthru */
|
||||
|
||||
case LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE:
|
||||
case LWSCM_WSCL_ISSUE_HANDSHAKE:
|
||||
|
||||
/*
|
||||
* we are under PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE
|
||||
|
@ -204,7 +204,7 @@ int lws_client_socket_service(struct lws_context *context,
|
|||
lws_latency_pre(context, wsi);
|
||||
n = SSL_connect(wsi->ssl);
|
||||
lws_latency(context, wsi,
|
||||
"SSL_connect LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE",
|
||||
"SSL_connect LWSCM_WSCL_ISSUE_HANDSHAKE",
|
||||
n, n > 0);
|
||||
|
||||
if (n < 0) {
|
||||
|
@ -231,7 +231,7 @@ int lws_client_socket_service(struct lws_context *context,
|
|||
"SSL_connect WANT_WRITE... retrying\n");
|
||||
lws_callback_on_writable(wsi);
|
||||
some_wait:
|
||||
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_SSL;
|
||||
wsi->mode = LWSCM_WSCL_WAITING_SSL;
|
||||
|
||||
return 0; /* no error */
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ some_wait:
|
|||
lwsl_err("SSL connect error %lu: %s\n",
|
||||
n,
|
||||
ERR_error_string(n,
|
||||
(char *)context->service_buffer));
|
||||
(char *)context->serv_buf));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -258,15 +258,15 @@ some_wait:
|
|||
|
||||
/* fallthru */
|
||||
|
||||
case LWS_CONNMODE_WS_CLIENT_WAITING_SSL:
|
||||
case LWSCM_WSCL_WAITING_SSL:
|
||||
|
||||
if (wsi->use_ssl) {
|
||||
|
||||
if (wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_SSL) {
|
||||
if (wsi->mode == LWSCM_WSCL_WAITING_SSL) {
|
||||
lws_latency_pre(context, wsi);
|
||||
n = SSL_connect(wsi->ssl);
|
||||
lws_latency(context, wsi,
|
||||
"SSL_connect LWS_CONNMODE_WS_CLIENT_WAITING_SSL",
|
||||
"SSL_connect LWSCM_WSCL_WAITING_SSL",
|
||||
n, n > 0);
|
||||
|
||||
if (n < 0) {
|
||||
|
@ -306,7 +306,7 @@ some_wait:
|
|||
if (n != SSL_ERROR_NONE) {
|
||||
lwsl_err("SSL connect error %lu: %s\n",
|
||||
n, ERR_error_string(n,
|
||||
(char *)context->service_buffer));
|
||||
(char *)context->serv_buf));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -329,7 +329,7 @@ some_wait:
|
|||
lwsl_notice("accepting self-signed certificate\n");
|
||||
} else {
|
||||
lwsl_err("server's cert didn't look good, X509_V_ERR = %d: %s\n",
|
||||
n, ERR_error_string(n, (char *)context->service_buffer));
|
||||
n, ERR_error_string(n, (char *)context->serv_buf));
|
||||
lws_close_free_wsi(wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
return 0;
|
||||
|
@ -340,13 +340,13 @@ some_wait:
|
|||
wsi->ssl = NULL;
|
||||
#endif
|
||||
|
||||
wsi->mode = LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE2;
|
||||
wsi->mode = LWSCM_WSCL_ISSUE_HANDSHAKE2;
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND,
|
||||
AWAITING_TIMEOUT);
|
||||
|
||||
/* fallthru */
|
||||
|
||||
case LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE2:
|
||||
case LWSCM_WSCL_ISSUE_HANDSHAKE2:
|
||||
p = lws_generate_client_handshake(wsi, p);
|
||||
if (p == NULL) {
|
||||
lwsl_err("Failed to generate handshake for client\n");
|
||||
|
@ -358,10 +358,10 @@ some_wait:
|
|||
|
||||
lws_latency_pre(context, wsi);
|
||||
|
||||
n = lws_ssl_capable_write(wsi, context->service_buffer,
|
||||
p - (char *)context->service_buffer);
|
||||
n = lws_ssl_capable_write(wsi, context->serv_buf,
|
||||
p - (char *)context->serv_buf);
|
||||
lws_latency(context, wsi, "send lws_issue_raw", n,
|
||||
n == p - (char *)context->service_buffer);
|
||||
n == p - (char *)context->serv_buf);
|
||||
switch (n) {
|
||||
case LWS_SSL_CAPABLE_ERROR:
|
||||
lwsl_debug("ERROR writing to client socket\n");
|
||||
|
@ -374,12 +374,12 @@ some_wait:
|
|||
|
||||
wsi->u.hdr.parser_state = WSI_TOKEN_NAME_PART;
|
||||
wsi->u.hdr.lextable_pos = 0;
|
||||
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY;
|
||||
wsi->mode = LWSCM_WSCL_WAITING_SERVER_REPLY;
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE,
|
||||
AWAITING_TIMEOUT);
|
||||
break;
|
||||
|
||||
case LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY:
|
||||
case LWSCM_WSCL_WAITING_SERVER_REPLY:
|
||||
|
||||
/* handle server hung up on us */
|
||||
|
||||
|
@ -454,12 +454,12 @@ bail3:
|
|||
lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS);
|
||||
return -1;
|
||||
|
||||
case LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT:
|
||||
lwsl_ext("LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT\n");
|
||||
case LWSCM_WSCL_WAITING_EXTENSION_CONNECT:
|
||||
lwsl_ext("LWSCM_WSCL_WAITING_EXTENSION_CONNECT\n");
|
||||
break;
|
||||
|
||||
case LWS_CONNMODE_WS_CLIENT_PENDING_CANDIDATE_CHILD:
|
||||
lwsl_ext("LWS_CONNMODE_WS_CLIENT_PENDING_CANDIDATE_CHILD\n");
|
||||
case LWSCM_WSCL_PENDING_CANDIDATE_CHILD:
|
||||
lwsl_ext("LWSCM_WSCL_PENDING_CANDIDATE_CHILD\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -620,13 +620,13 @@ check_extensions:
|
|||
* and go through matching them or identifying bogons
|
||||
*/
|
||||
|
||||
if (lws_hdr_copy(wsi, (char *)context->service_buffer,
|
||||
sizeof(context->service_buffer), WSI_TOKEN_EXTENSIONS) < 0) {
|
||||
if (lws_hdr_copy(wsi, (char *)context->serv_buf,
|
||||
sizeof(context->serv_buf), WSI_TOKEN_EXTENSIONS) < 0) {
|
||||
lwsl_warn("ext list from server failed to copy\n");
|
||||
goto bail2;
|
||||
}
|
||||
|
||||
c = (char *)context->service_buffer;
|
||||
c = (char *)context->serv_buf;
|
||||
n = 0;
|
||||
while (more) {
|
||||
|
||||
|
@ -730,8 +730,8 @@ check_accept:
|
|||
|
||||
lws_free(wsi->u.hdr.ah);
|
||||
|
||||
lws_union_transition(wsi, LWS_CONNMODE_WS_CLIENT);
|
||||
wsi->state = WSI_STATE_ESTABLISHED;
|
||||
lws_union_transition(wsi, LWSCM_WS_CLIENT);
|
||||
wsi->state = LWSS_ESTABLISHED;
|
||||
|
||||
wsi->rxflow_change_to = LWS_RXFLOW_ALLOW;
|
||||
|
||||
|
@ -787,7 +787,7 @@ check_accept:
|
|||
return 0;
|
||||
|
||||
bail3:
|
||||
lws_free2(wsi->u.ws.rx_user_buffer);
|
||||
lws_free_set_NULL(wsi->u.ws.rx_user_buffer);
|
||||
close_reason = LWS_CLOSE_STATUS_NOSTATUS;
|
||||
|
||||
bail2:
|
||||
|
@ -807,7 +807,7 @@ bail2:
|
|||
lwsl_info("closing connection due to bail2 connection error\n");
|
||||
|
||||
/* free up his parsing allocations */
|
||||
lws_free2(wsi->u.hdr.ah);
|
||||
lws_free_set_NULL(wsi->u.hdr.ah);
|
||||
lws_close_free_wsi(wsi, close_reason);
|
||||
|
||||
return 1;
|
||||
|
@ -893,7 +893,7 @@ lws_generate_client_handshake(struct lws *wsi, char *pkt)
|
|||
ext = context->extensions;
|
||||
while (ext && ext->callback) {
|
||||
|
||||
n = lws_ext_callback_for_each_extension_type(context, wsi,
|
||||
n = lws_ext_cb_all_exts(context, wsi,
|
||||
LWS_EXT_CALLBACK_CHECK_OK_TO_PROPOSE_EXTENSION,
|
||||
(char *)ext->name, 0);
|
||||
if (n) { /* an extension vetos us */
|
||||
|
@ -939,7 +939,7 @@ lws_generate_client_handshake(struct lws *wsi, char *pkt)
|
|||
context->protocols[0].callback(wsi,
|
||||
LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER,
|
||||
NULL, &p,
|
||||
(pkt + sizeof(context->service_buffer)) - p - 12);
|
||||
(pkt + sizeof(context->serv_buf)) - p - 12);
|
||||
|
||||
p += sprintf(p, "\x0d\x0a");
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ lws_create_context(struct lws_context_creation_info *info)
|
|||
lwsl_notice(" Started with daemon pid %d\n", pid_daemon);
|
||||
}
|
||||
#endif
|
||||
context->listen_service_extraseen = 0;
|
||||
context->lserv_seen = 0;
|
||||
context->protocols = info->protocols;
|
||||
context->token_limits = info->token_limits;
|
||||
context->listen_port = info->port;
|
||||
|
@ -226,11 +226,11 @@ lws_create_context(struct lws_context_creation_info *info)
|
|||
* allocations they need
|
||||
*/
|
||||
if (info->port != CONTEXT_PORT_NO_LISTEN) {
|
||||
if (lws_ext_callback_for_each_extension_type(context, NULL,
|
||||
if (lws_ext_cb_all_exts(context, NULL,
|
||||
LWS_EXT_CALLBACK_SERVER_CONTEXT_CONSTRUCT, NULL, 0) < 0)
|
||||
goto bail;
|
||||
} else
|
||||
if (lws_ext_callback_for_each_extension_type(context, NULL,
|
||||
if (lws_ext_cb_all_exts(context, NULL,
|
||||
LWS_EXT_CALLBACK_CLIENT_CONTEXT_CONSTRUCT, NULL, 0) < 0)
|
||||
goto bail;
|
||||
|
||||
|
@ -279,10 +279,10 @@ lws_context_destroy(struct lws_context *context)
|
|||
* allocations they might have made
|
||||
*/
|
||||
|
||||
n = lws_ext_callback_for_each_extension_type(context, NULL,
|
||||
n = lws_ext_cb_all_exts(context, NULL,
|
||||
LWS_EXT_CALLBACK_SERVER_CONTEXT_DESTRUCT, NULL, 0);
|
||||
|
||||
n = lws_ext_callback_for_each_extension_type(context, NULL,
|
||||
n = lws_ext_cb_all_exts(context, NULL,
|
||||
LWS_EXT_CALLBACK_CLIENT_CONTEXT_DESTRUCT, NULL, 0);
|
||||
|
||||
/*
|
||||
|
|
|
@ -74,7 +74,7 @@ static void lws_daemon_closing(int sigact)
|
|||
if (getpid() == pid_daemon)
|
||||
if (lock_path) {
|
||||
unlink(lock_path);
|
||||
lws_free2(lock_path);
|
||||
lws_free_set_NULL(lock_path);
|
||||
}
|
||||
|
||||
kill(getpid(), SIGKILL);
|
||||
|
|
|
@ -43,8 +43,7 @@ LWS_VISIBLE struct lws_extension *lws_get_internal_extensions()
|
|||
|
||||
/* 0 = nobody had nonzero return, 1 = somebody had positive return, -1 = fail */
|
||||
|
||||
int lws_ext_callback_for_each_active(struct lws *wsi, int reason, void *arg,
|
||||
int len)
|
||||
int lws_ext_cb_wsi_active_exts(struct lws *wsi, int reason, void *arg, int len)
|
||||
{
|
||||
int n, m, handled = 0;
|
||||
|
||||
|
@ -68,9 +67,8 @@ int lws_ext_callback_for_each_active(struct lws *wsi, int reason, void *arg,
|
|||
return handled;
|
||||
}
|
||||
|
||||
int lws_ext_callback_for_each_extension_type(
|
||||
struct lws_context *context, struct lws *wsi,
|
||||
int reason, void *arg, int len)
|
||||
int lws_ext_cb_all_exts(struct lws_context *context, struct lws *wsi,
|
||||
int reason, void *arg, int len)
|
||||
{
|
||||
int n = 0, m, handled = 0;
|
||||
const struct lws_extension *ext = context->extensions;
|
||||
|
@ -118,7 +116,7 @@ lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len)
|
|||
ret = 0;
|
||||
|
||||
/* show every extension the new incoming data */
|
||||
m = lws_ext_callback_for_each_active(wsi,
|
||||
m = lws_ext_cb_wsi_active_exts(wsi,
|
||||
LWS_EXT_CALLBACK_PACKET_TX_PRESEND, &eff_buf, 0);
|
||||
if (m < 0)
|
||||
return -1;
|
||||
|
@ -164,7 +162,7 @@ lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len)
|
|||
* Or we had to hold on to some of it?
|
||||
*/
|
||||
|
||||
if (!lws_send_pipe_choked(wsi) && !wsi->truncated_send_len)
|
||||
if (!lws_send_pipe_choked(wsi) && !wsi->trunc_len)
|
||||
/* no we could add more, lets's do that */
|
||||
continue;
|
||||
|
||||
|
|
|
@ -66,9 +66,9 @@ lws_read(struct lws *wsi, unsigned char *buf, size_t len)
|
|||
|
||||
switch (wsi->state) {
|
||||
#ifdef LWS_USE_HTTP2
|
||||
case WSI_STATE_HTTP2_AWAIT_CLIENT_PREFACE:
|
||||
case WSI_STATE_HTTP2_ESTABLISHED_PRE_SETTINGS:
|
||||
case WSI_STATE_HTTP2_ESTABLISHED:
|
||||
case LWSS_HTTP2_AWAIT_CLIENT_PREFACE:
|
||||
case LWSS_HTTP2_ESTABLISHED_PRE_SETTINGS:
|
||||
case LWSS_HTTP2_ESTABLISHED:
|
||||
n = 0;
|
||||
while (n < len) {
|
||||
/*
|
||||
|
@ -89,15 +89,15 @@ lws_read(struct lws *wsi, unsigned char *buf, size_t len)
|
|||
break;
|
||||
#endif
|
||||
http_new:
|
||||
case WSI_STATE_HTTP:
|
||||
case LWSS_HTTP:
|
||||
wsi->hdr_parsing_completed = 0;
|
||||
/* fallthru */
|
||||
case WSI_STATE_HTTP_ISSUING_FILE:
|
||||
wsi->state = WSI_STATE_HTTP_HEADERS;
|
||||
case LWSS_HTTP_ISSUING_FILE:
|
||||
wsi->state = LWSS_HTTP_HEADERS;
|
||||
wsi->u.hdr.parser_state = WSI_TOKEN_NAME_PART;
|
||||
wsi->u.hdr.lextable_pos = 0;
|
||||
/* fallthru */
|
||||
case WSI_STATE_HTTP_HEADERS:
|
||||
case LWSS_HTTP_HEADERS:
|
||||
lwsl_parser("issuing %d bytes to parser\n", (int)len);
|
||||
|
||||
if (lws_handshake_client(wsi, &buf, len))
|
||||
|
@ -109,8 +109,10 @@ http_new:
|
|||
goto bail;
|
||||
|
||||
/* It's possible that we've exhausted our data already, but
|
||||
* lws_handshake_server doesn't update len for us. Figure out how
|
||||
* much was read, so that we can proceed appropriately: */
|
||||
* lws_handshake_server doesn't update len for us.
|
||||
* Figure out how much was read, so that we can proceed
|
||||
* appropriately:
|
||||
*/
|
||||
len -= (buf - last_char);
|
||||
|
||||
if (!wsi->hdr_parsing_completed)
|
||||
|
@ -118,12 +120,12 @@ http_new:
|
|||
goto read_ok;
|
||||
|
||||
switch (wsi->state) {
|
||||
case WSI_STATE_HTTP:
|
||||
case WSI_STATE_HTTP_HEADERS:
|
||||
case LWSS_HTTP:
|
||||
case LWSS_HTTP_HEADERS:
|
||||
goto http_complete;
|
||||
case WSI_STATE_HTTP_ISSUING_FILE:
|
||||
case LWSS_HTTP_ISSUING_FILE:
|
||||
goto read_ok;
|
||||
case WSI_STATE_HTTP_BODY:
|
||||
case LWSS_HTTP_BODY:
|
||||
wsi->u.http.content_remain =
|
||||
wsi->u.http.content_length;
|
||||
if (wsi->u.http.content_remain)
|
||||
|
@ -136,7 +138,7 @@ http_new:
|
|||
}
|
||||
break;
|
||||
|
||||
case WSI_STATE_HTTP_BODY:
|
||||
case LWSS_HTTP_BODY:
|
||||
http_postbody:
|
||||
while (len && wsi->u.http.content_remain) {
|
||||
/* Copy as much as possible, up to the limit of:
|
||||
|
@ -173,12 +175,12 @@ postbody_completion:
|
|||
}
|
||||
break;
|
||||
|
||||
case WSI_STATE_ESTABLISHED:
|
||||
case WSI_STATE_AWAITING_CLOSE_ACK:
|
||||
case LWSS_ESTABLISHED:
|
||||
case LWSS_AWAITING_CLOSE_ACK:
|
||||
if (lws_handshake_client(wsi, &buf, len))
|
||||
goto bail;
|
||||
switch (wsi->mode) {
|
||||
case LWS_CONNMODE_WS_SERVING:
|
||||
case LWSCM_WS_SERVING:
|
||||
|
||||
if (lws_interpret_incoming_packet(wsi, buf, len) < 0) {
|
||||
lwsl_info("interpret_incoming_packet has bailed\n");
|
||||
|
|
21
lib/header.c
21
lib/header.c
|
@ -36,7 +36,7 @@ lws_add_http_header_by_name(struct lws *wsi, const unsigned char *name,
|
|||
unsigned char **p, unsigned char *end)
|
||||
{
|
||||
#ifdef LWS_USE_HTTP2
|
||||
if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING)
|
||||
if (wsi->mode == LWSCM_HTTP2_SERVING)
|
||||
return lws_add_http2_header_by_name(wsi, name,
|
||||
value, length, p, end);
|
||||
#else
|
||||
|
@ -64,7 +64,7 @@ int lws_finalize_http_header(struct lws *wsi, unsigned char **p,
|
|||
unsigned char *end)
|
||||
{
|
||||
#ifdef LWS_USE_HTTP2
|
||||
if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING)
|
||||
if (wsi->mode == LWSCM_HTTP2_SERVING)
|
||||
return 0;
|
||||
#else
|
||||
(void)wsi;
|
||||
|
@ -84,7 +84,7 @@ lws_add_http_header_by_token(struct lws *wsi, enum lws_token_indexes token,
|
|||
{
|
||||
const unsigned char *name;
|
||||
#ifdef LWS_USE_HTTP2
|
||||
if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING)
|
||||
if (wsi->mode == LWSCM_HTTP2_SERVING)
|
||||
return lws_add_http2_header_by_token(wsi, token, value, length, p, end);
|
||||
#endif
|
||||
name = lws_token_to_string(token);
|
||||
|
@ -101,7 +101,8 @@ int lws_add_http_header_content_length(struct lws *wsi,
|
|||
int n;
|
||||
|
||||
n = sprintf(b, "%lu", content_length);
|
||||
if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH, (unsigned char *)b, n, p, end))
|
||||
if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH,
|
||||
(unsigned char *)b, n, p, end))
|
||||
return 1;
|
||||
wsi->u.http.content_length = content_length;
|
||||
wsi->u.http.content_remain = content_length;
|
||||
|
@ -140,16 +141,15 @@ static const char *err500[] = {
|
|||
};
|
||||
|
||||
int
|
||||
lws_add_http_header_status(struct lws *wsi,
|
||||
unsigned int code, unsigned char **p,
|
||||
unsigned char *end)
|
||||
lws_add_http_header_status(struct lws *wsi, unsigned int code,
|
||||
unsigned char **p, unsigned char *end)
|
||||
{
|
||||
unsigned char code_and_desc[60];
|
||||
const char *description = "";
|
||||
int n;
|
||||
|
||||
#ifdef LWS_USE_HTTP2
|
||||
if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING)
|
||||
if (wsi->mode == LWSCM_HTTP2_SERVING)
|
||||
return lws_add_http2_header_status(wsi, code, p, end);
|
||||
#endif
|
||||
if (code >= 400 && code < (400 + ARRAY_SIZE(err400)))
|
||||
|
@ -165,7 +165,6 @@ lws_add_http_header_status(struct lws *wsi,
|
|||
|
||||
/**
|
||||
* lws_return_http_status() - Return simple http status
|
||||
* @context: libwebsockets context
|
||||
* @wsi: Websocket instance (available from user callback)
|
||||
* @code: Status index, eg, 404
|
||||
* @html_body: User-readable HTML description < 1KB, or NULL
|
||||
|
@ -178,10 +177,10 @@ lws_return_http_status(struct lws *wsi, unsigned int code, const char *html_body
|
|||
{
|
||||
int n, m;
|
||||
struct lws_context *context = lws_get_ctx(wsi);
|
||||
unsigned char *p = context->service_buffer +
|
||||
unsigned char *p = context->serv_buf +
|
||||
LWS_SEND_BUFFER_PRE_PADDING;
|
||||
unsigned char *start = p;
|
||||
unsigned char *end = p + sizeof(context->service_buffer) -
|
||||
unsigned char *end = p + sizeof(context->serv_buf) -
|
||||
LWS_SEND_BUFFER_PRE_PADDING;
|
||||
|
||||
if (!html_body)
|
||||
|
|
14
lib/http2.c
14
lib/http2.c
|
@ -79,7 +79,7 @@ lws_create_server_child_wsi(struct lws_context *context, struct lws *parent_wsi,
|
|||
wsi->u.http2.my_priority = 16;
|
||||
wsi->u.http2.tx_credit = 65535;
|
||||
|
||||
wsi->state = WSI_STATE_HTTP2_ESTABLISHED;
|
||||
wsi->state = LWSS_HTTP2_ESTABLISHED;
|
||||
wsi->mode = parent_wsi->mode;
|
||||
|
||||
wsi->protocol = &context->protocols[0];
|
||||
|
@ -203,13 +203,13 @@ lws_http2_parser(struct lws *wsi, unsigned char c)
|
|||
int n;
|
||||
|
||||
switch (wsi->state) {
|
||||
case WSI_STATE_HTTP2_AWAIT_CLIENT_PREFACE:
|
||||
case LWSS_HTTP2_AWAIT_CLIENT_PREFACE:
|
||||
if (https_client_preface[wsi->u.http2.count++] != c)
|
||||
return 1;
|
||||
|
||||
if (!https_client_preface[wsi->u.http2.count]) {
|
||||
lwsl_info("http2: %p: established\n", wsi);
|
||||
wsi->state = WSI_STATE_HTTP2_ESTABLISHED_PRE_SETTINGS;
|
||||
wsi->state = LWSS_HTTP2_ESTABLISHED_PRE_SETTINGS;
|
||||
wsi->u.http2.count = 0;
|
||||
wsi->u.http2.tx_credit = 65535;
|
||||
|
||||
|
@ -224,8 +224,8 @@ lws_http2_parser(struct lws *wsi, unsigned char c)
|
|||
}
|
||||
break;
|
||||
|
||||
case WSI_STATE_HTTP2_ESTABLISHED_PRE_SETTINGS:
|
||||
case WSI_STATE_HTTP2_ESTABLISHED:
|
||||
case LWSS_HTTP2_ESTABLISHED_PRE_SETTINGS:
|
||||
case LWSS_HTTP2_ESTABLISHED:
|
||||
if (wsi->u.http2.frame_state == LWS_HTTP2_FRAME_HEADER_LENGTH) { // payload
|
||||
wsi->u.http2.count++;
|
||||
wsi->u.http2.stream_wsi->u.http2.count = wsi->u.http2.count;
|
||||
|
@ -457,8 +457,8 @@ int lws_http2_do_pps_send(struct lws_context *context, struct lws *wsi)
|
|||
return 1;
|
||||
}
|
||||
/* this is the end of the preface dance then? */
|
||||
if (wsi->state == WSI_STATE_HTTP2_ESTABLISHED_PRE_SETTINGS) {
|
||||
wsi->state = WSI_STATE_HTTP2_ESTABLISHED;
|
||||
if (wsi->state == LWSS_HTTP2_ESTABLISHED_PRE_SETTINGS) {
|
||||
wsi->state = LWSS_HTTP2_ESTABLISHED;
|
||||
|
||||
wsi->u.http.fd = LWS_INVALID_FILE;
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ lws_initloop(
|
|||
* and register a callback for read operations:
|
||||
*/
|
||||
ev_io_init(w_accept, lws_accept_cb,
|
||||
context->listen_service_fd, EV_READ);
|
||||
context->lserv_fd, EV_READ);
|
||||
ev_io_start(context->io_loop,w_accept);
|
||||
|
||||
/* Register the signal watcher unless the user has indicated otherwise: */
|
||||
|
|
|
@ -50,8 +50,8 @@ lws_free_wsi(struct lws *wsi)
|
|||
wsi->user_space && !wsi->user_space_externally_allocated)
|
||||
lws_free(wsi->user_space);
|
||||
|
||||
lws_free2(wsi->rxflow_buffer);
|
||||
lws_free2(wsi->truncated_send_malloc);
|
||||
lws_free_set_NULL(wsi->rxflow_buffer);
|
||||
lws_free_set_NULL(wsi->trunc_alloc);
|
||||
lws_free_header_table(wsi);
|
||||
lws_free(wsi);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason)
|
|||
|
||||
old_state = wsi->state;
|
||||
|
||||
if (wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED &&
|
||||
if (wsi->mode == LWSCM_HTTP_SERVING_ACCEPTED &&
|
||||
wsi->u.http.fd != LWS_INVALID_FILE) {
|
||||
lwsl_debug("closing http file\n");
|
||||
lws_plat_file_close(wsi, wsi->u.http.fd);
|
||||
|
@ -83,24 +83,24 @@ lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason)
|
|||
goto just_kill_connection;
|
||||
|
||||
switch (old_state) {
|
||||
case WSI_STATE_DEAD_SOCKET:
|
||||
case LWSS_DEAD_SOCKET:
|
||||
return;
|
||||
|
||||
/* we tried the polite way... */
|
||||
case WSI_STATE_AWAITING_CLOSE_ACK:
|
||||
case LWSS_AWAITING_CLOSE_ACK:
|
||||
goto just_kill_connection;
|
||||
|
||||
case WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE:
|
||||
if (wsi->truncated_send_len) {
|
||||
case LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE:
|
||||
if (wsi->trunc_len) {
|
||||
lws_callback_on_writable(wsi);
|
||||
return;
|
||||
}
|
||||
lwsl_info("wsi %p completed WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE\n", wsi);
|
||||
lwsl_info("wsi %p completed LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE\n", wsi);
|
||||
goto just_kill_connection;
|
||||
default:
|
||||
if (wsi->truncated_send_len) {
|
||||
lwsl_info("wsi %p entering WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE\n", wsi);
|
||||
wsi->state = WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE;
|
||||
if (wsi->trunc_len) {
|
||||
lwsl_info("wsi %p entering LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE\n", wsi);
|
||||
wsi->state = LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE;
|
||||
lws_set_timeout(wsi, PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE, 5);
|
||||
return;
|
||||
}
|
||||
|
@ -109,11 +109,11 @@ lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason)
|
|||
|
||||
wsi->u.ws.close_reason = reason;
|
||||
|
||||
if (wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT ||
|
||||
wsi->mode == LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE)
|
||||
if (wsi->mode == LWSCM_WSCL_WAITING_CONNECT ||
|
||||
wsi->mode == LWSCM_WSCL_ISSUE_HANDSHAKE)
|
||||
goto just_kill_connection;
|
||||
|
||||
if (wsi->mode == LWS_CONNMODE_HTTP_SERVING)
|
||||
if (wsi->mode == LWSCM_HTTP_SERVING)
|
||||
context->protocols[0].callback(wsi, LWS_CALLBACK_CLOSED_HTTP,
|
||||
wsi->user_space, NULL, 0);
|
||||
|
||||
|
@ -122,7 +122,7 @@ lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason)
|
|||
* parent and just his ch1 aspect is closing?
|
||||
*/
|
||||
|
||||
if (lws_ext_callback_for_each_active(wsi,
|
||||
if (lws_ext_cb_wsi_active_exts(wsi,
|
||||
LWS_EXT_CALLBACK_CHECK_OK_TO_REALLY_CLOSE, NULL, 0) > 0) {
|
||||
lwsl_ext("extension vetoed close\n");
|
||||
return;
|
||||
|
@ -140,7 +140,7 @@ lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason)
|
|||
|
||||
/* show every extension the new incoming data */
|
||||
|
||||
m = lws_ext_callback_for_each_active(wsi,
|
||||
m = lws_ext_cb_wsi_active_exts(wsi,
|
||||
LWS_EXT_CALLBACK_FLUSH_PENDING_TX, &eff_buf, 0);
|
||||
if (m < 0) {
|
||||
lwsl_ext("Extension reports fatal error\n");
|
||||
|
@ -169,19 +169,17 @@ lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason)
|
|||
* add any necessary version-specific stuff. If the write fails,
|
||||
* no worries we are closing anyway. If we didn't initiate this
|
||||
* close, then our state has been changed to
|
||||
* WSI_STATE_RETURNED_CLOSE_ALREADY and we will skip this.
|
||||
* LWSS_RETURNED_CLOSE_ALREADY and we will skip this.
|
||||
*
|
||||
* Likewise if it's a second call to close this connection after we
|
||||
* sent the close indication to the peer already, we are in state
|
||||
* WSI_STATE_AWAITING_CLOSE_ACK and will skip doing this a second time.
|
||||
* LWSS_AWAITING_CLOSE_ACK and will skip doing this a second time.
|
||||
*/
|
||||
|
||||
if (old_state == WSI_STATE_ESTABLISHED &&
|
||||
if (old_state == LWSS_ESTABLISHED &&
|
||||
reason != LWS_CLOSE_STATUS_NOSTATUS &&
|
||||
reason != LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY) {
|
||||
|
||||
lwsl_debug("sending close indication...\n");
|
||||
|
||||
/* make valgrind happy */
|
||||
memset(buf, 0, sizeof(buf));
|
||||
n = lws_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING + 2],
|
||||
|
@ -191,7 +189,7 @@ lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason)
|
|||
* we have sent a nice protocol level indication we
|
||||
* now wish to close, we should not send anything more
|
||||
*/
|
||||
wsi->state = WSI_STATE_AWAITING_CLOSE_ACK;
|
||||
wsi->state = LWSS_AWAITING_CLOSE_ACK;
|
||||
|
||||
/*
|
||||
* ...and we should wait for a reply for a bit
|
||||
|
@ -221,23 +219,23 @@ just_kill_connection:
|
|||
/* checking return redundant since we anyway close */
|
||||
remove_wsi_socket_from_fds(wsi);
|
||||
|
||||
wsi->state = WSI_STATE_DEAD_SOCKET;
|
||||
wsi->state = LWSS_DEAD_SOCKET;
|
||||
|
||||
lws_free2(wsi->rxflow_buffer);
|
||||
lws_free_set_NULL(wsi->rxflow_buffer);
|
||||
lws_free_header_table(wsi);
|
||||
|
||||
if ((old_state == WSI_STATE_ESTABLISHED ||
|
||||
wsi->mode == LWS_CONNMODE_WS_SERVING ||
|
||||
wsi->mode == LWS_CONNMODE_WS_CLIENT)) {
|
||||
if (old_state == LWSS_ESTABLISHED ||
|
||||
wsi->mode == LWSCM_WS_SERVING ||
|
||||
wsi->mode == LWSCM_WS_CLIENT) {
|
||||
|
||||
lws_free2(wsi->u.ws.rx_user_buffer);
|
||||
lws_free_set_NULL(wsi->u.ws.rx_user_buffer);
|
||||
|
||||
if (wsi->truncated_send_malloc)
|
||||
if (wsi->trunc_alloc)
|
||||
/* not going to be completed... nuke it */
|
||||
lws_free2(wsi->truncated_send_malloc);
|
||||
lws_free_set_NULL(wsi->trunc_alloc);
|
||||
|
||||
if (wsi->u.ws.ping_payload_buf) {
|
||||
lws_free2(wsi->u.ws.ping_payload_buf);
|
||||
lws_free_set_NULL(wsi->u.ws.ping_payload_buf);
|
||||
wsi->u.ws.ping_payload_alloc = 0;
|
||||
wsi->u.ws.ping_payload_len = 0;
|
||||
wsi->u.ws.ping_pending_flag = 0;
|
||||
|
@ -247,19 +245,19 @@ just_kill_connection:
|
|||
/* tell the user it's all over for this guy */
|
||||
|
||||
if (wsi->protocol && wsi->protocol->callback &&
|
||||
((old_state == WSI_STATE_ESTABLISHED) ||
|
||||
(old_state == WSI_STATE_RETURNED_CLOSE_ALREADY) ||
|
||||
(old_state == WSI_STATE_AWAITING_CLOSE_ACK) ||
|
||||
(old_state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE))) {
|
||||
((old_state == LWSS_ESTABLISHED) ||
|
||||
(old_state == LWSS_RETURNED_CLOSE_ALREADY) ||
|
||||
(old_state == LWSS_AWAITING_CLOSE_ACK) ||
|
||||
(old_state == LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE))) {
|
||||
lwsl_debug("calling back CLOSED\n");
|
||||
wsi->protocol->callback(wsi, LWS_CALLBACK_CLOSED,
|
||||
wsi->user_space, NULL, 0);
|
||||
} else if (wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED) {
|
||||
} else if (wsi->mode == LWSCM_HTTP_SERVING_ACCEPTED) {
|
||||
lwsl_debug("calling back CLOSED_HTTP\n");
|
||||
context->protocols[0].callback(wsi, LWS_CALLBACK_CLOSED_HTTP,
|
||||
wsi->user_space, NULL, 0 );
|
||||
} else if (wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY ||
|
||||
wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT) {
|
||||
} else if (wsi->mode == LWSCM_WSCL_WAITING_SERVER_REPLY ||
|
||||
wsi->mode == LWSCM_WSCL_WAITING_CONNECT) {
|
||||
lwsl_debug("Connection closed before server reply\n");
|
||||
context->protocols[0].callback(wsi,
|
||||
LWS_CALLBACK_CLIENT_CONNECTION_ERROR,
|
||||
|
@ -270,8 +268,7 @@ just_kill_connection:
|
|||
|
||||
/* deallocate any active extension contexts */
|
||||
|
||||
if (lws_ext_callback_for_each_active(wsi, LWS_EXT_CALLBACK_DESTROY,
|
||||
NULL, 0) < 0)
|
||||
if (lws_ext_cb_wsi_active_exts(wsi, LWS_EXT_CALLBACK_DESTROY, NULL, 0) < 0)
|
||||
lwsl_warn("extension destruction failed\n");
|
||||
#ifndef LWS_NO_EXTENSIONS
|
||||
for (n = 0; n < wsi->count_active_extensions; n++)
|
||||
|
@ -281,7 +278,7 @@ just_kill_connection:
|
|||
* inform all extensions in case they tracked this guy out of band
|
||||
* even though not active on him specifically
|
||||
*/
|
||||
if (lws_ext_callback_for_each_extension_type(context, wsi,
|
||||
if (lws_ext_cb_all_exts(context, wsi,
|
||||
LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING, NULL, 0) < 0)
|
||||
lwsl_warn("ext destroy wsi failed\n");
|
||||
|
||||
|
@ -392,7 +389,6 @@ lws_get_addresses(struct lws_context *context, void *ads, char *name,
|
|||
|
||||
/**
|
||||
* lws_get_peer_addresses() - Get client address information
|
||||
* @context: Libwebsockets context
|
||||
* @wsi: Local struct lws associated with
|
||||
* @fd: Connection socket descriptor
|
||||
* @name: Buffer to take client address name
|
||||
|
@ -884,7 +880,7 @@ lws_is_ssl(struct lws *wsi)
|
|||
LWS_VISIBLE int
|
||||
lws_partial_buffered(struct lws *wsi)
|
||||
{
|
||||
return !!wsi->truncated_send_len;
|
||||
return !!wsi->trunc_len;
|
||||
}
|
||||
|
||||
void lws_set_protocol_write_pending(struct lws *wsi,
|
||||
|
@ -904,7 +900,7 @@ lws_get_peer_write_allowance(struct lws *wsi)
|
|||
{
|
||||
#ifdef LWS_USE_HTTP2
|
||||
/* only if we are using HTTP2 on this connection */
|
||||
if (wsi->mode != LWS_CONNMODE_HTTP2_SERVING)
|
||||
if (wsi->mode != LWSCM_HTTP2_SERVING)
|
||||
return -1;
|
||||
/* user is only interested in how much he can send, or that he can't */
|
||||
if (wsi->u.http2.tx_credit <= 0)
|
||||
|
|
|
@ -760,7 +760,6 @@ struct lws_extension;
|
|||
|
||||
/**
|
||||
* callback_function() - User server actions
|
||||
* @context: Websockets context
|
||||
* @wsi: Opaque websocket instance pointer
|
||||
* @reason: The reason for the call
|
||||
* @user: Pointer to per-session user data allocated by library
|
||||
|
|
|
@ -45,7 +45,7 @@ LWS_VISIBLE int lws_send_pipe_choked(struct lws *wsi)
|
|||
struct lws_pollfd fds;
|
||||
|
||||
/* treat the fact we got a truncated send pending as if we're choked */
|
||||
if (wsi->truncated_send_len)
|
||||
if (wsi->trunc_len)
|
||||
return 1;
|
||||
|
||||
fds.fd = wsi->sock;
|
||||
|
|
|
@ -14,18 +14,19 @@ unsigned long long time_in_microseconds(void)
|
|||
return ((unsigned long long)tv.tv_sec * 1000000LL) + tv.tv_usec;
|
||||
}
|
||||
|
||||
LWS_VISIBLE int lws_get_random(struct lws_context *context,
|
||||
void *buf, int len)
|
||||
LWS_VISIBLE int
|
||||
lws_get_random(struct lws_context *context, void *buf, int len)
|
||||
{
|
||||
return read(context->fd_random, (char *)buf, len);
|
||||
}
|
||||
|
||||
LWS_VISIBLE int lws_send_pipe_choked(struct lws *wsi)
|
||||
LWS_VISIBLE int
|
||||
lws_send_pipe_choked(struct lws *wsi)
|
||||
{
|
||||
struct lws_pollfd fds;
|
||||
|
||||
/* treat the fact we got a truncated send pending as if we're choked */
|
||||
if (wsi->truncated_send_len)
|
||||
if (wsi->trunc_len)
|
||||
return 1;
|
||||
|
||||
fds.fd = wsi->sock;
|
||||
|
@ -148,9 +149,9 @@ lws_plat_service(struct lws_context *context, int timeout_ms)
|
|||
wsi = context->pending_read_list;
|
||||
while (wsi) {
|
||||
wsi_next = wsi->pending_read_list_next;
|
||||
context->fds[wsi->position_in_fds_table].revents |=
|
||||
context->fds[wsi->position_in_fds_table].events & POLLIN;
|
||||
if (context->fds[wsi->position_in_fds_table].revents & POLLIN) {
|
||||
context->fds[wsi->position_in_fds_table].revents |=
|
||||
context->fds[wsi->position_in_fds_table].events & POLLIN;
|
||||
if (context->fds[wsi->position_in_fds_table].revents & POLLIN)
|
||||
/*
|
||||
* he's going to get serviced now, take him off the
|
||||
* list of guys with buffered SSL. If he still has some
|
||||
|
@ -158,7 +159,7 @@ lws_plat_service(struct lws_context *context, int timeout_ms)
|
|||
* list then.
|
||||
*/
|
||||
lws_ssl_remove_wsi_from_buffered_list(wsi);
|
||||
}
|
||||
|
||||
wsi = wsi_next;
|
||||
}
|
||||
#endif
|
||||
|
@ -166,7 +167,6 @@ lws_plat_service(struct lws_context *context, int timeout_ms)
|
|||
/* any socket with events to service? */
|
||||
|
||||
for (n = 0; n < context->fds_count; n++) {
|
||||
|
||||
if (!context->fds[n].revents)
|
||||
continue;
|
||||
|
||||
|
@ -202,7 +202,7 @@ lws_plat_set_socket_options(struct lws_context *context, int fd)
|
|||
/* enable keepalive on this socket */
|
||||
optval = 1;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE,
|
||||
(const void *)&optval, optlen) < 0)
|
||||
(const void *)&optval, optlen) < 0)
|
||||
return 1;
|
||||
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
|
||||
|
@ -216,17 +216,17 @@ lws_plat_set_socket_options(struct lws_context *context, int fd)
|
|||
/* set the keepalive conditions we want on it too */
|
||||
optval = context->ka_time;
|
||||
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE,
|
||||
(const void *)&optval, optlen) < 0)
|
||||
(const void *)&optval, optlen) < 0)
|
||||
return 1;
|
||||
|
||||
optval = context->ka_interval;
|
||||
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL,
|
||||
(const void *)&optval, optlen) < 0)
|
||||
(const void *)&optval, optlen) < 0)
|
||||
return 1;
|
||||
|
||||
optval = context->ka_probes;
|
||||
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT,
|
||||
(const void *)&optval, optlen) < 0)
|
||||
(const void *)&optval, optlen) < 0)
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
@ -275,7 +275,6 @@ static void sigpipe_handler(int x)
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
LWS_VISIBLE int
|
||||
lws_plat_context_early_init(void)
|
||||
{
|
||||
|
@ -398,7 +397,7 @@ lws_plat_service_periodic(struct lws_context *context)
|
|||
{
|
||||
/* if our parent went down, don't linger around */
|
||||
if (context->started_with_parent &&
|
||||
kill(context->started_with_parent, 0) < 0)
|
||||
kill(context->started_with_parent, 0) < 0)
|
||||
kill(getpid(), SIGTERM);
|
||||
}
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ lws_plat_service(struct lws_context *context, int timeout_ms)
|
|||
|
||||
for (i = 0; i < context->fds_count; ++i) {
|
||||
pfd = &context->fds[i];
|
||||
if (pfd->fd == context->listen_service_fd)
|
||||
if (pfd->fd == context->lserv_fd)
|
||||
continue;
|
||||
|
||||
if (pfd->events & LWS_POLLOUT) {
|
||||
|
|
112
lib/output.c
112
lib/output.c
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* libwebsockets - small server side websockets and web server implementation
|
||||
*
|
||||
* Copyright (C) 2010-2014 Andy Green <andy@warmcat.com>
|
||||
* Copyright (C) 2010-2015 Andy Green <andy@warmcat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -28,11 +28,10 @@ lws_0405_frame_mask_generate(struct lws *wsi)
|
|||
|
||||
/* fetch the per-frame nonce */
|
||||
|
||||
n = lws_get_random(lws_get_ctx(wsi),
|
||||
wsi->u.ws.frame_masking_nonce_04, 4);
|
||||
n = lws_get_random(lws_get_ctx(wsi), wsi->u.ws.mask_nonce, 4);
|
||||
if (n != 4) {
|
||||
lwsl_parser("Unable to read from random device %s %d\n",
|
||||
SYSTEM_RANDOM_FILEPATH, n);
|
||||
SYSTEM_RANDOM_FILEPATH, n);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -97,18 +96,18 @@ int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len)
|
|||
if (!len)
|
||||
return 0;
|
||||
/* just ignore sends after we cleared the truncation buffer */
|
||||
if (wsi->state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE &&
|
||||
!wsi->truncated_send_len)
|
||||
if (wsi->state == LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE &&
|
||||
!wsi->trunc_len)
|
||||
return len;
|
||||
|
||||
if (wsi->truncated_send_len && (buf < wsi->truncated_send_malloc ||
|
||||
buf > (wsi->truncated_send_malloc + wsi->truncated_send_len +
|
||||
wsi->truncated_send_offset))) {
|
||||
if (wsi->trunc_len && (buf < wsi->trunc_alloc ||
|
||||
buf > (wsi->trunc_alloc + wsi->trunc_len +
|
||||
wsi->trunc_offset))) {
|
||||
lwsl_err("****** %x Sending new, pending truncated ...\n", wsi);
|
||||
assert(0);
|
||||
}
|
||||
|
||||
m = lws_ext_callback_for_each_active(wsi,
|
||||
m = lws_ext_cb_wsi_active_exts(wsi,
|
||||
LWS_EXT_CALLBACK_PACKET_TX_DO_SEND, &buf, len);
|
||||
if (m < 0)
|
||||
return -1;
|
||||
|
@ -123,11 +122,13 @@ int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len)
|
|||
/* nope, send it on the socket directly */
|
||||
lws_latency_pre(context, wsi);
|
||||
n = lws_ssl_capable_write(wsi, buf, len);
|
||||
lws_latency(context, wsi, "send lws_issue_raw", n, (unsigned int)n == len);
|
||||
lws_latency(context, wsi, "send lws_issue_raw", n,
|
||||
(unsigned int)n == len);
|
||||
|
||||
switch (n) {
|
||||
case LWS_SSL_CAPABLE_ERROR:
|
||||
lwsl_err("%s: wsi %p: LWS_SSL_CAPABLE_ERROR\n", __func__, (void *)wsi);
|
||||
lwsl_err("%s: wsi %p: LWS_SSL_CAPABLE_ERROR\n", __func__,
|
||||
(void *)wsi);
|
||||
/* we're going to close, let close know sends aren't possible */
|
||||
wsi->socket_is_permanently_unusable = 1;
|
||||
return -1;
|
||||
|
@ -141,17 +142,16 @@ handle_truncated_send:
|
|||
/*
|
||||
* we were already handling a truncated send?
|
||||
*/
|
||||
if (wsi->truncated_send_len) {
|
||||
lwsl_info("***** %x partial send moved on by %d (vs %d)\n",
|
||||
wsi, n, real_len);
|
||||
wsi->truncated_send_offset += n;
|
||||
wsi->truncated_send_len -= n;
|
||||
if (wsi->trunc_len) {
|
||||
lwsl_info("%p partial adv %d (vs %d)\n", wsi, n, real_len);
|
||||
wsi->trunc_offset += n;
|
||||
wsi->trunc_len -= n;
|
||||
|
||||
if (!wsi->truncated_send_len) {
|
||||
if (!wsi->trunc_len) {
|
||||
lwsl_info("***** %x partial send completed\n", wsi);
|
||||
/* done with it, but don't free it */
|
||||
n = real_len;
|
||||
if (wsi->state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE) {
|
||||
if (wsi->state == LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE) {
|
||||
lwsl_info("***** %x signalling to close now\n", wsi);
|
||||
return -1; /* retry closing now */
|
||||
}
|
||||
|
@ -180,29 +180,27 @@ handle_truncated_send:
|
|||
* Newly truncated send. Buffer the remainder (it will get
|
||||
* first priority next time the socket is writable)
|
||||
*/
|
||||
lwsl_info("***** %x new partial sent %d from %d total\n",
|
||||
wsi, n, real_len);
|
||||
lwsl_info("%p new partial sent %d from %d total\n", wsi, n, real_len);
|
||||
|
||||
/*
|
||||
* - if we still have a suitable malloc lying around, use it
|
||||
* - or, if too small, reallocate it
|
||||
* - or, if no buffer, create it
|
||||
*/
|
||||
if (!wsi->truncated_send_malloc ||
|
||||
real_len - n > wsi->truncated_send_allocation) {
|
||||
lws_free(wsi->truncated_send_malloc);
|
||||
if (!wsi->trunc_alloc || real_len - n > wsi->trunc_alloc_len) {
|
||||
lws_free(wsi->trunc_alloc);
|
||||
|
||||
wsi->truncated_send_allocation = real_len - n;
|
||||
wsi->truncated_send_malloc = lws_malloc(real_len - n);
|
||||
if (!wsi->truncated_send_malloc) {
|
||||
wsi->trunc_alloc_len = real_len - n;
|
||||
wsi->trunc_alloc = lws_malloc(real_len - n);
|
||||
if (!wsi->trunc_alloc) {
|
||||
lwsl_err("truncated send: unable to malloc %d\n",
|
||||
real_len - n);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
wsi->truncated_send_offset = 0;
|
||||
wsi->truncated_send_len = real_len - n;
|
||||
memcpy(wsi->truncated_send_malloc, buf + n, real_len - n);
|
||||
wsi->trunc_offset = 0;
|
||||
wsi->trunc_len = real_len - n;
|
||||
memcpy(wsi->trunc_alloc, buf + n, real_len - n);
|
||||
|
||||
/* since something buffered, force it to get another chance to send */
|
||||
lws_callback_on_writable(wsi);
|
||||
|
@ -243,7 +241,7 @@ handle_truncated_send:
|
|||
LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf,
|
||||
size_t len, enum lws_write_protocol protocol)
|
||||
{
|
||||
int masked7 = wsi->mode == LWS_CONNMODE_WS_CLIENT;
|
||||
int masked7 = wsi->mode == LWSCM_WS_CLIENT;
|
||||
unsigned char is_masked_bit = 0;
|
||||
unsigned char *dropmask = NULL;
|
||||
struct lws_tokens eff_buf;
|
||||
|
@ -263,8 +261,8 @@ LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf,
|
|||
|
||||
/* websocket protocol, either binary or text */
|
||||
|
||||
if (wsi->state != WSI_STATE_ESTABLISHED &&
|
||||
!(wsi->state == WSI_STATE_RETURNED_CLOSE_ALREADY &&
|
||||
if (wsi->state != LWSS_ESTABLISHED &&
|
||||
!(wsi->state == LWSS_RETURNED_CLOSE_ALREADY &&
|
||||
protocol == LWS_WRITE_CLOSE))
|
||||
return -1;
|
||||
|
||||
|
@ -288,8 +286,8 @@ LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf,
|
|||
case LWS_WRITE_CLOSE:
|
||||
break;
|
||||
default:
|
||||
if (lws_ext_callback_for_each_active(wsi,
|
||||
LWS_EXT_CALLBACK_PAYLOAD_TX, &eff_buf, 0) < 0)
|
||||
if (lws_ext_cb_wsi_active_exts(wsi, LWS_EXT_CALLBACK_PAYLOAD_TX,
|
||||
&eff_buf, 0) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -318,17 +316,17 @@ LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf,
|
|||
|
||||
switch (protocol & 0xf) {
|
||||
case LWS_WRITE_TEXT:
|
||||
n = LWS_WS_OPCODE_07__TEXT_FRAME;
|
||||
n = LWSWSOPC_TEXT_FRAME;
|
||||
break;
|
||||
case LWS_WRITE_BINARY:
|
||||
n = LWS_WS_OPCODE_07__BINARY_FRAME;
|
||||
n = LWSWSOPC_BINARY_FRAME;
|
||||
break;
|
||||
case LWS_WRITE_CONTINUATION:
|
||||
n = LWS_WS_OPCODE_07__CONTINUATION;
|
||||
n = LWSWSOPC_CONTINUATION;
|
||||
break;
|
||||
|
||||
case LWS_WRITE_CLOSE:
|
||||
n = LWS_WS_OPCODE_07__CLOSE;
|
||||
n = LWSWSOPC_CLOSE;
|
||||
|
||||
/*
|
||||
* 06+ has a 2-byte status code in network order
|
||||
|
@ -343,10 +341,10 @@ LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf,
|
|||
}
|
||||
break;
|
||||
case LWS_WRITE_PING:
|
||||
n = LWS_WS_OPCODE_07__PING;
|
||||
n = LWSWSOPC_PING;
|
||||
break;
|
||||
case LWS_WRITE_PONG:
|
||||
n = LWS_WS_OPCODE_07__PONG;
|
||||
n = LWSWSOPC_PONG;
|
||||
break;
|
||||
default:
|
||||
lwsl_warn("lws_write: unknown write opc / protocol\n");
|
||||
|
@ -398,8 +396,7 @@ do_more_inside_frame:
|
|||
* the protocol demands it
|
||||
*/
|
||||
|
||||
if (wsi->mode == LWS_CONNMODE_WS_CLIENT) {
|
||||
|
||||
if (wsi->mode == LWSCM_WS_CLIENT) {
|
||||
if (!wsi->u.ws.inside_frame)
|
||||
if (lws_0405_frame_mask_generate(wsi)) {
|
||||
lwsl_err("frame mask generation failed\n");
|
||||
|
@ -412,11 +409,11 @@ do_more_inside_frame:
|
|||
if (dropmask) { /* never set if already inside frame */
|
||||
for (n = 4; n < (int)len + 4; n++)
|
||||
dropmask[n] = dropmask[n] ^
|
||||
wsi->u.ws.frame_masking_nonce_04[
|
||||
wsi->u.ws.mask_nonce[
|
||||
(wsi->u.ws.frame_mask_index++) & 3];
|
||||
|
||||
/* copy the frame nonce into place */
|
||||
memcpy(dropmask, wsi->u.ws.frame_masking_nonce_04, 4);
|
||||
memcpy(dropmask, wsi->u.ws.mask_nonce, 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -430,7 +427,7 @@ send_raw:
|
|||
case LWS_WRITE_PONG:
|
||||
case LWS_WRITE_PING:
|
||||
#ifdef LWS_USE_HTTP2
|
||||
if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING) {
|
||||
if (wsi->mode == LWSCM_HTTP2_SERVING) {
|
||||
unsigned char flags = 0;
|
||||
|
||||
n = LWS_HTTP2_FRAME_TYPE_DATA;
|
||||
|
@ -512,11 +509,10 @@ LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi)
|
|||
int n, m;
|
||||
|
||||
while (!lws_send_pipe_choked(wsi)) {
|
||||
|
||||
if (wsi->truncated_send_len) {
|
||||
if (lws_issue_raw(wsi, wsi->truncated_send_malloc +
|
||||
wsi->truncated_send_offset,
|
||||
wsi->truncated_send_len) < 0) {
|
||||
if (wsi->trunc_len) {
|
||||
if (lws_issue_raw(wsi, wsi->trunc_alloc +
|
||||
wsi->trunc_offset,
|
||||
wsi->trunc_len) < 0) {
|
||||
lwsl_info("%s: closing\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
@ -527,8 +523,8 @@ LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi)
|
|||
goto all_sent;
|
||||
|
||||
if (lws_plat_file_read(wsi, wsi->u.http.fd, &amount,
|
||||
context->service_buffer,
|
||||
sizeof(context->service_buffer)) < 0)
|
||||
context->serv_buf,
|
||||
sizeof(context->serv_buf)) < 0)
|
||||
return -1; /* caller will close */
|
||||
|
||||
n = (int)amount;
|
||||
|
@ -536,7 +532,7 @@ LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi)
|
|||
lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT,
|
||||
AWAITING_TIMEOUT);
|
||||
wsi->u.http.filepos += n;
|
||||
m = lws_write(wsi, context->service_buffer, n,
|
||||
m = lws_write(wsi, context->serv_buf, n,
|
||||
wsi->u.http.filepos == wsi->u.http.filelen ?
|
||||
LWS_WRITE_HTTP_FINAL : LWS_WRITE_HTTP);
|
||||
if (m < 0)
|
||||
|
@ -544,16 +540,14 @@ LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi)
|
|||
|
||||
if (m != n)
|
||||
/* adjust for what was not sent */
|
||||
if (lws_plat_file_seek_cur(wsi,
|
||||
wsi->u.http.fd,
|
||||
if (lws_plat_file_seek_cur(wsi, wsi->u.http.fd,
|
||||
m - n) ==
|
||||
(unsigned long)-1)
|
||||
return -1;
|
||||
}
|
||||
all_sent:
|
||||
if (!wsi->truncated_send_len &&
|
||||
wsi->u.http.filepos == wsi->u.http.filelen) {
|
||||
wsi->state = WSI_STATE_HTTP;
|
||||
if (!wsi->trunc_len && wsi->u.http.filepos == wsi->u.http.filelen) {
|
||||
wsi->state = LWSS_HTTP;
|
||||
|
||||
/* we might be in keepalive, so close it off here */
|
||||
lws_plat_file_close(wsi, wsi->u.http.fd);
|
||||
|
|
|
@ -76,7 +76,7 @@ int lws_allocate_header_table(struct lws *wsi)
|
|||
|
||||
int lws_free_header_table(struct lws *wsi)
|
||||
{
|
||||
lws_free2(wsi->u.hdr.ah);
|
||||
lws_free_set_NULL(wsi->u.hdr.ah);
|
||||
wsi->u.hdr.ah = NULL;
|
||||
return 0;
|
||||
};
|
||||
|
@ -448,7 +448,7 @@ swallow:
|
|||
* Server needs to look out for unknown methods...
|
||||
*/
|
||||
if (wsi->u.hdr.lextable_pos < 0 &&
|
||||
wsi->mode == LWS_CONNMODE_HTTP_SERVING) {
|
||||
wsi->mode == LWSCM_HTTP_SERVING) {
|
||||
/* this is not a header we know about */
|
||||
for (m = 0; m < ARRAY_SIZE(methods); m++)
|
||||
if (ah->frag_index[methods[m]]) {
|
||||
|
@ -629,19 +629,19 @@ lws_rx_sm(struct lws *wsi, unsigned char c)
|
|||
}
|
||||
break;
|
||||
case LWS_RXPS_04_MASK_NONCE_1:
|
||||
wsi->u.ws.frame_masking_nonce_04[1] = c;
|
||||
wsi->u.ws.mask_nonce[1] = c;
|
||||
if (c)
|
||||
wsi->u.ws.all_zero_nonce = 0;
|
||||
wsi->lws_rx_parse_state = LWS_RXPS_04_MASK_NONCE_2;
|
||||
break;
|
||||
case LWS_RXPS_04_MASK_NONCE_2:
|
||||
wsi->u.ws.frame_masking_nonce_04[2] = c;
|
||||
wsi->u.ws.mask_nonce[2] = c;
|
||||
if (c)
|
||||
wsi->u.ws.all_zero_nonce = 0;
|
||||
wsi->lws_rx_parse_state = LWS_RXPS_04_MASK_NONCE_3;
|
||||
break;
|
||||
case LWS_RXPS_04_MASK_NONCE_3:
|
||||
wsi->u.ws.frame_masking_nonce_04[3] = c;
|
||||
wsi->u.ws.mask_nonce[3] = c;
|
||||
if (c)
|
||||
wsi->u.ws.all_zero_nonce = 0;
|
||||
|
||||
|
@ -693,10 +693,10 @@ handle_first:
|
|||
wsi->u.ws.final = !!((c >> 7) & 1);
|
||||
|
||||
switch (wsi->u.ws.opcode) {
|
||||
case LWS_WS_OPCODE_07__TEXT_FRAME:
|
||||
case LWS_WS_OPCODE_07__BINARY_FRAME:
|
||||
case LWSWSOPC_TEXT_FRAME:
|
||||
case LWSWSOPC_BINARY_FRAME:
|
||||
wsi->u.ws.frame_is_binary =
|
||||
wsi->u.ws.opcode == LWS_WS_OPCODE_07__BINARY_FRAME;
|
||||
wsi->u.ws.opcode == LWSWSOPC_BINARY_FRAME;
|
||||
break;
|
||||
}
|
||||
wsi->lws_rx_parse_state = LWS_RXPS_04_FRAME_HDR_LEN;
|
||||
|
@ -814,28 +814,28 @@ handle_first:
|
|||
break;
|
||||
|
||||
case LWS_RXPS_07_COLLECT_FRAME_KEY_1:
|
||||
wsi->u.ws.frame_masking_nonce_04[0] = c;
|
||||
wsi->u.ws.mask_nonce[0] = c;
|
||||
if (c)
|
||||
wsi->u.ws.all_zero_nonce = 0;
|
||||
wsi->lws_rx_parse_state = LWS_RXPS_07_COLLECT_FRAME_KEY_2;
|
||||
break;
|
||||
|
||||
case LWS_RXPS_07_COLLECT_FRAME_KEY_2:
|
||||
wsi->u.ws.frame_masking_nonce_04[1] = c;
|
||||
wsi->u.ws.mask_nonce[1] = c;
|
||||
if (c)
|
||||
wsi->u.ws.all_zero_nonce = 0;
|
||||
wsi->lws_rx_parse_state = LWS_RXPS_07_COLLECT_FRAME_KEY_3;
|
||||
break;
|
||||
|
||||
case LWS_RXPS_07_COLLECT_FRAME_KEY_3:
|
||||
wsi->u.ws.frame_masking_nonce_04[2] = c;
|
||||
wsi->u.ws.mask_nonce[2] = c;
|
||||
if (c)
|
||||
wsi->u.ws.all_zero_nonce = 0;
|
||||
wsi->lws_rx_parse_state = LWS_RXPS_07_COLLECT_FRAME_KEY_4;
|
||||
break;
|
||||
|
||||
case LWS_RXPS_07_COLLECT_FRAME_KEY_4:
|
||||
wsi->u.ws.frame_masking_nonce_04[3] = c;
|
||||
wsi->u.ws.mask_nonce[3] = c;
|
||||
if (c)
|
||||
wsi->u.ws.all_zero_nonce = 0;
|
||||
wsi->lws_rx_parse_state =
|
||||
|
@ -861,7 +861,7 @@ handle_first:
|
|||
else
|
||||
wsi->u.ws.rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING +
|
||||
(wsi->u.ws.rx_user_buffer_head++)] =
|
||||
c ^ wsi->u.ws.frame_masking_nonce_04[
|
||||
c ^ wsi->u.ws.mask_nonce[
|
||||
(wsi->u.ws.frame_mask_index++) & 3];
|
||||
|
||||
if (--wsi->u.ws.rx_packet_length == 0) {
|
||||
|
@ -895,9 +895,9 @@ spill:
|
|||
lwsl_parser("spill on %s\n", wsi->protocol->name);
|
||||
|
||||
switch (wsi->u.ws.opcode) {
|
||||
case LWS_WS_OPCODE_07__CLOSE:
|
||||
case LWSWSOPC_CLOSE:
|
||||
/* is this an acknowledgement of our close? */
|
||||
if (wsi->state == WSI_STATE_AWAITING_CLOSE_ACK) {
|
||||
if (wsi->state == LWSS_AWAITING_CLOSE_ACK) {
|
||||
/*
|
||||
* fine he has told us he is closing too, let's
|
||||
* finish our close
|
||||
|
@ -905,17 +905,17 @@ spill:
|
|||
lwsl_parser("seen client close ack\n");
|
||||
return -1;
|
||||
}
|
||||
if (wsi->state == WSI_STATE_RETURNED_CLOSE_ALREADY)
|
||||
if (wsi->state == LWSS_RETURNED_CLOSE_ALREADY)
|
||||
/* if he sends us 2 CLOSE, kill him */
|
||||
return -1;
|
||||
|
||||
lwsl_parser("server sees client close packet\n");
|
||||
wsi->state = WSI_STATE_RETURNED_CLOSE_ALREADY;
|
||||
wsi->state = LWSS_RETURNED_CLOSE_ALREADY;
|
||||
/* deal with the close packet contents as a PONG */
|
||||
wsi->u.ws.payload_is_close = 1;
|
||||
goto process_as_ping;
|
||||
|
||||
case LWS_WS_OPCODE_07__PING:
|
||||
case LWSWSOPC_PING:
|
||||
lwsl_info("received %d byte ping, sending pong\n",
|
||||
wsi->u.ws.rx_user_buffer_head);
|
||||
|
||||
|
@ -937,7 +937,7 @@ process_as_ping:
|
|||
/* if existing buffer is too small, drop it */
|
||||
if (wsi->u.ws.ping_payload_buf &&
|
||||
wsi->u.ws.ping_payload_alloc < wsi->u.ws.rx_user_buffer_head) {
|
||||
lws_free2(wsi->u.ws.ping_payload_buf);
|
||||
lws_free_set_NULL(wsi->u.ws.ping_payload_buf);
|
||||
}
|
||||
|
||||
/* if no buffer, allocate it */
|
||||
|
@ -961,7 +961,7 @@ ping_drop:
|
|||
wsi->u.ws.rx_user_buffer_head = 0;
|
||||
return 0;
|
||||
|
||||
case LWS_WS_OPCODE_07__PONG:
|
||||
case LWSWSOPC_PONG:
|
||||
lwsl_info("received pong\n");
|
||||
lwsl_hexdump(&wsi->u.ws.rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
|
||||
wsi->u.ws.rx_user_buffer_head);
|
||||
|
@ -970,9 +970,9 @@ ping_drop:
|
|||
callback_action = LWS_CALLBACK_RECEIVE_PONG;
|
||||
break;
|
||||
|
||||
case LWS_WS_OPCODE_07__TEXT_FRAME:
|
||||
case LWS_WS_OPCODE_07__BINARY_FRAME:
|
||||
case LWS_WS_OPCODE_07__CONTINUATION:
|
||||
case LWSWSOPC_TEXT_FRAME:
|
||||
case LWSWSOPC_BINARY_FRAME:
|
||||
case LWSWSOPC_CONTINUATION:
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -988,7 +988,7 @@ ping_drop:
|
|||
LWS_SEND_BUFFER_PRE_PADDING];
|
||||
eff_buf.token_len = wsi->u.ws.rx_user_buffer_head;
|
||||
|
||||
if (lws_ext_callback_for_each_active(wsi,
|
||||
if (lws_ext_cb_wsi_active_exts(wsi,
|
||||
LWS_EXT_CALLBACK_EXTENDED_PAYLOAD_RX,
|
||||
&eff_buf, 0) <= 0) /* not handle or fail */
|
||||
lwsl_ext("ext opc opcode 0x%x unknown\n",
|
||||
|
@ -1008,7 +1008,7 @@ ping_drop:
|
|||
LWS_SEND_BUFFER_PRE_PADDING];
|
||||
eff_buf.token_len = wsi->u.ws.rx_user_buffer_head;
|
||||
|
||||
if (lws_ext_callback_for_each_active(wsi,
|
||||
if (lws_ext_cb_wsi_active_exts(wsi,
|
||||
LWS_EXT_CALLBACK_PAYLOAD_RX, &eff_buf, 0) < 0)
|
||||
return -1;
|
||||
|
||||
|
|
36
lib/pollfd.c
36
lib/pollfd.c
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* libwebsockets - small server side websockets and web server implementation
|
||||
*
|
||||
* Copyright (C) 2010-2014 Andy Green <andy@warmcat.com>
|
||||
* Copyright (C) 2010-2015 Andy Green <andy@warmcat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -22,8 +22,7 @@
|
|||
#include "private-libwebsockets.h"
|
||||
|
||||
int
|
||||
insert_wsi_socket_into_fds(struct lws_context *context,
|
||||
struct lws *wsi)
|
||||
insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi)
|
||||
{
|
||||
struct lws_pollargs pa = { wsi->sock, LWS_POLLIN, 0 };
|
||||
|
||||
|
@ -35,7 +34,7 @@ insert_wsi_socket_into_fds(struct lws_context *context,
|
|||
#if !defined(_WIN32) && !defined(MBED_OPERATORS)
|
||||
if (wsi->sock >= context->max_fds) {
|
||||
lwsl_err("Socket fd %d is too high (%d)\n",
|
||||
wsi->sock, context->max_fds);
|
||||
wsi->sock, context->max_fds);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
@ -43,9 +42,6 @@ insert_wsi_socket_into_fds(struct lws_context *context,
|
|||
assert(wsi);
|
||||
assert(lws_socket_is_valid(wsi->sock));
|
||||
|
||||
// lwsl_info("insert_wsi_socket_into_fds: wsi=%p, sock=%d, fds pos=%d\n",
|
||||
// wsi, wsi->sock, context->fds_count);
|
||||
|
||||
if (context->protocols[0].callback(wsi, LWS_CALLBACK_LOCK_POLL,
|
||||
wsi->user_space, (void *) &pa, 1))
|
||||
return -1;
|
||||
|
@ -73,6 +69,7 @@ int
|
|||
remove_wsi_socket_from_fds(struct lws *wsi)
|
||||
{
|
||||
int m;
|
||||
struct lws *end_wsi;
|
||||
struct lws_pollargs pa = { wsi->sock, 0, 0 };
|
||||
struct lws_context *context = wsi->context;
|
||||
|
||||
|
@ -83,13 +80,13 @@ remove_wsi_socket_from_fds(struct lws *wsi)
|
|||
#if !defined(_WIN32) && !defined(MBED_OPERATORS)
|
||||
if (wsi->sock > context->max_fds) {
|
||||
lwsl_err("Socket fd %d too high (%d)\n",
|
||||
wsi->sock, context->max_fds);
|
||||
wsi->sock, context->max_fds);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
lwsl_info("%s: wsi=%p, sock=%d, fds pos=%d\n", __func__,
|
||||
wsi, wsi->sock, wsi->position_in_fds_table);
|
||||
wsi, wsi->sock, wsi->position_in_fds_table);
|
||||
|
||||
if (context->protocols[0].callback(wsi, LWS_CALLBACK_LOCK_POLL,
|
||||
wsi->user_space, (void *)&pa, 1))
|
||||
|
@ -107,18 +104,17 @@ remove_wsi_socket_from_fds(struct lws *wsi)
|
|||
* (still same fd pointing to same wsi)
|
||||
*/
|
||||
/* end guy's "position in fds table" changed */
|
||||
wsi_from_fd(context,context->fds[context->fds_count].fd)->
|
||||
position_in_fds_table = m;
|
||||
end_wsi = wsi_from_fd(context, context->fds[context->fds_count].fd);
|
||||
end_wsi->position_in_fds_table = m;
|
||||
/* deletion guy's lws_lookup entry needs nuking */
|
||||
delete_from_fd(context,wsi->sock);
|
||||
delete_from_fd(context, wsi->sock);
|
||||
/* removed wsi has no position any more */
|
||||
wsi->position_in_fds_table = -1;
|
||||
|
||||
/* remove also from external POLL support via protocol 0 */
|
||||
if (lws_socket_is_valid(wsi->sock)) {
|
||||
if (context->protocols[0].callback(wsi,
|
||||
LWS_CALLBACK_DEL_POLL_FD, wsi->user_space,
|
||||
(void *) &pa, 0))
|
||||
if (context->protocols[0].callback(wsi, LWS_CALLBACK_DEL_POLL_FD,
|
||||
wsi->user_space, (void *) &pa, 0))
|
||||
return -1;
|
||||
}
|
||||
if (context->protocols[0].callback(wsi, LWS_CALLBACK_UNLOCK_POLL,
|
||||
|
@ -200,7 +196,6 @@ lws_change_pollfd(struct lws *wsi, int _and, int _or)
|
|||
* becomes able to be written to without
|
||||
* blocking
|
||||
*
|
||||
* @context: libwebsockets context
|
||||
* @wsi: Websocket connection instance to get callback for
|
||||
*/
|
||||
|
||||
|
@ -213,7 +208,7 @@ lws_callback_on_writable(struct lws *wsi)
|
|||
|
||||
lwsl_info("%s: %p\n", __func__, wsi);
|
||||
|
||||
if (wsi->mode != LWS_CONNMODE_HTTP2_SERVING)
|
||||
if (wsi->mode != LWSCM_HTTP2_SERVING)
|
||||
goto network_sock;
|
||||
|
||||
if (wsi->u.http2.requested_POLLOUT) {
|
||||
|
@ -255,7 +250,7 @@ lws_callback_on_writable(struct lws *wsi)
|
|||
network_sock:
|
||||
#endif
|
||||
|
||||
if (lws_ext_callback_for_each_active(wsi,
|
||||
if (lws_ext_cb_wsi_active_exts(wsi,
|
||||
LWS_EXT_CALLBACK_REQUEST_ON_WRITEABLE, NULL, 0))
|
||||
return 1;
|
||||
|
||||
|
@ -278,15 +273,16 @@ network_sock:
|
|||
* becomes possible to write to each socket without
|
||||
* blocking in turn.
|
||||
*
|
||||
* @context: lws_context
|
||||
* @protocol: Protocol whose connections will get callbacks
|
||||
*/
|
||||
|
||||
LWS_VISIBLE int
|
||||
lws_callback_on_writable_all_protocol(const struct lws_context *context,
|
||||
const struct lws_protocols *protocol)
|
||||
const struct lws_protocols *protocol)
|
||||
{
|
||||
int n;
|
||||
struct lws *wsi;
|
||||
int n;
|
||||
|
||||
for (n = 0; n < context->fds_count; n++) {
|
||||
wsi = wsi_from_fd(context,context->fds[n].fd);
|
||||
|
|
|
@ -316,38 +316,38 @@ extern "C" {
|
|||
* if not in a connection storm, check for incoming
|
||||
* connections this many normal connection services
|
||||
*/
|
||||
#define LWS_LISTEN_SERVICE_MODULO 10
|
||||
#define LWS_lserv_mod 10
|
||||
|
||||
enum lws_websocket_opcodes_07 {
|
||||
LWS_WS_OPCODE_07__CONTINUATION = 0,
|
||||
LWS_WS_OPCODE_07__TEXT_FRAME = 1,
|
||||
LWS_WS_OPCODE_07__BINARY_FRAME = 2,
|
||||
LWSWSOPC_CONTINUATION = 0,
|
||||
LWSWSOPC_TEXT_FRAME = 1,
|
||||
LWSWSOPC_BINARY_FRAME = 2,
|
||||
|
||||
LWS_WS_OPCODE_07__NOSPEC__MUX = 7,
|
||||
LWSWSOPC_NOSPEC__MUX = 7,
|
||||
|
||||
/* control extensions 8+ */
|
||||
|
||||
LWS_WS_OPCODE_07__CLOSE = 8,
|
||||
LWS_WS_OPCODE_07__PING = 9,
|
||||
LWS_WS_OPCODE_07__PONG = 0xa,
|
||||
LWSWSOPC_CLOSE = 8,
|
||||
LWSWSOPC_PING = 9,
|
||||
LWSWSOPC_PONG = 0xa,
|
||||
};
|
||||
|
||||
|
||||
enum lws_connection_states {
|
||||
WSI_STATE_HTTP,
|
||||
WSI_STATE_HTTP_ISSUING_FILE,
|
||||
WSI_STATE_HTTP_HEADERS,
|
||||
WSI_STATE_HTTP_BODY,
|
||||
WSI_STATE_DEAD_SOCKET,
|
||||
WSI_STATE_ESTABLISHED,
|
||||
WSI_STATE_CLIENT_UNCONNECTED,
|
||||
WSI_STATE_RETURNED_CLOSE_ALREADY,
|
||||
WSI_STATE_AWAITING_CLOSE_ACK,
|
||||
WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE,
|
||||
LWSS_HTTP,
|
||||
LWSS_HTTP_ISSUING_FILE,
|
||||
LWSS_HTTP_HEADERS,
|
||||
LWSS_HTTP_BODY,
|
||||
LWSS_DEAD_SOCKET,
|
||||
LWSS_ESTABLISHED,
|
||||
LWSS_CLIENT_UNCONNECTED,
|
||||
LWSS_RETURNED_CLOSE_ALREADY,
|
||||
LWSS_AWAITING_CLOSE_ACK,
|
||||
LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE,
|
||||
|
||||
WSI_STATE_HTTP2_AWAIT_CLIENT_PREFACE,
|
||||
WSI_STATE_HTTP2_ESTABLISHED_PRE_SETTINGS,
|
||||
WSI_STATE_HTTP2_ESTABLISHED,
|
||||
LWSS_HTTP2_AWAIT_CLIENT_PREFACE,
|
||||
LWSS_HTTP2_ESTABLISHED_PRE_SETTINGS,
|
||||
LWSS_HTTP2_ESTABLISHED,
|
||||
};
|
||||
|
||||
enum http_version {
|
||||
|
@ -397,30 +397,30 @@ enum lws_rx_parse_state {
|
|||
|
||||
|
||||
enum connection_mode {
|
||||
LWS_CONNMODE_HTTP_SERVING,
|
||||
LWS_CONNMODE_HTTP_SERVING_ACCEPTED, /* actual HTTP service going on */
|
||||
LWS_CONNMODE_PRE_WS_SERVING_ACCEPT,
|
||||
LWSCM_HTTP_SERVING,
|
||||
LWSCM_HTTP_SERVING_ACCEPTED, /* actual HTTP service going on */
|
||||
LWSCM_PRE_WS_SERVING_ACCEPT,
|
||||
|
||||
LWS_CONNMODE_WS_SERVING,
|
||||
LWS_CONNMODE_WS_CLIENT,
|
||||
LWSCM_WS_SERVING,
|
||||
LWSCM_WS_CLIENT,
|
||||
|
||||
LWS_CONNMODE_HTTP2_SERVING,
|
||||
LWSCM_HTTP2_SERVING,
|
||||
|
||||
/* transient, ssl delay hiding */
|
||||
LWS_CONNMODE_SSL_ACK_PENDING,
|
||||
LWSCM_SSL_ACK_PENDING,
|
||||
|
||||
/* transient modes */
|
||||
LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT,
|
||||
LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY,
|
||||
LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE,
|
||||
LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE2,
|
||||
LWS_CONNMODE_WS_CLIENT_WAITING_SSL,
|
||||
LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY,
|
||||
LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT,
|
||||
LWS_CONNMODE_WS_CLIENT_PENDING_CANDIDATE_CHILD,
|
||||
LWSCM_WSCL_WAITING_CONNECT,
|
||||
LWSCM_WSCL_WAITING_PROXY_REPLY,
|
||||
LWSCM_WSCL_ISSUE_HANDSHAKE,
|
||||
LWSCM_WSCL_ISSUE_HANDSHAKE2,
|
||||
LWSCM_WSCL_WAITING_SSL,
|
||||
LWSCM_WSCL_WAITING_SERVER_REPLY,
|
||||
LWSCM_WSCL_WAITING_EXTENSION_CONNECT,
|
||||
LWSCM_WSCL_PENDING_CANDIDATE_CHILD,
|
||||
|
||||
/* special internal types */
|
||||
LWS_CONNMODE_SERVER_LISTENER,
|
||||
LWSCM_SERVER_LISTENER,
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -485,15 +485,15 @@ struct lws_context {
|
|||
* does not last longer than the service action (since next service
|
||||
* of any socket can likewise use it and overwrite)
|
||||
*/
|
||||
unsigned char service_buffer[LWS_MAX_SOCKET_IO_BUF];
|
||||
unsigned char serv_buf[LWS_MAX_SOCKET_IO_BUF];
|
||||
|
||||
int started_with_parent;
|
||||
|
||||
int fd_random;
|
||||
int listen_service_modulo;
|
||||
int listen_service_count;
|
||||
lws_sockfd_type listen_service_fd;
|
||||
int listen_service_extraseen;
|
||||
int lserv_mod;
|
||||
int lserv_count;
|
||||
lws_sockfd_type lserv_fd;
|
||||
int lserv_seen;
|
||||
|
||||
/*
|
||||
* set to the Thread ID that's doing the service loop just before entry
|
||||
|
@ -815,7 +815,7 @@ struct _lws_header_related {
|
|||
struct _lws_websocket_related {
|
||||
char *rx_user_buffer;
|
||||
unsigned int rx_user_buffer_head;
|
||||
unsigned char frame_masking_nonce_04[4];
|
||||
unsigned char mask_nonce[4];
|
||||
unsigned char frame_mask_index;
|
||||
size_t rx_packet_length;
|
||||
unsigned char opcode;
|
||||
|
@ -879,10 +879,10 @@ struct lws {
|
|||
unsigned int rxflow_change_to:2;
|
||||
|
||||
/* truncated send handling */
|
||||
unsigned char *truncated_send_malloc; /* non-NULL means buffering in progress */
|
||||
unsigned int truncated_send_allocation; /* size of malloc */
|
||||
unsigned int truncated_send_offset; /* where we are in terms of spilling */
|
||||
unsigned int truncated_send_len; /* how much is buffered */
|
||||
unsigned char *trunc_alloc; /* non-NULL means buffering in progress */
|
||||
unsigned int trunc_alloc_len; /* size of malloc */
|
||||
unsigned int trunc_offset; /* where we are in terms of spilling */
|
||||
unsigned int trunc_len; /* how much is buffered */
|
||||
|
||||
void *user_space;
|
||||
|
||||
|
@ -1006,16 +1006,16 @@ lws_any_extension_handled(struct lws *wsi,
|
|||
void *v, size_t len);
|
||||
|
||||
LWS_EXTERN int
|
||||
lws_ext_callback_for_each_active(struct lws *wsi, int reason,
|
||||
lws_ext_cb_wsi_active_exts(struct lws *wsi, int reason,
|
||||
void *buf, int len);
|
||||
LWS_EXTERN int
|
||||
lws_ext_callback_for_each_extension_type(struct lws_context *context,
|
||||
lws_ext_cb_all_exts(struct lws_context *context,
|
||||
struct lws *wsi, int reason,
|
||||
void *arg, int len);
|
||||
#else
|
||||
#define lws_any_extension_handled(_a, _b, _c, _d) (0)
|
||||
#define lws_ext_callback_for_each_active(_a, _b, _c, _d) (0)
|
||||
#define lws_ext_callback_for_each_extension_type(_a, _b, _c, _d, _e) (0)
|
||||
#define lws_ext_cb_wsi_active_exts(_a, _b, _c, _d) (0)
|
||||
#define lws_ext_cb_all_exts(_a, _b, _c, _d, _e) (0)
|
||||
#define lws_issue_raw_ext_access lws_issue_raw
|
||||
#define lws_context_init_extensions(_a, _b)
|
||||
#endif
|
||||
|
@ -1240,7 +1240,7 @@ lws_zalloc(size_t size);
|
|||
|
||||
#define lws_malloc(S) lws_realloc(NULL, S)
|
||||
#define lws_free(P) lws_realloc(P, 0)
|
||||
#define lws_free2(P) do { lws_realloc(P, 0); (P) = NULL; } while(0)
|
||||
#define lws_free_set_NULL(P) do { lws_realloc(P, 0); (P) = NULL; } while(0)
|
||||
|
||||
/* lws_plat_ */
|
||||
LWS_EXTERN void
|
||||
|
|
|
@ -47,12 +47,12 @@ lws_extension_server_handshake(struct lws *wsi, char **p)
|
|||
* and go through them
|
||||
*/
|
||||
|
||||
if (lws_hdr_copy(wsi, (char *)context->service_buffer,
|
||||
sizeof(context->service_buffer),
|
||||
if (lws_hdr_copy(wsi, (char *)context->serv_buf,
|
||||
sizeof(context->serv_buf),
|
||||
WSI_TOKEN_EXTENSIONS) < 0)
|
||||
return 1;
|
||||
|
||||
c = (char *)context->service_buffer;
|
||||
c = (char *)context->serv_buf;
|
||||
lwsl_parser("WSI_TOKEN_EXTENSIONS = '%s'\n", c);
|
||||
wsi->count_active_extensions = 0;
|
||||
n = 0;
|
||||
|
@ -176,15 +176,15 @@ handshake_0405(struct lws_context *context, struct lws *wsi)
|
|||
* since key length is restricted above (currently 128), cannot
|
||||
* overflow
|
||||
*/
|
||||
n = sprintf((char *)context->service_buffer,
|
||||
n = sprintf((char *)context->serv_buf,
|
||||
"%s258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
|
||||
lws_hdr_simple_ptr(wsi, WSI_TOKEN_KEY));
|
||||
|
||||
lws_SHA1(context->service_buffer, n, hash);
|
||||
lws_SHA1(context->serv_buf, n, hash);
|
||||
|
||||
accept_len = lws_b64_encode_string((char *)hash, 20,
|
||||
(char *)context->service_buffer,
|
||||
sizeof(context->service_buffer));
|
||||
(char *)context->serv_buf,
|
||||
sizeof(context->serv_buf));
|
||||
if (accept_len < 0) {
|
||||
lwsl_warn("Base64 encoded hash too long\n");
|
||||
goto bail;
|
||||
|
@ -198,13 +198,13 @@ handshake_0405(struct lws_context *context, struct lws *wsi)
|
|||
|
||||
/* make a buffer big enough for everything */
|
||||
|
||||
response = (char *)context->service_buffer + MAX_WEBSOCKET_04_KEY_LEN + LWS_SEND_BUFFER_PRE_PADDING;
|
||||
response = (char *)context->serv_buf + MAX_WEBSOCKET_04_KEY_LEN + LWS_SEND_BUFFER_PRE_PADDING;
|
||||
p = response;
|
||||
LWS_CPYAPP(p, "HTTP/1.1 101 Switching Protocols\x0d\x0a"
|
||||
"Upgrade: WebSocket\x0d\x0a"
|
||||
"Connection: Upgrade\x0d\x0a"
|
||||
"Sec-WebSocket-Accept: ");
|
||||
strcpy(p, (char *)context->service_buffer);
|
||||
strcpy(p, (char *)context->serv_buf);
|
||||
p += accept_len;
|
||||
|
||||
if (lws_hdr_total_length(wsi, WSI_TOKEN_PROTOCOL)) {
|
||||
|
@ -250,7 +250,7 @@ handshake_0405(struct lws_context *context, struct lws *wsi)
|
|||
|
||||
/* alright clean up and set ourselves into established state */
|
||||
|
||||
wsi->state = WSI_STATE_ESTABLISHED;
|
||||
wsi->state = LWSS_ESTABLISHED;
|
||||
wsi->lws_rx_parse_state = LWS_RXPS_NEW;
|
||||
|
||||
/* notify user code that we're ready to roll */
|
||||
|
|
171
lib/server.c
171
lib/server.c
|
@ -90,14 +90,10 @@ int lws_context_init_server(struct lws_context_creation_info *info,
|
|||
serv_addr4.sin_addr.s_addr = INADDR_ANY;
|
||||
serv_addr4.sin_family = AF_INET;
|
||||
|
||||
if (info->iface) {
|
||||
if (interface_to_sa(context, info->iface,
|
||||
if (info->iface && interface_to_sa(context, info->iface,
|
||||
(struct sockaddr_in *)v, n) < 0) {
|
||||
lwsl_err("Unable to find interface %s\n",
|
||||
info->iface);
|
||||
compatible_close(sockfd);
|
||||
return 1;
|
||||
}
|
||||
lwsl_err("Unable to find interface %s\n", info->iface);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
serv_addr4.sin_port = htons(info->port);
|
||||
|
@ -107,8 +103,7 @@ int lws_context_init_server(struct lws_context_creation_info *info,
|
|||
if (n < 0) {
|
||||
lwsl_err("ERROR on binding to port %d (%d %d)\n",
|
||||
info->port, n, LWS_ERRNO);
|
||||
compatible_close(sockfd);
|
||||
return 1;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
if (getsockname(sockfd, (struct sockaddr *)&sin, &len) == -1)
|
||||
|
@ -122,22 +117,19 @@ int lws_context_init_server(struct lws_context_creation_info *info,
|
|||
wsi = lws_zalloc(sizeof(struct lws));
|
||||
if (wsi == NULL) {
|
||||
lwsl_err("Out of mem\n");
|
||||
compatible_close(sockfd);
|
||||
return 1;
|
||||
goto bail;
|
||||
}
|
||||
wsi->context = context;
|
||||
wsi->sock = sockfd;
|
||||
wsi->mode = LWS_CONNMODE_SERVER_LISTENER;
|
||||
wsi->mode = LWSCM_SERVER_LISTENER;
|
||||
wsi->protocol = context->protocols;
|
||||
|
||||
if (insert_wsi_socket_into_fds(context, wsi)) {
|
||||
compatible_close(sockfd);
|
||||
return 1;
|
||||
}
|
||||
if (insert_wsi_socket_into_fds(context, wsi))
|
||||
goto bail;
|
||||
|
||||
context->listen_service_modulo = LWS_LISTEN_SERVICE_MODULO;
|
||||
context->listen_service_count = 0;
|
||||
context->listen_service_fd = sockfd;
|
||||
context->lserv_mod = LWS_lserv_mod;
|
||||
context->lserv_count = 0;
|
||||
context->lserv_fd = sockfd;
|
||||
|
||||
#if LWS_POSIX
|
||||
listen(sockfd, LWS_SOMAXCONN);
|
||||
|
@ -147,6 +139,11 @@ int lws_context_init_server(struct lws_context_creation_info *info,
|
|||
lwsl_notice(" Listening on port %d\n", info->port);
|
||||
|
||||
return 0;
|
||||
|
||||
bail:
|
||||
compatible_close(sockfd);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -306,7 +303,7 @@ int lws_http_action(struct lws *wsi)
|
|||
}
|
||||
|
||||
/* now drop the header info we kept a pointer to */
|
||||
lws_free2(wsi->u.http.ah);
|
||||
lws_free_set_NULL(wsi->u.http.ah);
|
||||
|
||||
if (n) {
|
||||
lwsl_info("LWS_CALLBACK_HTTP closing\n");
|
||||
|
@ -320,16 +317,16 @@ int lws_http_action(struct lws *wsi)
|
|||
* In any case, return 0 and let lws_read decide how to
|
||||
* proceed based on state
|
||||
*/
|
||||
if (wsi->state != WSI_STATE_HTTP_ISSUING_FILE)
|
||||
if (wsi->state != LWSS_HTTP_ISSUING_FILE)
|
||||
/* Prepare to read body if we have a content length: */
|
||||
if (wsi->u.http.content_length > 0)
|
||||
wsi->state = WSI_STATE_HTTP_BODY;
|
||||
wsi->state = LWSS_HTTP_BODY;
|
||||
|
||||
return 0;
|
||||
|
||||
bail_nuke_ah:
|
||||
/* drop the header info */
|
||||
lws_free2(wsi->u.hdr.ah);
|
||||
lws_free_set_NULL(wsi->u.hdr.ah);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -344,7 +341,7 @@ int lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len)
|
|||
char protocol_name[32];
|
||||
char *p;
|
||||
|
||||
/* LWS_CONNMODE_WS_SERVING */
|
||||
/* LWSCM_WS_SERVING */
|
||||
|
||||
while (len--) {
|
||||
if (lws_parse(wsi, *(*buf)++)) {
|
||||
|
@ -357,18 +354,18 @@ int lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len)
|
|||
|
||||
lwsl_parser("lws_parse sees parsing complete\n");
|
||||
|
||||
wsi->mode = LWS_CONNMODE_PRE_WS_SERVING_ACCEPT;
|
||||
wsi->mode = LWSCM_PRE_WS_SERVING_ACCEPT;
|
||||
lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
|
||||
|
||||
/* is this websocket protocol or normal http 1.0? */
|
||||
|
||||
if (!lws_hdr_total_length(wsi, WSI_TOKEN_UPGRADE) ||
|
||||
!lws_hdr_total_length(wsi, WSI_TOKEN_CONNECTION)) {
|
||||
!lws_hdr_total_length(wsi, WSI_TOKEN_CONNECTION)) {
|
||||
|
||||
ah = wsi->u.hdr.ah;
|
||||
|
||||
lws_union_transition(wsi, LWS_CONNMODE_HTTP_SERVING_ACCEPTED);
|
||||
wsi->state = WSI_STATE_HTTP;
|
||||
lws_union_transition(wsi, LWSCM_HTTP_SERVING_ACCEPTED);
|
||||
wsi->state = LWSS_HTTP;
|
||||
wsi->u.http.fd = LWS_INVALID_FILE;
|
||||
|
||||
/* expose it at the same offset as u.hdr */
|
||||
|
@ -412,7 +409,7 @@ upgrade_h2c:
|
|||
|
||||
ah = wsi->u.hdr.ah;
|
||||
|
||||
lws_union_transition(wsi, LWS_CONNMODE_HTTP2_SERVING);
|
||||
lws_union_transition(wsi, LWSCM_HTTP2_SERVING);
|
||||
|
||||
/* http2 union member has http union struct at start */
|
||||
wsi->u.http.ah = ah;
|
||||
|
@ -436,7 +433,7 @@ upgrade_h2c:
|
|||
return 1;
|
||||
}
|
||||
|
||||
wsi->state = WSI_STATE_HTTP2_AWAIT_CLIENT_PREFACE;
|
||||
wsi->state = LWSS_HTTP2_AWAIT_CLIENT_PREFACE;
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
|
@ -496,8 +493,7 @@ upgrade_ws:
|
|||
/* we didn't find a protocol he wanted? */
|
||||
|
||||
if (!hit) {
|
||||
if (lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL) ==
|
||||
NULL) {
|
||||
if (!lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL)) {
|
||||
/*
|
||||
* some clients only have one protocol and
|
||||
* do not sent the protocol list header...
|
||||
|
@ -553,7 +549,7 @@ upgrade_ws:
|
|||
/* drop the header info -- no bail_nuke_ah after this */
|
||||
lws_free_header_table(wsi);
|
||||
|
||||
lws_union_transition(wsi, LWS_CONNMODE_WS_SERVING);
|
||||
lws_union_transition(wsi, LWSCM_WS_SERVING);
|
||||
|
||||
/*
|
||||
* create the frame buffer for this connection according to the
|
||||
|
@ -607,8 +603,8 @@ lws_create_new_server_wsi(struct lws_context *context)
|
|||
|
||||
/* intialize the instance struct */
|
||||
|
||||
new_wsi->state = WSI_STATE_HTTP;
|
||||
new_wsi->mode = LWS_CONNMODE_HTTP_SERVING;
|
||||
new_wsi->state = LWSS_HTTP;
|
||||
new_wsi->mode = LWSCM_HTTP_SERVING;
|
||||
new_wsi->hdr_parsing_completed = 0;
|
||||
|
||||
#ifdef LWS_OPENSSL_SUPPORT
|
||||
|
@ -660,8 +656,8 @@ int lws_http_transaction_completed(struct lws *wsi)
|
|||
}
|
||||
|
||||
/* otherwise set ourselves up ready to go again */
|
||||
wsi->state = WSI_STATE_HTTP;
|
||||
wsi->mode = LWS_CONNMODE_HTTP_SERVING;
|
||||
wsi->state = LWSS_HTTP;
|
||||
wsi->mode = LWSCM_HTTP_SERVING;
|
||||
wsi->u.http.content_length = 0;
|
||||
|
||||
/* He asked for it to stay alive indefinitely */
|
||||
|
@ -692,21 +688,21 @@ int lws_server_socket_service(struct lws_context *context,
|
|||
|
||||
switch (wsi->mode) {
|
||||
|
||||
case LWS_CONNMODE_HTTP_SERVING:
|
||||
case LWS_CONNMODE_HTTP_SERVING_ACCEPTED:
|
||||
case LWS_CONNMODE_HTTP2_SERVING:
|
||||
case LWSCM_HTTP_SERVING:
|
||||
case LWSCM_HTTP_SERVING_ACCEPTED:
|
||||
case LWSCM_HTTP2_SERVING:
|
||||
|
||||
/* handle http headers coming in */
|
||||
|
||||
/* pending truncated sends have uber priority */
|
||||
|
||||
if (wsi->truncated_send_len) {
|
||||
if (pollfd->revents & LWS_POLLOUT)
|
||||
if (lws_issue_raw(wsi, wsi->truncated_send_malloc +
|
||||
wsi->truncated_send_offset,
|
||||
wsi->truncated_send_len) < 0) {
|
||||
goto fail;
|
||||
}
|
||||
if (wsi->trunc_len) {
|
||||
if (!(pollfd->revents & LWS_POLLOUT))
|
||||
break;
|
||||
|
||||
if (lws_issue_raw(wsi, wsi->trunc_alloc + wsi->trunc_offset,
|
||||
wsi->trunc_len) < 0)
|
||||
goto fail;
|
||||
/*
|
||||
* we can't afford to allow input processing send
|
||||
* something new, so spin around he event loop until
|
||||
|
@ -717,38 +713,38 @@ int lws_server_socket_service(struct lws_context *context,
|
|||
|
||||
/* any incoming data ready? */
|
||||
|
||||
if (pollfd->revents & LWS_POLLIN) {
|
||||
len = lws_ssl_capable_read(wsi, context->service_buffer,
|
||||
sizeof(context->service_buffer));
|
||||
lwsl_debug("%s: read %d\r\n", __func__, len);
|
||||
switch (len) {
|
||||
case 0:
|
||||
lwsl_info("lws_server_skt_srv: read 0 len\n");
|
||||
/* lwsl_info(" state=%d\n", wsi->state); */
|
||||
if (!wsi->hdr_parsing_completed)
|
||||
lws_free_header_table(wsi);
|
||||
/* fallthru */
|
||||
case LWS_SSL_CAPABLE_ERROR:
|
||||
goto fail;
|
||||
case LWS_SSL_CAPABLE_MORE_SERVICE:
|
||||
goto try_pollout;
|
||||
}
|
||||
if (!(pollfd->revents & LWS_POLLIN))
|
||||
goto try_pollout;
|
||||
|
||||
/* just ignore incoming if waiting for close */
|
||||
if (wsi->state != WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE) {
|
||||
len = lws_ssl_capable_read(wsi, context->serv_buf,
|
||||
sizeof(context->serv_buf));
|
||||
lwsl_debug("%s: read %d\r\n", __func__, len);
|
||||
switch (len) {
|
||||
case 0:
|
||||
lwsl_info("lws_server_skt_srv: read 0 len\n");
|
||||
/* lwsl_info(" state=%d\n", wsi->state); */
|
||||
if (!wsi->hdr_parsing_completed)
|
||||
lws_free_header_table(wsi);
|
||||
/* fallthru */
|
||||
case LWS_SSL_CAPABLE_ERROR:
|
||||
goto fail;
|
||||
case LWS_SSL_CAPABLE_MORE_SERVICE:
|
||||
goto try_pollout;
|
||||
}
|
||||
|
||||
/*
|
||||
* hm this may want to send
|
||||
* (via HTTP callback for example)
|
||||
*/
|
||||
n = lws_read(wsi, context->service_buffer, len);
|
||||
if (n < 0) /* we closed wsi */
|
||||
return 1;
|
||||
/* just ignore incoming if waiting for close */
|
||||
if (wsi->state != LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE) {
|
||||
/*
|
||||
* hm this may want to send
|
||||
* (via HTTP callback for example)
|
||||
*/
|
||||
n = lws_read(wsi, context->serv_buf, len);
|
||||
if (n < 0) /* we closed wsi */
|
||||
return 1;
|
||||
|
||||
/* hum he may have used up the
|
||||
* writability above */
|
||||
break;
|
||||
}
|
||||
/* hum he may have used up the
|
||||
* writability above */
|
||||
break;
|
||||
}
|
||||
|
||||
try_pollout:
|
||||
|
@ -763,7 +759,7 @@ try_pollout:
|
|||
|
||||
lws_libev_io(wsi, LWS_EV_STOP | LWS_EV_WRITE);
|
||||
|
||||
if (wsi->state != WSI_STATE_HTTP_ISSUING_FILE) {
|
||||
if (wsi->state != LWSS_HTTP_ISSUING_FILE) {
|
||||
n = user_callback_handle_rxflow(
|
||||
wsi->protocol->callback,
|
||||
wsi, LWS_CALLBACK_HTTP_WRITEABLE,
|
||||
|
@ -779,7 +775,7 @@ try_pollout:
|
|||
goto fail;
|
||||
break;
|
||||
|
||||
case LWS_CONNMODE_SERVER_LISTENER:
|
||||
case LWSCM_SERVER_LISTENER:
|
||||
|
||||
#if LWS_POSIX
|
||||
/* pollin means a client has connected to us then */
|
||||
|
@ -794,7 +790,7 @@ try_pollout:
|
|||
accept_fd = accept(pollfd->fd, (struct sockaddr *)&cli_addr,
|
||||
&clilen);
|
||||
lws_latency(context, wsi,
|
||||
"unencrypted accept LWS_CONNMODE_SERVER_LISTENER",
|
||||
"unencrypted accept LWSCM_SERVER_LISTENER",
|
||||
accept_fd, accept_fd >= 0);
|
||||
if (accept_fd < 0) {
|
||||
if (LWS_ERRNO == LWS_EAGAIN ||
|
||||
|
@ -877,11 +873,11 @@ fail:
|
|||
|
||||
/**
|
||||
* lws_serve_http_file() - Send a file back to the client using http
|
||||
* @context: libwebsockets context
|
||||
* @wsi: Websocket instance (available from user callback)
|
||||
* @file: The file to issue over http
|
||||
* @content_type: The http content type, eg, text/html
|
||||
* @other_headers: NULL or pointer to \0-terminated other header string
|
||||
* @other_headers: NULL or pointer to header string
|
||||
* @other_headers_len: length of the other headers if non-NULL
|
||||
*
|
||||
* This function is intended to be called from the callback in response
|
||||
* to http requests from the client. It allows the callback to issue
|
||||
|
@ -900,14 +896,15 @@ LWS_VISIBLE int lws_serve_http_file(struct lws *wsi, const char *file,
|
|||
int other_headers_len)
|
||||
{
|
||||
struct lws_context *context = lws_get_ctx(wsi);
|
||||
unsigned char *response = context->service_buffer +
|
||||
unsigned char *response = context->serv_buf +
|
||||
LWS_SEND_BUFFER_PRE_PADDING;
|
||||
unsigned char *p = response;
|
||||
unsigned char *end = p + sizeof(context->service_buffer) -
|
||||
unsigned char *end = p + sizeof(context->serv_buf) -
|
||||
LWS_SEND_BUFFER_PRE_PADDING;
|
||||
int ret = 0;
|
||||
|
||||
wsi->u.http.fd = lws_plat_file_open(wsi, file, &wsi->u.http.filelen, O_RDONLY);
|
||||
wsi->u.http.fd = lws_plat_file_open(wsi, file, &wsi->u.http.filelen,
|
||||
O_RDONLY);
|
||||
|
||||
if (wsi->u.http.fd == LWS_INVALID_FILE) {
|
||||
lwsl_err("Unable to open '%s'\n", file);
|
||||
|
@ -946,13 +943,13 @@ LWS_VISIBLE int lws_serve_http_file(struct lws *wsi, const char *file,
|
|||
}
|
||||
|
||||
wsi->u.http.filepos = 0;
|
||||
wsi->state = WSI_STATE_HTTP_ISSUING_FILE;
|
||||
wsi->state = LWSS_HTTP_ISSUING_FILE;
|
||||
|
||||
return lws_serve_http_file_fragment(wsi);
|
||||
}
|
||||
|
||||
int lws_interpret_incoming_packet(struct lws *wsi, unsigned char *buf,
|
||||
size_t len)
|
||||
int
|
||||
lws_interpret_incoming_packet(struct lws *wsi, unsigned char *buf, size_t len)
|
||||
{
|
||||
size_t n = 0;
|
||||
int m;
|
||||
|
|
112
lib/service.c
112
lib/service.c
|
@ -27,10 +27,10 @@ lws_calllback_as_writeable(struct lws *wsi)
|
|||
int n;
|
||||
|
||||
switch (wsi->mode) {
|
||||
case LWS_CONNMODE_WS_CLIENT:
|
||||
case LWSCM_WS_CLIENT:
|
||||
n = LWS_CALLBACK_CLIENT_WRITEABLE;
|
||||
break;
|
||||
case LWS_CONNMODE_WS_SERVING:
|
||||
case LWSCM_WS_SERVING:
|
||||
n = LWS_CALLBACK_SERVER_WRITEABLE;
|
||||
break;
|
||||
default:
|
||||
|
@ -55,17 +55,17 @@ lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd)
|
|||
|
||||
/* pending truncated sends have uber priority */
|
||||
|
||||
if (wsi->truncated_send_len) {
|
||||
if (lws_issue_raw(wsi, wsi->truncated_send_malloc +
|
||||
wsi->truncated_send_offset,
|
||||
wsi->truncated_send_len) < 0) {
|
||||
if (wsi->trunc_len) {
|
||||
if (lws_issue_raw(wsi, wsi->trunc_alloc +
|
||||
wsi->trunc_offset,
|
||||
wsi->trunc_len) < 0) {
|
||||
lwsl_info("%s signalling to close\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
/* leave POLLOUT active either way */
|
||||
return 0;
|
||||
} else
|
||||
if (wsi->state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE)
|
||||
if (wsi->state == LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE)
|
||||
return -1; /* retry closing now */
|
||||
|
||||
#ifdef LWS_USE_HTTP2
|
||||
|
@ -88,9 +88,9 @@ lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd)
|
|||
#endif
|
||||
/* pending control packets have next priority */
|
||||
|
||||
if ((wsi->state == WSI_STATE_ESTABLISHED &&
|
||||
if ((wsi->state == LWSS_ESTABLISHED &&
|
||||
wsi->u.ws.ping_pending_flag) ||
|
||||
(wsi->state == WSI_STATE_RETURNED_CLOSE_ALREADY &&
|
||||
(wsi->state == LWSS_RETURNED_CLOSE_ALREADY &&
|
||||
wsi->u.ws.payload_is_close)) {
|
||||
|
||||
if (wsi->u.ws.payload_is_close)
|
||||
|
@ -114,12 +114,12 @@ lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd)
|
|||
|
||||
/* if we are closing, don't confuse the user with writeable cb */
|
||||
|
||||
if (wsi->state == WSI_STATE_RETURNED_CLOSE_ALREADY)
|
||||
if (wsi->state == LWSS_RETURNED_CLOSE_ALREADY)
|
||||
goto user_service;
|
||||
|
||||
/* if nothing critical, user can get the callback */
|
||||
|
||||
m = lws_ext_callback_for_each_active(wsi, LWS_EXT_CALLBACK_IS_WRITEABLE,
|
||||
m = lws_ext_cb_wsi_active_exts(wsi, LWS_EXT_CALLBACK_IS_WRITEABLE,
|
||||
NULL, 0);
|
||||
#ifndef LWS_NO_EXTENSIONS
|
||||
if (!wsi->extension_data_pending)
|
||||
|
@ -144,7 +144,7 @@ lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd)
|
|||
|
||||
/* give every extension a chance to spill */
|
||||
|
||||
m = lws_ext_callback_for_each_active(wsi,
|
||||
m = lws_ext_cb_wsi_active_exts(wsi,
|
||||
LWS_EXT_CALLBACK_PACKET_TX_PRESEND,
|
||||
&eff_buf, 0);
|
||||
if (m < 0) {
|
||||
|
@ -232,7 +232,7 @@ user_service:
|
|||
* notifications, so we can't hold pointers
|
||||
*/
|
||||
|
||||
if (wsi->mode != LWS_CONNMODE_HTTP2_SERVING) {
|
||||
if (wsi->mode != LWSCM_HTTP2_SERVING) {
|
||||
lwsl_info("%s: non http2\n", __func__);
|
||||
goto notify;
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ lws_service_timeout_check(struct lws *wsi, unsigned int sec)
|
|||
* if extensions want in on it (eg, we are a mux parent)
|
||||
* give them a chance to service child timeouts
|
||||
*/
|
||||
if (lws_ext_callback_for_each_active(wsi, LWS_EXT_CALLBACK_1HZ,
|
||||
if (lws_ext_cb_wsi_active_exts(wsi, LWS_EXT_CALLBACK_1HZ,
|
||||
NULL, sec) < 0)
|
||||
return 0;
|
||||
|
||||
|
@ -352,7 +352,7 @@ LWS_VISIBLE int
|
|||
lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd)
|
||||
{
|
||||
#if LWS_POSIX
|
||||
int listen_socket_fds_index = 0;
|
||||
int idx = 0;
|
||||
#endif
|
||||
lws_sockfd_type our_fd = 0;
|
||||
struct lws_tokens eff_buf;
|
||||
|
@ -366,9 +366,8 @@ lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd)
|
|||
int more;
|
||||
|
||||
#if LWS_POSIX
|
||||
if (context->listen_service_fd)
|
||||
listen_socket_fds_index = wsi_from_fd(context,
|
||||
context->listen_service_fd)->position_in_fds_table;
|
||||
if (context->lserv_fd)
|
||||
idx = wsi_from_fd(context, context->lserv_fd)->position_in_fds_table;
|
||||
#endif
|
||||
/*
|
||||
* you can call us with pollfd = NULL to just allow the once-per-second
|
||||
|
@ -426,44 +425,37 @@ lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd)
|
|||
#if LWS_POSIX
|
||||
/*
|
||||
* deal with listen service piggybacking
|
||||
* every listen_service_modulo services of other fds, we
|
||||
* every lserv_mod services of other fds, we
|
||||
* sneak one in to service the listen socket if there's anything waiting
|
||||
*
|
||||
* To handle connection storms, as found in ab, if we previously saw a
|
||||
* pending connection here, it causes us to check again next time.
|
||||
*/
|
||||
|
||||
if (context->listen_service_fd && pollfd !=
|
||||
&context->fds[listen_socket_fds_index]) {
|
||||
context->listen_service_count++;
|
||||
if (context->listen_service_extraseen ||
|
||||
context->listen_service_count ==
|
||||
context->listen_service_modulo) {
|
||||
context->listen_service_count = 0;
|
||||
if (context->lserv_fd && pollfd != &context->fds[idx]) {
|
||||
context->lserv_count++;
|
||||
if (context->lserv_seen ||
|
||||
context->lserv_count == context->lserv_mod) {
|
||||
context->lserv_count = 0;
|
||||
m = 1;
|
||||
if (context->listen_service_extraseen > 5)
|
||||
if (context->lserv_seen > 5)
|
||||
m = 2;
|
||||
while (m--) {
|
||||
/*
|
||||
* even with extpoll, we prepared this
|
||||
* internal fds for listen
|
||||
*/
|
||||
n = lws_poll_listen_fd(
|
||||
&context->fds[listen_socket_fds_index]);
|
||||
if (n > 0) { /* there's a conn waiting for us */
|
||||
lws_service_fd(context,
|
||||
&context->
|
||||
fds[listen_socket_fds_index]);
|
||||
context->listen_service_extraseen++;
|
||||
} else {
|
||||
if (context->listen_service_extraseen)
|
||||
context->
|
||||
listen_service_extraseen--;
|
||||
n = lws_poll_listen_fd(&context->fds[idx]);
|
||||
if (n <= 0) {
|
||||
if (context->lserv_seen)
|
||||
context->lserv_seen--;
|
||||
break;
|
||||
}
|
||||
/* there's a conn waiting for us */
|
||||
lws_service_fd(context, &context->fds[idx]);
|
||||
context->lserv_seen++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* handle session socket closed */
|
||||
|
@ -487,10 +479,10 @@ lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd)
|
|||
/* okay, what we came here to do... */
|
||||
|
||||
switch (wsi->mode) {
|
||||
case LWS_CONNMODE_HTTP_SERVING:
|
||||
case LWS_CONNMODE_HTTP_SERVING_ACCEPTED:
|
||||
case LWS_CONNMODE_SERVER_LISTENER:
|
||||
case LWS_CONNMODE_SSL_ACK_PENDING:
|
||||
case LWSCM_HTTP_SERVING:
|
||||
case LWSCM_HTTP_SERVING_ACCEPTED:
|
||||
case LWSCM_SERVER_LISTENER:
|
||||
case LWSCM_SSL_ACK_PENDING:
|
||||
n = lws_server_socket_service(context, wsi, pollfd);
|
||||
if (n) /* closed by above */
|
||||
return 1;
|
||||
|
@ -499,21 +491,21 @@ lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd)
|
|||
goto handle_pending;
|
||||
goto handled;
|
||||
|
||||
case LWS_CONNMODE_WS_SERVING:
|
||||
case LWS_CONNMODE_WS_CLIENT:
|
||||
case LWS_CONNMODE_HTTP2_SERVING:
|
||||
case LWSCM_WS_SERVING:
|
||||
case LWSCM_WS_CLIENT:
|
||||
case LWSCM_HTTP2_SERVING:
|
||||
|
||||
/* the guy requested a callback when it was OK to write */
|
||||
|
||||
if ((pollfd->revents & LWS_POLLOUT) &&
|
||||
(wsi->state == WSI_STATE_ESTABLISHED ||
|
||||
wsi->state == WSI_STATE_HTTP2_ESTABLISHED ||
|
||||
wsi->state == WSI_STATE_HTTP2_ESTABLISHED_PRE_SETTINGS ||
|
||||
wsi->state == WSI_STATE_RETURNED_CLOSE_ALREADY ||
|
||||
wsi->state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE) &&
|
||||
(wsi->state == LWSS_ESTABLISHED ||
|
||||
wsi->state == LWSS_HTTP2_ESTABLISHED ||
|
||||
wsi->state == LWSS_HTTP2_ESTABLISHED_PRE_SETTINGS ||
|
||||
wsi->state == LWSS_RETURNED_CLOSE_ALREADY ||
|
||||
wsi->state == LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE) &&
|
||||
lws_handle_POLLOUT_event(wsi, pollfd)) {
|
||||
if (wsi->state == WSI_STATE_RETURNED_CLOSE_ALREADY)
|
||||
wsi->state = WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE;
|
||||
if (wsi->state == LWSS_RETURNED_CLOSE_ALREADY)
|
||||
wsi->state = LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE;
|
||||
lwsl_info("lws_service_fd: closing\n");
|
||||
goto close_and_handled;
|
||||
}
|
||||
|
@ -536,9 +528,9 @@ lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd)
|
|||
read:
|
||||
|
||||
eff_buf.token_len = lws_ssl_capable_read(wsi,
|
||||
context->service_buffer,
|
||||
context->serv_buf,
|
||||
pending ? pending :
|
||||
sizeof(context->service_buffer));
|
||||
sizeof(context->serv_buf));
|
||||
switch (eff_buf.token_len) {
|
||||
case 0:
|
||||
lwsl_info("service_fd: closing due to 0 length read\n");
|
||||
|
@ -564,13 +556,13 @@ read:
|
|||
* used then so it is efficient.
|
||||
*/
|
||||
|
||||
eff_buf.token = (char *)context->service_buffer;
|
||||
eff_buf.token = (char *)context->serv_buf;
|
||||
drain:
|
||||
|
||||
do {
|
||||
more = 0;
|
||||
|
||||
m = lws_ext_callback_for_each_active(wsi,
|
||||
m = lws_ext_cb_wsi_active_exts(wsi,
|
||||
LWS_EXT_CALLBACK_PACKET_RX_PREPARSE, &eff_buf, 0);
|
||||
if (m < 0)
|
||||
goto close_and_handled;
|
||||
|
@ -596,15 +588,15 @@ drain:
|
|||
pending = lws_ssl_pending(wsi);
|
||||
if (pending) {
|
||||
handle_pending:
|
||||
pending = pending > sizeof(context->service_buffer) ?
|
||||
sizeof(context->service_buffer) : pending;
|
||||
pending = pending > sizeof(context->serv_buf) ?
|
||||
sizeof(context->serv_buf) : pending;
|
||||
goto read;
|
||||
}
|
||||
|
||||
if (draining_flow && wsi->rxflow_buffer &&
|
||||
wsi->rxflow_pos == wsi->rxflow_len) {
|
||||
lwsl_info("flow buffer: drained\n");
|
||||
lws_free2(wsi->rxflow_buffer);
|
||||
lws_free_set_NULL(wsi->rxflow_buffer);
|
||||
/* having drained the rxflow buffer, can rearm POLLIN */
|
||||
#ifdef LWS_NO_SERVER
|
||||
n =
|
||||
|
|
|
@ -136,8 +136,8 @@ void lws_http2_configure_if_upgraded(struct lws *wsi)
|
|||
|
||||
ah = wsi->u.hdr.ah;
|
||||
|
||||
lws_union_transition(wsi, LWS_CONNMODE_HTTP2_SERVING);
|
||||
wsi->state = WSI_STATE_HTTP2_AWAIT_CLIENT_PREFACE;
|
||||
lws_union_transition(wsi, LWSCM_HTTP2_SERVING);
|
||||
wsi->state = LWSS_HTTP2_AWAIT_CLIENT_PREFACE;
|
||||
|
||||
/* http2 union member has http union struct at start */
|
||||
wsi->u.http.ah = ah;
|
||||
|
|
123
lib/ssl.c
123
lib/ssl.c
|
@ -26,8 +26,8 @@
|
|||
|
||||
int openssl_websocket_private_data_index;
|
||||
|
||||
static int lws_context_init_ssl_pem_passwd_cb(char * buf, int size,
|
||||
int rwflag, void *userdata)
|
||||
static int
|
||||
lws_context_init_ssl_pem_passwd_cb(char * buf, int size, int rwflag, void *userdata)
|
||||
{
|
||||
struct lws_context_creation_info * info =
|
||||
(struct lws_context_creation_info *)userdata;
|
||||
|
@ -38,8 +38,7 @@ static int lws_context_init_ssl_pem_passwd_cb(char * buf, int size,
|
|||
return strlen(buf);
|
||||
}
|
||||
|
||||
static void lws_ssl_bind_passphrase(SSL_CTX *ssl_ctx,
|
||||
struct lws_context_creation_info *info)
|
||||
static void lws_ssl_bind_passphrase(SSL_CTX *ssl_ctx, struct lws_context_creation_info *info)
|
||||
{
|
||||
if (!info->ssl_private_key_password)
|
||||
return;
|
||||
|
@ -49,8 +48,7 @@ static void lws_ssl_bind_passphrase(SSL_CTX *ssl_ctx,
|
|||
* SSL_CTX_use_PrivateKey_file function
|
||||
*/
|
||||
SSL_CTX_set_default_passwd_cb_userdata(ssl_ctx, (void *)info);
|
||||
SSL_CTX_set_default_passwd_cb(ssl_ctx,
|
||||
lws_context_init_ssl_pem_passwd_cb);
|
||||
SSL_CTX_set_default_passwd_cb(ssl_ctx, lws_context_init_ssl_pem_passwd_cb);
|
||||
}
|
||||
|
||||
#ifndef LWS_NO_SERVER
|
||||
|
@ -88,7 +86,7 @@ OpenSSL_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx)
|
|||
|
||||
LWS_VISIBLE int
|
||||
lws_context_init_server_ssl(struct lws_context_creation_info *info,
|
||||
struct lws_context *context)
|
||||
struct lws_context *context)
|
||||
{
|
||||
SSL_METHOD *method;
|
||||
struct lws wsi;
|
||||
|
@ -149,7 +147,7 @@ lws_context_init_server_ssl(struct lws_context_creation_info *info,
|
|||
error = ERR_get_error();
|
||||
lwsl_err("problem creating ssl method %lu: %s\n",
|
||||
error, ERR_error_string(error,
|
||||
(char *)context->service_buffer));
|
||||
(char *)context->serv_buf));
|
||||
return 1;
|
||||
}
|
||||
context->ssl_ctx = SSL_CTX_new(method); /* create context */
|
||||
|
@ -157,7 +155,7 @@ lws_context_init_server_ssl(struct lws_context_creation_info *info,
|
|||
error = ERR_get_error();
|
||||
lwsl_err("problem creating ssl context %lu: %s\n",
|
||||
error, ERR_error_string(error,
|
||||
(char *)context->service_buffer));
|
||||
(char *)context->serv_buf));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -173,8 +171,7 @@ lws_context_init_server_ssl(struct lws_context_creation_info *info,
|
|||
|
||||
/* as a server, are we requiring clients to identify themselves? */
|
||||
|
||||
if (info->options &
|
||||
LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT) {
|
||||
if (info->options & LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT) {
|
||||
int verify_options = SSL_VERIFY_PEER;
|
||||
|
||||
if (!(info->options & LWS_SERVER_OPTION_PEER_CERT_NOT_REQUIRED))
|
||||
|
@ -198,13 +195,11 @@ lws_context_init_server_ssl(struct lws_context_creation_info *info,
|
|||
context->ssl_ctx, NULL, 0);
|
||||
}
|
||||
|
||||
if (info->options & LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT) {
|
||||
if (info->options & LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT)
|
||||
/* Normally SSL listener rejects non-ssl, optionally allow */
|
||||
context->allow_non_ssl_on_ssl_port = 1;
|
||||
}
|
||||
|
||||
if (context->use_ssl) {
|
||||
|
||||
/* openssl init for server sockets */
|
||||
|
||||
/* set the local certificate from CertFile */
|
||||
|
@ -216,7 +211,7 @@ lws_context_init_server_ssl(struct lws_context_creation_info *info,
|
|||
info->ssl_cert_filepath,
|
||||
error,
|
||||
ERR_error_string(error,
|
||||
(char *)context->service_buffer));
|
||||
(char *)context->serv_buf));
|
||||
return 1;
|
||||
}
|
||||
lws_ssl_bind_passphrase(context->ssl_ctx, info);
|
||||
|
@ -230,11 +225,10 @@ lws_context_init_server_ssl(struct lws_context_creation_info *info,
|
|||
lwsl_err("ssl problem getting key '%s' %lu: %s\n",
|
||||
info->ssl_private_key_filepath, error,
|
||||
ERR_error_string(error,
|
||||
(char *)context->service_buffer));
|
||||
(char *)context->serv_buf));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else
|
||||
if (context->protocols[0].callback(&wsi,
|
||||
LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY,
|
||||
context->ssl_ctx, NULL, 0)) {
|
||||
|
@ -242,7 +236,6 @@ lws_context_init_server_ssl(struct lws_context_creation_info *info,
|
|||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* verify private key */
|
||||
if (!SSL_CTX_check_private_key(context->ssl_ctx)) {
|
||||
|
@ -325,7 +318,7 @@ int lws_context_init_client_ssl(struct lws_context_creation_info *info,
|
|||
error = ERR_get_error();
|
||||
lwsl_err("problem creating ssl method %lu: %s\n",
|
||||
error, ERR_error_string(error,
|
||||
(char *)context->service_buffer));
|
||||
(char *)context->serv_buf));
|
||||
return 1;
|
||||
}
|
||||
/* create context */
|
||||
|
@ -334,7 +327,7 @@ int lws_context_init_client_ssl(struct lws_context_creation_info *info,
|
|||
error = ERR_get_error();
|
||||
lwsl_err("problem creating ssl context %lu: %s\n",
|
||||
error, ERR_error_string(error,
|
||||
(char *)context->service_buffer));
|
||||
(char *)context->serv_buf));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -389,7 +382,7 @@ int lws_context_init_client_ssl(struct lws_context_creation_info *info,
|
|||
info->ssl_cert_filepath,
|
||||
ERR_get_error(),
|
||||
ERR_error_string(ERR_get_error(),
|
||||
(char *)context->service_buffer));
|
||||
(char *)context->serv_buf));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -402,7 +395,7 @@ int lws_context_init_client_ssl(struct lws_context_creation_info *info,
|
|||
info->ssl_private_key_filepath,
|
||||
ERR_get_error(),
|
||||
ERR_error_string(ERR_get_error(),
|
||||
(char *)context->service_buffer));
|
||||
(char *)context->serv_buf));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -469,35 +462,47 @@ lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len)
|
|||
if (!n)
|
||||
return LWS_SSL_CAPABLE_ERROR;
|
||||
|
||||
if (n > 0) {
|
||||
/*
|
||||
* if it was our buffer that limited what we read,
|
||||
* check if SSL has additional data pending inside SSL buffers.
|
||||
*
|
||||
* Because these won't signal at the network layer with POLLIN
|
||||
* and if we don't realize, this data will sit there forever
|
||||
*/
|
||||
if (n == len && wsi->ssl && SSL_pending(wsi->ssl)) {
|
||||
if (!wsi->pending_read_list_next && !wsi->pending_read_list_prev) {
|
||||
if (context->pending_read_list != wsi) {
|
||||
/* add us to the linked list of guys with pending ssl */
|
||||
if (context->pending_read_list)
|
||||
context->pending_read_list->pending_read_list_prev = wsi;
|
||||
wsi->pending_read_list_next = context->pending_read_list;
|
||||
wsi->pending_read_list_prev = NULL;
|
||||
context->pending_read_list = wsi;
|
||||
}
|
||||
}
|
||||
} else
|
||||
lws_ssl_remove_wsi_from_buffered_list(wsi);
|
||||
if (n < 0) {
|
||||
n = SSL_get_error(wsi->ssl, n);
|
||||
if (n == SSL_ERROR_WANT_READ || n == SSL_ERROR_WANT_WRITE)
|
||||
return LWS_SSL_CAPABLE_MORE_SERVICE;
|
||||
|
||||
return n;
|
||||
return LWS_SSL_CAPABLE_ERROR;
|
||||
}
|
||||
n = SSL_get_error(wsi->ssl, n);
|
||||
if (n == SSL_ERROR_WANT_READ || n == SSL_ERROR_WANT_WRITE)
|
||||
return LWS_SSL_CAPABLE_MORE_SERVICE;
|
||||
lwsl_err("%s: LWS_SSL_CAPABLE_ERROR\n", __func__);
|
||||
return LWS_SSL_CAPABLE_ERROR;
|
||||
|
||||
/*
|
||||
* if it was our buffer that limited what we read,
|
||||
* check if SSL has additional data pending inside SSL buffers.
|
||||
*
|
||||
* Because these won't signal at the network layer with POLLIN
|
||||
* and if we don't realize, this data will sit there forever
|
||||
*/
|
||||
if (n != len)
|
||||
goto bail;
|
||||
if (!wsi->ssl)
|
||||
goto bail;
|
||||
if (!SSL_pending(wsi->ssl))
|
||||
goto bail;
|
||||
if (wsi->pending_read_list_next)
|
||||
return n;
|
||||
if (wsi->pending_read_list_prev)
|
||||
return n;
|
||||
if (context->pending_read_list == wsi)
|
||||
return n;
|
||||
|
||||
/* add us to the linked list of guys with pending ssl */
|
||||
if (context->pending_read_list)
|
||||
context->pending_read_list->pending_read_list_prev = wsi;
|
||||
|
||||
wsi->pending_read_list_next = context->pending_read_list;
|
||||
wsi->pending_read_list_prev = NULL;
|
||||
context->pending_read_list = wsi;
|
||||
|
||||
return n;
|
||||
bail:
|
||||
lws_ssl_remove_wsi_from_buffered_list(wsi);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
LWS_VISIBLE int
|
||||
|
@ -527,7 +532,7 @@ lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len)
|
|||
lws_set_blocking_send(wsi);
|
||||
return LWS_SSL_CAPABLE_MORE_SERVICE;
|
||||
}
|
||||
lwsl_err("%s: LWS_SSL_CAPABLE_ERROR\n", __func__);
|
||||
|
||||
return LWS_SSL_CAPABLE_ERROR;
|
||||
}
|
||||
|
||||
|
@ -566,7 +571,7 @@ lws_server_socket_service_ssl(struct lws **pwsi, struct lws *new_wsi,
|
|||
return 0;
|
||||
|
||||
switch (wsi->mode) {
|
||||
case LWS_CONNMODE_SERVER_LISTENER:
|
||||
case LWSCM_SERVER_LISTENER:
|
||||
|
||||
if (!new_wsi) {
|
||||
lwsl_err("no new_wsi\n");
|
||||
|
@ -615,7 +620,7 @@ lws_server_socket_service_ssl(struct lws **pwsi, struct lws *new_wsi,
|
|||
|
||||
*pwsi = new_wsi;
|
||||
wsi = *pwsi;
|
||||
wsi->mode = LWS_CONNMODE_SSL_ACK_PENDING;
|
||||
wsi->mode = LWSCM_SSL_ACK_PENDING;
|
||||
if (insert_wsi_socket_into_fds(context, wsi))
|
||||
goto fail;
|
||||
|
||||
|
@ -626,7 +631,7 @@ lws_server_socket_service_ssl(struct lws **pwsi, struct lws *new_wsi,
|
|||
|
||||
/* fallthru */
|
||||
|
||||
case LWS_CONNMODE_SSL_ACK_PENDING:
|
||||
case LWSCM_SSL_ACK_PENDING:
|
||||
|
||||
if (lws_change_pollfd(wsi, LWS_POLLOUT, 0))
|
||||
goto fail;
|
||||
|
@ -635,8 +640,8 @@ lws_server_socket_service_ssl(struct lws **pwsi, struct lws *new_wsi,
|
|||
|
||||
lws_latency_pre(context, wsi);
|
||||
|
||||
n = recv(wsi->sock, (char *)context->service_buffer,
|
||||
sizeof(context->service_buffer), MSG_PEEK);
|
||||
n = recv(wsi->sock, (char *)context->serv_buf,
|
||||
sizeof(context->serv_buf), MSG_PEEK);
|
||||
|
||||
/*
|
||||
* optionally allow non-SSL connect on SSL listening socket
|
||||
|
@ -646,7 +651,7 @@ lws_server_socket_service_ssl(struct lws **pwsi, struct lws *new_wsi,
|
|||
*/
|
||||
|
||||
if (context->allow_non_ssl_on_ssl_port) {
|
||||
if (n >= 1 && context->service_buffer[0] >= ' ') {
|
||||
if (n >= 1 && context->serv_buf[0] >= ' ') {
|
||||
/*
|
||||
* TLS content-type for Handshake is 0x16, and
|
||||
* for ChangeCipherSpec Record, it's 0x14
|
||||
|
@ -686,7 +691,7 @@ lws_server_socket_service_ssl(struct lws **pwsi, struct lws *new_wsi,
|
|||
|
||||
n = SSL_accept(wsi->ssl);
|
||||
lws_latency(context, wsi,
|
||||
"SSL_accept LWS_CONNMODE_SSL_ACK_PENDING\n", n, n == 1);
|
||||
"SSL_accept LWSCM_SSL_ACK_PENDING\n", n, n == 1);
|
||||
|
||||
if (n == 1)
|
||||
goto accepted;
|
||||
|
@ -720,7 +725,7 @@ accepted:
|
|||
lws_set_timeout(wsi, PENDING_TIMEOUT_ESTABLISH_WITH_SERVER,
|
||||
AWAITING_TIMEOUT);
|
||||
|
||||
wsi->mode = LWS_CONNMODE_HTTP_SERVING;
|
||||
wsi->mode = LWSCM_HTTP_SERVING;
|
||||
|
||||
lws_http2_configure_if_upgraded(wsi);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue