mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00
Re-indent source files (assuming tab size was 4)
This commit is contained in:
parent
38bca2992a
commit
4dab41e383
30 changed files with 514 additions and 514 deletions
|
@ -44,9 +44,9 @@
|
|||
#include "private-libwebsockets.h"
|
||||
|
||||
static const char encode[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
"abcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
static const char decode[] = "|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW"
|
||||
"$$$$$$XYZ[\\]^_`abcdefghijklmnopq";
|
||||
"$$$$$$XYZ[\\]^_`abcdefghijklmnopq";
|
||||
|
||||
LWS_VISIBLE int
|
||||
lws_b64_encode_string(const char *in, int in_len, char *out, int out_size)
|
||||
|
@ -73,9 +73,9 @@ lws_b64_encode_string(const char *in, int in_len, char *out, int out_size)
|
|||
|
||||
*out++ = encode[triple[0] >> 2];
|
||||
*out++ = encode[((triple[0] & 0x03) << 4) |
|
||||
((triple[1] & 0xf0) >> 4)];
|
||||
((triple[1] & 0xf0) >> 4)];
|
||||
*out++ = (len > 1 ? encode[((triple[1] & 0x0f) << 2) |
|
||||
((triple[2] & 0xc0) >> 6)] : '=');
|
||||
((triple[2] & 0xc0) >> 6)] : '=');
|
||||
*out++ = (len > 2 ? encode[triple[2] & 0x3f] : '=');
|
||||
|
||||
done += 4;
|
||||
|
@ -164,7 +164,7 @@ lws_b64_selftest(void)
|
|||
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
n = lws_b64_encode_string(plaintext[test],
|
||||
strlen(plaintext[test]), buf, sizeof buf);
|
||||
strlen(plaintext[test]), buf, sizeof buf);
|
||||
if (n != strlen(coded[test]) || strcmp(buf, coded[test])) {
|
||||
lwsl_err("Failed lws_b64 encode selftest "
|
||||
"%d result '%s' %d\n", test, buf, n);
|
||||
|
|
|
@ -18,7 +18,7 @@ struct libwebsocket *libwebsocket_client_connect_2(
|
|||
int plen = 0;
|
||||
const char *ads;
|
||||
|
||||
lwsl_client("libwebsocket_client_connect_2\n");
|
||||
lwsl_client("libwebsocket_client_connect_2\n");
|
||||
|
||||
/*
|
||||
* proxy?
|
||||
|
@ -54,7 +54,7 @@ struct libwebsocket *libwebsocket_client_connect_2(
|
|||
/*
|
||||
* prepare the actual connection (to the proxy, if any)
|
||||
*/
|
||||
lwsl_client("libwebsocket_client_connect_2: address %s\n", ads);
|
||||
lwsl_client("libwebsocket_client_connect_2: address %s\n", ads);
|
||||
|
||||
#ifdef LWS_USE_IPV6
|
||||
if (LWS_IPV6_ENABLED(context)) {
|
||||
|
@ -156,7 +156,7 @@ struct libwebsocket *libwebsocket_client_connect_2(
|
|||
|
||||
libwebsocket_set_timeout(wsi,
|
||||
PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE,
|
||||
AWAITING_TIMEOUT);
|
||||
AWAITING_TIMEOUT);
|
||||
#ifdef LWS_USE_IPV6
|
||||
if (LWS_IPV6_ENABLED(context)) {
|
||||
v = (struct sockaddr *)&client_addr6;
|
||||
|
@ -204,7 +204,7 @@ struct libwebsocket *libwebsocket_client_connect_2(
|
|||
if (connect(wsi->sock, v, n) == -1 || LWS_ERRNO == LWS_EISCONN) {
|
||||
|
||||
if (LWS_ERRNO == LWS_EALREADY || LWS_ERRNO == LWS_EINPROGRESS
|
||||
|| LWS_ERRNO == LWS_EWOULDBLOCK) {
|
||||
|| LWS_ERRNO == LWS_EWOULDBLOCK) {
|
||||
lwsl_client("nonblocking connect retry\n");
|
||||
|
||||
/*
|
||||
|
@ -249,7 +249,7 @@ struct libwebsocket *libwebsocket_client_connect_2(
|
|||
|
||||
libwebsocket_set_timeout(wsi,
|
||||
PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE,
|
||||
AWAITING_TIMEOUT);
|
||||
AWAITING_TIMEOUT);
|
||||
|
||||
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY;
|
||||
|
||||
|
@ -290,7 +290,7 @@ oom4:
|
|||
|
||||
failed:
|
||||
libwebsocket_close_and_free_session(context, wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -316,14 +316,14 @@ failed:
|
|||
|
||||
LWS_VISIBLE struct libwebsocket *
|
||||
libwebsocket_client_connect(struct libwebsocket_context *context,
|
||||
const char *address,
|
||||
int port,
|
||||
int ssl_connection,
|
||||
const char *path,
|
||||
const char *host,
|
||||
const char *origin,
|
||||
const char *protocol,
|
||||
int ietf_version_or_minus_one)
|
||||
const char *address,
|
||||
int port,
|
||||
int ssl_connection,
|
||||
const char *path,
|
||||
const char *host,
|
||||
const char *origin,
|
||||
const char *protocol,
|
||||
int ietf_version_or_minus_one)
|
||||
{
|
||||
struct libwebsocket *wsi;
|
||||
|
||||
|
@ -401,14 +401,14 @@ libwebsocket_client_connect(struct libwebsocket_context *context,
|
|||
|
||||
libwebsocket_set_timeout(wsi,
|
||||
PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE,
|
||||
AWAITING_TIMEOUT);
|
||||
AWAITING_TIMEOUT);
|
||||
|
||||
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT;
|
||||
return wsi;
|
||||
}
|
||||
lwsl_client("libwebsocket_client_connect: direct conn\n");
|
||||
|
||||
return libwebsocket_client_connect_2(context, wsi);
|
||||
return libwebsocket_client_connect_2(context, wsi);
|
||||
|
||||
bail1:
|
||||
lws_free(wsi->u.hdr.ah);
|
||||
|
@ -441,20 +441,20 @@ bail:
|
|||
|
||||
LWS_VISIBLE struct libwebsocket *
|
||||
libwebsocket_client_connect_extended(struct libwebsocket_context *context,
|
||||
const char *address,
|
||||
int port,
|
||||
int ssl_connection,
|
||||
const char *path,
|
||||
const char *host,
|
||||
const char *origin,
|
||||
const char *protocol,
|
||||
int ietf_version_or_minus_one,
|
||||
void *userdata)
|
||||
const char *address,
|
||||
int port,
|
||||
int ssl_connection,
|
||||
const char *path,
|
||||
const char *host,
|
||||
const char *origin,
|
||||
const char *protocol,
|
||||
int ietf_version_or_minus_one,
|
||||
void *userdata)
|
||||
{
|
||||
struct libwebsocket *ws =
|
||||
libwebsocket_client_connect(context, address, port,
|
||||
ssl_connection, path, host, origin, protocol,
|
||||
ietf_version_or_minus_one);
|
||||
ietf_version_or_minus_one);
|
||||
|
||||
if (ws && !ws->user_space && userdata) {
|
||||
ws->user_space_externally_allocated = 1;
|
||||
|
|
|
@ -49,7 +49,7 @@ int libwebsocket_client_rx_sm(struct libwebsocket *wsi, unsigned char c)
|
|||
|
||||
default:
|
||||
lwsl_err("unknown spec version %02d\n",
|
||||
wsi->ietf_spec_revision);
|
||||
wsi->ietf_spec_revision);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -221,12 +221,12 @@ int libwebsocket_client_rx_sm(struct libwebsocket *wsi, unsigned char c)
|
|||
|
||||
if ((!wsi->u.ws.this_frame_masked) || wsi->u.ws.all_zero_nonce)
|
||||
wsi->u.ws.rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING +
|
||||
(wsi->u.ws.rx_user_buffer_head++)] = c;
|
||||
(wsi->u.ws.rx_user_buffer_head++)] = c;
|
||||
else
|
||||
wsi->u.ws.rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING +
|
||||
(wsi->u.ws.rx_user_buffer_head++)] =
|
||||
(wsi->u.ws.rx_user_buffer_head++)] =
|
||||
c ^ wsi->u.ws.frame_masking_nonce_04[
|
||||
(wsi->u.ws.frame_mask_index++) & 3];
|
||||
(wsi->u.ws.frame_mask_index++) & 3];
|
||||
|
||||
if (--wsi->u.ws.rx_packet_length == 0) {
|
||||
/* spill because we have the whole frame */
|
||||
|
@ -240,8 +240,8 @@ int libwebsocket_client_rx_sm(struct libwebsocket *wsi, unsigned char c)
|
|||
*/
|
||||
|
||||
if (!wsi->protocol->rx_buffer_size &&
|
||||
wsi->u.ws.rx_user_buffer_head !=
|
||||
LWS_MAX_SOCKET_IO_BUF)
|
||||
wsi->u.ws.rx_user_buffer_head !=
|
||||
LWS_MAX_SOCKET_IO_BUF)
|
||||
break;
|
||||
else
|
||||
if (wsi->protocol->rx_buffer_size &&
|
||||
|
@ -306,7 +306,7 @@ spill:
|
|||
|
||||
/* 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)
|
||||
wsi->u.ws.ping_payload_alloc < wsi->u.ws.rx_user_buffer_head)
|
||||
lws_free2(wsi->u.ws.ping_payload_buf);
|
||||
|
||||
/* if no buffer, allocate it */
|
||||
|
@ -319,7 +319,7 @@ spill:
|
|||
|
||||
/* stash the pong payload */
|
||||
memcpy(wsi->u.ws.ping_payload_buf + LWS_SEND_BUFFER_PRE_PADDING,
|
||||
&wsi->u.ws.rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
|
||||
&wsi->u.ws.rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
|
||||
wsi->u.ws.rx_user_buffer_head);
|
||||
|
||||
wsi->u.ws.ping_payload_len = wsi->u.ws.rx_user_buffer_head;
|
||||
|
@ -336,7 +336,7 @@ ping_drop:
|
|||
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);
|
||||
wsi->u.ws.rx_user_buffer_head);
|
||||
|
||||
/* issue it */
|
||||
callback_action = LWS_CALLBACK_CLIENT_RECEIVE_PONG;
|
||||
|
@ -366,7 +366,7 @@ ping_drop:
|
|||
&eff_buf, 0) <= 0) { /* not handle or fail */
|
||||
|
||||
lwsl_ext("Unhandled ext opc 0x%x\n",
|
||||
wsi->u.ws.opcode);
|
||||
wsi->u.ws.opcode);
|
||||
wsi->u.ws.rx_user_buffer_head = 0;
|
||||
|
||||
return 0;
|
||||
|
@ -393,7 +393,7 @@ ping_drop:
|
|||
return -1;
|
||||
|
||||
if (eff_buf.token_len <= 0 &&
|
||||
callback_action != LWS_CALLBACK_CLIENT_RECEIVE_PONG)
|
||||
callback_action != LWS_CALLBACK_CLIENT_RECEIVE_PONG)
|
||||
goto already_done;
|
||||
|
||||
eff_buf.token[eff_buf.token_len] = '\0';
|
||||
|
|
90
lib/client.c
90
lib/client.c
|
@ -3,20 +3,20 @@
|
|||
*
|
||||
* Copyright (C) 2010-2014 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
|
||||
* License as published by the Free Software Foundation:
|
||||
* version 2.1 of the License.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation:
|
||||
* version 2.1 of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "private-libwebsockets.h"
|
||||
|
@ -60,7 +60,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
* timeout protection set in client-handshake.c
|
||||
*/
|
||||
|
||||
if (libwebsocket_client_connect_2(context, wsi) == NULL) {
|
||||
if (libwebsocket_client_connect_2(context, wsi) == NULL) {
|
||||
/* closed */
|
||||
lwsl_client("closed\n");
|
||||
return -1;
|
||||
|
@ -79,7 +79,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
(void *)wsi, pollfd->fd);
|
||||
|
||||
libwebsocket_close_and_free_session(context, wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
}
|
||||
|
||||
libwebsocket_close_and_free_session(context, wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
lwsl_err("ERROR reading from proxy socket\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
context->service_buffer[13] = '\0';
|
||||
if (strcmp((char *)context->service_buffer, "HTTP/1.0 200 ")) {
|
||||
libwebsocket_close_and_free_session(context, wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
lwsl_err("ERROR proxy: %s\n", context->service_buffer);
|
||||
return 0;
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
|
||||
SSL_set_ex_data(wsi->ssl,
|
||||
openssl_websocket_private_data_index,
|
||||
context);
|
||||
context);
|
||||
}
|
||||
|
||||
if (wsi->use_ssl) {
|
||||
|
@ -191,7 +191,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
n = SSL_connect(wsi->ssl);
|
||||
lws_latency(context, wsi,
|
||||
"SSL_connect LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE",
|
||||
n, n > 0);
|
||||
n, n > 0);
|
||||
|
||||
if (n < 0) {
|
||||
n = SSL_get_error(wsi->ssl, n);
|
||||
|
@ -212,7 +212,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
*/
|
||||
|
||||
lwsl_info(
|
||||
"SSL_connect WANT_... retrying\n");
|
||||
"SSL_connect WANT_... retrying\n");
|
||||
libwebsocket_callback_on_writable(
|
||||
context, wsi);
|
||||
|
||||
|
@ -309,11 +309,11 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
n = SSL_get_verify_result(wsi->ssl);
|
||||
lws_latency(context, wsi,
|
||||
"SSL_get_verify_result LWS_CONNMODE..HANDSHAKE",
|
||||
n, n > 0);
|
||||
n, n > 0);
|
||||
|
||||
if (n != X509_V_OK) {
|
||||
if ((n == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT ||
|
||||
n == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) && wsi->use_ssl == 2) {
|
||||
n == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) && wsi->use_ssl == 2) {
|
||||
lwsl_notice("accepting self-signed certificate\n");
|
||||
} else {
|
||||
lwsl_err("server's cert didn't look good, X509_V_ERR = %d: %s\n",
|
||||
|
@ -331,7 +331,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
wsi->mode = LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE2;
|
||||
libwebsocket_set_timeout(wsi,
|
||||
PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND,
|
||||
AWAITING_TIMEOUT);
|
||||
AWAITING_TIMEOUT);
|
||||
|
||||
/* fallthru */
|
||||
|
||||
|
@ -340,7 +340,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
if (p == NULL) {
|
||||
lwsl_err("Failed to generate handshake for client\n");
|
||||
libwebsocket_close_and_free_session(context, wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -354,7 +354,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
case LWS_SSL_CAPABLE_ERROR:
|
||||
lwsl_debug("ERROR writing to client socket\n");
|
||||
libwebsocket_close_and_free_session(context, wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
return 0;
|
||||
case LWS_SSL_CAPABLE_MORE_SERVICE:
|
||||
libwebsocket_callback_on_writable(context, wsi);
|
||||
|
@ -366,7 +366,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY;
|
||||
libwebsocket_set_timeout(wsi,
|
||||
PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE,
|
||||
AWAITING_TIMEOUT);
|
||||
AWAITING_TIMEOUT);
|
||||
break;
|
||||
|
||||
case LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY:
|
||||
|
@ -387,12 +387,12 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
/* interpret the server response */
|
||||
|
||||
/*
|
||||
* HTTP/1.1 101 Switching Protocols
|
||||
* Upgrade: websocket
|
||||
* Connection: Upgrade
|
||||
* Sec-WebSocket-Accept: me89jWimTRKTWwrS3aRrL53YZSo=
|
||||
* Sec-WebSocket-Nonce: AQIDBAUGBwgJCgsMDQ4PEC==
|
||||
* Sec-WebSocket-Protocol: chat
|
||||
* HTTP/1.1 101 Switching Protocols
|
||||
* Upgrade: websocket
|
||||
* Connection: Upgrade
|
||||
* Sec-WebSocket-Accept: me89jWimTRKTWwrS3aRrL53YZSo=
|
||||
* Sec-WebSocket-Nonce: AQIDBAUGBwgJCgsMDQ4PEC==
|
||||
* Sec-WebSocket-Protocol: chat
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -405,7 +405,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
*/
|
||||
len = 1;
|
||||
while (wsi->u.hdr.parser_state != WSI_PARSING_COMPLETE &&
|
||||
len > 0) {
|
||||
len > 0) {
|
||||
n = lws_ssl_capable_read(context, wsi, &c, 1);
|
||||
lws_latency(context, wsi, "send lws_issue_raw", n, n == 1);
|
||||
switch (n) {
|
||||
|
@ -442,7 +442,7 @@ bail3:
|
|||
lwsl_info(
|
||||
"closing connection at LWS_CONNMODE...SERVER_REPLY\n");
|
||||
libwebsocket_close_and_free_session(context, wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
return -1;
|
||||
|
||||
case LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT:
|
||||
|
@ -508,7 +508,7 @@ lws_client_interpret_server_handshake(struct libwebsocket_context *context,
|
|||
}
|
||||
if (p && strncmp(p, "101", 3)) {
|
||||
lwsl_warn(
|
||||
"lws_client_handshake: got bad HTTP response '%s'\n", p);
|
||||
"lws_client_handshake: got bad HTTP response '%s'\n", p);
|
||||
goto bail3;
|
||||
}
|
||||
|
||||
|
@ -520,7 +520,7 @@ lws_client_interpret_server_handshake(struct libwebsocket_context *context,
|
|||
strtolower(p);
|
||||
if (strcmp(p, "websocket")) {
|
||||
lwsl_warn(
|
||||
"lws_client_handshake: got bad Upgrade header '%s'\n", p);
|
||||
"lws_client_handshake: got bad Upgrade header '%s'\n", p);
|
||||
goto bail3;
|
||||
}
|
||||
|
||||
|
@ -563,7 +563,7 @@ lws_client_interpret_server_handshake(struct libwebsocket_context *context,
|
|||
|
||||
while (pc && *pc && !okay) {
|
||||
if (!strncmp(pc, p, len) &&
|
||||
(pc[len] == ',' || pc[len] == '\0')) {
|
||||
(pc[len] == ',' || pc[len] == '\0')) {
|
||||
okay = 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -715,7 +715,7 @@ check_accept:
|
|||
|
||||
wsi->protocol->callback(context, wsi,
|
||||
LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH,
|
||||
wsi->user_space, NULL, 0);
|
||||
wsi->user_space, NULL, 0);
|
||||
|
||||
/* clear his proxy connection timeout */
|
||||
|
||||
|
@ -758,7 +758,7 @@ check_accept:
|
|||
|
||||
wsi->protocol->callback(context, wsi,
|
||||
LWS_CALLBACK_CLIENT_ESTABLISHED,
|
||||
wsi->user_space, NULL, 0);
|
||||
wsi->user_space, NULL, 0);
|
||||
#ifndef LWS_NO_EXTENSIONS
|
||||
/*
|
||||
* inform all extensions, not just active ones since they
|
||||
|
@ -789,7 +789,7 @@ bail2:
|
|||
if (wsi->protocol)
|
||||
wsi->protocol->callback(context, wsi,
|
||||
LWS_CALLBACK_CLIENT_CONNECTION_ERROR,
|
||||
wsi->user_space, NULL, 0);
|
||||
wsi->user_space, NULL, 0);
|
||||
|
||||
lwsl_info("closing connection due to bail2 connection error\n");
|
||||
|
||||
|
@ -826,7 +826,7 @@ libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
|
|||
lwsl_err("Unable to read from random dev %s\n",
|
||||
SYSTEM_RANDOM_FILEPATH);
|
||||
libwebsocket_close_and_free_session(context, wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -840,7 +840,7 @@ libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
|
|||
* Connection: Upgrade
|
||||
* Host: 127.0.0.1:9999
|
||||
* Origin: http://127.0.0.1
|
||||
* Sec-WebSocket-Key1: 1 0 2#0W 9 89 7 92 ^
|
||||
* Sec-WebSocket-Key1: 1 0 2#0W 9 89 7 92 ^
|
||||
* Sec-WebSocket-Key2: 7 7Y 4328 B2v[8(z1
|
||||
* Cookie: socketio=websocket
|
||||
*
|
||||
|
@ -865,7 +865,7 @@ libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
|
|||
"Pragma: no-cache\x0d\x0a""Cache-Control: no-cache\x0d\x0a");
|
||||
|
||||
p += sprintf(p, "Host: %s\x0d\x0a",
|
||||
lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_HOST));
|
||||
lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_HOST));
|
||||
p += sprintf(p,
|
||||
"Upgrade: websocket\x0d\x0a""Connection: Upgrade\x0d\x0a""Sec-WebSocket-Key: ");
|
||||
strcpy(p, key_b64);
|
||||
|
@ -873,11 +873,11 @@ libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
|
|||
p += sprintf(p, "\x0d\x0a");
|
||||
if (lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN))
|
||||
p += sprintf(p, "Origin: http://%s\x0d\x0a",
|
||||
lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN));
|
||||
lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN));
|
||||
|
||||
if (lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS))
|
||||
p += sprintf(p, "Sec-WebSocket-Protocol: %s\x0d\x0a",
|
||||
lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS));
|
||||
lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS));
|
||||
|
||||
/* tell the server what extensions we could support */
|
||||
|
||||
|
@ -925,7 +925,7 @@ libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
|
|||
|
||||
if (wsi->ietf_spec_revision)
|
||||
p += sprintf(p, "Sec-WebSocket-Version: %d\x0d\x0a",
|
||||
wsi->ietf_spec_revision);
|
||||
wsi->ietf_spec_revision);
|
||||
|
||||
/* give userland a chance to append, eg, cookies */
|
||||
|
||||
|
|
|
@ -136,13 +136,13 @@ libwebsocket_create_context(struct lws_context_creation_info *info)
|
|||
sizeof(struct libwebsocket_context) +
|
||||
((sizeof(struct libwebsocket_pollfd) +
|
||||
sizeof(struct libwebsocket *)) *
|
||||
context->max_fds));
|
||||
context->max_fds));
|
||||
|
||||
context->fds = lws_zalloc(sizeof(struct libwebsocket_pollfd) *
|
||||
context->max_fds);
|
||||
if (context->fds == NULL) {
|
||||
lwsl_err("Unable to allocate fds array for %d connections\n",
|
||||
context->max_fds);
|
||||
context->max_fds);
|
||||
lws_free(context);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ libwebsocket_create_context(struct lws_context_creation_info *info)
|
|||
if (context->lws_lookup == NULL) {
|
||||
lwsl_err(
|
||||
"Unable to allocate lws_lookup array for %d connections\n",
|
||||
context->max_fds);
|
||||
context->max_fds);
|
||||
lws_free(context->fds);
|
||||
lws_free(context);
|
||||
return NULL;
|
||||
|
@ -188,7 +188,7 @@ libwebsocket_create_context(struct lws_context_creation_info *info)
|
|||
|
||||
if (info->http_proxy_address) {
|
||||
strncpy(context->http_proxy_address, info->http_proxy_address,
|
||||
sizeof(context->http_proxy_address) - 1);
|
||||
sizeof(context->http_proxy_address) - 1);
|
||||
context->http_proxy_address[
|
||||
sizeof(context->http_proxy_address) - 1] = '\0';
|
||||
context->http_proxy_port = info->http_proxy_port;
|
||||
|
@ -197,7 +197,7 @@ libwebsocket_create_context(struct lws_context_creation_info *info)
|
|||
p = getenv("http_proxy");
|
||||
if (p) {
|
||||
strncpy(context->http_proxy_address, p,
|
||||
sizeof(context->http_proxy_address) - 1);
|
||||
sizeof(context->http_proxy_address) - 1);
|
||||
context->http_proxy_address[
|
||||
sizeof(context->http_proxy_address) - 1] = '\0';
|
||||
|
||||
|
@ -215,12 +215,12 @@ libwebsocket_create_context(struct lws_context_creation_info *info)
|
|||
if (context->http_proxy_address[0])
|
||||
lwsl_notice(" Proxy %s:%u\n",
|
||||
context->http_proxy_address,
|
||||
context->http_proxy_port);
|
||||
context->http_proxy_port);
|
||||
|
||||
lwsl_notice(
|
||||
" per-conn mem: %u + %u headers + protocol rx buf\n",
|
||||
sizeof(struct libwebsocket),
|
||||
sizeof(struct allocated_headers));
|
||||
sizeof(struct allocated_headers));
|
||||
|
||||
if (lws_context_init_server_ssl(info, context))
|
||||
goto bail;
|
||||
|
@ -250,14 +250,14 @@ libwebsocket_create_context(struct lws_context_creation_info *info)
|
|||
info->protocols[context->count_protocols].owning_server =
|
||||
context;
|
||||
info->protocols[context->count_protocols].protocol_index =
|
||||
context->count_protocols;
|
||||
context->count_protocols;
|
||||
|
||||
/*
|
||||
* inform all the protocols that they are doing their one-time
|
||||
* initialization if they want to
|
||||
*/
|
||||
info->protocols[context->count_protocols].callback(context,
|
||||
NULL, LWS_CALLBACK_PROTOCOL_INIT, NULL, NULL, 0);
|
||||
NULL, LWS_CALLBACK_PROTOCOL_INIT, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -60,7 +60,7 @@ child_handler(int signum)
|
|||
if (sent != len)
|
||||
fprintf(stderr,
|
||||
"unable write pid to lock file %s, code=%d (%s)\n",
|
||||
lock_path, errno, strerror(errno));
|
||||
lock_path, errno, strerror(errno));
|
||||
|
||||
close(fd);
|
||||
exit(!!(sent == len));
|
||||
|
@ -112,11 +112,11 @@ lws_daemonize(const char *_lock_path)
|
|||
ret = kill(n, 0);
|
||||
if (ret >= 0) {
|
||||
fprintf(stderr,
|
||||
"Daemon already running from pid %d\n", n);
|
||||
"Daemon already running from pid %d\n", n);
|
||||
exit(1);
|
||||
}
|
||||
fprintf(stderr,
|
||||
"Removing stale lock file %s from dead pid %d\n",
|
||||
"Removing stale lock file %s from dead pid %d\n",
|
||||
_lock_path, n);
|
||||
unlink(lock_path);
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ lws_daemonize(const char *_lock_path)
|
|||
pid_daemon = fork();
|
||||
if (pid_daemon < 0) {
|
||||
fprintf(stderr, "unable to fork daemon, code=%d (%s)",
|
||||
errno, strerror(errno));
|
||||
errno, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -195,15 +195,15 @@ lws_daemonize(const char *_lock_path)
|
|||
/* Redirect standard files to /dev/null */
|
||||
if (!freopen("/dev/null", "r", stdin))
|
||||
fprintf(stderr, "unable to freopen() stdin, code %d (%s)",
|
||||
errno, strerror(errno));
|
||||
errno, strerror(errno));
|
||||
|
||||
if (!freopen("/dev/null", "w", stdout))
|
||||
fprintf(stderr, "unable to freopen() stdout, code %d (%s)",
|
||||
errno, strerror(errno));
|
||||
errno, strerror(errno));
|
||||
|
||||
if (!freopen("/dev/null", "w", stderr))
|
||||
fprintf(stderr, "unable to freopen() stderr, code %d (%s)",
|
||||
errno, strerror(errno));
|
||||
errno, strerror(errno));
|
||||
|
||||
/* Tell the parent process that we are A-okay */
|
||||
kill(parent, SIGUSR1);
|
||||
|
|
|
@ -15,7 +15,7 @@ int lws_extension_callback_deflate_frame(
|
|||
void *user, void *in, size_t len)
|
||||
{
|
||||
struct lws_ext_deflate_frame_conn *conn =
|
||||
(struct lws_ext_deflate_frame_conn *)user;
|
||||
(struct lws_ext_deflate_frame_conn *)user;
|
||||
struct lws_tokens *eff_buf = (struct lws_tokens *)in;
|
||||
size_t current_payload, remaining_payload, total_payload;
|
||||
int n;
|
||||
|
@ -112,7 +112,7 @@ bail:
|
|||
}
|
||||
|
||||
memcpy(conn->buf_pre + conn->buf_pre_used,
|
||||
eff_buf->token, current_payload);
|
||||
eff_buf->token, current_payload);
|
||||
conn->buf_pre_used += current_payload;
|
||||
|
||||
eff_buf->token = NULL;
|
||||
|
@ -125,7 +125,7 @@ bail:
|
|||
current_payload;
|
||||
|
||||
memcpy(conn->buf_pre + conn->buf_pre_used,
|
||||
eff_buf->token, current_payload);
|
||||
eff_buf->token, current_payload);
|
||||
conn->buf_pre_used = 0;
|
||||
|
||||
conn->zs_in.next_in = conn->buf_pre;
|
||||
|
@ -239,9 +239,9 @@ bail:
|
|||
return -1;
|
||||
}
|
||||
conn->buf_out = lws_realloc(conn->buf_out,
|
||||
LWS_SEND_BUFFER_PRE_PADDING +
|
||||
conn->buf_out_length +
|
||||
LWS_SEND_BUFFER_POST_PADDING);
|
||||
LWS_SEND_BUFFER_PRE_PADDING +
|
||||
conn->buf_out_length +
|
||||
LWS_SEND_BUFFER_POST_PADDING);
|
||||
if (!conn->buf_out) {
|
||||
lwsl_err("Out of memory\n");
|
||||
return -1;
|
||||
|
@ -251,7 +251,7 @@ bail:
|
|||
conn->buf_out_length);
|
||||
|
||||
conn->zs_out.next_out = (conn->buf_out +
|
||||
LWS_SEND_BUFFER_PRE_PADDING + len_so_far);
|
||||
LWS_SEND_BUFFER_PRE_PADDING + len_so_far);
|
||||
conn->zs_out.avail_out =
|
||||
(conn->buf_out_length - len_so_far);
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ bail:
|
|||
eff_buf->token = (char *)(conn->buf_out +
|
||||
LWS_SEND_BUFFER_PRE_PADDING);
|
||||
eff_buf->token_len = (int)(conn->zs_out.next_out -
|
||||
(conn->buf_out + LWS_SEND_BUFFER_PRE_PADDING)) - 4;
|
||||
(conn->buf_out + LWS_SEND_BUFFER_PRE_PADDING)) - 4;
|
||||
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -12,10 +12,10 @@ int lws_extension_callback_deflate_stream(
|
|||
struct libwebsocket_extension *ext,
|
||||
struct libwebsocket *wsi,
|
||||
enum libwebsocket_extension_callback_reasons reason,
|
||||
void *user, void *in, size_t len)
|
||||
void *user, void *in, size_t len)
|
||||
{
|
||||
struct lws_ext_deflate_stream_conn *conn =
|
||||
(struct lws_ext_deflate_stream_conn *)user;
|
||||
(struct lws_ext_deflate_stream_conn *)user;
|
||||
int n;
|
||||
struct lws_tokens *eff_buf = (struct lws_tokens *)in;
|
||||
|
||||
|
@ -38,7 +38,7 @@ int lws_extension_callback_deflate_stream(
|
|||
n = deflateInit2(&conn->zs_out,
|
||||
DEFLATE_STREAM_COMPRESSION_LEVEL, Z_DEFLATED,
|
||||
-LWS_ZLIB_WINDOW_BITS, LWS_ZLIB_MEMLEVEL,
|
||||
Z_DEFAULT_STRATEGY);
|
||||
Z_DEFAULT_STRATEGY);
|
||||
if (n != Z_OK) {
|
||||
lwsl_err("deflateInit returned %d\n", n);
|
||||
return 1;
|
||||
|
|
|
@ -17,4 +17,4 @@ extern int lws_extension_callback_deflate_stream(
|
|||
struct libwebsocket_extension *ext,
|
||||
struct libwebsocket *wsi,
|
||||
enum libwebsocket_extension_callback_reasons reason,
|
||||
void *user, void *in, size_t len);
|
||||
void *user, void *in, size_t len);
|
||||
|
|
|
@ -29,7 +29,7 @@ struct libwebsocket_extension libwebsocket_internal_extensions[] = {
|
|||
|
||||
LWS_VISIBLE void
|
||||
lws_context_init_extensions(struct lws_context_creation_info *info,
|
||||
struct libwebsocket_context *context)
|
||||
struct libwebsocket_context *context)
|
||||
{
|
||||
context->extensions = info->extensions;
|
||||
lwsl_info(" LWS_MAX_EXTENSIONS_ACTIVE: %u\n", LWS_MAX_EXTENSIONS_ACTIVE);
|
||||
|
@ -58,7 +58,7 @@ int lws_ext_callback_for_each_active(struct libwebsocket *wsi, int reason,
|
|||
if (m < 0) {
|
||||
lwsl_ext(
|
||||
"Extension '%s' failed to handle callback %d!\n",
|
||||
wsi->active_extensions[n]->name, reason);
|
||||
wsi->active_extensions[n]->name, reason);
|
||||
return -1;
|
||||
}
|
||||
if (m > handled)
|
||||
|
@ -81,7 +81,7 @@ int lws_ext_callback_for_each_extension_type(
|
|||
if (m < 0) {
|
||||
lwsl_ext(
|
||||
"Extension '%s' failed to handle callback %d!\n",
|
||||
wsi->active_extensions[n]->name, reason);
|
||||
wsi->active_extensions[n]->name, reason);
|
||||
return -1;
|
||||
}
|
||||
if (m)
|
||||
|
@ -120,7 +120,7 @@ lws_issue_raw_ext_access(struct libwebsocket *wsi,
|
|||
|
||||
/* show every extension the new incoming data */
|
||||
m = lws_ext_callback_for_each_active(wsi,
|
||||
LWS_EXT_CALLBACK_PACKET_TX_PRESEND, &eff_buf, 0);
|
||||
LWS_EXT_CALLBACK_PACKET_TX_PRESEND, &eff_buf, 0);
|
||||
if (m < 0)
|
||||
return -1;
|
||||
if (m) /* handled */
|
||||
|
@ -137,7 +137,7 @@ lws_issue_raw_ext_access(struct libwebsocket *wsi,
|
|||
|
||||
if (eff_buf.token_len) {
|
||||
n = lws_issue_raw(wsi, (unsigned char *)eff_buf.token,
|
||||
eff_buf.token_len);
|
||||
eff_buf.token_len);
|
||||
if (n < 0) {
|
||||
lwsl_info("closing from ext access\n");
|
||||
return -1;
|
||||
|
@ -176,7 +176,7 @@ lws_issue_raw_ext_access(struct libwebsocket *wsi,
|
|||
* when he is ready to send and take care of it there
|
||||
*/
|
||||
libwebsocket_callback_on_writable(
|
||||
wsi->protocol->owning_server, wsi);
|
||||
wsi->protocol->owning_server, wsi);
|
||||
wsi->extension_data_pending = 1;
|
||||
ret = 0;
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ int
|
|||
lws_any_extension_handled(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
enum libwebsocket_extension_callback_reasons r,
|
||||
void *v, size_t len)
|
||||
void *v, size_t len)
|
||||
{
|
||||
int n;
|
||||
int handled = 0;
|
||||
|
|
|
@ -62,8 +62,8 @@
|
|||
|
||||
static int
|
||||
getifaddrs2(struct ifaddrs **ifap,
|
||||
int af, int siocgifconf, int siocgifflags,
|
||||
size_t ifreq_sz)
|
||||
int af, int siocgifconf, int siocgifflags,
|
||||
size_t ifreq_sz)
|
||||
{
|
||||
int ret;
|
||||
int fd;
|
||||
|
@ -153,12 +153,12 @@ getifaddrs2(struct ifaddrs **ifap,
|
|||
(*end)->ifa_broadaddr =
|
||||
lws_malloc(sizeof(ifr->ifr_broadaddr));
|
||||
memcpy((*end)->ifa_broadaddr, &ifr->ifr_broadaddr,
|
||||
sizeof(ifr->ifr_broadaddr));
|
||||
sizeof(ifr->ifr_broadaddr));
|
||||
} else if (ifreq.ifr_flags & IFF_POINTOPOINT) {
|
||||
(*end)->ifa_dstaddr =
|
||||
lws_malloc(sizeof(ifr->ifr_dstaddr));
|
||||
memcpy((*end)->ifa_dstaddr, &ifr->ifr_dstaddr,
|
||||
sizeof(ifr->ifr_dstaddr));
|
||||
sizeof(ifr->ifr_dstaddr));
|
||||
} else
|
||||
(*end)->ifa_dstaddr = NULL;
|
||||
#else
|
||||
|
@ -231,7 +231,7 @@ print_addr(const char *s, struct sockaddr *sa)
|
|||
printf(" %s=%d/", s, sa->sa_family);
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
|
||||
for (i = 0;
|
||||
i < sa->sa_len - ((long)sa->sa_data - (long)&sa->sa_family); i++)
|
||||
i < sa->sa_len - ((long)sa->sa_data - (long)&sa->sa_family); i++)
|
||||
printf("%02x", ((unsigned char *)sa->sa_data)[i]);
|
||||
#else
|
||||
for (i = 0; i < sizeof(sa->sa_data); i++)
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
|
||||
LWS_VISIBLE int
|
||||
libwebsocket_read(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, unsigned char *buf, size_t len)
|
||||
struct libwebsocket *wsi, unsigned char *buf, size_t len)
|
||||
{
|
||||
size_t n;
|
||||
int body_chunk_len;
|
||||
|
@ -226,7 +226,7 @@ bail:
|
|||
lwsl_debug("closing connection at libwebsocket_read bail:\n");
|
||||
|
||||
libwebsocket_close_and_free_session(context, wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
48
lib/header.c
48
lib/header.c
|
@ -30,12 +30,12 @@ const unsigned char *lws_token_to_string(enum lws_token_indexes token)
|
|||
}
|
||||
|
||||
int lws_add_http_header_by_name(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
const unsigned char *name,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
struct libwebsocket *wsi,
|
||||
const unsigned char *name,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
{
|
||||
#ifdef LWS_USE_HTTP2
|
||||
if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING)
|
||||
|
@ -62,9 +62,9 @@ int lws_add_http_header_by_name(struct libwebsocket_context *context,
|
|||
}
|
||||
|
||||
int lws_finalize_http_header(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
struct libwebsocket *wsi,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
{
|
||||
#ifdef LWS_USE_HTTP2
|
||||
if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING)
|
||||
|
@ -78,12 +78,12 @@ int lws_finalize_http_header(struct libwebsocket_context *context,
|
|||
}
|
||||
|
||||
int lws_add_http_header_by_token(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
enum lws_token_indexes token,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
struct libwebsocket *wsi,
|
||||
enum lws_token_indexes token,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
{
|
||||
const unsigned char *name;
|
||||
#ifdef LWS_USE_HTTP2
|
||||
|
@ -97,10 +97,10 @@ int lws_add_http_header_by_token(struct libwebsocket_context *context,
|
|||
}
|
||||
|
||||
int lws_add_http_header_content_length(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
unsigned long content_length,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
struct libwebsocket *wsi,
|
||||
unsigned long content_length,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
{
|
||||
char b[24];
|
||||
int n;
|
||||
|
@ -145,10 +145,10 @@ static const char *err500[] = {
|
|||
};
|
||||
|
||||
int lws_add_http_header_status(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
unsigned int code,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
struct libwebsocket *wsi,
|
||||
unsigned int code,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
{
|
||||
unsigned char code_and_desc[60];
|
||||
const char *description = "";
|
||||
|
@ -180,7 +180,7 @@ int lws_add_http_header_status(struct libwebsocket_context *context,
|
|||
*/
|
||||
LWS_VISIBLE int libwebsockets_return_http_status(
|
||||
struct libwebsocket_context *context, struct libwebsocket *wsi,
|
||||
unsigned int code, const char *html_body)
|
||||
unsigned int code, const char *html_body)
|
||||
{
|
||||
int n, m;
|
||||
|
||||
|
|
36
lib/hpack.c
36
lib/hpack.c
|
@ -494,7 +494,7 @@ pre_data:
|
|||
if (wsi->u.http2.value) {
|
||||
if (lws_frag_start(wsi,
|
||||
lws_token_from_index(wsi,
|
||||
wsi->u.http2.header_index, NULL, NULL)))
|
||||
wsi->u.http2.header_index, NULL, NULL)))
|
||||
return 1;
|
||||
} else
|
||||
wsi->u.hdr.parser_state = WSI_TOKEN_NAME_PART;
|
||||
|
@ -521,7 +521,7 @@ pre_data:
|
|||
wsi->u.http2.hpack_pos =
|
||||
huftable_decode(
|
||||
wsi->u.http2.hpack_pos,
|
||||
(c >> 7) & 1);
|
||||
(c >> 7) & 1);
|
||||
c <<= 1;
|
||||
if (wsi->u.http2.hpack_pos == 0xffff)
|
||||
return 1;
|
||||
|
@ -610,12 +610,12 @@ static int lws_http2_num(int starting_bits, unsigned long num, unsigned char **p
|
|||
}
|
||||
|
||||
int lws_add_http2_header_by_name(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
const unsigned char *name,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
struct libwebsocket *wsi,
|
||||
const unsigned char *name,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
{
|
||||
int len;
|
||||
|
||||
|
@ -648,12 +648,12 @@ int lws_add_http2_header_by_name(struct libwebsocket_context *context,
|
|||
}
|
||||
|
||||
int lws_add_http2_header_by_token(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
enum lws_token_indexes token,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
struct libwebsocket *wsi,
|
||||
enum lws_token_indexes token,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
{
|
||||
const unsigned char *name;
|
||||
|
||||
|
@ -665,10 +665,10 @@ int lws_add_http2_header_by_token(struct libwebsocket_context *context,
|
|||
}
|
||||
|
||||
int lws_add_http2_header_status(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
unsigned int code,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
struct libwebsocket *wsi,
|
||||
unsigned int code,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
{
|
||||
unsigned char status[10];
|
||||
int n;
|
||||
|
|
22
lib/http2.c
22
lib/http2.c
|
@ -27,8 +27,8 @@ const struct http2_settings lws_http2_default_settings = { {
|
|||
/* LWS_HTTP2_SETTINGS__HEADER_TABLE_SIZE */ 4096,
|
||||
/* LWS_HTTP2_SETTINGS__ENABLE_PUSH */ 1,
|
||||
/* LWS_HTTP2_SETTINGS__MAX_CONCURRENT_STREAMS */ 100,
|
||||
/* LWS_HTTP2_SETTINGS__INITIAL_WINDOW_SIZE */ 65535,
|
||||
/* LWS_HTTP2_SETTINGS__MAX_FRAME_SIZE */ 16384,
|
||||
/* LWS_HTTP2_SETTINGS__INITIAL_WINDOW_SIZE */ 65535,
|
||||
/* LWS_HTTP2_SETTINGS__MAX_FRAME_SIZE */ 16384,
|
||||
/* LWS_HTTP2_SETTINGS__MAX_HEADER_LIST_SIZE */ ~0,
|
||||
}};
|
||||
|
||||
|
@ -187,7 +187,7 @@ static const char * https_client_preface =
|
|||
|
||||
int
|
||||
lws_http2_parser(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, unsigned char c)
|
||||
struct libwebsocket *wsi, unsigned char c)
|
||||
{
|
||||
struct libwebsocket *swsi;
|
||||
int n;
|
||||
|
@ -225,9 +225,9 @@ lws_http2_parser(struct libwebsocket_context *context,
|
|||
wsi->u.http2.stream_wsi->u.http2.one_setting[wsi->u.http2.count % LWS_HTTP2_SETTINGS_LENGTH] = c;
|
||||
if (wsi->u.http2.count % LWS_HTTP2_SETTINGS_LENGTH == LWS_HTTP2_SETTINGS_LENGTH - 1)
|
||||
if (lws_http2_interpret_settings_payload(
|
||||
&wsi->u.http2.stream_wsi->u.http2.peer_settings,
|
||||
wsi->u.http2.one_setting,
|
||||
LWS_HTTP2_SETTINGS_LENGTH))
|
||||
&wsi->u.http2.stream_wsi->u.http2.peer_settings,
|
||||
wsi->u.http2.one_setting,
|
||||
LWS_HTTP2_SETTINGS_LENGTH))
|
||||
return 1;
|
||||
break;
|
||||
case LWS_HTTP2_FRAME_TYPE_CONTINUATION:
|
||||
|
@ -430,8 +430,8 @@ int lws_http2_do_pps_send(struct libwebsocket_context *context, struct libwebsoc
|
|||
m += sizeof(wsi->u.http2.one_setting);
|
||||
}
|
||||
n = lws_http2_frame_write(wsi, LWS_HTTP2_FRAME_TYPE_SETTINGS,
|
||||
0, LWS_HTTP2_STREAM_ID_MASTER, m,
|
||||
&settings[LWS_SEND_BUFFER_PRE_PADDING]);
|
||||
0, LWS_HTTP2_STREAM_ID_MASTER, m,
|
||||
&settings[LWS_SEND_BUFFER_PRE_PADDING]);
|
||||
if (n != m) {
|
||||
lwsl_info("send %d %d\n", n, m);
|
||||
return 1;
|
||||
|
@ -482,9 +482,9 @@ int lws_http2_do_pps_send(struct libwebsocket_context *context, struct libwebsoc
|
|||
case LWS_PPS_HTTP2_PONG:
|
||||
memcpy(&settings[LWS_SEND_BUFFER_PRE_PADDING], wsi->u.http2.ping_payload, 8);
|
||||
n = lws_http2_frame_write(wsi, LWS_HTTP2_FRAME_TYPE_PING,
|
||||
LWS_HTTP2_FLAG_SETTINGS_ACK,
|
||||
LWS_HTTP2_STREAM_ID_MASTER, 8,
|
||||
&settings[LWS_SEND_BUFFER_PRE_PADDING]);
|
||||
LWS_HTTP2_FLAG_SETTINGS_ACK,
|
||||
LWS_HTTP2_STREAM_ID_MASTER, 8,
|
||||
&settings[LWS_SEND_BUFFER_PRE_PADDING]);
|
||||
if (n != 8) {
|
||||
lwsl_info("send %d %d\n", n, m);
|
||||
return 1;
|
||||
|
|
|
@ -53,7 +53,7 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context,
|
|||
old_state = wsi->state;
|
||||
|
||||
if (wsi->socket_is_permanently_unusable ||
|
||||
reason == LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY)
|
||||
reason == LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY)
|
||||
goto just_kill_connection;
|
||||
|
||||
switch (old_state) {
|
||||
|
@ -113,7 +113,7 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context,
|
|||
*/
|
||||
|
||||
if (lws_ext_callback_for_each_active(wsi,
|
||||
LWS_EXT_CALLBACK_CHECK_OK_TO_REALLY_CLOSE, NULL, 0) > 0) {
|
||||
LWS_EXT_CALLBACK_CHECK_OK_TO_REALLY_CLOSE, NULL, 0) > 0) {
|
||||
lwsl_ext("extension vetoed close\n");
|
||||
return;
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context,
|
|||
|
||||
if (eff_buf.token_len)
|
||||
if (lws_issue_raw(wsi, (unsigned char *)eff_buf.token,
|
||||
eff_buf.token_len) != eff_buf.token_len) {
|
||||
eff_buf.token_len) != eff_buf.token_len) {
|
||||
lwsl_debug("close: ext spill failed\n");
|
||||
goto just_kill_connection;
|
||||
}
|
||||
|
@ -166,8 +166,8 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context,
|
|||
*/
|
||||
|
||||
if (old_state == WSI_STATE_ESTABLISHED &&
|
||||
reason != LWS_CLOSE_STATUS_NOSTATUS &&
|
||||
reason != LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY) {
|
||||
reason != LWS_CLOSE_STATUS_NOSTATUS &&
|
||||
reason != LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY) {
|
||||
|
||||
lwsl_debug("sending close indication...\n");
|
||||
|
||||
|
@ -175,7 +175,7 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context,
|
|||
memset(buf, 0, sizeof(buf));
|
||||
n = libwebsocket_write(wsi,
|
||||
&buf[LWS_SEND_BUFFER_PRE_PADDING + 2],
|
||||
0, LWS_WRITE_CLOSE);
|
||||
0, LWS_WRITE_CLOSE);
|
||||
if (n >= 0) {
|
||||
/*
|
||||
* we have sent a nice protocol level indication we
|
||||
|
@ -224,8 +224,8 @@ just_kill_connection:
|
|||
}
|
||||
|
||||
if ((old_state == WSI_STATE_ESTABLISHED ||
|
||||
wsi->mode == LWS_CONNMODE_WS_SERVING ||
|
||||
wsi->mode == LWS_CONNMODE_WS_CLIENT)) {
|
||||
wsi->mode == LWS_CONNMODE_WS_SERVING ||
|
||||
wsi->mode == LWS_CONNMODE_WS_CLIENT)) {
|
||||
|
||||
lws_free2(wsi->u.ws.rx_user_buffer);
|
||||
|
||||
|
@ -251,7 +251,7 @@ just_kill_connection:
|
|||
(old_state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE))) {
|
||||
lwsl_debug("calling back CLOSED\n");
|
||||
wsi->protocol->callback(context, wsi, LWS_CALLBACK_CLOSED,
|
||||
wsi->user_space, NULL, 0);
|
||||
wsi->user_space, NULL, 0);
|
||||
} else if (wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED) {
|
||||
lwsl_debug("calling back CLOSED_HTTP\n");
|
||||
context->protocols[0].callback(context, wsi,
|
||||
|
@ -278,7 +278,7 @@ just_kill_connection:
|
|||
* even though not active on him specifically
|
||||
*/
|
||||
if (lws_ext_callback_for_each_extension_type(context, wsi,
|
||||
LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING, NULL, 0) < 0)
|
||||
LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING, NULL, 0) < 0)
|
||||
lwsl_warn("ext destroy wsi failed\n");
|
||||
|
||||
/* lwsl_info("closing fd=%d\n", wsi->sock); */
|
||||
|
@ -298,7 +298,7 @@ just_kill_connection:
|
|||
LWS_CALLBACK_WSI_DESTROY, wsi->user_space, NULL, 0);
|
||||
|
||||
if (wsi->protocol && wsi->protocol->per_session_data_size &&
|
||||
wsi->user_space && !wsi->user_space_externally_allocated)
|
||||
wsi->user_space && !wsi->user_space_externally_allocated)
|
||||
lws_free(wsi->user_space);
|
||||
|
||||
/* As a precaution, free the header table in case it lingered: */
|
||||
|
@ -308,8 +308,8 @@ just_kill_connection:
|
|||
|
||||
LWS_VISIBLE int
|
||||
libwebsockets_get_addresses(struct libwebsocket_context *context,
|
||||
void *ads, char *name, int name_len,
|
||||
char *rip, int rip_len)
|
||||
void *ads, char *name, int name_len,
|
||||
char *rip, int rip_len)
|
||||
{
|
||||
struct addrinfo ai, *res;
|
||||
void *p = NULL;
|
||||
|
@ -511,7 +511,7 @@ libwebsocket_get_socket_fd(struct libwebsocket *wsi)
|
|||
#ifdef LWS_LATENCY
|
||||
void
|
||||
lws_latency(struct libwebsocket_context *context, struct libwebsocket *wsi,
|
||||
const char *action, int ret, int completed)
|
||||
const char *action, int ret, int completed)
|
||||
{
|
||||
unsigned long long u;
|
||||
char buf[256];
|
||||
|
@ -529,17 +529,17 @@ lws_latency(struct libwebsocket_context *context, struct libwebsocket *wsi,
|
|||
sprintf(buf,
|
||||
"Completion first try lat %lluus: %p: ret %d: %s\n",
|
||||
u - wsi->latency_start,
|
||||
(void *)wsi, ret, action);
|
||||
(void *)wsi, ret, action);
|
||||
else
|
||||
sprintf(buf,
|
||||
"Completion %lluus: lat %lluus: %p: ret %d: %s\n",
|
||||
u - wsi->action_start,
|
||||
u - wsi->latency_start,
|
||||
(void *)wsi, ret, action);
|
||||
(void *)wsi, ret, action);
|
||||
wsi->action_start = 0;
|
||||
} else
|
||||
sprintf(buf, "lat %lluus: %p: ret %d: %s\n",
|
||||
u - wsi->latency_start, (void *)wsi, ret, action);
|
||||
u - wsi->latency_start, (void *)wsi, ret, action);
|
||||
|
||||
if (u - wsi->latency_start > context->worst_latency) {
|
||||
context->worst_latency = u - wsi->latency_start;
|
||||
|
@ -780,7 +780,7 @@ LWS_VISIBLE void _lws_log(int filter, const char *format, ...)
|
|||
*/
|
||||
|
||||
LWS_VISIBLE void lws_set_log_level(int level, void (*log_emit_function)(int level,
|
||||
const char *line))
|
||||
const char *line))
|
||||
{
|
||||
log_level = level;
|
||||
if (log_emit_function)
|
||||
|
@ -829,8 +829,8 @@ lws_partial_buffered(struct libwebsocket *wsi)
|
|||
}
|
||||
|
||||
void lws_set_protocol_write_pending(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
enum lws_pending_protocol_send pend)
|
||||
struct libwebsocket *wsi,
|
||||
enum lws_pending_protocol_send pend)
|
||||
{
|
||||
lwsl_info("setting pps %d\n", pend);
|
||||
|
||||
|
|
|
@ -1027,8 +1027,8 @@ struct libwebsocket_extension {
|
|||
* setting of the private key directly via openSSL library calls
|
||||
* @ssl_ca_filepath: CA certificate filepath or NULL
|
||||
* @ssl_cipher_list: List of valid ciphers to use (eg,
|
||||
* "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL"
|
||||
* or you can leave it as NULL to get "DEFAULT"
|
||||
* "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL"
|
||||
* or you can leave it as NULL to get "DEFAULT"
|
||||
* @http_proxy_address: If non-NULL, attempts to proxy via the given address
|
||||
* @http_proxy_port: If http_proxy_address was non-NULL, uses this port at the address
|
||||
* @gid: group id to change to after setting listen socket, or -1.
|
||||
|
@ -1072,7 +1072,7 @@ struct lws_context_creation_info {
|
|||
#ifdef LWS_OPENSSL_SUPPORT
|
||||
SSL_CTX *provided_client_ssl_ctx;
|
||||
#else /* maintain structure layout either way */
|
||||
void *provided_client_ssl_ctx;
|
||||
void *provided_client_ssl_ctx;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -1103,36 +1103,36 @@ lws_token_to_string(enum lws_token_indexes token);
|
|||
|
||||
LWS_VISIBLE LWS_EXTERN int
|
||||
lws_add_http_header_by_name(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
const unsigned char *name,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
struct libwebsocket *wsi,
|
||||
const unsigned char *name,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
LWS_VISIBLE LWS_EXTERN int
|
||||
lws_finalize_http_header(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
struct libwebsocket *wsi,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
LWS_VISIBLE LWS_EXTERN int
|
||||
lws_add_http_header_by_token(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
enum lws_token_indexes token,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
struct libwebsocket *wsi,
|
||||
enum lws_token_indexes token,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
LWS_VISIBLE LWS_EXTERN int lws_add_http_header_content_length(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
unsigned long content_length,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
struct libwebsocket *wsi,
|
||||
unsigned long content_length,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
LWS_VISIBLE LWS_EXTERN int
|
||||
lws_add_http_header_status(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
unsigned int code,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
struct libwebsocket *wsi,
|
||||
unsigned int code,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
|
||||
LWS_EXTERN int lws_http_transaction_completed(struct libwebsocket *wsi);
|
||||
|
||||
|
@ -1188,7 +1188,7 @@ libwebsocket_set_timeout(struct libwebsocket *wsi,
|
|||
* memset(&buf[LWS_SEND_BUFFER_PRE_PADDING], 0, 128);
|
||||
*
|
||||
* libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], 128,
|
||||
* LWS_WRITE_TEXT);
|
||||
* LWS_WRITE_TEXT);
|
||||
*
|
||||
* When sending LWS_WRITE_HTTP, there is no protocol addition and you can just
|
||||
* use the whole buffer without taking care of the above.
|
||||
|
@ -1206,7 +1206,7 @@ libwebsocket_set_timeout(struct libwebsocket *wsi,
|
|||
|
||||
LWS_VISIBLE LWS_EXTERN int
|
||||
libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf, size_t len,
|
||||
enum libwebsocket_write_protocol protocol);
|
||||
enum libwebsocket_write_protocol protocol);
|
||||
|
||||
/* helper for case where buffer may be const */
|
||||
#define libwebsocket_write_http(wsi, buf, len) \
|
||||
|
@ -1231,7 +1231,7 @@ libwebsockets_get_protocol(struct libwebsocket *wsi);
|
|||
|
||||
LWS_VISIBLE LWS_EXTERN int
|
||||
libwebsocket_callback_on_writable(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi);
|
||||
struct libwebsocket *wsi);
|
||||
|
||||
LWS_VISIBLE LWS_EXTERN int
|
||||
libwebsocket_callback_on_writable_all_protocol(
|
||||
|
@ -1281,26 +1281,26 @@ lws_get_peer_write_allowance(struct libwebsocket *wsi);
|
|||
|
||||
LWS_VISIBLE LWS_EXTERN struct libwebsocket *
|
||||
libwebsocket_client_connect(struct libwebsocket_context *clients,
|
||||
const char *address,
|
||||
int port,
|
||||
int ssl_connection,
|
||||
const char *path,
|
||||
const char *host,
|
||||
const char *origin,
|
||||
const char *protocol,
|
||||
int ietf_version_or_minus_one);
|
||||
const char *address,
|
||||
int port,
|
||||
int ssl_connection,
|
||||
const char *path,
|
||||
const char *host,
|
||||
const char *origin,
|
||||
const char *protocol,
|
||||
int ietf_version_or_minus_one);
|
||||
|
||||
LWS_VISIBLE LWS_EXTERN struct libwebsocket *
|
||||
libwebsocket_client_connect_extended(struct libwebsocket_context *clients,
|
||||
const char *address,
|
||||
int port,
|
||||
int ssl_connection,
|
||||
const char *path,
|
||||
const char *host,
|
||||
const char *origin,
|
||||
const char *protocol,
|
||||
int ietf_version_or_minus_one,
|
||||
void *userdata);
|
||||
const char *address,
|
||||
int port,
|
||||
int ssl_connection,
|
||||
const char *path,
|
||||
const char *host,
|
||||
const char *origin,
|
||||
const char *protocol,
|
||||
int ietf_version_or_minus_one,
|
||||
void *userdata);
|
||||
|
||||
LWS_VISIBLE LWS_EXTERN const char *
|
||||
libwebsocket_canonical_hostname(struct libwebsocket_context *context);
|
||||
|
@ -1313,7 +1313,7 @@ libwebsockets_get_peer_addresses(struct libwebsocket_context *context,
|
|||
|
||||
LWS_VISIBLE LWS_EXTERN int
|
||||
libwebsockets_get_random(struct libwebsocket_context *context,
|
||||
void *buf, int len);
|
||||
void *buf, int len);
|
||||
|
||||
LWS_VISIBLE LWS_EXTERN int
|
||||
lws_daemonize(const char *_lock_path);
|
||||
|
@ -1359,7 +1359,7 @@ lws_hdr_copy(struct libwebsocket *wsi, char *dest, int len,
|
|||
LWS_VISIBLE LWS_EXTERN int
|
||||
libwebsocket_read(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
unsigned char *buf, size_t len);
|
||||
unsigned char *buf, size_t len);
|
||||
|
||||
#ifndef LWS_NO_EXTENSIONS
|
||||
LWS_VISIBLE LWS_EXTERN struct libwebsocket_extension *libwebsocket_get_internal_extensions();
|
||||
|
|
|
@ -15,7 +15,7 @@ unsigned long long time_in_microseconds(void)
|
|||
}
|
||||
|
||||
LWS_VISIBLE int libwebsockets_get_random(struct libwebsocket_context *context,
|
||||
void *buf, int len)
|
||||
void *buf, int len)
|
||||
{
|
||||
return read(context->fd_random, (char *)buf, len);
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ lws_plat_service(struct libwebsocket_context *context, int timeout_ms)
|
|||
lws_libev_run(context);
|
||||
|
||||
context->service_tid = context->protocols[0].callback(context, NULL,
|
||||
LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
|
||||
LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
|
||||
|
||||
#ifdef LWS_OPENSSL_SUPPORT
|
||||
/* if we know we have non-network pending data, do not wait in poll */
|
||||
|
@ -202,7 +202,7 @@ lws_plat_set_socket_options(struct libwebsocket_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 libwebsocket_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
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ lws_plat_init_fd_tables(struct libwebsocket_context *context)
|
|||
context->fd_random = open(SYSTEM_RANDOM_FILEPATH, O_RDONLY);
|
||||
if (context->fd_random < 0) {
|
||||
lwsl_err("Unable to open random device %s %d\n",
|
||||
SYSTEM_RANDOM_FILEPATH, context->fd_random);
|
||||
SYSTEM_RANDOM_FILEPATH, context->fd_random);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -373,13 +373,13 @@ interface_to_sa(struct libwebsocket_context *context,
|
|||
#endif
|
||||
memcpy(addr,
|
||||
(struct sockaddr_in *)ifc->ifa_addr,
|
||||
sizeof(struct sockaddr_in));
|
||||
sizeof(struct sockaddr_in));
|
||||
break;
|
||||
#ifdef LWS_USE_IPV6
|
||||
case AF_INET6:
|
||||
memcpy(&addr6->sin6_addr,
|
||||
&((struct sockaddr_in6 *)ifc->ifa_addr)->sin6_addr,
|
||||
sizeof(struct in6_addr));
|
||||
sizeof(struct in6_addr));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
|
@ -406,7 +406,7 @@ interface_to_sa(struct libwebsocket_context *context,
|
|||
|
||||
LWS_VISIBLE void
|
||||
lws_plat_insert_socket_into_fds(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi)
|
||||
struct libwebsocket *wsi)
|
||||
{
|
||||
lws_libev_io(context, wsi, LWS_EV_START | LWS_EV_READ);
|
||||
context->fds[context->fds_count++].revents = 0;
|
||||
|
@ -423,13 +423,13 @@ lws_plat_service_periodic(struct libwebsocket_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);
|
||||
}
|
||||
|
||||
LWS_VISIBLE int
|
||||
lws_plat_change_pollfd(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, struct libwebsocket_pollfd *pfd)
|
||||
struct libwebsocket *wsi, struct libwebsocket_pollfd *pfd)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ delete_from_fd(struct libwebsocket_context *context, int fd)
|
|||
if (context->fd_hashtable[h].wsi[n]->sock == fd) {
|
||||
while (n < context->fd_hashtable[h].length) {
|
||||
context->fd_hashtable[h].wsi[n] =
|
||||
context->fd_hashtable[h].wsi[n + 1];
|
||||
context->fd_hashtable[h].wsi[n + 1];
|
||||
n++;
|
||||
}
|
||||
context->fd_hashtable[h].length--;
|
||||
|
@ -87,7 +87,7 @@ delete_from_fd(struct libwebsocket_context *context, int fd)
|
|||
}
|
||||
|
||||
LWS_VISIBLE int libwebsockets_get_random(struct libwebsocket_context *context,
|
||||
void *buf, int len)
|
||||
void *buf, int len)
|
||||
{
|
||||
int n;
|
||||
char *p = (char *)buf;
|
||||
|
@ -149,7 +149,7 @@ lws_plat_service(struct libwebsocket_context *context, int timeout_ms)
|
|||
return 1;
|
||||
|
||||
context->service_tid = context->protocols[0].callback(context, NULL,
|
||||
LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
|
||||
LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
|
||||
|
||||
for (i = 0; i < context->fds_count; ++i) {
|
||||
pfd = &context->fds[i];
|
||||
|
@ -167,7 +167,7 @@ lws_plat_service(struct libwebsocket_context *context, int timeout_ms)
|
|||
}
|
||||
|
||||
ev = WSAWaitForMultipleEvents(context->fds_count + 1,
|
||||
context->events, FALSE, timeout_ms, FALSE);
|
||||
context->events, FALSE, timeout_ms, FALSE);
|
||||
context->service_tid = 0;
|
||||
|
||||
if (ev == WSA_WAIT_TIMEOUT) {
|
||||
|
@ -187,9 +187,9 @@ lws_plat_service(struct libwebsocket_context *context, int timeout_ms)
|
|||
|
||||
if (WSAEnumNetworkEvents(pfd->fd,
|
||||
context->events[ev - WSA_WAIT_EVENT_0],
|
||||
&networkevents) == SOCKET_ERROR) {
|
||||
&networkevents) == SOCKET_ERROR) {
|
||||
lwsl_err("WSAEnumNetworkEvents() failed with error %d\n",
|
||||
LWS_ERRNO);
|
||||
LWS_ERRNO);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ lws_plat_set_socket_options(struct libwebsocket_context *context, int fd)
|
|||
/* enable keepalive on this socket */
|
||||
optval = 1;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE,
|
||||
(const char *)&optval, optlen) < 0)
|
||||
(const char *)&optval, optlen) < 0)
|
||||
return 1;
|
||||
|
||||
alive.onoff = TRUE;
|
||||
|
@ -223,7 +223,7 @@ lws_plat_set_socket_options(struct libwebsocket_context *context, int fd)
|
|||
alive.keepaliveinterval = context->ka_interval;
|
||||
|
||||
if (WSAIoctl(fd, SIO_KEEPALIVE_VALS, &alive, sizeof(alive),
|
||||
NULL, 0, &dwBytesRet, NULL, NULL))
|
||||
NULL, 0, &dwBytesRet, NULL, NULL))
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -325,7 +325,7 @@ interface_to_sa(struct libwebsocket_context *context,
|
|||
|
||||
LWS_VISIBLE void
|
||||
lws_plat_insert_socket_into_fds(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi)
|
||||
struct libwebsocket *wsi)
|
||||
{
|
||||
context->fds[context->fds_count++].revents = 0;
|
||||
context->events[context->fds_count] = WSACreateEvent();
|
||||
|
@ -347,7 +347,7 @@ lws_plat_service_periodic(struct libwebsocket_context *context)
|
|||
|
||||
LWS_VISIBLE int
|
||||
lws_plat_change_pollfd(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, struct libwebsocket_pollfd *pfd)
|
||||
struct libwebsocket *wsi, struct libwebsocket_pollfd *pfd)
|
||||
{
|
||||
long networkevents = LWS_POLLOUT | LWS_POLLHUP;
|
||||
|
||||
|
@ -356,7 +356,7 @@ lws_plat_change_pollfd(struct libwebsocket_context *context,
|
|||
|
||||
if (WSAEventSelect(wsi->sock,
|
||||
context->events[wsi->position_in_fds_table + 1],
|
||||
networkevents) != SOCKET_ERROR)
|
||||
networkevents) != SOCKET_ERROR)
|
||||
return 0;
|
||||
|
||||
lwsl_err("WSAEventSelect() failed with error %d\n", LWS_ERRNO);
|
||||
|
|
|
@ -461,7 +461,7 @@ again:
|
|||
|
||||
fprintf(stdout, "/* total size %d bytes, biggest jump %d/256, fails=%d */\n};\n"
|
||||
"\n static unsigned char lextable_terms[] = {\n",
|
||||
pos, biggest, fails);
|
||||
pos, biggest, fails);
|
||||
|
||||
for (n = 0; n < (walk + 7) / 8; n++) {
|
||||
if (!(n & 7))
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
|
||||
/*
|
||||
* b7 = 0 = 1-byte seq
|
||||
* 0x08 = fail
|
||||
* 2-byte seq
|
||||
* 0x08 = fail
|
||||
* 2-byte seq
|
||||
* 0x00 - 0x07, then terminal as given in 2nd byte
|
||||
3-byte seq
|
||||
3-byte seq
|
||||
* no match: go fwd 3 byte, match: jump fwd by amt in +1/+2 bytes
|
||||
* = 1 = 1-byte seq
|
||||
* no match: die, match go fwd 1 byte
|
||||
|
@ -184,7 +184,7 @@ again:
|
|||
fprintf(stdout, " 0x%02X, 0x%02X "
|
||||
" "
|
||||
"/* - terminal marker %2d - */,\n",
|
||||
y >> 8, y & 0xff, y & 0x7f);
|
||||
y >> 8, y & 0xff, y & 0x7f);
|
||||
pos += 2;
|
||||
walk += 2;
|
||||
continue;
|
||||
|
|
66
lib/output.c
66
lib/output.c
|
@ -3,20 +3,20 @@
|
|||
*
|
||||
* Copyright (C) 2010-2014 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
|
||||
* License as published by the Free Software Foundation:
|
||||
* version 2.1 of the License.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation:
|
||||
* version 2.1 of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "private-libwebsockets.h"
|
||||
|
@ -32,7 +32,7 @@ libwebsocket_0405_frame_mask_generate(struct libwebsocket *wsi)
|
|||
wsi->u.ws.frame_masking_nonce_04, 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;
|
||||
}
|
||||
|
||||
|
@ -64,9 +64,9 @@ LWS_VISIBLE void lwsl_hexdump(void *vbuf, size_t len)
|
|||
for (m = 0; m < 16 && n < len; m++)
|
||||
p += sprintf(p, "%02X ", buf[n++]);
|
||||
while (m++ < 16)
|
||||
p += sprintf(p, " ");
|
||||
p += sprintf(p, " ");
|
||||
|
||||
p += sprintf(p, " ");
|
||||
p += sprintf(p, " ");
|
||||
|
||||
for (m = 0; m < 16 && (start + m) < len; m++) {
|
||||
if (buf[start + m] >= ' ' && buf[start + m] < 127)
|
||||
|
@ -147,7 +147,7 @@ handle_truncated_send:
|
|||
*/
|
||||
if (wsi->truncated_send_len) {
|
||||
lwsl_info("***** %x partial send moved on by %d (vs %d)\n",
|
||||
wsi, n, real_len);
|
||||
wsi, n, real_len);
|
||||
wsi->truncated_send_offset += n;
|
||||
wsi->truncated_send_len -= n;
|
||||
|
||||
|
@ -162,7 +162,7 @@ handle_truncated_send:
|
|||
}
|
||||
/* always callback on writeable */
|
||||
libwebsocket_callback_on_writable(
|
||||
wsi->protocol->owning_server, wsi);
|
||||
wsi->protocol->owning_server, wsi);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
@ -186,12 +186,12 @@ handle_truncated_send:
|
|||
* first priority next time the socket is writable)
|
||||
*/
|
||||
lwsl_info("***** %x new partial sent %d from %d total\n",
|
||||
wsi, n, real_len);
|
||||
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 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) {
|
||||
|
@ -235,7 +235,7 @@ handle_truncated_send:
|
|||
* for both http and websocket protocols.
|
||||
*
|
||||
* In the case of sending using websocket protocol, be sure to allocate
|
||||
* valid storage before and after buf as explained above. This scheme
|
||||
* valid storage before and after buf as explained above. This scheme
|
||||
* allows maximum efficiency of sending data and protocol in a single
|
||||
* packet while not burdening the user code with any protocol knowledge.
|
||||
*
|
||||
|
@ -258,14 +258,14 @@ LWS_VISIBLE int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf,
|
|||
struct lws_tokens eff_buf;
|
||||
|
||||
if (len == 0 && protocol != LWS_WRITE_CLOSE &&
|
||||
protocol != LWS_WRITE_PING && protocol != LWS_WRITE_PONG) {
|
||||
protocol != LWS_WRITE_PING && protocol != LWS_WRITE_PONG) {
|
||||
lwsl_warn("zero length libwebsocket_write attempt\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (protocol == LWS_WRITE_HTTP ||
|
||||
protocol == LWS_WRITE_HTTP_FINAL ||
|
||||
protocol == LWS_WRITE_HTTP_HEADERS)
|
||||
protocol == LWS_WRITE_HTTP_FINAL ||
|
||||
protocol == LWS_WRITE_HTTP_HEADERS)
|
||||
goto send_raw;
|
||||
|
||||
/* websocket protocol, either binary or text */
|
||||
|
@ -294,7 +294,7 @@ LWS_VISIBLE int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf,
|
|||
break;
|
||||
default:
|
||||
if (lws_ext_callback_for_each_active(wsi,
|
||||
LWS_EXT_CALLBACK_PAYLOAD_TX, &eff_buf, 0) < 0)
|
||||
LWS_EXT_CALLBACK_PAYLOAD_TX, &eff_buf, 0) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -466,7 +466,7 @@ send_raw:
|
|||
}
|
||||
#endif
|
||||
return lws_issue_raw(wsi, (unsigned char *)buf - pre,
|
||||
len + pre + post);
|
||||
len + pre + post);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -523,7 +523,7 @@ LWS_VISIBLE int libwebsockets_serve_http_file_fragment(
|
|||
if (wsi->truncated_send_len) {
|
||||
if (lws_issue_raw(wsi, wsi->truncated_send_malloc +
|
||||
wsi->truncated_send_offset,
|
||||
wsi->truncated_send_len) < 0) {
|
||||
wsi->truncated_send_len) < 0) {
|
||||
lwsl_info("closing from libwebsockets_serve_http_file_fragment\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -534,13 +534,13 @@ LWS_VISIBLE int libwebsockets_serve_http_file_fragment(
|
|||
goto all_sent;
|
||||
|
||||
compatible_file_read(n, wsi->u.http.fd, context->service_buffer,
|
||||
sizeof(context->service_buffer));
|
||||
sizeof(context->service_buffer));
|
||||
if (n < 0)
|
||||
return -1; /* caller will close */
|
||||
if (n) {
|
||||
wsi->u.http.filepos += n;
|
||||
m = libwebsocket_write(wsi, context->service_buffer, n,
|
||||
wsi->u.http.filepos == wsi->u.http.filelen ? LWS_WRITE_HTTP_FINAL : LWS_WRITE_HTTP);
|
||||
wsi->u.http.filepos == wsi->u.http.filelen ? LWS_WRITE_HTTP_FINAL : LWS_WRITE_HTTP);
|
||||
if (m < 0)
|
||||
return -1;
|
||||
|
||||
|
@ -572,7 +572,7 @@ all_sent:
|
|||
|
||||
LWS_VISIBLE int
|
||||
lws_ssl_capable_read_no_ssl(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, unsigned char *buf, int len)
|
||||
struct libwebsocket *wsi, unsigned char *buf, int len)
|
||||
{
|
||||
int n;
|
||||
|
||||
|
@ -594,8 +594,8 @@ lws_ssl_capable_write_no_ssl(struct libwebsocket *wsi, unsigned char *buf, int l
|
|||
return n;
|
||||
|
||||
if (LWS_ERRNO == LWS_EAGAIN ||
|
||||
LWS_ERRNO == LWS_EWOULDBLOCK ||
|
||||
LWS_ERRNO == LWS_EINTR) {
|
||||
LWS_ERRNO == LWS_EWOULDBLOCK ||
|
||||
LWS_ERRNO == LWS_EINTR) {
|
||||
if (LWS_ERRNO == LWS_EWOULDBLOCK)
|
||||
lws_set_blocking_send(wsi);
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ int lws_hdr_simple_create(struct libwebsocket *wsi,
|
|||
{
|
||||
wsi->u.hdr.ah->next_frag_index++;
|
||||
if (wsi->u.hdr.ah->next_frag_index ==
|
||||
sizeof(wsi->u.hdr.ah->frags) / sizeof(wsi->u.hdr.ah->frags[0])) {
|
||||
sizeof(wsi->u.hdr.ah->frags) / sizeof(wsi->u.hdr.ah->frags[0])) {
|
||||
lwsl_warn("More hdr frags than we can deal with, dropping\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -145,10 +145,10 @@ int lws_hdr_simple_create(struct libwebsocket *wsi,
|
|||
wsi->u.hdr.ah->frag_index[h] = wsi->u.hdr.ah->next_frag_index;
|
||||
|
||||
wsi->u.hdr.ah->frags[wsi->u.hdr.ah->next_frag_index].offset =
|
||||
wsi->u.hdr.ah->pos;
|
||||
wsi->u.hdr.ah->pos;
|
||||
wsi->u.hdr.ah->frags[wsi->u.hdr.ah->next_frag_index].len = 0;
|
||||
wsi->u.hdr.ah->frags[wsi->u.hdr.ah->next_frag_index].next_frag_index =
|
||||
0;
|
||||
0;
|
||||
|
||||
do {
|
||||
if (wsi->u.hdr.ah->pos == sizeof(wsi->u.hdr.ah->data)) {
|
||||
|
@ -220,7 +220,7 @@ int libwebsocket_parse(
|
|||
/* collect into malloc'd buffers */
|
||||
/* optional initial space swallow */
|
||||
if (!wsi->u.hdr.ah->frags[wsi->u.hdr.ah->frag_index[
|
||||
wsi->u.hdr.parser_state]].len && c == ' ')
|
||||
wsi->u.hdr.parser_state]].len && c == ' ')
|
||||
break;
|
||||
|
||||
for (m = 0; m < ARRAY_SIZE(methods); m++)
|
||||
|
@ -362,11 +362,11 @@ int libwebsocket_parse(
|
|||
wsi->u.hdr.ah->next_frag_index++;
|
||||
wsi->u.hdr.ah->frags[
|
||||
wsi->u.hdr.ah->next_frag_index].offset =
|
||||
wsi->u.hdr.ah->pos;
|
||||
wsi->u.hdr.ah->pos;
|
||||
wsi->u.hdr.ah->frags[
|
||||
wsi->u.hdr.ah->next_frag_index].len = 0;
|
||||
wsi->u.hdr.ah->frags[
|
||||
wsi->u.hdr.ah->next_frag_index].next_frag_index = 0;
|
||||
wsi->u.hdr.ah->next_frag_index].next_frag_index = 0;
|
||||
|
||||
wsi->u.hdr.ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS] =
|
||||
wsi->u.hdr.ah->next_frag_index;
|
||||
|
@ -409,7 +409,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 == LWS_CONNMODE_HTTP_SERVING) {
|
||||
/* this is not a header we know about */
|
||||
for (m = 0; m < ARRAY_SIZE(methods); m++)
|
||||
if (wsi->u.hdr.ah->frag_index[methods[m]]) {
|
||||
|
@ -481,16 +481,16 @@ start_fragment:
|
|||
wsi->u.hdr.ah->next_frag_index++;
|
||||
if (wsi->u.hdr.ah->next_frag_index ==
|
||||
sizeof(wsi->u.hdr.ah->frags) /
|
||||
sizeof(wsi->u.hdr.ah->frags[0])) {
|
||||
sizeof(wsi->u.hdr.ah->frags[0])) {
|
||||
lwsl_warn("More hdr frags than we can deal with\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
wsi->u.hdr.ah->frags[wsi->u.hdr.ah->next_frag_index].offset =
|
||||
wsi->u.hdr.ah->pos;
|
||||
wsi->u.hdr.ah->pos;
|
||||
wsi->u.hdr.ah->frags[wsi->u.hdr.ah->next_frag_index].len = 0;
|
||||
wsi->u.hdr.ah->frags[
|
||||
wsi->u.hdr.ah->next_frag_index].next_frag_index = 0;
|
||||
wsi->u.hdr.ah->next_frag_index].next_frag_index = 0;
|
||||
|
||||
n = wsi->u.hdr.ah->frag_index[wsi->u.hdr.parser_state];
|
||||
if (!n) { /* first fragment */
|
||||
|
@ -543,7 +543,7 @@ set_parsing_complete:
|
|||
if (lws_hdr_total_length(wsi, WSI_TOKEN_UPGRADE)) {
|
||||
if (lws_hdr_total_length(wsi, WSI_TOKEN_VERSION))
|
||||
wsi->ietf_spec_revision =
|
||||
atoi(lws_hdr_simple_ptr(wsi, WSI_TOKEN_VERSION));
|
||||
atoi(lws_hdr_simple_ptr(wsi, WSI_TOKEN_VERSION));
|
||||
|
||||
lwsl_parser("v%02d hdrs completed\n", wsi->ietf_spec_revision);
|
||||
}
|
||||
|
@ -588,7 +588,7 @@ libwebsocket_rx_sm(struct libwebsocket *wsi, unsigned char c)
|
|||
|
||||
default:
|
||||
lwsl_warn("lws_rx_sm: unknown spec version %d\n",
|
||||
wsi->ietf_spec_revision);
|
||||
wsi->ietf_spec_revision);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -660,7 +660,7 @@ handle_first:
|
|||
case LWS_WS_OPCODE_07__TEXT_FRAME:
|
||||
case LWS_WS_OPCODE_07__BINARY_FRAME:
|
||||
wsi->u.ws.frame_is_binary =
|
||||
wsi->u.ws.opcode == LWS_WS_OPCODE_07__BINARY_FRAME;
|
||||
wsi->u.ws.opcode == LWS_WS_OPCODE_07__BINARY_FRAME;
|
||||
break;
|
||||
}
|
||||
wsi->lws_rx_parse_state = LWS_RXPS_04_FRAME_HDR_LEN;
|
||||
|
@ -821,12 +821,12 @@ handle_first:
|
|||
|
||||
if (wsi->u.ws.all_zero_nonce)
|
||||
wsi->u.ws.rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING +
|
||||
(wsi->u.ws.rx_user_buffer_head++)] = c;
|
||||
(wsi->u.ws.rx_user_buffer_head++)] = c;
|
||||
else
|
||||
wsi->u.ws.rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING +
|
||||
(wsi->u.ws.rx_user_buffer_head++)] =
|
||||
(wsi->u.ws.rx_user_buffer_head++)] =
|
||||
c ^ wsi->u.ws.frame_masking_nonce_04[
|
||||
(wsi->u.ws.frame_mask_index++) & 3];
|
||||
(wsi->u.ws.frame_mask_index++) & 3];
|
||||
|
||||
if (--wsi->u.ws.rx_packet_length == 0) {
|
||||
/* spill because we have the whole frame */
|
||||
|
@ -840,8 +840,8 @@ handle_first:
|
|||
*/
|
||||
|
||||
if (!wsi->protocol->rx_buffer_size &&
|
||||
wsi->u.ws.rx_user_buffer_head !=
|
||||
LWS_MAX_SOCKET_IO_BUF)
|
||||
wsi->u.ws.rx_user_buffer_head !=
|
||||
LWS_MAX_SOCKET_IO_BUF)
|
||||
break;
|
||||
else
|
||||
if (wsi->protocol->rx_buffer_size &&
|
||||
|
@ -900,7 +900,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) {
|
||||
wsi->u.ws.ping_payload_alloc < wsi->u.ws.rx_user_buffer_head) {
|
||||
lws_free2(wsi->u.ws.ping_payload_buf);
|
||||
}
|
||||
|
||||
|
@ -913,7 +913,7 @@ process_as_ping:
|
|||
|
||||
/* stash the pong payload */
|
||||
memcpy(wsi->u.ws.ping_payload_buf + LWS_SEND_BUFFER_PRE_PADDING,
|
||||
&wsi->u.ws.rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
|
||||
&wsi->u.ws.rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
|
||||
wsi->u.ws.rx_user_buffer_head);
|
||||
|
||||
wsi->u.ws.ping_payload_len = wsi->u.ws.rx_user_buffer_head;
|
||||
|
@ -952,7 +952,7 @@ ping_drop:
|
|||
LWS_EXT_CALLBACK_EXTENDED_PAYLOAD_RX,
|
||||
&eff_buf, 0) <= 0) /* not handle or fail */
|
||||
lwsl_ext("ext opc opcode 0x%x unknown\n",
|
||||
wsi->u.ws.opcode);
|
||||
wsi->u.ws.opcode);
|
||||
|
||||
wsi->u.ws.rx_user_buffer_head = 0;
|
||||
return 0;
|
||||
|
@ -983,8 +983,8 @@ ping_drop:
|
|||
wsi->user_space,
|
||||
eff_buf.token,
|
||||
eff_buf.token_len);
|
||||
else
|
||||
lwsl_err("No callback on payload spill!\n");
|
||||
else
|
||||
lwsl_err("No callback on payload spill!\n");
|
||||
}
|
||||
|
||||
wsi->u.ws.rx_user_buffer_head = 0;
|
||||
|
@ -1003,7 +1003,7 @@ illegal_ctl_length:
|
|||
|
||||
/**
|
||||
* libwebsockets_remaining_packet_payload() - Bytes to come before "overall"
|
||||
* rx packet is complete
|
||||
* rx packet is complete
|
||||
* @wsi: Websocket instance (available from user callback)
|
||||
*
|
||||
* This function is intended to be called from the callback if the
|
||||
|
|
20
lib/pollfd.c
20
lib/pollfd.c
|
@ -23,7 +23,7 @@
|
|||
|
||||
int
|
||||
insert_wsi_socket_into_fds(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi)
|
||||
struct libwebsocket *wsi)
|
||||
{
|
||||
struct libwebsocket_pollargs pa = { wsi->sock, LWS_POLLIN, 0 };
|
||||
|
||||
|
@ -44,7 +44,7 @@ insert_wsi_socket_into_fds(struct libwebsocket_context *context,
|
|||
assert(wsi->sock >= 0);
|
||||
|
||||
lwsl_info("insert_wsi_socket_into_fds: wsi=%p, sock=%d, fds pos=%d\n",
|
||||
wsi, wsi->sock, context->fds_count);
|
||||
wsi, wsi->sock, context->fds_count);
|
||||
|
||||
context->protocols[0].callback(context, wsi,
|
||||
LWS_CALLBACK_LOCK_POLL,
|
||||
|
@ -71,7 +71,7 @@ insert_wsi_socket_into_fds(struct libwebsocket_context *context,
|
|||
|
||||
int
|
||||
remove_wsi_socket_from_fds(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi)
|
||||
struct libwebsocket *wsi)
|
||||
{
|
||||
int m;
|
||||
struct libwebsocket_pollargs pa = { wsi->sock, 0, 0 };
|
||||
|
@ -87,7 +87,7 @@ remove_wsi_socket_from_fds(struct libwebsocket_context *context,
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
context->protocols[0].callback(context, wsi,
|
||||
LWS_CALLBACK_LOCK_POLL,
|
||||
|
@ -115,12 +115,12 @@ remove_wsi_socket_from_fds(struct libwebsocket_context *context,
|
|||
/* remove also from external POLL support via protocol 0 */
|
||||
if (wsi->sock) {
|
||||
context->protocols[0].callback(context, wsi,
|
||||
LWS_CALLBACK_DEL_POLL_FD, wsi->user_space,
|
||||
(void *) &pa, 0);
|
||||
LWS_CALLBACK_DEL_POLL_FD, wsi->user_space,
|
||||
(void *) &pa, 0);
|
||||
}
|
||||
context->protocols[0].callback(context, wsi,
|
||||
LWS_CALLBACK_UNLOCK_POLL,
|
||||
wsi->user_space, (void *) &pa, 0);
|
||||
LWS_CALLBACK_UNLOCK_POLL,
|
||||
wsi->user_space, (void *) &pa, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ lws_change_pollfd(struct libwebsocket *wsi, int _and, int _or)
|
|||
sampled_tid = context->service_tid;
|
||||
if (sampled_tid) {
|
||||
tid = context->protocols[0].callback(context, NULL,
|
||||
LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
|
||||
LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
|
||||
if (tid != sampled_tid)
|
||||
libwebsocket_cancel_service(context);
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ lws_change_pollfd(struct libwebsocket *wsi, int _and, int _or)
|
|||
|
||||
LWS_VISIBLE int
|
||||
libwebsocket_callback_on_writable(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi)
|
||||
struct libwebsocket *wsi)
|
||||
{
|
||||
#ifdef LWS_USE_HTTP2
|
||||
struct libwebsocket *network_wsi, *wsi2;
|
||||
|
|
|
@ -3,20 +3,20 @@
|
|||
*
|
||||
* Copyright (C) 2010 - 2013 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
|
||||
* License as published by the Free Software Foundation:
|
||||
* version 2.1 of the License.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation:
|
||||
* version 2.1 of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "lws_config.h"
|
||||
|
@ -166,7 +166,7 @@
|
|||
#if defined(WIN32) || defined(_WIN32)
|
||||
|
||||
#ifndef BIG_ENDIAN
|
||||
#define BIG_ENDIAN 4321 /* to show byte order (taken from gcc) */
|
||||
#define BIG_ENDIAN 4321 /* to show byte order (taken from gcc) */
|
||||
#endif
|
||||
#ifndef LITTLE_ENDIAN
|
||||
#define LITTLE_ENDIAN 1234
|
||||
|
@ -214,7 +214,7 @@ typedef unsigned __int64 u_int64_t;
|
|||
#endif
|
||||
#if defined(__BIGENDIAN__)
|
||||
#define BYTE_ORDER __BIGENDIAN__
|
||||
#define LITTLE_ENDIAN 1234 /* to show byte order (taken from gcc); for suppres warning that LITTLE_ENDIAN is not defined. */
|
||||
#define LITTLE_ENDIAN 1234 /* to show byte order (taken from gcc); for suppres warning that LITTLE_ENDIAN is not defined. */
|
||||
#define BIG_ENDIAN __BIGENDIAN__
|
||||
#endif
|
||||
#endif
|
||||
|
@ -492,7 +492,7 @@ struct libwebsocket_context {
|
|||
#ifndef LWS_NO_EXTENSIONS
|
||||
struct libwebsocket_extension *extensions;
|
||||
#endif
|
||||
struct lws_token_limits *token_limits;
|
||||
struct lws_token_limits *token_limits;
|
||||
void *user_space;
|
||||
};
|
||||
|
||||
|
@ -560,9 +560,9 @@ struct lws_fragments {
|
|||
|
||||
/* notice that these union members:
|
||||
*
|
||||
* hdr
|
||||
* http
|
||||
* http2
|
||||
* hdr
|
||||
* http
|
||||
* http2
|
||||
*
|
||||
* all have a pointer to allocated_headers struct as their first member.
|
||||
*
|
||||
|
@ -584,7 +584,7 @@ struct allocated_headers {
|
|||
|
||||
struct _lws_http_mode_related {
|
||||
/* MUST be first in struct */
|
||||
struct allocated_headers *ah; /* mirroring _lws_header_related */
|
||||
struct allocated_headers *ah; /* mirroring _lws_header_related */
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
HANDLE fd;
|
||||
#else
|
||||
|
@ -793,8 +793,8 @@ struct libwebsocket {
|
|||
/* lifetime members */
|
||||
|
||||
#ifdef LWS_USE_LIBEV
|
||||
struct lws_io_watcher w_read;
|
||||
struct lws_io_watcher w_write;
|
||||
struct lws_io_watcher w_read;
|
||||
struct lws_io_watcher w_write;
|
||||
#endif /* LWS_USE_LIBEV */
|
||||
const struct libwebsocket_protocols *protocol;
|
||||
#ifndef LWS_NO_EXTENSIONS
|
||||
|
@ -866,11 +866,11 @@ LWS_EXTERN int log_level;
|
|||
|
||||
LWS_EXTERN void
|
||||
libwebsocket_close_and_free_session(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, enum lws_close_status);
|
||||
struct libwebsocket *wsi, enum lws_close_status);
|
||||
|
||||
LWS_EXTERN int
|
||||
remove_wsi_socket_from_fds(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi);
|
||||
struct libwebsocket *wsi);
|
||||
LWS_EXTERN int
|
||||
lws_rxflow_cache(struct libwebsocket *wsi, unsigned char *buf, int n, int len);
|
||||
|
||||
|
@ -885,12 +885,12 @@ static inline void lws_latency_pre(struct libwebsocket_context *context,
|
|||
extern void
|
||||
lws_latency(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, const char *action,
|
||||
int ret, int completion);
|
||||
int ret, int completion);
|
||||
#endif
|
||||
|
||||
LWS_EXTERN void lws_set_protocol_write_pending(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
enum lws_pending_protocol_send pend);
|
||||
struct libwebsocket *wsi,
|
||||
enum lws_pending_protocol_send pend);
|
||||
LWS_EXTERN int
|
||||
libwebsocket_client_rx_sm(struct libwebsocket *wsi, unsigned char c);
|
||||
|
||||
|
@ -921,7 +921,7 @@ delete_from_fd(struct libwebsocket_context *context, int fd);
|
|||
|
||||
LWS_EXTERN int
|
||||
insert_wsi_socket_into_fds(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi);
|
||||
struct libwebsocket *wsi);
|
||||
|
||||
LWS_EXTERN int
|
||||
lws_issue_raw(struct libwebsocket *wsi, unsigned char *buf, size_t len);
|
||||
|
@ -929,7 +929,7 @@ lws_issue_raw(struct libwebsocket *wsi, unsigned char *buf, size_t len);
|
|||
|
||||
LWS_EXTERN int
|
||||
libwebsocket_service_timeout_check(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, unsigned int sec);
|
||||
struct libwebsocket *wsi, unsigned int sec);
|
||||
|
||||
LWS_EXTERN struct libwebsocket *
|
||||
libwebsocket_client_connect_2(struct libwebsocket_context *context,
|
||||
|
@ -944,7 +944,7 @@ libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
|
|||
|
||||
LWS_EXTERN int
|
||||
lws_handle_POLLOUT_event(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd);
|
||||
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd);
|
||||
|
||||
/*
|
||||
* EXTENSIONS
|
||||
|
@ -953,7 +953,7 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context,
|
|||
#ifndef LWS_NO_EXTENSIONS
|
||||
LWS_VISIBLE void
|
||||
lws_context_init_extensions(struct lws_context_creation_info *info,
|
||||
struct libwebsocket_context *context);
|
||||
struct libwebsocket_context *context);
|
||||
LWS_EXTERN int
|
||||
lws_any_extension_handled(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
|
@ -962,7 +962,7 @@ lws_any_extension_handled(struct libwebsocket_context *context,
|
|||
|
||||
LWS_EXTERN int
|
||||
lws_ext_callback_for_each_active(struct libwebsocket *wsi, int reason,
|
||||
void *buf, int len);
|
||||
void *buf, int len);
|
||||
LWS_EXTERN int
|
||||
lws_ext_callback_for_each_extension_type(
|
||||
struct libwebsocket_context *context, struct libwebsocket *wsi,
|
||||
|
@ -1006,7 +1006,7 @@ lws_http2_interpret_settings_payload(struct http2_settings *settings, unsigned c
|
|||
LWS_EXTERN void lws_http2_init(struct http2_settings *settings);
|
||||
LWS_EXTERN int
|
||||
lws_http2_parser(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, unsigned char c);
|
||||
struct libwebsocket *wsi, unsigned char c);
|
||||
LWS_EXTERN int lws_http2_do_pps_send(struct libwebsocket_context *context, struct libwebsocket *wsi);
|
||||
LWS_EXTERN int lws_http2_frame_write(struct libwebsocket *wsi, int type, int flags, unsigned int sid, unsigned int len, unsigned char *buf);
|
||||
LWS_EXTERN struct libwebsocket *
|
||||
|
@ -1016,26 +1016,26 @@ LWS_EXTERN int lws_hpack_interpret(struct libwebsocket_context *context,
|
|||
unsigned char c);
|
||||
LWS_EXTERN int
|
||||
lws_add_http2_header_by_name(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
const unsigned char *name,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
struct libwebsocket *wsi,
|
||||
const unsigned char *name,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
LWS_EXTERN int
|
||||
lws_add_http2_header_by_token(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
enum lws_token_indexes token,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
struct libwebsocket *wsi,
|
||||
enum lws_token_indexes token,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
LWS_EXTERN int
|
||||
lws_add_http2_header_status(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi,
|
||||
unsigned int code,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
struct libwebsocket *wsi,
|
||||
unsigned int code,
|
||||
unsigned char **p,
|
||||
unsigned char *end);
|
||||
LWS_EXTERN
|
||||
void lws_http2_configure_if_upgraded(struct libwebsocket *wsi);
|
||||
#else
|
||||
|
@ -1066,9 +1066,9 @@ lws_change_pollfd(struct libwebsocket *wsi, int _and, int _or);
|
|||
|
||||
#ifndef LWS_NO_SERVER
|
||||
int lws_context_init_server(struct lws_context_creation_info *info,
|
||||
struct libwebsocket_context *context);
|
||||
struct libwebsocket_context *context);
|
||||
LWS_EXTERN int handshake_0405(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi);
|
||||
struct libwebsocket *wsi);
|
||||
LWS_EXTERN int
|
||||
libwebsocket_interpret_incoming_packet(struct libwebsocket *wsi,
|
||||
unsigned char *buf, size_t len);
|
||||
|
@ -1119,7 +1119,7 @@ enum lws_ssl_capable_status {
|
|||
LWS_EXTERN int openssl_websocket_private_data_index;
|
||||
LWS_EXTERN int
|
||||
lws_ssl_capable_read(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, unsigned char *buf, int len);
|
||||
struct libwebsocket *wsi, unsigned char *buf, int len);
|
||||
|
||||
LWS_EXTERN int
|
||||
lws_ssl_capable_write(struct libwebsocket *wsi, unsigned char *buf, int len);
|
||||
|
@ -1133,11 +1133,11 @@ LWS_EXTERN void
|
|||
lws_ssl_context_destroy(struct libwebsocket_context *context);
|
||||
LWS_VISIBLE void
|
||||
lws_ssl_remove_wsi_from_buffered_list(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi);
|
||||
struct libwebsocket *wsi);
|
||||
#ifndef LWS_NO_SERVER
|
||||
LWS_EXTERN int
|
||||
lws_context_init_server_ssl(struct lws_context_creation_info *info,
|
||||
struct libwebsocket_context *context);
|
||||
struct libwebsocket_context *context);
|
||||
#else
|
||||
#define lws_context_init_server_ssl(_a, _b) (0)
|
||||
#endif
|
||||
|
@ -1156,7 +1156,7 @@ lws_context_init_http2_ssl(struct libwebsocket_context *context);
|
|||
|
||||
LWS_EXTERN int
|
||||
lws_ssl_capable_read_no_ssl(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, unsigned char *buf, int len);
|
||||
struct libwebsocket *wsi, unsigned char *buf, int len);
|
||||
|
||||
LWS_EXTERN int
|
||||
lws_ssl_capable_write_no_ssl(struct libwebsocket *wsi, unsigned char *buf, int len);
|
||||
|
@ -1167,7 +1167,7 @@ lws_ssl_capable_write_no_ssl(struct libwebsocket *wsi, unsigned char *buf, int l
|
|||
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd);
|
||||
#ifdef LWS_OPENSSL_SUPPORT
|
||||
LWS_EXTERN int lws_context_init_client_ssl(struct lws_context_creation_info *info,
|
||||
struct libwebsocket_context *context);
|
||||
struct libwebsocket_context *context);
|
||||
#else
|
||||
#define lws_context_init_client_ssl(_a, _b) (0)
|
||||
#endif
|
||||
|
@ -1184,7 +1184,7 @@ lws_ssl_capable_write_no_ssl(struct libwebsocket *wsi, unsigned char *buf, int l
|
|||
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd);
|
||||
LWS_EXTERN int _libwebsocket_rx_flow_control(struct libwebsocket *wsi);
|
||||
LWS_EXTERN int lws_handshake_server(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, unsigned char **buf, size_t len);
|
||||
struct libwebsocket *wsi, unsigned char **buf, size_t len);
|
||||
#else
|
||||
#define lws_server_socket_service(_a, _b, _c) (0)
|
||||
#define _libwebsocket_rx_flow_control(_a) (0)
|
||||
|
@ -1192,8 +1192,8 @@ lws_ssl_capable_write_no_ssl(struct libwebsocket *wsi, unsigned char *buf, int l
|
|||
#endif
|
||||
|
||||
LWS_EXTERN int libwebsockets_get_addresses(struct libwebsocket_context *context,
|
||||
void *ads, char *name, int name_len,
|
||||
char *rip, int rip_len);
|
||||
void *ads, char *name, int name_len,
|
||||
char *rip, int rip_len);
|
||||
|
||||
/*
|
||||
* custom allocator
|
||||
|
@ -1213,16 +1213,16 @@ lws_zalloc(size_t size);
|
|||
*/
|
||||
LWS_EXTERN void
|
||||
lws_plat_delete_socket_from_fds(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, int m);
|
||||
struct libwebsocket *wsi, int m);
|
||||
LWS_EXTERN void
|
||||
lws_plat_insert_socket_into_fds(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi);
|
||||
struct libwebsocket *wsi);
|
||||
LWS_EXTERN void
|
||||
lws_plat_service_periodic(struct libwebsocket_context *context);
|
||||
|
||||
LWS_EXTERN int
|
||||
lws_plat_change_pollfd(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, struct libwebsocket_pollfd *pfd);
|
||||
struct libwebsocket *wsi, struct libwebsocket_pollfd *pfd);
|
||||
LWS_EXTERN int
|
||||
lws_plat_context_early_init(void);
|
||||
LWS_EXTERN void
|
||||
|
|
|
@ -49,7 +49,7 @@ lws_extension_server_handshake(struct libwebsocket_context *context,
|
|||
|
||||
if (lws_hdr_copy(wsi, (char *)context->service_buffer,
|
||||
sizeof(context->service_buffer),
|
||||
WSI_TOKEN_EXTENSIONS) < 0)
|
||||
WSI_TOKEN_EXTENSIONS) < 0)
|
||||
return 1;
|
||||
|
||||
c = (char *)context->service_buffer;
|
||||
|
@ -124,9 +124,9 @@ lws_extension_server_handshake(struct libwebsocket_context *context,
|
|||
|
||||
wsi->active_extensions_user[
|
||||
wsi->count_active_extensions] =
|
||||
lws_zalloc(ext->per_session_data_size);
|
||||
lws_zalloc(ext->per_session_data_size);
|
||||
if (wsi->active_extensions_user[
|
||||
wsi->count_active_extensions] == NULL) {
|
||||
wsi->count_active_extensions] == NULL) {
|
||||
lwsl_err("Out of mem\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi)
|
|||
}
|
||||
|
||||
if (lws_hdr_total_length(wsi, WSI_TOKEN_KEY) >=
|
||||
MAX_WEBSOCKET_04_KEY_LEN) {
|
||||
MAX_WEBSOCKET_04_KEY_LEN) {
|
||||
lwsl_warn("Client key too long %d\n", MAX_WEBSOCKET_04_KEY_LEN);
|
||||
goto bail;
|
||||
}
|
||||
|
@ -206,9 +206,9 @@ handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi)
|
|||
response = (char *)context->service_buffer + 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: ");
|
||||
"Upgrade: WebSocket\x0d\x0a"
|
||||
"Connection: Upgrade\x0d\x0a"
|
||||
"Sec-WebSocket-Accept: ");
|
||||
strcpy(p, (char *)context->service_buffer);
|
||||
p += accept_len;
|
||||
|
||||
|
@ -237,7 +237,7 @@ handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi)
|
|||
|
||||
if (!lws_any_extension_handled(context, wsi,
|
||||
LWS_EXT_CALLBACK_HANDSHAKE_REPLY_TX,
|
||||
response, p - response)) {
|
||||
response, p - response)) {
|
||||
|
||||
/* okay send the handshake response accepting the connection */
|
||||
|
||||
|
|
46
lib/server.c
46
lib/server.c
|
@ -23,7 +23,7 @@
|
|||
#include "private-libwebsockets.h"
|
||||
|
||||
int lws_context_init_server(struct lws_context_creation_info *info,
|
||||
struct libwebsocket_context *context)
|
||||
struct libwebsocket_context *context)
|
||||
{
|
||||
int n;
|
||||
int sockfd;
|
||||
|
@ -58,7 +58,7 @@ int lws_context_init_server(struct lws_context_creation_info *info,
|
|||
* allow us to restart even if old sockets in TIME_WAIT
|
||||
*/
|
||||
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
|
||||
(const void *)&opt, sizeof(opt)) < 0) {
|
||||
(const void *)&opt, sizeof(opt)) < 0) {
|
||||
compatible_close(sockfd);
|
||||
return 1;
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ int lws_context_init_server(struct lws_context_creation_info *info,
|
|||
n = bind(sockfd, v, n);
|
||||
if (n < 0) {
|
||||
lwsl_err("ERROR on binding to port %d (%d %d)\n",
|
||||
info->port, n, LWS_ERRNO);
|
||||
info->port, n, LWS_ERRNO);
|
||||
compatible_close(sockfd);
|
||||
return 1;
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ _libwebsocket_rx_flow_control(struct libwebsocket *wsi)
|
|||
wsi->rxflow_change_to &= ~LWS_RXFLOW_PENDING_CHANGE;
|
||||
|
||||
lwsl_info("rxflow: wsi %p change_to %d\n", wsi,
|
||||
wsi->rxflow_change_to & LWS_RXFLOW_ALLOW);
|
||||
wsi->rxflow_change_to & LWS_RXFLOW_ALLOW);
|
||||
|
||||
/* adjust the pollfd for this wsi */
|
||||
|
||||
|
@ -169,7 +169,7 @@ _libwebsocket_rx_flow_control(struct libwebsocket *wsi)
|
|||
}
|
||||
|
||||
int lws_http_action(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi)
|
||||
struct libwebsocket *wsi)
|
||||
{
|
||||
char *uri_ptr = NULL;
|
||||
int uri_len = 0;
|
||||
|
@ -223,7 +223,7 @@ int lws_http_action(struct libwebsocket_context *context,
|
|||
uri_ptr = lws_hdr_simple_ptr(wsi, methods[n]);
|
||||
uri_len = lws_hdr_total_length(wsi, methods[n]);
|
||||
lwsl_info("Method: %s request for '%s'\n",
|
||||
method_names[n], uri_ptr);
|
||||
method_names[n], uri_ptr);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -264,7 +264,7 @@ int lws_http_action(struct libwebsocket_context *context,
|
|||
/* Override default if http "Connection:" header: */
|
||||
if (lws_hdr_total_length(wsi, WSI_TOKEN_CONNECTION)) {
|
||||
lws_hdr_copy(wsi, http_conn_str, sizeof(http_conn_str) - 1,
|
||||
WSI_TOKEN_CONNECTION);
|
||||
WSI_TOKEN_CONNECTION);
|
||||
http_conn_str[sizeof(http_conn_str) - 1] = '\0';
|
||||
if (!strcasecmp(http_conn_str, "keep-alive"))
|
||||
connection_type = HTTP_CONNECTION_KEEP_ALIVE;
|
||||
|
@ -278,7 +278,7 @@ int lws_http_action(struct libwebsocket_context *context,
|
|||
if (wsi->protocol->callback)
|
||||
n = wsi->protocol->callback(context, wsi,
|
||||
LWS_CALLBACK_FILTER_HTTP_CONNECTION,
|
||||
wsi->user_space, uri_ptr, uri_len);
|
||||
wsi->user_space, uri_ptr, uri_len);
|
||||
|
||||
if (!n) {
|
||||
/*
|
||||
|
@ -286,12 +286,12 @@ int lws_http_action(struct libwebsocket_context *context,
|
|||
* put a timeout on it having arrived
|
||||
*/
|
||||
libwebsocket_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT,
|
||||
AWAITING_TIMEOUT);
|
||||
AWAITING_TIMEOUT);
|
||||
|
||||
if (wsi->protocol->callback)
|
||||
n = wsi->protocol->callback(context, wsi,
|
||||
LWS_CALLBACK_HTTP,
|
||||
wsi->user_space, uri_ptr, uri_len);
|
||||
LWS_CALLBACK_HTTP,
|
||||
wsi->user_space, uri_ptr, uri_len);
|
||||
}
|
||||
|
||||
/* now drop the header info we kept a pointer to */
|
||||
|
@ -353,7 +353,7 @@ int lws_handshake_server(struct libwebsocket_context *context,
|
|||
/* 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;
|
||||
|
||||
|
@ -414,9 +414,9 @@ upgrade_h2c:
|
|||
lws_http2_interpret_settings_payload(&wsi->u.http2.peer_settings, (unsigned char *)protocol_list, n);
|
||||
|
||||
strcpy(protocol_list,
|
||||
"HTTP/1.1 101 Switching Protocols\x0d\x0a"
|
||||
"Connection: Upgrade\x0d\x0a"
|
||||
"Upgrade: h2c\x0d\x0a\x0d\x0a");
|
||||
"HTTP/1.1 101 Switching Protocols\x0d\x0a"
|
||||
"Connection: Upgrade\x0d\x0a"
|
||||
"Upgrade: h2c\x0d\x0a\x0d\x0a");
|
||||
n = lws_issue_raw(wsi, (unsigned char *)protocol_list,
|
||||
strlen(protocol_list));
|
||||
if (n != strlen(protocol_list)) {
|
||||
|
@ -470,7 +470,7 @@ upgrade_ws:
|
|||
continue;
|
||||
}
|
||||
if (!strcmp(context->protocols[n].name,
|
||||
protocol_name)) {
|
||||
protocol_name)) {
|
||||
lwsl_info("prot match %d\n", n);
|
||||
wsi->protocol = &context->protocols[n];
|
||||
hit = 1;
|
||||
|
@ -512,7 +512,7 @@ upgrade_ws:
|
|||
if ((wsi->protocol->callback)(wsi->protocol->owning_server, wsi,
|
||||
LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION,
|
||||
wsi->user_space,
|
||||
lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL), 0)) {
|
||||
lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL), 0)) {
|
||||
lwsl_warn("User code denied connection\n");
|
||||
goto bail_nuke_ah;
|
||||
}
|
||||
|
@ -534,7 +534,7 @@ upgrade_ws:
|
|||
|
||||
default:
|
||||
lwsl_warn("Unknown client spec version %d\n",
|
||||
wsi->ietf_spec_revision);
|
||||
wsi->ietf_spec_revision);
|
||||
goto bail_nuke_ah;
|
||||
}
|
||||
|
||||
|
@ -566,7 +566,7 @@ upgrade_ws:
|
|||
}
|
||||
|
||||
lwsl_parser("accepted v%02d connection\n",
|
||||
wsi->ietf_spec_revision);
|
||||
wsi->ietf_spec_revision);
|
||||
} /* while all chars are handled */
|
||||
|
||||
return 0;
|
||||
|
@ -693,7 +693,7 @@ int lws_server_socket_service(struct libwebsocket_context *context,
|
|||
if (pollfd->revents & LWS_POLLIN) {
|
||||
len = lws_ssl_capable_read(context, wsi,
|
||||
context->service_buffer,
|
||||
sizeof(context->service_buffer));
|
||||
sizeof(context->service_buffer));
|
||||
switch (len) {
|
||||
case 0:
|
||||
lwsl_info("lws_server_skt_srv: read 0 len\n");
|
||||
|
@ -768,10 +768,10 @@ try_pollout:
|
|||
clilen = sizeof(cli_addr);
|
||||
lws_latency_pre(context, wsi);
|
||||
accept_fd = accept(pollfd->fd, (struct sockaddr *)&cli_addr,
|
||||
&clilen);
|
||||
&clilen);
|
||||
lws_latency(context, wsi,
|
||||
"unencrypted accept LWS_CONNMODE_SERVER_LISTENER",
|
||||
accept_fd, accept_fd >= 0);
|
||||
accept_fd, accept_fd >= 0);
|
||||
if (accept_fd < 0) {
|
||||
if (LWS_ERRNO == LWS_EAGAIN || LWS_ERRNO == LWS_EWOULDBLOCK) {
|
||||
lwsl_debug("accept asks to try again\n");
|
||||
|
@ -963,7 +963,7 @@ lws_server_get_canonical_hostname(struct libwebsocket_context *context,
|
|||
|
||||
/* find canonical hostname */
|
||||
gethostname((char *)context->canonical_hostname,
|
||||
sizeof(context->canonical_hostname) - 1);
|
||||
sizeof(context->canonical_hostname) - 1);
|
||||
|
||||
lwsl_notice(" canonical_hostname = %s\n", context->canonical_hostname);
|
||||
}
|
||||
|
|
|
@ -3,20 +3,20 @@
|
|||
*
|
||||
* Copyright (C) 2010-2014 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
|
||||
* License as published by the Free Software Foundation:
|
||||
* version 2.1 of the License.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation:
|
||||
* version 2.1 of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "private-libwebsockets.h"
|
||||
|
@ -41,7 +41,7 @@ lws_calllback_as_writeable(struct libwebsocket_context *context,
|
|||
lwsl_info("%s: %p (user=%p)\n", __func__, wsi, wsi->user_space);
|
||||
return user_callback_handle_rxflow(wsi->protocol->callback, context,
|
||||
wsi, (enum libwebsocket_callback_reasons) n,
|
||||
wsi->user_space, NULL, 0);
|
||||
wsi->user_space, NULL, 0);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -93,12 +93,12 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context,
|
|||
/* pending control packets have next priority */
|
||||
|
||||
if (wsi->state == WSI_STATE_ESTABLISHED &&
|
||||
wsi->u.ws.ping_pending_flag) {
|
||||
wsi->u.ws.ping_pending_flag) {
|
||||
n = libwebsocket_write(wsi,
|
||||
&wsi->u.ws.ping_payload_buf[
|
||||
LWS_SEND_BUFFER_PRE_PADDING],
|
||||
wsi->u.ws.ping_payload_len,
|
||||
LWS_WRITE_PONG);
|
||||
LWS_WRITE_PONG);
|
||||
if (n < 0)
|
||||
return -1;
|
||||
|
||||
|
@ -115,7 +115,7 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context,
|
|||
/* if nothing critical, user can get the callback */
|
||||
|
||||
m = lws_ext_callback_for_each_active(wsi, LWS_EXT_CALLBACK_IS_WRITEABLE,
|
||||
NULL, 0);
|
||||
NULL, 0);
|
||||
#ifndef LWS_NO_EXTENSIONS
|
||||
if (!wsi->extension_data_pending)
|
||||
goto user_service;
|
||||
|
@ -141,7 +141,7 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context,
|
|||
|
||||
m = lws_ext_callback_for_each_active(wsi,
|
||||
LWS_EXT_CALLBACK_PACKET_TX_PRESEND,
|
||||
&eff_buf, 0);
|
||||
&eff_buf, 0);
|
||||
if (m < 0) {
|
||||
lwsl_err("ext reports fatal error\n");
|
||||
return -1;
|
||||
|
@ -157,7 +157,7 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context,
|
|||
|
||||
if (eff_buf.token_len) {
|
||||
n = lws_issue_raw(wsi, (unsigned char *)eff_buf.token,
|
||||
eff_buf.token_len);
|
||||
eff_buf.token_len);
|
||||
if (n < 0) {
|
||||
lwsl_info("closing from POLLOUT spill\n");
|
||||
return -1;
|
||||
|
@ -191,7 +191,7 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context,
|
|||
|
||||
/*
|
||||
* Yes, he's choked. Leave the POLLOUT masked on so we will
|
||||
* come back here when he is unchoked. Don't call the user
|
||||
* come back here when he is unchoked. Don't call the user
|
||||
* callback to enforce ordering of spilling, he'll get called
|
||||
* when we come back here and there's nothing more to spill.
|
||||
*/
|
||||
|
@ -270,7 +270,7 @@ notify:
|
|||
|
||||
int
|
||||
libwebsocket_service_timeout_check(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, unsigned int sec)
|
||||
struct libwebsocket *wsi, unsigned int sec)
|
||||
{
|
||||
/*
|
||||
* if extensions want in on it (eg, we are a mux parent)
|
||||
|
@ -364,7 +364,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
|
|||
if (context->listen_service_fd)
|
||||
listen_socket_fds_index = wsi_from_fd(context,context->listen_service_fd)->position_in_fds_table;
|
||||
|
||||
/*
|
||||
/*
|
||||
* you can call us with pollfd = NULL to just allow the once-per-second
|
||||
* global timeout checks; if less than a second since the last check
|
||||
* it returns immediately then.
|
||||
|
@ -430,11 +430,11 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
|
|||
*/
|
||||
|
||||
if (context->listen_service_fd && pollfd !=
|
||||
&context->fds[listen_socket_fds_index]) {
|
||||
&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_modulo) {
|
||||
context->listen_service_count = 0;
|
||||
m = 1;
|
||||
if (context->listen_service_extraseen > 5)
|
||||
|
@ -453,7 +453,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
|
|||
} else {
|
||||
if (context->listen_service_extraseen)
|
||||
context->
|
||||
listen_service_extraseen--;
|
||||
listen_service_extraseen--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -467,7 +467,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
|
|||
(pollfd->revents & LWS_POLLHUP)) {
|
||||
|
||||
lwsl_debug("Session Socket %p (fd=%d) dead\n",
|
||||
(void *)wsi, pollfd->fd);
|
||||
(void *)wsi, pollfd->fd);
|
||||
|
||||
goto close_and_handled;
|
||||
}
|
||||
|
@ -491,17 +491,17 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
|
|||
/* 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_FLUSHING_STORED_SEND_BEFORE_CLOSE) &&
|
||||
(wsi->state == WSI_STATE_ESTABLISHED ||
|
||||
wsi->state == WSI_STATE_HTTP2_ESTABLISHED ||
|
||||
wsi->state == WSI_STATE_HTTP2_ESTABLISHED_PRE_SETTINGS ||
|
||||
wsi->state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE) &&
|
||||
lws_handle_POLLOUT_event(context, wsi, pollfd)) {
|
||||
lwsl_info("libwebsocket_service_fd: closing\n");
|
||||
goto close_and_handled;
|
||||
}
|
||||
|
||||
if (wsi->rxflow_buffer &&
|
||||
(wsi->rxflow_change_to & LWS_RXFLOW_ALLOW)) {
|
||||
(wsi->rxflow_change_to & LWS_RXFLOW_ALLOW)) {
|
||||
lwsl_info("draining rxflow\n");
|
||||
/* well, drain it */
|
||||
eff_buf.token = (char *)wsi->rxflow_buffer +
|
||||
|
@ -518,7 +518,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
|
|||
|
||||
eff_buf.token_len = lws_ssl_capable_read(context, wsi,
|
||||
context->service_buffer,
|
||||
sizeof(context->service_buffer));
|
||||
sizeof(context->service_buffer));
|
||||
switch (eff_buf.token_len) {
|
||||
case 0:
|
||||
lwsl_info("service_fd: closing due to 0 length read\n");
|
||||
|
@ -563,7 +563,7 @@ drain:
|
|||
if (eff_buf.token_len) {
|
||||
n = libwebsocket_read(context, wsi,
|
||||
(unsigned char *)eff_buf.token,
|
||||
eff_buf.token_len);
|
||||
eff_buf.token_len);
|
||||
if (n < 0) {
|
||||
/* we closed wsi */
|
||||
n = 0;
|
||||
|
@ -625,7 +625,7 @@ handled:
|
|||
* 1) Accept new connections to our context's server
|
||||
*
|
||||
* 2) Call the receive callback for incoming frame data received by
|
||||
* server or client connections.
|
||||
* server or client connections.
|
||||
*
|
||||
* You need to call this service function periodically to all the above
|
||||
* functions to happen; if your application is single-threaded you can
|
||||
|
|
|
@ -102,7 +102,7 @@ lws_context_init_http2_ssl(struct libwebsocket_context *context)
|
|||
#else
|
||||
lwsl_notice(
|
||||
" HTTP2 / ALPN configured but not supported by OpenSSL 0x%x\n",
|
||||
OPENSSL_VERSION_NUMBER);
|
||||
OPENSSL_VERSION_NUMBER);
|
||||
#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L
|
||||
}
|
||||
|
||||
|
@ -151,4 +151,4 @@ void lws_http2_configure_if_upgraded(struct libwebsocket *wsi)
|
|||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
|
84
lib/ssl.c
84
lib/ssl.c
|
@ -3,20 +3,20 @@
|
|||
*
|
||||
* Copyright (C) 2010-2014 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
|
||||
* License as published by the Free Software Foundation:
|
||||
* version 2.1 of the License.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation:
|
||||
* version 2.1 of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "private-libwebsockets.h"
|
||||
|
@ -35,7 +35,7 @@ static int lws_context_init_ssl_pem_passwd_cb(char * buf, int size, int rwflag,
|
|||
}
|
||||
|
||||
static void lws_ssl_bind_passphrase(SSL_CTX *ssl_ctx,
|
||||
struct lws_context_creation_info *info)
|
||||
struct lws_context_creation_info *info)
|
||||
{
|
||||
if (!info->ssl_private_key_password)
|
||||
return;
|
||||
|
@ -46,7 +46,7 @@ static void lws_ssl_bind_passphrase(SSL_CTX *ssl_ctx,
|
|||
*/
|
||||
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);
|
||||
lws_context_init_ssl_pem_passwd_cb);
|
||||
}
|
||||
|
||||
#ifndef LWS_NO_SERVER
|
||||
|
@ -76,7 +76,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 libwebsocket_context *context)
|
||||
struct libwebsocket_context *context)
|
||||
{
|
||||
SSL_METHOD *method;
|
||||
int error;
|
||||
|
@ -125,7 +125,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->service_buffer));
|
||||
return 1;
|
||||
}
|
||||
context->ssl_ctx = SSL_CTX_new(method); /* create context */
|
||||
|
@ -133,7 +133,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->service_buffer));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -155,8 +155,8 @@ lws_context_init_server_ssl(struct lws_context_creation_info *info,
|
|||
/* absolutely require the client cert */
|
||||
|
||||
SSL_CTX_set_verify(context->ssl_ctx,
|
||||
SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
|
||||
OpenSSL_verify_callback);
|
||||
SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
|
||||
OpenSSL_verify_callback);
|
||||
|
||||
/*
|
||||
* give user code a chance to load certs into the server
|
||||
|
@ -165,7 +165,7 @@ lws_context_init_server_ssl(struct lws_context_creation_info *info,
|
|||
|
||||
context->protocols[0].callback(context, NULL,
|
||||
LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS,
|
||||
context->ssl_ctx, NULL, 0);
|
||||
context->ssl_ctx, NULL, 0);
|
||||
}
|
||||
|
||||
if (info->options & LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT) {
|
||||
|
@ -186,7 +186,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->service_buffer));
|
||||
return 1;
|
||||
}
|
||||
lws_ssl_bind_passphrase(context->ssl_ctx, info);
|
||||
|
@ -194,14 +194,14 @@ lws_context_init_server_ssl(struct lws_context_creation_info *info,
|
|||
if (info->ssl_private_key_filepath != NULL) {
|
||||
/* set the private key from KeyFile */
|
||||
if (SSL_CTX_use_PrivateKey_file(context->ssl_ctx,
|
||||
info->ssl_private_key_filepath,
|
||||
SSL_FILETYPE_PEM) != 1) {
|
||||
info->ssl_private_key_filepath,
|
||||
SSL_FILETYPE_PEM) != 1) {
|
||||
error = ERR_get_error();
|
||||
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->service_buffer));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ libwebsockets_decode_ssl_error(void)
|
|||
#ifndef LWS_NO_CLIENT
|
||||
|
||||
int lws_context_init_client_ssl(struct lws_context_creation_info *info,
|
||||
struct libwebsocket_context *context)
|
||||
struct libwebsocket_context *context)
|
||||
{
|
||||
int error;
|
||||
int n;
|
||||
|
@ -294,7 +294,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->service_buffer));
|
||||
return 1;
|
||||
}
|
||||
/* create context */
|
||||
|
@ -303,7 +303,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->service_buffer));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -312,7 +312,7 @@ int lws_context_init_client_ssl(struct lws_context_creation_info *info,
|
|||
SSL_OP_NO_COMPRESSION);
|
||||
#endif
|
||||
SSL_CTX_set_options(context->ssl_client_ctx,
|
||||
SSL_OP_CIPHER_SERVER_PREFERENCE);
|
||||
SSL_OP_CIPHER_SERVER_PREFERENCE);
|
||||
if (info->ssl_cipher_list)
|
||||
SSL_CTX_set_cipher_list(context->ssl_client_ctx,
|
||||
info->ssl_cipher_list);
|
||||
|
@ -327,12 +327,12 @@ int lws_context_init_client_ssl(struct lws_context_creation_info *info,
|
|||
if (!info->ssl_ca_filepath) {
|
||||
if (!SSL_CTX_load_verify_locations(
|
||||
context->ssl_client_ctx, NULL,
|
||||
LWS_OPENSSL_CLIENT_CERTS))
|
||||
LWS_OPENSSL_CLIENT_CERTS))
|
||||
lwsl_err(
|
||||
"Unable to load SSL Client certs from %s "
|
||||
"(set by --with-client-cert-dir= "
|
||||
"in configure) -- client ssl isn't "
|
||||
"going to work", LWS_OPENSSL_CLIENT_CERTS);
|
||||
"Unable to load SSL Client certs from %s "
|
||||
"(set by --with-client-cert-dir= "
|
||||
"in configure) -- client ssl isn't "
|
||||
"going to work", LWS_OPENSSL_CLIENT_CERTS);
|
||||
} else
|
||||
if (!SSL_CTX_load_verify_locations(
|
||||
context->ssl_client_ctx, info->ssl_ca_filepath,
|
||||
|
@ -367,12 +367,12 @@ int lws_context_init_client_ssl(struct lws_context_creation_info *info,
|
|||
lws_ssl_bind_passphrase(context->ssl_client_ctx, info);
|
||||
/* set the private key from KeyFile */
|
||||
if (SSL_CTX_use_PrivateKey_file(context->ssl_client_ctx,
|
||||
info->ssl_private_key_filepath, SSL_FILETYPE_PEM) != 1) {
|
||||
info->ssl_private_key_filepath, SSL_FILETYPE_PEM) != 1) {
|
||||
lwsl_err("use_PrivateKey_file '%s' %lu: %s\n",
|
||||
info->ssl_private_key_filepath,
|
||||
ERR_get_error(),
|
||||
ERR_error_string(ERR_get_error(),
|
||||
(char *)context->service_buffer));
|
||||
(char *)context->service_buffer));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -394,11 +394,11 @@ int lws_context_init_client_ssl(struct lws_context_creation_info *info,
|
|||
|
||||
LWS_VISIBLE void
|
||||
lws_ssl_remove_wsi_from_buffered_list(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi)
|
||||
struct libwebsocket *wsi)
|
||||
{
|
||||
if (!wsi->pending_read_list_prev &&
|
||||
!wsi->pending_read_list_next &&
|
||||
context->pending_read_list != wsi)
|
||||
!wsi->pending_read_list_next &&
|
||||
context->pending_read_list != wsi)
|
||||
/* we are not on the list */
|
||||
return;
|
||||
|
||||
|
@ -420,7 +420,7 @@ lws_ssl_remove_wsi_from_buffered_list(struct libwebsocket_context *context,
|
|||
|
||||
LWS_VISIBLE int
|
||||
lws_ssl_capable_read(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, unsigned char *buf, int len)
|
||||
struct libwebsocket *wsi, unsigned char *buf, int len)
|
||||
{
|
||||
int n;
|
||||
|
||||
|
@ -520,9 +520,9 @@ lws_server_socket_service_ssl(struct libwebsocket_context *context,
|
|||
new_wsi->ssl = SSL_new(context->ssl_ctx);
|
||||
if (new_wsi->ssl == NULL) {
|
||||
lwsl_err("SSL_new failed: %s\n",
|
||||
ERR_error_string(SSL_get_error(
|
||||
new_wsi->ssl, 0), NULL));
|
||||
libwebsockets_decode_ssl_error();
|
||||
ERR_error_string(SSL_get_error(
|
||||
new_wsi->ssl, 0), NULL));
|
||||
libwebsockets_decode_ssl_error();
|
||||
lws_free(new_wsi);
|
||||
compatible_close(accept_fd);
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue