/* 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;
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)) {
}
if (connect(wsi->sock, v, n) == -1 || LWS_ERRNO == LWS_EISCONN) {
-
if (LWS_ERRNO == LWS_EALREADY ||
LWS_ERRNO == LWS_EINPROGRESS ||
LWS_ERRNO == LWS_EWOULDBLOCK
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");
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;
}
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;
oom4:
lws_free(wsi->u.hdr.ah);
lws_free(wsi);
+
return NULL;
failed:
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;
* 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");
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");
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;
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;
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) {
*/
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
&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);
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) {
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);
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:
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 */
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;
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");
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
/* 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 */
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) {
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;
}
/* fallthru */
- case LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE:
+ case LWSCM_WSCL_ISSUE_HANDSHAKE:
/*
* we are under PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE
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) {
"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 */
}
lwsl_err("SSL connect error %lu: %s\n",
n,
ERR_error_string(n,
- (char *)context->service_buffer));
+ (char *)context->serv_buf));
return 0;
}
}
/* 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) {
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;
}
}
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;
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");
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");
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 */
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;
* 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) {
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;
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:
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;
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 */
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");
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;
* 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;
* 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);
/*
if (getpid() == pid_daemon)
if (lock_path) {
unlink(lock_path);
- lws_free2(lock_path);
+ lws_free_set_NULL(lock_path);
}
kill(getpid(), SIGKILL);
/* 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;
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;
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;
* 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;
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) {
/*
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))
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)
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)
}
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:
}
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");
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
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;
{
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);
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;
};
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)))
/**
* 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
{
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)
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];
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;
}
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;
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;
* 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: */
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);
}
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);
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;
}
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);
* 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;
/* 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");
* 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],
* 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
/* 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;
/* 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,
/* 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++)
* 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");
/**
* 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
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,
{
#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)
/**
* 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
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;
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;
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
* list then.
*/
lws_ssl_remove_wsi_from_buffered_list(wsi);
- }
+
wsi = wsi_next;
}
#endif
/* any socket with events to service? */
for (n = 0; n < context->fds_count; n++) {
-
if (!context->fds[n].revents)
continue;
/* 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__) || \
/* 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
}
{
}
-
LWS_VISIBLE int
lws_plat_context_early_init(void)
{
{
/* 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);
}
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) {
/*
* 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
/* 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;
}
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;
/* 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;
/*
* 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 */
}
* 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);
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;
/* 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;
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;
}
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
}
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");
* 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");
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);
}
}
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;
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;
}
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;
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)
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);
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;
};
* 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]]) {
}
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;
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;
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 =
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) {
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
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);
/* 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 */
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);
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:
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",
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;
/*
* 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
#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 };
#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
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;
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;
#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))
* (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,
* becomes able to be written to without
* blocking
*
- * @context: libwebsockets context
* @wsi: Websocket connection instance to get callback for
*/
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) {
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;
* 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);
* 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,
-
- WSI_STATE_HTTP2_AWAIT_CLIENT_PREFACE,
- WSI_STATE_HTTP2_ESTABLISHED_PRE_SETTINGS,
- WSI_STATE_HTTP2_ESTABLISHED,
+ 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,
+
+ LWSS_HTTP2_AWAIT_CLIENT_PREFACE,
+ LWSS_HTTP2_ESTABLISHED_PRE_SETTINGS,
+ LWSS_HTTP2_ESTABLISHED,
};
enum http_version {
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 {
* 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
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;
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;
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
#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
* 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;
* 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;
/* 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)) {
/* 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 */
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);
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)
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);
lwsl_notice(" Listening on port %d\n", info->port);
return 0;
+
+bail:
+ compatible_close(sockfd);
+
+ return 1;
}
int
}
/* 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");
* 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;
}
char protocol_name[32];
char *p;
- /* LWS_CONNMODE_WS_SERVING */
+ /* LWSCM_WS_SERVING */
while (len--) {
if (lws_parse(wsi, *(*buf)++)) {
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 */
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;
return 1;
}
- wsi->state = WSI_STATE_HTTP2_AWAIT_CLIENT_PREFACE;
+ wsi->state = LWSS_HTTP2_AWAIT_CLIENT_PREFACE;
return 0;
#endif
/* 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...
/* 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
/* 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
}
/* 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 */
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
/* 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;
- }
-
- /* just ignore incoming if waiting for close */
- if (wsi->state != WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE) {
+ if (!(pollfd->revents & LWS_POLLIN))
+ goto try_pollout;
+
+ 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:
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,
goto fail;
break;
- case LWS_CONNMODE_SERVER_LISTENER:
+ case LWSCM_SERVER_LISTENER:
#if LWS_POSIX
/* pollin means a client has connected to us then */
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 ||
/**
* 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
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);
}
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;
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:
/* 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
#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)
/* 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)
/* 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) {
* 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;
}
* 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;
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;
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
#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 */
/* 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;
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;
}
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");
* 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;
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 =
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;
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;
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;
* 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
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;
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 */
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;
}
/* 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))
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 */
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);
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)) {
return 1;
}
- }
/* verify private key */
if (!SSL_CTX_check_private_key(context->ssl_ctx)) {
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 */
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;
}
info->ssl_cert_filepath,
ERR_get_error(),
ERR_error_string(ERR_get_error(),
- (char *)context->service_buffer));
+ (char *)context->serv_buf));
return 1;
}
}
info->ssl_private_key_filepath,
ERR_get_error(),
ERR_error_string(ERR_get_error(),
- (char *)context->service_buffer));
+ (char *)context->serv_buf));
return 1;
}
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
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;
}
return 0;
switch (wsi->mode) {
- case LWS_CONNMODE_SERVER_LISTENER:
+ case LWSCM_SERVER_LISTENER:
if (!new_wsi) {
lwsl_err("no new_wsi\n");
*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;
/* fallthru */
- case LWS_CONNMODE_SSL_ACK_PENDING:
+ case LWSCM_SSL_ACK_PENDING:
if (lws_change_pollfd(wsi, LWS_POLLOUT, 0))
goto fail;
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
*/
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
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;
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);