}
#endif
- wsi = malloc(sizeof(struct libwebsocket));
+ wsi = (struct libwebsocket *) malloc(sizeof(struct libwebsocket));
if (wsi == NULL)
goto bail1;
/* copy parameters over so state machine has access */
- wsi->c_path = malloc(strlen(path) + 1);
+ wsi->c_path = (char *)malloc(strlen(path) + 1);
if (wsi->c_path == NULL)
goto bail1;
strcpy(wsi->c_path, path);
- wsi->c_host = malloc(strlen(host) + 1);
+ wsi->c_host = (char *)malloc(strlen(host) + 1);
if (wsi->c_host == NULL)
goto oom1;
strcpy(wsi->c_host, host);
if (origin) {
- wsi->c_origin = malloc(strlen(origin) + 1);
+ wsi->c_origin = (char *)malloc(strlen(origin) + 1);
strcpy(wsi->c_origin, origin);
if (wsi->c_origin == NULL)
goto oom2;
const char *pc;
struct libwebsocket_protocols *pp;
- wsi->c_protocol = malloc(strlen(protocol) + 1);
+ wsi->c_protocol = (char *)malloc(strlen(protocol) + 1);
if (wsi->c_protocol == NULL)
goto oom3;
if (channel == 0) {
muxdebug("lws_mux_subcommand_header: given ch 0\n");
- *((int *)0) = 0;
+ assert(0);
}
if (channel < 31)
if (channel == 0) {
muxdebug("lws_ext_x_google_mux__send_addchannel: given ch 0\n");
- *((int *)0) = 0;
+ assert(0);
}
wsi_child->ietf_spec_revision = wsi->ietf_spec_revision;
case LWS_EXT_XGM_STATE__MUX_BLOCK_1:
// fprintf(stderr, "LWS_EXT_XGM_STATE__MUX_BLOCK_1: opc=%d channel=%d\n", c & 7, c >> 3);
- conn->block_subopcode = c & 7;
+ conn->block_subopcode = (enum lws_ext_x_goole_mux__mux_opcodes)(c & 7);
conn->block_subchannel = (c >> 3) & 0x1f;
conn->ignore_cmd = 0;
/* client: we received all server's ADD ack */
if (conn->block_subchannel != 1) {
- child_conn = lws_get_extension_user_matching_ext(
+ child_conn = (struct lws_ext_x_google_mux_conn *) lws_get_extension_user_matching_ext(
wsi_child, this_ext);
muxdebug("Received server's ADD Channel ACK for "
"subchannel %d child_conn=%p!\n",
/* reply with ADDCHANNEL to ack it */
wsi->xor_mask = xor_no_mask;
- child_conn = lws_get_extension_user_matching_ext(wsi_child,
+ child_conn = (struct lws_ext_x_google_mux_conn *)lws_get_extension_user_matching_ext(wsi_child,
this_ext);
if (!child_conn) {
fprintf(stderr, "wsi_child %p has no child conn!", (void *)wsi_child);
int n;
struct lws_tokens *eff_buf = (struct lws_tokens *)in;
unsigned char *p = NULL;
- struct lws_ext_x_google_mux_context *mux_ctx =
+ struct lws_ext_x_google_mux_context *mux_ctx = (struct lws_ext_x_google_mux_context *)
ext->per_context_private_data;
struct libwebsocket *wsi_parent;
struct libwebsocket *wsi_child;
continue;
muxdebug(" %s / %s\n", wsi_parent->c_address, (char *)in);
- if (strcmp(wsi_parent->c_address, in))
+ if (strcmp((const char*)wsi_parent->c_address, (const char *)in))
continue;
muxdebug(" %u / %u\n", wsi_parent->c_port, (unsigned int)len);
parent_conn = conn;
} else {
- parent_conn = lws_get_extension_user_matching_ext(conn->wsi_parent, ext);
+ parent_conn = (struct lws_ext_x_google_mux_conn *)lws_get_extension_user_matching_ext(conn->wsi_parent, ext);
if (parent_conn == 0) {
muxdebug("failed to get parent conn\n");
break;
} else {
wsi_parent = conn->wsi_parent;
- parent_conn = lws_get_extension_user_matching_ext(conn->wsi_parent, ext);
+ parent_conn = (struct lws_ext_x_google_mux_conn *)lws_get_extension_user_matching_ext(conn->wsi_parent, ext);
if (parent_conn == 0) {
muxdebug("failed to get parent conn\n");
break;
* get parent / transport mux context
*/
- parent_conn = lws_get_extension_user_matching_ext(conn->wsi_parent, ext);
+ parent_conn = (struct lws_ext_x_google_mux_conn *)lws_get_extension_user_matching_ext(conn->wsi_parent, ext);
if (parent_conn == 0) {
muxdebug("failed to get parent conn\n");
return 0;
/* disallow deflate-stream if we are a mux child connection */
- if (strcmp(in, "deflate-stream") == 0 &&
+ if (strcmp((const char*)in, "deflate-stream") == 0 &&
client_handshake_generation_is_for_mux_child) {
muxdebug("mux banned deflate-stream on child connection\n");
/* make a buffer big enough for everything */
- response = malloc(256 +
+ response = (char *)malloc(256 +
wsi->utf8_token[WSI_TOKEN_UPGRADE].token_len +
wsi->utf8_token[WSI_TOKEN_CONNECTION].token_len +
wsi->utf8_token[WSI_TOKEN_HOST].token_len +
/* it's complete: go ahead and send it */
- debug("issuing response packet %d len\n", (int)(p - response));
-#ifdef DEBUG
+ _debug("issuing response packet %d len\n", (int)(p - response));
+#ifdef _DEBUG
fwrite(response, 1, p - response, stderr);
#endif
n = libwebsocket_write(wsi, (unsigned char *)response,
if (!wsi->utf8_token[WSI_TOKEN_HOST].token_len ||
!wsi->utf8_token[WSI_TOKEN_KEY].token_len) {
- debug("handshake_04 missing pieces\n");
+ _debug("handshake_04 missing pieces\n");
/* completed header processing, but missing some bits */
goto bail;
}
/* make a buffer big enough for everything */
- response = malloc(256 +
+ response = (char *)malloc(256 +
wsi->utf8_token[WSI_TOKEN_UPGRADE].token_len +
wsi->utf8_token[WSI_TOKEN_CONNECTION].token_len +
wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len);
/* okay send the handshake response accepting the connection */
- debug("issuing response packet %d len\n", (int)(p - response));
+ _debug("issuing response packet %d len\n", (int)(p - response));
#ifdef DEBUG
fwrite(response, 1, p - response, stderr);
#endif
/* fallthru */
case WSI_STATE_HTTP_HEADERS:
- debug("issuing %d bytes to parser\n", (int)len);
-#ifdef DEBUG
+ _debug("issuing %d bytes to parser\n", (int)len);
+#ifdef _DEBUG
fwrite(buf, 1, len, stderr);
#endif
break;
case 4: /* 04 */
wsi->xor_mask = xor_mask_04;
- debug("libwebsocket_parse calling handshake_04\n");
+ _debug("libwebsocket_parse calling handshake_04\n");
if (handshake_0405(context, wsi))
goto bail;
break;
case 8:
case 13:
wsi->xor_mask = xor_mask_05;
- debug("libwebsocket_parse calling handshake_04\n");
+ _debug("libwebsocket_parse calling handshake_04\n");
if (handshake_0405(context, wsi))
goto bail;
break;
void *buf, int len)
{
int n;
- char *p = buf;
+ char *p = (char *)buf;
#ifdef WIN32
for (n = 0; n < len; n++)
else
n = LWS_CALLBACK_SERVER_WRITEABLE;
- wsi->protocol->callback(context, wsi, n, wsi->user_space, NULL, 0);
+ wsi->protocol->callback(context, wsi, (enum libwebsocket_callback_reasons) n, wsi->user_space, NULL, 0);
return 0;
}
struct libwebsocket *new_wsi;
int n;
- new_wsi = malloc(sizeof(struct libwebsocket));
+ new_wsi = (struct libwebsocket *)malloc(sizeof(struct libwebsocket));
if (new_wsi == NULL) {
fprintf(stderr, "Out of memory for new connection\n");
return NULL;
wsi->state = WSI_STATE_ESTABLISHED;
wsi->mode = LWS_CONNMODE_WS_CLIENT;
- debug("handshake OK for protocol %s\n", wsi->protocol->name);
+ _debug("handshake OK for protocol %s\n", wsi->protocol->name);
/* call him back to inform him he is up */
* ssl params which fail then retry
* and succeed
*/
- debug("SSL_accept failed skt %u: %s\n",
+ _debug("SSL_accept failed skt %u: %s\n",
pollfd->fd,
ERR_error_string(SSL_get_error(
new_wsi->ssl, n), NULL));
break;
}
- debug("accepted new SSL conn "
+ _debug("accepted new SSL conn "
"port %u on fd=%d SSL ver %s\n",
ntohs(cli_addr.sin_port), accept_fd,
SSL_get_version(new_wsi->ssl));
} else
#endif
- debug("accepted new conn port %u on fd=%d\n",
+ _debug("accepted new conn port %u on fd=%d\n",
ntohs(cli_addr.sin_port), accept_fd);
insert_wsi(context, new_wsi);
/* create a dummy wsi for the connection and add it */
- new_wsi = malloc(sizeof(struct libwebsocket));
- memset(new_wsi, 0, sizeof(struct libwebsocket));
+ new_wsi = (struct libwebsocket *)malloc(sizeof(struct libwebsocket));
+ memset(new_wsi, 0, sizeof (struct libwebsocket));
new_wsi->sock = accept_fd;
new_wsi->mode = LWS_CONNMODE_BROADCAST_PROXY;
new_wsi->state = WSI_STATE_ESTABLISHED;
if (pollfd->revents & (POLLERR | POLLHUP)) {
- debug("Session Socket %p (fd=%d) dead\n",
+ _debug("Session Socket %p (fd=%d) dead\n",
(void *)wsi, pollfd->fd);
libwebsocket_close_and_free_session(context, wsi,
if (context->listen_port)
m = LWS_EXT_CALLBACK_SERVER_CONTEXT_DESTRUCT;
while (ext && ext->callback) {
- ext->callback(context, ext, NULL, m, NULL, NULL, 0);
+ ext->callback(context, ext, NULL, (enum libwebsocket_extension_callback_reasons)m, NULL, NULL, 0);
ext++;
}
#endif
- context = malloc(sizeof(struct libwebsocket_context));
+ context = (struct libwebsocket_context *) malloc(sizeof(struct libwebsocket_context));
if (!context) {
fprintf(stderr, "No memory for websocket context\n");
return NULL;
return NULL;
}
- wsi = malloc(sizeof(struct libwebsocket));
- memset(wsi, 0, sizeof(struct libwebsocket));
+ wsi = (struct libwebsocket *)malloc(sizeof(struct libwebsocket));
+ memset(wsi, 0, sizeof (struct libwebsocket));
wsi->sock = sockfd;
wsi->count_active_extensions = 0;
wsi->mode = LWS_CONNMODE_SERVER_LISTENER;
protocols[context->count_protocols].callback;
context->count_protocols++) {
- debug(" Protocol: %s\n", protocols[context->count_protocols].name);
+ _debug(" Protocol: %s\n", protocols[context->count_protocols].name);
protocols[context->count_protocols].owning_server = context;
protocols[context->count_protocols].protocol_index =
ntohs(cli_addr.sin_port);
listen(fd, 5);
- debug(" Protocol %s broadcast socket %d\n",
+ _debug(" Protocol %s broadcast socket %d\n",
protocols[context->count_protocols].name,
ntohs(cli_addr.sin_port));
/* dummy wsi per broadcast proxy socket */
- wsi = malloc(sizeof(struct libwebsocket));
- memset(wsi, 0, sizeof(struct libwebsocket));
+ wsi = (struct libwebsocket *)malloc(sizeof(struct libwebsocket));
+ memset(wsi, 0, sizeof (struct libwebsocket));
wsi->sock = fd;
wsi->mode = LWS_CONNMODE_BROADCAST_PROXY_LISTENER;
wsi->count_active_extensions = 0;
if (extensions) {
while (extensions->callback) {
debug(" Extension: %s\n", extensions->name);
- extensions->callback(context, extensions,
- NULL, m, NULL, NULL, 0);
+ extensions->callback(context, extensions, NULL,
+ (enum libwebsocket_extension_callback_reasons)m,
+ NULL, NULL, 0);
extensions++;
}
}
case WSI_TOKEN_HTTP:
case WSI_TOKEN_MUXURL:
- debug("WSI_TOKEN_(%d) '%c'\n", wsi->parser_state, c);
+ _debug("WSI_TOKEN_(%d) '%c'\n", wsi->parser_state, c);
/* collect into malloc'd buffers */
/* optional space swallow */
wsi->parser_state = WSI_TOKEN_SKIPPING;
break;
}
- wsi->utf8_token[wsi->parser_state].token =
+ wsi->utf8_token[wsi->parser_state].token = (char *)
realloc(wsi->utf8_token[wsi->parser_state].token,
wsi->current_alloc_len);
}
wsi->utf8_token[wsi->parser_state].token[
wsi->utf8_token[wsi->parser_state].token_len] = '\0';
wsi->parser_state = WSI_TOKEN_SKIPPING_SAW_CR;
- debug("*\n");
+ _debug("*\n");
break;
}
/* For any supported protocol we have enough payload */
- debug("Setting WSI_PARSING_COMPLETE\n");
+ _debug("Setting WSI_PARSING_COMPLETE\n");
wsi->parser_state = WSI_PARSING_COMPLETE;
break;
wsi->parser_state = WSI_TOKEN_MUXURL;
wsi->current_alloc_len = LWS_INITIAL_HDR_ALLOC;
- wsi->utf8_token[wsi->parser_state].token =
+ wsi->utf8_token[wsi->parser_state].token = (char *)
malloc(wsi->current_alloc_len);
wsi->utf8_token[wsi->parser_state].token_len = 0;
break;
/* collecting and checking a name part */
case WSI_TOKEN_NAME_PART:
- debug("WSI_TOKEN_NAME_PART '%c'\n", c);
+ _debug("WSI_TOKEN_NAME_PART '%c'\n", c);
if (wsi->name_buffer_pos == sizeof(wsi->name_buffer) - 1) {
/* name bigger than we can handle, skip until next */
continue;
if (strcasecmp(lws_tokens[n].token, wsi->name_buffer))
continue;
- debug("known hdr '%s'\n", wsi->name_buffer);
+ _debug("known hdr '%s'\n", wsi->name_buffer);
/*
* WSORIGIN is protocol equiv to ORIGIN,
if (n == WSI_TOKEN_SWORIGIN)
n = WSI_TOKEN_ORIGIN;
- wsi->parser_state = WSI_TOKEN_GET_URI + n;
+ wsi->parser_state = (enum lws_token_indexes) (WSI_TOKEN_GET_URI + n);
n = WSI_TOKEN_COUNT;
continue;
wsi->current_alloc_len = LWS_INITIAL_HDR_ALLOC;
- wsi->utf8_token[wsi->parser_state].token =
+ wsi->utf8_token[wsi->parser_state].token = (char *)
malloc(wsi->current_alloc_len);
wsi->utf8_token[wsi->parser_state].token_len = 0;
}
wsi->parser_state = WSI_TOKEN_GET_URI;
wsi->current_alloc_len = LWS_INITIAL_HDR_ALLOC;
wsi->utf8_token[WSI_TOKEN_GET_URI].token =
- malloc(wsi->current_alloc_len);
+ (char *)malloc(wsi->current_alloc_len);
break;
}
}
if (!wsi->utf8_token[WSI_TOKEN_UPGRADE].token_len) {
/* they're HTTP headers, not websocket upgrade! */
- debug("Setting WSI_PARSING_COMPLETE "
+ _debug("Setting WSI_PARSING_COMPLETE "
"from http headers\n");
wsi->parser_state = WSI_PARSING_COMPLETE;
}
if (wsi->utf8_token[WSI_TOKEN_VERSION].token_len &&
atoi(wsi->utf8_token[WSI_TOKEN_VERSION].token) >= 4) {
- debug("04 header completed\n");
+ _debug("04 header completed\n");
wsi->parser_state = WSI_PARSING_COMPLETE;
wsi->utf8_token[WSI_TOKEN_CHALLENGE].token_len = 0;
free(wsi->utf8_token[WSI_TOKEN_CHALLENGE].token);
/* client parser? */
if (wsi->ietf_spec_revision >= 4) {
- debug("04 header completed\n");
+ _debug("04 header completed\n");
wsi->parser_state = WSI_PARSING_COMPLETE;
}
/* skipping arg part of a name we didn't recognize */
case WSI_TOKEN_SKIPPING:
- debug("WSI_TOKEN_SKIPPING '%c'\n", c);
+ _debug("WSI_TOKEN_SKIPPING '%c'\n", c);
if (c == '\x0d')
wsi->parser_state = WSI_TOKEN_SKIPPING_SAW_CR;
break;
case WSI_TOKEN_SKIPPING_SAW_CR:
- debug("WSI_TOKEN_SKIPPING_SAW_CR '%c'\n", c);
+ _debug("WSI_TOKEN_SKIPPING_SAW_CR '%c'\n", c);
if (c == '\x0a')
wsi->parser_state = WSI_TOKEN_NAME_PART;
else
break;
/* we're done, ignore anything else */
case WSI_PARSING_COMPLETE:
- debug("WSI_PARSING_COMPLETE '%c'\n", c);
+ _debug("WSI_PARSING_COMPLETE '%c'\n", c);
break;
default: /* keep gcc happy */
if (c)
break;
- debug("Seen that client is requesting "
+ _debug("Seen that client is requesting "
"a v76 close, sending ack\n");
buf[0] = 0xff;
buf[1] = 0;
fprintf(stderr, "ERROR writing to socket");
return -1;
}
- debug(" v76 close ack sent, server closing skt\n");
+ _debug(" v76 close ack sent, server closing skt\n");
/* returning < 0 will get it closed in parent */
return -1;
* layer? If so service it and hide it from the user callback
*/
- debug("spill on %s\n", wsi->protocol->name);
+ _debug("spill on %s\n", wsi->protocol->name);
switch (wsi->opcode) {
case LWS_WS_OPCODE_07__CLOSE:
* fine he has told us he is closing too, let's
* finish our close
*/
- debug("seen client close ack\n");
+ _debug("seen client close ack\n");
return -1;
}
debug("server sees client close packet\n");
default:
- debug("passing opcode %x up to exts\n", wsi->opcode);
+ _debug("passing opcode %x up to exts\n", wsi->opcode);
/*
* It's something special we can't understand here.
struct lws_tokens eff_buf;
int m;
- debug(" CRX: %02X %d\n", c, wsi->lws_rx_parse_state);
+ _debug(" CRX: %02X %d\n", c, wsi->lws_rx_parse_state);
switch (wsi->lws_rx_parse_state) {
case LWS_RXPS_NEW:
if (c)
break;
- debug("Seen that client is requesting "
+ _debug("Seen that client is requesting "
"a v76 close, sending ack\n");
buf[0] = 0xff;
buf[1] = 0;
fprintf(stderr, "ERROR writing to socket");
return -1;
}
- debug(" v76 close ack sent, server closing skt\n");
+ _debug(" v76 close ack sent, server closing skt\n");
/* returning < 0 will get it closed in parent */
return -1;
debug("seen server's close ack\n");
return -1;
}
- debug("client sees server close packet len = %d\n", wsi->rx_user_buffer_head);
+ _debug("client sees server close packet len = %d\n", wsi->rx_user_buffer_head);
/* parrot the close packet payload back */
n = libwebsocket_write(wsi, (unsigned char *)
&wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
wsi->rx_user_buffer_head, LWS_WRITE_CLOSE);
- debug("client writing close ack returned %d\n", n);
+ _debug("client writing close ack returned %d\n", n);
wsi->state = WSI_STATE_RETURNED_CLOSE_ALREADY;
/* close the connection */
return -1;
if (wsi->protocol->callback)
wsi->protocol->callback(
wsi->protocol->owning_server,
- wsi, callback_action,
+ wsi,
+ (enum libwebsocket_callback_reasons)callback_action,
wsi->user_space,
eff_buf.token,
eff_buf.token_len);
eff_buf.token_len))
return -1;
- debug("written %d bytes to client\n", eff_buf.token_len);
+ _debug("written %d bytes to client\n", eff_buf.token_len);
/* no extension has more to spill */
#include "libwebsockets.h"
#if 0
-#define DEBUG
+#define _DEBUG
#endif
-#ifdef DEBUG
+#ifdef _DEBUG
#ifdef WIN32
-static
+#define _debug(...) lws_log(LWS_LOG_DEBUG, __VA_ARGS__)
#else
static inline
#endif
}
#else
#ifdef WIN32
-#define debug(...)
+#define _debug(...)
#else
static inline
-void debug(const char *format, ...)
+void _debug(const char *format, ...)
{
}
#endif