} else
triple[i] = 0;
}
- if (len) {
+ if (!len)
+ continue;
- if (done + 4 >= out_size)
- return -1;
+ if (done + 4 >= out_size)
+ return -1;
- *out++ = encode[triple[0] >> 2];
- *out++ = encode[((triple[0] & 0x03) << 4) |
- ((triple[1] & 0xf0) >> 4)];
- *out++ = (len > 1 ? encode[((triple[1] & 0x0f) << 2) |
+ *out++ = encode[triple[0] >> 2];
+ *out++ = encode[((triple[0] & 0x03) << 4) |
+ ((triple[1] & 0xf0) >> 4)];
+ *out++ = (len > 1 ? encode[((triple[1] & 0x0f) << 2) |
((triple[2] & 0xc0) >> 6)] : '=');
- *out++ = (len > 2 ? encode[triple[2] & 0x3f] : '=');
+ *out++ = (len > 2 ? encode[triple[2] & 0x3f] : '=');
- done += 4;
- line += 4;
- }
-#if 0
- if (line >= 72) {
-
- if (done + 2 >= out_size)
- return -1;
-
- *out++ = '\r';
- *out++ = '\n';
- done += 2;
- line = 0;
- }
-#endif
+ done += 4;
+ line += 4;
}
if (done + 1 >= out_size)
char buf[64];
int n;
int test;
- static const char *plaintext[] = {
+ static const char * const plaintext[] = {
"sanity check base 64"
};
- static const char *coded[] = {
+ static const char * const coded[] = {
"c2FuaXR5IGNoZWNrIGJhc2UgNjQ="
};
#include <netdb.h>
-struct libwebsocket * __libwebsocket_client_connect_2(
+struct libwebsocket *__libwebsocket_client_connect_2(
struct libwebsocket_context *context,
struct libwebsocket *wsi
) {
char pkt[512];
int opt = 1;
#if defined(__APPLE__)
- struct protoent* tcp_proto;
+ struct protoent *tcp_proto;
#endif
debug("__libwebsocket_client_connect_2\n");
/* Disable Nagle */
#if !defined(__APPLE__)
- setsockopt(wsi->sock, SOL_TCP, TCP_NODELAY, (const void *)&opt, sizeof(opt));
+ setsockopt(wsi->sock, SOL_TCP, TCP_NODELAY,
+ (const void *)&opt, sizeof(opt));
#else
- tcp_proto = getprotobyname("TCP");
- setsockopt(wsi->sock, tcp_proto->p_proto, TCP_NODELAY, &opt, sizeof(opt));
+ tcp_proto = getprotobyname("TCP");
+ setsockopt(wsi->sock, tcp_proto->p_proto, TCP_NODELAY,
+ &opt, sizeof(opt));
#endif
/* Set receiving timeout */
setsockopt(wsi->sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof tv);
if (connect(wsi->sock, (struct sockaddr *)&server_addr,
- sizeof(struct sockaddr)) == -1) {
+ sizeof(struct sockaddr)) == -1) {
fprintf(stderr, "Connect failed\n");
goto oom4;
}
* the server, or just one. The server will pick the one it
* likes best.
* @ietf_version_or_minus_one: -1 to ask to connect using the default, latest
- * protocol supported, or the specific protocol ordinal
+ * protocol supported, or the specific protocol ordinal
*
* This function creates a connection to a remote server
*/
if (wsi->c_path == NULL)
goto bail1;
strcpy(wsi->c_path, path);
+
wsi->c_host = 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);
strcpy(wsi->c_origin, origin);
goto oom2;
} else
wsi->c_origin = NULL;
+
if (protocol) {
wsi->c_protocol = malloc(strlen(protocol) + 1);
if (wsi->c_protocol == NULL)
} else
wsi->c_protocol = NULL;
-
/* set up appropriate masking */
wsi->xor_mask = xor_no_mask;
#include "private-libwebsockets.h"
+#define LWS_CPYAPP(ptr, str) { strcpy(ptr, str); ptr += strlen(str); }
+#define LWS_CPYAPP_TOKEN(ptr, tok) { strcpy(p, wsi->utf8_token[tok].token); \
+ p += wsi->utf8_token[tok].token_len; }
static int
interpret_key(const char *key, unsigned long *result)
int rem = 0;
while (*p) {
- if (isdigit(*p)) {
- if (digit_pos == sizeof(digits) - 1)
- return -1;
- digits[digit_pos++] = *p;
+ if (!isdigit(*p)) {
+ p++;
+ continue;
}
- p++;
+ if (digit_pos == sizeof(digits) - 1)
+ return -1;
+ digits[digit_pos++] = *p++;
}
digits[digit_pos] = '\0';
if (!digit_pos)
goto bail;
/* allocate the per-connection user memory (if any) */
- if (wsi->protocol->per_session_data_size && !libwebsocket_ensure_user_space(wsi))
- goto bail;
+ if (wsi->protocol->per_session_data_size &&
+ !libwebsocket_ensure_user_space(wsi))
+ goto bail;
/* create the response packet */
}
p = response;
- strcpy(p, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a"
- "Upgrade: WebSocket\x0d\x0a");
- p += strlen("HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a"
- "Upgrade: WebSocket\x0d\x0a");
- strcpy(p, "Connection: Upgrade\x0d\x0a"
- "Sec-WebSocket-Origin: ");
- p += strlen("Connection: Upgrade\x0d\x0a"
- "Sec-WebSocket-Origin: ");
+ LWS_CPYAPP(p, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a"
+ "Upgrade: WebSocket\x0d\x0a"
+ "Connection: Upgrade\x0d\x0a"
+ "Sec-WebSocket-Origin: ");
strcpy(p, wsi->utf8_token[WSI_TOKEN_ORIGIN].token);
p += wsi->utf8_token[WSI_TOKEN_ORIGIN].token_len;
#ifdef LWS_OPENSSL_SUPPORT
- if (wsi->ssl) {
- strcpy(p, "\x0d\x0aSec-WebSocket-Location: wss://");
- p += strlen("\x0d\x0aSec-WebSocket-Location: wss://");
- } else {
-#endif
- strcpy(p, "\x0d\x0aSec-WebSocket-Location: ws://");
- p += strlen("\x0d\x0aSec-WebSocket-Location: ws://");
-#ifdef LWS_OPENSSL_SUPPORT
- }
+ if (wsi->ssl)
+ LWS_CPYAPP(p, "\x0d\x0aSec-WebSocket-Location: wss://");
+ else
#endif
- strcpy(p, wsi->utf8_token[WSI_TOKEN_HOST].token);
- p += wsi->utf8_token[WSI_TOKEN_HOST].token_len;
- strcpy(p, wsi->utf8_token[WSI_TOKEN_GET_URI].token);
- p += wsi->utf8_token[WSI_TOKEN_GET_URI].token_len;
+ LWS_CPYAPP(p, "\x0d\x0aSec-WebSocket-Location: ws://");
+
+ LWS_CPYAPP_TOKEN(p, WSI_TOKEN_HOST);
+ LWS_CPYAPP_TOKEN(p, WSI_TOKEN_GET_URI);
if (wsi->utf8_token[WSI_TOKEN_PROTOCOL].token) {
- strcpy(p, "\x0d\x0aSec-WebSocket-Protocol: ");
- p += strlen("\x0d\x0aSec-WebSocket-Protocol: ");
- strcpy(p, wsi->utf8_token[WSI_TOKEN_PROTOCOL].token);
- p += wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len;
+ LWS_CPYAPP(p, "\x0d\x0aSec-WebSocket-Protocol: ");
+ LWS_CPYAPP_TOKEN(p, WSI_TOKEN_PROTOCOL);
}
- strcpy(p, "\x0d\x0a\x0d\x0a");
- p += strlen("\x0d\x0a\x0d\x0a");
+ LWS_CPYAPP(p, "\x0d\x0a\x0d\x0a");
/* convert the two keys into 32-bit integers */
int accept_len;
char *c;
char ext_name[128];
- struct libwebsocket_extension * ext;
+ struct libwebsocket_extension *ext;
int ext_count = 0;
int more = 1;
}
/* allocate the per-connection user memory (if any) */
- if (wsi->protocol->per_session_data_size && !libwebsocket_ensure_user_space(wsi))
- goto bail;
+ if (wsi->protocol->per_session_data_size &&
+ !libwebsocket_ensure_user_space(wsi))
+ goto bail;
/* create the response packet */
}
p = response;
- strcpy(p, "HTTP/1.1 101 Switching Protocols\x0d\x0a"
- "Upgrade: WebSocket\x0d\x0a");
- p += strlen("HTTP/1.1 101 Switching Protocols\x0d\x0a"
- "Upgrade: WebSocket\x0d\x0a");
- strcpy(p, "Connection: Upgrade\x0d\x0a"
- "Sec-WebSocket-Accept: ");
- p += strlen("Connection: Upgrade\x0d\x0a"
- "Sec-WebSocket-Accept: ");
+ LWS_CPYAPP(p, "HTTP/1.1 101 Switching Protocols\x0d\x0a"
+ "Upgrade: WebSocket\x0d\x0a"
+ "Connection: Upgrade\x0d\x0a"
+ "Sec-WebSocket-Accept: ");
strcpy(p, accept_buf);
p += accept_len;
if (wsi->ietf_spec_revision == 4) {
- strcpy(p, "\x0d\x0aSec-WebSocket-Nonce: ");
- p += strlen("\x0d\x0aSec-WebSocket-Nonce: ");
+ LWS_CPYAPP(p, "\x0d\x0aSec-WebSocket-Nonce: ");
/* select the nonce */
}
if (wsi->utf8_token[WSI_TOKEN_PROTOCOL].token) {
- strcpy(p, "\x0d\x0aSec-WebSocket-Protocol: ");
- p += strlen("\x0d\x0aSec-WebSocket-Protocol: ");
- strcpy(p, wsi->utf8_token[WSI_TOKEN_PROTOCOL].token);
- p += wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len;
+ LWS_CPYAPP(p, "\x0d\x0aSec-WebSocket-Protocol: ");
+ LWS_CPYAPP_TOKEN(p, WSI_TOKEN_PROTOCOL);
}
/*
*/
c = wsi->utf8_token[WSI_TOKEN_EXTENSIONS].token;
- debug("wsi->utf8_token[WSI_TOKEN_EXTENSIONS].token = %s\n", wsi->utf8_token[WSI_TOKEN_EXTENSIONS].token);
+ debug("wsi->utf8_token[WSI_TOKEN_EXTENSIONS].token = %s\n",
+ wsi->utf8_token[WSI_TOKEN_EXTENSIONS].token);
wsi->count_active_extensions = 0;
n = 0;
while (more) {
-
+
if (*c && (*c != ',' && *c != ' ' && *c != '\t')) {
ext_name[n] = *c++;
if (n < sizeof(ext_name) - 1)
}
/* apply it */
-
+
if (ext_count)
*p++ = ',';
- else {
- strcpy(p, "\x0d\x0aSec-WebSocket-Extensions: ");
- p += strlen("\x0d\x0aSec-WebSocket-Extensions: ");
- }
+ else
+ LWS_CPYAPP(p,
+ "\x0d\x0aSec-WebSocket-Extensions: ");
p += sprintf(p, "%s", ext_name);
ext_count++;
memset(wsi->active_extensions_user[
wsi->count_active_extensions], 0,
ext->per_session_data_size);
-
+
wsi->active_extensions[
wsi->count_active_extensions] = ext;
/* end of response packet */
- strcpy(p, "\x0d\x0a\x0d\x0a");
- p += strlen("\x0d\x0a\x0d\x0a");
+ LWS_CPYAPP(p, "\x0d\x0a\x0d\x0a");
if (wsi->ietf_spec_revision == 4) {
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 */
*/
int
-libwebsocket_read(struct libwebsocket_context *context, struct libwebsocket *wsi,
- unsigned char * buf, size_t len)
+libwebsocket_read(struct libwebsocket_context *context,
+ struct libwebsocket *wsi, unsigned char * buf, size_t len)
{
size_t n;
default:
break;
}
-
+
/* LWS_CONNMODE_WS_SERVING */
for (n = 0; n < len; n++)
}
if (!wsi->protocol)
- fprintf(stderr, "NULL protocol coming on libwebsocket_read\n");
+ fprintf(stderr, "NULL protocol at libwebsocket_read\n");
/*
* It's websocket
static int
-interface_to_sa(const char* ifname, struct sockaddr_in *addr, size_t addrlen)
+interface_to_sa(const char *ifname, struct sockaddr_in *addr, size_t addrlen)
{
int rc = -1;
#ifdef WIN32
- // TODO
+ /* TODO */
#else
struct ifaddrs *ifr;
struct ifaddrs *ifc;
if (sin->sin_family != AF_INET)
continue;
memcpy(addr, sin, addrlen);
- rc = 0;
+ rc = 0;
}
freeifaddrs(ifr);
/* tell the user it's all over for this guy */
if (wsi->protocol && wsi->protocol->callback &&
- ((old_state == WSI_STATE_ESTABLISHED) ||
- (old_state == WSI_STATE_RETURNED_CLOSE_ALREADY) ||
- (old_state == WSI_STATE_AWAITING_CLOSE_ACK))) {
+ ((old_state == WSI_STATE_ESTABLISHED) ||
+ (old_state == WSI_STATE_RETURNED_CLOSE_ALREADY) ||
+ (old_state == WSI_STATE_AWAITING_CLOSE_ACK))) {
debug("calling back CLOSED\n");
wsi->protocol->callback(context, wsi, LWS_CALLBACK_CLOSED,
wsi->user_space, NULL, 0);
} else
- debug("not calling back closed due to old_state=%d\n",
- old_state);
-
+ debug("not calling back closed, old_state=%d\n", old_state);
/* deallocate any active extension contexts */
/**
* libwebsockets_hangup_on_client() - Server calls to terminate client
- * connection
+ * connection
* @context: libwebsockets context
* @fd: Connection socket descriptor
*/
* @rip_len: Length of client address IP buffer
*
* This function fills in @name and @rip with the name and IP of
- * the client connected with socket descriptor @fd. Names may be
- * truncated if there is not enough room. If either cannot be
- * determined, they will be returned as valid zero-length strings.
+ * the client connected with socket descriptor @fd. Names may be
+ * truncated if there is not enough room. If either cannot be
+ * determined, they will be returned as valid zero-length strings.
*/
void
perror("getpeername");
return;
}
-
+
host = gethostbyaddr((char *) &sin.sin_addr, sizeof sin.sin_addr,
AF_INET);
if (host == NULL) {
#ifdef AF_LOCAL
else {
un = (struct sockaddr_un *)p;
- strncpy(ip, un->sun_path, sizeof(ip) -1);
+ strncpy(ip, un->sun_path, sizeof(ip) - 1);
ip[sizeof(ip) - 1] = '\0';
}
#endif
void libwebsockets_00_spaceout(char *key, int spaces, int seed)
{
char *p;
-
+
key++;
while (spaces--) {
if (*key && (seed & 1))
key++;
seed >>= 1;
-
+
p = key + strlen(key);
while (p >= key) {
p[1] = p[0];
key++;
while (count--) {
-
+
if (*key && (seed & 1))
key++;
seed >>= 1;
LWS_EXT_CALLBACK_PACKET_TX_PRESEND,
wsi->active_extensions_user[n], &eff_buf, 0);
if (m < 0) {
- fprintf(stderr, "extension reports fatal error\n");
+ fprintf(stderr, "ext reports fatal error\n");
return -1;
}
if (m)
if (!wsi->pending_timeout)
return;
-
+
/*
* if we went beyond the allowed time, kill the
* connection
return NULL;
}
- memset(new_wsi, 0, sizeof (struct libwebsocket));
+ memset(new_wsi, 0, sizeof(struct libwebsocket));
new_wsi->count_active_extensions = 0;
new_wsi->pending_timeout = NO_PENDING_TIMEOUT;
struct libwebsocket_extension *ext;
struct libwebsocket_extension *ext1;
int ext_count = 0;
- unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 1 + MAX_BROADCAST_PAYLOAD +
- LWS_SEND_BUFFER_POST_PADDING];
+ unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 1 +
+ MAX_BROADCAST_PAYLOAD + LWS_SEND_BUFFER_POST_PADDING];
static const char magic_websocket_guid[] =
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
unsigned int count;
char challenge[16];
- libwebsockets_get_random(context, &spaces_1,
- sizeof(char));
- libwebsockets_get_random(context, &spaces_2,
- sizeof(char));
+ libwebsockets_get_random(context, &spaces_1, sizeof(char));
+ libwebsockets_get_random(context, &spaces_2, sizeof(char));
spaces_1 = (spaces_1 % 12) + 1;
spaces_2 = (spaces_2 % 12) + 1;
"Connection: Upgrade\x0d\x0aHost: %s\x0d\x0a",
wsi->c_host);
if (wsi->c_origin)
- p += sprintf(p, "Origin: %s\x0d\x0a",
- wsi->c_origin);
+ p += sprintf(p, "Origin: %s\x0d\x0a", wsi->c_origin);
if (wsi->c_protocol)
p += sprintf(p, "Sec-WebSocket-Protocol: %s"
"\x0d\x0a", wsi->c_protocol);
- p += sprintf(p, "Sec-WebSocket-Key1: %s\x0d\x0a",
- key_1);
- p += sprintf(p, "Sec-WebSocket-Key2: %s\x0d\x0a",
- key_2);
+ p += sprintf(p, "Sec-WebSocket-Key1: %s\x0d\x0a", key_1);
+ p += sprintf(p, "Sec-WebSocket-Key2: %s\x0d\x0a", key_2);
/* give userland a chance to append, eg, cookies */
p += sprintf(p, "Sec-WebSocket-Extensions: ");
- ext =context->extensions;
+ ext = context->extensions;
while (ext && ext->callback) {
n = 0;
ext1 = context->extensions;
- while (ext1 && ext1->callback) {
+ while (ext1 && ext1->callback) {
n |= ext1->callback(context, ext1, wsi,
LWS_EXT_CALLBACK_CHECK_OK_TO_PROPOSE_EXTENSION,
NULL, (char *)ext->name, 0);
ext1++;
}
- if (n) {
-
- /* an extension vetos us */
+ if (n) { /* an extension vetos us */
debug("ext %s vetoed\n", (char *)ext->name);
ext++;
continue;
issue_hdr:
-// puts(pkt);
+#if 0
+ puts(pkt);
+#endif
/* done with these now */
lws_client_interpret_server_handshake(struct libwebsocket_context *context,
struct libwebsocket *wsi)
{
- unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 1 + MAX_BROADCAST_PAYLOAD +
- LWS_SEND_BUFFER_POST_PADDING];
+ unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 1 +
+ MAX_BROADCAST_PAYLOAD + LWS_SEND_BUFFER_POST_PADDING];
char pkt[1024];
char *p = &pkt[0];
const char *pc;
}
strtolower(wsi->utf8_token[WSI_TOKEN_HTTP].token);
- if (strncmp(wsi->utf8_token[WSI_TOKEN_HTTP].token,
- "101", 3)) {
+ if (strncmp(wsi->utf8_token[WSI_TOKEN_HTTP].token, "101", 3)) {
fprintf(stderr, "libwebsocket_client_handshake "
"server sent bad HTTP response '%s'\n",
wsi->utf8_token[WSI_TOKEN_HTTP].token);
goto bail3;
}
- if (wsi->utf8_token[WSI_TOKEN_CHALLENGE].token_len <
- 16) {
+ if (wsi->utf8_token[WSI_TOKEN_CHALLENGE].token_len < 16) {
fprintf(stderr, "libwebsocket_client_handshake "
"challenge reply too short %d\n",
wsi->utf8_token[
* Now let's confirm it sent all the necessary headers
*/
#if 0
- fprintf(stderr, "WSI_TOKEN_HTTP: %d\n", wsi->utf8_token[WSI_TOKEN_HTTP].token_len);
- fprintf(stderr, "WSI_TOKEN_UPGRADE: %d\n", wsi->utf8_token[WSI_TOKEN_UPGRADE].token_len);
- fprintf(stderr, "WSI_TOKEN_CONNECTION: %d\n", wsi->utf8_token[WSI_TOKEN_CONNECTION].token_len);
- fprintf(stderr, "WSI_TOKEN_ACCEPT: %d\n", wsi->utf8_token[WSI_TOKEN_ACCEPT].token_len);
- fprintf(stderr, "WSI_TOKEN_NONCE: %d\n", wsi->utf8_token[WSI_TOKEN_NONCE].token_len);
- fprintf(stderr, "WSI_TOKEN_PROTOCOL: %d\n", wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len);
+ fprintf(stderr, "WSI_TOKEN_HTTP: %d\n",
+ wsi->utf8_token[WSI_TOKEN_HTTP].token_len);
+ fprintf(stderr, "WSI_TOKEN_UPGRADE: %d\n",
+ wsi->utf8_token[WSI_TOKEN_UPGRADE].token_len);
+ fprintf(stderr, "WSI_TOKEN_CONNECTION: %d\n",
+ wsi->utf8_token[WSI_TOKEN_CONNECTION].token_len);
+ fprintf(stderr, "WSI_TOKEN_ACCEPT: %d\n",
+ wsi->utf8_token[WSI_TOKEN_ACCEPT].token_len);
+ fprintf(stderr, "WSI_TOKEN_NONCE: %d\n",
+ wsi->utf8_token[WSI_TOKEN_NONCE].token_len);
+ fprintf(stderr, "WSI_TOKEN_PROTOCOL: %d\n",
+ wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len);
#endif
- if (!wsi->utf8_token[WSI_TOKEN_HTTP].token_len ||
- !wsi->utf8_token[WSI_TOKEN_UPGRADE].token_len ||
- !wsi->utf8_token[WSI_TOKEN_CONNECTION].token_len ||
- !wsi->utf8_token[WSI_TOKEN_ACCEPT].token_len ||
- (!wsi->utf8_token[WSI_TOKEN_NONCE].token_len &&
+ if (!wsi->utf8_token[WSI_TOKEN_HTTP].token_len ||
+ !wsi->utf8_token[WSI_TOKEN_UPGRADE].token_len ||
+ !wsi->utf8_token[WSI_TOKEN_CONNECTION].token_len ||
+ !wsi->utf8_token[WSI_TOKEN_ACCEPT].token_len ||
+ (!wsi->utf8_token[WSI_TOKEN_NONCE].token_len &&
wsi->ietf_spec_revision == 4) ||
- (!wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len &&
- wsi->c_protocol != NULL)) {
- debug("libwebsocket_client_handshake "
+ (!wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len &&
+ wsi->c_protocol != NULL)) {
+ debug("libwebsocket_client_handshake "
"missing required header(s)\n");
pkt[len] = '\0';
debug("%s", pkt);
select_protocol:
pc = wsi->c_protocol;
if (pc == NULL)
- fprintf(stderr, "lws_client_interpret_server_handshake: NULL c_protocol\n");
+ fprintf(stderr, "lws_client_interpret_server_handshake: "
+ "NULL c_protocol\n");
else
- debug("lws_client_interpret_server_handshake: cPprotocol='%s'\n", pc);
+ debug("lws_client_interpret_server_handshake: "
+ "cPprotocol='%s'\n", pc);
/*
* confirm the protocol the server wants to talk was in the list
if (!wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len) {
- fprintf(stderr, "lws_client_interpret_server_handshake WSI_TOKEN_PROTOCOL is null\n");
+ fprintf(stderr, "lws_client_interpret_server_handshake "
+ "WSI_TOKEN_PROTOCOL is null\n");
/*
* no protocol name to work from,
* default to first protocol
}
while (*pc && !okay) {
- if ((!strncmp(pc,
- wsi->utf8_token[WSI_TOKEN_PROTOCOL].token,
- wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len)) &&
- (pc[wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len] == ',' ||
- pc[wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len] == '\0')) {
+ if ((!strncmp(pc, wsi->utf8_token[WSI_TOKEN_PROTOCOL].token,
+ wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len)) &&
+ (pc[wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len] == ',' ||
+ pc[wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len] == '\0')) {
okay = 1;
continue;
}
if (wsi->c_protocol)
free(wsi->c_protocol);
-
if (!okay) {
fprintf(stderr, "libwebsocket_client_handshake server "
"sent bad protocol '%s'\n",
/* instantiate the accepted extensions */
if (!wsi->utf8_token[WSI_TOKEN_EXTENSIONS].token_len) {
- debug("no client extenstions allowed by server \n");
+ debug("no client extenstions allowed by server\n");
goto check_accept;
}
strcpy(p, magic_websocket_04_masking_guid);
SHA1(buf, strlen((char *)buf), wsi->masking_key_04);
}
- accept_ok:
+accept_ok:
/* allocate the per-connection user memory (if any) */
- if (wsi->protocol->per_session_data_size && !libwebsocket_ensure_user_space(wsi))
- goto bail2;
+ if (wsi->protocol->per_session_data_size &&
+ !libwebsocket_ensure_user_space(wsi))
+ goto bail2;
/* clear his proxy connection timeout */
wsi->state = WSI_STATE_ESTABLISHED;
wsi->mode = LWS_CONNMODE_WS_CLIENT;
- fprintf(stderr, "handshake OK for protocol %s\n",
- wsi->protocol->name);
+ fprintf(stderr, "handshake OK for protocol %s\n", wsi->protocol->name);
/* call him back to inform him he is up */
wsi->protocol->callback(context, wsi,
- LWS_CALLBACK_CLIENT_ESTABLISHED,
- wsi->user_space,
- NULL, 0);
+ LWS_CALLBACK_CLIENT_ESTABLISHED,
+ wsi->user_space, NULL, 0);
/*
* inform all extensions, not just active ones since they
* libwebsocket_service_fd() - Service polled socket with something waiting
* @context: Websocket context
* @pollfd: The pollfd entry describing the socket fd and which events
- * happened.
+ * happened.
*
* This function closes any active connections and then frees the
* context. After calling this, any further use of the context is
libwebsocket_service_fd(struct libwebsocket_context *context,
struct pollfd *pollfd)
{
- unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 1 + MAX_BROADCAST_PAYLOAD +
- LWS_SEND_BUFFER_POST_PADDING];
+ unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 1 +
+ MAX_BROADCAST_PAYLOAD + LWS_SEND_BUFFER_POST_PADDING];
struct libwebsocket *wsi;
struct libwebsocket *new_wsi;
int n;
/* Disable Nagle */
opt = 1;
- setsockopt(accept_fd, IPPROTO_TCP, TCP_NODELAY, (const void *)&opt,
- sizeof(opt));
+ setsockopt(accept_fd, IPPROTO_TCP, TCP_NODELAY,
+ (const void *)&opt, sizeof(opt));
/*
* look at who we connected to and give user code a chance
if ((context->protocols[0].callback)(context, wsi,
LWS_CALLBACK_FILTER_NETWORK_CONNECTION,
- (void*)(long)accept_fd, NULL, 0)) {
+ (void *)(long)accept_fd, NULL, 0)) {
debug("Callback denied network connection\n");
#ifdef WIN32
closesocket(accept_fd);
free(new_wsi);
break;
}
-
+
debug("accepted new SSL conn "
"port %u on fd=%d SSL ver %s\n",
ntohs(cli_addr.sin_port), accept_fd,
case LWS_CONNMODE_BROADCAST_PROXY_LISTENER:
/* as we are listening, POLLIN means accept() is needed */
-
+
if (!pollfd->revents & POLLIN)
break;
/* create a dummy wsi for the connection and add it */
new_wsi = malloc(sizeof(struct libwebsocket));
- memset(new_wsi, 0, 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 & POLLOUT)
- if (lws_handle_POLLOUT_event(context, wsi, pollfd) < 0) {
- libwebsocket_close_and_free_session(context, wsi,
- LWS_CLOSE_STATUS_NORMAL);
+ if (lws_handle_POLLOUT_event(context, wsi,
+ pollfd) < 0) {
+ libwebsocket_close_and_free_session(
+ context, wsi, LWS_CLOSE_STATUS_NORMAL);
return 1;
}
fprintf(stderr, "SSL connect error %s\n",
ERR_error_string(ERR_get_error(),
ssl_err_buf));
- libwebsocket_close_and_free_session(context, wsi,
- LWS_CLOSE_STATUS_NOSTATUS);
+ libwebsocket_close_and_free_session(context,
+ wsi, LWS_CLOSE_STATUS_NOSTATUS);
return 1;
}
#endif
p = libwebsockets_generate_client_handshake(context, wsi, p);
- if (p ==NULL)
+ if (p == NULL)
return 1;
/* send our request to the server */
}
/*
- * hs may also be coming in multiple packets, there is a 5-second
+ * hs may also be coming in multiple packets, there is a 5-sec
* libwebsocket timeout still active here too, so if parsing did
* not complete just wait for next packet coming in this state
*/
if (wsi->c_protocol)
free(wsi->c_protocol);
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:
- fprintf(stderr, "LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT\n");
+ fprintf(stderr,
+ "LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT\n");
break;
case LWS_CONNMODE_WS_CLIENT_PENDING_CANDIDATE_CHILD:
- fprintf(stderr, "LWS_CONNMODE_WS_CLIENT_PENDING_CANDIDATE_CHILD\n");
+ fprintf(stderr,
+ "LWS_CONNMODE_WS_CLIENT_PENDING_CANDIDATE_CHILD\n");
break;
fprintf(stderr, "Socket read returned %d\n",
eff_buf.token_len);
if (errno != EINTR)
- libwebsocket_close_and_free_session(context, wsi,
- LWS_CLOSE_STATUS_NOSTATUS);
+ libwebsocket_close_and_free_session(context,
+ wsi, LWS_CLOSE_STATUS_NOSTATUS);
return 1;
}
if (!eff_buf.token_len) {
libwebsocket_close_and_free_session(context, wsi,
- LWS_CLOSE_STATUS_NOSTATUS);
+ LWS_CLOSE_STATUS_NOSTATUS);
return 1;
}
wsi->active_extensions_user[n],
&eff_buf, 0);
if (m < 0) {
- fprintf(stderr, "Extension reports fatal error\n");
- libwebsocket_close_and_free_session(context, wsi,
- LWS_CLOSE_STATUS_NOSTATUS);
+ fprintf(stderr,
+ "Extension reports fatal error\n");
+ libwebsocket_close_and_free_session(
+ context, wsi,
+ LWS_CLOSE_STATUS_NOSTATUS);
return 1;
}
if (m)
if (eff_buf.token_len) {
n = libwebsocket_read(context, wsi,
- (unsigned char *)eff_buf.token, eff_buf.token_len);
+ (unsigned char *)eff_buf.token,
+ eff_buf.token_len);
if (n < 0)
/* we closed wsi */
return 1;
int
lws_any_extension_handled(struct libwebsocket_context *context,
- struct libwebsocket *wsi,
- enum libwebsocket_extension_callback_reasons r,
+ struct libwebsocket *wsi,
+ enum libwebsocket_extension_callback_reasons r,
void *v, size_t len)
{
int n;
void *
lws_get_extension_user_matching_ext(struct libwebsocket *wsi,
- struct libwebsocket_extension * ext)
+ struct libwebsocket_extension *ext)
{
int n = 0;
int
libwebsocket_callback_on_writable(struct libwebsocket_context *context,
- struct libwebsocket *wsi)
+ struct libwebsocket *wsi)
{
int n;
int handled = 0;
}
if (n == context->fds_count)
- fprintf(stderr, "libwebsocket_callback_on_writable: failed to find socket %d\n", wsi->sock);
+ fprintf(stderr, "libwebsocket_callback_on_writable: "
+ "failed to find socket %d\n", wsi->sock);
/* external POLL support via protocol 0 */
context->protocols[0].callback(context, wsi,
* static
*/
context = SSL_get_ex_data(ssl, openssl_websocket_private_data_index);
-
+
n = context->protocols[0].callback(NULL, NULL,
LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION,
x509_ctx, ssl, preverify_ok);
* entry that has a NULL callback pointer.
* It's not const because we write the owning_server member
* @extensions: NULL or array of libwebsocket_extension structs listing the
- * extensions this context supports
+ * extensions this context supports
* @ssl_cert_filepath: If libwebsockets was compiled to use ssl, and you want
* to listen using SSL, set to the filepath to fetch the
* server cert from, otherwise NULL for unencrypted
WORD wVersionRequested;
WSADATA wsaData;
int err;
- HMODULE wsdll;
+ HMODULE wsdll;
/* Use the MAKEWORD(lowbyte, highbyte) macro from Windef.h */
wVersionRequested = MAKEWORD(2, 2);
return NULL;
}
- wsdll = GetModuleHandle("Ws2_32.dll");
- if (wsdll)
- {
- poll = (PFNWSAPOLL)GetProcAddress(wsdll, "WSAPoll");
- }
+ /* default to a poll() made out of select() */
+ poll = emulated_poll;
- if (!poll)
- {
- poll = emulated_poll;
- }
+ /* if windows socket lib available, use his WSAPoll */
+ wsdll = GetModuleHandle("Ws2_32.dll");
+ if (wsdll)
+ poll = (PFNWSAPOLL)GetProcAddress(wsdll, "WSAPoll");
}
#endif
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';
}
/* client context */
- if (port == CONTEXT_PORT_NO_LISTEN)
- {
+
+ if (port == CONTEXT_PORT_NO_LISTEN) {
method = (SSL_METHOD *)SSLv23_client_method();
if (!method) {
fprintf(stderr, "problem creating ssl method: %s\n",
LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS,
context->ssl_client_ctx, NULL, 0);
}
+
/* as a server, are we requiring clients to identify themselves? */
if (options & LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT) {
/* 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);
}
/* allow us to restart even if old sockets in TIME_WAIT */
- setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const void *)&opt, sizeof(opt));
-
+ setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
+ (const void *)&opt, sizeof(opt));
/* Disable Nagle */
opt = 1;
- setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (const void *)&opt, sizeof(opt));
+ setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY,
+ (const void *)&opt, sizeof(opt));
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
}
wsi = malloc(sizeof(struct libwebsocket));
- memset(wsi, 0, sizeof (struct libwebsocket));
+ memset(wsi, 0, sizeof(struct libwebsocket));
wsi->sock = sockfd;
wsi->count_active_extensions = 0;
wsi->mode = LWS_CONNMODE_SERVER_LISTENER;
fprintf(stderr, " Listening on port %d\n", port);
/* list in the internal poll array */
-
+
context->fds[context->fds_count].fd = sockfd;
context->fds[context->fds_count++].events = POLLIN;
}
- /* drop any root privs for this process */
+ /*
+ * drop any root privs for this process
+ * to listen on port < 1023 we would have needed root, but now we are
+ * listening, we don't want the power for anything else
+ */
#ifdef WIN32
#else
if (gid != -1)
protocols[context->count_protocols].callback;
context->count_protocols++) {
- fprintf(stderr, " Protocol: %s\n", protocols[context->count_protocols].name);
+ fprintf(stderr, " Protocol: %s\n",
+ protocols[context->count_protocols].name);
protocols[context->count_protocols].owning_server = context;
protocols[context->count_protocols].protocol_index =
}
/* allow us to restart even if old sockets in TIME_WAIT */
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&opt, sizeof(opt));
+ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&opt,
+ sizeof(opt));
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
/* dummy wsi per broadcast proxy socket */
wsi = malloc(sizeof(struct libwebsocket));
- memset(wsi, 0, sizeof (struct libwebsocket));
+ memset(wsi, 0, sizeof(struct libwebsocket));
wsi->sock = fd;
wsi->mode = LWS_CONNMODE_BROADCAST_PROXY_LISTENER;
wsi->count_active_extensions = 0;
struct libwebsocket_context *context = protocol->owning_server;
int n;
int m;
- struct libwebsocket * wsi;
+ struct libwebsocket *wsi;
if (!protocol->broadcast_socket_user_fd) {
/*
"conn user space\n");
return NULL;
}
- memset(wsi->user_space, 0, wsi->protocol->per_session_data_size);
+ memset(wsi->user_space, 0,
+ wsi->protocol->per_session_data_size);
}
return wsi->user_space;
}
wsi->current_alloc_len = LWS_INITIAL_HDR_ALLOC;
wsi->utf8_token[wsi->parser_state].token =
- malloc(wsi->current_alloc_len);
+ malloc(wsi->current_alloc_len);
wsi->utf8_token[wsi->parser_state].token_len = 0;
}
int handled;
int m;
-// fprintf(stderr, "RX: %02X ", c);
+#if 0
+ fprintf(stderr, "RX: %02X ", c);
+#endif
switch (wsi->lws_rx_parse_state) {
case LWS_RXPS_NEW:
case LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED:
- if (wsi->ietf_spec_revision < 4 || (wsi->all_zero_nonce && wsi->ietf_spec_revision >= 5))
+ if (wsi->ietf_spec_revision < 4 ||
+ (wsi->all_zero_nonce && wsi->ietf_spec_revision >= 5))
wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING +
(wsi->rx_user_buffer_head++)] = c;
else
if (wsi->ietf_spec_revision < 7)
switch (c & 0xf) {
case LWS_WS_OPCODE_04__CONTINUATION:
- wsi->opcode = LWS_WS_OPCODE_07__CONTINUATION;
+ wsi->opcode =
+ LWS_WS_OPCODE_07__CONTINUATION;
break;
case LWS_WS_OPCODE_04__CLOSE:
wsi->opcode = LWS_WS_OPCODE_07__CLOSE;
wsi->opcode = LWS_WS_OPCODE_07__PONG;
break;
case LWS_WS_OPCODE_04__TEXT_FRAME:
- wsi->opcode = LWS_WS_OPCODE_07__TEXT_FRAME;
+ wsi->opcode =
+ LWS_WS_OPCODE_07__TEXT_FRAME;
break;
case LWS_WS_OPCODE_04__BINARY_FRAME:
- wsi->opcode = LWS_WS_OPCODE_07__BINARY_FRAME;
+ wsi->opcode =
+ LWS_WS_OPCODE_07__BINARY_FRAME;
break;
default:
fprintf(stderr, "reserved opcodes not "
- "usable pre v7 protocol\n");
+ "usable pre v7 protocol\n");
return -1;
}
else
else {
if (c)
wsi->lws_rx_parse_state =
- LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED;
+ LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED;
else {
wsi->lws_rx_parse_state = LWS_RXPS_NEW;
goto spill;
else {
if (wsi->rx_packet_length)
wsi->lws_rx_parse_state =
- LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED;
+ LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED;
else {
wsi->lws_rx_parse_state = LWS_RXPS_NEW;
goto spill;
else {
if (wsi->rx_packet_length)
wsi->lws_rx_parse_state =
- LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED;
+ LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED;
else {
wsi->lws_rx_parse_state = LWS_RXPS_NEW;
goto spill;
debug("seen server's close ack\n");
return -1;
}
- fprintf(stderr, "client sees server close packet len = %d\n", wsi->rx_user_buffer_head);
+ fprintf(stderr, "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);
- fprintf(stderr, "client writing close ack returned %d\n", n);
+ fprintf(stderr, "client writing close "
+ "ack returned %d\n", n);
wsi->state = WSI_STATE_RETURNED_CLOSE_ALREADY;
/* close the connection */
return -1;
*/
memcpy(buf, wsi->frame_masking_nonce_04, 4);
-
+
memcpy(buf + 4, wsi->masking_key_04, 20);
/* concatenate the nonce with the connection key then hash it */
start = n;
fprintf(stderr, "%04X: ", start);
-
+
for (m = 0; m < 16 && n < len; m++)
fprintf(stderr, "%02X ", buf[n++]);
while (m++ < 16)
return -1;
}
if (m) /* handled */ {
-// fprintf(stderr, "ext sent it\n");
+/* fprintf(stderr, "ext sent it\n"); */
return 0;
}
}
- if (!wsi->sock) {
+ if (!wsi->sock)
fprintf(stderr, "** error 0 sock but expected to send\n");
- }
/*
* nope, send it on the socket directly
LWS_EXT_CALLBACK_PACKET_TX_PRESEND,
wsi->active_extensions_user[n], &eff_buf, 0);
if (m < 0) {
- fprintf(stderr, "Extension reports fatal error\n");
+ fprintf(stderr, "Extension: fatal error\n");
return -1;
}
if (m)
if (eff_buf.token_len)
if (lws_issue_raw(wsi, (unsigned char *)eff_buf.token,
- eff_buf.token_len))
+ eff_buf.token_len))
return -1;
/* we used up what we had */
int pre = 0;
int post = 0;
int shift = 7;
- int masked7 = wsi->mode == LWS_CONNMODE_WS_CLIENT && wsi->xor_mask != xor_no_mask;
+ int masked7 = wsi->mode == LWS_CONNMODE_WS_CLIENT &&
+ wsi->xor_mask != xor_no_mask;
unsigned char *dropmask = NULL;
unsigned char is_masked_bit = 0;
* v5 mandates the first byte of close packet
* in both client and server directions
*/
-
+
switch (wsi->ietf_spec_revision) {
case 0:
case 4:
if (len < 1)
len = 1;
-
+
switch (wsi->mode) {
case LWS_CONNMODE_WS_SERVING:
/*
* to control the raw packet payload content
*/
- if (!(protocol & LWS_WRITE_CLIENT_IGNORE_XOR_MASK) && wsi->xor_mask != xor_no_mask) {
+ if (!(protocol & LWS_WRITE_CLIENT_IGNORE_XOR_MASK) &&
+ wsi->xor_mask != xor_no_mask) {
if (libwebsocket_0405_frame_mask_generate(wsi)) {
fprintf(stderr, "libwebsocket_write: "
* in v7, just mask the payload
*/
for (n = 0; n < (int)len; n++)
- dropmask[n + 4] = wsi->xor_mask(wsi, dropmask[n + 4]);
+ dropmask[n + 4] =
+ wsi->xor_mask(wsi, dropmask[n + 4]);
if (wsi->ietf_spec_revision < 7) {
if (dropmask)
/* copy the frame nonce into place */
- memcpy(dropmask, wsi->frame_masking_nonce_04, 4);
+ memcpy(dropmask,
+ wsi->frame_masking_nonce_04, 4);
} else {
if (wsi->ietf_spec_revision < 7) {
"Server: libwebsockets\x0d\x0a"
"Content-Type: %s\x0d\x0a"
"Content-Length: %u\x0d\x0a"
- "\x0d\x0a", content_type, (unsigned int)stat_buf.st_size);
+ "\x0d\x0a", content_type,
+ (unsigned int)stat_buf.st_size);
libwebsocket_write(wsi, (unsigned char *)buf, p - buf, LWS_WRITE_HTTP);
* but happily have something equivalent in the SO_NOSIGPIPE flag.
*/
#ifdef __APPLE__
-#define MSG_NOSIGNAL SO_NOSIGPIPE
+#define MSG_NOSIGNAL SO_NOSIGPIPE
#endif
unsigned long last_timeout_check_s;
int fd_random;
-
+
#ifdef LWS_OPENSSL_SUPPORT
int use_ssl;
SSL_CTX *ssl_ctx;
const struct libwebsocket_protocols *protocol;
struct libwebsocket_extension *
active_extensions[LWS_MAX_EXTENSIONS_ACTIVE];
- void * active_extensions_user[LWS_MAX_EXTENSIONS_ACTIVE];
+ void *active_extensions_user[LWS_MAX_EXTENSIONS_ACTIVE];
int count_active_extensions;
enum lws_connection_states state;
unsigned char *buf, size_t len);
extern int
-libwebsocket_read(struct libwebsocket_context *context, struct libwebsocket *wsi,
- unsigned char * buf, size_t len);
+libwebsocket_read(struct libwebsocket_context *context,
+ struct libwebsocket *wsi,
+ unsigned char *buf, size_t len);
extern int
lws_b64_selftest(void);
libwebsocket_service_timeout_check(struct libwebsocket_context *context,
struct libwebsocket *wsi, unsigned int sec);
-extern struct libwebsocket * __libwebsocket_client_connect_2(
- struct libwebsocket_context *context,
+extern struct libwebsocket *
+__libwebsocket_client_connect_2(struct libwebsocket_context *context,
struct libwebsocket *wsi);
extern struct libwebsocket *
extern int
lws_any_extension_handled(struct libwebsocket_context *context,
- struct libwebsocket *wsi,
- enum libwebsocket_extension_callback_reasons r,
- void *v, size_t len);
+ struct libwebsocket *wsi,
+ enum libwebsocket_extension_callback_reasons r,
+ void *v, size_t len);
extern void *
lws_get_extension_user_matching_ext(struct libwebsocket *wsi,
- struct libwebsocket_extension * ext);
+ struct libwebsocket_extension *ext);
extern int
lws_client_interpret_server_handshake(struct libwebsocket_context *context,
#define BYTE_ORDER LITTLE_ENDIAN
#endif
-typedef unsigned char u_int8_t;
-typedef unsigned int u_int32_t;
typedef unsigned __int64 u_int64_t;
-typedef void* caddr_t;
#undef __P
#ifndef __P
#endif
#endif
-#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
+#define bzero(b, len) (memset((b), '\0', (len)), (void) 0)
#else
#include <sys/cdefs.h>
struct sha1_ctxt {
union {
- u_int8_t b8[20];
- u_int32_t b32[5];
+ unsigned char b8[20];
+ unsigned int b32[5];
} h;
union {
- u_int8_t b8[8];
- u_int64_t b64[1];
+ unsigned char b8[8];
+ u_int64_t b64[1];
} c;
union {
- u_int8_t b8[64];
- u_int32_t b32[16];
+ unsigned char b8[64];
+ unsigned int b32[16];
} m;
- u_int8_t count;
+ unsigned char count;
};
/* sanity check */
#ifndef unsupported
/* constant table */
-static u_int32_t _K[] = { 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6 };
+static unsigned int _K[] = { 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6 };
#define K(t) _K[(t) / 20]
#define F0(b, c, d) (((b) & (c)) | ((~(b)) & (d)))
ctxt->c.b64[0] += 8; \
if (COUNT % 64 == 0) \
sha1_step(ctxt); \
- }
+ }
#define PUTPAD(x) { \
ctxt->m.b8[(COUNT % 64)] = (x); \
COUNT %= 64; \
if (COUNT % 64 == 0) \
sha1_step(ctxt); \
- }
+ }
static void sha1_step __P((struct sha1_ctxt *));
static void
sha1_step(struct sha1_ctxt *ctxt)
{
- u_int32_t a, b, c, d, e;
+ unsigned int a, b, c, d, e, tmp;
size_t t, s;
- u_int32_t tmp;
#if BYTE_ORDER == LITTLE_ENDIAN
struct sha1_ctxt tctxt;
}
void
-sha1_loop(struct sha1_ctxt *ctxt, const u_int8_t *input, size_t len)
+sha1_loop(struct sha1_ctxt *ctxt, const unsigned char *input, size_t len)
{
size_t gaplen;
size_t gapstart;
}
void
-sha1_result(struct sha1_ctxt *ctxt, caddr_t digest0)
+sha1_result(struct sha1_ctxt *ctxt, void *digest0)
{
- u_int8_t *digest;
+ unsigned char *digest;
- digest = (u_int8_t *)digest0;
+ digest = (unsigned char *)digest0;
sha1_pad(ctxt);
#if BYTE_ORDER == BIG_ENDIAN
memcpy(digest, &ctxt->h.b8[0], 20);
sha1_init(&ctx);
sha1_loop(&ctx, d, n);
- sha1_result(&ctx, (caddr_t)md);
+ sha1_result(&ctx, (void *)md);
return md;
}
/* dumb_increment protocol */
static int
-callback_dumb_increment(struct libwebsocket_context * this,
+callback_dumb_increment(struct libwebsocket_context *this,
struct libwebsocket *wsi,
enum libwebsocket_callback_reasons reason,
void *user, void *in, size_t len)
static int
-callback_lws_mirror(struct libwebsocket_context * this,
+callback_lws_mirror(struct libwebsocket_context *this,
struct libwebsocket *wsi,
enum libwebsocket_callback_reasons reason,
void *user, void *in, size_t len)
/* create a client websocket using mirror protocol */
- wsi_mirror = libwebsocket_client_connect(context, address, port,
- use_ssl, "/", argv[optind], argv[optind],
- protocols[PROTOCOL_LWS_MIRROR].name, ietf_version);
+ wsi_mirror = libwebsocket_client_connect(context,
+ address, port, use_ssl, "/",
+ argv[optind], argv[optind],
+ protocols[PROTOCOL_LWS_MIRROR].name,
+ ietf_version);
if (wsi_mirror == NULL) {
- fprintf(stderr, "libwebsocket dumb connect failed\n");
+ fprintf(stderr, "libwebsocket "
+ "dumb connect failed\n");
return -1;
}
mirror_lifetime = 10 + (random() & 1023);
- fprintf(stderr, "opened mirror connection with %d lifetime\n", mirror_lifetime);
+ fprintf(stderr, "opened mirror connection with "
+ "%d lifetime\n", mirror_lifetime);
} else {
};
static int
-callback_fraggle(struct libwebsocket_context * context,
+callback_fraggle(struct libwebsocket_context *context,
struct libwebsocket *wsi,
enum libwebsocket_callback_reasons reason,
void *user, void *in, size_t len)
bp[1] = psf->sum >> 16;
bp[2] = psf->sum >> 8;
bp[3] = psf->sum;
-
+
n = libwebsocket_write(wsi, (unsigned char *)bp,
4, LWS_WRITE_BINARY);
{ "port", required_argument, NULL, 'p' },
{ "ssl", no_argument, NULL, 's' },
{ "killmask", no_argument, NULL, 'k' },
- { "interface", required_argument, NULL, 'i' },
- { "client", no_argument, NULL, 'c' },
+ { "interface", required_argument, NULL, 'i' },
+ { "client", no_argument, NULL, 'c' },
{ NULL, 0, 0, 0 }
};
struct libwebsocket_context *context;
int opts = 0;
char interface_name[128] = "";
- const char * interface = NULL;
+ const char *interface = NULL;
struct libwebsocket *wsi;
const char *address;
int server_port = port;
/* this protocol server (always the first one) just knows how to do HTTP */
-static int callback_http(struct libwebsocket_context * context,
+static int callback_http(struct libwebsocket_context *context,
struct libwebsocket *wsi,
enum libwebsocket_callback_reasons reason, void *user,
void *in, size_t len)
/*[WSI_TOKEN_HTTP] =*/ "Http",
/*[WSI_TOKEN_MUXURL] =*/ "MuxURL",
};
-
+
for (n = 0; n < WSI_TOKEN_COUNT; n++) {
if (lwst[n].token == NULL)
continue;
};
static int
-callback_dumb_increment(struct libwebsocket_context * context,
+callback_dumb_increment(struct libwebsocket_context *context,
struct libwebsocket *wsi,
enum libwebsocket_callback_reasons reason,
void *user, void *in, size_t len)
switch (reason) {
case LWS_CALLBACK_ESTABLISHED:
- fprintf(stderr, "callback_dumb_increment: LWS_CALLBACK_ESTABLISHED\n");
+ fprintf(stderr, "callback_dumb_increment: "
+ "LWS_CALLBACK_ESTABLISHED\n");
pss->number = 0;
break;
static int
-callback_lws_mirror(struct libwebsocket_context * context,
+callback_lws_mirror(struct libwebsocket_context *context,
struct libwebsocket *wsi,
enum libwebsocket_callback_reasons reason,
void *user, void *in, size_t len)
switch (reason) {
case LWS_CALLBACK_ESTABLISHED:
- fprintf(stderr, "callback_lws_mirror: LWS_CALLBACK_ESTABLISHED\n");
+ fprintf(stderr, "callback_lws_mirror: "
+ "LWS_CALLBACK_ESTABLISHED\n");
pss->ringbuffer_tail = ringbuffer_head;
pss->wsi = wsi;
break;
{ "port", required_argument, NULL, 'p' },
{ "ssl", no_argument, NULL, 's' },
{ "killmask", no_argument, NULL, 'k' },
- { "interface", required_argument, NULL, 'i' },
+ { "interface", required_argument, NULL, 'i' },
{ "closetest", no_argument, NULL, 'c' },
{ NULL, 0, 0, 0 }
};
struct libwebsocket_context *context;
int opts = 0;
char interface_name[128] = "";
- const char * interface = NULL;
+ const char *interface = NULL;
#ifdef LWS_NO_FORK
unsigned int oldus = 0;
#endif