mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
clean more whitespace 5
Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
dc8a3a817a
commit
576d3ec0df
3 changed files with 75 additions and 61 deletions
54
lib/client.c
54
lib/client.c
|
@ -345,9 +345,8 @@ some_wait:
|
|||
#endif
|
||||
|
||||
wsi->mode = LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE2;
|
||||
lws_set_timeout(wsi,
|
||||
PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND,
|
||||
AWAITING_TIMEOUT);
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND,
|
||||
AWAITING_TIMEOUT);
|
||||
|
||||
/* fallthru */
|
||||
|
||||
|
@ -356,7 +355,7 @@ some_wait:
|
|||
if (p == NULL) {
|
||||
lwsl_err("Failed to generate handshake for client\n");
|
||||
lws_close_and_free_session(context, wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -364,13 +363,15 @@ some_wait:
|
|||
|
||||
lws_latency_pre(context, wsi);
|
||||
|
||||
n = lws_ssl_capable_write(wsi, context->service_buffer, p - (char *)context->service_buffer);
|
||||
lws_latency(context, wsi, "send lws_issue_raw", n, n == p - (char *)context->service_buffer);
|
||||
n = lws_ssl_capable_write(wsi, context->service_buffer,
|
||||
p - (char *)context->service_buffer);
|
||||
lws_latency(context, wsi, "send lws_issue_raw", n,
|
||||
n == p - (char *)context->service_buffer);
|
||||
switch (n) {
|
||||
case LWS_SSL_CAPABLE_ERROR:
|
||||
lwsl_debug("ERROR writing to client socket\n");
|
||||
lws_close_and_free_session(context, wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
return 0;
|
||||
case LWS_SSL_CAPABLE_MORE_SERVICE:
|
||||
lws_callback_on_writable(context, wsi);
|
||||
|
@ -380,9 +381,8 @@ some_wait:
|
|||
wsi->u.hdr.parser_state = WSI_TOKEN_NAME_PART;
|
||||
wsi->u.hdr.lextable_pos = 0;
|
||||
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY;
|
||||
lws_set_timeout(wsi,
|
||||
PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE,
|
||||
AWAITING_TIMEOUT);
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE,
|
||||
AWAITING_TIMEOUT);
|
||||
break;
|
||||
|
||||
case LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY:
|
||||
|
@ -421,9 +421,10 @@ some_wait:
|
|||
*/
|
||||
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);
|
||||
lws_latency(context, wsi, "send lws_issue_raw", n,
|
||||
n == 1);
|
||||
switch (n) {
|
||||
case LWS_SSL_CAPABLE_ERROR:
|
||||
goto bail3;
|
||||
|
@ -455,10 +456,9 @@ some_wait:
|
|||
return lws_client_interpret_server_handshake(context, wsi);
|
||||
|
||||
bail3:
|
||||
lwsl_info(
|
||||
"closing connection at LWS_CONNMODE...SERVER_REPLY\n");
|
||||
lwsl_info("closing conn at LWS_CONNMODE...SERVER_REPLY\n");
|
||||
lws_close_and_free_session(context, wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
return -1;
|
||||
|
||||
case LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT:
|
||||
|
@ -493,14 +493,15 @@ int
|
|||
lws_client_interpret_server_handshake(struct lws_context *context,
|
||||
struct lws *wsi)
|
||||
{
|
||||
int n, len, okay = 0, more = 1, isErrorCodeReceived = 0;
|
||||
int close_reason = LWS_CLOSE_STATUS_PROTOCOL_ERR;
|
||||
int n, len, okay = 0, isErrorCodeReceived = 0;
|
||||
const char *pc;
|
||||
char *p;
|
||||
#ifndef LWS_NO_EXTENSIONS
|
||||
struct lws_extension *ext;
|
||||
char ext_name[128];
|
||||
const char *c;
|
||||
int more = 1;
|
||||
void *v;
|
||||
#endif
|
||||
|
||||
|
@ -551,7 +552,7 @@ lws_client_interpret_server_handshake(struct lws_context *context,
|
|||
}
|
||||
|
||||
pc = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS);
|
||||
if (pc == NULL) {
|
||||
if (!pc) {
|
||||
lwsl_parser("lws_client_int_s_hs: no protocol list\n");
|
||||
} else
|
||||
lwsl_parser("lws_client_int_s_hs: protocol list '%s'\n", pc);
|
||||
|
@ -658,14 +659,12 @@ check_extensions:
|
|||
n = 0;
|
||||
ext = wsi->protocol->owning_server->extensions;
|
||||
while (ext && ext->callback) {
|
||||
|
||||
if (strcmp(ext_name, ext->name)) {
|
||||
ext++;
|
||||
continue;
|
||||
}
|
||||
|
||||
n = 1;
|
||||
|
||||
lwsl_ext("instantiating client ext %s\n", ext_name);
|
||||
|
||||
/* instantiate the extension on this conn */
|
||||
|
@ -683,12 +682,11 @@ check_extensions:
|
|||
|
||||
/* allow him to construct his context */
|
||||
|
||||
ext->callback(wsi->protocol->owning_server,
|
||||
ext, wsi,
|
||||
LWS_EXT_CALLBACK_CLIENT_CONSTRUCT,
|
||||
wsi->active_extensions_user[
|
||||
ext->callback(wsi->protocol->owning_server, ext, wsi,
|
||||
LWS_EXT_CALLBACK_CLIENT_CONSTRUCT,
|
||||
wsi->active_extensions_user[
|
||||
wsi->count_active_extensions],
|
||||
NULL, 0);
|
||||
NULL, 0);
|
||||
|
||||
wsi->count_active_extensions++;
|
||||
|
||||
|
@ -727,7 +725,6 @@ check_accept:
|
|||
* we seem to be good to go, give client last chance to check
|
||||
* headers and OK it
|
||||
*/
|
||||
|
||||
wsi->protocol->callback(context, wsi,
|
||||
LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH,
|
||||
wsi->user_space, NULL, 0);
|
||||
|
@ -762,7 +759,8 @@ check_accept:
|
|||
}
|
||||
lwsl_info("Allocating client RX buffer %d\n", n);
|
||||
|
||||
if (setsockopt(wsi->sock, SOL_SOCKET, SO_SNDBUF, (const char *)&n, sizeof n)) {
|
||||
if (setsockopt(wsi->sock, SOL_SOCKET, SO_SNDBUF, (const char *)&n,
|
||||
sizeof n)) {
|
||||
lwsl_warn("Failed to set SNDBUF to %d", n);
|
||||
goto bail3;
|
||||
}
|
||||
|
@ -840,9 +838,9 @@ lws_generate_client_handshake(struct lws_context *context,
|
|||
n = lws_get_random(context, hash, 16);
|
||||
if (n != 16) {
|
||||
lwsl_err("Unable to read from random dev %s\n",
|
||||
SYSTEM_RANDOM_FILEPATH);
|
||||
SYSTEM_RANDOM_FILEPATH);
|
||||
lws_close_and_free_session(context, wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
50
lib/hpack.c
50
lib/hpack.c
|
@ -241,7 +241,8 @@ static void lws_dump_header(struct lws *wsi, int hdr)
|
|||
lwsl_info(" hdr tok %d (%s) = '%s'\n", hdr, lws_token_to_string(hdr), s);
|
||||
}
|
||||
|
||||
static int lws_token_from_index(struct lws *wsi, int index, char **arg, int *len)
|
||||
static int
|
||||
lws_token_from_index(struct lws *wsi, int index, char **arg, int *len)
|
||||
{
|
||||
struct hpack_dynamic_table *dyn;
|
||||
|
||||
|
@ -269,7 +270,8 @@ static int lws_token_from_index(struct lws *wsi, int index, char **arg, int *len
|
|||
return dyn->entries[index].token;
|
||||
}
|
||||
|
||||
static int lws_hpack_add_dynamic_header(struct lws *wsi, int token, char *arg, int len)
|
||||
static int
|
||||
lws_hpack_add_dynamic_header(struct lws *wsi, int token, char *arg, int len)
|
||||
{
|
||||
struct hpack_dynamic_table *dyn;
|
||||
int ret = 1;
|
||||
|
@ -305,7 +307,8 @@ static int lws_hpack_add_dynamic_header(struct lws *wsi, int token, char *arg, i
|
|||
memcpy(dyn->args + dyn->pos, arg, len);
|
||||
dyn->entries[dyn->next].arg_len = len;
|
||||
|
||||
lwsl_info("%s: added dynamic hdr %d, token %d (%s), len %d\n", __func__, dyn->next, token, lws_token_to_string(token), len);
|
||||
lwsl_info("%s: added dynamic hdr %d, token %d (%s), len %d\n",
|
||||
__func__, dyn->next, token, lws_token_to_string(token), len);
|
||||
|
||||
dyn->pos += len;
|
||||
dyn->next++;
|
||||
|
@ -326,7 +329,8 @@ static int lws_write_indexed_hdr(struct lws *wsi, int idx)
|
|||
const char *p;
|
||||
int tok = lws_token_from_index(wsi, idx, NULL, 0);
|
||||
|
||||
lwsl_info("writing indexed hdr %d (tok %d '%s')\n", idx, tok, lws_token_to_string(tok));
|
||||
lwsl_info("writing indexed hdr %d (tok %d '%s')\n", idx, tok,
|
||||
lws_token_to_string(tok));
|
||||
|
||||
if (lws_frag_start(wsi, tok))
|
||||
return 1;
|
||||
|
@ -492,9 +496,9 @@ int lws_hpack_interpret(struct lws_context *context,
|
|||
if (wsi->u.http2.hpack_len < 0x7f) {
|
||||
pre_data:
|
||||
if (wsi->u.http2.value) {
|
||||
if (lws_frag_start(wsi,
|
||||
lws_token_from_index(wsi,
|
||||
wsi->u.http2.header_index, NULL, NULL)))
|
||||
if (lws_frag_start(wsi, lws_token_from_index(wsi,
|
||||
wsi->u.http2.header_index,
|
||||
NULL, NULL)))
|
||||
return 1;
|
||||
} else
|
||||
wsi->u.hdr.parser_state = WSI_TOKEN_NAME_PART;
|
||||
|
@ -518,10 +522,9 @@ pre_data:
|
|||
for (n = 0; n < 8; n++) {
|
||||
if (wsi->u.http2.huff) {
|
||||
prev = wsi->u.http2.hpack_pos;
|
||||
wsi->u.http2.hpack_pos =
|
||||
huftable_decode(
|
||||
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;
|
||||
|
@ -550,7 +553,10 @@ pre_data:
|
|||
switch (wsi->u.http2.hpack_type) {
|
||||
case HPKT_LITERAL_HDR_VALUE_INCR:
|
||||
case HPKT_INDEXED_HDR_6_VALUE_INCR: // !!!
|
||||
if (lws_hpack_add_dynamic_header(wsi, lws_token_from_index(wsi, wsi->u.http2.header_index, NULL, NULL), NULL, 0))
|
||||
if (lws_hpack_add_dynamic_header(wsi,
|
||||
lws_token_from_index(wsi,
|
||||
wsi->u.http2.header_index,
|
||||
NULL, NULL), NULL, 0))
|
||||
return 1;
|
||||
break;
|
||||
default:
|
||||
|
@ -562,8 +568,11 @@ pre_data:
|
|||
if (lws_frag_end(wsi))
|
||||
return 1;
|
||||
|
||||
lws_dump_header(wsi, lws_token_from_index(wsi, wsi->u.http2.header_index, NULL, NULL));
|
||||
if (wsi->u.http2.count + wsi->u.http2.padding == wsi->u.http2.length)
|
||||
lws_dump_header(wsi, lws_token_from_index(
|
||||
wsi, wsi->u.http2.header_index,
|
||||
NULL, NULL));
|
||||
if (wsi->u.http2.count + wsi->u.http2.padding ==
|
||||
wsi->u.http2.length)
|
||||
wsi->u.http2.hpack = HKPS_OPT_DISCARD_PADDING;
|
||||
else
|
||||
wsi->u.http2.hpack = HPKS_TYPE;
|
||||
|
@ -610,13 +619,10 @@ static int lws_http2_num(int starting_bits, unsigned long num,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int lws_add_http2_header_by_name(struct lws_context *context,
|
||||
struct lws *wsi,
|
||||
int lws_add_http2_header_by_name(struct lws_context *context, struct lws *wsi,
|
||||
const unsigned char *name,
|
||||
const unsigned char *value,
|
||||
int length,
|
||||
unsigned char **p,
|
||||
unsigned char *end)
|
||||
const unsigned char *value, int length,
|
||||
unsigned char **p, unsigned char *end)
|
||||
{
|
||||
int len;
|
||||
|
||||
|
@ -649,9 +655,9 @@ int lws_add_http2_header_by_name(struct lws_context *context,
|
|||
}
|
||||
|
||||
int lws_add_http2_header_by_token(struct lws_context *context, struct lws *wsi,
|
||||
enum lws_token_indexes token,
|
||||
const unsigned char *value, int length,
|
||||
unsigned char **p, unsigned char *end)
|
||||
enum lws_token_indexes token,
|
||||
const unsigned char *value, int length,
|
||||
unsigned char **p, unsigned char *end)
|
||||
{
|
||||
const unsigned char *name;
|
||||
|
||||
|
|
32
lib/http2.c
32
lib/http2.c
|
@ -52,7 +52,8 @@ lws_http2_wsi_from_id(struct lws *wsi, unsigned int sid)
|
|||
}
|
||||
|
||||
struct lws *
|
||||
lws_create_server_child_wsi(struct lws_context *context, struct lws *parent_wsi, unsigned int sid)
|
||||
lws_create_server_child_wsi(struct lws_context *context, struct lws *parent_wsi,
|
||||
unsigned int sid)
|
||||
{
|
||||
struct lws *wsi = lws_create_new_server_wsi(context);
|
||||
|
||||
|
@ -60,7 +61,9 @@ lws_create_server_child_wsi(struct lws_context *context, struct lws *parent_wsi,
|
|||
return NULL;
|
||||
|
||||
/* no more children allowed by parent */
|
||||
if (parent_wsi->u.http2.child_count + 1 == parent_wsi->u.http2.peer_settings.setting[LWS_HTTP2_SETTINGS__MAX_CONCURRENT_STREAMS])
|
||||
if (parent_wsi->u.http2.child_count + 1 ==
|
||||
parent_wsi->u.http2.peer_settings.setting[
|
||||
LWS_HTTP2_SETTINGS__MAX_CONCURRENT_STREAMS])
|
||||
return NULL;
|
||||
|
||||
lws_http2_init(&wsi->u.http2.peer_settings);
|
||||
|
@ -82,7 +85,8 @@ lws_create_server_child_wsi(struct lws_context *context, struct lws *parent_wsi,
|
|||
wsi->protocol = &context->protocols[0];
|
||||
lws_ensure_user_space(wsi);
|
||||
|
||||
lwsl_info("%s: %p new child %p, sid %d, user_space=%p\n", __func__, parent_wsi, wsi, sid, wsi->user_space);
|
||||
lwsl_info("%s: %p new child %p, sid %d, user_space=%p\n", __func__,
|
||||
parent_wsi, wsi, sid, wsi->user_space);
|
||||
|
||||
return wsi;
|
||||
}
|
||||
|
@ -105,7 +109,8 @@ int lws_remove_server_child_wsi(struct lws_context *context, struct lws *wsi)
|
|||
}
|
||||
|
||||
int
|
||||
lws_http2_interpret_settings_payload(struct http2_settings *settings, unsigned char *buf, int len)
|
||||
lws_http2_interpret_settings_payload(struct http2_settings *settings,
|
||||
unsigned char *buf, int len)
|
||||
{
|
||||
unsigned int a, b;
|
||||
|
||||
|
@ -140,7 +145,8 @@ struct lws *lws_http2_get_network_wsi(struct lws *wsi)
|
|||
return wsi;
|
||||
}
|
||||
|
||||
int lws_http2_frame_write(struct lws *wsi, int type, int flags, unsigned int sid, unsigned int len, unsigned char *buf)
|
||||
int lws_http2_frame_write(struct lws *wsi, int type, int flags,
|
||||
unsigned int sid, unsigned int len, unsigned char *buf)
|
||||
{
|
||||
struct lws *wsi_eff = lws_http2_get_network_wsi(wsi);
|
||||
unsigned char *p = &buf[-LWS_HTTP2_FRAME_HEADER_LENGTH];
|
||||
|
@ -157,15 +163,19 @@ int lws_http2_frame_write(struct lws *wsi, int type, int flags, unsigned int sid
|
|||
*p++ = sid;
|
||||
|
||||
lwsl_info("%s: %p (eff %p). type %d, flags 0x%x, sid=%d, len=%d\n",
|
||||
__func__, wsi, wsi_eff, type, flags, sid, len, wsi->u.http2.tx_credit);
|
||||
__func__, wsi, wsi_eff, type, flags, sid, len,
|
||||
wsi->u.http2.tx_credit);
|
||||
|
||||
if (type == LWS_HTTP2_FRAME_TYPE_DATA) {
|
||||
if (wsi->u.http2.tx_credit < len)
|
||||
lwsl_err("%s: %p: sending payload len %d but tx_credit only %d!\n", len, wsi->u.http2.tx_credit);
|
||||
lwsl_err("%s: %p: sending payload len %d"
|
||||
" but tx_credit only %d!\n", len,
|
||||
wsi->u.http2.tx_credit);
|
||||
wsi->u.http2.tx_credit -= len;
|
||||
}
|
||||
|
||||
n = lws_issue_raw(wsi_eff, &buf[-LWS_HTTP2_FRAME_HEADER_LENGTH], len + LWS_HTTP2_FRAME_HEADER_LENGTH);
|
||||
n = lws_issue_raw(wsi_eff, &buf[-LWS_HTTP2_FRAME_HEADER_LENGTH],
|
||||
len + LWS_HTTP2_FRAME_HEADER_LENGTH);
|
||||
if (n >= LWS_HTTP2_FRAME_HEADER_LENGTH)
|
||||
return n - LWS_HTTP2_FRAME_HEADER_LENGTH;
|
||||
|
||||
|
@ -186,8 +196,7 @@ static const char * https_client_preface =
|
|||
"PRI * HTTP/2.0\x0d\x0a\x0d\x0aSM\x0d\x0a\x0d\x0a";
|
||||
|
||||
int
|
||||
lws_http2_parser(struct lws_context *context,
|
||||
struct lws *wsi, unsigned char c)
|
||||
lws_http2_parser(struct lws_context *context, struct lws *wsi, unsigned char c)
|
||||
{
|
||||
struct lws *swsi;
|
||||
int n;
|
||||
|
@ -210,7 +219,8 @@ lws_http2_parser(struct lws_context *context,
|
|||
* and the peer must send a SETTINGS with ACK flag...
|
||||
*/
|
||||
|
||||
lws_set_protocol_write_pending(context, wsi, LWS_PPS_HTTP2_MY_SETTINGS);
|
||||
lws_set_protocol_write_pending(context, wsi,
|
||||
LWS_PPS_HTTP2_MY_SETTINGS);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue