2013-01-18 11:43:21 +08:00
|
|
|
/*
|
|
|
|
* libwebsockets - small server side websockets and web server implementation
|
|
|
|
*
|
2015-11-02 20:34:12 +08:00
|
|
|
* Copyright (C) 2010-2015 Andy Green <andy@warmcat.com>
|
2013-01-18 11:43:21 +08:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation:
|
|
|
|
* version 2.1 of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "private-libwebsockets.h"
|
|
|
|
|
2014-04-03 08:24:29 +08:00
|
|
|
int lws_context_init_server(struct lws_context_creation_info *info,
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws_context *context)
|
2014-04-03 08:24:29 +08:00
|
|
|
{
|
|
|
|
#ifdef LWS_USE_IPV6
|
|
|
|
struct sockaddr_in6 serv_addr6;
|
|
|
|
#endif
|
2015-12-06 08:00:03 +08:00
|
|
|
#if LWS_POSIX
|
2014-04-03 08:24:29 +08:00
|
|
|
struct sockaddr_in serv_addr4;
|
2015-12-06 08:00:03 +08:00
|
|
|
socklen_t len = sizeof(struct sockaddr);
|
|
|
|
struct sockaddr_in sin;
|
2014-04-03 08:24:29 +08:00
|
|
|
struct sockaddr *v;
|
2015-12-06 08:00:03 +08:00
|
|
|
int n, opt = 1;
|
2015-11-02 20:34:12 +08:00
|
|
|
#endif
|
2015-12-06 08:00:03 +08:00
|
|
|
lws_sockfd_type sockfd;
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws *wsi;
|
2014-04-03 08:24:29 +08:00
|
|
|
|
|
|
|
/* set up our external listening socket we serve on */
|
|
|
|
|
|
|
|
if (info->port == CONTEXT_PORT_NO_LISTEN)
|
|
|
|
return 0;
|
|
|
|
|
2015-11-02 20:34:12 +08:00
|
|
|
#if LWS_POSIX
|
2014-04-03 08:24:29 +08:00
|
|
|
#ifdef LWS_USE_IPV6
|
|
|
|
if (LWS_IPV6_ENABLED(context))
|
|
|
|
sockfd = socket(AF_INET6, SOCK_STREAM, 0);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2015-11-14 13:48:58 +08:00
|
|
|
if (sockfd == -1) {
|
2015-11-02 20:34:12 +08:00
|
|
|
#else
|
|
|
|
sockfd = mbed3_create_tcp_stream_socket();
|
|
|
|
if (!lws_sockfd_valid(sockfd)) {
|
|
|
|
#endif
|
2014-04-03 08:24:29 +08:00
|
|
|
lwsl_err("ERROR opening socket\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-11-02 20:34:12 +08:00
|
|
|
#if LWS_POSIX
|
2014-04-03 08:24:29 +08:00
|
|
|
/*
|
|
|
|
* allow us to restart even if old sockets in TIME_WAIT
|
|
|
|
*/
|
2014-11-30 13:07:11 +08:00
|
|
|
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
|
2015-12-06 08:00:03 +08:00
|
|
|
(const void *)&opt, sizeof(opt)) < 0) {
|
2014-11-30 13:30:57 +08:00
|
|
|
compatible_close(sockfd);
|
2014-11-30 13:07:11 +08:00
|
|
|
return 1;
|
2014-11-30 13:30:57 +08:00
|
|
|
}
|
2015-11-02 20:34:12 +08:00
|
|
|
#endif
|
2014-04-03 08:24:29 +08:00
|
|
|
lws_plat_set_socket_options(context, sockfd);
|
|
|
|
|
2015-11-02 20:34:12 +08:00
|
|
|
#if LWS_POSIX
|
2014-04-03 08:24:29 +08:00
|
|
|
#ifdef LWS_USE_IPV6
|
|
|
|
if (LWS_IPV6_ENABLED(context)) {
|
|
|
|
v = (struct sockaddr *)&serv_addr6;
|
|
|
|
n = sizeof(struct sockaddr_in6);
|
|
|
|
bzero((char *) &serv_addr6, sizeof(serv_addr6));
|
|
|
|
serv_addr6.sin6_addr = in6addr_any;
|
|
|
|
serv_addr6.sin6_family = AF_INET6;
|
|
|
|
serv_addr6.sin6_port = htons(info->port);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
v = (struct sockaddr *)&serv_addr4;
|
|
|
|
n = sizeof(serv_addr4);
|
|
|
|
bzero((char *) &serv_addr4, sizeof(serv_addr4));
|
|
|
|
serv_addr4.sin_addr.s_addr = INADDR_ANY;
|
|
|
|
serv_addr4.sin_family = AF_INET;
|
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
if (info->iface && interface_to_sa(context, info->iface,
|
2014-04-03 08:24:29 +08:00
|
|
|
(struct sockaddr_in *)v, n) < 0) {
|
2015-12-17 17:03:59 +08:00
|
|
|
lwsl_err("Unable to find interface %s\n", info->iface);
|
|
|
|
goto bail;
|
2014-04-03 08:24:29 +08:00
|
|
|
}
|
2014-04-27 12:32:15 +02:00
|
|
|
|
|
|
|
serv_addr4.sin_port = htons(info->port);
|
2014-04-03 08:24:29 +08:00
|
|
|
} /* ipv4 */
|
|
|
|
|
|
|
|
n = bind(sockfd, v, n);
|
|
|
|
if (n < 0) {
|
|
|
|
lwsl_err("ERROR on binding to port %d (%d %d)\n",
|
|
|
|
info->port, n, LWS_ERRNO);
|
2015-12-17 17:03:59 +08:00
|
|
|
goto bail;
|
2014-04-03 08:24:29 +08:00
|
|
|
}
|
2014-12-04 23:59:35 +01:00
|
|
|
|
2014-04-03 08:24:29 +08:00
|
|
|
if (getsockname(sockfd, (struct sockaddr *)&sin, &len) == -1)
|
|
|
|
lwsl_warn("getsockname: %s\n", strerror(LWS_ERRNO));
|
|
|
|
else
|
|
|
|
info->port = ntohs(sin.sin_port);
|
2015-11-02 20:34:12 +08:00
|
|
|
#endif
|
2014-04-03 08:24:29 +08:00
|
|
|
|
|
|
|
context->listen_port = info->port;
|
|
|
|
|
2015-12-04 11:08:32 +08:00
|
|
|
wsi = lws_zalloc(sizeof(struct lws));
|
2014-04-03 08:24:29 +08:00
|
|
|
if (wsi == NULL) {
|
|
|
|
lwsl_err("Out of mem\n");
|
2015-12-17 17:03:59 +08:00
|
|
|
goto bail;
|
2014-04-03 08:24:29 +08:00
|
|
|
}
|
2015-12-11 09:36:14 +08:00
|
|
|
wsi->context = context;
|
2014-04-03 08:24:29 +08:00
|
|
|
wsi->sock = sockfd;
|
2015-12-17 17:03:59 +08:00
|
|
|
wsi->mode = LWSCM_SERVER_LISTENER;
|
2015-11-02 20:34:12 +08:00
|
|
|
wsi->protocol = context->protocols;
|
2014-04-03 08:24:29 +08:00
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
if (insert_wsi_socket_into_fds(context, wsi))
|
|
|
|
goto bail;
|
2014-04-03 08:24:29 +08:00
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
context->lserv_mod = LWS_lserv_mod;
|
|
|
|
context->lserv_count = 0;
|
|
|
|
context->lserv_fd = sockfd;
|
2014-04-03 08:24:29 +08:00
|
|
|
|
2015-11-02 20:34:12 +08:00
|
|
|
#if LWS_POSIX
|
2014-04-03 08:24:29 +08:00
|
|
|
listen(sockfd, LWS_SOMAXCONN);
|
2015-11-02 20:34:12 +08:00
|
|
|
#else
|
|
|
|
mbed3_tcp_stream_bind(sockfd, info->port, wsi);
|
|
|
|
#endif
|
2014-04-03 08:24:29 +08:00
|
|
|
lwsl_notice(" Listening on port %d\n", info->port);
|
2014-12-04 23:59:35 +01:00
|
|
|
|
2014-04-03 08:24:29 +08:00
|
|
|
return 0;
|
2015-12-17 17:03:59 +08:00
|
|
|
|
|
|
|
bail:
|
|
|
|
compatible_close(sockfd);
|
|
|
|
|
|
|
|
return 1;
|
2014-04-03 08:24:29 +08:00
|
|
|
}
|
|
|
|
|
2014-04-03 08:40:05 +08:00
|
|
|
int
|
2015-12-04 11:08:32 +08:00
|
|
|
_lws_rx_flow_control(struct lws *wsi)
|
2014-04-03 08:40:05 +08:00
|
|
|
{
|
2016-01-20 09:23:24 +08:00
|
|
|
if (!wsi || wsi->context->being_destroyed)
|
|
|
|
return 0;
|
|
|
|
|
2014-04-03 08:40:05 +08:00
|
|
|
/* there is no pending change */
|
2014-10-08 12:00:53 +08:00
|
|
|
if (!(wsi->rxflow_change_to & LWS_RXFLOW_PENDING_CHANGE))
|
2014-04-03 08:40:05 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* stuff is still buffered, not ready to really accept new input */
|
2014-10-08 12:00:53 +08:00
|
|
|
if (wsi->rxflow_buffer) {
|
2014-04-03 08:40:05 +08:00
|
|
|
/* get ourselves called back to deal with stashed buffer */
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_callback_on_writable(wsi);
|
2014-04-03 08:40:05 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pending is cleared, we can change rxflow state */
|
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
wsi->rxflow_change_to &= ~LWS_RXFLOW_PENDING_CHANGE;
|
2014-04-03 08:40:05 +08:00
|
|
|
|
|
|
|
lwsl_info("rxflow: wsi %p change_to %d\n", wsi,
|
2014-10-08 12:00:53 +08:00
|
|
|
wsi->rxflow_change_to & LWS_RXFLOW_ALLOW);
|
2014-04-03 08:40:05 +08:00
|
|
|
|
|
|
|
/* adjust the pollfd for this wsi */
|
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
if (wsi->rxflow_change_to & LWS_RXFLOW_ALLOW) {
|
2014-04-11 13:14:37 +08:00
|
|
|
if (lws_change_pollfd(wsi, 0, LWS_POLLIN)) {
|
|
|
|
lwsl_info("%s: fail\n", __func__);
|
2014-04-03 08:40:05 +08:00
|
|
|
return -1;
|
2014-04-11 13:14:37 +08:00
|
|
|
}
|
2014-04-03 08:40:05 +08:00
|
|
|
} else
|
|
|
|
if (lws_change_pollfd(wsi, LWS_POLLIN, 0))
|
|
|
|
return -1;
|
|
|
|
|
2014-04-12 11:47:25 +08:00
|
|
|
return 0;
|
2014-04-03 08:40:05 +08:00
|
|
|
}
|
|
|
|
|
2015-12-15 21:15:58 +08:00
|
|
|
int lws_http_action(struct lws *wsi)
|
2014-04-03 09:03:37 +08:00
|
|
|
{
|
HTTP Version, Keep-alive support, No-copy POST
This is a squashed commit from https://github.com/andrew-canaday/libwebsockets,
dev/http_keepalive branch (strategies changed a few times, so the commit
history is clutteread). This branch is submitted for clarity, but the other
can be used as a reference or alternative.
* added **enum http_version** to track HTTP/1.0 vs HTTP/1.1 requests
* added **enum http_connection_type** to track keep-alive vs close
* replaced content_length_seen and body_index with **content_remain**
* removed **post_buffer** (see handshake.c modifications)
* removed post_buffer free
* switch state to WSI_TOKEN_SKIPPING after URI is complete to store version
* delete *spill* label (unused)
* add vars to track HTTP version and connection type
* HTTP version defaults to 1.0
* connection type defaults to 'close' for 1.0, keep-alive for 1.1
* additional checks in **cleanup:** label:
* if HTTP version string is present and valid, set enum val appropriately
* override connection default with the "Connection:" header, if present
* set state to WSI_STATE_HTTP_BODY if content_length > 0
* return 0 on HTTP requests, unless LWS_CALLBACK_HTTP indicates otherwise
* add vars to track remaining content_length and body chunk size
* re-arrange switch case order to facilitate creation of jump-table
* added new labels:
* **read_ok**: normal location reach on break from switch; just return 0
* **http_complete**: check for keep-alive + init state, mode, hdr table
* **http_new**: jump location for keep-alive when http_complete sees len>0
* after libwebsocket_parse, jump to one of those labels based on state
* POST body handling:
* don't bother iterating over input byte-by-byte or using memcpy
* just pass the relevant portion of the context->service_buffer to callback
2014-07-13 01:07:36 -04:00
|
|
|
enum http_connection_type connection_type;
|
2015-12-06 08:00:03 +08:00
|
|
|
enum http_version request_version;
|
2014-04-03 09:03:37 +08:00
|
|
|
char content_length_str[32];
|
2015-12-06 08:00:03 +08:00
|
|
|
unsigned int n, count = 0;
|
2014-10-08 12:00:53 +08:00
|
|
|
char http_version_str[10];
|
|
|
|
char http_conn_str[20];
|
2015-12-06 08:00:03 +08:00
|
|
|
int http_version_len;
|
|
|
|
char *uri_ptr = NULL;
|
|
|
|
int uri_len = 0;
|
|
|
|
|
2015-01-10 19:01:52 -08:00
|
|
|
static const unsigned char methods[] = {
|
|
|
|
WSI_TOKEN_GET_URI,
|
|
|
|
WSI_TOKEN_POST_URI,
|
|
|
|
WSI_TOKEN_OPTIONS_URI,
|
|
|
|
WSI_TOKEN_PUT_URI,
|
|
|
|
WSI_TOKEN_PATCH_URI,
|
|
|
|
WSI_TOKEN_DELETE_URI,
|
2014-10-12 08:38:16 +08:00
|
|
|
#ifdef LWS_USE_HTTP2
|
2015-01-10 19:01:52 -08:00
|
|
|
WSI_TOKEN_HTTP_COLON_PATH,
|
2014-10-12 08:38:16 +08:00
|
|
|
#endif
|
2015-01-10 19:01:52 -08:00
|
|
|
};
|
2015-02-20 07:37:20 +08:00
|
|
|
#ifdef _DEBUG
|
2015-01-10 19:01:52 -08:00
|
|
|
static const char * const method_names[] = {
|
|
|
|
"GET", "POST", "OPTIONS", "PUT", "PATCH", "DELETE",
|
|
|
|
#ifdef LWS_USE_HTTP2
|
|
|
|
":path",
|
|
|
|
#endif
|
|
|
|
};
|
2015-02-20 07:37:20 +08:00
|
|
|
#endif
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2015-01-10 19:01:52 -08:00
|
|
|
/* it's not websocket.... shall we accept it as http? */
|
|
|
|
|
|
|
|
for (n = 0; n < ARRAY_SIZE(methods); n++)
|
|
|
|
if (lws_hdr_total_length(wsi, methods[n]))
|
|
|
|
count++;
|
|
|
|
if (!count) {
|
2014-10-08 12:00:53 +08:00
|
|
|
lwsl_warn("Missing URI in HTTP request\n");
|
|
|
|
goto bail_nuke_ah;
|
|
|
|
}
|
|
|
|
|
2015-01-10 19:01:52 -08:00
|
|
|
if (count != 1) {
|
|
|
|
lwsl_warn("multiple methods?\n");
|
2014-10-08 12:00:53 +08:00
|
|
|
goto bail_nuke_ah;
|
|
|
|
}
|
|
|
|
|
2015-12-04 09:23:56 +08:00
|
|
|
if (lws_ensure_user_space(wsi))
|
2014-10-08 12:00:53 +08:00
|
|
|
goto bail_nuke_ah;
|
|
|
|
|
2015-01-10 19:01:52 -08:00
|
|
|
for (n = 0; n < ARRAY_SIZE(methods); n++)
|
|
|
|
if (lws_hdr_total_length(wsi, methods[n])) {
|
|
|
|
uri_ptr = lws_hdr_simple_ptr(wsi, methods[n]);
|
|
|
|
uri_len = lws_hdr_total_length(wsi, methods[n]);
|
|
|
|
lwsl_info("Method: %s request for '%s'\n",
|
|
|
|
method_names[n], uri_ptr);
|
|
|
|
break;
|
|
|
|
}
|
2014-10-08 12:00:53 +08:00
|
|
|
|
|
|
|
/* HTTP header had a content length? */
|
|
|
|
|
|
|
|
wsi->u.http.content_length = 0;
|
2015-01-10 19:01:52 -08:00
|
|
|
if (lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI) ||
|
|
|
|
lws_hdr_total_length(wsi, WSI_TOKEN_PATCH_URI) ||
|
|
|
|
lws_hdr_total_length(wsi, WSI_TOKEN_PUT_URI))
|
2014-10-08 12:00:53 +08:00
|
|
|
wsi->u.http.content_length = 100 * 1024 * 1024;
|
|
|
|
|
|
|
|
if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)) {
|
|
|
|
lws_hdr_copy(wsi, content_length_str,
|
2015-12-16 18:19:08 +08:00
|
|
|
sizeof(content_length_str) - 1,
|
|
|
|
WSI_TOKEN_HTTP_CONTENT_LENGTH);
|
2014-10-08 12:00:53 +08:00
|
|
|
wsi->u.http.content_length = atoi(content_length_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* http_version? Default to 1.0, override with token: */
|
|
|
|
request_version = HTTP_VERSION_1_0;
|
|
|
|
|
|
|
|
/* Works for single digit HTTP versions. : */
|
|
|
|
http_version_len = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP);
|
|
|
|
if (http_version_len > 7) {
|
|
|
|
lws_hdr_copy(wsi, http_version_str,
|
|
|
|
sizeof(http_version_str) - 1, WSI_TOKEN_HTTP);
|
|
|
|
if (http_version_str[5] == '1' && http_version_str[7] == '1')
|
|
|
|
request_version = HTTP_VERSION_1_1;
|
|
|
|
}
|
|
|
|
wsi->u.http.request_version = request_version;
|
|
|
|
|
|
|
|
/* HTTP/1.1 defaults to "keep-alive", 1.0 to "close" */
|
|
|
|
if (request_version == HTTP_VERSION_1_1)
|
|
|
|
connection_type = HTTP_CONNECTION_KEEP_ALIVE;
|
|
|
|
else
|
|
|
|
connection_type = HTTP_CONNECTION_CLOSE;
|
|
|
|
|
|
|
|
/* Override default if http "Connection:" header: */
|
|
|
|
if (lws_hdr_total_length(wsi, WSI_TOKEN_CONNECTION)) {
|
|
|
|
lws_hdr_copy(wsi, http_conn_str, sizeof(http_conn_str) - 1,
|
|
|
|
WSI_TOKEN_CONNECTION);
|
|
|
|
http_conn_str[sizeof(http_conn_str) - 1] = '\0';
|
|
|
|
if (!strcasecmp(http_conn_str, "keep-alive"))
|
|
|
|
connection_type = HTTP_CONNECTION_KEEP_ALIVE;
|
|
|
|
else
|
2015-10-20 12:12:12 +08:00
|
|
|
if (!strcasecmp(http_conn_str, "close"))
|
2014-10-08 12:00:53 +08:00
|
|
|
connection_type = HTTP_CONNECTION_CLOSE;
|
|
|
|
}
|
|
|
|
wsi->u.http.connection_type = connection_type;
|
|
|
|
|
2015-12-17 07:54:44 +08:00
|
|
|
n = wsi->protocol->callback(wsi, LWS_CALLBACK_FILTER_HTTP_CONNECTION,
|
2015-12-06 08:00:03 +08:00
|
|
|
wsi->user_space, uri_ptr, uri_len);
|
2014-10-08 12:00:53 +08:00
|
|
|
|
|
|
|
if (!n) {
|
|
|
|
/*
|
|
|
|
* if there is content supposed to be coming,
|
|
|
|
* put a timeout on it having arrived
|
|
|
|
*/
|
2015-12-04 08:43:54 +08:00
|
|
|
lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT,
|
2015-12-06 08:00:03 +08:00
|
|
|
AWAITING_TIMEOUT);
|
2014-10-08 12:00:53 +08:00
|
|
|
|
2015-12-17 07:54:44 +08:00
|
|
|
n = wsi->protocol->callback(wsi, LWS_CALLBACK_HTTP,
|
|
|
|
wsi->user_space, uri_ptr, uri_len);
|
2014-10-08 12:00:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* now drop the header info we kept a pointer to */
|
2015-12-17 17:03:59 +08:00
|
|
|
lws_free_set_NULL(wsi->u.http.ah);
|
2014-10-08 12:00:53 +08:00
|
|
|
|
|
|
|
if (n) {
|
|
|
|
lwsl_info("LWS_CALLBACK_HTTP closing\n");
|
|
|
|
return 1; /* struct ah ptr already nuked */ }
|
|
|
|
|
2015-12-14 08:52:03 +08:00
|
|
|
/*
|
2014-10-08 12:00:53 +08:00
|
|
|
* If we're not issuing a file, check for content_length or
|
|
|
|
* HTTP keep-alive. No keep-alive header allocation for
|
2015-12-14 08:52:03 +08:00
|
|
|
* ISSUING_FILE, as this uses HTTP/1.0.
|
|
|
|
*
|
2015-12-04 08:43:54 +08:00
|
|
|
* In any case, return 0 and let lws_read decide how to
|
2014-10-08 12:00:53 +08:00
|
|
|
* proceed based on state
|
|
|
|
*/
|
2015-12-17 17:03:59 +08:00
|
|
|
if (wsi->state != LWSS_HTTP_ISSUING_FILE)
|
2014-10-08 12:00:53 +08:00
|
|
|
/* Prepare to read body if we have a content length: */
|
|
|
|
if (wsi->u.http.content_length > 0)
|
2015-12-17 17:03:59 +08:00
|
|
|
wsi->state = LWSS_HTTP_BODY;
|
2014-10-08 12:00:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bail_nuke_ah:
|
|
|
|
/* drop the header info */
|
2015-12-17 17:03:59 +08:00
|
|
|
lws_free_set_NULL(wsi->u.hdr.ah);
|
2014-12-05 00:09:20 +01:00
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-16 18:19:08 +08:00
|
|
|
int lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len)
|
2014-10-08 12:00:53 +08:00
|
|
|
{
|
2015-12-17 18:25:25 +08:00
|
|
|
struct lws_context *context = lws_get_context(wsi);
|
2014-10-08 12:00:53 +08:00
|
|
|
struct allocated_headers *ah;
|
2015-12-06 08:00:03 +08:00
|
|
|
int protocol_len, n, hit;
|
2014-07-19 06:52:39 +08:00
|
|
|
char protocol_list[128];
|
|
|
|
char protocol_name[32];
|
|
|
|
char *p;
|
2014-04-03 09:03:37 +08:00
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
/* LWSCM_WS_SERVING */
|
2014-04-03 09:03:37 +08:00
|
|
|
|
|
|
|
while (len--) {
|
2016-01-21 11:10:26 +08:00
|
|
|
|
|
|
|
assert(wsi->mode == LWSCM_HTTP_SERVING);
|
|
|
|
|
2015-12-15 21:15:58 +08:00
|
|
|
if (lws_parse(wsi, *(*buf)++)) {
|
2015-12-04 09:23:56 +08:00
|
|
|
lwsl_info("lws_parse failed\n");
|
2014-04-03 09:03:37 +08:00
|
|
|
goto bail_nuke_ah;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wsi->u.hdr.parser_state != WSI_PARSING_COMPLETE)
|
|
|
|
continue;
|
|
|
|
|
2015-12-04 09:23:56 +08:00
|
|
|
lwsl_parser("lws_parse sees parsing complete\n");
|
2014-04-03 09:03:37 +08:00
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
wsi->mode = LWSCM_PRE_WS_SERVING_ACCEPT;
|
2015-12-04 08:43:54 +08:00
|
|
|
lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
|
2014-04-03 09:03:37 +08:00
|
|
|
|
|
|
|
/* is this websocket protocol or normal http 1.0? */
|
|
|
|
|
2016-01-21 11:10:26 +08:00
|
|
|
if (lws_hdr_total_length(wsi, WSI_TOKEN_UPGRADE)) {
|
|
|
|
if (!strcasecmp(lws_hdr_simple_ptr(wsi, WSI_TOKEN_UPGRADE),
|
|
|
|
"websocket")) {
|
|
|
|
lwsl_info("Upgrade to ws\n");
|
|
|
|
goto upgrade_ws;
|
|
|
|
}
|
|
|
|
#ifdef LWS_USE_HTTP2
|
|
|
|
if (!strcasecmp(lws_hdr_simple_ptr(wsi, WSI_TOKEN_UPGRADE),
|
|
|
|
"h2c-14")) {
|
|
|
|
lwsl_info("Upgrade to h2c-14\n");
|
|
|
|
goto upgrade_h2c;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
lwsl_err("Unknown upgrade\n");
|
|
|
|
/* dunno what he wanted to upgrade to */
|
|
|
|
goto bail_nuke_ah;
|
|
|
|
}
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2016-01-21 11:10:26 +08:00
|
|
|
/* no upgrade ack... he remained as HTTP */
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2016-01-21 11:10:26 +08:00
|
|
|
lwsl_info("No upgrade\n");
|
|
|
|
ah = wsi->u.hdr.ah;
|
2014-04-03 09:03:37 +08:00
|
|
|
|
2016-01-21 11:10:26 +08:00
|
|
|
lws_union_transition(wsi, LWSCM_HTTP_SERVING_ACCEPTED);
|
|
|
|
wsi->state = LWSS_HTTP;
|
|
|
|
wsi->u.http.fd = LWS_INVALID_FILE;
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2016-01-21 11:10:26 +08:00
|
|
|
/* expose it at the same offset as u.hdr */
|
|
|
|
wsi->u.http.ah = ah;
|
|
|
|
lwsl_debug("%s: wsi %p: ah %p\n", __func__, (void *)wsi, (void *)wsi->u.hdr.ah);
|
2014-04-03 09:03:37 +08:00
|
|
|
|
2016-01-21 11:10:26 +08:00
|
|
|
n = lws_http_action(wsi);
|
2014-04-03 09:03:37 +08:00
|
|
|
|
2016-01-21 11:10:26 +08:00
|
|
|
return n;
|
2014-09-30 09:43:14 +08:00
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
#ifdef LWS_USE_HTTP2
|
|
|
|
upgrade_h2c:
|
|
|
|
if (!lws_hdr_total_length(wsi, WSI_TOKEN_HTTP2_SETTINGS)) {
|
|
|
|
lwsl_err("missing http2_settings\n");
|
2014-09-30 09:43:14 +08:00
|
|
|
goto bail_nuke_ah;
|
|
|
|
}
|
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
lwsl_err("h2c upgrade...\n");
|
2014-09-30 09:43:14 +08:00
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP2_SETTINGS);
|
|
|
|
/* convert the peer's HTTP-Settings */
|
2015-12-06 08:00:03 +08:00
|
|
|
n = lws_b64_decode_string(p, protocol_list,
|
|
|
|
sizeof(protocol_list));
|
2014-10-08 12:00:53 +08:00
|
|
|
if (n < 0) {
|
|
|
|
lwsl_parser("HTTP2_SETTINGS too long\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* adopt the header info */
|
|
|
|
|
|
|
|
ah = wsi->u.hdr.ah;
|
2014-09-30 09:43:14 +08:00
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
lws_union_transition(wsi, LWSCM_HTTP2_SERVING);
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
/* http2 union member has http union struct at start */
|
|
|
|
wsi->u.http.ah = ah;
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
lws_http2_init(&wsi->u.http2.peer_settings);
|
|
|
|
lws_http2_init(&wsi->u.http2.my_settings);
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
/* HTTP2 union */
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2015-12-06 08:00:03 +08:00
|
|
|
lws_http2_interpret_settings_payload(&wsi->u.http2.peer_settings,
|
|
|
|
(unsigned char *)protocol_list, n);
|
2014-10-08 12:00:53 +08:00
|
|
|
|
|
|
|
strcpy(protocol_list,
|
|
|
|
"HTTP/1.1 101 Switching Protocols\x0d\x0a"
|
|
|
|
"Connection: Upgrade\x0d\x0a"
|
|
|
|
"Upgrade: h2c\x0d\x0a\x0d\x0a");
|
2014-10-29 09:39:08 +08:00
|
|
|
n = lws_issue_raw(wsi, (unsigned char *)protocol_list,
|
|
|
|
strlen(protocol_list));
|
|
|
|
if (n != strlen(protocol_list)) {
|
2014-10-08 12:00:53 +08:00
|
|
|
lwsl_debug("http2 switch: ERROR writing to socket\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
wsi->state = LWSS_HTTP2_AWAIT_CLIENT_PREFACE;
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-09-30 09:43:14 +08:00
|
|
|
return 0;
|
2014-10-08 12:00:53 +08:00
|
|
|
#endif
|
2014-09-30 09:43:14 +08:00
|
|
|
|
2014-09-30 08:15:49 +08:00
|
|
|
upgrade_ws:
|
2014-04-03 09:03:37 +08:00
|
|
|
if (!wsi->protocol)
|
2015-12-04 08:43:54 +08:00
|
|
|
lwsl_err("NULL protocol at lws_read\n");
|
2014-04-03 09:03:37 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* It's websocket
|
|
|
|
*
|
2014-07-19 06:52:39 +08:00
|
|
|
* Select the first protocol we support from the list
|
|
|
|
* the client sent us.
|
|
|
|
*
|
|
|
|
* Copy it to remove header fragmentation
|
2014-04-03 09:03:37 +08:00
|
|
|
*/
|
|
|
|
|
2014-07-19 06:52:39 +08:00
|
|
|
if (lws_hdr_copy(wsi, protocol_list, sizeof(protocol_list) - 1,
|
|
|
|
WSI_TOKEN_PROTOCOL) < 0) {
|
|
|
|
lwsl_err("protocol list too long");
|
|
|
|
goto bail_nuke_ah;
|
|
|
|
}
|
2014-04-03 09:03:37 +08:00
|
|
|
|
2014-07-19 06:52:39 +08:00
|
|
|
protocol_len = lws_hdr_total_length(wsi, WSI_TOKEN_PROTOCOL);
|
|
|
|
protocol_list[protocol_len] = '\0';
|
|
|
|
p = protocol_list;
|
|
|
|
hit = 0;
|
|
|
|
|
|
|
|
while (*p && !hit) {
|
2015-11-02 13:10:33 +08:00
|
|
|
unsigned int n = 0;
|
2014-07-19 06:52:39 +08:00
|
|
|
while (n < sizeof(protocol_name) - 1 && *p && *p !=',')
|
|
|
|
protocol_name[n++] = *p++;
|
|
|
|
protocol_name[n] = '\0';
|
|
|
|
if (*p)
|
|
|
|
p++;
|
|
|
|
|
|
|
|
lwsl_info("checking %s\n", protocol_name);
|
|
|
|
|
|
|
|
n = 0;
|
2014-11-30 12:45:39 +08:00
|
|
|
while (wsi->protocol && context->protocols[n].callback) {
|
2014-08-11 09:11:57 +08:00
|
|
|
if (!wsi->protocol->name) {
|
|
|
|
n++;
|
2014-07-19 06:52:39 +08:00
|
|
|
continue;
|
2014-08-11 09:11:57 +08:00
|
|
|
}
|
2014-07-19 06:52:39 +08:00
|
|
|
if (!strcmp(context->protocols[n].name,
|
|
|
|
protocol_name)) {
|
|
|
|
lwsl_info("prot match %d\n", n);
|
|
|
|
wsi->protocol = &context->protocols[n];
|
|
|
|
hit = 1;
|
2014-04-03 09:03:37 +08:00
|
|
|
break;
|
2014-07-19 06:52:39 +08:00
|
|
|
}
|
2014-04-03 09:03:37 +08:00
|
|
|
|
2014-07-19 06:52:39 +08:00
|
|
|
n++;
|
|
|
|
}
|
2014-04-03 09:03:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we didn't find a protocol he wanted? */
|
|
|
|
|
2014-07-19 06:52:39 +08:00
|
|
|
if (!hit) {
|
2015-12-17 17:03:59 +08:00
|
|
|
if (!lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL)) {
|
2014-07-19 06:52:39 +08:00
|
|
|
/*
|
|
|
|
* some clients only have one protocol and
|
|
|
|
* do not sent the protocol list header...
|
|
|
|
* allow it and match to protocol 0
|
|
|
|
*/
|
|
|
|
lwsl_info("defaulting to prot 0 handler\n");
|
2014-04-03 09:03:37 +08:00
|
|
|
wsi->protocol = &context->protocols[0];
|
|
|
|
} else {
|
2014-07-19 06:52:39 +08:00
|
|
|
lwsl_err("No protocol from list \"%s\" supported\n",
|
|
|
|
protocol_list);
|
2014-04-03 09:03:37 +08:00
|
|
|
goto bail_nuke_ah;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate wsi->user storage */
|
2015-12-04 09:23:56 +08:00
|
|
|
if (lws_ensure_user_space(wsi))
|
2014-04-03 09:03:37 +08:00
|
|
|
goto bail_nuke_ah;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Give the user code a chance to study the request and
|
|
|
|
* have the opportunity to deny it
|
|
|
|
*/
|
|
|
|
|
2015-12-17 07:54:44 +08:00
|
|
|
if ((wsi->protocol->callback)(wsi,
|
2014-04-03 09:03:37 +08:00
|
|
|
LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION,
|
|
|
|
wsi->user_space,
|
|
|
|
lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL), 0)) {
|
|
|
|
lwsl_warn("User code denied connection\n");
|
|
|
|
goto bail_nuke_ah;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform the handshake according to the protocol version the
|
|
|
|
* client announced
|
|
|
|
*/
|
|
|
|
|
|
|
|
switch (wsi->ietf_spec_revision) {
|
|
|
|
case 13:
|
|
|
|
lwsl_parser("lws_parse calling handshake_04\n");
|
|
|
|
if (handshake_0405(context, wsi)) {
|
|
|
|
lwsl_info("hs0405 has failed the connection\n");
|
|
|
|
goto bail_nuke_ah;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
lwsl_warn("Unknown client spec version %d\n",
|
|
|
|
wsi->ietf_spec_revision);
|
|
|
|
goto bail_nuke_ah;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* drop the header info -- no bail_nuke_ah after this */
|
2014-11-07 11:21:09 +08:00
|
|
|
lws_free_header_table(wsi);
|
2014-04-03 09:03:37 +08:00
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
lws_union_transition(wsi, LWSCM_WS_SERVING);
|
2014-04-03 09:03:37 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* create the frame buffer for this connection according to the
|
|
|
|
* size mentioned in the protocol definition. If 0 there, use
|
|
|
|
* a big default for compatibility
|
|
|
|
*/
|
|
|
|
|
|
|
|
n = wsi->protocol->rx_buffer_size;
|
|
|
|
if (!n)
|
|
|
|
n = LWS_MAX_SOCKET_IO_BUF;
|
|
|
|
n += LWS_SEND_BUFFER_PRE_PADDING + LWS_SEND_BUFFER_POST_PADDING;
|
2014-12-04 23:59:35 +01:00
|
|
|
wsi->u.ws.rx_user_buffer = lws_malloc(n);
|
2014-04-03 09:03:37 +08:00
|
|
|
if (!wsi->u.ws.rx_user_buffer) {
|
|
|
|
lwsl_err("Out of Mem allocating rx buffer %d\n", n);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-01-20 09:19:17 +08:00
|
|
|
wsi->u.ws.rx_ubuf_alloc = n;
|
2014-04-03 09:03:37 +08:00
|
|
|
lwsl_info("Allocating RX buffer %d\n", n);
|
2015-11-02 20:34:12 +08:00
|
|
|
#if LWS_POSIX
|
2015-12-06 08:00:03 +08:00
|
|
|
if (setsockopt(wsi->sock, SOL_SOCKET, SO_SNDBUF,
|
|
|
|
(const char *)&n, sizeof n)) {
|
2014-04-03 09:03:37 +08:00
|
|
|
lwsl_warn("Failed to set SNDBUF to %d", n);
|
|
|
|
return 1;
|
|
|
|
}
|
2015-11-02 20:34:12 +08:00
|
|
|
#endif
|
2016-01-21 11:10:26 +08:00
|
|
|
lwsl_parser("accepted v%02d connection\n", wsi->ietf_spec_revision);
|
|
|
|
|
|
|
|
return 0;
|
2014-04-03 09:03:37 +08:00
|
|
|
} /* while all chars are handled */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bail_nuke_ah:
|
|
|
|
/* drop the header info */
|
2014-11-07 11:21:09 +08:00
|
|
|
lws_free_header_table(wsi);
|
2014-04-03 09:03:37 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws *
|
|
|
|
lws_create_new_server_wsi(struct lws_context *context)
|
2013-01-18 11:43:21 +08:00
|
|
|
{
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws *new_wsi;
|
2013-01-18 11:43:21 +08:00
|
|
|
|
2015-12-04 11:08:32 +08:00
|
|
|
new_wsi = lws_zalloc(sizeof(struct lws));
|
2013-01-18 11:43:21 +08:00
|
|
|
if (new_wsi == NULL) {
|
|
|
|
lwsl_err("Out of memory for new connection\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-12-11 09:36:14 +08:00
|
|
|
new_wsi->context = context;
|
2013-01-18 11:43:21 +08:00
|
|
|
new_wsi->pending_timeout = NO_PENDING_TIMEOUT;
|
2014-10-08 12:00:53 +08:00
|
|
|
new_wsi->rxflow_change_to = LWS_RXFLOW_ALLOW;
|
2013-01-18 11:43:21 +08:00
|
|
|
|
|
|
|
/* intialize the instance struct */
|
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
new_wsi->state = LWSS_HTTP;
|
|
|
|
new_wsi->mode = LWSCM_HTTP_SERVING;
|
2013-02-11 21:43:41 +08:00
|
|
|
new_wsi->hdr_parsing_completed = 0;
|
2013-01-18 11:43:21 +08:00
|
|
|
|
2015-03-28 10:20:50 +08:00
|
|
|
#ifdef LWS_OPENSSL_SUPPORT
|
|
|
|
new_wsi->use_ssl = LWS_SSL_ENABLED(context);
|
|
|
|
#endif
|
|
|
|
|
replace per header mallocs with single malloc 3 level struct
This big patch replaces the malloc / realloc per header
approach used until now with a single three-level struct
that gets malloc'd during the header union phase and freed
in one go when we transition to a different union phase.
It's more expensive in that we malloc a bit more than 4Kbytes,
but it's a lot cheaper in terms of malloc, frees, heap fragmentation,
no reallocs, nothing to configure. It also moves from arrays of
pointers (8 bytes on x86_64) to unsigned short offsets into the
data array, (2 bytes on all platforms).
The 3-level thing is all in one struct
- array indexed by the header enum, pointing to first "fragment" index
(ie, header type to fragment lookup, or 0 for none)
- array of fragments indexes, enough for 2 x the number of known headers
(fragment array... note that fragments can point to a "next"
fragment if the same header is spread across multiple entries)
- linear char array where the known header payload gets written
(fragments point into null-terminated strings stored in here,
only the known header content is stored)
http headers can legally be split over multiple headers of the same
name which should be concatenated. This scheme does not linearly
conatenate them but uses a linked list in the fragment structs to
link them. There are apis to get the total length and copy out a
linear, concatenated version to a buffer.
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-10 18:02:31 +08:00
|
|
|
if (lws_allocate_header_table(new_wsi)) {
|
2014-12-04 23:59:35 +01:00
|
|
|
lws_free(new_wsi);
|
replace per header mallocs with single malloc 3 level struct
This big patch replaces the malloc / realloc per header
approach used until now with a single three-level struct
that gets malloc'd during the header union phase and freed
in one go when we transition to a different union phase.
It's more expensive in that we malloc a bit more than 4Kbytes,
but it's a lot cheaper in terms of malloc, frees, heap fragmentation,
no reallocs, nothing to configure. It also moves from arrays of
pointers (8 bytes on x86_64) to unsigned short offsets into the
data array, (2 bytes on all platforms).
The 3-level thing is all in one struct
- array indexed by the header enum, pointing to first "fragment" index
(ie, header type to fragment lookup, or 0 for none)
- array of fragments indexes, enough for 2 x the number of known headers
(fragment array... note that fragments can point to a "next"
fragment if the same header is spread across multiple entries)
- linear char array where the known header payload gets written
(fragments point into null-terminated strings stored in here,
only the known header content is stored)
http headers can legally be split over multiple headers of the same
name which should be concatenated. This scheme does not linearly
conatenate them but uses a linked list in the fragment structs to
link them. There are apis to get the total length and copy out a
linear, concatenated version to a buffer.
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-10 18:02:31 +08:00
|
|
|
return NULL;
|
2013-01-18 11:43:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* these can only be set once the protocol is known
|
|
|
|
* we set an unestablished connection's protocol pointer
|
|
|
|
* to the start of the supported list, so it can look
|
|
|
|
* for matching ones during the handshake
|
|
|
|
*/
|
|
|
|
new_wsi->protocol = context->protocols;
|
|
|
|
new_wsi->user_space = NULL;
|
|
|
|
new_wsi->ietf_spec_revision = 0;
|
2015-11-14 07:35:27 +08:00
|
|
|
new_wsi->sock = LWS_SOCK_INVALID;
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-02-15 19:25:50 +08:00
|
|
|
/*
|
|
|
|
* outermost create notification for wsi
|
|
|
|
* no user_space because no protocol selection
|
|
|
|
*/
|
2015-12-17 07:54:44 +08:00
|
|
|
context->protocols[0].callback(new_wsi, LWS_CALLBACK_WSI_CREATE, NULL,
|
|
|
|
NULL, 0);
|
2014-02-15 19:25:50 +08:00
|
|
|
|
2013-01-18 11:43:21 +08:00
|
|
|
return new_wsi;
|
|
|
|
}
|
|
|
|
|
2014-10-17 08:38:44 +08:00
|
|
|
/**
|
|
|
|
* lws_http_transaction_completed() - wait for new http transaction or close
|
|
|
|
* @wsi: websocket connection
|
|
|
|
*
|
|
|
|
* Returns 1 if the HTTP connection must close now
|
|
|
|
* Returns 0 and resets connection to wait for new HTTP header /
|
|
|
|
* transaction if possible
|
|
|
|
*/
|
|
|
|
|
|
|
|
LWS_VISIBLE
|
2015-12-04 11:08:32 +08:00
|
|
|
int lws_http_transaction_completed(struct lws *wsi)
|
2014-10-17 08:38:44 +08:00
|
|
|
{
|
|
|
|
/* if we can't go back to accept new headers, drop the connection */
|
|
|
|
if (wsi->u.http.connection_type != HTTP_CONNECTION_KEEP_ALIVE) {
|
|
|
|
lwsl_info("%s: close connection\n", __func__);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* otherwise set ourselves up ready to go again */
|
2015-12-17 17:03:59 +08:00
|
|
|
wsi->state = LWSS_HTTP;
|
|
|
|
wsi->mode = LWSCM_HTTP_SERVING;
|
2015-10-21 08:16:34 +08:00
|
|
|
wsi->u.http.content_length = 0;
|
|
|
|
|
|
|
|
/* He asked for it to stay alive indefinitely */
|
2015-12-04 08:43:54 +08:00
|
|
|
lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
|
2015-10-21 08:16:34 +08:00
|
|
|
|
|
|
|
if (lws_allocate_header_table(wsi))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* If we're (re)starting on headers, need other implied init */
|
|
|
|
wsi->u.hdr.ues = URIES_IDLE;
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2015-10-21 08:16:34 +08:00
|
|
|
lwsl_info("%s: keep-alive await new transaction\n", __func__);
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-17 08:38:44 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-02 20:34:12 +08:00
|
|
|
LWS_VISIBLE
|
2015-12-04 11:08:32 +08:00
|
|
|
int lws_server_socket_service(struct lws_context *context,
|
2015-12-04 11:30:53 +08:00
|
|
|
struct lws *wsi, struct lws_pollfd *pollfd)
|
2013-01-18 11:43:21 +08:00
|
|
|
{
|
2015-11-02 20:34:12 +08:00
|
|
|
lws_sockfd_type accept_fd = LWS_SOCK_INVALID;
|
|
|
|
#if LWS_POSIX
|
2013-01-18 11:43:21 +08:00
|
|
|
struct sockaddr_in cli_addr;
|
2015-12-06 06:39:51 +08:00
|
|
|
socklen_t clilen;
|
2015-11-02 20:34:12 +08:00
|
|
|
#endif
|
2015-12-06 06:39:51 +08:00
|
|
|
struct lws *new_wsi = NULL;
|
|
|
|
int n, len;
|
2013-01-18 11:43:21 +08:00
|
|
|
|
|
|
|
switch (wsi->mode) {
|
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
case LWSCM_HTTP_SERVING:
|
|
|
|
case LWSCM_HTTP_SERVING_ACCEPTED:
|
|
|
|
case LWSCM_HTTP2_SERVING:
|
2013-01-18 11:43:21 +08:00
|
|
|
|
|
|
|
/* handle http headers coming in */
|
|
|
|
|
2013-12-09 14:16:17 +08:00
|
|
|
/* pending truncated sends have uber priority */
|
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
if (wsi->trunc_len) {
|
|
|
|
if (!(pollfd->revents & LWS_POLLOUT))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (lws_issue_raw(wsi, wsi->trunc_alloc + wsi->trunc_offset,
|
|
|
|
wsi->trunc_len) < 0)
|
|
|
|
goto fail;
|
2013-12-09 14:16:17 +08:00
|
|
|
/*
|
|
|
|
* we can't afford to allow input processing send
|
|
|
|
* something new, so spin around he event loop until
|
|
|
|
* he doesn't have any partials
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-18 11:43:21 +08:00
|
|
|
/* any incoming data ready? */
|
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
if (!(pollfd->revents & LWS_POLLIN))
|
|
|
|
goto try_pollout;
|
|
|
|
|
|
|
|
len = lws_ssl_capable_read(wsi, context->serv_buf,
|
|
|
|
sizeof(context->serv_buf));
|
|
|
|
lwsl_debug("%s: read %d\r\n", __func__, len);
|
|
|
|
switch (len) {
|
|
|
|
case 0:
|
|
|
|
lwsl_info("lws_server_skt_srv: read 0 len\n");
|
|
|
|
/* lwsl_info(" state=%d\n", wsi->state); */
|
|
|
|
if (!wsi->hdr_parsing_completed)
|
|
|
|
lws_free_header_table(wsi);
|
|
|
|
/* fallthru */
|
|
|
|
case LWS_SSL_CAPABLE_ERROR:
|
|
|
|
goto fail;
|
|
|
|
case LWS_SSL_CAPABLE_MORE_SERVICE:
|
|
|
|
goto try_pollout;
|
|
|
|
}
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
/* just ignore incoming if waiting for close */
|
|
|
|
if (wsi->state != LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE) {
|
|
|
|
/*
|
|
|
|
* hm this may want to send
|
|
|
|
* (via HTTP callback for example)
|
|
|
|
*/
|
|
|
|
n = lws_read(wsi, context->serv_buf, len);
|
|
|
|
if (n < 0) /* we closed wsi */
|
|
|
|
return 1;
|
2013-12-09 14:16:17 +08:00
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
/* hum he may have used up the
|
|
|
|
* writability above */
|
|
|
|
break;
|
2013-01-18 11:43:21 +08:00
|
|
|
}
|
|
|
|
|
2014-10-09 08:37:12 +08:00
|
|
|
try_pollout:
|
2013-01-18 11:43:21 +08:00
|
|
|
/* this handles POLLOUT for http serving fragments */
|
|
|
|
|
2014-03-30 09:18:05 +02:00
|
|
|
if (!(pollfd->revents & LWS_POLLOUT))
|
2013-01-18 11:43:21 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* one shot */
|
2014-04-02 14:25:10 +08:00
|
|
|
if (lws_change_pollfd(wsi, LWS_POLLOUT, 0))
|
|
|
|
goto fail;
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_libev_io(wsi, LWS_EV_STOP | LWS_EV_WRITE);
|
2013-12-18 09:48:26 +08:00
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
if (wsi->state != LWSS_HTTP_ISSUING_FILE) {
|
2013-02-14 22:23:54 +08:00
|
|
|
n = user_callback_handle_rxflow(
|
|
|
|
wsi->protocol->callback,
|
|
|
|
wsi, LWS_CALLBACK_HTTP_WRITEABLE,
|
2015-12-17 07:54:44 +08:00
|
|
|
wsi->user_space, NULL, 0);
|
2013-02-14 22:23:54 +08:00
|
|
|
if (n < 0)
|
2014-11-30 13:35:24 +08:00
|
|
|
goto fail;
|
2013-01-18 11:43:21 +08:00
|
|
|
break;
|
2013-02-14 22:23:54 +08:00
|
|
|
}
|
2013-01-18 11:43:21 +08:00
|
|
|
|
2014-10-17 08:38:44 +08:00
|
|
|
/* >0 == completion, <0 == error */
|
2015-12-16 18:19:08 +08:00
|
|
|
n = lws_serve_http_file_fragment(wsi);
|
2014-10-17 08:38:44 +08:00
|
|
|
if (n < 0 || (n > 0 && lws_http_transaction_completed(wsi)))
|
2014-11-30 13:35:24 +08:00
|
|
|
goto fail;
|
2013-01-18 11:43:21 +08:00
|
|
|
break;
|
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
case LWSCM_SERVER_LISTENER:
|
2013-01-18 11:43:21 +08:00
|
|
|
|
2015-11-02 20:34:12 +08:00
|
|
|
#if LWS_POSIX
|
2013-01-18 11:43:21 +08:00
|
|
|
/* pollin means a client has connected to us then */
|
|
|
|
|
2014-03-30 09:18:05 +02:00
|
|
|
if (!(pollfd->revents & LWS_POLLIN))
|
2013-01-18 11:43:21 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* listen socket got an unencrypted connection... */
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2013-01-18 11:43:21 +08:00
|
|
|
clilen = sizeof(cli_addr);
|
2013-01-29 12:37:35 +08:00
|
|
|
lws_latency_pre(context, wsi);
|
2013-01-18 11:43:21 +08:00
|
|
|
accept_fd = accept(pollfd->fd, (struct sockaddr *)&cli_addr,
|
2015-12-06 08:00:03 +08:00
|
|
|
&clilen);
|
2013-02-11 17:13:32 +08:00
|
|
|
lws_latency(context, wsi,
|
2015-12-17 17:03:59 +08:00
|
|
|
"unencrypted accept LWSCM_SERVER_LISTENER",
|
2013-02-11 17:13:32 +08:00
|
|
|
accept_fd, accept_fd >= 0);
|
2013-01-18 11:43:21 +08:00
|
|
|
if (accept_fd < 0) {
|
2015-12-06 08:00:03 +08:00
|
|
|
if (LWS_ERRNO == LWS_EAGAIN ||
|
|
|
|
LWS_ERRNO == LWS_EWOULDBLOCK) {
|
2013-01-28 12:19:10 +08:00
|
|
|
lwsl_debug("accept asks to try again\n");
|
|
|
|
break;
|
|
|
|
}
|
2014-02-28 12:37:52 +01:00
|
|
|
lwsl_warn("ERROR on accept: %s\n", strerror(LWS_ERRNO));
|
2013-01-18 11:43:21 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
lws_plat_set_socket_options(context, accept_fd);
|
2015-11-02 20:34:12 +08:00
|
|
|
#else
|
|
|
|
/* not very beautiful... */
|
|
|
|
accept_fd = (lws_sockfd_type)pollfd;
|
|
|
|
#endif
|
2013-01-18 11:43:21 +08:00
|
|
|
/*
|
|
|
|
* look at who we connected to and give user code a chance
|
|
|
|
* to reject based on client IP. There's no protocol selected
|
|
|
|
* yet so we issue this to protocols[0]
|
|
|
|
*/
|
|
|
|
|
2015-12-17 07:54:44 +08:00
|
|
|
if ((context->protocols[0].callback)(wsi,
|
2013-01-18 11:43:21 +08:00
|
|
|
LWS_CALLBACK_FILTER_NETWORK_CONNECTION,
|
2013-02-20 20:56:59 +08:00
|
|
|
NULL, (void *)(long)accept_fd, 0)) {
|
2013-01-18 11:43:21 +08:00
|
|
|
lwsl_debug("Callback denied network connection\n");
|
|
|
|
compatible_close(accept_fd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-04 09:23:56 +08:00
|
|
|
new_wsi = lws_create_new_server_wsi(context);
|
2013-01-18 11:43:21 +08:00
|
|
|
if (new_wsi == NULL) {
|
|
|
|
compatible_close(accept_fd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_wsi->sock = accept_fd;
|
|
|
|
|
2014-02-15 14:36:02 +08:00
|
|
|
/* the transport is accepted... give him time to negotiate */
|
2015-12-06 06:39:51 +08:00
|
|
|
lws_set_timeout(new_wsi, PENDING_TIMEOUT_ESTABLISH_WITH_SERVER,
|
|
|
|
AWAITING_TIMEOUT);
|
2014-02-15 14:36:02 +08:00
|
|
|
|
2015-11-02 20:34:12 +08:00
|
|
|
#if LWS_POSIX == 0
|
|
|
|
mbed3_tcp_stream_accept(accept_fd, new_wsi);
|
|
|
|
#endif
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-02-06 23:15:51 -02:00
|
|
|
/*
|
|
|
|
* A new connection was accepted. Give the user a chance to
|
|
|
|
* set properties of the newly created wsi. There's no protocol
|
|
|
|
* selected yet so we issue this to protocols[0]
|
|
|
|
*/
|
2015-12-17 07:54:44 +08:00
|
|
|
(context->protocols[0].callback)(new_wsi,
|
2015-12-05 21:51:47 +08:00
|
|
|
LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED,
|
|
|
|
NULL, NULL, 0);
|
2014-02-06 23:15:51 -02:00
|
|
|
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_libev_accept(new_wsi, accept_fd);
|
2014-02-06 23:15:51 -02:00
|
|
|
|
2014-04-12 10:07:02 +08:00
|
|
|
if (!LWS_SSL_ENABLED(context)) {
|
2015-11-08 12:10:26 +08:00
|
|
|
#if LWS_POSIX
|
2013-01-28 12:19:10 +08:00
|
|
|
lwsl_debug("accepted new conn port %u on fd=%d\n",
|
|
|
|
ntohs(cli_addr.sin_port), accept_fd);
|
2015-11-08 12:10:26 +08:00
|
|
|
#endif
|
2015-10-15 07:39:33 +08:00
|
|
|
if (insert_wsi_socket_into_fds(context, new_wsi))
|
|
|
|
goto fail;
|
2013-12-14 11:41:29 +08:00
|
|
|
}
|
2013-01-18 11:43:21 +08:00
|
|
|
break;
|
2013-01-28 12:19:10 +08:00
|
|
|
|
2013-01-18 11:43:21 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-04-12 10:07:02 +08:00
|
|
|
|
2015-12-15 21:15:58 +08:00
|
|
|
if (!lws_server_socket_service_ssl(&wsi, new_wsi, accept_fd, pollfd))
|
2015-12-06 06:39:51 +08:00
|
|
|
return 0;
|
2015-04-23 05:37:46 +08:00
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
fail:
|
2015-12-15 21:15:58 +08:00
|
|
|
lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS);
|
2015-12-05 21:51:47 +08:00
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
return 1;
|
2013-01-18 11:43:21 +08:00
|
|
|
}
|
2013-02-11 17:52:23 +01:00
|
|
|
|
2013-11-11 07:30:33 +08:00
|
|
|
/**
|
2015-12-04 08:43:54 +08:00
|
|
|
* lws_serve_http_file() - Send a file back to the client using http
|
2013-11-11 07:30:33 +08:00
|
|
|
* @wsi: Websocket instance (available from user callback)
|
|
|
|
* @file: The file to issue over http
|
|
|
|
* @content_type: The http content type, eg, text/html
|
2015-12-17 17:03:59 +08:00
|
|
|
* @other_headers: NULL or pointer to header string
|
|
|
|
* @other_headers_len: length of the other headers if non-NULL
|
2013-11-11 07:30:33 +08:00
|
|
|
*
|
|
|
|
* This function is intended to be called from the callback in response
|
|
|
|
* to http requests from the client. It allows the callback to issue
|
|
|
|
* local files down the http link in a single step.
|
|
|
|
*
|
|
|
|
* Returning <0 indicates error and the wsi should be closed. Returning
|
2014-10-17 08:38:44 +08:00
|
|
|
* >0 indicates the file was completely sent and
|
|
|
|
* lws_http_transaction_completed() called on the wsi (and close if != 0)
|
2013-11-11 07:30:33 +08:00
|
|
|
* ==0 indicates the file transfer is started and needs more service later,
|
|
|
|
* the wsi should be left alone.
|
|
|
|
*/
|
|
|
|
|
2015-12-16 18:19:08 +08:00
|
|
|
LWS_VISIBLE int lws_serve_http_file(struct lws *wsi, const char *file,
|
2015-12-04 11:30:53 +08:00
|
|
|
const char *content_type,
|
|
|
|
const char *other_headers,
|
|
|
|
int other_headers_len)
|
2013-11-11 07:30:33 +08:00
|
|
|
{
|
2015-12-17 18:25:25 +08:00
|
|
|
struct lws_context *context = lws_get_context(wsi);
|
2015-12-17 17:03:59 +08:00
|
|
|
unsigned char *response = context->serv_buf +
|
2015-12-06 08:00:03 +08:00
|
|
|
LWS_SEND_BUFFER_PRE_PADDING;
|
2014-10-08 12:00:53 +08:00
|
|
|
unsigned char *p = response;
|
2015-12-17 17:03:59 +08:00
|
|
|
unsigned char *end = p + sizeof(context->serv_buf) -
|
2015-12-06 08:00:03 +08:00
|
|
|
LWS_SEND_BUFFER_PRE_PADDING;
|
2013-11-11 07:30:33 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
wsi->u.http.fd = lws_plat_file_open(wsi, file, &wsi->u.http.filelen,
|
|
|
|
O_RDONLY);
|
2013-11-11 07:30:33 +08:00
|
|
|
|
2014-02-27 03:21:50 +01:00
|
|
|
if (wsi->u.http.fd == LWS_INVALID_FILE) {
|
2013-11-11 07:30:33 +08:00
|
|
|
lwsl_err("Unable to open '%s'\n", file);
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL);
|
|
|
|
|
2013-11-11 07:30:33 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-12-16 18:19:08 +08:00
|
|
|
if (lws_add_http_header_status(wsi, 200, &p, end))
|
2014-10-17 08:38:44 +08:00
|
|
|
return -1;
|
2015-12-16 18:19:08 +08:00
|
|
|
if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_SERVER,
|
2015-12-06 08:00:03 +08:00
|
|
|
(unsigned char *)"libwebsockets", 13,
|
|
|
|
&p, end))
|
2014-10-17 08:38:44 +08:00
|
|
|
return -1;
|
2015-12-16 18:19:08 +08:00
|
|
|
if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE,
|
2015-12-06 08:00:03 +08:00
|
|
|
(unsigned char *)content_type,
|
|
|
|
strlen(content_type), &p, end))
|
2014-10-17 08:38:44 +08:00
|
|
|
return -1;
|
2015-12-16 18:19:08 +08:00
|
|
|
if (lws_add_http_header_content_length(wsi, wsi->u.http.filelen, &p, end))
|
2014-10-17 08:38:44 +08:00
|
|
|
return -1;
|
2014-10-12 14:31:47 +08:00
|
|
|
|
2013-11-11 07:30:33 +08:00
|
|
|
if (other_headers) {
|
2014-10-12 14:31:47 +08:00
|
|
|
if ((end - p) < other_headers_len)
|
|
|
|
return -1;
|
|
|
|
memcpy(p, other_headers, other_headers_len);
|
|
|
|
p += other_headers_len;
|
2013-11-11 07:30:33 +08:00
|
|
|
}
|
|
|
|
|
2015-12-16 18:19:08 +08:00
|
|
|
if (lws_finalize_http_header(wsi, &p, end))
|
2014-10-17 08:38:44 +08:00
|
|
|
return -1;
|
2015-12-14 08:52:03 +08:00
|
|
|
|
lws_plat_fd implement platform default handlers
This is a rewrite of the patch from Soapyman here
https://github.com/warmcat/libwebsockets/pull/363
The main changes compared to Soapyman's original patch are
- There's no new stuff in the info struct user code does any overrides
it may want to do explicitly after lws_context_create returns
- User overrides for file ops can call through (subclass) to the original
platform implementation using lws_get_fops_plat()
- A typedef is provided for plat-specific fd type
- Public helpers are provided to allow user code to be platform-independent
about file access, using the lws platform file operations underneath:
static inline lws_filefd_type
lws_plat_file_open(struct lws_plat_file_ops *fops, const char *filename,
unsigned long *filelen, int flags)
static inline int
lws_plat_file_close(struct lws_plat_file_ops *fops, lws_filefd_type fd)
static inline unsigned long
lws_plat_file_seek_cur(struct lws_plat_file_ops *fops, lws_filefd_type fd,
long offset_from_cur_pos)
static inline int
lws_plat_file_read(struct lws_plat_file_ops *fops, lws_filefd_type fd,
unsigned long *amount, unsigned char *buf, unsigned long len)
static inline int
lws_plat_file_write(struct lws_plat_file_ops *fops, lws_filefd_type fd,
unsigned long *amount, unsigned char *buf, unsigned long len)
There's example documentation and implementation in the test server.
Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-10 07:58:58 +08:00
|
|
|
ret = lws_write(wsi, response, p - response, LWS_WRITE_HTTP_HEADERS);
|
2014-10-08 12:00:53 +08:00
|
|
|
if (ret != (p - response)) {
|
|
|
|
lwsl_err("_write returned %d from %d\n", ret, (p - response));
|
2013-11-11 07:30:33 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wsi->u.http.filepos = 0;
|
2015-12-17 17:03:59 +08:00
|
|
|
wsi->state = LWSS_HTTP_ISSUING_FILE;
|
2013-11-11 07:30:33 +08:00
|
|
|
|
2015-12-16 18:19:08 +08:00
|
|
|
return lws_serve_http_file_fragment(wsi);
|
2013-11-11 07:30:33 +08:00
|
|
|
}
|
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
int
|
|
|
|
lws_interpret_incoming_packet(struct lws *wsi, unsigned char *buf, size_t len)
|
2014-04-10 14:08:10 +08:00
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
int m;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
lwsl_parser("received %d byte packet\n", (int)len);
|
|
|
|
lwsl_hexdump(buf, len);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* let the rx protocol state machine have as much as it needs */
|
|
|
|
|
|
|
|
while (n < len) {
|
|
|
|
/*
|
|
|
|
* we were accepting input but now we stopped doing so
|
|
|
|
*/
|
2014-10-08 12:00:53 +08:00
|
|
|
if (!(wsi->rxflow_change_to & LWS_RXFLOW_ALLOW)) {
|
|
|
|
lws_rxflow_cache(wsi, buf, n, len);
|
2014-04-10 14:08:10 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* account for what we're using in rxflow buffer */
|
2014-10-08 12:00:53 +08:00
|
|
|
if (wsi->rxflow_buffer)
|
|
|
|
wsi->rxflow_pos++;
|
2014-04-10 14:08:10 +08:00
|
|
|
|
|
|
|
/* process the byte */
|
2015-12-04 09:23:56 +08:00
|
|
|
m = lws_rx_sm(wsi, buf[n++]);
|
2014-04-10 14:08:10 +08:00
|
|
|
if (m < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2014-04-12 10:07:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LWS_VISIBLE void
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_server_get_canonical_hostname(struct lws_context *context,
|
2015-12-04 11:30:53 +08:00
|
|
|
struct lws_context_creation_info *info)
|
2014-04-12 10:07:02 +08:00
|
|
|
{
|
|
|
|
if (info->options & LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME)
|
|
|
|
return;
|
2015-11-02 20:34:12 +08:00
|
|
|
#if LWS_POSIX
|
2014-04-12 10:07:02 +08:00
|
|
|
/* find canonical hostname */
|
|
|
|
gethostname((char *)context->canonical_hostname,
|
|
|
|
sizeof(context->canonical_hostname) - 1);
|
|
|
|
|
|
|
|
lwsl_notice(" canonical_hostname = %s\n", context->canonical_hostname);
|
2015-11-02 20:34:12 +08:00
|
|
|
#else
|
|
|
|
(void)context;
|
|
|
|
#endif
|
2014-04-27 13:28:22 +02:00
|
|
|
}
|