Skip to content
Snippets Groups Projects
Commit d478fb8c authored by Andy Green's avatar Andy Green
Browse files

clean more whitespace 3

parent 1cc03887
No related branches found
No related tags found
No related merge requests found
#include "private-libwebsockets.h" #include "private-libwebsockets.h"
struct lws *lws_client_connect_2( struct lws *
struct lws_context *context, lws_client_connect_2(struct lws_context *context, struct lws *wsi)
struct lws *wsi {
) {
struct lws_pollfd pfd;
#ifdef LWS_USE_IPV6 #ifdef LWS_USE_IPV6
struct sockaddr_in6 server_addr6; struct sockaddr_in6 server_addr6;
struct sockaddr_in6 client_addr6; struct sockaddr_in6 client_addr6;
...@@ -12,17 +10,14 @@ struct lws *lws_client_connect_2( ...@@ -12,17 +10,14 @@ struct lws *lws_client_connect_2(
#endif #endif
struct sockaddr_in server_addr4; struct sockaddr_in server_addr4;
struct sockaddr_in client_addr4; struct sockaddr_in client_addr4;
struct lws_pollfd pfd;
struct sockaddr *v; struct sockaddr *v;
int n; int n, plen = 0;
int plen = 0;
const char *ads; const char *ads;
lwsl_client("lws_client_connect_2\n"); lwsl_client("lws_client_connect_2\n");
/* /* proxy? */
* proxy?
*/
if (context->http_proxy_port) { if (context->http_proxy_port) {
plen = sprintf((char *)context->service_buffer, plen = sprintf((char *)context->service_buffer,
...@@ -216,14 +211,13 @@ struct lws *lws_client_connect_2( ...@@ -216,14 +211,13 @@ struct lws *lws_client_connect_2(
if (connect(wsi->sock, v, n) == -1 || LWS_ERRNO == LWS_EISCONN) { if (connect(wsi->sock, v, n) == -1 || LWS_ERRNO == LWS_EISCONN) {
if (LWS_ERRNO == LWS_EALREADY if (LWS_ERRNO == LWS_EALREADY ||
|| LWS_ERRNO == LWS_EINPROGRESS LWS_ERRNO == LWS_EINPROGRESS ||
|| LWS_ERRNO == LWS_EWOULDBLOCK LWS_ERRNO == LWS_EWOULDBLOCK
#ifdef _WIN32 #ifdef _WIN32
|| LWS_ERRNO == WSAEINVAL || LWS_ERRNO == WSAEINVAL
#endif #endif
) ) {
{
lwsl_client("nonblocking connect retry\n"); lwsl_client("nonblocking connect retry\n");
/* /*
...@@ -249,26 +243,26 @@ struct lws *lws_client_connect_2( ...@@ -249,26 +243,26 @@ struct lws *lws_client_connect_2(
if (context->http_proxy_port) { if (context->http_proxy_port) {
/* OK from now on we talk via the proxy, so connect to that */
/* /*
* OK from now on we talk via the proxy, so connect to that
*
* (will overwrite existing pointer, * (will overwrite existing pointer,
* leaving old string/frag there but unreferenced) * leaving old string/frag there but unreferenced)
*/ */
if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS, if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS,
context->http_proxy_address)) context->http_proxy_address))
goto failed; goto failed;
wsi->u.hdr.ah->c_port = context->http_proxy_port; wsi->u.hdr.ah->c_port = context->http_proxy_port;
n = send(wsi->sock, (char *)context->service_buffer, plen, MSG_NOSIGNAL); n = send(wsi->sock, (char *)context->service_buffer, plen,
MSG_NOSIGNAL);
if (n < 0) { if (n < 0) {
lwsl_debug("ERROR writing to proxy socket\n"); lwsl_debug("ERROR writing to proxy socket\n");
goto failed; goto failed;
} }
lws_set_timeout(wsi, lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE,
PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE, AWAITING_TIMEOUT);
AWAITING_TIMEOUT);
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY; wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY;
...@@ -285,8 +279,8 @@ struct lws *lws_client_connect_2( ...@@ -285,8 +279,8 @@ struct lws *lws_client_connect_2(
* cover with a timeout. * cover with a timeout.
*/ */
lws_set_timeout(wsi, lws_set_timeout(wsi, PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE,
PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE, AWAITING_TIMEOUT); AWAITING_TIMEOUT);
wsi->mode = LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE; wsi->mode = LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE;
pfd.fd = wsi->sock; pfd.fd = wsi->sock;
...@@ -308,8 +302,8 @@ oom4: ...@@ -308,8 +302,8 @@ oom4:
return NULL; return NULL;
failed: failed:
lws_close_and_free_session(context, wsi, lws_close_and_free_session(context, wsi, LWS_CLOSE_STATUS_NOSTATUS);
LWS_CLOSE_STATUS_NOSTATUS);
return NULL; return NULL;
} }
...@@ -334,15 +328,10 @@ failed: ...@@ -334,15 +328,10 @@ failed:
*/ */
LWS_VISIBLE struct lws * LWS_VISIBLE struct lws *
lws_client_connect(struct lws_context *context, lws_client_connect(struct lws_context *context, const char *address,
const char *address, int port, int ssl_connection, const char *path,
int port, const char *host, const char *origin,
int ssl_connection, const char *protocol, int ietf_version_or_minus_one)
const char *path,
const char *host,
const char *origin,
const char *protocol,
int ietf_version_or_minus_one)
{ {
struct lws *wsi; struct lws *wsi;
...@@ -392,16 +381,15 @@ lws_client_connect(struct lws_context *context, ...@@ -392,16 +381,15 @@ lws_client_connect(struct lws_context *context,
goto bail1; goto bail1;
if (origin) if (origin)
if (lws_hdr_simple_create(wsi, if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_ORIGIN, origin))
_WSI_TOKEN_CLIENT_ORIGIN, origin))
goto bail1; goto bail1;
/* /*
* this is a list of protocols we tell the server we're okay with * this is a list of protocols we tell the server we're okay with
* stash it for later when we compare server response with it * stash it for later when we compare server response with it
*/ */
if (protocol) if (protocol)
if (lws_hdr_simple_create(wsi, if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS,
_WSI_TOKEN_CLIENT_SENT_PROTOCOLS, protocol)) protocol))
goto bail1; goto bail1;
wsi->protocol = &context->protocols[0]; wsi->protocol = &context->protocols[0];
...@@ -415,12 +403,12 @@ lws_client_connect(struct lws_context *context, ...@@ -415,12 +403,12 @@ lws_client_connect(struct lws_context *context,
if (lws_ext_callback_for_each_extension_type(context, wsi, if (lws_ext_callback_for_each_extension_type(context, wsi,
LWS_EXT_CALLBACK_CAN_PROXY_CLIENT_CONNECTION, LWS_EXT_CALLBACK_CAN_PROXY_CLIENT_CONNECTION,
(void *)address, port) > 0) { (void *)address, port) > 0) {
lwsl_client("lws_client_connect: ext handling conn\n"); lwsl_client("lws_client_connect: ext handling conn\n");
lws_set_timeout(wsi, lws_set_timeout(wsi,
PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE, PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE,
AWAITING_TIMEOUT); AWAITING_TIMEOUT);
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT; wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT;
return wsi; return wsi;
...@@ -459,26 +447,22 @@ bail: ...@@ -459,26 +447,22 @@ bail:
*/ */
LWS_VISIBLE struct lws * LWS_VISIBLE struct lws *
lws_client_connect_extended(struct lws_context *context, lws_client_connect_extended(struct lws_context *context, const char *address,
const char *address, int port, int ssl_connection, const char *path,
int port, const char *host, const char *origin,
int ssl_connection, const char *protocol, int ietf_version_or_minus_one,
const char *path, void *userdata)
const char *host,
const char *origin,
const char *protocol,
int ietf_version_or_minus_one,
void *userdata)
{ {
struct lws *ws = struct lws *wsi;
lws_client_connect(context, address, port,
ssl_connection, path, host, origin, protocol, wsi = lws_client_connect(context, address, port, ssl_connection, path,
ietf_version_or_minus_one); host, origin, protocol,
ietf_version_or_minus_one);
if (ws && !ws->user_space && userdata) {
ws->user_space_externally_allocated = 1; if (wsi && !wsi->user_space && userdata) {
ws->user_space = userdata ; wsi->user_space_externally_allocated = 1;
wsi->user_space = userdata ;
} }
return ws ; return wsi;
} }
...@@ -24,9 +24,8 @@ ...@@ -24,9 +24,8 @@
int lws_client_rx_sm(struct lws *wsi, unsigned char c) int lws_client_rx_sm(struct lws *wsi, unsigned char c)
{ {
int callback_action = LWS_CALLBACK_CLIENT_RECEIVE; int callback_action = LWS_CALLBACK_CLIENT_RECEIVE;
int handled;
struct lws_tokens eff_buf; struct lws_tokens eff_buf;
int m; int handled, m;
switch (wsi->lws_rx_parse_state) { switch (wsi->lws_rx_parse_state) {
case LWS_RXPS_NEW: case LWS_RXPS_NEW:
...@@ -54,7 +53,6 @@ int lws_client_rx_sm(struct lws *wsi, unsigned char c) ...@@ -54,7 +53,6 @@ int lws_client_rx_sm(struct lws *wsi, unsigned char c)
} }
break; break;
case LWS_RXPS_04_FRAME_HDR_LEN: case LWS_RXPS_04_FRAME_HDR_LEN:
wsi->u.ws.this_frame_masked = !!(c & 0x80); wsi->u.ws.this_frame_masked = !!(c & 0x80);
...@@ -287,7 +285,7 @@ spill: ...@@ -287,7 +285,7 @@ spill:
case LWS_WS_OPCODE_07__PING: case LWS_WS_OPCODE_07__PING:
lwsl_info("received %d byte ping, sending pong\n", lwsl_info("received %d byte ping, sending pong\n",
wsi->u.ws.rx_user_buffer_head); wsi->u.ws.rx_user_buffer_head);
if (wsi->u.ws.ping_pending_flag) { if (wsi->u.ws.ping_pending_flag) {
/* /*
...@@ -306,13 +304,15 @@ spill: ...@@ -306,13 +304,15 @@ spill:
/* if existing buffer is too small, drop it */ /* if existing buffer is too small, drop it */
if (wsi->u.ws.ping_payload_buf && 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); lws_free2(wsi->u.ws.ping_payload_buf);
/* if no buffer, allocate it */ /* if no buffer, allocate it */
if (!wsi->u.ws.ping_payload_buf) { if (!wsi->u.ws.ping_payload_buf) {
wsi->u.ws.ping_payload_buf = lws_malloc(wsi->u.ws.rx_user_buffer_head wsi->u.ws.ping_payload_buf =
+ LWS_SEND_BUFFER_PRE_PADDING); lws_malloc(wsi->u.ws.rx_user_buffer_head +
LWS_SEND_BUFFER_PRE_PADDING);
wsi->u.ws.ping_payload_alloc = wsi->u.ws.ping_payload_alloc =
wsi->u.ws.rx_user_buffer_head; wsi->u.ws.rx_user_buffer_head;
} }
...@@ -334,9 +334,8 @@ ping_drop: ...@@ -334,9 +334,8 @@ ping_drop:
case LWS_WS_OPCODE_07__PONG: case LWS_WS_OPCODE_07__PONG:
lwsl_info("client receied pong\n"); lwsl_info("client receied pong\n");
lwsl_hexdump(&wsi->u.ws.rx_user_buffer[ lwsl_hexdump(&wsi->u.ws.rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
LWS_SEND_BUFFER_PRE_PADDING], wsi->u.ws.rx_user_buffer_head);
wsi->u.ws.rx_user_buffer_head);
/* issue it */ /* issue it */
callback_action = LWS_CALLBACK_CLIENT_RECEIVE_PONG; callback_action = LWS_CALLBACK_CLIENT_RECEIVE_PONG;
...@@ -366,7 +365,7 @@ ping_drop: ...@@ -366,7 +365,7 @@ ping_drop:
&eff_buf, 0) <= 0) { /* not handle or fail */ &eff_buf, 0) <= 0) { /* not handle or fail */
lwsl_ext("Unhandled ext opc 0x%x\n", lwsl_ext("Unhandled ext opc 0x%x\n",
wsi->u.ws.opcode); wsi->u.ws.opcode);
wsi->u.ws.rx_user_buffer_head = 0; wsi->u.ws.rx_user_buffer_head = 0;
return 0; return 0;
...@@ -388,12 +387,12 @@ ping_drop: ...@@ -388,12 +387,12 @@ ping_drop:
eff_buf.token_len = wsi->u.ws.rx_user_buffer_head; eff_buf.token_len = wsi->u.ws.rx_user_buffer_head;
if (lws_ext_callback_for_each_active(wsi, if (lws_ext_callback_for_each_active(wsi,
LWS_EXT_CALLBACK_PAYLOAD_RX, LWS_EXT_CALLBACK_PAYLOAD_RX,
&eff_buf, 0) < 0) /* fail */ &eff_buf, 0) < 0) /* fail */
return -1; return -1;
if (eff_buf.token_len <= 0 && if (eff_buf.token_len <= 0 &&
callback_action != LWS_CALLBACK_CLIENT_RECEIVE_PONG) callback_action != LWS_CALLBACK_CLIENT_RECEIVE_PONG)
goto already_done; goto already_done;
eff_buf.token[eff_buf.token_len] = '\0'; eff_buf.token[eff_buf.token_len] = '\0';
...@@ -404,13 +403,9 @@ ping_drop: ...@@ -404,13 +403,9 @@ ping_drop:
if (callback_action == LWS_CALLBACK_CLIENT_RECEIVE_PONG) if (callback_action == LWS_CALLBACK_CLIENT_RECEIVE_PONG)
lwsl_info("Client doing pong callback\n"); lwsl_info("Client doing pong callback\n");
m = wsi->protocol->callback( m = wsi->protocol->callback(wsi->protocol->owning_server,
wsi->protocol->owning_server, wsi, (enum lws_callback_reasons)callback_action,
wsi, wsi->user_space, eff_buf.token, eff_buf.token_len);
(enum lws_callback_reasons)callback_action,
wsi->user_space,
eff_buf.token,
eff_buf.token_len);
/* if user code wants to close, let caller know */ /* if user code wants to close, let caller know */
if (m) if (m)
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
int lws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len) int lws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len)
{ {
int n; unsigned int n;
switch (wsi->mode) { switch (wsi->mode) {
case LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY: case LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY:
...@@ -44,12 +44,11 @@ int lws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len) ...@@ -44,12 +44,11 @@ int lws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len)
} }
int lws_client_socket_service(struct lws_context *context, int lws_client_socket_service(struct lws_context *context,
struct lws *wsi, struct lws_pollfd *pollfd) struct lws *wsi, struct lws_pollfd *pollfd)
{ {
int n;
char *p = (char *)&context->service_buffer[0]; char *p = (char *)&context->service_buffer[0];
int len;
unsigned char c; unsigned char c;
int n, len;
switch (wsi->mode) { switch (wsi->mode) {
...@@ -88,13 +87,12 @@ int lws_client_socket_service(struct lws_context *context, ...@@ -88,13 +87,12 @@ int lws_client_socket_service(struct lws_context *context,
if (n < 0) { if (n < 0) {
if (LWS_ERRNO == LWS_EAGAIN) { if (LWS_ERRNO == LWS_EAGAIN) {
lwsl_debug( lwsl_debug("Proxy read returned EAGAIN... retrying\n");
"Proxy read returned EAGAIN... retrying\n");
return 0; return 0;
} }
lws_close_and_free_session(context, wsi, lws_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS); LWS_CLOSE_STATUS_NOSTATUS);
lwsl_err("ERROR reading from proxy socket\n"); lwsl_err("ERROR reading from proxy socket\n");
return 0; return 0;
} }
...@@ -104,7 +102,7 @@ int lws_client_socket_service(struct lws_context *context, ...@@ -104,7 +102,7 @@ int lws_client_socket_service(struct lws_context *context,
strcmp((char *)context->service_buffer, "HTTP/1.1 200 ") strcmp((char *)context->service_buffer, "HTTP/1.1 200 ")
) { ) {
lws_close_and_free_session(context, wsi, lws_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS); LWS_CLOSE_STATUS_NOSTATUS);
lwsl_err("ERROR proxy: %s\n", context->service_buffer); lwsl_err("ERROR proxy: %s\n", context->service_buffer);
return 0; return 0;
} }
...@@ -493,22 +491,18 @@ strtolower(char *s) ...@@ -493,22 +491,18 @@ strtolower(char *s)
int int
lws_client_interpret_server_handshake(struct lws_context *context, lws_client_interpret_server_handshake(struct lws_context *context,
struct lws *wsi) struct lws *wsi)
{ {
int n, len, okay = 0, more = 1, isErrorCodeReceived = 0;
int close_reason = LWS_CLOSE_STATUS_PROTOCOL_ERR;
const char *pc; const char *pc;
int okay = 0;
char *p; char *p;
int len;
int isErrorCodeReceived = 0;
#ifndef LWS_NO_EXTENSIONS #ifndef LWS_NO_EXTENSIONS
char ext_name[128];
struct lws_extension *ext; struct lws_extension *ext;
void *v; char ext_name[128];
int more = 1;
const char *c; const char *c;
void *v;
#endif #endif
int n;
int close_reason = LWS_CLOSE_STATUS_PROTOCOL_ERR;
/* /*
* well, what the server sent looked reasonable for syntax. * well, what the server sent looked reasonable for syntax.
...@@ -736,7 +730,7 @@ check_accept: ...@@ -736,7 +730,7 @@ check_accept:
wsi->protocol->callback(context, wsi, wsi->protocol->callback(context, wsi,
LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH, LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH,
wsi->user_space, NULL, 0); wsi->user_space, NULL, 0);
/* clear his proxy connection timeout */ /* clear his proxy connection timeout */
...@@ -777,9 +771,8 @@ check_accept: ...@@ -777,9 +771,8 @@ check_accept:
/* call him back to inform him he is up */ /* call him back to inform him he is up */
wsi->protocol->callback(context, wsi, wsi->protocol->callback(context, wsi, LWS_CALLBACK_CLIENT_ESTABLISHED,
LWS_CALLBACK_CLIENT_ESTABLISHED, wsi->user_space, NULL, 0);
wsi->user_space, NULL, 0);
#ifndef LWS_NO_EXTENSIONS #ifndef LWS_NO_EXTENSIONS
/* /*
* inform all extensions, not just active ones since they * inform all extensions, not just active ones since they
...@@ -811,20 +804,19 @@ bail2: ...@@ -811,20 +804,19 @@ bail2:
if (isErrorCodeReceived && p) { if (isErrorCodeReceived && p) {
wsi->protocol->callback(context, wsi, wsi->protocol->callback(context, wsi,
LWS_CALLBACK_CLIENT_CONNECTION_ERROR, LWS_CALLBACK_CLIENT_CONNECTION_ERROR,
wsi->user_space, p, (unsigned int)strlen(p)); wsi->user_space, p,
(unsigned int)strlen(p));
} else { } else {
wsi->protocol->callback(context, wsi, wsi->protocol->callback(context, wsi,
LWS_CALLBACK_CLIENT_CONNECTION_ERROR, 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"); lwsl_info("closing connection due to bail2 connection error\n");
/* free up his parsing allocations */ /* free up his parsing allocations */
lws_free2(wsi->u.hdr.ah); lws_free2(wsi->u.hdr.ah);
lws_close_and_free_session(context, wsi, close_reason); lws_close_and_free_session(context, wsi, close_reason);
return 1; return 1;
...@@ -833,12 +825,9 @@ bail2: ...@@ -833,12 +825,9 @@ bail2:
char * char *
lws_generate_client_handshake(struct lws_context *context, lws_generate_client_handshake(struct lws_context *context,
struct lws *wsi, char *pkt) struct lws *wsi, char *pkt)
{ {
char buf[128]; char buf[128], hash[20], key_b64[40], *p = pkt;
char hash[20];
char key_b64[40];
char *p = pkt;
int n; int n;
#ifndef LWS_NO_EXTENSIONS #ifndef LWS_NO_EXTENSIONS
struct lws_extension *ext; struct lws_extension *ext;
...@@ -848,7 +837,6 @@ lws_generate_client_handshake(struct lws_context *context, ...@@ -848,7 +837,6 @@ lws_generate_client_handshake(struct lws_context *context,
/* /*
* create the random key * create the random key
*/ */
n = lws_get_random(context, hash, 16); n = lws_get_random(context, hash, 16);
if (n != 16) { if (n != 16) {
lwsl_err("Unable to read from random dev %s\n", lwsl_err("Unable to read from random dev %s\n",
...@@ -887,15 +875,16 @@ lws_generate_client_handshake(struct lws_context *context, ...@@ -887,15 +875,16 @@ lws_generate_client_handshake(struct lws_context *context,
*/ */
p += sprintf(p, "GET %s HTTP/1.1\x0d\x0a", p += sprintf(p, "GET %s HTTP/1.1\x0d\x0a",
lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_URI)); lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_URI));
p += sprintf(p, p += sprintf(p, "Pragma: no-cache\x0d\x0a"
"Pragma: no-cache\x0d\x0a""Cache-Control: no-cache\x0d\x0a"); "Cache-Control: no-cache\x0d\x0a");
p += sprintf(p, "Host: %s\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, p += sprintf(p, "Upgrade: websocket\x0d\x0a"
"Upgrade: websocket\x0d\x0a""Connection: Upgrade\x0d\x0a""Sec-WebSocket-Key: "); "Connection: Upgrade\x0d\x0a"
"Sec-WebSocket-Key: ");
strcpy(p, key_b64); strcpy(p, key_b64);
p += strlen(key_b64); p += strlen(key_b64);
p += sprintf(p, "\x0d\x0a"); p += sprintf(p, "\x0d\x0a");
...@@ -916,7 +905,7 @@ lws_generate_client_handshake(struct lws_context *context, ...@@ -916,7 +905,7 @@ lws_generate_client_handshake(struct lws_context *context,
n = lws_ext_callback_for_each_extension_type(context, wsi, n = lws_ext_callback_for_each_extension_type(context, wsi,
LWS_EXT_CALLBACK_CHECK_OK_TO_PROPOSE_EXTENSION, LWS_EXT_CALLBACK_CHECK_OK_TO_PROPOSE_EXTENSION,
(char *)ext->name, 0); (char *)ext->name, 0);
if (n) { /* an extension vetos us */ if (n) { /* an extension vetos us */
lwsl_ext("ext %s vetoed\n", (char *)ext->name); lwsl_ext("ext %s vetoed\n", (char *)ext->name);
ext++; ext++;
...@@ -953,13 +942,14 @@ lws_generate_client_handshake(struct lws_context *context, ...@@ -953,13 +942,14 @@ lws_generate_client_handshake(struct lws_context *context,
if (wsi->ietf_spec_revision) if (wsi->ietf_spec_revision)
p += sprintf(p, "Sec-WebSocket-Version: %d\x0d\x0a", 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 */ /* give userland a chance to append, eg, cookies */
context->protocols[0].callback(context, wsi, context->protocols[0].callback(context, wsi,
LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER, LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER,
NULL, &p, (pkt + sizeof(context->service_buffer)) - p - 12); NULL, &p,
(pkt + sizeof(context->service_buffer)) - p - 12);
p += sprintf(p, "\x0d\x0a"); p += sprintf(p, "\x0d\x0a");
...@@ -971,8 +961,8 @@ lws_generate_client_handshake(struct lws_context *context, ...@@ -971,8 +961,8 @@ lws_generate_client_handshake(struct lws_context *context,
lws_SHA1((unsigned char *)buf, n, (unsigned char *)hash); lws_SHA1((unsigned char *)buf, n, (unsigned char *)hash);
lws_b64_encode_string(hash, 20, lws_b64_encode_string(hash, 20,
wsi->u.hdr.ah->initial_handshake_hash_base64, wsi->u.hdr.ah->initial_handshake_hash_base64,
sizeof(wsi->u.hdr.ah->initial_handshake_hash_base64)); sizeof(wsi->u.hdr.ah->initial_handshake_hash_base64));
return p; return p;
} }
......
...@@ -75,10 +75,10 @@ LWS_VISIBLE struct lws_context * ...@@ -75,10 +75,10 @@ LWS_VISIBLE struct lws_context *
lws_create_context(struct lws_context_creation_info *info) lws_create_context(struct lws_context_creation_info *info)
{ {
struct lws_context *context = NULL; struct lws_context *context = NULL;
char *p;
#if LWS_POSIX #if LWS_POSIX
int pid_daemon = get_daemonize_pid(); int pid_daemon = get_daemonize_pid();
#endif #endif
char *p;
lwsl_notice("Initial logging level %d\n", log_level); lwsl_notice("Initial logging level %d\n", log_level);
...@@ -304,7 +304,6 @@ lws_context_destroy(struct lws_context *context) ...@@ -304,7 +304,6 @@ lws_context_destroy(struct lws_context *context)
} }
lws_plat_context_early_destroy(context); lws_plat_context_early_destroy(context);
lws_ssl_context_destroy(context); lws_ssl_context_destroy(context);
if (context->fds) if (context->fds)
......
...@@ -34,9 +34,7 @@ int get_daemonize_pid() ...@@ -34,9 +34,7 @@ int get_daemonize_pid()
static void static void
child_handler(int signum) child_handler(int signum)
{ {
int fd; int fd, len, sent;
int len;
int sent;
char sz[20]; char sz[20];
switch (signum) { switch (signum) {
...@@ -93,11 +91,10 @@ static void lws_daemon_closing(int sigact) ...@@ -93,11 +91,10 @@ static void lws_daemon_closing(int sigact)
LWS_VISIBLE int LWS_VISIBLE int
lws_daemonize(const char *_lock_path) lws_daemonize(const char *_lock_path)
{ {
struct sigaction act;
pid_t sid, parent; pid_t sid, parent;
int fd; int n, fd, ret;
char buf[10]; char buf[10];
int n, ret;
struct sigaction act;
/* already a daemon */ /* already a daemon */
if (getppid() == 1) if (getppid() == 1)
......
...@@ -29,20 +29,20 @@ const unsigned char *lws_token_to_string(enum lws_token_indexes token) ...@@ -29,20 +29,20 @@ const unsigned char *lws_token_to_string(enum lws_token_indexes token)
if ((unsigned int)token >= ARRAY_SIZE(set)) if ((unsigned int)token >= ARRAY_SIZE(set))
return NULL; return NULL;
return (unsigned char *)set[token]; return (unsigned char *)set[token];
} }
int lws_add_http_header_by_name(struct lws_context *context, int
struct lws *wsi, lws_add_http_header_by_name(struct lws_context *context, struct lws *wsi,
const unsigned char *name, const unsigned char *name,
const unsigned char *value, const unsigned char *value, int length,
int length, unsigned char **p, unsigned char *end)
unsigned char **p,
unsigned char *end)
{ {
#ifdef LWS_USE_HTTP2 #ifdef LWS_USE_HTTP2
if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING) if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING)
return lws_add_http2_header_by_name(context, wsi, name, value, length, p, end); return lws_add_http2_header_by_name(context, wsi, name,
value, length, p, end);
#else #else
(void)wsi; (void)wsi;
(void)context; (void)context;
...@@ -61,13 +61,12 @@ int lws_add_http_header_by_name(struct lws_context *context, ...@@ -61,13 +61,12 @@ int lws_add_http_header_by_name(struct lws_context *context,
*p += length; *p += length;
*((*p)++) = '\x0d'; *((*p)++) = '\x0d';
*((*p)++) = '\x0a'; *((*p)++) = '\x0a';
return 0; return 0;
} }
int lws_finalize_http_header(struct lws_context *context, int lws_finalize_http_header(struct lws_context *context, struct lws *wsi,
struct lws *wsi, unsigned char **p, unsigned char *end)
unsigned char **p,
unsigned char *end)
{ {
(void)context; (void)context;
#ifdef LWS_USE_HTTP2 #ifdef LWS_USE_HTTP2
...@@ -80,16 +79,15 @@ int lws_finalize_http_header(struct lws_context *context, ...@@ -80,16 +79,15 @@ int lws_finalize_http_header(struct lws_context *context,
return 1; return 1;
*((*p)++) = '\x0d'; *((*p)++) = '\x0d';
*((*p)++) = '\x0a'; *((*p)++) = '\x0a';
return 0; return 0;
} }
int lws_add_http_header_by_token(struct lws_context *context, int
struct lws *wsi, lws_add_http_header_by_token(struct lws_context *context, struct lws *wsi,
enum lws_token_indexes token, enum lws_token_indexes token,
const unsigned char *value, const unsigned char *value, int length,
int length, unsigned char **p, unsigned char *end)
unsigned char **p,
unsigned char *end)
{ {
const unsigned char *name; const unsigned char *name;
#ifdef LWS_USE_HTTP2 #ifdef LWS_USE_HTTP2
...@@ -103,10 +101,9 @@ int lws_add_http_header_by_token(struct lws_context *context, ...@@ -103,10 +101,9 @@ int lws_add_http_header_by_token(struct lws_context *context,
} }
int lws_add_http_header_content_length(struct lws_context *context, int lws_add_http_header_content_length(struct lws_context *context,
struct lws *wsi, struct lws *wsi,
unsigned long content_length, unsigned long content_length,
unsigned char **p, unsigned char **p, unsigned char *end)
unsigned char *end)
{ {
char b[24]; char b[24];
int n; int n;
...@@ -150,11 +147,10 @@ static const char *err500[] = { ...@@ -150,11 +147,10 @@ static const char *err500[] = {
"HTTP Version Not Supported" "HTTP Version Not Supported"
}; };
int lws_add_http_header_status(struct lws_context *context, int
struct lws *wsi, lws_add_http_header_status(struct lws_context *context, struct lws *wsi,
unsigned int code, unsigned int code, unsigned char **p,
unsigned char **p, unsigned char *end)
unsigned char *end)
{ {
unsigned char code_and_desc[60]; unsigned char code_and_desc[60];
const char *description = ""; const char *description = "";
...@@ -171,7 +167,8 @@ int lws_add_http_header_status(struct lws_context *context, ...@@ -171,7 +167,8 @@ int lws_add_http_header_status(struct lws_context *context,
n = sprintf((char *)code_and_desc, "HTTP/1.0 %u %s", code, description); n = sprintf((char *)code_and_desc, "HTTP/1.0 %u %s", code, description);
return lws_add_http_header_by_name(context, wsi, NULL, code_and_desc, n, p, end); return lws_add_http_header_by_name(context, wsi, NULL, code_and_desc,
n, p, end);
} }
/** /**
...@@ -184,25 +181,31 @@ int lws_add_http_header_status(struct lws_context *context, ...@@ -184,25 +181,31 @@ int lws_add_http_header_status(struct lws_context *context,
* Helper to report HTTP errors back to the client cleanly and * Helper to report HTTP errors back to the client cleanly and
* consistently * consistently
*/ */
LWS_VISIBLE int lws_return_http_status( LWS_VISIBLE int
struct lws_context *context, struct lws *wsi, lws_return_http_status(struct lws_context *context, struct lws *wsi,
unsigned int code, const char *html_body) unsigned int code, const char *html_body)
{ {
int n, m; int n, m;
unsigned char *p = context->service_buffer + LWS_SEND_BUFFER_PRE_PADDING; unsigned char *p = context->service_buffer +
LWS_SEND_BUFFER_PRE_PADDING;
unsigned char *start = p; unsigned char *start = p;
unsigned char *end = p + sizeof(context->service_buffer) - unsigned char *end = p + sizeof(context->service_buffer) -
LWS_SEND_BUFFER_PRE_PADDING; LWS_SEND_BUFFER_PRE_PADDING;
if (!html_body) if (!html_body)
html_body = ""; html_body = "";
if (lws_add_http_header_status(context, wsi, code, &p, end)) if (lws_add_http_header_status(context, wsi, code, &p, end))
return 1; return 1;
if (lws_add_http_header_by_token(context, wsi, WSI_TOKEN_HTTP_SERVER, (unsigned char *)"libwebsockets", 13, &p, end)) if (lws_add_http_header_by_token(context, wsi, WSI_TOKEN_HTTP_SERVER,
(unsigned char *)"libwebsockets", 13,
&p, end))
return 1; return 1;
if (lws_add_http_header_by_token(context, wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, (unsigned char *)"text/html", 9, &p, end)) if (lws_add_http_header_by_token(context, wsi,
WSI_TOKEN_HTTP_CONTENT_TYPE,
(unsigned char *)"text/html", 9,
&p, end))
return 1; return 1;
if (lws_finalize_http_header(context, wsi, &p, end)) if (lws_finalize_http_header(context, wsi, &p, end))
return 1; return 1;
...@@ -211,7 +214,8 @@ LWS_VISIBLE int lws_return_http_status( ...@@ -211,7 +214,8 @@ LWS_VISIBLE int lws_return_http_status(
if (m != (int)(p - start)) if (m != (int)(p - start))
return 1; return 1;
n = sprintf((char *)start, "<html><body><h1>%u</h1>%s</body></html>", code, html_body); n = sprintf((char *)start, "<html><body><h1>%u</h1>%s</body></html>",
code, html_body);
m = lws_write(wsi, start, n, LWS_WRITE_HTTP); m = lws_write(wsi, start, n, LWS_WRITE_HTTP);
return m != n; return m != n;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment