diff --git a/READMEs/README.unix-domain-reverse-proxy.md b/READMEs/README.unix-domain-reverse-proxy.md index bca4f7520..1db8abd12 100644 --- a/READMEs/README.unix-domain-reverse-proxy.md +++ b/READMEs/README.unix-domain-reverse-proxy.md @@ -89,9 +89,13 @@ Headers are converted to all lower-case and hpack format for h2 return connectio Header and payload proxying is staged according to when the return connection (which may be an h2 child stream) is writable. -### Behaviour is unix domain socket server unavailable +### Behaviour if unix domain socket server unavailable If the server that listens on the unix domain socket is down or being restarted, lws understands that it couldn't connect to it and returns a clean 503 response `HTTP_STATUS_SERVICE_UNAVAILABLE` along with a brief human-readable explanation. +The generated status page produced will try to bring in a stylesheet +`/error.css`. This allows you to produce a styled error pages with logos, +graphics etc. See [this](https://libwebsockets.org/git/badrepo) for an example of what you can do with it. + diff --git a/changelog b/changelog index 8ce883c2e..4ce593582 100644 --- a/changelog +++ b/changelog @@ -15,7 +15,11 @@ v3.1.0 - CHANGE: Minimal examples updated to use Content Security Policy best practices, using `LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE` vhost - option flag and disabling of inline style and scripts. + option flag and disabling of inline style and scripts. A side-effect of + this is that buffers used to marshal headers have to be prepared to take + more content than previously... LWS_RECOMMENDED_MIN_HEADER_SPACE (2048 + currently) is available for user (and internal) use to logically tie the + buffer size to this usecase (and follow future increases). - NEW: CMAKE - LWS_FOR_GITOHASHI: sets various cmake options suitable for gitohashi diff --git a/include/libwebsockets/lws-adopt.h b/include/libwebsockets/lws-adopt.h index 919a668de..256e3f9fd 100644 --- a/include/libwebsockets/lws-adopt.h +++ b/include/libwebsockets/lws-adopt.h @@ -47,8 +47,8 @@ LWS_VISIBLE LWS_EXTERN struct lws * lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd); /** - * lws_adopt_socket_vhost() - adopt foreign socket as if listen socket accepted it - * for vhost + * lws_adopt_socket_vhost() - adopt foreign socket as if listen socket accepted + * it for vhost * * \param vh: lws vhost * \param accept_fd: fd of already-accepted socket to adopt @@ -142,8 +142,8 @@ lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd, * accepted it for vhost. * \param vhost: lws vhost * \param accept_fd: fd of already-accepted socket to adopt - * \param readbuf: NULL or pointer to data that must be drained before reading from - * accept_fd + * \param readbuf: NULL or pointer to data that must be drained before + * reading from accept_fd * \param len: The length of the data held at \param readbuf * * Either returns new wsi bound to accept_fd, or closes accept_fd and @@ -161,8 +161,9 @@ lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd, * readbuf is limited to the size of the ah rx buf, currently 2048 bytes. */ LWS_VISIBLE LWS_EXTERN struct lws * -lws_adopt_socket_vhost_readbuf(struct lws_vhost *vhost, lws_sockfd_type accept_fd, - const char *readbuf, size_t len); +lws_adopt_socket_vhost_readbuf(struct lws_vhost *vhost, + lws_sockfd_type accept_fd, const char *readbuf, + size_t len); #define LWS_CAUDP_BIND 1 diff --git a/include/libwebsockets/lws-context-vhost.h b/include/libwebsockets/lws-context-vhost.h index c6ab222a2..a63d70862 100644 --- a/include/libwebsockets/lws-context-vhost.h +++ b/include/libwebsockets/lws-context-vhost.h @@ -146,18 +146,20 @@ enum lws_context_options { * mappings like www.mysite.com / mysite.com */ LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE = (1 << 28), - /**< (VH) Send lws default HTTP headers recommended by Mozilla Observatory - * for security. This is a helper option that sends canned headers on each - * http response enabling a VERY strict Content Security Policy. The policy - * is so strict, for example it won't let the page run its own inline JS nor - * show images or take CSS from a different server. In many cases your JS only - * comes from your server as do the image sources and CSS, so that is what you - * want... attackers hoping to inject JS into your DOM are completely out of - * luck since even if they succeed, it will be rejected for execution by the - * browser according to the strict CSP. In other cases you have to deviate from - * the complete strictness, in which case don't use this flag: use the .headers - * member in the vhost init described in struct lws_context_creation_info - * instead to send the adapted headers yourself. + /**< (VH) Send lws default HTTP headers recommended by Mozilla + * Observatory for security. This is a helper option that sends canned + * headers on each http response enabling a VERY strict Content Security + * Policy. The policy is so strict, for example it won't let the page + * run its own inline JS nor show images or take CSS from a different + * server. In many cases your JS only comes from your server as do the + * image sources and CSS, so that is what you want... attackers hoping + * to inject JS into your DOM are completely out of luck since even if + * they succeed, it will be rejected for execution by the browser + * according to the strict CSP. In other cases you have to deviate from + * the complete strictness, in which case don't use this flag: use the + * .headers member in the vhost init described in struct + * lws_context_creation_info instead to send the adapted headers + * yourself. */ /****** add new things just above ---^ ******/ @@ -194,15 +196,15 @@ struct lws_context_creation_info { * sockets in abstract namespace, by prepending an at symbol to the * socket name. */ const struct lws_protocols *protocols; - /**< VHOST: Array of structures listing supported protocols and a protocol- - * specific callback for each one. The list is ended with an + /**< VHOST: Array of structures listing supported protocols and a + * protocol-specific callback for each one. The list is ended with an * entry that has a NULL callback pointer. */ const struct lws_extension *extensions; /**< VHOST: NULL or array of lws_extension structs listing the * extensions this context supports. */ const struct lws_token_limits *token_limits; - /**< CONTEXT: NULL or struct lws_token_limits pointer which is initialized - * with a token length limit for each possible WSI_TOKEN_ */ + /**< CONTEXT: NULL or struct lws_token_limits pointer which is + * initialized with a token length limit for each possible WSI_TOKEN_ */ const char *ssl_private_key_password; /**< VHOST: NULL or the passphrase needed for the private key. (For * backwards compatibility, this can also be used to pass the client @@ -241,13 +243,16 @@ struct lws_context_creation_info { */ const char *http_proxy_address; /**< VHOST: If non-NULL, attempts to proxy via the given address. - * If proxy auth is required, use format "username:password\@server:port" */ + * If proxy auth is required, use format + * "username:password\@server:port" */ unsigned int http_proxy_port; /**< VHOST: If http_proxy_address was non-NULL, uses this port */ int gid; - /**< CONTEXT: group id to change to after setting listen socket, or -1. */ + /**< CONTEXT: group id to change to after setting listen socket, + * or -1. */ int uid; - /**< CONTEXT: user id to change to after setting listen socket, or -1. */ + /**< CONTEXT: user id to change to after setting listen socket, + * or -1. */ unsigned int options; /**< VHOST + CONTEXT: 0, or LWS_SERVER_OPTION_... bitfields */ void *user; @@ -302,7 +307,8 @@ struct lws_context_creation_info { * nonzero, this member lets you set the timeout used in seconds. * Otherwise a default timeout is used. */ const char *ecdh_curve; - /**< VHOST: if NULL, defaults to initializing server with "prime256v1" */ + /**< VHOST: if NULL, defaults to initializing server with + * "prime256v1" */ const char *vhost_name; /**< VHOST: name of vhost, must match external DNS name used to * access the site, like "warmcat.com" as it's used to match @@ -385,10 +391,11 @@ struct lws_context_creation_info { const char *client_ssl_ca_filepath; /**< VHOST: Client SSL context init: CA certificate filepath or NULL */ const void *client_ssl_ca_mem; - /**< VHOST: Client SSL context init: CA certificate memory buffer or NULL - * use this to load CA cert from memory instead of file */ + /**< VHOST: Client SSL context init: CA certificate memory buffer or + * NULL... use this to load CA cert from memory instead of file */ unsigned int client_ssl_ca_mem_len; - /**< VHOST: Client SSL context init: length of client_ssl_ca_mem in bytes */ + /**< VHOST: Client SSL context init: length of client_ssl_ca_mem in + * bytes */ const char *client_ssl_cipher_list; /**< VHOST: Client SSL context init: List of valid ciphers to use (eg, @@ -403,10 +410,12 @@ struct lws_context_creation_info { * backwards compatibility. */ int simultaneous_ssl_restriction; - /**< CONTEXT: 0 (no limit) or limit of simultaneous SSL sessions possible.*/ + /**< CONTEXT: 0 (no limit) or limit of simultaneous SSL sessions + * possible.*/ const char *socks_proxy_address; /**< VHOST: If non-NULL, attempts to proxy via the given address. - * If proxy auth is required, use format "username:password\@server:port" */ + * If proxy auth is required, use format + * "username:password\@server:port" */ unsigned int socks_proxy_port; /**< VHOST: If socks_proxy_address was non-NULL, uses this port */ #if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP) diff --git a/include/libwebsockets/lws-genrsa.h b/include/libwebsockets/lws-genrsa.h index 1ad4f3d2d..3e427e292 100644 --- a/include/libwebsockets/lws-genrsa.h +++ b/include/libwebsockets/lws-genrsa.h @@ -161,8 +161,8 @@ lws_genrsa_public_verify(struct lws_genrsa_ctx *ctx, const uint8_t *in, */ LWS_VISIBLE LWS_EXTERN int lws_genrsa_public_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in, - enum lws_genhash_types hash_type, uint8_t *sig, - size_t sig_len); + enum lws_genhash_types hash_type, uint8_t *sig, + size_t sig_len); /** lws_genrsa_public_decrypt_destroy() - Destroy RSA public decrypt context * diff --git a/include/libwebsockets/lws-http.h b/include/libwebsockets/lws-http.h index 9319ac98f..eb3d826eb 100644 --- a/include/libwebsockets/lws-http.h +++ b/include/libwebsockets/lws-http.h @@ -133,7 +133,8 @@ struct lws_process_html_args { int len; /**< length of the original data at p */ int max_len; /**< maximum length we can grow the data to */ int final; /**< set if this is the last chunk of the file */ - int chunked; /**< 0 == unchunked, 1 == produce chunk headers (incompatible with HTTP/2) */ + int chunked; /**< 0 == unchunked, 1 == produce chunk headers + (incompatible with HTTP/2) */ }; typedef const char *(*lws_process_html_state_cb)(void *data, int index); @@ -146,7 +147,8 @@ struct lws_process_html_state { const char * const *vars; /**< list of variable names */ int count_vars; /**< count of variable names */ - lws_process_html_state_cb replace; /**< called on match to perform substitution */ + lws_process_html_state_cb replace; + /**< called on match to perform substitution */ }; /*! lws_chunked_html_process() - generic chunked substitution @@ -360,7 +362,8 @@ lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h); * \param frag_idx: which fragment of h we want to get the length of */ LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx); +lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, + int frag_idx); /** * lws_hdr_copy() - copy all fragments of the given header to a buffer diff --git a/include/libwebsockets/lws-logs.h b/include/libwebsockets/lws-logs.h index a108cd751..9317dcc70 100644 --- a/include/libwebsockets/lws-logs.h +++ b/include/libwebsockets/lws-logs.h @@ -34,20 +34,20 @@ ///@{ enum lws_log_levels { - LLL_ERR = 1 << 0, - LLL_WARN = 1 << 1, - LLL_NOTICE = 1 << 2, - LLL_INFO = 1 << 3, - LLL_DEBUG = 1 << 4, - LLL_PARSER = 1 << 5, - LLL_HEADER = 1 << 6, - LLL_EXT = 1 << 7, - LLL_CLIENT = 1 << 8, - LLL_LATENCY = 1 << 9, - LLL_USER = 1 << 10, - LLL_THREAD = 1 << 11, + LLL_ERR = 1 << 0, + LLL_WARN = 1 << 1, + LLL_NOTICE = 1 << 2, + LLL_INFO = 1 << 3, + LLL_DEBUG = 1 << 4, + LLL_PARSER = 1 << 5, + LLL_HEADER = 1 << 6, + LLL_EXT = 1 << 7, + LLL_CLIENT = 1 << 8, + LLL_LATENCY = 1 << 9, + LLL_USER = 1 << 10, + LLL_THREAD = 1 << 11, - LLL_COUNT = 12 /* set to count of valid flags */ + LLL_COUNT = 12 /* set to count of valid flags */ }; LWS_VISIBLE LWS_EXTERN void _lws_log(int filter, const char *format, ...) LWS_FORMAT(2); diff --git a/include/libwebsockets/lws-plugin-generic-sessions.h b/include/libwebsockets/lws-plugin-generic-sessions.h index 4cf1b3c8e..7f46f854e 100644 --- a/include/libwebsockets/lws-plugin-generic-sessions.h +++ b/include/libwebsockets/lws-plugin-generic-sessions.h @@ -42,10 +42,10 @@ typedef struct { char id[41]; /**< ascii hex representation of hash */ } lwsgw_h /** enum lwsgs_auth_bits */ enum lwsgs_auth_bits { - LWSGS_AUTH_LOGGED_IN = 1, /**< user is logged in as somebody */ - LWSGS_AUTH_ADMIN = 2, /**< logged in as the admin user */ - LWSGS_AUTH_VERIFIED = 4, /**< user has verified his email */ - LWSGS_AUTH_FORGOT_FLOW = 8, /**< he just completed "forgot password" flow */ + LWSGS_AUTH_LOGGED_IN = 1, /**< user is logged in as somebody */ + LWSGS_AUTH_ADMIN = 2, /**< logged in as the admin user */ + LWSGS_AUTH_VERIFIED = 4, /**< user has verified his email */ + LWSGS_AUTH_FORGOT_FLOW = 8, /**< just completed "forgot password" */ }; /** struct lws_session_info - information about user session status */ diff --git a/include/libwebsockets/lws-protocols-plugins.h b/include/libwebsockets/lws-protocols-plugins.h index 5b3507d7a..b6cc44e27 100644 --- a/include/libwebsockets/lws-protocols-plugins.h +++ b/include/libwebsockets/lws-protocols-plugins.h @@ -123,8 +123,8 @@ lws_protocol_get(struct lws *wsi) LWS_WARN_DEPRECATED; * helper to be called in the per-vhost init LWS_CALLBACK_PROTOCOL_INIT */ LWS_VISIBLE LWS_EXTERN void * -lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost, const struct lws_protocols *prot, - int size); +lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost, + const struct lws_protocols *prot, int size); /** * lws_protocol_vh_priv_get() - retreive a protocol's per-vhost storage @@ -136,7 +136,8 @@ lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost, const struct lws_protocols * by lws_protocol_vh_priv_zalloc() earlier */ LWS_VISIBLE LWS_EXTERN void * -lws_protocol_vh_priv_get(struct lws_vhost *vhost, const struct lws_protocols *prot); +lws_protocol_vh_priv_get(struct lws_vhost *vhost, + const struct lws_protocols *prot); /** * lws_adjust_protocol_psds - change a vhost protocol's per session data size diff --git a/include/libwebsockets/lws-spa.h b/include/libwebsockets/lws-spa.h index 886d99ad8..fcaf3889f 100644 --- a/include/libwebsockets/lws-spa.h +++ b/include/libwebsockets/lws-spa.h @@ -65,8 +65,8 @@ enum lws_spa_fileupload_states { * HTTP provided by the client. */ typedef int (*lws_spa_fileupload_cb)(void *data, const char *name, - const char *filename, char *buf, int len, - enum lws_spa_fileupload_states state); + const char *filename, char *buf, int len, + enum lws_spa_fileupload_states state); /** struct lws_spa - opaque urldecode parser capable of handling multipart * and file uploads */ diff --git a/include/libwebsockets/lws-writeable.h b/include/libwebsockets/lws-writeable.h index b37cbffc0..dd5659c3f 100644 --- a/include/libwebsockets/lws-writeable.h +++ b/include/libwebsockets/lws-writeable.h @@ -124,7 +124,8 @@ lws_callback_all_protocol(struct lws_context *context, */ LWS_VISIBLE LWS_EXTERN int lws_callback_all_protocol_vhost(struct lws_vhost *vh, - const struct lws_protocols *protocol, int reason) + const struct lws_protocols *protocol, + int reason) LWS_WARN_DEPRECATED; /** @@ -143,8 +144,8 @@ LWS_WARN_DEPRECATED; */ LWS_VISIBLE int lws_callback_all_protocol_vhost_args(struct lws_vhost *vh, - const struct lws_protocols *protocol, int reason, - void *argp, size_t len); + const struct lws_protocols *protocol, + int reason, void *argp, size_t len); /** * lws_callback_vhost_protocols() - Callback all protocols enabled on a vhost @@ -186,7 +187,7 @@ lws_callback_vhost_protocols_vhost(struct lws_vhost *vh, int reason, void *in, LWS_VISIBLE LWS_EXTERN int lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len); + void *user, void *in, size_t len); /** * lws_get_socket_fd() - returns the socket file descriptor diff --git a/include/libwebsockets/lws-ws-ext.h b/include/libwebsockets/lws-ws-ext.h index 7bcf4e01a..3face4f34 100644 --- a/include/libwebsockets/lws-ws-ext.h +++ b/include/libwebsockets/lws-ws-ext.h @@ -168,8 +168,8 @@ lws_set_extension_option(struct lws *wsi, const char *ext_name, */ LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi, - void *ext_user, const struct lws_ext_options *opts, - const char *o, int len); + void *ext_user, const struct lws_ext_options *opts, + const char *o, int len); /** lws_extension_callback_pm_deflate() - extension for RFC7692 * @@ -183,11 +183,12 @@ lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi, * * Built-in callback implementing RFC7692 permessage-deflate */ -LWS_EXTERN -int lws_extension_callback_pm_deflate( - struct lws_context *context, const struct lws_extension *ext, - struct lws *wsi, enum lws_extension_callback_reasons reason, - void *user, void *in, size_t len); +LWS_EXTERN int +lws_extension_callback_pm_deflate(struct lws_context *context, + const struct lws_extension *ext, + struct lws *wsi, + enum lws_extension_callback_reasons reason, + void *user, void *in, size_t len); /* * The internal exts are part of the public abi diff --git a/lib/core/adopt.c b/lib/core/adopt.c index d16713795..49ac5af16 100644 --- a/lib/core/adopt.c +++ b/lib/core/adopt.c @@ -95,8 +95,8 @@ lws_create_new_server_wsi(struct lws_vhost *vhost, int fixed_tsi) * outermost create notification for wsi * no user_space because no protocol selection */ - vhost->protocols[0].callback(new_wsi, LWS_CALLBACK_WSI_CREATE, - NULL, NULL, 0); + vhost->protocols[0].callback(new_wsi, LWS_CALLBACK_WSI_CREATE, NULL, + NULL, 0); return new_wsi; } @@ -216,8 +216,8 @@ lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type, * by deferring callback to this point, after insertion to fds, * lws_callback_on_writable() can work from the callback */ - if ((new_wsi->protocol->callback)( - new_wsi, n, new_wsi->user_space, NULL, 0)) + if ((new_wsi->protocol->callback)(new_wsi, n, new_wsi->user_space, + NULL, 0)) goto fail; /* role may need to do something after all adoption completed */ @@ -309,7 +309,8 @@ adopt_socket_readbuf(struct lws *wsi, const char *readbuf, size_t len) lwsl_notice("%s: calling service on readbuf ah\n", __func__); - /* unlike a normal connect, we have the headers already + /* + * unlike a normal connect, we have the headers already * (or the first part of them anyway). * libuv won't come back and service us without a network * event, so we need to do the header service right here. @@ -400,7 +401,7 @@ lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd, const char *readbuf, size_t len) { return adopt_socket_readbuf(lws_adopt_socket(context, accept_fd), - readbuf, len); + readbuf, len); } LWS_VISIBLE struct lws * @@ -409,5 +410,5 @@ lws_adopt_socket_vhost_readbuf(struct lws_vhost *vhost, const char *readbuf, size_t len) { return adopt_socket_readbuf(lws_adopt_socket_vhost(vhost, accept_fd), - readbuf, len); + readbuf, len); } diff --git a/lib/core/connect.c b/lib/core/connect.c index 7dd2a5e03..daffc193c 100644 --- a/lib/core/connect.c +++ b/lib/core/connect.c @@ -88,8 +88,8 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i) */ #if LWS_MAX_SMP > 1 - tid = wsi->vhost->protocols[0].callback(wsi, - LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0); + tid = wsi->vhost->protocols[0].callback(wsi, LWS_CALLBACK_GET_THREAD_ID, + NULL, NULL, 0); lws_context_lock(i->context, "client find tsi"); diff --git a/lib/core/context.c b/lib/core/context.c index 24f1cca23..94b2d8633 100644 --- a/lib/core/context.c +++ b/lib/core/context.c @@ -317,8 +317,8 @@ lws_protocol_init(struct lws_context *context) (void *)pvo, 0)) { lws_free(vh->protocol_vh_privs[n]); vh->protocol_vh_privs[n] = NULL; - lwsl_err("%s: protocol %s failed init\n", __func__, - vh->protocols[n].name); + lwsl_err("%s: protocol %s failed init\n", + __func__, vh->protocols[n].name); return 1; } @@ -462,10 +462,12 @@ lws_create_vhost(struct lws_context *context, n += (int)strlen(info->ssl_private_key_filepath) + 1; if (n) { - vh->tls.key_path = vh->tls.alloc_cert_path = lws_malloc(n, "vh paths"); + vh->tls.key_path = vh->tls.alloc_cert_path = + lws_malloc(n, "vh paths"); if (info->ssl_cert_filepath) { n = (int)strlen(info->ssl_cert_filepath) + 1; - memcpy(vh->tls.alloc_cert_path, info->ssl_cert_filepath, n); + memcpy(vh->tls.alloc_cert_path, + info->ssl_cert_filepath, n); vh->tls.key_path += n; } if (info->ssl_private_key_filepath) @@ -480,7 +482,7 @@ lws_create_vhost(struct lws_context *context, */ lwsp = lws_zalloc(sizeof(struct lws_protocols) * (vh->count_protocols + context->plugin_protocol_count + 1), - "vhost-specific plugin table"); + "vhost-specific plugin table"); if (!lwsp) { lwsl_err("OOM\n"); return NULL; @@ -557,8 +559,8 @@ lws_create_vhost(struct lws_context *context, break; } lwsl_notice("Creating Vhost '%s' %s, %d protocols, IPv6 %s\n", - vh->name, buf, vh->count_protocols, - LWS_IPV6_ENABLED(vh) ? "on" : "off"); + vh->name, buf, vh->count_protocols, + LWS_IPV6_ENABLED(vh) ? "on" : "off"); } mounts = info->mounts; while (mounts) { @@ -673,7 +675,6 @@ lws_create_vhost(struct lws_context *context, goto bail1; } - while (1) { if (!(*vh1)) { *vh1 = vh; @@ -758,7 +759,7 @@ lws_create_event_pipes(struct lws_context *context) wsi = lws_zalloc(sizeof(*wsi), "event pipe wsi"); if (!wsi) { - lwsl_err("Out of mem\n"); + lwsl_err("%s: Out of mem\n", __func__); return 1; } wsi->context = context; @@ -829,8 +830,6 @@ lws_create_context(const struct lws_context_creation_info *info) struct rlimit rt; #endif - - lwsl_info("Initial logging level %d\n", log_level); lwsl_info("Libwebsockets version: %s\n", library_version); diff --git a/lib/core/dummy-callback.c b/lib/core/dummy-callback.c index eed70dd78..8fd18be9c 100644 --- a/lib/core/dummy-callback.c +++ b/lib/core/dummy-callback.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010-2018 Andy Green * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -166,7 +166,8 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, lwsl_debug("%s: %p: issuing proxy headers\n", __func__, wsi); - n = lws_write(wsi, wsi->http.pending_return_headers + LWS_PRE, + n = lws_write(wsi, wsi->http.pending_return_headers + + LWS_PRE, wsi->http.pending_return_headers_len, LWS_WRITE_HTTP_HEADERS); @@ -339,10 +340,11 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, if (lws_finalize_http_header(parent, &p, end)) return 1; - parent->http.pending_return_headers_len = lws_ptr_diff(p, start); + parent->http.pending_return_headers_len = + lws_ptr_diff(p, start); parent->http.pending_return_headers = - lws_malloc(parent->http.pending_return_headers_len + LWS_PRE, - "return proxy headers"); + lws_malloc(parent->http.pending_return_headers_len + + LWS_PRE, "return proxy headers"); if (!parent->http.pending_return_headers) return -1; @@ -351,7 +353,8 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, parent->reason_bf |= LWS_CB_REASON_AUX_BF__PROXY_HEADERS; - lwsl_debug("%s: LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: prepared headers\n", __func__); + lwsl_debug("%s: LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: " + "prepared headers\n", __func__); lws_callback_on_writable(parent); break; } @@ -475,12 +478,15 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, /* gzip handling */ if (!wsi->http.cgi->gzip_init) { - lwsl_err("inflating gzip\n"); + lwsl_info("inflating gzip\n"); - memset(&wsi->http.cgi->inflate, 0, sizeof(wsi->http.cgi->inflate)); + memset(&wsi->http.cgi->inflate, 0, + sizeof(wsi->http.cgi->inflate)); - if (inflateInit2(&wsi->http.cgi->inflate, 16 + 15) != Z_OK) { - lwsl_err("%s: iniflateInit failed\n", __func__); + if (inflateInit2(&wsi->http.cgi->inflate, + 16 + 15) != Z_OK) { + lwsl_err("%s: iniflateInit failed\n", + __func__); return -1; } diff --git a/lib/core/libwebsockets.c b/lib/core/libwebsockets.c index 1da3a44af..972422114 100644 --- a/lib/core/libwebsockets.c +++ b/lib/core/libwebsockets.c @@ -439,7 +439,8 @@ __lws_hrtimer_service(struct lws_context_per_thread *pt) if (!pt->dll_head_hrtimer.next) return LWS_HRTIMER_NOWAIT; - wsi = lws_container_of(pt->dll_head_hrtimer.next, struct lws, dll_hrtimer); + wsi = lws_container_of(pt->dll_head_hrtimer.next, struct lws, + dll_hrtimer); gettimeofday(&now, NULL); t = (now.tv_sec * 1000000ll) + now.tv_usec; @@ -477,7 +478,8 @@ lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs) if (secs == LWS_TO_KILL_SYNC) { lws_remove_from_timeout_list(wsi); lwsl_debug("synchronously killing %p\n", wsi); - lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "to sync kill"); + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, + "to sync kill"); return; } @@ -592,7 +594,8 @@ lws_remove_child_from_any_parent(struct lws *wsi) } int -lws_bind_protocol(struct lws *wsi, const struct lws_protocols *p, const char *reason) +lws_bind_protocol(struct lws *wsi, const struct lws_protocols *p, + const char *reason) { // if (wsi->protocol == p) // return 0; @@ -648,7 +651,8 @@ lws_bind_protocol(struct lws *wsi, const struct lws_protocols *p, const char *re } void -__lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, const char *caller) +__lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, + const char *caller) { struct lws_context_per_thread *pt; struct lws *wsi1, *wsi2; @@ -680,20 +684,21 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, const char * if ((int)reason != -1) lws_vhost_lock(wsi->vhost); lws_start_foreach_dll_safe(struct lws_dll_lws *, d, d1, - wsi->dll_client_transaction_queue_head.next) { + wsi->dll_client_transaction_queue_head.next) { struct lws *w = lws_container_of(d, struct lws, - dll_client_transaction_queue); + dll_client_transaction_queue); __lws_close_free_wsi(w, -1, "trans q leader closing"); } lws_end_foreach_dll_safe(d, d1); /* - * !!! If we are closing, but we have pending pipelined transaction - * results we already sent headers for, that's going to destroy sync - * for HTTP/1 and leave H2 stream with no live swsi. + * !!! If we are closing, but we have pending pipelined + * transaction results we already sent headers for, that's going + * to destroy sync for HTTP/1 and leave H2 stream with no live + * swsi. * - * However this is normal if we are being closed because the transaction - * queue leader is closing. + * However this is normal if we are being closed because the + * transaction queue leader is closing. */ lws_dll_lws_remove(&wsi->dll_client_transaction_queue); if ((int)reason !=-1) @@ -709,7 +714,8 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, const char * wsi2->parent = NULL; /* stop it doing shutdown processing */ wsi2->socket_is_permanently_unusable = 1; - __lws_close_free_wsi(wsi2, reason, "general child recurse"); + __lws_close_free_wsi(wsi2, reason, + "general child recurse"); wsi2 = wsi1; } wsi->child_list = NULL; @@ -734,7 +740,8 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, const char * lws_cgi_remove_and_kill(wsi->parent); /* end the binding between us and master */ - wsi->parent->http.cgi->stdwsi[(int)wsi->cgi_channel] = NULL; + wsi->parent->http.cgi->stdwsi[(int)wsi->cgi_channel] = + NULL; } wsi->socket_is_permanently_unusable = 1; @@ -886,7 +893,7 @@ just_kill_connection: } else #endif { - lwsl_info("%s: shutdown conn: %p (sock %d, state 0x%x)\n", + lwsl_info("%s: shutdown conn: %p (sk %d, state 0x%x)\n", __func__, wsi, (int)(long)wsi->desc.sockfd, lwsi_state(wsi)); if (!wsi->socket_is_permanently_unusable && @@ -1066,8 +1073,7 @@ lws_buflist_append_segment(struct lws_buflist **head, const uint8_t *buf, lwsl_info("%s: len %u first %d %p\n", __func__, (uint32_t)len, first, p); - nbuf = (struct lws_buflist *) - lws_malloc(sizeof(**head) + len, __func__); + nbuf = (struct lws_buflist *)lws_malloc(sizeof(**head) + len, __func__); if (!nbuf) { lwsl_err("%s: OOM\n", __func__); return -1; @@ -1609,8 +1615,8 @@ lws_vfs_select_fops(const struct lws_plat_file_ops *fops, const char *vfs_path, while (n < (int)LWS_ARRAY_SIZE(pf->fi) && pf->fi[n].sig) { if (p >= vfs_path + pf->fi[n].len) if (!strncmp(p - (pf->fi[n].len - 1), - pf->fi[n].sig, - pf->fi[n].len - 1)) { + pf->fi[n].sig, + pf->fi[n].len - 1)) { *vpath = p + 1; return pf; } @@ -2287,7 +2293,7 @@ lws_get_peer_write_allowance(struct lws *wsi) LWS_VISIBLE void lws_role_transition(struct lws *wsi, enum lwsi_role role, enum lwsi_state state, - struct lws_role_ops *ops) + struct lws_role_ops *ops) { #if defined(_DEBUG) const char *name = "(unset)"; @@ -2408,7 +2414,7 @@ __lws_rx_flow_control(struct lws *wsi) wsi->rxflow_change_to &= ~LWS_RXFLOW_PENDING_CHANGE; lwsl_info("rxflow: wsi %p change_to %d\n", wsi, - wsi->rxflow_change_to & LWS_RXFLOW_ALLOW); + wsi->rxflow_change_to & LWS_RXFLOW_ALLOW); /* adjust the pollfd for this wsi */ @@ -2720,7 +2726,7 @@ lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port, #endif if (n < 0) { lwsl_err("ERROR on binding fd %d to port %d (%d %d)\n", - sockfd, port, n, LWS_ERRNO); + sockfd, port, n, LWS_ERRNO); /* if something already listening, tell caller to fail permanently */ @@ -2735,7 +2741,7 @@ lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port, #if defined(LWS_WITH_UNIX_SOCK) if (LWS_UNIX_SOCK_ENABLED(vhost) && vhost->context->uid) if (chown(serv_unix.sun_path, vhost->context->uid, - vhost->context->gid)) + vhost->context->gid)) lwsl_notice("%s: chown for unix skt %s failed\n", __func__, serv_unix.sun_path); #endif @@ -2814,7 +2820,7 @@ lws_get_addr_scope(const char *ipaddr) for (i = 0; i < 5; i++) { ret = GetAdaptersAddresses(AF_INET6, GAA_FLAG_INCLUDE_PREFIX, - NULL, addrs, &size); + NULL, addrs, &size); if ((ret == NO_ERROR) || (ret == ERROR_NO_DATA)) { break; } else if (ret == ERROR_BUFFER_OVERFLOW) diff --git a/lib/core/output.c b/lib/core/output.c index 6c8b9b91d..49d289db4 100644 --- a/lib/core/output.c +++ b/lib/core/output.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010-2018 Andy Green * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -146,7 +146,7 @@ int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len) m = (int)real_len; if (lwsi_state(wsi) == LRS_FLUSHING_BEFORE_CLOSE) { - lwsl_info("** %p signalling to close now\n", wsi); + lwsl_info("*%p signalling to close now\n", wsi); return -1; /* retry closing now */ } @@ -190,7 +190,8 @@ int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len) lws_buflist_append_segment(&wsi->buflist_out, buf + m, real_len - m); lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_WRITE_PARTIALS, 1); - lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_B_PARTIALS_ACCEPTED_PARTS, m); + lws_stats_atomic_bump(wsi->context, pt, + LWSSTATS_B_PARTIALS_ACCEPTED_PARTS, m); #if !defined(LWS_WITH_ESP32) if (lws_wsi_is_udp(wsi)) { @@ -305,7 +306,7 @@ lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len) } lwsl_debug("ERROR writing len %d to skt fd %d err %d / errno %d\n", - len, wsi->desc.sockfd, n, LWS_ERRNO); + len, wsi->desc.sockfd, n, LWS_ERRNO); return LWS_SSL_CAPABLE_ERROR; } diff --git a/lib/core/pollfd.c b/lib/core/pollfd.c index 4bb92b0d2..834298577 100644 --- a/lib/core/pollfd.c +++ b/lib/core/pollfd.c @@ -134,7 +134,8 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa) pfd = &pt->fds[wsi->position_in_fds_table]; pa->fd = wsi->desc.sockfd; - lwsl_debug("%s: wsi %p: fd %d events %d -> %d\n", __func__, wsi, pa->fd, pfd->events, (pfd->events & ~_and) | _or); + lwsl_debug("%s: wsi %p: fd %d events %d -> %d\n", __func__, wsi, + pa->fd, pfd->events, (pfd->events & ~_and) | _or); pa->prev_events = pfd->events; pa->events = pfd->events = (pfd->events & ~_and) | _or; @@ -245,7 +246,8 @@ __insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi) #if !defined(_WIN32) if (wsi->desc.sockfd - lws_plat_socket_offset() >= context->max_fds) { lwsl_err("Socket fd %d is too high (%d) offset %d\n", - wsi->desc.sockfd, context->max_fds, lws_plat_socket_offset()); + wsi->desc.sockfd, context->max_fds, + lws_plat_socket_offset()); return 1; } #endif @@ -325,7 +327,7 @@ __remove_wsi_socket_from_fds(struct lws *wsi) LWS_EV_STOP | LWS_EV_READ | LWS_EV_WRITE | LWS_EV_PREPARE_DELETION); - lwsl_debug("%s: wsi=%p, sock=%d, fds pos=%d, end guy pos=%d, endfd=%d\n", + lwsl_debug("%s: wsi=%p, skt=%d, fds pos=%d, end guy pos=%d, endfd=%d\n", __func__, wsi, wsi->desc.sockfd, wsi->position_in_fds_table, pt->fds_count, pt->fds[pt->fds_count].fd); @@ -337,10 +339,11 @@ __remove_wsi_socket_from_fds(struct lws *wsi) lws_plat_delete_socket_from_fds(context, wsi, m); pt->count_conns--; v = (int) pt->fds[m].fd; - /* end guy's "position in fds table" is now the deletion guy's old one */ + /* end guy's "position in fds table" is now the deletion + * guy's old one */ end_wsi = wsi_from_fd(context, v); if (!end_wsi) { - lwsl_err("no wsi for fd %d at pos %d, pt->fds_count=%d\n", + lwsl_err("no wsi for fd %d pos %d, pt->fds_count=%d\n", (int)pt->fds[m].fd, m, pt->fds_count); assert(0); } else @@ -549,7 +552,7 @@ lws_callback_on_writable_all_protocol(const struct lws_context *context, while (vhost) { for (n = 0; n < vhost->count_protocols; n++) if (protocol->callback == - vhost->protocols[n].callback && + vhost->protocols[n].callback && !strcmp(protocol->name, vhost->protocols[n].name)) break; if (n != vhost->count_protocols) diff --git a/lib/core/private.h b/lib/core/private.h index a5722b890..c1a0a661b 100644 --- a/lib/core/private.h +++ b/lib/core/private.h @@ -164,11 +164,11 @@ extern "C" { * Non-SSL mode also uses these types. */ enum lws_ssl_capable_status { - LWS_SSL_CAPABLE_ERROR = -1, /* it failed */ - LWS_SSL_CAPABLE_DONE = 0, /* it succeeded */ - LWS_SSL_CAPABLE_MORE_SERVICE_READ = -2, /* retry WANT_READ */ - LWS_SSL_CAPABLE_MORE_SERVICE_WRITE = -3, /* retry WANT_WRITE */ - LWS_SSL_CAPABLE_MORE_SERVICE = -4, /* general retry */ + LWS_SSL_CAPABLE_ERROR = -1, /* it failed */ + LWS_SSL_CAPABLE_DONE = 0, /* it succeeded */ + LWS_SSL_CAPABLE_MORE_SERVICE_READ = -2, /* retry WANT_READ */ + LWS_SSL_CAPABLE_MORE_SERVICE_WRITE = -3, /* retry WANT_WRITE */ + LWS_SSL_CAPABLE_MORE_SERVICE = -4, /* general retry */ }; #if defined(__clang__) @@ -403,7 +403,8 @@ struct lws_context_per_thread { struct lws_pt_eventlibs_libevent event; #endif -#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || defined(LWS_WITH_LIBEVENT) +#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || \ + defined(LWS_WITH_LIBEVENT) struct lws_signal_watcher w_sigint; #endif @@ -779,7 +780,7 @@ enum { #if defined(LWS_WITH_ESP32) LWS_EXTERN int -lws_find_string_in_file(const char *filename, const char *string, int stringlen); +lws_find_string_in_file(const char *filename, const char *str, int stringlen); #endif #ifdef LWS_WITH_IPV6 @@ -864,7 +865,8 @@ struct lws { /* lifetime members */ -#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || defined(LWS_WITH_LIBEVENT) +#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || \ + defined(LWS_WITH_LIBEVENT) struct lws_io_watcher w_read; #endif #if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBEVENT) @@ -1457,8 +1459,8 @@ LWS_EXTERN int lws_check_byte_utf8(unsigned char state, unsigned char c); LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_check_utf8(unsigned char *state, unsigned char *buf, size_t len); -LWS_EXTERN int alloc_file(struct lws_context *context, const char *filename, uint8_t **buf, - lws_filepos_t *amount); +LWS_EXTERN int alloc_file(struct lws_context *context, const char *filename, + uint8_t **buf, lws_filepos_t *amount); LWS_EXTERN void @@ -1495,7 +1497,8 @@ void socks_generate_msg(struct lws *wsi, enum socks_msg_type type, void lws_peer_track_wsi_close(struct lws_context *context, struct lws_peer *peer); int -lws_peer_confirm_ah_attach_ok(struct lws_context *context, struct lws_peer *peer); +lws_peer_confirm_ah_attach_ok(struct lws_context *context, + struct lws_peer *peer); void lws_peer_track_ah_detach(struct lws_context *context, struct lws_peer *peer); void diff --git a/lib/core/service.c b/lib/core/service.c index 065756b15..ef251409c 100644 --- a/lib/core/service.c +++ b/lib/core/service.c @@ -349,7 +349,8 @@ lws_service_adjust_timeout(struct lws_context *context, int timeout_ms, int tsi) return 0; #endif - /* 2) if we know we have non-network pending data, do not wait in poll */ + /* 2) if we know we have non-network pending data, + * do not wait in poll */ if (pt->context->tls_ops && pt->context->tls_ops->fake_POLLIN_for_buffered && @@ -361,7 +362,8 @@ lws_service_adjust_timeout(struct lws_context *context, int timeout_ms, int tsi) * it, we should not wait in poll */ - lws_start_foreach_dll(struct lws_dll_lws *, d, pt->dll_head_buflist.next) { + lws_start_foreach_dll(struct lws_dll_lws *, d, + pt->dll_head_buflist.next) { struct lws *wsi = lws_container_of(d, struct lws, dll_buflist); if (lwsi_state(wsi) != LRS_DEFERRING_ACTION) @@ -372,7 +374,6 @@ lws_service_adjust_timeout(struct lws_context *context, int timeout_ms, int tsi) * poll but hurry along and service them */ - } lws_end_foreach_dll(d); return timeout_ms; @@ -459,8 +460,10 @@ lws_buflist_aware_consume(struct lws *wsi, struct lws_tokens *ebuf, int used, if (m < 0) return 1; /* OOM */ if (m) { - lwsl_debug("%s: added %p to rxflow list\n", __func__, wsi); - lws_dll_lws_add_front(&wsi->dll_buflist, &pt->dll_head_buflist); + lwsl_debug("%s: added %p to rxflow list\n", + __func__, wsi); + lws_dll_lws_add_front(&wsi->dll_buflist, + &pt->dll_head_buflist); } } @@ -546,7 +549,8 @@ lws_service_flag_pending(struct lws_context *context, int tsi) */ lws_start_foreach_dll_safe(struct lws_dll_lws *, p, p1, pt->tls.pending_tls_head.next) { - struct lws *wsi = lws_container_of(p, struct lws, tls.pending_tls_list); + struct lws *wsi = lws_container_of(p, struct lws, + tls.pending_tls_list); pt->fds[wsi->position_in_fds_table].revents |= pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN; diff --git a/lib/event-libs/libuv/libuv.c b/lib/event-libs/libuv/libuv.c index 3de132f03..39363f14c 100644 --- a/lib/event-libs/libuv/libuv.c +++ b/lib/event-libs/libuv/libuv.c @@ -162,8 +162,8 @@ lws_libuv_stop(struct lws_context *context) if (!wsi) continue; lws_close_free_wsi(wsi, - LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY, __func__ - /* no protocol close */); + LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY, + __func__ /* no protocol close */); n--; } } @@ -635,8 +635,8 @@ elops_accept_uv(struct lws *wsi) (int)(long long)wsi->desc.filefd); else uv_poll_init_socket(pt->uv.io_loop, - wsi->w_read.uv.pwatcher, - wsi->desc.sockfd); + wsi->w_read.uv.pwatcher, + wsi->desc.sockfd); ((uv_handle_t *)wsi->w_read.uv.pwatcher)->data = (void *)wsi; diff --git a/lib/misc/daemonize.c b/lib/misc/daemonize.c index c4bf28ccf..b41609f48 100644 --- a/lib/misc/daemonize.c +++ b/lib/misc/daemonize.c @@ -9,6 +9,10 @@ * * This version is LGPL2.1+SLE like the rest of libwebsockets and is * Copyright (c)2006 - 2013 Andy Green + * + * + * You're much better advised to use systemd to daemonize stuff without needing + * this kind of support in the app itself. */ #include @@ -35,6 +39,9 @@ int get_daemonize_pid() static void child_handler(int signum) { + int len, sent, fd; + char sz[20]; + switch (signum) { case SIGALRM: /* timed out daemonizing */ @@ -43,28 +50,27 @@ child_handler(int signum) case SIGUSR1: /* positive confirmation we daemonized well */ - if (lock_path) { - char sz[20]; - int len, sent; + if (!lock_path) + exit(0); - /* Create the lock file as the current user */ + /* Create the lock file as the current user */ - int fd = lws_open(lock_path, O_TRUNC | O_RDWR | O_CREAT, 0640); - if (fd < 0) { - fprintf(stderr, - "unable to create lock file %s, code=%d (%s)\n", - lock_path, errno, strerror(errno)); - exit(0); - } - len = sprintf(sz, "%u", pid_daemon); - sent = write(fd, sz, len); - if (sent != len) - fprintf(stderr, - "unable to write pid to lock file %s, code=%d (%s)\n", - lock_path, errno, strerror(errno)); - - close(fd); + fd = lws_open(lock_path, O_TRUNC | O_RDWR | O_CREAT, 0640); + if (fd < 0) { + fprintf(stderr, + "unable to create lock file %s, code=%d (%s)\n", + lock_path, errno, strerror(errno)); + exit(0); } + len = sprintf(sz, "%u", pid_daemon); + sent = write(fd, sz, len); + if (sent != len) + fprintf(stderr, + "unable to write pid to lock file %s, code=%d (%s)\n", + lock_path, errno, strerror(errno)); + + close(fd); + exit(0); //!!(sent == len)); @@ -118,12 +124,13 @@ lws_daemonize(const char *_lock_path) ret = kill(n, 0); if (ret >= 0) { fprintf(stderr, - "Daemon already running from pid %d\n", n); + "Daemon already running pid %d\n", + n); exit(1); } fprintf(stderr, - "Removing stale lock file %s from dead pid %d\n", - _lock_path, n); + "Removing stale lock %s from dead pid %d\n", + _lock_path, n); unlink(lock_path); } } diff --git a/lib/misc/fts/trie-fd.c b/lib/misc/fts/trie-fd.c index 18eb5df78..9e9105e93 100644 --- a/lib/misc/fts/trie-fd.c +++ b/lib/misc/fts/trie-fd.c @@ -617,8 +617,8 @@ ensure: struct lwsac *lt_head = NULL; struct linetable *ltst; char path[256], *pp; - off_t fo; int footprint; + off_t fo; ofd = -1; grab(o, sizeof(buf)); diff --git a/lib/misc/fts/trie.c b/lib/misc/fts/trie.c index c4a97cdcf..8dd93f7a4 100644 --- a/lib/misc/fts/trie.c +++ b/lib/misc/fts/trie.c @@ -261,7 +261,8 @@ lws_fts_create(int fd) t->fd = fd; t->lwsac_head = lwsac_head; - t->root = lwsac_use(&lwsac_head, sizeof(*t->root), TRIE_LWSAC_BLOCK_SIZE); + t->root = lwsac_use(&lwsac_head, sizeof(*t->root), + TRIE_LWSAC_BLOCK_SIZE); if (!t->root) goto unwind; @@ -349,7 +350,7 @@ lws_fts_file_index(struct lws_fts *t, const char *filepath, int filepath_len, static struct lws_fts_entry * lws_fts_entry_child_add(struct lws_fts *t, unsigned char c, - struct lws_fts_entry *parent) + struct lws_fts_entry *parent) { struct lws_fts_entry *e, **pe; @@ -537,7 +538,7 @@ name_entry(struct lws_fts_entry *e1, char *s, int len) int lws_fts_fill(struct lws_fts *t, uint32_t file_index, const char *buf, - size_t len) + size_t len) { unsigned long long tf = lws_time_in_microseconds(); unsigned char c, linetable[256], vlibuf[8]; @@ -900,7 +901,7 @@ seal: e = lws_fts_entry_child_add(t, c, t->parser); if (!e) { - lwsl_err("%s: lws_fts_entry_child_add fail2\n", + lwsl_err("%s: child_add fail2\n", __func__); return 1; } diff --git a/lib/misc/lwsac/cached-file.c b/lib/misc/lwsac/cached-file.c index f5f64d216..cc5de64bd 100644 --- a/lib/misc/lwsac/cached-file.c +++ b/lib/misc/lwsac/cached-file.c @@ -34,8 +34,8 @@ * - the file is already in memory * * it just returns with *cache left alone; this costs very little. You should - * call `lwsac_use_cached_file_start()` and `lwsac_use_cached_file_end()` to lock - * the cache against deletion while you are using it. + * call `lwsac_use_cached_file_start()` and `lwsac_use_cached_file_end()` + * to lock the cache against deletion while you are using it. * * If it's * diff --git a/lib/misc/peer-limits.c b/lib/misc/peer-limits.c index 8ccf3fdb5..cc4c07d63 100644 --- a/lib/misc/peer-limits.c +++ b/lib/misc/peer-limits.c @@ -213,12 +213,15 @@ lws_peer_dump_from_wsi(struct lws *wsi) peer = wsi->peer; #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - lwsl_notice("%s: wsi %p: created %llu: wsi: %d/%d, ah %d/%d\n", __func__, - wsi, (unsigned long long)peer->time_created, peer->count_wsi, peer->total_wsi, + lwsl_notice("%s: wsi %p: created %llu: wsi: %d/%d, ah %d/%d\n", + __func__, + wsi, (unsigned long long)peer->time_created, + peer->count_wsi, peer->total_wsi, peer->http.count_ah, peer->http.total_ah); #else lwsl_notice("%s: wsi %p: created %llu: wsi: %d/%d\n", __func__, - wsi, (unsigned long long)peer->time_created, peer->count_wsi, peer->total_wsi); + wsi, (unsigned long long)peer->time_created, + peer->count_wsi, peer->total_wsi); #endif } @@ -255,12 +258,14 @@ lws_peer_track_wsi_close(struct lws_context *context, struct lws_peer *peer) #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) int -lws_peer_confirm_ah_attach_ok(struct lws_context *context, struct lws_peer *peer) +lws_peer_confirm_ah_attach_ok(struct lws_context *context, + struct lws_peer *peer) { if (!peer) return 0; - if (context->ip_limit_ah && peer->http.count_ah >= context->ip_limit_ah) { + if (context->ip_limit_ah && + peer->http.count_ah >= context->ip_limit_ah) { lwsl_info("peer reached ah limit %d, deferring\n", context->ip_limit_ah); diff --git a/lib/misc/romfs.c b/lib/misc/romfs.c index 3f120bfc8..814999a6e 100644 --- a/lib/misc/romfs.c +++ b/lib/misc/romfs.c @@ -137,7 +137,8 @@ romfs_lookup(romfs_t romfs, romfs_inode_t start, const char *path) cp = (const char *)cache; set_cache((romfs_inode_t)n, RFS_STRING_MAX); - while (*p && *p != '/' && *cp && *p == *cp && (p - path) < RFS_STRING_MAX) { + while (*p && *p != '/' && *cp && *p == *cp && + (p - path) < RFS_STRING_MAX) { p++; n++; cp++; diff --git a/lib/plat/unix/unix-caps.c b/lib/plat/unix/unix-caps.c index 82b0e2bc0..64aea6181 100644 --- a/lib/plat/unix/unix-caps.c +++ b/lib/plat/unix/unix-caps.c @@ -74,7 +74,7 @@ lws_plat_drop_app_privileges(const struct lws_context_creation_info *info) if (info->count_caps) { int n; for (n = 0; n < info->count_caps; n++) - lwsl_notice(" RETAINING CAPABILITY %d\n", + lwsl_notice(" RETAINING CAP %d\n", (int)info->caps[n]); } #endif diff --git a/lib/roles/cgi/cgi-server.c b/lib/roles/cgi/cgi-server.c index a73299bd9..684c74f42 100644 --- a/lib/roles/cgi/cgi-server.c +++ b/lib/roles/cgi/cgi-server.c @@ -108,8 +108,9 @@ lws_create_basic_wsi(struct lws_context *context, int tsi) } LWS_VISIBLE LWS_EXTERN int -lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len, - int timeout_secs, const struct lws_protocol_vhost_options *mp_cgienv) +lws_cgi(struct lws *wsi, const char * const *exec_array, + int script_uri_path_len, int timeout_secs, + const struct lws_protocol_vhost_options *mp_cgienv) { struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; char *env_array[30], cgi_path[500], e[1024], *p = e, @@ -197,7 +198,8 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len sum += lws_snprintf(sum, sumend - sum, "%s ", exec_array[0]); if (0) { - char *pct = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_CONTENT_ENCODING); + char *pct = lws_hdr_simple_ptr(wsi, + WSI_TOKEN_HTTP_CONTENT_ENCODING); if (pct && !strcmp(pct, "gzip")) wsi->http.cgi->gzip_inflate = 1; @@ -343,7 +345,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_ENCODING)) { env_array[n++] = p; p += lws_snprintf(p, end - p, "HTTP_CONTENT_ENCODING=%s", - lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_CONTENT_ENCODING)); + lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_CONTENT_ENCODING)); p++; } if (script_uri_path_len >= 0 && @@ -357,7 +359,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_ACCEPT_ENCODING)) { env_array[n++] = p; p += lws_snprintf(p, end - p, "HTTP_ACCEPT_ENCODING=%s", - lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_ACCEPT_ENCODING)); + lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_ACCEPT_ENCODING)); p++; } if (script_uri_path_len >= 0 && @@ -379,7 +381,8 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)) wsi->http.cgi->post_in_expected = - atoll(lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)); + atoll(lws_hdr_simple_ptr(wsi, + WSI_TOKEN_HTTP_CONTENT_LENGTH)); } @@ -558,7 +561,7 @@ lws_cgi_write_split_stdout_headers(struct lws *wsi) lwsl_debug("LHCS_RESPONSE: issuing response %d\n", wsi->http.cgi->response_code); if (lws_add_http_header_status(wsi, - wsi->http.cgi->response_code, + wsi->http.cgi->response_code, &p, end)) return 1; if (!wsi->http.cgi->explicitly_chunked && @@ -589,8 +592,10 @@ lws_cgi_write_split_stdout_headers(struct lws *wsi) goto post_hpack_recode; p = wsi->http.cgi->headers_start; - wsi->http.cgi->headers_start = wsi->http.cgi->headers_pos; - wsi->http.cgi->headers_dumped = wsi->http.cgi->headers_start; + wsi->http.cgi->headers_start = + wsi->http.cgi->headers_pos; + wsi->http.cgi->headers_dumped = + wsi->http.cgi->headers_start; hrs = HR_NAME; name = buf; @@ -661,16 +666,13 @@ lws_cgi_write_split_stdout_headers(struct lws *wsi) post_hpack_recode: /* finalize cached headers before dumping them */ if (lws_finalize_http_header(wsi, - (unsigned char **)&wsi->http.cgi->headers_pos, - (unsigned char *)wsi->http.cgi->headers_end)) { + (unsigned char **)&wsi->http.cgi->headers_pos, + (unsigned char *)wsi->http.cgi->headers_end)) { lwsl_notice("finalize failed\n"); return -1; } -// lwsl_hexdump_notice(wsi->http.cgi->headers_pos, -// wsi->http.cgi->headers_end - wsi->http.cgi->headers_pos); - wsi->hdr_state = LHCS_DUMP_HEADERS; wsi->reason_bf |= LWS_CB_REASON_AUX_BF__CGI_HEADERS; lws_callback_on_writable(wsi); @@ -679,7 +681,8 @@ post_hpack_recode: case LHCS_DUMP_HEADERS: - n = wsi->http.cgi->headers_pos - wsi->http.cgi->headers_dumped; + n = wsi->http.cgi->headers_pos - + wsi->http.cgi->headers_dumped; if (n > 512) n = 512; @@ -693,19 +696,21 @@ post_hpack_recode: } m = lws_write(wsi, - (unsigned char *)wsi->http.cgi->headers_dumped, + (unsigned char *)wsi->http.cgi->headers_dumped, n, cmd); if (m < 0) { lwsl_debug("%s: write says %d\n", __func__, m); return -1; } wsi->http.cgi->headers_dumped += n; - if (wsi->http.cgi->headers_dumped == wsi->http.cgi->headers_pos) { + if (wsi->http.cgi->headers_dumped == + wsi->http.cgi->headers_pos) { wsi->hdr_state = LHCS_PAYLOAD; lws_free_set_NULL(wsi->http.cgi->headers_buf); lwsl_debug("freed cgi headers\n"); } else { - wsi->reason_bf |= LWS_CB_REASON_AUX_BF__CGI_HEADERS; + wsi->reason_bf |= + LWS_CB_REASON_AUX_BF__CGI_HEADERS; lws_callback_on_writable(wsi); } @@ -716,7 +721,7 @@ post_hpack_recode: } if (!wsi->http.cgi->headers_buf) { - /* if we don't already have a headers buf, cook one up */ + /* if we don't already have a headers buf, cook one */ n = 2048; if (wsi->http2_substream) n = 4096; @@ -728,10 +733,12 @@ post_hpack_recode: } lwsl_debug("allocated cgi hdrs\n"); - wsi->http.cgi->headers_start = wsi->http.cgi->headers_buf + LWS_PRE; + wsi->http.cgi->headers_start = + wsi->http.cgi->headers_buf + LWS_PRE; wsi->http.cgi->headers_pos = wsi->http.cgi->headers_start; wsi->http.cgi->headers_dumped = wsi->http.cgi->headers_pos; - wsi->http.cgi->headers_end = wsi->http.cgi->headers_buf + n - 1; + wsi->http.cgi->headers_end = + wsi->http.cgi->headers_buf + n - 1; for (n = 0; n < SIGNIFICANT_HDR_COUNT; n++) { wsi->http.cgi->match[n] = 0; @@ -751,7 +758,8 @@ post_hpack_recode: else n = 0; - if (wsi->http.cgi->headers_pos >= wsi->http.cgi->headers_end - 4) { + if (wsi->http.cgi->headers_pos >= + wsi->http.cgi->headers_end - 4) { lwsl_notice("CGI hdrs > buf size\n"); return -1; @@ -822,7 +830,7 @@ post_hpack_recode: /* presence of Location: mandates 302 retcode */ if (wsi->hdr_state != LCHS_HEADER && !significant_hdr[SIGNIFICANT_HDR_LOCATION][ - wsi->http.cgi->match[SIGNIFICANT_HDR_LOCATION]]) { + wsi->http.cgi->match[SIGNIFICANT_HDR_LOCATION]]) { lwsl_debug("CGI: Location hdr seen\n"); wsi->http.cgi->response_code = 302; } @@ -899,7 +907,8 @@ agin: memcpy(term + LWS_PRE, (uint8_t *)"0\x0d\x0a\x0d\x0a", 5); - if (lws_write(wsi, term + LWS_PRE, 5, LWS_WRITE_HTTP_FINAL) != 5) + if (lws_write(wsi, term + LWS_PRE, 5, + LWS_WRITE_HTTP_FINAL) != 5) return -1; wsi->http.cgi->cgi_transaction_over = 1; @@ -926,7 +935,8 @@ agin: } */ cmd = LWS_WRITE_HTTP; - if (wsi->http.cgi->content_length_seen + n == wsi->http.cgi->content_length) + if (wsi->http.cgi->content_length_seen + n == + wsi->http.cgi->content_length) cmd = LWS_WRITE_HTTP_FINAL; m = lws_write(wsi, (unsigned char *)start, n, cmd); @@ -988,7 +998,7 @@ lws_cgi_kill(struct lws *wsi) "failed errno %d " "(maybe zombie)\n", __func__, - wsi->http.cgi->pid, errno); + wsi->http.cgi->pid, errno); } } } @@ -1013,8 +1023,8 @@ handled: if (wsi->http.cgi->pid != -1) { n = user_callback_handle_rxflow(wsi->protocol->callback, wsi, LWS_CALLBACK_CGI_TERMINATED, - wsi->user_space, - (void *)&args, wsi->http.cgi->pid); + wsi->user_space, (void *)&args, + wsi->http.cgi->pid); wsi->http.cgi->pid = -1; if (n && !wsi->http.cgi->being_closed) lws_close_free_wsi(wsi, 0, "lws_cgi_kill"); @@ -1056,9 +1066,10 @@ lws_cgi_kill_terminated(struct lws_context_per_thread *pt) continue; if (cgi->content_length) { - lwsl_debug("%s: wsi %p: expected content length seen: %lld\n", - __func__, cgi->wsi, - (unsigned long long)cgi->content_length_seen); + lwsl_debug("%s: wsi %p: expected content " + "length seen: %lld\n", __func__, + cgi->wsi, + (unsigned long long)cgi->content_length_seen); } /* reap it */ @@ -1126,8 +1137,9 @@ lws_cgi_kill_terminated(struct lws_context_per_thread *pt) continue; if (cgi->content_length) - lwsl_debug("%s: wsi %p: expected content length seen: %lld\n", - __func__, cgi->wsi, + lwsl_debug("%s: wsi %p: expected " + "content len seen: %lld\n", __func__, + cgi->wsi, (unsigned long long)cgi->content_length_seen); /* reap it */ diff --git a/lib/roles/h1/ops-h1.c b/lib/roles/h1/ops-h1.c index 4988a289c..2fa0fe16e 100644 --- a/lib/roles/h1/ops-h1.c +++ b/lib/roles/h1/ops-h1.c @@ -90,7 +90,6 @@ lws_read_h1(struct lws *wsi, unsigned char *buf, lws_filepos_t len) * appropriately: */ len -= (buf - last_char); -// lwsl_debug("%s: thinks we have used %ld\n", __func__, (long)len); if (!wsi->hdr_parsing_completed) /* More header content on the way */ @@ -162,7 +161,8 @@ http_postbody: buf += n; if (wsi->http.rx_content_remain) { - lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, + lws_set_timeout(wsi, + PENDING_TIMEOUT_HTTP_CONTENT, wsi->context->timeout_secs); break; } @@ -315,7 +315,8 @@ lws_h1_server_socket_service(struct lws *wsi, struct lws_pollfd *pollfd) lwsi_state(wsi) == LRS_BODY)) { if (!wsi->http.ah && lws_header_table_attach(wsi, 0)) { - lwsl_info("%s: wsi %p: ah not available\n", __func__, wsi); + lwsl_info("%s: wsi %p: ah not available\n", __func__, + wsi); goto try_pollout; } @@ -341,7 +342,8 @@ lws_h1_server_socket_service(struct lws *wsi, struct lws_pollfd *pollfd) * and draining the extensions */ if (wsi->ws && - (wsi->ws->rx_draining_ext || wsi->ws->tx_draining_ext)) + (wsi->ws->rx_draining_ext || + wsi->ws->tx_draining_ext)) goto try_pollout; #endif /* @@ -584,12 +586,14 @@ rops_handle_POLLIN_h1(struct lws_context_per_thread *pt, struct lws *wsi, if (!lwsi_role_client(wsi)) { int n; - lwsl_debug("%s: %p: wsistate 0x%x\n", __func__, wsi, wsi->wsistate); + lwsl_debug("%s: %p: wsistate 0x%x\n", __func__, wsi, + wsi->wsistate); n = lws_h1_server_socket_service(wsi, pollfd); if (n != LWS_HPI_RET_HANDLED) return n; if (lwsi_state(wsi) != LRS_SSL_INIT) - if (lws_server_socket_service_ssl(wsi, LWS_SOCK_INVALID)) + if (lws_server_socket_service_ssl(wsi, + LWS_SOCK_INVALID)) return LWS_HPI_RET_PLEASE_CLOSE_ME; return LWS_HPI_RET_HANDLED; @@ -619,10 +623,9 @@ rops_handle_POLLIN_h1(struct lws_context_per_thread *pt, struct lws *wsi, /* let user code know, he'll usually ask for writeable * callback and drain / re-enable it there */ - if (user_callback_handle_rxflow( - wsi->protocol->callback, - wsi, LWS_CALLBACK_RECEIVE_CLIENT_HTTP, - wsi->user_space, NULL, 0)) { + if (user_callback_handle_rxflow(wsi->protocol->callback, wsi, + LWS_CALLBACK_RECEIVE_CLIENT_HTTP, + wsi->user_space, NULL, 0)) { lwsl_info("RECEIVE_CLIENT_HTTP closed it\n"); return LWS_HPI_RET_PLEASE_CLOSE_ME; } diff --git a/lib/roles/h2/hpack.c b/lib/roles/h2/hpack.c index 93e5e58b5..e127dcd51 100644 --- a/lib/roles/h2/hpack.c +++ b/lib/roles/h2/hpack.c @@ -1,7 +1,7 @@ /* * lib/hpack.c * - * Copyright (C) 2014-2017 Andy Green + * Copyright (C) 2014-2018 Andy Green * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -536,7 +536,8 @@ lws_dynamic_token_insert(struct lws *wsi, int hdr_len, if (lws_hdr_index != LWS_HPACK_IGNORE_ENTRY) { if (dyn->entries[new_index].value) lws_free_set_NULL(dyn->entries[new_index].value); - dyn->entries[new_index].value = lws_malloc(len + 1, "hpack dyn"); + dyn->entries[new_index].value = + lws_malloc(len + 1, "hpack dyn"); if (!dyn->entries[new_index].value) return 1; @@ -644,7 +645,8 @@ lws_hpack_dynamic_size(struct lws *wsi, int size) if (dyn->entries) { for (n = 0; n < min; n++) { - m = (dyn->pos - dyn->used_entries + n) % dyn->num_entries; + m = (dyn->pos - dyn->used_entries + n) % + dyn->num_entries; if (m < 0) m += dyn->num_entries; dte[n] = dyn->entries[m]; @@ -859,7 +861,7 @@ int lws_hpack_interpret(struct lws *wsi, unsigned char c) } /* indexed header */ h2n->hpack_type = HPKT_INDEXED_HDR_6_VALUE_INCR; - lwsl_header(" HPKT_INDEXED_HDR_6_VALUE_INCR (hdr %d)\n", + lwsl_header(" HPKT_INDEXED_HDR_6_VALUE_INCR (hdr %d)\n", c & 0x3f); h2n->hdr_idx = c & 0x3f; if ((c & 0x3f) == 0x3f) { @@ -894,7 +896,7 @@ int lws_hpack_interpret(struct lws *wsi, unsigned char c) } if (c == 0x10) { /* literal name NEVER */ h2n->hpack_type = HPKT_LITERAL_HDR_VALUE_NEVER; - lwsl_header(" HPKT_LITERAL_HDR_VALUE_NEVER\n"); + lwsl_header(" HPKT_LITERAL_HDR_VALUE_NEVER\n"); h2n->hpack = HPKS_HLEN; h2n->value = 0; break; @@ -903,7 +905,7 @@ int lws_hpack_interpret(struct lws *wsi, unsigned char c) /* indexed name */ if (c & 0x10) { h2n->hpack_type = HPKT_INDEXED_HDR_4_VALUE_NEVER; - lwsl_header(" HPKT_LITERAL_HDR_4_VALUE_NEVER\n"); + lwsl_header("HPKT_LITERAL_HDR_4_VALUE_NEVER\n"); } else { h2n->hpack_type = HPKT_INDEXED_HDR_4_VALUE; lwsl_header(" HPKT_INDEXED_HDR_4_VALUE\n"); @@ -1035,7 +1037,8 @@ pre_data: default: if (n != -1 && n != LWS_HPACK_IGNORE_ENTRY && lws_frag_start(wsi, n)) { - lwsl_header("%s: frag start failed\n", __func__); + lwsl_header("%s: frag start failed\n", + __func__); return 1; } break; @@ -1114,7 +1117,8 @@ pre_data: } } if (lws_frag_append(wsi, c1)) { - lwsl_notice("%s: frag app fail\n", + lwsl_notice( + "%s: frag app fail\n", __func__); return 1; } diff --git a/lib/roles/h2/http2.c b/lib/roles/h2/http2.c index d558f1106..48b2b41f7 100644 --- a/lib/roles/h2/http2.c +++ b/lib/roles/h2/http2.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010-2018 Andy Green * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -196,7 +196,8 @@ lws_wsi_server_new(struct lws_vhost *vh, struct lws *parent_wsi, wsi->h2.my_priority = 16; wsi->h2.tx_cr = nwsi->h2.h2n->set.s[H2SET_INITIAL_WINDOW_SIZE]; - wsi->h2.peer_tx_cr_est = nwsi->vhost->h2.set.s[H2SET_INITIAL_WINDOW_SIZE]; + wsi->h2.peer_tx_cr_est = + nwsi->vhost->h2.set.s[H2SET_INITIAL_WINDOW_SIZE]; lwsi_set_state(wsi, LRS_ESTABLISHED); lwsi_set_role(wsi, lwsi_role(parent_wsi)); @@ -259,7 +260,8 @@ lws_wsi_h2_adopt(struct lws *parent_wsi, struct lws *wsi) wsi->h2.my_priority = 16; wsi->h2.tx_cr = nwsi->h2.h2n->set.s[H2SET_INITIAL_WINDOW_SIZE]; - wsi->h2.peer_tx_cr_est = nwsi->vhost->h2.set.s[H2SET_INITIAL_WINDOW_SIZE]; + wsi->h2.peer_tx_cr_est = + nwsi->vhost->h2.set.s[H2SET_INITIAL_WINDOW_SIZE]; if (lws_ensure_user_space(wsi)) goto bail1; @@ -465,7 +467,8 @@ lws_h2_settings(struct lws *wsi, struct http2_settings *settings, w->h2.tx_cr + b - settings->s[a]); w->h2.tx_cr += b - settings->s[a]; if (w->h2.tx_cr > 0 && - w->h2.tx_cr <= (int32_t)(b - settings->s[a])) + w->h2.tx_cr <= + (int32_t)(b - settings->s[a])) lws_callback_on_writable(w); } lws_end_foreach_ll(w, h2.sibling_list); @@ -573,8 +576,8 @@ int lws_h2_frame_write(struct lws *wsi, int type, int flags, *p++ = sid; lwsl_debug("%s: %p (eff %p). typ %d, fl 0x%x, sid=%d, len=%d, " - "txcr=%d, nwsi->txcr=%d\n", __func__, wsi, nwsi, type, flags, - sid, len, wsi->h2.tx_cr, nwsi->h2.tx_cr); + "txcr=%d, nwsi->txcr=%d\n", __func__, wsi, nwsi, type, flags, + sid, len, wsi->h2.tx_cr, nwsi->h2.tx_cr); if (type == LWS_H2_FRAME_TYPE_DATA) { if (wsi->h2.tx_cr < (int)len) @@ -660,7 +663,8 @@ int lws_h2_do_pps_send(struct lws *wsi) case LWS_H2_PPS_ACK_SETTINGS: /* send ack ... always empty */ n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_SETTINGS, 1, - LWS_H2_STREAM_ID_MASTER, 0, &set[LWS_PRE]); + LWS_H2_STREAM_ID_MASTER, 0, + &set[LWS_PRE]); if (n) { lwsl_err("ack tells %d\n", n); goto bail; @@ -754,7 +758,9 @@ int lws_h2_do_pps_send(struct lws *wsi) } cwsi = lws_h2_wsi_from_id(wsi, pps->u.rs.sid); if (cwsi) { - lwsl_debug("%s: closing cwsi %p %s %s (wsi %p)\n", __func__, cwsi, cwsi->role_ops->name, cwsi->protocol->name, wsi); + lwsl_debug("%s: closing cwsi %p %s %s (wsi %p)\n", + __func__, cwsi, cwsi->role_ops->name, + cwsi->protocol->name, wsi); lws_close_free_wsi(cwsi, 0, "reset stream"); } break; @@ -822,7 +828,7 @@ lws_h2_parse_frame_header(struct lws *wsi) if (h2n->sid) h2n->swsi = lws_h2_wsi_from_id(wsi, h2n->sid); - lwsl_debug("%p (%p): fr hdr: typ 0x%x, flags 0x%x, sid 0x%x, len 0x%x\n", + lwsl_debug("%p (%p): fr hdr: typ 0x%x, fla 0x%x, sid 0x%x, len 0x%x\n", wsi, h2n->swsi, h2n->type, h2n->flags, h2n->sid, h2n->length); @@ -856,7 +862,8 @@ lws_h2_parse_frame_header(struct lws *wsi) #endif ) { lwsl_notice("ignoring straggling data\n"); - h2n->type = LWS_H2_FRAME_TYPE_COUNT; /* ie, IGNORE */ + /* ie, IGNORE */ + h2n->type = LWS_H2_FRAME_TYPE_COUNT; } else { lws_h2_goaway(wsi, H2_ERR_STREAM_CLOSED, "Data for nonexistent sid"); @@ -868,7 +875,7 @@ lws_h2_parse_frame_header(struct lws *wsi) h2n->type != LWS_H2_FRAME_TYPE_HEADERS && h2n->type != LWS_H2_FRAME_TYPE_PRIORITY) { /* if not credible, reject it */ - lwsl_info("%s: wsi %p, No child for sid %d, rx cmd %d\n", + lwsl_info("%s: wsi %p, No child for sid %d, rxcmd %d\n", __func__, h2n->swsi, h2n->sid, h2n->type); lws_h2_goaway(wsi, H2_ERR_STREAM_CLOSED, "Data for nonexistent sid"); @@ -1045,9 +1052,11 @@ lws_h2_parse_frame_header(struct lws *wsi) return 1; } - if (h2n->swsi && !h2n->swsi->h2.END_STREAM && h2n->swsi->h2.END_HEADERS && - !(h2n->flags & LWS_H2_FLAG_END_STREAM)) { - lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, "extra HEADERS together"); + if (h2n->swsi && !h2n->swsi->h2.END_STREAM && + h2n->swsi->h2.END_HEADERS && + !(h2n->flags & LWS_H2_FLAG_END_STREAM)) { + lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, + "extra HEADERS together"); return 1; } @@ -1055,7 +1064,9 @@ lws_h2_parse_frame_header(struct lws *wsi) if (wsi->client_h2_alpn) { if (h2n->sid) { h2n->swsi = lws_h2_wsi_from_id(wsi, h2n->sid); - lwsl_info("HEADERS: nwsi %p: sid %d mapped to wsi %p\n", wsi, h2n->sid, h2n->swsi); + lwsl_info("HEADERS: nwsi %p: sid %d mapped " + "to wsi %p\n", wsi, h2n->sid, + h2n->swsi); if (!h2n->swsi) break; } @@ -1076,7 +1087,8 @@ lws_h2_parse_frame_header(struct lws *wsi) h2n->swsi = lws_wsi_server_new(wsi->vhost, wsi, h2n->sid); if (!h2n->swsi) { - lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, "OOM"); + lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, + "OOM"); return 1; } @@ -1086,7 +1098,8 @@ lws_h2_parse_frame_header(struct lws *wsi) goto cleanup_wsi; pps->u.update_window.sid = h2n->sid; pps->u.update_window.credit = 4 * 65536; - h2n->swsi->h2.peer_tx_cr_est += pps->u.update_window.credit; + h2n->swsi->h2.peer_tx_cr_est += + pps->u.update_window.credit; lws_pps_schedule(wsi, pps); pps = lws_h2_new_pps(LWS_H2_PPS_UPDATE_WINDOW); @@ -1141,7 +1154,8 @@ update_end_headers: /* no END_HEADERS means CONTINUATION must come */ h2n->swsi->h2.END_HEADERS = !!(h2n->flags & LWS_H2_FLAG_END_HEADERS); - lwsl_info("%p: END_HEADERS %d\n", h2n->swsi, h2n->swsi->h2.END_HEADERS); + lwsl_info("%p: END_HEADERS %d\n", h2n->swsi, + h2n->swsi->h2.END_HEADERS); if (h2n->swsi->h2.END_HEADERS) h2n->cont_exp = 0; lwsl_debug("END_HEADERS %d\n", h2n->swsi->h2.END_HEADERS); @@ -1281,15 +1295,16 @@ lws_h2_parse_end_of_frame(struct lws *wsi) /* we have a transaction queue that wants to pipeline */ lws_vhost_lock(wsi->vhost); lws_start_foreach_dll_safe(struct lws_dll_lws *, d, d1, - wsi->dll_client_transaction_queue_head.next) { + wsi->dll_client_transaction_queue_head.next) { struct lws *w = lws_container_of(d, struct lws, - dll_client_transaction_queue); + dll_client_transaction_queue); if (lwsi_state(w) == LRS_H1C_ISSUE_HANDSHAKE2) { - lwsl_info("%s: client pipeq %p to be h2\n", + lwsl_info("%s: cli pipeq %p to be h2\n", __func__, w); - /* remove ourselves from the client queue */ - lws_dll_lws_remove(&w->dll_client_transaction_queue); + /* remove ourselves from client queue */ + lws_dll_lws_remove( + &w->dll_client_transaction_queue); /* attach ourselves as an h2 stream */ lws_wsi_h2_adopt(wsi, w); @@ -1347,8 +1362,9 @@ lws_h2_parse_end_of_frame(struct lws *wsi) #if !defined(LWS_NO_CLIENT) if (h2n->swsi->client_h2_substream) { if (lws_client_interpret_server_handshake(h2n->swsi)) { - lws_h2_rst_stream(h2n->swsi, H2_ERR_STREAM_CLOSED, - "protocol CLI_EST closed it"); + lws_h2_rst_stream(h2n->swsi, + H2_ERR_STREAM_CLOSED, + "protocol CLI_EST closed it"); break; } } @@ -1361,7 +1377,7 @@ lws_h2_parse_end_of_frame(struct lws *wsi) h2n->swsi->http.rx_content_remain = h2n->swsi->http.rx_content_length; lwsl_info("setting rx_content_length %lld\n", - (long long)h2n->swsi->http.rx_content_length); + (long long)h2n->swsi->http.rx_content_length); } { @@ -1382,12 +1398,15 @@ lws_h2_parse_end_of_frame(struct lws *wsi) continue; } - if (lws_hdr_copy(h2n->swsi, buf, sizeof buf, n) < 0) { - lwsl_info(" %s !oversize!\n", (char *)c); + if (lws_hdr_copy(h2n->swsi, buf, sizeof buf, + n) < 0) { + lwsl_info(" %s !oversize!\n", + (char *)c); } else { buf[sizeof(buf) - 1] = '\0'; - lwsl_info(" %s = %s\n", (char *)c, buf); + lwsl_info(" %s = %s\n", + (char *)c, buf); } n++; } while (c); @@ -1450,9 +1469,11 @@ lws_h2_parse_end_of_frame(struct lws *wsi) p = lws_hdr_simple_ptr(h2n->swsi, WSI_TOKEN_HTTP_COLON_METHOD); if (!strcmp(p, "POST")) h2n->swsi->http.ah->frag_index[WSI_TOKEN_POST_URI] = - h2n->swsi->http.ah->frag_index[WSI_TOKEN_HTTP_COLON_PATH]; + h2n->swsi->http.ah->frag_index[ + WSI_TOKEN_HTTP_COLON_PATH]; - lwsl_debug("%s: setting DEF_ACT from 0x%x\n", __func__, h2n->swsi->wsistate); + lwsl_debug("%s: setting DEF_ACT from 0x%x\n", __func__, + h2n->swsi->wsistate); lwsi_set_state(h2n->swsi, LRS_DEFERRING_ACTION); lws_callback_on_writable(h2n->swsi); break; @@ -1461,7 +1482,8 @@ lws_h2_parse_end_of_frame(struct lws *wsi) if (!h2n->swsi) break; - if (lws_hdr_total_length(h2n->swsi, WSI_TOKEN_HTTP_CONTENT_LENGTH) && + if (lws_hdr_total_length(h2n->swsi, + WSI_TOKEN_HTTP_CONTENT_LENGTH) && h2n->swsi->h2.END_STREAM && h2n->swsi->http.rx_content_length && h2n->swsi->http.rx_content_remain) { @@ -1472,7 +1494,8 @@ lws_h2_parse_end_of_frame(struct lws *wsi) if (h2n->swsi->h2.END_STREAM && h2n->swsi->h2.h2_state == LWS_H2_STATE_OPEN) - lws_h2_state(h2n->swsi, LWS_H2_STATE_HALF_CLOSED_REMOTE); + lws_h2_state(h2n->swsi, + LWS_H2_STATE_HALF_CLOSED_REMOTE); if (h2n->swsi->h2.END_STREAM && h2n->swsi->h2.h2_state == LWS_H2_STATE_HALF_CLOSED_LOCAL) @@ -1486,10 +1509,12 @@ lws_h2_parse_end_of_frame(struct lws *wsi) if (h2n->swsi->client_h2_substream && h2n->flags & LWS_H2_FLAG_END_STREAM) { - lwsl_info("%s: %p: DATA: end stream\n", __func__, h2n->swsi); + lwsl_info("%s: %p: DATA: end stream\n", + __func__, h2n->swsi); if (h2n->swsi->h2.h2_state == LWS_H2_STATE_OPEN) { - lws_h2_state(h2n->swsi, LWS_H2_STATE_HALF_CLOSED_REMOTE); + lws_h2_state(h2n->swsi, + LWS_H2_STATE_HALF_CLOSED_REMOTE); // lws_h2_rst_stream(h2n->swsi, H2_ERR_NO_ERROR, // "client done"); @@ -1591,7 +1616,7 @@ lws_h2_parse_end_of_frame(struct lws *wsi) case LWS_H2_FRAME_TYPE_RST_STREAM: lwsl_info("LWS_H2_FRAME_TYPE_RST_STREAM: sid %d: reason 0x%x\n", - h2n->sid, h2n->hpack_e_dep); + h2n->sid, h2n->hpack_e_dep); break; case LWS_H2_FRAME_TYPE_COUNT: /* IGNORING FRAME */ @@ -1670,7 +1695,8 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen, */ h2n->count++; - if (h2n->flags & LWS_H2_FLAG_PADDED && !h2n->pad_length) { + if (h2n->flags & LWS_H2_FLAG_PADDED && + !h2n->pad_length) { /* * Get the padding count... actual padding is * at the end of the frame. @@ -1680,7 +1706,8 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen, h2n->preamble++; if (h2n->padding > h2n->length - 1) - lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, + lws_h2_goaway(wsi, + H2_ERR_PROTOCOL_ERROR, "execssive padding"); break; /* we consumed this */ } @@ -1701,9 +1728,11 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen, h2n->dep, h2n->weight_temp); break; /* we consumed this */ } - if (h2n->padding && h2n->count > (h2n->length - h2n->padding)) { + if (h2n->padding && h2n->count > + (h2n->length - h2n->padding)) { if (c) { - lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, + lws_h2_goaway(wsi, + H2_ERR_PROTOCOL_ERROR, "nonzero padding"); break; } @@ -1719,7 +1748,8 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen, h2n->one_setting[n] = c; if (n != LWS_H2_SETTINGS_LEN - 1) break; - lws_h2_settings(wsi, &h2n->set, h2n->one_setting, + lws_h2_settings(wsi, &h2n->set, + h2n->one_setting, LWS_H2_SETTINGS_LEN); break; @@ -1728,7 +1758,8 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen, if (!h2n->swsi) break; if (lws_hpack_interpret(h2n->swsi, c)) { - lwsl_info("%s: hpack failed\n", __func__); + lwsl_info("%s: hpack failed\n", + __func__); goto fail; } break; @@ -1755,41 +1786,54 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen, default: if (h2n->inside - 9 < sizeof(h2n->goaway_str) - 1) - h2n->goaway_str[h2n->inside - 9] = c; - h2n->goaway_str[sizeof(h2n->goaway_str) - 1] = '\0'; + h2n->goaway_str[ + h2n->inside - 9] = c; + h2n->goaway_str[ + sizeof(h2n->goaway_str) - 1] = '\0'; break; } break; case LWS_H2_FRAME_TYPE_DATA: - lwsl_info("%s: LWS_H2_FRAME_TYPE_DATA\n", __func__); + lwsl_info("%s: LWS_H2_FRAME_TYPE_DATA\n", + __func__); - /* let the network wsi live a bit longer if subs are active... - * our frame may take a long time to chew through */ + /* + * let the network wsi live a bit longer if + * subs are active... our frame may take a long + * time to chew through + */ if (!wsi->ws_over_h2_count) - lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE, 31); + lws_set_timeout(wsi, + PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE, + 31); if (!h2n->swsi) break; - if (lws_buflist_next_segment_len(&h2n->swsi->buflist, NULL)) - lwsl_info("%s: substream has pending\n", __func__); + if (lws_buflist_next_segment_len( + &h2n->swsi->buflist, NULL)) + lwsl_info("%s: substream has pending\n", + __func__); if (lwsi_role_http(h2n->swsi) && lwsi_state(h2n->swsi) == LRS_ESTABLISHED) { lwsi_set_state(h2n->swsi, LRS_BODY); - lwsl_info("%s: setting swsi %p to LRS_BODY\n", + lwsl_info("%s: swsi %p to LRS_BODY\n", __func__, h2n->swsi); } if (lws_hdr_total_length(h2n->swsi, - WSI_TOKEN_HTTP_CONTENT_LENGTH) && + WSI_TOKEN_HTTP_CONTENT_LENGTH) && h2n->swsi->http.rx_content_length && - h2n->swsi->http.rx_content_remain < inlen + 1 && /* last */ - h2n->inside < h2n->length) { /* unread data in frame */ - lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, - "More rx than content_length told"); + h2n->swsi->http.rx_content_remain < + inlen + 1 && /* last */ + h2n->inside < h2n->length) { + /* unread data in frame */ + lws_h2_goaway(wsi, + H2_ERR_PROTOCOL_ERROR, + "More rx than content_length told"); break; } @@ -1807,9 +1851,11 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen, if (h2n->swsi->client_h2_substream) { m = user_callback_handle_rxflow( - h2n->swsi->protocol->callback, - h2n->swsi, LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ, - h2n->swsi->user_space, in - 1, n); + h2n->swsi->protocol->callback, + h2n->swsi, + LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ, + h2n->swsi->user_space, + in - 1, n); in += n - 1; h2n->inside += n; @@ -1817,7 +1863,8 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen, inlen -= n - 1; if (m) { - lwsl_info("RECEIVE_CLIENT_HTTP closed it\n"); + lwsl_info("RECEIVE_CLIENT_HTTP " + "closed it\n"); goto close_swsi_and_return; } @@ -2117,7 +2164,7 @@ lws_h2_client_handshake(struct lws *wsi) WSI_TOKEN_HTTP_COLON_AUTHORITY, (unsigned char *)lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN), - lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_ORIGIN), + lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_ORIGIN), &p, end)) goto fail_length; @@ -2145,7 +2192,7 @@ lws_h2_client_handshake(struct lws *wsi) return 0; fail_length: - lwsl_err("Client hdrs too long: extend context info.pt_serv_buf_size\n"); + lwsl_err("Client hdrs too long: incr context info.pt_serv_buf_size\n"); return -1; } @@ -2264,7 +2311,7 @@ lws_read_h2(struct lws *wsi, unsigned char *buf, lws_filepos_t len) m = lws_h2_parser(wsi, buf, len, &body_chunk_len); if (m && m != 2) { - lwsl_debug("%s: http2_parser bailed: %d\n", __func__, m); + lwsl_debug("%s: http2_parser bail: %d\n", __func__, m); lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "lws_read_h2 bail"); diff --git a/lib/roles/h2/ops-h2.c b/lib/roles/h2/ops-h2.c index ea3f69d45..9f23f9e35 100644 --- a/lib/roles/h2/ops-h2.c +++ b/lib/roles/h2/ops-h2.c @@ -585,8 +585,9 @@ rops_close_kill_connection_h2(struct lws *wsi, enum lws_close_status reason) wsi->http.proxy_clientside = 0; - if (user_callback_handle_rxflow(wsi_eff->protocol->callback, wsi_eff, - LWS_CALLBACK_COMPLETED_CLIENT_HTTP, + if (user_callback_handle_rxflow(wsi_eff->protocol->callback, + wsi_eff, + LWS_CALLBACK_COMPLETED_CLIENT_HTTP, wsi_eff->user_space, NULL, 0)) wsi->http.proxy_clientside = 0; } @@ -1037,7 +1038,8 @@ rops_perform_user_POLLOUT_h2(struct lws *wsi) /* Notify peer that we decided to close */ - if (lwsi_role_ws(w) && lwsi_state(w) == LRS_WAITING_TO_SEND_CLOSE) { + if (lwsi_role_ws(w) && + lwsi_state(w) == LRS_WAITING_TO_SEND_CLOSE) { lwsl_debug("sending close packet\n"); w->waiting_to_send_close_frame = 0; n = lws_write(w, &w->ws->ping_payload_buf[LWS_PRE], @@ -1074,7 +1076,7 @@ rops_perform_user_POLLOUT_h2(struct lws *wsi) w->ws->ping_pending_flag = 0; if (w->ws->payload_is_close) { /* oh... a close frame... then we are done */ - lwsl_debug("Acknowledged peer's close packet\n"); + lwsl_debug("Ack'd peer's close packet\n"); w->ws->payload_is_close = 0; lwsi_set_state(w, LRS_RETURNED_CLOSE); lws_close_free_wsi(w, LWS_CLOSE_STATUS_NOSTATUS, @@ -1086,7 +1088,7 @@ rops_perform_user_POLLOUT_h2(struct lws *wsi) lws_callback_on_writable(w); (w)->h2.requested_POLLOUT = 1; - /* otherwise for PING, leave POLLOUT active either way */ + /* otherwise for PING, leave POLLOUT active both ways */ goto next_child; } #endif @@ -1163,7 +1165,7 @@ rops_alpn_negotiated_h2(struct lws *wsi, const char *alpn) /* HTTP2 union */ lws_hpack_dynamic_size(wsi, - wsi->h2.h2n->set.s[H2SET_HEADER_TABLE_SIZE]); + wsi->h2.h2n->set.s[H2SET_HEADER_TABLE_SIZE]); wsi->h2.tx_cr = 65535; lwsl_info("%s: wsi %p: configured for h2\n", __func__, wsi); diff --git a/lib/roles/h2/private.h b/lib/roles/h2/private.h index 664c509dc..f64968732 100644 --- a/lib/roles/h2/private.h +++ b/lib/roles/h2/private.h @@ -350,18 +350,19 @@ struct lws * lws_h2_get_nth_child(struct lws *wsi, int n); LWS_EXTERN void lws_h2_init(struct lws *wsi); LWS_EXTERN int lws_h2_settings(struct lws *nwsi, struct http2_settings *settings, - unsigned char *buf, int len); + unsigned char *buf, int len); LWS_EXTERN int lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen, lws_filepos_t *inused); -LWS_EXTERN int lws_h2_do_pps_send(struct lws *wsi); -LWS_EXTERN int lws_h2_frame_write(struct lws *wsi, int type, int flags, - unsigned int sid, unsigned int len, - unsigned char *buf); +LWS_EXTERN int +lws_h2_do_pps_send(struct lws *wsi); +LWS_EXTERN int +lws_h2_frame_write(struct lws *wsi, int type, int flags, unsigned int sid, + unsigned int len, unsigned char *buf); LWS_EXTERN struct lws * lws_h2_wsi_from_id(struct lws *wsi, unsigned int sid); -LWS_EXTERN int lws_hpack_interpret(struct lws *wsi, - unsigned char c); +LWS_EXTERN int +lws_hpack_interpret(struct lws *wsi, unsigned char c); LWS_EXTERN int lws_add_http2_header_by_name(struct lws *wsi, const unsigned char *name, @@ -369,9 +370,9 @@ lws_add_http2_header_by_name(struct lws *wsi, unsigned char **p, unsigned char *end); LWS_EXTERN int lws_add_http2_header_by_token(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); LWS_EXTERN int lws_add_http2_header_status(struct lws *wsi, unsigned int code, unsigned char **p, diff --git a/lib/roles/http/client/client-handshake.c b/lib/roles/http/client/client-handshake.c index 973901b3f..6b4e98f34 100644 --- a/lib/roles/http/client/client-handshake.c +++ b/lib/roles/http/client/client-handshake.c @@ -131,7 +131,7 @@ lws_client_connect_2(struct lws *wsi) } #endif - lwsl_info("applying %p to txn queue on %p (wsistate 0x%x)\n", + lwsl_info("applying %p to txn queue on %p state 0x%x\n", wsi, w, w->wsistate); /* * ...let's add ourselves to his transaction queue... @@ -337,7 +337,7 @@ create_new_conn: } else if (n == EAI_SYSTEM) { struct hostent *host; - lwsl_info("getaddrinfo (ipv4) failed, trying gethostbyname\n"); + lwsl_info("ipv4 getaddrinfo err, try gethostbyname\n"); host = gethostbyname(ads); if (host) { p = host->h_addr; @@ -451,7 +451,8 @@ ads_known: iface = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_IFACE); if (iface) { - n = lws_socket_bind(wsi->vhost, wsi->desc.sockfd, 0, iface); + n = lws_socket_bind(wsi->vhost, wsi->desc.sockfd, 0, + iface); if (n < 0) { cce = "unable to bind socket"; goto failed; @@ -563,7 +564,8 @@ ads_known: goto failed; } - lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SOCKS_GREETING_REPLY, + lws_set_timeout(wsi, + PENDING_TIMEOUT_AWAITING_SOCKS_GREETING_REPLY, AWAITING_TIMEOUT); lwsi_set_state(wsi, LRS_WAITING_SOCKS_GREETING_REPLY); @@ -594,7 +596,7 @@ send_hs: * wait in the queue until it's possible to send them. */ lws_callback_on_writable(wsi_piggyback); - lwsl_info("%s: wsi %p: waiting to send headers (parent state %x)\n", + lwsl_info("%s: wsi %p: waiting to send hdrs (par state 0x%x)\n", __func__, wsi, lwsi_state(wsi_piggyback)); } else { lwsl_info("%s: wsi %p: client creating own connection\n", @@ -674,7 +676,8 @@ failed1: #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) /** - * lws_client_reset() - retarget a connected wsi to start over with a new connection (ie, redirect) + * lws_client_reset() - retarget a connected wsi to start over with a new + * connection (ie, redirect) * this only works if still in HTTP, ie, not upgraded yet * wsi: connection to reset * address: network address of the new server @@ -1020,8 +1023,9 @@ void socks_generate_msg(struct lws *wsi, enum socks_msg_type type, /* length of the password */ pt->serv_buf[len++] = passwd_len; /* password */ - lws_strncpy((char *)&pt->serv_buf[len], wsi->vhost->socks_password, - context->pt_serv_buf_size - len + 1); + lws_strncpy((char *)&pt->serv_buf[len], + wsi->vhost->socks_password, + context->pt_serv_buf_size - len + 1); len += passwd_len; break; diff --git a/lib/roles/http/client/client.c b/lib/roles/http/client/client.c index ecf44c8df..1d6f13dcf 100644 --- a/lib/roles/http/client/client.c +++ b/lib/roles/http/client/client.c @@ -1,7 +1,7 @@ /* * libwebsockets - lib/client/client.c * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010-2018 Andy Green * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -48,7 +48,7 @@ lws_client_wsi_effective(struct lws *wsi) } lws_end_foreach_dll_safe(d, d1); return lws_container_of(tail, struct lws, - dll_client_transaction_queue); + dll_client_transaction_queue); } /* @@ -66,7 +66,7 @@ _lws_client_wsi_master(struct lws *wsi) d = wsi->dll_client_transaction_queue.prev; while (d) { wsi_eff = lws_container_of(d, struct lws, - dll_client_transaction_queue_head); + dll_client_transaction_queue_head); d = d->prev; } @@ -111,11 +111,12 @@ lws_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd, */ lws_vhost_lock(wsi->vhost); lws_start_foreach_dll_safe(struct lws_dll_lws *, d, d1, - wsi->dll_client_transaction_queue_head.next) { + wsi->dll_client_transaction_queue_head.next) { struct lws *w = lws_container_of(d, struct lws, dll_client_transaction_queue); - lwsl_debug("%s: %p states 0x%x\n", __func__, w, w->wsistate); + lwsl_debug("%s: %p states 0x%x\n", __func__, w, + w->wsistate); if (lwsi_state(w) == LRS_H1C_ISSUE_HANDSHAKE2) wfound = w; } lws_end_foreach_dll_safe(d, d1); @@ -208,7 +209,8 @@ lws_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd, case LRS_WAITING_SOCKS_AUTH_REPLY: if (pt->serv_buf[0] != SOCKS_SUBNEGOTIATION_VERSION_1 || - pt->serv_buf[1] != SOCKS_SUBNEGOTIATION_STATUS_SUCCESS) + pt->serv_buf[1] != + SOCKS_SUBNEGOTIATION_STATUS_SUCCESS) goto socks_reply_fail; lwsl_client("SOCKS password OK, sending connect\n"); @@ -243,8 +245,8 @@ socks_reply_fail: /* free stash since we are done with it */ lws_client_stash_destroy(wsi); if (lws_hdr_simple_create(wsi, - _WSI_TOKEN_CLIENT_PEER_ADDRESS, - wsi->vhost->socks_proxy_address)) + _WSI_TOKEN_CLIENT_PEER_ADDRESS, + wsi->vhost->socks_proxy_address)) goto bail3; wsi->c_port = wsi->vhost->socks_proxy_port; @@ -379,7 +381,8 @@ start_ws_handshake: return 0; lwsl_err("Failed to generate handshake for client\n"); - lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "chs"); + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, + "chs"); return 0; } @@ -387,8 +390,9 @@ start_ws_handshake: lws_latency_pre(context, wsi); w = _lws_client_wsi_master(wsi); - lwsl_info("%s: HANDSHAKE2: %p: sending headers on %p (wsistate 0x%x 0x%x)\n", - __func__, wsi, w, wsi->wsistate, w->wsistate); + lwsl_info("%s: HANDSHAKE2: %p: sending headers on %p " + "(wsistate 0x%x 0x%x)\n", __func__, wsi, w, + wsi->wsistate, w->wsistate); n = lws_ssl_capable_write(w, (unsigned char *)sb, (int)(p - sb)); lws_latency(context, wsi, "send lws_issue_raw", n, @@ -396,7 +400,8 @@ start_ws_handshake: switch (n) { case LWS_SSL_CAPABLE_ERROR: lwsl_debug("ERROR writing to client socket\n"); - lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "cws"); + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, + "cws"); return 0; case LWS_SSL_CAPABLE_MORE_SERVICE: lws_callback_on_writable(wsi); @@ -421,7 +426,7 @@ start_ws_handshake: #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) w->http.ah->parser_state = WSI_TOKEN_NAME_PART; w->http.ah->lextable_pos = 0; - /* If we're (re)starting on headers, need other implied init */ + /* If we're (re)starting on hdr, need other implied init */ wsi->http.ah->ues = URIES_IDLE; #endif } @@ -629,7 +634,8 @@ lws_http_transaction_completed_client(struct lws *wsi) /* If we're (re)starting on headers, need other implied init */ wsi->http.ah->ues = URIES_IDLE; - lwsl_info("%s: %p: new queued transaction as %p\n", __func__, wsi, wsi_eff); + lwsl_info("%s: %p: new queued transaction as %p\n", __func__, wsi, + wsi_eff); lws_callback_on_writable(wsi); return 0; @@ -688,7 +694,8 @@ lws_client_interpret_server_handshake(struct lws *wsi) */ #if defined(LWS_ROLE_H2) if (wsi->client_h2_alpn || wsi->client_h2_substream) { - lwsl_debug("%s: %p: transitioning to h2 client\n", __func__, wsi); + lwsl_debug("%s: %p: transitioning to h2 client\n", + __func__, wsi); lws_role_transition(wsi, LWSIFR_CLIENT, LRS_ESTABLISHED, &role_ops_h2); } else @@ -696,7 +703,8 @@ lws_client_interpret_server_handshake(struct lws *wsi) { #if defined(LWS_ROLE_H1) { - lwsl_debug("%s: %p: transitioning to h1 client\n", __func__, wsi); + lwsl_debug("%s: %p: transitioning to h1 client\n", + __func__, wsi); lws_role_transition(wsi, LWSIFR_CLIENT, LRS_ESTABLISHED, &role_ops_h1); } @@ -829,7 +837,8 @@ lws_client_interpret_server_handshake(struct lws *wsi) /* if h1 KA is allowed, enable the queued pipeline guys */ - if (!wsi->client_h2_alpn && !wsi->client_h2_substream && w == wsi) { /* ie, coming to this for the first time */ + if (!wsi->client_h2_alpn && !wsi->client_h2_substream && + w == wsi) { /* ie, coming to this for the first time */ if (wsi->http.conn_type == HTTP_CONNECTION_KEEP_ALIVE) wsi->keepalive_active = 1; else { @@ -850,13 +859,16 @@ lws_client_interpret_server_handshake(struct lws *wsi) wsi->keepalive_rejected = 1; lws_vhost_lock(wsi->vhost); - lws_start_foreach_dll_safe(struct lws_dll_lws *, d, d1, - wsi->dll_client_transaction_queue_head.next) { - struct lws *ww = lws_container_of(d, struct lws, - dll_client_transaction_queue); + lws_start_foreach_dll_safe(struct lws_dll_lws *, + d, d1, + wsi->dll_client_transaction_queue_head.next) { + struct lws *ww = lws_container_of(d, + struct lws, + dll_client_transaction_queue); /* remove him from our queue */ - lws_dll_lws_remove(&ww->dll_client_transaction_queue); + lws_dll_lws_remove( + &ww->dll_client_transaction_queue); /* give up on pipelining */ ww->client_pipeline = 0; @@ -1096,9 +1108,9 @@ lws_generate_client_handshake(struct lws *wsi, char *pkt) /* give userland a chance to append, eg, cookies */ if (wsi->protocol->callback(wsi, - LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER, - wsi->user_space, &p, - (pkt + wsi->context->pt_serv_buf_size) - p - 12)) + LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER, + wsi->user_space, &p, + (pkt + wsi->context->pt_serv_buf_size) - p - 12)) return NULL; p += sprintf(p, "\x0d\x0a"); diff --git a/lib/roles/http/compression/brotli/brotli.c b/lib/roles/http/compression/brotli/brotli.c index 14ad96104..0c977deb8 100644 --- a/lib/roles/http/compression/brotli/brotli.c +++ b/lib/roles/http/compression/brotli/brotli.c @@ -33,7 +33,7 @@ lcs_init_compression_brotli(lws_comp_ctx_t *ctx, int decomp) BrotliEncoderSetParameter(ctx->u.br_en, BROTLI_PARAM_MODE, BROTLI_MODE_TEXT); BrotliEncoderSetParameter(ctx->u.br_en, - BROTLI_PARAM_QUALITY, BROTLI_MIN_QUALITY); + BROTLI_PARAM_QUALITY, BROTLI_MIN_QUALITY); } } else @@ -77,7 +77,7 @@ lcs_process_brotli(lws_comp_ctx_t *ctx, const void *in, size_t *ilen_iused, return -1; } - ctx->may_have_more = !a_out;//!BrotliEncoderIsFinished(ctx->u.br_en); + ctx->may_have_more = !a_out; } else { n = BrotliDecoderDecompressStream(ctx->u.br_de, &a_in, &n_in, diff --git a/lib/roles/http/compression/deflate/deflate.c b/lib/roles/http/compression/deflate/deflate.c index 2f3fab5e6..c092ec5fa 100644 --- a/lib/roles/http/compression/deflate/deflate.c +++ b/lib/roles/http/compression/deflate/deflate.c @@ -54,7 +54,7 @@ lcs_init_compression_deflate(lws_comp_ctx_t *ctx, int decomp) static int lcs_process_deflate(lws_comp_ctx_t *ctx, const void *in, size_t *ilen_iused, - void *out, size_t *olen_oused) + void *out, size_t *olen_oused) { size_t olen_oused_in = *olen_oused; int n; diff --git a/lib/roles/http/compression/private.h b/lib/roles/http/compression/private.h index dafa77c77..26aeaf348 100644 --- a/lib/roles/http/compression/private.h +++ b/lib/roles/http/compression/private.h @@ -60,7 +60,7 @@ struct lws_compression_support { int (*init_compression)(lws_comp_ctx_t *ctx, int decomp); /** pass data into the context to be processed */ int (*process)(lws_comp_ctx_t *ctx, const void *in, size_t *ilen_iused, - void *out, size_t *olen_oused); + void *out, size_t *olen_oused); /** destroy the de/compression context */ void (*destroy)(lws_comp_ctx_t *ctx); }; diff --git a/lib/roles/http/header.c b/lib/roles/http/header.c index ae10f7dea..448c5a8b5 100644 --- a/lib/roles/http/header.c +++ b/lib/roles/http/header.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010-2018 Andy Green * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -116,9 +116,10 @@ lws_add_http_header_by_token(struct lws *wsi, enum lws_token_indexes token, return lws_add_http_header_by_name(wsi, name, value, length, p, end); } -int lws_add_http_header_content_length(struct lws *wsi, - lws_filepos_t content_length, - unsigned char **p, unsigned char *end) +int +lws_add_http_header_content_length(struct lws *wsi, + lws_filepos_t content_length, + unsigned char **p, unsigned char *end) { char b[24]; int n; @@ -200,7 +201,8 @@ lws_add_http_common_headers(struct lws *wsi, unsigned int code, } #endif if (!wsi->http2_substream) { - if (lws_add_http_header_by_token(wsi, WSI_TOKEN_CONNECTION, + if (lws_add_http_header_by_token(wsi, + WSI_TOKEN_CONNECTION, (unsigned char *)ka[t], (int)strlen(ka[t]), p, end)) return 1; @@ -364,7 +366,8 @@ lws_add_http_header_status(struct lws *wsi, unsigned int _code, } LWS_VISIBLE int -lws_return_http_status(struct lws *wsi, unsigned int code, const char *html_body) +lws_return_http_status(struct lws *wsi, unsigned int code, + const char *html_body) { struct lws_context *context = lws_get_context(wsi); struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; diff --git a/lib/roles/http/server/access-log.c b/lib/roles/http/server/access-log.c index be79d080a..41d9c71d9 100644 --- a/lib/roles/http/server/access-log.c +++ b/lib/roles/http/server/access-log.c @@ -90,14 +90,15 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int uri_len, int met uri[m] = '\0'; lws_snprintf(wsi->http.access_log.header_log, l, - "%s - - [%s] \"%s %s %s\"", - pa, da, me, uri, hver[wsi->http.request_version]); + "%s - - [%s] \"%s %s %s\"", + pa, da, me, uri, hver[wsi->http.request_version]); //lwsl_notice("%s\n", wsi->http.access_log.header_log); l = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_USER_AGENT); if (l) { - wsi->http.access_log.user_agent = lws_malloc(l + 5, "access log"); + wsi->http.access_log.user_agent = + lws_malloc(l + 5, "access log"); if (!wsi->http.access_log.user_agent) { lwsl_err("OOM getting user agent\n"); lws_free_set_NULL(wsi->http.access_log.header_log); @@ -163,8 +164,9 @@ lws_access_log(struct lws *wsi) * maintaining the structure of the log text */ l = lws_snprintf(ass, sizeof(ass) - 7, "%s %d %lu \"%s", - wsi->http.access_log.header_log, - wsi->http.access_log.response, wsi->http.access_log.sent, p1); + wsi->http.access_log.header_log, + wsi->http.access_log.response, + wsi->http.access_log.sent, p1); if (strlen(p) > sizeof(ass) - 6 - l) p[sizeof(ass) - 6 - l] = '\0'; l += lws_snprintf(ass + l, sizeof(ass) - 1 - l, "\" \"%s\"\n", p); diff --git a/lib/roles/http/server/lejp-conf.c b/lib/roles/http/server/lejp-conf.c index 205023821..0dd701d83 100644 --- a/lib/roles/http/server/lejp-conf.c +++ b/lib/roles/http/server/lejp-conf.c @@ -479,13 +479,19 @@ lejp_vhosts_cb(struct lejp_ctx *ctx, char reason) #if defined(LWS_WITH_TLS) if (a->enable_client_ssl) { - const char *cert_filepath = a->info->client_ssl_cert_filepath; - const char *private_key_filepath = a->info->client_ssl_private_key_filepath; - const char *ca_filepath = a->info->client_ssl_ca_filepath; - const char *cipher_list = a->info->client_ssl_cipher_list; + const char *cert_filepath = + a->info->client_ssl_cert_filepath; + const char *private_key_filepath = + a->info->client_ssl_private_key_filepath; + const char *ca_filepath = + a->info->client_ssl_ca_filepath; + const char *cipher_list = + a->info->client_ssl_cipher_list; + memset(a->info, 0, sizeof(*a->info)); a->info->client_ssl_cert_filepath = cert_filepath; - a->info->client_ssl_private_key_filepath = private_key_filepath; + a->info->client_ssl_private_key_filepath = + private_key_filepath; a->info->client_ssl_ca_filepath = ca_filepath; a->info->client_ssl_cipher_list = cipher_list; a->info->options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; @@ -652,8 +658,8 @@ lejp_vhosts_cb(struct lejp_ctx *ctx, char reason) a->p += n; mp_cgienv->value = a->p; mp_cgienv->options = NULL; - //lwsl_notice(" adding pmo / cgi-env '%s' = '%s'\n", mp_cgienv->name, - // mp_cgienv->value); + //lwsl_notice(" adding pmo / cgi-env '%s' = '%s'\n", + // mp_cgienv->name, mp_cgienv->value); goto dostring; case LEJPVP_PROTOCOL_NAME_OPT: @@ -683,7 +689,7 @@ lejp_vhosts_cb(struct lejp_ctx *ctx, char reason) a->pvo_em->next = a->m.extra_mimetypes; a->m.extra_mimetypes = a->pvo_em; a->pvo_em->name = a->p; - lwsl_notice(" adding extra-mimetypes %s -> %s\n", a->p, ctx->buf); + lwsl_notice(" + extra-mimetypes %s -> %s\n", a->p, ctx->buf); a->p += n; a->pvo_em->value = a->p; a->pvo_em->options = NULL; @@ -801,7 +807,8 @@ dostring: n = lws_ptr_diff(a->end, a->p); lws_strncpy(a->p, p, n + 1); a->p += n; - a->p += lws_snprintf(a->p, a->end - a->p, "%s", LWS_INSTALL_DATADIR); + a->p += lws_snprintf(a->p, a->end - a->p, "%s", + LWS_INSTALL_DATADIR); p += n + strlen(ESC_INSTALL_DATADIR); } @@ -976,7 +983,8 @@ lwsws_get_config_globals(struct lws_context_creation_info *info, const char *d, return 1; lws_snprintf(dd, sizeof(dd) - 1, "%s/conf.d", d); if (lwsws_get_config_d(&a, dd, paths_global, - LWS_ARRAY_SIZE(paths_global), lejp_globals_cb) > 1) + LWS_ARRAY_SIZE(paths_global), + lejp_globals_cb) > 1) return 1; a.plugin_dirs[a.count_plugin_dirs] = NULL; diff --git a/lib/roles/http/server/lws-spa.c b/lib/roles/http/server/lws-spa.c index bdf456389..7229a2e32 100644 --- a/lib/roles/http/server/lws-spa.c +++ b/lib/roles/http/server/lws-spa.c @@ -99,7 +99,8 @@ lws_urldecode_s_create(struct lws *wsi, char *out, int out_len, void *data, if (lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_HTTP_CONTENT_TYPE) > 0) { - /* multipart/form-data; boundary=----WebKitFormBoundarycc7YgAPEIHvgE9Bf */ + /* multipart/form-data; + * boundary=----WebKitFormBoundarycc7YgAPEIHvgE9Bf */ if (!strncmp(buf, "multipart/form-data", 19)) { s->multipart_form_data = 1; @@ -270,7 +271,8 @@ retry_as_first: } in++; if (!m) { - s->state = MT_IGNORE1; // Unknown header - ignore it + /* Unknown header - ignore it */ + s->state = MT_IGNORE1; s->mp = 0; continue; } @@ -417,18 +419,16 @@ lws_urldecode_s_destroy(struct lws_urldecode_stateful *s) struct lws_spa { struct lws_urldecode_stateful *s; - lws_spa_fileupload_cb opt_cb; const char * const *param_names; - int count_params; - char **params; - int *param_length; void *opt_data; - + lws_spa_fileupload_cb opt_cb; + int *param_length; + int count_params; + int max_storage; + char finalized; + char **params; char *storage; char *end; - int max_storage; - - char finalized; }; static int @@ -489,8 +489,8 @@ lws_urldecode_spa_cb(void *data, const char *name, char **buf, int len, LWS_VISIBLE LWS_EXTERN struct lws_spa * lws_spa_create(struct lws *wsi, const char * const *param_names, - int count_params, int max_storage, - lws_spa_fileupload_cb opt_cb, void *opt_data) + int count_params, int max_storage, + lws_spa_fileupload_cb opt_cb, void *opt_data) { struct lws_spa *spa = lws_zalloc(sizeof(*spa), "spa"); @@ -596,11 +596,8 @@ lws_spa_destroy(struct lws_spa *spa) if (spa->s) lws_urldecode_s_destroy(spa->s); - lwsl_debug("%s %p %p %p %p\n", __func__, - spa->param_length, - spa->params, - spa->storage, - spa); + lwsl_debug("%s %p %p %p %p\n", __func__, spa->param_length, + spa->params, spa->storage, spa); lws_free(spa->param_length); lws_free(spa->params); diff --git a/lib/roles/http/server/parsers.c b/lib/roles/http/server/parsers.c index c5617fccf..641e9b8da 100644 --- a/lib/roles/http/server/parsers.c +++ b/lib/roles/http/server/parsers.c @@ -240,7 +240,8 @@ lws_header_table_attach(struct lws *wsi, int autoservice) wsi->http.ah->wsi = wsi; /* mark our owner */ pt->http.ah_count_in_use++; -#if defined(LWS_WITH_PEER_LIMITS) && (defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)) +#if defined(LWS_WITH_PEER_LIMITS) && (defined(LWS_ROLE_H1) || \ + defined(LWS_ROLE_H2)) lws_context_lock(context, "ah attach"); /* <========================= */ if (wsi->peer) wsi->peer->http.count_ah++; @@ -353,13 +354,15 @@ int __lws_header_table_detach(struct lws *wsi, int autoservice) if (!wsi) /* everybody waiting already has too many ah... */ goto nobody_usable_waiting; - lwsl_info("%s: transferring ah to last eligible wsi in wait list %p (wsistate 0x%x)\n", __func__, wsi, wsi->wsistate); + lwsl_info("%s: transferring ah to last eligible wsi in wait list " + "%p (wsistate 0x%x)\n", __func__, wsi, wsi->wsistate); wsi->http.ah = ah; ah->wsi = wsi; /* new owner */ __lws_header_table_reset(wsi, autoservice); -#if defined(LWS_WITH_PEER_LIMITS) && (defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)) +#if defined(LWS_WITH_PEER_LIMITS) && (defined(LWS_ROLE_H1) || \ + defined(LWS_ROLE_H2)) lws_context_lock(context, "ah detach"); /* <========================= */ if (wsi->peer) wsi->peer->http.count_ah++; @@ -397,7 +400,8 @@ int __lws_header_table_detach(struct lws *wsi, int autoservice) } #endif - assert(!!pt->http.ah_wait_list_length == !!(lws_intptr_t)pt->http.ah_wait_list); + assert(!!pt->http.ah_wait_list_length == + !!(lws_intptr_t)pt->http.ah_wait_list); bail: lwsl_info("%s: wsi %p: ah %p (tsi=%d, count = %d)\n", __func__, (void *)wsi, (void *)ah, pt->tid, pt->http.ah_count_in_use); @@ -521,7 +525,8 @@ LWS_VISIBLE int lws_hdr_copy(struct lws *wsi, char *dst, int len, return 0; do { - comma = (wsi->http.ah->frags[n].nfrag && h != WSI_TOKEN_HTTP_COOKIE) ? 1 : 0; + comma = (wsi->http.ah->frags[n].nfrag && + h != WSI_TOKEN_HTTP_COOKIE) ? 1 : 0; if (wsi->http.ah->frags[n].len + comma >= len) return -1; @@ -890,8 +895,9 @@ lws_parse(struct lws *wsi, unsigned char *buf, int *len) if (ah->ups == URIPS_SEEN_SLASH_DOT_DOT) { /* * back up one dir level if possible - * safe against header fragmentation because - * the method URI can only be in 1 fragment + * safe against header fragmentation + * because the method URI can only be + * in 1 fragment */ if (ah->frags[ah->nfrag].len > 2) { ah->pos--; @@ -961,7 +967,8 @@ swallow: pos = ah->lextable_pos; while (1) { - if (lextable[pos] & (1 << 7)) { /* 1-byte, fail on mismatch */ + if (lextable[pos] & (1 << 7)) { + /* 1-byte, fail on mismatch */ if ((lextable[pos] & 0x7f) != c) { nope: ah->lextable_pos = -1; @@ -980,14 +987,15 @@ nope: goto nope; /* b7 = 0, end or 3-byte */ - if (lextable[pos] < FAIL_CHAR) { /* terminal marker */ + if (lextable[pos] < FAIL_CHAR) { /* term mark */ ah->lextable_pos = pos; break; } if (lextable[pos] == c) { /* goto */ - ah->lextable_pos = pos + (lextable[pos + 1]) + - (lextable[pos + 2] << 8); + ah->lextable_pos = pos + + (lextable[pos + 1]) + + (lextable[pos + 2] << 8); break; } @@ -1060,13 +1068,13 @@ nope: n = WSI_TOKEN_ORIGIN; ah->parser_state = (enum lws_token_indexes) - (WSI_TOKEN_GET_URI + n); + (WSI_TOKEN_GET_URI + n); ah->ups = URIPS_IDLE; if (context->token_limits) ah->current_token_limit = context-> - token_limits->token_limit[ - ah->parser_state]; + token_limits->token_limit[ + ah->parser_state]; else ah->current_token_limit = wsi->context->max_http_header_data; diff --git a/lib/roles/http/server/rewrite.c b/lib/roles/http/server/rewrite.c index 3b923ecef..eca443a24 100644 --- a/lib/roles/http/server/rewrite.c +++ b/lib/roles/http/server/rewrite.c @@ -3,7 +3,8 @@ #if defined(LWS_WITH_HUBBUB) LWS_EXTERN struct lws_rewrite * -lws_rewrite_create(struct lws *wsi, hubbub_callback_t cb, const char *from, const char *to) +lws_rewrite_create(struct lws *wsi, hubbub_callback_t cb, const char *from, + const char *to) { struct lws_rewrite *r = lws_malloc(sizeof(*r), "rewrite"); diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c index a2b9075b8..729315602 100644 --- a/lib/roles/http/server/server.c +++ b/lib/roles/http/server/server.c @@ -40,7 +40,7 @@ static const char * const intermediates[] = { "private", "public" }; int _lws_vhost_init_server(const struct lws_context_creation_info *info, - struct lws_vhost *vhost) + struct lws_vhost *vhost) { int n, opt = 1, limit = 1; lws_sockfd_type sockfd; @@ -381,8 +381,8 @@ lws_select_vhost(struct lws_context *context, int port, const char *servername) LWS_VISIBLE LWS_EXTERN const char * lws_get_mimetype(const char *file, const struct lws_http_mount *m) { - int n = (int)strlen(file); const struct lws_protocol_vhost_options *pvo = NULL; + int n = (int)strlen(file); if (m) pvo = m->extra_mimetypes; @@ -616,18 +616,21 @@ lws_http_serve(struct lws *wsi, char *uri, const char *origin, if (m->cache_max_age && m->cache_reusable) { if (!m->cache_revalidate) { cc = cache_control; - cclen = sprintf(cache_control, "%s, max-age=%u", - intermediates[wsi->cache_intermediaries], - m->cache_max_age); + cclen = sprintf(cache_control, + "%s, max-age=%u", + intermediates[wsi->cache_intermediaries], + m->cache_max_age); } else { cc = cache_control; - cclen = sprintf(cache_control, "must-revalidate, %s, max-age=%u", - intermediates[wsi->cache_intermediaries], - m->cache_max_age); + cclen = sprintf(cache_control, + "must-revalidate, %s, max-age=%u", + intermediates[wsi->cache_intermediaries], + m->cache_max_age); } } - if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CACHE_CONTROL, + if (lws_add_http_header_by_token(wsi, + WSI_TOKEN_HTTP_CACHE_CONTROL, (unsigned char *)cc, cclen, &p, end)) return -1; @@ -909,24 +912,25 @@ lws_http_get_uri_and_method(struct lws *wsi, char **puri_ptr, int *puri_len) return -1; } +static const char * const oprot[] = { + "http://", "https://" +}; + int lws_http_action(struct lws *wsi) { struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; - enum http_conn_type conn_type; - enum http_version request_version; - char content_length_str[32]; - struct lws_process_html_args args; const struct lws_http_mount *hit = NULL; - unsigned int n; + enum http_version request_version; + struct lws_process_html_args args; + enum http_conn_type conn_type; + char content_length_str[32]; char http_version_str[12]; - char http_conn_str[25]; - int http_version_len; char *uri_ptr = NULL, *s; int uri_len = 0, meth, m; - static const char * const oprot[] = { - "http://", "https://" - }; + char http_conn_str[25]; + int http_version_len; + unsigned int n; meth = lws_http_get_uri_and_method(wsi, &uri_ptr, &uri_len); if (meth < 0 || meth >= (int)LWS_ARRAY_SIZE(method_names)) @@ -1063,7 +1067,8 @@ lws_http_action(struct lws *wsi) lwsl_info("no hit\n"); - if (lws_bind_protocol(wsi, &wsi->vhost->protocols[0], "no mount hit")) + if (lws_bind_protocol(wsi, &wsi->vhost->protocols[0], + "no mount hit")) return 1; lwsi_set_state(wsi, LRS_DOING_TRANSACTION); @@ -1099,9 +1104,9 @@ lws_http_action(struct lws *wsi) hit->origin_protocol == LWSMPRO_REDIR_HTTPS)) && (hit->origin_protocol != LWSMPRO_CGI && hit->origin_protocol != LWSMPRO_CALLBACK)) { - unsigned char *start = pt->serv_buf + LWS_PRE, - *p = start, *end = p + wsi->context->pt_serv_buf_size - - LWS_PRE - 512; + unsigned char *start = pt->serv_buf + LWS_PRE, *p = start, + *end = p + wsi->context->pt_serv_buf_size - + LWS_PRE - 512; lwsl_info("Doing 301 '%s' org %s\n", s, hit->origin); @@ -1214,9 +1219,9 @@ lws_http_action(struct lws *wsi) if (hit->origin_protocol == LWSMPRO_HTTPS || hit->origin_protocol == LWSMPRO_HTTP) { + char ads[96], rpath[256], *pcolon, *pslash, unix_skt = 0; struct lws_client_connect_info i; struct lws *cwsi; - char ads[96], rpath[256], *pcolon, *pslash, unix_skt = 0; int n, na; memset(&i, 0, sizeof(i)); @@ -1268,8 +1273,7 @@ lws_http_action(struct lws *wsi) i.port = atoi(pcolon + 1); n = lws_snprintf(rpath, sizeof(rpath) - 1, "/%s/%s", - pslash + 1, uri_ptr + - hit->mountpoint_len) - 2; + pslash + 1, uri_ptr + hit->mountpoint_len) - 2; lws_clean_url(rpath); na = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_URI_ARGS); if (na) { @@ -2018,7 +2022,7 @@ lws_http_transaction_completed(struct lws *wsi) if (wsi->http.ah) { // lws_buflist_describe(&wsi->buflist, wsi); if (!lws_buflist_next_segment_len(&wsi->buflist, NULL)) { - lwsl_debug("%s: %p: nothing in buflist so detaching ah\n", + lwsl_debug("%s: %p: nothing in buflist, detaching ah\n", __func__, wsi); lws_header_table_detach(wsi, 1); #ifdef LWS_WITH_TLS @@ -2038,7 +2042,7 @@ lws_http_transaction_completed(struct lws *wsi) } #endif } else { - lwsl_info("%s: %p: resetting and keeping ah as pipeline\n", + lwsl_info("%s: %p: resetting/keeping ah as pipeline\n", __func__, wsi); lws_header_table_reset(wsi, 0); /* @@ -2074,21 +2078,21 @@ lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, { struct lws_context *context = lws_get_context(wsi); struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; + unsigned char *response = pt->serv_buf + LWS_PRE; #if defined(LWS_WITH_RANGES) struct lws_range_parsing *rp = &wsi->http.range; #endif + int ret = 0, cclen = 8, n = HTTP_STATUS_OK; char cache_control[50], *cc = "no-store"; - unsigned char *response = pt->serv_buf + LWS_PRE; + lws_fop_flags_t fflags = LWS_O_RDONLY; + const struct lws_plat_file_ops *fops; + lws_filepos_t total_content_length; unsigned char *p = response; unsigned char *end = p + context->pt_serv_buf_size - LWS_PRE; - lws_filepos_t total_content_length; - int ret = 0, cclen = 8, n = HTTP_STATUS_OK; - lws_fop_flags_t fflags = LWS_O_RDONLY; + const char *vpath; #if defined(LWS_WITH_RANGES) int ranges; #endif - const struct lws_plat_file_ops *fops; - const char *vpath; if (wsi->handling_404) n = HTTP_STATUS_NOT_FOUND; @@ -2108,7 +2112,8 @@ lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, if (!wsi->http.fop_fd) { lwsl_info("%s: Unable to open: '%s': errno %d\n", __func__, file, errno); - if (lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL)) + if (lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, + NULL)) return -1; return !wsi->http2_substream; } @@ -2129,14 +2134,14 @@ lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, */ if (ranges < 0) { /* it means he expressed a range in Range:, but it was illegal */ - lws_return_http_status(wsi, HTTP_STATUS_REQ_RANGE_NOT_SATISFIABLE, - NULL); + lws_return_http_status(wsi, + HTTP_STATUS_REQ_RANGE_NOT_SATISFIABLE, NULL); if (lws_http_transaction_completed(wsi)) return -1; /* <0 means just hang up */ lws_vfs_file_close(&wsi->http.fop_fd); - return 0; /* == 0 means we dealt with the transaction complete */ + return 0; /* == 0 means we did the transaction complete */ } if (ranges) n = HTTP_STATUS_PARTIAL_CONTENT; @@ -2316,7 +2321,8 @@ lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, if (!other_headers || (!strstr(other_headers, "cache-control") && !strstr(other_headers, "Cache-Control"))) { - if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CACHE_CONTROL, + if (lws_add_http_header_by_token(wsi, + WSI_TOKEN_HTTP_CACHE_CONTROL, (unsigned char *)cc, cclen, &p, end)) return -1; } @@ -2379,7 +2385,7 @@ LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi) wsi->http.comp_ctx.may_have_more) { enum lws_write_protocol wp = LWS_WRITE_HTTP; - lwsl_info("%s: completing comp partial (buflist_comp %p, may %d)\n", + lwsl_info("%s: completing comp partial (buflist %p, may %d)\n", __func__, wsi->http.comp_ctx.buflist_comp, wsi->http.comp_ctx.may_have_more); @@ -2421,7 +2427,8 @@ LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi) LWS_H2_FRAME_HEADER_LENGTH, "_lws\x0d\x0a" "Content-Type: %s\x0d\x0a" - "Content-Range: bytes %llu-%llu/%llu\x0d\x0a" + "Content-Range: bytes " + "%llu-%llu/%llu\x0d\x0a" "\x0d\x0a", wsi->http.multipart_content_type, wsi->http.range.start, @@ -2436,7 +2443,8 @@ LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi) } #endif - poss = context->pt_serv_buf_size - n - LWS_H2_FRAME_HEADER_LENGTH; + poss = context->pt_serv_buf_size - n - + LWS_H2_FRAME_HEADER_LENGTH; if (wsi->http.tx_content_length) if (poss > wsi->http.tx_content_remain) @@ -2524,11 +2532,9 @@ LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi) lwsl_debug("added trailing boundary\n"); } #endif - m = lws_write(wsi, p, n, - wsi->http.filepos + amount == wsi->http.filelen ? - LWS_WRITE_HTTP_FINAL : - LWS_WRITE_HTTP - ); + m = lws_write(wsi, p, n, wsi->http.filepos + amount == + wsi->http.filelen ? + LWS_WRITE_HTTP_FINAL : LWS_WRITE_HTTP); if (m < 0) goto file_had_it; @@ -2581,9 +2587,8 @@ all_sent: if (wsi->protocol->callback && user_callback_handle_rxflow(wsi->protocol->callback, - wsi, LWS_CALLBACK_HTTP_FILE_COMPLETION, - wsi->user_space, NULL, - 0) < 0) { + wsi, LWS_CALLBACK_HTTP_FILE_COMPLETION, + wsi->user_space, NULL, 0) < 0) { /* * For http/1.x, the choices from * transaction_completed are either @@ -2687,8 +2692,7 @@ skip: n = (int)strlen(pc); s->swallow[s->pos] = '\0'; if (n != s->pos) { - memmove(s->start + n, - s->start + s->pos, + memmove(s->start + n, s->start + s->pos, old_len - (sp - args->p)); old_len += (n - s->pos) + 1; } diff --git a/lib/roles/ws/client-parser-ws.c b/lib/roles/ws/client-parser-ws.c index 7287fb159..f5aaa6dbb 100644 --- a/lib/roles/ws/client-parser-ws.c +++ b/lib/roles/ws/client-parser-ws.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010-2018 Andy Green * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -399,9 +399,11 @@ spill: memcpy(wsi->ws->ping_payload_buf + LWS_PRE, pp, wsi->ws->rx_ubuf_head); - wsi->ws->close_in_ping_buffer_len = wsi->ws->rx_ubuf_head; + wsi->ws->close_in_ping_buffer_len = + wsi->ws->rx_ubuf_head; - lwsl_info("%s: scheduling return close as ack\n", __func__); + lwsl_info("%s: scheduling return close as ack\n", + __func__); __lws_change_pollfd(wsi, LWS_POLLIN, 0); lws_set_timeout(wsi, PENDING_TIMEOUT_CLOSE_SEND, 3); wsi->waiting_to_send_close_frame = 1; @@ -437,7 +439,7 @@ spill: /* stash the pong payload */ memcpy(wsi->ws->ping_payload_buf + LWS_PRE, &wsi->ws->rx_ubuf[LWS_PRE], - wsi->ws->rx_ubuf_head); + wsi->ws->rx_ubuf_head); wsi->ws->ping_payload_len = wsi->ws->rx_ubuf_head; wsi->ws->ping_pending_flag = 1; diff --git a/lib/roles/ws/client-ws.c b/lib/roles/ws/client-ws.c index 463a788cf..d88833f38 100644 --- a/lib/roles/ws/client-ws.c +++ b/lib/roles/ws/client-ws.c @@ -217,8 +217,8 @@ lws_client_ws_upgrade(struct lws *wsi, const char **cce) const struct lws_extension *ext; char ext_name[128]; const char *c, *a; - char ignore; int more = 1; + char ignore; #endif if (wsi->client_h2_substream) {/* !!! client ws-over-h2 not there yet */ @@ -469,7 +469,8 @@ check_extensions: if (ext->callback(lws_get_context(wsi), ext, wsi, LWS_EXT_CB_CLIENT_CONSTRUCT, - (void *)&wsi->ws->act_ext_user[wsi->ws->count_act_ext], + (void *)&wsi->ws->act_ext_user[ + wsi->ws->count_act_ext], (void *)&opts, 0)) { lwsl_info(" ext %s failed construction\n", ext_name); @@ -491,8 +492,10 @@ check_extensions: } if (ext_name[0] && - lws_ext_parse_options(ext, wsi, wsi->ws->act_ext_user[ - wsi->ws->count_act_ext], opts, ext_name, + lws_ext_parse_options(ext, wsi, + wsi->ws->act_ext_user[ + wsi->ws->count_act_ext], + opts, ext_name, (int)strlen(ext_name))) { lwsl_err("%s: unable to parse user defaults '%s'", __func__, ext_name); @@ -504,7 +507,8 @@ check_extensions: * give the extension the server options */ if (a && lws_ext_parse_options(ext, wsi, - wsi->ws->act_ext_user[wsi->ws->count_act_ext], + wsi->ws->act_ext_user[ + wsi->ws->count_act_ext], opts, a, lws_ptr_diff(c, a))) { lwsl_err("%s: unable to parse remote def '%s'", __func__, a); diff --git a/lib/roles/ws/ext/extension-permessage-deflate.c b/lib/roles/ws/ext/extension-permessage-deflate.c index 0079b27c0..b832d1d27 100644 --- a/lib/roles/ws/ext/extension-permessage-deflate.c +++ b/lib/roles/ws/ext/extension-permessage-deflate.c @@ -82,8 +82,10 @@ lws_extension_callback_pm_deflate(struct lws_context *context, oa = in; if (!oa->option_name) break; - lwsl_ext("%s: named option set: %s\n", __func__, oa->option_name); - for (n = 0; n < (int)LWS_ARRAY_SIZE(lws_ext_pm_deflate_options); n++) + lwsl_ext("%s: named option set: %s\n", __func__, + oa->option_name); + for (n = 0; n < (int)LWS_ARRAY_SIZE(lws_ext_pm_deflate_options); + n++) if (!strcmp(lws_ext_pm_deflate_options[n].name, oa->option_name)) break; @@ -204,8 +206,7 @@ lws_extension_callback_pm_deflate(struct lws_context *context, * rx buffer by the caller, so this assumption is safe while * we block new rx while draining the existing rx */ - if (!priv->rx.avail_in && ebuf->token && - ebuf->len) { + if (!priv->rx.avail_in && ebuf->token && ebuf->len) { priv->rx.next_in = (unsigned char *)ebuf->token; priv->rx.avail_in = ebuf->len; } @@ -330,7 +331,7 @@ lws_extension_callback_pm_deflate(struct lws_context *context, n = deflateInit2(&priv->tx, priv->args[PMD_COMP_LEVEL], Z_DEFLATED, -priv->args[PMD_SERVER_MAX_WINDOW_BITS + - (wsi->vhost->listen_port <= 0)], + (wsi->vhost->listen_port <= 0)], priv->args[PMD_MEM_LEVEL], Z_DEFAULT_STRATEGY); if (n != Z_OK) { diff --git a/lib/roles/ws/ext/extension.c b/lib/roles/ws/ext/extension.c index 9e9938a39..d8c0d5371 100644 --- a/lib/roles/ws/ext/extension.c +++ b/lib/roles/ws/ext/extension.c @@ -54,26 +54,31 @@ lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi, n = 0; pending_close_quote = 0; while (m) { - if (m & 1) { - lwsl_ext(" m=%d, n=%d, w=%d\n", m, n, w); + if (!(m & 1)) { + m >>= 1; + n++; + continue; + } + lwsl_ext(" m=%d, n=%d, w=%d\n", m, n, w); - if (*in == opts[n].name[w]) { - if (!opts[n].name[w + 1]) { - oa.option_index = n; - lwsl_ext("hit %d\n", oa.option_index); - leap = LEAPS_SEEK_VAL; - if (len == 1) - goto set_arg; - break; - } - } else { - match_map &= ~(1 << n); - if (!match_map) { - lwsl_ext("empty match map\n"); - return -1; - } + if (*in == opts[n].name[w]) { + if (!opts[n].name[w + 1]) { + oa.option_index = n; + lwsl_ext("hit %d\n", + oa.option_index); + leap = LEAPS_SEEK_VAL; + if (len == 1) + goto set_arg; + break; + } + } else { + match_map &= ~(1 << n); + if (!match_map) { + lwsl_ext("empty match map\n"); + return -1; } } + m >>= 1; n++; } @@ -167,9 +172,9 @@ int lws_ext_cb_active(struct lws *wsi, int reason, void *arg, int len) return 0; for (n = 0; n < wsi->ws->count_act_ext; n++) { - m = wsi->ws->active_extensions[n]->callback(lws_get_context(wsi), - wsi->ws->active_extensions[n], wsi, reason, - wsi->ws->act_ext_user[n], arg, len); + m = wsi->ws->active_extensions[n]->callback( + lws_get_context(wsi), wsi->ws->active_extensions[n], + wsi, reason, wsi->ws->act_ext_user[n], arg, len); if (m < 0) { lwsl_ext("Ext '%s' failed to handle callback %d!\n", wsi->ws->active_extensions[n]->name, reason); @@ -236,8 +241,8 @@ lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len) ret = 0; /* show every extension the new incoming data */ - m = lws_ext_cb_active(wsi, - LWS_EXT_CB_PACKET_TX_PRESEND, &ebuf, 0); + m = lws_ext_cb_active(wsi, LWS_EXT_CB_PACKET_TX_PRESEND, + &ebuf, 0); if (m < 0) return -1; if (m) /* handled */ @@ -254,7 +259,7 @@ lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len) if (ebuf.len) { n = lws_issue_raw(wsi, (unsigned char *)ebuf.token, - ebuf.len); + ebuf.len); if (n < 0) { lwsl_info("closing from ext access\n"); return -1; @@ -348,7 +353,8 @@ lws_set_extension_option(struct lws *wsi, const char *ext_name, oa.start = opt_val; oa.len = 0; - return wsi->ws->active_extensions[idx]->callback( - wsi->context, wsi->ws->active_extensions[idx], wsi, - LWS_EXT_CB_NAMED_OPTION_SET, wsi->ws->act_ext_user[idx], &oa, 0); + return wsi->ws->active_extensions[idx]->callback(wsi->context, + wsi->ws->active_extensions[idx], wsi, + LWS_EXT_CB_NAMED_OPTION_SET, wsi->ws->act_ext_user[idx], + &oa, 0); } diff --git a/lib/roles/ws/ops-ws.c b/lib/roles/ws/ops-ws.c index dd69ca3fe..1cbc6ac6a 100644 --- a/lib/roles/ws/ops-ws.c +++ b/lib/roles/ws/ops-ws.c @@ -155,7 +155,9 @@ handle_first: if (wsi->ws->opcode == LWSWSOPC_BINARY_FRAME) wsi->ws->check_utf8 = 0; if (wsi->ws->continuation_possible) { - lws_close_reason(wsi, LWS_CLOSE_STATUS_PROTOCOL_ERR, (uint8_t *)"bad cont", 8); + lws_close_reason(wsi, + LWS_CLOSE_STATUS_PROTOCOL_ERR, + (uint8_t *)"bad cont", 8); return -1; } wsi->ws->rsv_first_msg = (c & 0x70); @@ -166,7 +168,9 @@ handle_first: break; case LWSWSOPC_CONTINUATION: if (!wsi->ws->continuation_possible) { - lws_close_reason(wsi, LWS_CLOSE_STATUS_PROTOCOL_ERR, (uint8_t *)"bad cont", 8); + lws_close_reason(wsi, + LWS_CLOSE_STATUS_PROTOCOL_ERR, + (uint8_t *)"bad cont", 8); return -1; } break; @@ -184,7 +188,8 @@ handle_first: case 0xd: case 0xe: case 0xf: - lws_close_reason(wsi, LWS_CLOSE_STATUS_PROTOCOL_ERR, (uint8_t *)"bad opc", 7); + lws_close_reason(wsi, LWS_CLOSE_STATUS_PROTOCOL_ERR, + (uint8_t *)"bad opc", 7); lwsl_info("illegal opcode\n"); return -1; } @@ -193,7 +198,8 @@ handle_first: (wsi->ws->opcode == LWSWSOPC_TEXT_FRAME || wsi->ws->opcode == LWSWSOPC_BINARY_FRAME)) { lwsl_info("hey you owed us a FIN\n"); - lws_close_reason(wsi, LWS_CLOSE_STATUS_PROTOCOL_ERR, (uint8_t *)"bad fin", 7); + lws_close_reason(wsi, LWS_CLOSE_STATUS_PROTOCOL_ERR, + (uint8_t *)"bad fin", 7); return -1; } if ((!(wsi->ws->opcode & 8)) && wsi->ws->final) { @@ -373,17 +379,19 @@ handle_first: } if (!(already_processed & ALREADY_PROCESSED_IGNORE_CHAR)) { if (wsi->ws->all_zero_nonce) - wsi->ws->rx_ubuf[LWS_PRE + (wsi->ws->rx_ubuf_head++)] = - c; + wsi->ws->rx_ubuf[LWS_PRE + + (wsi->ws->rx_ubuf_head++)] = c; else - wsi->ws->rx_ubuf[LWS_PRE + (wsi->ws->rx_ubuf_head++)] = + wsi->ws->rx_ubuf[LWS_PRE + + (wsi->ws->rx_ubuf_head++)] = c ^ wsi->ws->mask[(wsi->ws->mask_idx++) & 3]; --wsi->ws->rx_packet_length; } if (!wsi->ws->rx_packet_length) { - lwsl_debug("%s: ws fragment length exhausted\n", __func__); + lwsl_debug("%s: ws fragment length exhausted\n", + __func__); /* spill because we have the whole frame */ wsi->lws_rx_parse_state = LWS_RXPS_NEW; goto spill; @@ -451,7 +459,8 @@ spill: * have to just close our end. */ wsi->socket_is_permanently_unusable = 1; - lwsl_parser("Closing on peer close due to Pending tx\n"); + lwsl_parser("Closing on peer close " + "due to pending tx\n"); return -1; } @@ -570,7 +579,8 @@ drain_extension: //if (lin) // lwsl_hexdump_notice(ebuf.token, ebuf.len); n = lws_ext_cb_active(wsi, LWS_EXT_CB_PAYLOAD_RX, &ebuf, 0); - lwsl_debug("%s: ext says %d / ebuf.len %d\n", __func__, n, ebuf.len); + lwsl_debug("%s: ext says %d / ebuf.len %d\n", __func__, + n, ebuf.len); if (wsi->ws->rx_draining_ext) already_processed &= ~ALREADY_PROCESSED_NO_CB; #endif @@ -813,9 +823,9 @@ LWS_VISIBLE int lws_is_final_fragment(struct lws *wsi) { #if !defined(LWS_WITHOUT_EXTENSIONS) - lwsl_debug("%s: final %d, rx pk length %ld, draining %ld\n", __func__, - wsi->ws->final, (long)wsi->ws->rx_packet_length, - (long)wsi->ws->rx_draining_ext); + lwsl_debug("%s: final %d, rx pk length %ld, draining %ld\n", __func__, + wsi->ws->final, (long)wsi->ws->rx_packet_length, + (long)wsi->ws->rx_draining_ext); return wsi->ws->final && !wsi->ws->rx_packet_length && !wsi->ws->rx_draining_ext; #else @@ -882,8 +892,8 @@ static int rops_handle_POLLIN_ws(struct lws_context_per_thread *pt, struct lws *wsi, struct lws_pollfd *pollfd) { - struct lws_tokens ebuf; unsigned int pending = 0; + struct lws_tokens ebuf; char buffered = 0; int n = 0, m; #if defined(LWS_WITH_HTTP2) @@ -927,7 +937,9 @@ rops_handle_POLLIN_ws(struct lws_context_per_thread *pt, struct lws *wsi, return LWS_HPI_RET_HANDLED; } - //lwsl_notice("%s: wsi->ws->tx_draining_ext %d revents 0x%x 0x%x %d\n", __func__, wsi->ws->tx_draining_ext, pollfd->revents, wsi->wsistate, lwsi_state_can_handle_POLLOUT(wsi)); + //lwsl_notice("%s: wsi->ws->tx_draining_ext %d revents 0x%x 0x%x %d\n", + //__func__, wsi->ws->tx_draining_ext, pollfd->revents, wsi->wsistate, + //lwsi_state_can_handle_POLLOUT(wsi)); /* 1: something requested a callback when it was OK to write */ @@ -1199,8 +1211,9 @@ int rops_handle_POLLOUT_ws(struct lws *wsi) if (n >= 0) { if (wsi->close_needs_ack) { lwsi_set_state(wsi, LRS_AWAITING_CLOSE_ACK); - lws_set_timeout(wsi, PENDING_TIMEOUT_CLOSE_ACK, 5); - lwsl_debug("sent close indication, awaiting ack\n"); + lws_set_timeout(wsi, PENDING_TIMEOUT_CLOSE_ACK, + 5); + lwsl_debug("sent close, await ack\n"); return LWS_HP_RET_BAIL_OK; } @@ -1225,7 +1238,8 @@ int rops_handle_POLLOUT_ws(struct lws *wsi) wsi->ws->ping_pending_flag = 0; return LWS_HP_RET_BAIL_OK; } - lwsl_info("issuing pong %d on wsi %p\n", wsi->ws->ping_payload_len, wsi); + lwsl_info("issuing pong %d on wsi %p\n", + wsi->ws->ping_payload_len, wsi); } n = lws_write(wsi, &wsi->ws->ping_payload_buf[LWS_PRE], @@ -1592,8 +1606,9 @@ rops_write_role_protocol_ws(struct lws *wsi, unsigned char *buf, size_t len, if (!(wpt & LWS_WRITE_NO_FIN) && len) *wp &= ~LWS_WRITE_NO_FIN; - lwsl_ext("FORCED draining wp to 0x%02X (stashed 0x%02X, incoming 0x%02X)\n", *wp, - wsi->ws->tx_draining_stashed_wp, wpt); + lwsl_ext("FORCED draining wp to 0x%02X " + "(stashed 0x%02X, incoming 0x%02X)\n", *wp, + wsi->ws->tx_draining_stashed_wp, wpt); // assert(0); } #endif @@ -1645,13 +1660,16 @@ rops_write_role_protocol_ws(struct lws *wsi, unsigned char *buf, size_t len, n = lws_ext_cb_active(wsi, LWS_EXT_CB_PAYLOAD_TX, &ebuf, *wp); if (n < 0) return -1; - // lwsl_notice("ext processed %d plaintext into %d compressed (wp 0x%x)\n", m, (int)ebuf.len, *wp); + // lwsl_notice("ext processed %d plaintext into %d compressed" + // " (wp 0x%x)\n", m, (int)ebuf.len, *wp); if (n && ebuf.len) { - lwsl_ext("write drain len %d (wp 0x%x) SETTING tx_draining_ext\n", (int)ebuf.len, *wp); + lwsl_ext("write drain len %d (wp 0x%x) SETTING " + "tx_draining_ext\n", (int)ebuf.len, *wp); /* extension requires further draining */ wsi->ws->tx_draining_ext = 1; - wsi->ws->tx_draining_ext_list = pt->ws.tx_draining_ext_list; + wsi->ws->tx_draining_ext_list = + pt->ws.tx_draining_ext_list; pt->ws.tx_draining_ext_list = wsi; /* we must come back to do more */ lws_callback_on_writable(wsi); @@ -1688,7 +1706,8 @@ rops_write_role_protocol_ws(struct lws *wsi, unsigned char *buf, size_t len, */ if (len && !ebuf.len) { if (!wsi->ws->stashed_write_pending) - wsi->ws->stashed_write_type = (char)(*wp) & 0x3f; + wsi->ws->stashed_write_type = + (char)(*wp) & 0x3f; wsi->ws->stashed_write_pending = 1; return (int)len; } @@ -1810,7 +1829,7 @@ do_more_inside_frame: assert(encap != wsi); return encap->role_ops->write_role_protocol(wsi, buf - pre, - len + pre, wp); + len + pre, wp); } switch ((*wp) & 0x1f) { diff --git a/lib/roles/ws/server-ws.c b/lib/roles/ws/server-ws.c index cef758e20..bdc45367d 100644 --- a/lib/roles/ws/server-ws.c +++ b/lib/roles/ws/server-ws.c @@ -124,7 +124,7 @@ lws_extension_server_handshake(struct lws *wsi, char **p, int budget) */ for (m = 0; m < wsi->ws->count_act_ext; m++) if (wsi->ws->active_extensions[m] == ext) { - lwsl_info("extension mentioned twice\n"); + lwsl_info("ext mentioned twice\n"); return 1; /* shenanigans */ } @@ -209,16 +209,17 @@ lws_extension_server_handshake(struct lws *wsi, char **p, int budget) oa.len = 0; lwsl_info("setting '%s'\n", po->name); if (!ext->callback(lws_get_context(wsi), - ext, wsi, - LWS_EXT_CB_OPTION_SET, - wsi->ws->act_ext_user[ - wsi->ws->count_act_ext], + ext, wsi, + LWS_EXT_CB_OPTION_SET, + wsi->ws->act_ext_user[ + wsi->ws->count_act_ext], &oa, (end - *p))) { - *p += lws_snprintf(*p, (end - *p), - "; %s", po->name); + *p += lws_snprintf(*p, + (end - *p), + "; %s", po->name); lwsl_debug("adding option %s\n", - po->name); + po->name); } po++; } @@ -230,7 +231,8 @@ lws_extension_server_handshake(struct lws *wsi, char **p, int budget) } wsi->ws->count_act_ext++; - lwsl_parser("cnt_act_ext <- %d\n", wsi->ws->count_act_ext); + lwsl_parser("cnt_act_ext <- %d\n", + wsi->ws->count_act_ext); if (args && *args == ',') more = 0; @@ -246,8 +248,6 @@ lws_extension_server_handshake(struct lws *wsi, char **p, int budget) } #endif - - int lws_process_ws_upgrade(struct lws *wsi) { @@ -325,8 +325,8 @@ check_protocol: */ lws_tokenize_init(&ts, buf, LWS_TOKENIZE_F_COMMA_SEP_LIST | - LWS_TOKENIZE_F_MINUS_NONTERM | - LWS_TOKENIZE_F_RFC7230_DELIMS); + LWS_TOKENIZE_F_MINUS_NONTERM | + LWS_TOKENIZE_F_RFC7230_DELIMS); ts.len = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_PROTOCOL); if (ts.len < 0) { lwsl_err("%s: protocol list too long\n", __func__); @@ -438,7 +438,8 @@ alloc_ws: lwsl_notice("h2 ws handshake failed\n"); return 1; } - lws_role_transition(wsi, LWSIFR_SERVER | LWSIFR_P_ENCAP_H2, + lws_role_transition(wsi, + LWSIFR_SERVER | LWSIFR_P_ENCAP_H2, LRS_ESTABLISHED, &role_ops_ws); } else #endif @@ -478,7 +479,8 @@ handshake_0405(struct lws_context *context, struct lws *wsi) goto bail; } - if (lws_hdr_total_length(wsi, WSI_TOKEN_KEY) >= MAX_WEBSOCKET_04_KEY_LEN) { + if (lws_hdr_total_length(wsi, WSI_TOKEN_KEY) >= + MAX_WEBSOCKET_04_KEY_LEN) { lwsl_warn("Client key too long %d\n", MAX_WEBSOCKET_04_KEY_LEN); goto bail; } @@ -508,7 +510,8 @@ handshake_0405(struct lws_context *context, struct lws *wsi) /* make a buffer big enough for everything */ - response = (char *)pt->serv_buf + MAX_WEBSOCKET_04_KEY_LEN + 256 + LWS_PRE; + response = (char *)pt->serv_buf + MAX_WEBSOCKET_04_KEY_LEN + + 256 + LWS_PRE; p = response; LWS_CPYAPP(p, "HTTP/1.1 101 Switching Protocols\x0d\x0a" "Upgrade: WebSocket\x0d\x0a" @@ -601,9 +604,9 @@ bail: static int lws_ws_frame_rest_is_payload(struct lws *wsi, uint8_t **buf, size_t len) { + unsigned int avail = (unsigned int)len; uint8_t *buffer = *buf, mask[4]; struct lws_tokens ebuf; - unsigned int avail = (unsigned int)len; #if !defined(LWS_WITHOUT_EXTENSIONS) unsigned int old_packet_length = (int)wsi->ws->rx_packet_length; #endif diff --git a/lib/tls/mbedtls/lws-genrsa.c b/lib/tls/mbedtls/lws-genrsa.c index 6c89fa7e9..99b2e7565 100644 --- a/lib/tls/mbedtls/lws-genrsa.c +++ b/lib/tls/mbedtls/lws-genrsa.c @@ -129,7 +129,7 @@ cleanup_1: LWS_VISIBLE int lws_genrsa_public_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, - size_t in_len, uint8_t *out, size_t out_max) + size_t in_len, uint8_t *out, size_t out_max) { size_t olen = 0; int n; @@ -149,7 +149,7 @@ lws_genrsa_public_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, LWS_VISIBLE int lws_genrsa_public_encrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, - size_t in_len, uint8_t *out) + size_t in_len, uint8_t *out) { int n; @@ -213,8 +213,8 @@ lws_genrsa_public_verify(struct lws_genrsa_ctx *ctx, const uint8_t *in, LWS_VISIBLE int lws_genrsa_public_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in, - enum lws_genhash_types hash_type, uint8_t *sig, - size_t sig_len) + enum lws_genhash_types hash_type, uint8_t *sig, + size_t sig_len) { int n, h = lws_genrsa_genrsa_hash_to_mbed_hash(hash_type); diff --git a/lib/tls/mbedtls/mbedtls-server.c b/lib/tls/mbedtls/mbedtls-server.c index f17c7e549..df6ddf2c6 100644 --- a/lib/tls/mbedtls/mbedtls-server.c +++ b/lib/tls/mbedtls/mbedtls-server.c @@ -294,18 +294,20 @@ lws_tls_server_accept(struct lws *wsi) if (n == 1) { if (strstr(wsi->vhost->name, ".invalid")) { - lwsl_notice("%s: vhost has .invalid, rejecting accept\n", __func__); + lwsl_notice("%s: vhost has .invalid, " + "rejecting accept\n", __func__); return LWS_SSL_CAPABLE_ERROR; } - n = lws_tls_peer_cert_info(wsi, LWS_TLS_CERT_INFO_COMMON_NAME, &ir, - sizeof(ir.ns.name)); + n = lws_tls_peer_cert_info(wsi, LWS_TLS_CERT_INFO_COMMON_NAME, + &ir, sizeof(ir.ns.name)); if (!n) lwsl_notice("%s: client cert CN '%s'\n", __func__, ir.ns.name); else - lwsl_info("%s: couldn't get client cert CN\n", __func__); + lwsl_info("%s: couldn't get client cert CN\n", + __func__); return LWS_SSL_CAPABLE_DONE; } @@ -322,7 +324,8 @@ lws_tls_server_accept(struct lws *wsi) if (m == SSL_ERROR_WANT_READ || SSL_want_read(wsi->tls.ssl)) { if (lws_change_pollfd(wsi, 0, LWS_POLLIN)) { - lwsl_info("%s: WANT_READ change_pollfd failed\n", __func__); + lwsl_info("%s: WANT_READ change_pollfd failed\n", + __func__); return LWS_SSL_CAPABLE_ERROR; } @@ -333,7 +336,8 @@ lws_tls_server_accept(struct lws *wsi) lwsl_debug("%s: WANT_WRITE\n", __func__); if (lws_change_pollfd(wsi, 0, LWS_POLLOUT)) { - lwsl_info("%s: WANT_WRITE change_pollfd failed\n", __func__); + lwsl_info("%s: WANT_WRITE change_pollfd failed\n", + __func__); return LWS_SSL_CAPABLE_ERROR; } return LWS_SSL_CAPABLE_MORE_SERVICE_WRITE; @@ -554,7 +558,8 @@ lws_tls_acme_sni_cert_create(struct lws_vhost *vhost, const char *san_a, //lwsl_hexdump_level(LLL_DEBUG, pkey_asn1, n); /* and to use our generated private key */ - n = SSL_CTX_use_PrivateKey_ASN1(0, vhost->tls.ssl_ctx, pkey_asn1, m); + n = SSL_CTX_use_PrivateKey_ASN1(0, vhost->tls.ssl_ctx, + pkey_asn1, m); lws_free(pkey_asn1); if (n != 1) { lwsl_err("%s: SSL_CTX_use_PrivateKey_ASN1 failed\n", diff --git a/lib/tls/mbedtls/ssl.c b/lib/tls/mbedtls/ssl.c index b6104715b..b81f88862 100644 --- a/lib/tls/mbedtls/ssl.c +++ b/lib/tls/mbedtls/ssl.c @@ -33,7 +33,8 @@ lws_context_init_ssl_library(const struct lws_context_creation_info *info) lwsl_info(" Compiled with MbedTLS support\n"); if (!lws_check_opt(info->options, LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT)) - lwsl_info(" SSL disabled: no LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT\n"); + lwsl_info(" SSL disabled: no " + "LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT\n"); return 0; } @@ -78,7 +79,8 @@ lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) if (!wsi->seen_rx && wsi->accept_start_us) { lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_MS_SSL_RX_DELAY, - lws_time_in_microseconds() - wsi->accept_start_us); + lws_time_in_microseconds() - + wsi->accept_start_us); lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_SSL_CONNS_HAD_RX, 1); wsi->seen_rx = 1; diff --git a/lib/tls/openssl/lws-genrsa.c b/lib/tls/openssl/lws-genrsa.c index d04aea87c..a136327b3 100644 --- a/lib/tls/openssl/lws-genrsa.c +++ b/lib/tls/openssl/lws-genrsa.c @@ -225,8 +225,8 @@ lws_genrsa_public_verify(struct lws_genrsa_ctx *ctx, const uint8_t *in, LWS_VISIBLE int lws_genrsa_public_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in, - enum lws_genhash_types hash_type, uint8_t *sig, - size_t sig_len) + enum lws_genhash_types hash_type, uint8_t *sig, + size_t sig_len) { int n = lws_genrsa_genrsa_hash_to_NID(hash_type), h = (int)lws_genhash_size(hash_type); diff --git a/lib/tls/openssl/openssl-client.c b/lib/tls/openssl/openssl-client.c index a452aa3e6..9754afa8d 100644 --- a/lib/tls/openssl/openssl-client.c +++ b/lib/tls/openssl/openssl-client.c @@ -40,29 +40,37 @@ OpenSSL_client_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) int err = X509_STORE_CTX_get_error(x509_ctx); if (err != X509_V_OK) { - ssl = X509_STORE_CTX_get_ex_data(x509_ctx, SSL_get_ex_data_X509_STORE_CTX_idx()); - wsi = SSL_get_ex_data(ssl, openssl_websocket_private_data_index); + ssl = X509_STORE_CTX_get_ex_data(x509_ctx, + SSL_get_ex_data_X509_STORE_CTX_idx()); + wsi = SSL_get_ex_data(ssl, + openssl_websocket_private_data_index); if ((err == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT || - err == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) && - wsi->tls.use_ssl & LCCSCF_ALLOW_SELFSIGNED) { - lwsl_notice("accepting self-signed certificate (verify_callback)\n"); + err == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) && + wsi->tls.use_ssl & LCCSCF_ALLOW_SELFSIGNED) { + lwsl_notice("accepting self-signed " + "certificate (verify_callback)\n"); X509_STORE_CTX_set_error(x509_ctx, X509_V_OK); return 1; // ok } else if ((err == X509_V_ERR_CERT_NOT_YET_VALID || - err == X509_V_ERR_CERT_HAS_EXPIRED) && - wsi->tls.use_ssl & LCCSCF_ALLOW_EXPIRED) { + err == X509_V_ERR_CERT_HAS_EXPIRED) && + wsi->tls.use_ssl & LCCSCF_ALLOW_EXPIRED) { if (err == X509_V_ERR_CERT_NOT_YET_VALID) - lwsl_notice("accepting not yet valid certificate (verify_callback)\n"); + lwsl_notice("accepting not yet valid " + "certificate (verify_" + "callback)\n"); else if (err == X509_V_ERR_CERT_HAS_EXPIRED) - lwsl_notice("accepting expired certificate (verify_callback)\n"); + lwsl_notice("accepting expired " + "certificate (verify_" + "callback)\n"); X509_STORE_CTX_set_error(x509_ctx, X509_V_OK); return 1; // ok } } } - ssl = X509_STORE_CTX_get_ex_data(x509_ctx, SSL_get_ex_data_X509_STORE_CTX_idx()); + ssl = X509_STORE_CTX_get_ex_data(x509_ctx, + SSL_get_ex_data_X509_STORE_CTX_idx()); wsi = SSL_get_ex_data(ssl, openssl_websocket_private_data_index); n = lws_get_context_protocol(wsi->context, 0).callback(wsi, @@ -76,14 +84,21 @@ OpenSSL_client_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) if (!preverify_ok) { int err = X509_STORE_CTX_get_error(x509_ctx); - if (err != X509_V_OK) { /* cert validation error was not handled in callback */ + if (err != X509_V_OK) { + /* cert validation error was not handled in callback */ int depth = X509_STORE_CTX_get_error_depth(x509_ctx); - const char* msg = X509_verify_cert_error_string(err); - lwsl_err("SSL error: %s (preverify_ok=%d;err=%d;depth=%d)\n", msg, preverify_ok, err, depth); + const char *msg = X509_verify_cert_error_string(err); + + lwsl_err("SSL error: %s (preverify_ok=%d;err=%d;" + "depth=%d)\n", msg, preverify_ok, err, depth); + return preverify_ok; // not ok } } - /* convert callback return code from 0 = OK to verify callback return value 1 = OK */ + /* + * convert callback return code from 0 = OK to verify callback + * return value 1 = OK + */ return !n; } #endif @@ -142,7 +157,7 @@ lws_ssl_client_bio_create(struct lws *wsi) /* Enable automatic hostname checks */ X509_VERIFY_PARAM_set_hostflags(param, - X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); + X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); X509_VERIFY_PARAM_set1_host(param, hostname, 0); } #endif @@ -150,7 +165,8 @@ lws_ssl_client_bio_create(struct lws *wsi) #if !defined(USE_WOLFSSL) #ifndef USE_OLD_CYASSL /* OpenSSL_client_verify_callback will be called @ SSL_connect() */ - SSL_set_verify(wsi->tls.ssl, SSL_VERIFY_PEER, OpenSSL_client_verify_callback); + SSL_set_verify(wsi->tls.ssl, SSL_VERIFY_PEER, + OpenSSL_client_verify_callback); #endif #endif @@ -164,11 +180,13 @@ lws_ssl_client_bio_create(struct lws *wsi) #ifdef USE_WOLFSSL #ifdef USE_OLD_CYASSL #ifdef CYASSL_SNI_HOST_NAME - CyaSSL_UseSNI(wsi->tls.ssl, CYASSL_SNI_HOST_NAME, hostname, strlen(hostname)); + CyaSSL_UseSNI(wsi->tls.ssl, CYASSL_SNI_HOST_NAME, hostname, + strlen(hostname)); #endif #else #ifdef WOLFSSL_SNI_HOST_NAME - wolfSSL_UseSNI(wsi->tls.ssl, WOLFSSL_SNI_HOST_NAME, hostname, strlen(hostname)); + wolfSSL_UseSNI(wsi->tls.ssl, WOLFSSL_SNI_HOST_NAME, hostname, + strlen(hostname)); #endif #endif #else @@ -194,7 +212,8 @@ lws_ssl_client_bio_create(struct lws *wsi) #endif #endif /* USE_WOLFSSL */ - wsi->tls.client_bio = BIO_new_socket((int)(long long)wsi->desc.sockfd, BIO_NOCLOSE); + wsi->tls.client_bio = BIO_new_socket((int)(long long)wsi->desc.sockfd, + BIO_NOCLOSE); SSL_set_bio(wsi->tls.ssl, wsi->tls.client_bio, wsi->tls.client_bio); #ifdef USE_WOLFSSL @@ -225,7 +244,8 @@ lws_ssl_client_bio_create(struct lws *wsi) SSL_set_alpn_protos(wsi->tls.ssl, openssl_alpn, n); #endif - SSL_set_ex_data(wsi->tls.ssl, openssl_websocket_private_data_index, wsi); + SSL_set_ex_data(wsi->tls.ssl, openssl_websocket_private_data_index, + wsi); return 0; } @@ -233,7 +253,8 @@ lws_ssl_client_bio_create(struct lws *wsi) enum lws_ssl_capable_status lws_tls_client_connect(struct lws *wsi) { -#if defined(LWS_HAVE_SSL_set_alpn_protos) && defined(LWS_HAVE_SSL_get0_alpn_selected) +#if defined(LWS_HAVE_SSL_set_alpn_protos) && \ + defined(LWS_HAVE_SSL_get0_alpn_selected) const unsigned char *prot; char a[32]; unsigned int len; @@ -241,7 +262,8 @@ lws_tls_client_connect(struct lws *wsi) int m, n = SSL_connect(wsi->tls.ssl); if (n == 1) { -#if defined(LWS_HAVE_SSL_set_alpn_protos) && defined(LWS_HAVE_SSL_get0_alpn_selected) +#if defined(LWS_HAVE_SSL_set_alpn_protos) && \ + defined(LWS_HAVE_SSL_get0_alpn_selected) SSL_get0_alpn_selected(wsi->tls.ssl, &prot, &len); if (len >= sizeof(a)) @@ -426,12 +448,14 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, x509_store = X509_STORE_new(); if (!client_CA || !X509_STORE_add_cert(x509_store, client_CA)) { X509_STORE_free(x509_store); - lwsl_err("Unable to load SSL Client certs from ssl_ca_mem -- " - "client ssl isn't going to work\n"); + lwsl_err("Unable to load SSL Client certs from " + "ssl_ca_mem -- client ssl isn't going to " + "work\n"); lws_ssl_elaborate_error(); } else { /* it doesn't increment x509_store ref counter */ - SSL_CTX_set_cert_store(vh->tls.ssl_client_ctx, x509_store); + SSL_CTX_set_cert_store(vh->tls.ssl_client_ctx, + x509_store); lwsl_info("loaded ssl_ca_mem\n"); } if (client_CA) @@ -445,11 +469,13 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, /* support for client-side certificate authentication */ if (cert_filepath) { - if (lws_tls_use_any_upgrade_check_extant(cert_filepath) != LWS_TLS_EXTANT_YES && + if (lws_tls_use_any_upgrade_check_extant(cert_filepath) != + LWS_TLS_EXTANT_YES && (info->options & LWS_SERVER_OPTION_IGNORE_MISSING_CERT)) return 0; - lwsl_notice("%s: doing cert filepath %s\n", __func__, cert_filepath); + lwsl_notice("%s: doing cert filepath %s\n", __func__, + cert_filepath); n = SSL_CTX_use_certificate_chain_file(vh->tls.ssl_client_ctx, cert_filepath); if (n < 1) { @@ -483,4 +509,3 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, return 0; } - diff --git a/lib/tls/openssl/openssl-server.c b/lib/tls/openssl/openssl-server.c index 63083739a..95dd96ebb 100644 --- a/lib/tls/openssl/openssl-server.c +++ b/lib/tls/openssl/openssl-server.c @@ -1,7 +1,7 @@ /* * libwebsockets - OpenSSL-specific server functions * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010-2018 Andy Green * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -44,8 +44,8 @@ OpenSSL_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) */ wsi = SSL_get_ex_data(ssl, openssl_websocket_private_data_index); - n = lws_tls_openssl_cert_info(topcert, LWS_TLS_CERT_INFO_COMMON_NAME, &ir, - sizeof(ir.ns.name)); + n = lws_tls_openssl_cert_info(topcert, LWS_TLS_CERT_INFO_COMMON_NAME, + &ir, sizeof(ir.ns.name)); if (!n) lwsl_info("%s: client cert CN '%s'\n", __func__, ir.ns.name); else @@ -78,7 +78,8 @@ lws_tls_server_client_cert_verify_config(struct lws_vhost *vh) sizeof(void *)); /* absolutely require the client cert */ - SSL_CTX_set_verify(vh->tls.ssl_ctx, verify_options, OpenSSL_verify_callback); + SSL_CTX_set_verify(vh->tls.ssl_ctx, verify_options, + OpenSSL_verify_callback); return 0; } @@ -148,18 +149,18 @@ lws_tls_server_certs_load(struct lws_vhost *vhost, struct lws *wsi, { #if defined(LWS_HAVE_OPENSSL_ECDH_H) const char *ecdh_curve = "prime256v1"; +#if defined(LWS_HAVE_SSL_EXTRA_CHAIN_CERTS) + STACK_OF(X509) *extra_certs = NULL; +#endif EC_KEY *ecdh, *EC_key = NULL; EVP_PKEY *pkey; X509 *x = NULL; int ecdh_nid; int KeyType; -#if defined(LWS_HAVE_SSL_EXTRA_CHAIN_CERTS) - STACK_OF(X509) *extra_certs = NULL; -#endif #endif unsigned long error; - uint8_t *p; lws_filepos_t flen; + uint8_t *p; int n = lws_tls_generic_cert_checks(vhost, cert, private_key), m; @@ -207,11 +208,12 @@ lws_tls_server_certs_load(struct lws_vhost *vhost, struct lws *wsi, return 1; } #ifndef USE_WOLFSSL - if (SSL_CTX_use_PrivateKey_ASN1(EVP_PKEY_RSA, vhost->tls.ssl_ctx, - p, (long)(long long)flen) != 1) { + if (SSL_CTX_use_PrivateKey_ASN1(EVP_PKEY_RSA, + vhost->tls.ssl_ctx, p, + (long)(long long)flen) != 1) { #else - if (wolfSSL_CTX_use_PrivateKey_buffer(vhost->tls.ssl_ctx, - p, flen, WOLFSSL_FILETYPE_ASN1) != 1) { + if (wolfSSL_CTX_use_PrivateKey_buffer(vhost->tls.ssl_ctx, p, + flen, WOLFSSL_FILETYPE_ASN1) != 1) { #endif lwsl_notice("unable to use memory privkey\n"); @@ -245,8 +247,8 @@ lws_tls_server_certs_load(struct lws_vhost *vhost, struct lws *wsi, } } else { if (vhost->protocols[0].callback(wsi, - LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY, - vhost->tls.ssl_ctx, NULL, 0)) { + LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY, + vhost->tls.ssl_ctx, NULL, 0)) { lwsl_err("ssl private key not set\n"); return 1; @@ -363,10 +365,12 @@ lws_tls_server_vhost_backend_init(const struct lws_context_creation_info *info, return 1; } - SSL_CTX_set_ex_data(vhost->tls.ssl_ctx, openssl_SSL_CTX_private_data_index, + SSL_CTX_set_ex_data(vhost->tls.ssl_ctx, + openssl_SSL_CTX_private_data_index, (char *)vhost->context); /* Disable SSLv2 and SSLv3 */ - SSL_CTX_set_options(vhost->tls.ssl_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3); + SSL_CTX_set_options(vhost->tls.ssl_ctx, SSL_OP_NO_SSLv2 | + SSL_OP_NO_SSLv3); #ifdef SSL_OP_NO_COMPRESSION SSL_CTX_set_options(vhost->tls.ssl_ctx, SSL_OP_NO_COMPRESSION); #endif @@ -401,10 +405,12 @@ lws_tls_server_vhost_backend_init(const struct lws_context_creation_info *info, /* SSL_clear_options introduced in 0.9.8m */ #if (OPENSSL_VERSION_NUMBER >= 0x009080df) && !defined(USE_WOLFSSL) if (info->ssl_options_clear) - SSL_CTX_clear_options(vhost->tls.ssl_ctx, info->ssl_options_clear); + SSL_CTX_clear_options(vhost->tls.ssl_ctx, + info->ssl_options_clear); #endif - lwsl_info(" SSL options 0x%lX\n", (unsigned long)SSL_CTX_get_options(vhost->tls.ssl_ctx)); + lwsl_info(" SSL options 0x%lX\n", + (unsigned long)SSL_CTX_get_options(vhost->tls.ssl_ctx)); if (!vhost->tls.use_ssl || !info->ssl_cert_filepath) return 0; @@ -483,8 +489,8 @@ lws_tls_server_accept(struct lws *wsi) n = lws_tls_peer_cert_info(wsi, LWS_TLS_CERT_INFO_COMMON_NAME, &ir, sizeof(ir.ns.name)); if (!n) - lwsl_notice("%s: client cert CN '%s'\n", - __func__, ir.ns.name); + lwsl_notice("%s: client cert CN '%s'\n", __func__, + ir.ns.name); else lwsl_info("%s: no client cert CN\n", __func__); @@ -765,7 +771,8 @@ lws_tls_acme_sni_csr_create(struct lws_context *context, const char *elements[], for (n = 0; n < LWS_TLS_REQ_ELEMENT_COUNT; n++) if (lws_tls_openssl_add_nid(subj, nid_list[n], elements[n])) { - lwsl_notice("%s: failed to add element %d\n", __func__, n); + lwsl_notice("%s: failed to add element %d\n", __func__, + n); goto bail3; } @@ -837,7 +844,8 @@ lws_tls_acme_sni_csr_create(struct lws_context *context, const char *elements[], *privkey_pem = malloc(bio_len); /* malloc so user code can own / free */ *privkey_len = (size_t)bio_len; if (!*privkey_pem) { - lwsl_notice("%s: need %ld for private key\n", __func__, bio_len); + lwsl_notice("%s: need %ld for private key\n", __func__, + bio_len); BIO_free(bio); goto bail3; } diff --git a/lib/tls/openssl/ssl.c b/lib/tls/openssl/ssl.c index 8396bb34d..174524dbd 100644 --- a/lib/tls/openssl/ssl.c +++ b/lib/tls/openssl/ssl.c @@ -48,7 +48,8 @@ int lws_ssl_get_error(struct lws *wsi, int n) return 99; m = SSL_get_error(wsi->tls.ssl, n); - lwsl_debug("%s: %p %d -> %d (errno %d)\n", __func__, wsi->tls.ssl, n, m, errno); + lwsl_debug("%s: %p %d -> %d (errno %d)\n", __func__, wsi->tls.ssl, n, m, + errno); return m; } @@ -129,7 +130,8 @@ lws_ssl_bind_passphrase(SSL_CTX *ssl_ctx, * SSL_CTX_use_PrivateKey_file function */ SSL_CTX_set_default_passwd_cb_userdata(ssl_ctx, (void *)info); - SSL_CTX_set_default_passwd_cb(ssl_ctx, lws_context_init_ssl_pem_passwd_cb); + SSL_CTX_set_default_passwd_cb(ssl_ctx, + lws_context_init_ssl_pem_passwd_cb); } int @@ -149,7 +151,8 @@ lws_context_init_ssl_library(const struct lws_context_creation_info *info) #endif #endif if (!lws_check_opt(info->options, LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT)) { - lwsl_info(" SSL disabled: no LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT\n"); + lwsl_info(" SSL disabled: no " + "LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT\n"); return 0; } @@ -200,8 +203,9 @@ lws_ssl_destroy(struct lws_vhost *vhost) ERR_remove_thread_state(NULL); #endif #endif - // after 1.1.0 no need -#if (OPENSSL_VERSION_NUMBER >= 0x10002000) && (OPENSSL_VERSION_NUMBER <= 0x10100000) + /* not needed after 1.1.0 */ +#if (OPENSSL_VERSION_NUMBER >= 0x10002000) && \ + (OPENSSL_VERSION_NUMBER <= 0x10100000) SSL_COMP_free_compression_methods(); #endif ERR_free_strings(); @@ -233,8 +237,10 @@ lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) #if defined(LWS_WITH_STATS) if (!wsi->seen_rx && wsi->accept_start_us) { lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_MS_SSL_RX_DELAY, - lws_time_in_microseconds() - wsi->accept_start_us); - lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_SSL_CONNS_HAD_RX, 1); + lws_time_in_microseconds() - + wsi->accept_start_us); + lws_stats_atomic_bump(wsi->context, pt, + LWSSTATS_C_SSL_CONNS_HAD_RX, 1); wsi->seen_rx = 1; } #endif @@ -407,8 +413,8 @@ lws_ssl_info_callback(const SSL *ssl, int where, int ret) si.ret = ret; if (user_callback_handle_rxflow(wsi->protocol->callback, - wsi, LWS_CALLBACK_SSL_INFO, - wsi->user_space, &si, 0)) + wsi, LWS_CALLBACK_SSL_INFO, + wsi->user_space, &si, 0)) lws_set_timeout(wsi, PENDING_TIMEOUT_KILLED_BY_SSL_INFO, -1); } @@ -714,7 +720,8 @@ lws_tls_peer_cert_info(struct lws *wsi, enum lws_tls_cert_info type, switch (type) { case LWS_TLS_CERT_INFO_VERIFIED: - buf->verified = SSL_get_verify_result(wsi->tls.ssl) == X509_V_OK; + buf->verified = SSL_get_verify_result(wsi->tls.ssl) == + X509_V_OK; break; default: rc = lws_tls_openssl_cert_info(x509, type, buf, len); @@ -747,5 +754,4 @@ tops_periodic_housekeeping_openssl(struct lws_context *context, time_t now) const struct lws_tls_ops tls_ops_openssl = { /* fake_POLLIN_for_buffered */ tops_fake_POLLIN_for_buffered_openssl, /* periodic_housekeeping */ tops_periodic_housekeeping_openssl, - }; diff --git a/lib/tls/private.h b/lib/tls/private.h index da724bf16..ad01bfd4f 100644 --- a/lib/tls/private.h +++ b/lib/tls/private.h @@ -73,8 +73,9 @@ #endif /* not mbedtls */ #if defined(OPENSSL_VERSION_NUMBER) #if (OPENSSL_VERSION_NUMBER < 0x0009080afL) -/* later openssl defines this to negate the presence of tlsext... but it was only - * introduced at 0.9.8j. Earlier versions don't know it exists so don't +/* + * later openssl defines this to negate the presence of tlsext... but it was + * only introduced at 0.9.8j. Earlier versions don't know it exists so don't * define it... making it look like the feature exists... */ #define OPENSSL_NO_TLSEXT @@ -213,8 +214,8 @@ lws_tls_generic_cert_checks(struct lws_vhost *vhost, const char *cert, const char *private_key); LWS_EXTERN int lws_tls_alloc_pem_to_der_file(struct lws_context *context, const char *filename, - const char *inbuf, lws_filepos_t inlen, - uint8_t **buf, lws_filepos_t *amount); + const char *inbuf, lws_filepos_t inlen, + uint8_t **buf, lws_filepos_t *amount); #if !defined(LWS_NO_SERVER) LWS_EXTERN int diff --git a/lib/tls/tls-client.c b/lib/tls/tls-client.c index 881f7c429..f69c685fa 100644 --- a/lib/tls/tls-client.c +++ b/lib/tls/tls-client.c @@ -1,7 +1,7 @@ /* * libwebsockets - client-related ssl code independent of backend * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010-2018 Andy Green * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -89,10 +89,10 @@ lws_ssl_client_connect2(struct lws *wsi, char *errbuf, int len) int lws_context_init_client_ssl(const struct lws_context_creation_info *info, struct lws_vhost *vhost) { - const char *ca_filepath = info->ssl_ca_filepath; - const char *cipher_list = info->ssl_cipher_list; const char *private_key_filepath = info->ssl_private_key_filepath; const char *cert_filepath = info->ssl_cert_filepath; + const char *ca_filepath = info->ssl_ca_filepath; + const char *cipher_list = info->ssl_cipher_list; struct lws wsi; if (vhost->options & LWS_SERVER_OPTION_ONLY_RAW) @@ -147,7 +147,7 @@ int lws_context_init_client_ssl(const struct lws_context_creation_info *info, vhost->protocols[0].callback(&wsi, LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS, - vhost->tls.ssl_client_ctx, NULL, 0); + vhost->tls.ssl_client_ctx, NULL, 0); return 0; } diff --git a/lib/tls/tls-server.c b/lib/tls/tls-server.c index c227e653b..9d3f70dbe 100644 --- a/lib/tls/tls-server.c +++ b/lib/tls/tls-server.c @@ -56,7 +56,8 @@ lws_context_init_alpn(struct lws_vhost *vhost) vhost->tls.alpn_ctx.data, sizeof(vhost->tls.alpn_ctx.data) - 1); - SSL_CTX_set_alpn_select_cb(vhost->tls.ssl_ctx, alpn_cb, &vhost->tls.alpn_ctx); + SSL_CTX_set_alpn_select_cb(vhost->tls.ssl_ctx, alpn_cb, + &vhost->tls.alpn_ctx); #else lwsl_err( " HTTP2 / ALPN configured but not supported by OpenSSL 0x%lx\n", @@ -177,10 +178,10 @@ LWS_VISIBLE int lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd) { struct lws_context *context = wsi->context; - struct lws_vhost *vh; struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; - int n; + struct lws_vhost *vh; char buf[256]; + int n; (void)buf; @@ -318,7 +319,8 @@ lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd) #endif errno = 0; lws_stats_atomic_bump(wsi->context, pt, - LWSSTATS_C_SSL_CONNECTIONS_ACCEPT_SPIN, 1); + LWSSTATS_C_SSL_CONNECTIONS_ACCEPT_SPIN, + 1); n = lws_tls_server_accept(wsi); lws_latency(context, wsi, "SSL_accept LRS_SSL_ACK_PENDING\n", n, n == 1); @@ -328,7 +330,8 @@ lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd) break; case LWS_SSL_CAPABLE_ERROR: lws_stats_atomic_bump(wsi->context, pt, - LWSSTATS_C_SSL_CONNECTIONS_FAILED, 1); + LWSSTATS_C_SSL_CONNECTIONS_FAILED, + 1); lwsl_info("SSL_accept failed socket %u: %d\n", wsi->desc.sockfd, n); wsi->socket_is_permanently_unusable = 1; @@ -344,7 +347,8 @@ lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd) if (wsi->accept_start_us) lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_MS_SSL_CONNECTIONS_ACCEPTED_DELAY, - lws_time_in_microseconds() - wsi->accept_start_us); + lws_time_in_microseconds() - + wsi->accept_start_us); wsi->accept_start_us = lws_time_in_microseconds(); #endif diff --git a/lib/tls/tls.c b/lib/tls/tls.c index be08ba93e..a32951689 100644 --- a/lib/tls/tls.c +++ b/lib/tls/tls.c @@ -154,12 +154,12 @@ bail: int lws_tls_alloc_pem_to_der_file(struct lws_context *context, const char *filename, - const char *inbuf, lws_filepos_t inlen, - uint8_t **buf, lws_filepos_t *amount) + const char *inbuf, lws_filepos_t inlen, + uint8_t **buf, lws_filepos_t *amount) { const uint8_t *pem, *p, *end; - uint8_t *q; lws_filepos_t len; + uint8_t *q; int n; if (filename) { @@ -219,23 +219,25 @@ bail: int lws_tls_check_cert_lifetime(struct lws_vhost *v) { - union lws_tls_cert_info_results ir; time_t now = (time_t)lws_now_secs(), life = 0; struct lws_acme_cert_aging_args caa; + union lws_tls_cert_info_results ir; int n; if (v->tls.ssl_ctx && !v->tls.skipped_certs) { - if (now < 1464083026) /* May 2016 */ + if (now < 1542933698) /* Nov 23 2018 00:42 UTC */ /* our clock is wrong and we can't judge the certs */ return -1; - n = lws_tls_vhost_cert_info(v, LWS_TLS_CERT_INFO_VALIDITY_TO, &ir, 0); + n = lws_tls_vhost_cert_info(v, LWS_TLS_CERT_INFO_VALIDITY_TO, + &ir, 0); if (n) return 1; life = (ir.time - now) / (24 * 3600); - lwsl_notice(" vhost %s: cert expiry: %dd\n", v->name, (int)life); + lwsl_notice(" vhost %s: cert expiry: %dd\n", v->name, + (int)life); } else lwsl_notice(" vhost %s: no cert\n", v->name); diff --git a/lwsws/main.c b/lwsws/main.c index f74fdf2b9..d3962d8d5 100644 --- a/lwsws/main.c +++ b/lwsws/main.c @@ -256,7 +256,6 @@ int main(int argc, char **argv) if (n > 0) for (m = 0; m < (int)LWS_ARRAY_SIZE(pids); m++) if (!pids[m]) { - // fprintf(stderr, "added child pid %d\n", n); pids[m] = n; break; } @@ -268,7 +267,6 @@ int main(int argc, char **argv) if (n > 0) for (m = 0; m < (int)LWS_ARRAY_SIZE(pids); m++) if (pids[m] == n) { - // fprintf(stderr, "reaped child pid %d\n", pids[m]); pids[m] = 0; break; } @@ -279,12 +277,6 @@ int main(int argc, char **argv) #endif /* child process */ -#ifndef _WIN32 - /* we will only try to log things according to our debug_level */ -// setlogmask(LOG_UPTO (LOG_DEBUG)); -// openlog("lwsws", syslog_options, LOG_DAEMON); -#endif - lws_set_log_level(debug_level, lwsl_emit_stderr_notimestamp); lwsl_notice("lwsws libwebsockets web server - license CC0 + LGPL2.1\n"); diff --git a/plugins/protocol_lws_mirror.c b/plugins/protocol_lws_mirror.c index a567e3224..e083b3761 100644 --- a/plugins/protocol_lws_mirror.c +++ b/plugins/protocol_lws_mirror.c @@ -1,7 +1,7 @@ /* * libwebsockets-test-server - libwebsockets test implementation * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010-2018 Andy Green * * This file is made available under the Creative Commons CC0 1.0 * Universal Public Domain Dedication. @@ -196,10 +196,10 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason, (struct per_vhost_data__lws_mirror *) lws_protocol_vh_priv_get(lws_get_vhost(wsi), lws_get_protocol(wsi)); + char name[300], update_worst, sent_something, *pn = name; struct mirror_instance *mi = NULL; const struct a_message *msg; struct a_message amsg; - char name[300], update_worst, sent_something, *pn = name; uint32_t oldest_tail; int n, count_mi = 0; @@ -229,7 +229,6 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason, count_mi++; if (!strcmp(pn, mi1->name)) { /* yes... we will join it */ - // lwsl_notice("Joining existing mi %p '%s'\n", mi1, pn); mi = mi1; break; } @@ -239,7 +238,7 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason, /* no existing mirror instance for name */ if (count_mi == MAX_MIRROR_INSTANCES) { - lws_pthread_mutex_unlock(&v->lock); /* } vhost lock */ + lws_pthread_mutex_unlock(&v->lock); /* } vh lock */ return -1; } @@ -436,7 +435,8 @@ bail2: } if (pss->mi->rx_enabled && - lws_ring_get_count_free_elements(pss->mi->ring) < RXFLOW_MIN) + lws_ring_get_count_free_elements(pss->mi->ring) < + RXFLOW_MIN) __mirror_rxflow_instance(pss->mi, 0); req_writable: