whitespace trailing mass cleanout
[platform/upstream/libwebsockets.git] / lib / private-libwebsockets.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2015 Andy Green <andy@warmcat.com>
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public
8  *  License as published by the Free Software Foundation:
9  *  version 2.1 of the License.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  *  MA  02110-1301  USA
20  */
21
22 #include "lws_config.h"
23 #include "lws_config_private.h"
24
25 #ifdef LWS_HAVE_SYS_TYPES_H
26 #include <sys/types.h>
27 #endif
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <time.h>
33 #include <ctype.h>
34 #include <limits.h>
35 #include <stdarg.h>
36 #include <assert.h>
37
38 #ifdef LWS_HAVE_SYS_STAT_H
39 #include <sys/stat.h>
40 #endif
41
42 #if defined(WIN32) || defined(_WIN32)
43 #if (WINVER < 0x0501)
44 #undef WINVER
45 #undef _WIN32_WINNT
46 #define WINVER 0x0501
47 #define _WIN32_WINNT WINVER
48 #endif
49 #define LWS_NO_DAEMONIZE
50 #define LWS_ERRNO WSAGetLastError()
51 #define LWS_EAGAIN WSAEWOULDBLOCK
52 #define LWS_EALREADY WSAEALREADY
53 #define LWS_EINPROGRESS WSAEINPROGRESS
54 #define LWS_EINTR WSAEINTR
55 #define LWS_EISCONN WSAEISCONN
56 #define LWS_EWOULDBLOCK WSAEWOULDBLOCK
57 #define LWS_POLLHUP (FD_CLOSE)
58 #define LWS_POLLIN (FD_READ | FD_ACCEPT)
59 #define LWS_POLLOUT (FD_WRITE)
60 #define MSG_NOSIGNAL 0
61 #define SHUT_RDWR SD_BOTH
62 #define SOL_TCP IPPROTO_TCP
63
64 #define compatible_close(fd) closesocket(fd)
65 #define lws_set_blocking_send(wsi) wsi->sock_send_blocking = TRUE
66 #define lws_socket_is_valid(x) (!!x)
67 #define LWS_SOCK_INVALID 0
68 #include <winsock2.h>
69 #include <windows.h>
70 #include <tchar.h>
71 #ifdef LWS_HAVE_IN6ADDR_H
72 #include <in6addr.h>
73 #endif
74 #include <mstcpip.h>
75
76 #ifndef __func__
77 #define __func__ __FUNCTION__
78 #endif
79
80 #ifdef _WIN32_WCE
81 #define vsnprintf _vsnprintf
82 #endif
83
84 #else /* not windows --> */
85
86 #include <fcntl.h>
87 #include <strings.h>
88 #include <unistd.h>
89 #include <sys/types.h>
90 #ifndef MBED_OPERATORS
91 #ifndef __cplusplus
92 #include <errno.h>
93 #endif
94 #include <netdb.h>
95 #include <signal.h>
96 #include <sys/socket.h>
97 #ifdef LWS_BUILTIN_GETIFADDRS
98  #include <getifaddrs.h>
99 #else
100  #include <ifaddrs.h>
101 #endif
102 #if defined (__ANDROID__)
103 #include <syslog.h>
104 #else
105 #include <sys/syslog.h>
106 #endif
107 #include <sys/un.h>
108 #include <sys/socket.h>
109 #include <netdb.h>
110 #include <netinet/in.h>
111 #include <netinet/tcp.h>
112 #include <arpa/inet.h>
113 #include <poll.h>
114 #ifdef LWS_USE_LIBEV
115 #include <ev.h>
116 #endif /* LWS_USE_LIBEV */
117 #include <sys/mman.h>
118
119 #endif /* MBED */
120
121 #ifndef LWS_NO_FORK
122 #ifdef LWS_HAVE_SYS_PRCTL_H
123 #include <sys/prctl.h>
124 #endif
125 #endif
126
127 #include <sys/time.h>
128
129 #define LWS_ERRNO errno
130 #define LWS_EAGAIN EAGAIN
131 #define LWS_EALREADY EALREADY
132 #define LWS_EINPROGRESS EINPROGRESS
133 #define LWS_EINTR EINTR
134 #define LWS_EISCONN EISCONN
135 #define LWS_EWOULDBLOCK EWOULDBLOCK
136 #define LWS_POLLHUP (POLLHUP|POLLERR)
137 #define LWS_POLLIN (POLLIN)
138 #define LWS_POLLOUT (POLLOUT)
139 #define compatible_close(fd) close(fd)
140 #define lws_set_blocking_send(wsi)
141
142 #ifdef MBED_OPERATORS
143 #define lws_socket_is_valid(x) ((x) != NULL)
144 #define LWS_SOCK_INVALID (NULL)
145 #else
146 #define lws_socket_is_valid(x) (x >= 0)
147 #define LWS_SOCK_INVALID (-1)
148 #endif
149 #endif
150
151 #ifndef LWS_HAVE_BZERO
152 #ifndef bzero
153 #define bzero(b, len) (memset((b), '\0', (len)), (void) 0)
154 #endif
155 #endif
156
157 #ifndef LWS_HAVE_STRERROR
158 #define strerror(x) ""
159 #endif
160
161 #ifdef LWS_OPENSSL_SUPPORT
162 #ifdef USE_WOLFSSL
163 #ifdef USE_OLD_CYASSL
164 #include <cyassl/openssl/ssl.h>
165 #include <cyassl/error-ssl.h>
166 #else
167 #include <wolfssl/openssl/ssl.h>
168 #include <wolfssl/error-ssl.h>
169 #endif /* not USE_OLD_CYASSL */
170 #else
171 #include <openssl/ssl.h>
172 #include <openssl/evp.h>
173 #include <openssl/err.h>
174 #include <openssl/md5.h>
175 #include <openssl/sha.h>
176 #endif /* not USE_WOLFSSL */
177 #endif
178
179 #include "libwebsockets.h"
180
181 #if defined(MBED_OPERATORS)
182 #undef compatible_close
183 #define compatible_close(fd) mbed3_delete_tcp_stream_socket(fd)
184 #ifndef BIG_ENDIAN
185 #define BIG_ENDIAN    4321  /* to show byte order (taken from gcc) */
186 #endif
187 #ifndef LITTLE_ENDIAN
188 #define LITTLE_ENDIAN 1234
189 #endif
190 #ifndef BYTE_ORDER
191 #define BYTE_ORDER LITTLE_ENDIAN
192 #endif
193 #endif
194
195 #if defined(WIN32) || defined(_WIN32)
196
197 #ifndef BIG_ENDIAN
198 #define BIG_ENDIAN    4321  /* to show byte order (taken from gcc) */
199 #endif
200 #ifndef LITTLE_ENDIAN
201 #define LITTLE_ENDIAN 1234
202 #endif
203 #ifndef BYTE_ORDER
204 #define BYTE_ORDER LITTLE_ENDIAN
205 #endif
206 #ifndef u_int64_t
207 typedef unsigned __int64 u_int64_t;
208 #endif
209
210 #undef __P
211 #ifndef __P
212 #if __STDC__
213 #define __P(protos) protos
214 #else
215 #define __P(protos) ()
216 #endif
217 #endif
218
219 #else
220
221 #include <sys/stat.h>
222 #include <sys/cdefs.h>
223 #include <sys/time.h>
224
225 #if defined(__APPLE__)
226 #include <machine/endian.h>
227 #elif defined(__FreeBSD__)
228 #include <sys/endian.h>
229 #elif defined(__linux__)
230 #include <endian.h>
231 #endif
232
233 #ifdef __cplusplus
234 extern "C" {
235 #endif
236 #include <stddef.h>
237
238 #ifndef container_of
239 #define container_of(P,T,M)     ((T *)((char *)(P) - offsetof(T, M)))
240 #endif
241
242 #if defined(__QNX__)
243         #include <gulliver.h>
244         #if defined(__LITTLEENDIAN__)
245                 #define BYTE_ORDER __LITTLEENDIAN__
246                 #define LITTLE_ENDIAN __LITTLEENDIAN__
247                 #define BIG_ENDIAN 4321  /* to show byte order (taken from gcc); for suppres warning that BIG_ENDIAN is not defined. */
248         #endif
249         #if defined(__BIGENDIAN__)
250                 #define BYTE_ORDER __BIGENDIAN__
251                 #define LITTLE_ENDIAN 1234  /* to show byte order (taken from gcc); for suppres warning that LITTLE_ENDIAN is not defined. */
252                 #define BIG_ENDIAN __BIGENDIAN__
253         #endif
254 #endif
255
256 #if !defined(BYTE_ORDER)
257 # define BYTE_ORDER __BYTE_ORDER
258 #endif
259 #if !defined(LITTLE_ENDIAN)
260 # define LITTLE_ENDIAN __LITTLE_ENDIAN
261 #endif
262 #if !defined(BIG_ENDIAN)
263 # define BIG_ENDIAN __BIG_ENDIAN
264 #endif
265
266 #endif
267
268 /*
269  * Mac OSX as well as iOS do not define the MSG_NOSIGNAL flag,
270  * but happily have something equivalent in the SO_NOSIGPIPE flag.
271  */
272 #ifdef __APPLE__
273 #define MSG_NOSIGNAL SO_NOSIGPIPE
274 #endif
275
276 #ifdef _WIN32
277 #ifndef FD_HASHTABLE_MODULUS
278 #define FD_HASHTABLE_MODULUS 32
279 #endif
280 #endif
281
282 #ifndef LWS_MAX_HEADER_LEN
283 #define LWS_MAX_HEADER_LEN 1024
284 #endif
285 #ifndef LWS_MAX_PROTOCOLS
286 #define LWS_MAX_PROTOCOLS 5
287 #endif
288 #ifndef LWS_MAX_EXTENSIONS_ACTIVE
289 #define LWS_MAX_EXTENSIONS_ACTIVE 3
290 #endif
291 #ifndef SPEC_LATEST_SUPPORTED
292 #define SPEC_LATEST_SUPPORTED 13
293 #endif
294 #ifndef AWAITING_TIMEOUT
295 #define AWAITING_TIMEOUT 5
296 #endif
297 #ifndef CIPHERS_LIST_STRING
298 #define CIPHERS_LIST_STRING "DEFAULT"
299 #endif
300 #ifndef LWS_SOMAXCONN
301 #define LWS_SOMAXCONN SOMAXCONN
302 #endif
303
304 #define MAX_WEBSOCKET_04_KEY_LEN 128
305 #define LWS_MAX_SOCKET_IO_BUF 4096
306
307 #ifndef SYSTEM_RANDOM_FILEPATH
308 #define SYSTEM_RANDOM_FILEPATH "/dev/urandom"
309 #endif
310 #ifndef LWS_MAX_ZLIB_CONN_BUFFER
311 #define LWS_MAX_ZLIB_CONN_BUFFER (64 * 1024)
312 #endif
313
314 /*
315  * if not in a connection storm, check for incoming
316  * connections this many normal connection services
317  */
318 #define LWS_LISTEN_SERVICE_MODULO 10
319
320 enum lws_websocket_opcodes_07 {
321         LWS_WS_OPCODE_07__CONTINUATION = 0,
322         LWS_WS_OPCODE_07__TEXT_FRAME = 1,
323         LWS_WS_OPCODE_07__BINARY_FRAME = 2,
324
325         LWS_WS_OPCODE_07__NOSPEC__MUX = 7,
326
327         /* control extensions 8+ */
328
329         LWS_WS_OPCODE_07__CLOSE = 8,
330         LWS_WS_OPCODE_07__PING = 9,
331         LWS_WS_OPCODE_07__PONG = 0xa,
332 };
333
334
335 enum lws_connection_states {
336         WSI_STATE_HTTP,
337         WSI_STATE_HTTP_ISSUING_FILE,
338         WSI_STATE_HTTP_HEADERS,
339         WSI_STATE_HTTP_BODY,
340         WSI_STATE_DEAD_SOCKET,
341         WSI_STATE_ESTABLISHED,
342         WSI_STATE_CLIENT_UNCONNECTED,
343         WSI_STATE_RETURNED_CLOSE_ALREADY,
344         WSI_STATE_AWAITING_CLOSE_ACK,
345         WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE,
346
347         WSI_STATE_HTTP2_AWAIT_CLIENT_PREFACE,
348         WSI_STATE_HTTP2_ESTABLISHED_PRE_SETTINGS,
349         WSI_STATE_HTTP2_ESTABLISHED,
350 };
351
352 enum http_version {
353         HTTP_VERSION_1_0,
354         HTTP_VERSION_1_1,
355 };
356
357 enum http_connection_type {
358         HTTP_CONNECTION_CLOSE,
359         HTTP_CONNECTION_KEEP_ALIVE
360 };
361
362 enum lws_pending_protocol_send {
363         LWS_PPS_NONE,
364         LWS_PPS_HTTP2_MY_SETTINGS,
365         LWS_PPS_HTTP2_ACK_SETTINGS,
366         LWS_PPS_HTTP2_PONG,
367 };
368
369 enum lws_rx_parse_state {
370         LWS_RXPS_NEW,
371
372         LWS_RXPS_04_MASK_NONCE_1,
373         LWS_RXPS_04_MASK_NONCE_2,
374         LWS_RXPS_04_MASK_NONCE_3,
375
376         LWS_RXPS_04_FRAME_HDR_1,
377         LWS_RXPS_04_FRAME_HDR_LEN,
378         LWS_RXPS_04_FRAME_HDR_LEN16_2,
379         LWS_RXPS_04_FRAME_HDR_LEN16_1,
380         LWS_RXPS_04_FRAME_HDR_LEN64_8,
381         LWS_RXPS_04_FRAME_HDR_LEN64_7,
382         LWS_RXPS_04_FRAME_HDR_LEN64_6,
383         LWS_RXPS_04_FRAME_HDR_LEN64_5,
384         LWS_RXPS_04_FRAME_HDR_LEN64_4,
385         LWS_RXPS_04_FRAME_HDR_LEN64_3,
386         LWS_RXPS_04_FRAME_HDR_LEN64_2,
387         LWS_RXPS_04_FRAME_HDR_LEN64_1,
388
389         LWS_RXPS_07_COLLECT_FRAME_KEY_1,
390         LWS_RXPS_07_COLLECT_FRAME_KEY_2,
391         LWS_RXPS_07_COLLECT_FRAME_KEY_3,
392         LWS_RXPS_07_COLLECT_FRAME_KEY_4,
393
394         LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED
395 };
396
397
398 enum connection_mode {
399         LWS_CONNMODE_HTTP_SERVING,
400         LWS_CONNMODE_HTTP_SERVING_ACCEPTED, /* actual HTTP service going on */
401         LWS_CONNMODE_PRE_WS_SERVING_ACCEPT,
402
403         LWS_CONNMODE_WS_SERVING,
404         LWS_CONNMODE_WS_CLIENT,
405
406         LWS_CONNMODE_HTTP2_SERVING,
407
408         /* transient, ssl delay hiding */
409         LWS_CONNMODE_SSL_ACK_PENDING,
410
411         /* transient modes */
412         LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT,
413         LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY,
414         LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE,
415         LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE2,
416         LWS_CONNMODE_WS_CLIENT_WAITING_SSL,
417         LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY,
418         LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT,
419         LWS_CONNMODE_WS_CLIENT_PENDING_CANDIDATE_CHILD,
420
421         /* special internal types */
422         LWS_CONNMODE_SERVER_LISTENER,
423 };
424
425 enum {
426         LWS_RXFLOW_ALLOW = (1 << 0),
427         LWS_RXFLOW_PENDING_CHANGE = (1 << 1),
428 };
429
430 struct lws_protocols;
431 struct lws;
432
433 #ifdef LWS_USE_LIBEV
434 struct lws_io_watcher {
435         struct ev_io watcher;
436         struct lws_context* context;
437 };
438
439 struct lws_signal_watcher {
440         struct ev_signal watcher;
441         struct lws_context* context;
442 };
443 #endif /* LWS_USE_LIBEV */
444
445 #ifdef _WIN32
446 #define LWS_FD_HASH(fd) ((fd ^ (fd >> 8) ^ (fd >> 16)) % FD_HASHTABLE_MODULUS)
447 struct lws_fd_hashtable {
448         struct lws **wsi;
449         int length;
450 };
451 #endif
452
453 struct lws_context {
454 #ifdef _WIN32
455         WSAEVENT *events;
456 #endif
457         struct lws_pollfd *fds;
458 #ifdef _WIN32
459 /* different implementation between unix and windows */
460         struct lws_fd_hashtable fd_hashtable[FD_HASHTABLE_MODULUS];
461 #else
462         struct lws **lws_lookup;  /* fd to wsi */
463 #endif
464         int fds_count;
465 #ifdef LWS_USE_LIBEV
466         struct ev_loop* io_loop;
467         struct lws_io_watcher w_accept;
468         struct lws_signal_watcher w_sigint;
469         lws_ev_signal_cb* lws_ev_sigint_cb;
470         int use_ev_sigint;
471 #endif /* LWS_USE_LIBEV */
472         int max_fds;
473         int listen_port;
474         const char *iface;
475         char http_proxy_address[128];
476         char canonical_hostname[128];
477         char proxy_basic_auth_token[128];
478         unsigned int http_proxy_port;
479         unsigned int options;
480         time_t last_timeout_check_s;
481
482         /*
483          * usable by anything in the service code, but only if the scope
484          * does not last longer than the service action (since next service
485          * of any socket can likewise use it and overwrite)
486          */
487         unsigned char service_buffer[LWS_MAX_SOCKET_IO_BUF];
488
489         int started_with_parent;
490
491         int fd_random;
492         int listen_service_modulo;
493         int listen_service_count;
494         lws_sockfd_type listen_service_fd;
495         int listen_service_extraseen;
496
497         /*
498          * set to the Thread ID that's doing the service loop just before entry
499          * to poll indicates service thread likely idling in poll()
500          * volatile because other threads may check it as part of processing
501          * for pollfd event change.
502          */
503         volatile int service_tid;
504 #ifndef _WIN32
505         int dummy_pipe_fds[2];
506 #endif
507
508         int ka_time;
509         int ka_probes;
510         int ka_interval;
511
512 #ifdef LWS_LATENCY
513         unsigned long worst_latency;
514         char worst_latency_info[256];
515 #endif
516
517 #ifdef LWS_OPENSSL_SUPPORT
518         int use_ssl;
519         int allow_non_ssl_on_ssl_port;
520         unsigned int user_supplied_ssl_ctx:1;
521         SSL_CTX *ssl_ctx;
522         SSL_CTX *ssl_client_ctx;
523         struct lws *pending_read_list; /* linked list */
524 #define lws_ssl_anybody_has_buffered_read(ctx) (ctx->use_ssl && ctx->pending_read_list)
525 #else
526 #define lws_ssl_anybody_has_buffered_read(ctx) (0)
527 #endif
528         const struct lws_protocols *protocols;
529         int count_protocols;
530 #ifndef LWS_NO_EXTENSIONS
531         const struct lws_extension *extensions;
532 #endif
533         const struct lws_token_limits *token_limits;
534         void *user_space;
535
536         struct lws_plat_file_ops fops;
537 };
538
539 enum {
540         LWS_EV_READ = (1 << 0),
541         LWS_EV_WRITE = (1 << 1),
542         LWS_EV_START = (1 << 2),
543         LWS_EV_STOP = (1 << 3),
544 };
545
546 #ifdef LWS_USE_LIBEV
547 #define LWS_LIBEV_ENABLED(context) (context->options & LWS_SERVER_OPTION_LIBEV)
548 LWS_EXTERN void lws_feature_status_libev(struct lws_context_creation_info *info);
549 LWS_EXTERN void
550 lws_libev_accept(struct lws_context *context,
551                  struct lws *new_wsi, lws_sockfd_type accept_fd);
552 LWS_EXTERN void
553 lws_libev_io(const struct lws_context *context,
554                                 struct lws *wsi, int flags);
555 LWS_EXTERN int
556 lws_libev_init_fd_table(struct lws_context *context);
557 LWS_EXTERN void
558 lws_libev_run(const struct lws_context *context);
559 #else
560 #define LWS_LIBEV_ENABLED(context) (0)
561 #ifdef LWS_POSIX
562 #define lws_feature_status_libev(_a) \
563                         lwsl_notice("libev support not compiled in\n")
564 #else
565 #define lws_feature_status_libev(_a)
566 #endif
567 #define lws_libev_accept(_a, _b, _c) ((void) 0)
568 #define lws_libev_io(_a, _b, _c) ((void) 0)
569 #define lws_libev_init_fd_table(_a) (0)
570 #define lws_libev_run(_a) ((void) 0)
571 #endif
572
573 #ifdef LWS_USE_IPV6
574 #define LWS_IPV6_ENABLED(context) \
575         (!(context->options & LWS_SERVER_OPTION_DISABLE_IPV6))
576 #else
577 #define LWS_IPV6_ENABLED(context) (0)
578 #endif
579
580 enum uri_path_states {
581         URIPS_IDLE,
582         URIPS_SEEN_SLASH,
583         URIPS_SEEN_SLASH_DOT,
584         URIPS_SEEN_SLASH_DOT_DOT,
585         URIPS_ARGUMENTS,
586 };
587
588 enum uri_esc_states {
589         URIES_IDLE,
590         URIES_SEEN_PERCENT,
591         URIES_SEEN_PERCENT_H1,
592 };
593
594 /*
595  * This is totally opaque to code using the library.  It's exported as a
596  * forward-reference pointer-only declaration; the user can use the pointer with
597  * other APIs to get information out of it.
598  */
599
600 struct lws_fragments {
601         unsigned short offset;
602         unsigned short len;
603         unsigned char next_frag_index;
604 };
605
606 /* notice that these union members:
607  *
608  *  hdr
609  *  http
610  *  http2
611  *
612  * all have a pointer to allocated_headers struct as their first member.
613  *
614  * It means for allocated_headers access, the three union paths can all be
615  * used interchangeably to access the same data
616  */
617
618 struct allocated_headers {
619         unsigned char next_frag_index;
620         unsigned short pos;
621         unsigned char frag_index[WSI_TOKEN_COUNT];
622         struct lws_fragments frags[WSI_TOKEN_COUNT * 2];
623         char data[LWS_MAX_HEADER_LEN];
624 #ifndef LWS_NO_CLIENT
625         char initial_handshake_hash_base64[30];
626         unsigned short c_port;
627 #endif
628 };
629
630 struct _lws_http_mode_related {
631         /* MUST be first in struct */
632         struct allocated_headers *ah; /* mirroring  _lws_header_related */
633         lws_filefd_type fd;
634         unsigned long filepos;
635         unsigned long filelen;
636
637         enum http_version request_version;
638         enum http_connection_type connection_type;
639         unsigned int content_length;
640         unsigned int content_remain;
641 };
642
643 #ifdef LWS_USE_HTTP2
644
645 enum lws_http2_settings {
646         LWS_HTTP2_SETTINGS__HEADER_TABLE_SIZE = 1,
647         LWS_HTTP2_SETTINGS__ENABLE_PUSH,
648         LWS_HTTP2_SETTINGS__MAX_CONCURRENT_STREAMS,
649         LWS_HTTP2_SETTINGS__INITIAL_WINDOW_SIZE,
650         LWS_HTTP2_SETTINGS__MAX_FRAME_SIZE,
651         LWS_HTTP2_SETTINGS__MAX_HEADER_LIST_SIZE,
652
653         LWS_HTTP2_SETTINGS__COUNT /* always last */
654 };
655
656 enum lws_http2_wellknown_frame_types {
657         LWS_HTTP2_FRAME_TYPE_DATA,
658         LWS_HTTP2_FRAME_TYPE_HEADERS,
659         LWS_HTTP2_FRAME_TYPE_PRIORITY,
660         LWS_HTTP2_FRAME_TYPE_RST_STREAM,
661         LWS_HTTP2_FRAME_TYPE_SETTINGS,
662         LWS_HTTP2_FRAME_TYPE_PUSH_PROMISE,
663         LWS_HTTP2_FRAME_TYPE_PING,
664         LWS_HTTP2_FRAME_TYPE_GOAWAY,
665         LWS_HTTP2_FRAME_TYPE_WINDOW_UPDATE,
666         LWS_HTTP2_FRAME_TYPE_CONTINUATION,
667
668         LWS_HTTP2_FRAME_TYPE_COUNT /* always last */
669 };
670
671 enum lws_http2_flags {
672         LWS_HTTP2_FLAG_END_STREAM = 1,
673         LWS_HTTP2_FLAG_END_HEADERS = 4,
674         LWS_HTTP2_FLAG_PADDED = 8,
675         LWS_HTTP2_FLAG_PRIORITY = 0x20,
676
677         LWS_HTTP2_FLAG_SETTINGS_ACK = 1,
678 };
679
680 #define LWS_HTTP2_STREAM_ID_MASTER 0
681 #define LWS_HTTP2_FRAME_HEADER_LENGTH 9
682 #define LWS_HTTP2_SETTINGS_LENGTH 6
683
684 struct http2_settings {
685         unsigned int setting[LWS_HTTP2_SETTINGS__COUNT];
686 };
687
688 enum http2_hpack_state {
689
690         /* optional before first header block */
691         HPKS_OPT_PADDING,
692         HKPS_OPT_E_DEPENDENCY,
693         HKPS_OPT_WEIGHT,
694
695         /* header block */
696         HPKS_TYPE,
697
698         HPKS_IDX_EXT,
699
700         HPKS_HLEN,
701         HPKS_HLEN_EXT,
702
703         HPKS_DATA,
704
705         /* optional after last header block */
706         HKPS_OPT_DISCARD_PADDING,
707 };
708
709 enum http2_hpack_type {
710         HPKT_INDEXED_HDR_7,
711         HPKT_INDEXED_HDR_6_VALUE_INCR,
712         HPKT_LITERAL_HDR_VALUE_INCR,
713         HPKT_INDEXED_HDR_4_VALUE,
714         HPKT_LITERAL_HDR_VALUE,
715         HPKT_SIZE_5
716 };
717
718 struct hpack_dt_entry {
719         int token; /* additions that don't map to a token are ignored */
720         int arg_offset;
721         int arg_len;
722 };
723
724 struct hpack_dynamic_table {
725         struct hpack_dt_entry *entries;
726         char *args;
727         int pos;
728         int next;
729         int num_entries;
730         int args_length;
731 };
732
733 struct _lws_http2_related {
734         /*
735          * having this first lets us also re-use all HTTP union code
736          * and in turn, http_mode_related has allocated headers in right
737          * place so we can use the header apis on the wsi directly still
738          */
739         struct _lws_http_mode_related http; /* MUST BE FIRST IN STRUCT */
740
741         struct http2_settings my_settings;
742         struct http2_settings peer_settings;
743
744         struct lws *parent_wsi;
745         struct lws *next_child_wsi;
746
747         struct hpack_dynamic_table *hpack_dyn_table;
748
749         unsigned int count;
750
751         /* frame */
752         unsigned int length;
753         unsigned int stream_id;
754         struct lws *stream_wsi;
755         unsigned char type;
756         unsigned char flags;
757         unsigned char frame_state;
758         unsigned char padding;
759
760         unsigned char ping_payload[8];
761
762         unsigned short round_robin_POLLOUT;
763         unsigned short count_POLLOUT_children;
764
765         unsigned int END_STREAM:1;
766         unsigned int END_HEADERS:1;
767         unsigned int send_END_STREAM:1;
768         unsigned int GOING_AWAY;
769         unsigned int requested_POLLOUT:1;
770         unsigned int waiting_tx_credit:1;
771
772         /* hpack */
773         enum http2_hpack_state hpack;
774         enum http2_hpack_type hpack_type;
775         unsigned int header_index;
776         unsigned int hpack_len;
777         unsigned short hpack_pos;
778         unsigned char hpack_m;
779         unsigned int hpack_e_dep;
780         unsigned int huff:1;
781         unsigned int value:1;
782
783         /* negative credit is mandated by the spec */
784         int tx_credit;
785         unsigned int my_stream_id;
786         unsigned int child_count;
787         int my_priority;
788         unsigned char initialized;
789         unsigned char one_setting[LWS_HTTP2_SETTINGS_LENGTH];
790 };
791
792 #define HTTP2_IS_TOPLEVEL_WSI(wsi) (!wsi->u.http2.parent_wsi)
793
794 #endif
795
796 struct _lws_header_related {
797         /* MUST be first in struct */
798         struct allocated_headers *ah;
799         short lextable_pos;
800         unsigned short current_token_limit;
801         unsigned char parser_state; /* enum lws_token_indexes */
802         enum uri_path_states ups;
803         enum uri_esc_states ues;
804         char esc_stash;
805 };
806
807 struct _lws_websocket_related {
808         char *rx_user_buffer;
809         unsigned int rx_user_buffer_head;
810         unsigned char frame_masking_nonce_04[4];
811         unsigned char frame_mask_index;
812         size_t rx_packet_length;
813         unsigned char opcode;
814         unsigned int final:1;
815         unsigned char rsv;
816         unsigned int frame_is_binary:1;
817         unsigned int all_zero_nonce:1;
818         short close_reason; /* enum lws_close_status */
819
820         unsigned int this_frame_masked:1;
821         unsigned int inside_frame:1; /* next write will be more of frame */
822         unsigned int clean_buffer:1; /* buffer not rewritten by extension */
823         unsigned int payload_is_close:1; /* process as PONG, but it is close */
824
825         unsigned char *ping_payload_buf; /* non-NULL if malloc'd */
826         unsigned int ping_payload_alloc; /* length malloc'd */
827         unsigned int ping_payload_len;
828         unsigned char ping_pending_flag;
829 };
830
831 struct lws {
832
833         /* lifetime members */
834
835 #ifdef LWS_USE_LIBEV
836         struct lws_io_watcher w_read;
837         struct lws_io_watcher w_write;
838 #endif /* LWS_USE_LIBEV */
839         struct lws_context *context;
840         const struct lws_protocols *protocol;
841 #ifndef LWS_NO_EXTENSIONS
842         const struct lws_extension *active_extensions[LWS_MAX_EXTENSIONS_ACTIVE];
843         void *active_extensions_user[LWS_MAX_EXTENSIONS_ACTIVE];
844         unsigned char count_active_extensions;
845         unsigned int extension_data_pending:1;
846 #endif
847         unsigned char ietf_spec_revision;
848         enum lws_pending_protocol_send pps;
849
850         char mode; /* enum connection_mode */
851         char state; /* enum lws_connection_states */
852         char lws_rx_parse_state; /* enum lws_rx_parse_state */
853         char rx_frame_type; /* enum lws_write_protocol */
854
855         unsigned int hdr_parsing_completed:1;
856         unsigned int user_space_externally_allocated:1;
857         unsigned int socket_is_permanently_unusable:1;
858
859         char pending_timeout; /* enum pending_timeout */
860         time_t pending_timeout_limit;
861         lws_sockfd_type sock;
862         int position_in_fds_table;
863 #ifdef LWS_LATENCY
864         unsigned long action_start;
865         unsigned long latency_start;
866 #endif
867         /* rxflow handling */
868         unsigned char *rxflow_buffer;
869         int rxflow_len;
870         int rxflow_pos;
871         unsigned int rxflow_change_to:2;
872
873         /* truncated send handling */
874         unsigned char *truncated_send_malloc; /* non-NULL means buffering in progress */
875         unsigned int truncated_send_allocation; /* size of malloc */
876         unsigned int truncated_send_offset; /* where we are in terms of spilling */
877         unsigned int truncated_send_len; /* how much is buffered */
878
879         void *user_space;
880
881         /* members with mutually exclusive lifetimes are unionized */
882
883         union u {
884                 struct _lws_http_mode_related http;
885 #ifdef LWS_USE_HTTP2
886                 struct _lws_http2_related http2;
887 #endif
888                 struct _lws_header_related hdr;
889                 struct _lws_websocket_related ws;
890         } u;
891
892 #ifdef LWS_OPENSSL_SUPPORT
893         SSL *ssl;
894         BIO *client_bio;
895         struct lws *pending_read_list_prev, *pending_read_list_next;
896         unsigned int use_ssl:2;
897         unsigned int upgraded:1;
898 #endif
899
900 #ifdef _WIN32
901         BOOL sock_send_blocking;
902 #endif
903 };
904
905 LWS_EXTERN int log_level;
906
907 LWS_EXTERN void
908 lws_close_and_free_session(struct lws_context *context,
909                            struct lws *wsi, enum lws_close_status);
910
911 LWS_EXTERN int
912 remove_wsi_socket_from_fds(struct lws_context *context, struct lws *wsi);
913 LWS_EXTERN int
914 lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len);
915
916 #ifndef LWS_LATENCY
917 static inline void
918 lws_latency(struct lws_context *context, struct lws *wsi, const char *action,
919             int ret, int completion) {
920         do {
921                 (void)context; (void)wsi; (void)action; (void)ret;
922                 (void)completion;
923         } while (0);
924 }
925 static inline void
926 lws_latency_pre(struct lws_context *context, struct lws *wsi) {
927         do { (void)context; (void)wsi; } while (0);
928 }
929 #else
930 #define lws_latency_pre(_context, _wsi) lws_latency(_context, _wsi, NULL, 0, 0)
931 extern void
932 lws_latency(struct lws_context *context, struct lws *wsi, const char *action,
933             int ret, int completion);
934 #endif
935
936 LWS_EXTERN void
937 lws_set_protocol_write_pending(struct lws_context *context, struct lws *wsi,
938                                enum lws_pending_protocol_send pend);
939 LWS_EXTERN int
940 lws_client_rx_sm(struct lws *wsi, unsigned char c);
941
942 LWS_EXTERN int
943 lws_parse(struct lws_context *context, struct lws *wsi, unsigned char c);
944
945 LWS_EXTERN int
946 lws_http_action(struct lws_context *context, struct lws *wsi);
947
948 LWS_EXTERN int
949 lws_b64_selftest(void);
950
951 #if defined(_WIN32) || defined(MBED_OPERATORS)
952 LWS_EXTERN struct lws *
953 wsi_from_fd(struct lws_context *context, lws_sockfd_type fd);
954
955 LWS_EXTERN int
956 insert_wsi(struct lws_context *context, struct lws *wsi);
957
958 LWS_EXTERN int
959 delete_from_fd(struct lws_context *context, lws_sockfd_type fd);
960 #else
961 #define wsi_from_fd(A,B)  A->lws_lookup[B]
962 #define insert_wsi(A,B)   A->lws_lookup[B->sock]=B
963 #define delete_from_fd(A,B) A->lws_lookup[B]=0
964 #endif
965
966 LWS_EXTERN int
967 insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi);
968
969 LWS_EXTERN int
970 lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len);
971
972
973 LWS_EXTERN int
974 lws_service_timeout_check(struct lws_context *context,
975                           struct lws *wsi, unsigned int sec);
976
977 LWS_EXTERN struct lws *
978 lws_client_connect_2(struct lws_context *context, struct lws *wsi);
979
980 LWS_EXTERN struct lws *
981 lws_create_new_server_wsi(struct lws_context *context);
982
983 LWS_EXTERN char *
984 lws_generate_client_handshake(struct lws_context *context, struct lws *wsi,
985                               char *pkt);
986
987 LWS_EXTERN int
988 lws_handle_POLLOUT_event(struct lws_context *context, struct lws *wsi,
989                          struct lws_pollfd *pollfd);
990
991 /*
992  * EXTENSIONS
993  */
994
995 #ifndef LWS_NO_EXTENSIONS
996 LWS_VISIBLE void
997 lws_context_init_extensions(struct lws_context_creation_info *info,
998                             struct lws_context *context);
999 LWS_EXTERN int
1000 lws_any_extension_handled(struct lws_context *context, struct lws *wsi,
1001                           enum lws_extension_callback_reasons r,
1002                           void *v, size_t len);
1003
1004 LWS_EXTERN int
1005 lws_ext_callback_for_each_active(struct lws *wsi, int reason,
1006                                  void *buf, int len);
1007 LWS_EXTERN int
1008 lws_ext_callback_for_each_extension_type(struct lws_context *context,
1009                                          struct lws *wsi, int reason,
1010                                          void *arg, int len);
1011 #else
1012 #define lws_any_extension_handled(_a, _b, _c, _d, _e) (0)
1013 #define lws_ext_callback_for_each_active(_a, _b, _c, _d) (0)
1014 #define lws_ext_callback_for_each_extension_type(_a, _b, _c, _d, _e) (0)
1015 #define lws_issue_raw_ext_access lws_issue_raw
1016 #define lws_context_init_extensions(_a, _b)
1017 #endif
1018
1019 LWS_EXTERN int
1020 lws_client_interpret_server_handshake(struct lws_context *context,
1021                                       struct lws *wsi);
1022
1023 LWS_EXTERN int
1024 lws_rx_sm(struct lws *wsi, unsigned char c);
1025
1026 LWS_EXTERN int
1027 lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len);
1028
1029 LWS_EXTERN int
1030 _lws_rx_flow_control(struct lws *wsi);
1031
1032 LWS_EXTERN void
1033 lws_union_transition(struct lws *wsi, enum connection_mode mode);
1034
1035 LWS_EXTERN int
1036 user_callback_handle_rxflow(callback_function, struct lws_context *context,
1037                         struct lws *wsi, enum lws_callback_reasons reason,
1038                         void *user, void *in, size_t len);
1039 #ifdef LWS_USE_HTTP2
1040 LWS_EXTERN struct lws *lws_http2_get_network_wsi(struct lws *wsi);
1041 struct lws * lws_http2_get_nth_child(struct lws *wsi, int n);
1042 LWS_EXTERN int
1043 lws_http2_interpret_settings_payload(struct http2_settings *settings,
1044                                      unsigned char *buf, int len);
1045 LWS_EXTERN void lws_http2_init(struct http2_settings *settings);
1046 LWS_EXTERN int
1047 lws_http2_parser(struct lws_context *context,
1048                      struct lws *wsi, unsigned char c);
1049 LWS_EXTERN int lws_http2_do_pps_send(struct lws_context *context,
1050                                      struct lws *wsi);
1051 LWS_EXTERN int lws_http2_frame_write(struct lws *wsi, int type, int flags,
1052                                      unsigned int sid, unsigned int len,
1053                                      unsigned char *buf);
1054 LWS_EXTERN struct lws *
1055 lws_http2_wsi_from_id(struct lws *wsi, unsigned int sid);
1056 LWS_EXTERN int lws_hpack_interpret(struct lws_context *context,
1057                                    struct lws *wsi,
1058                                    unsigned char c);
1059 LWS_EXTERN int
1060 lws_add_http2_header_by_name(struct lws_context *context, struct lws *wsi,
1061                              const unsigned char *name,
1062                              const unsigned char *value, int length,
1063                              unsigned char **p, unsigned char *end);
1064 LWS_EXTERN int
1065 lws_add_http2_header_by_token(struct lws_context *context, struct lws *wsi,
1066                             enum lws_token_indexes token,
1067                             const unsigned char *value, int length,
1068                             unsigned char **p, unsigned char *end);
1069 LWS_EXTERN int
1070 lws_add_http2_header_status(struct lws_context *context, struct lws *wsi,
1071                             unsigned int code, unsigned char **p,
1072                             unsigned char *end);
1073 LWS_EXTERN
1074 void lws_http2_configure_if_upgraded(struct lws *wsi);
1075 #else
1076 #define lws_http2_configure_if_upgraded(x)
1077 #endif
1078
1079 LWS_EXTERN int
1080 lws_plat_set_socket_options(struct lws_context *context, lws_sockfd_type fd);
1081
1082 LWS_EXTERN int
1083 lws_allocate_header_table(struct lws *wsi);
1084
1085 LWS_EXTERN int
1086 lws_free_header_table(struct lws *wsi);
1087
1088 LWS_EXTERN char *
1089 lws_hdr_simple_ptr(struct lws *wsi, enum lws_token_indexes h);
1090
1091 LWS_EXTERN int
1092 lws_hdr_simple_create(struct lws *wsi,
1093                                 enum lws_token_indexes h, const char *s);
1094
1095 LWS_EXTERN int
1096 lws_ensure_user_space(struct lws *wsi);
1097
1098 LWS_EXTERN int
1099 lws_change_pollfd(struct lws *wsi, int _and, int _or);
1100
1101 #ifndef LWS_NO_SERVER
1102 int lws_context_init_server(struct lws_context_creation_info *info,
1103                             struct lws_context *context);
1104 LWS_EXTERN int
1105 handshake_0405(struct lws_context *context, struct lws *wsi);
1106 LWS_EXTERN int
1107 lws_interpret_incoming_packet(struct lws *wsi, unsigned char *buf, size_t len);
1108 LWS_EXTERN void
1109 lws_server_get_canonical_hostname(struct lws_context *context,
1110                                   struct lws_context_creation_info *info);
1111 #else
1112 #define lws_context_init_server(_a, _b) (0)
1113 #define lws_interpret_incoming_packet(_a, _b, _c) (0)
1114 #define lws_server_get_canonical_hostname(_a, _b)
1115 #endif
1116
1117 #ifndef LWS_NO_DAEMONIZE
1118 LWS_EXTERN int get_daemonize_pid();
1119 #else
1120 #define get_daemonize_pid() (0)
1121 #endif
1122
1123 #if !defined(MBED_OPERATORS)
1124 LWS_EXTERN int
1125 interface_to_sa(struct lws_context *context, const char *ifname,
1126                 struct sockaddr_in *addr, size_t addrlen);
1127 #endif
1128 LWS_EXTERN void lwsl_emit_stderr(int level, const char *line);
1129
1130 enum lws_ssl_capable_status {
1131         LWS_SSL_CAPABLE_ERROR = -1,
1132         LWS_SSL_CAPABLE_MORE_SERVICE = -2,
1133 };
1134
1135 #ifndef LWS_OPENSSL_SUPPORT
1136 #define LWS_SSL_ENABLED(context) (0)
1137 #define lws_context_init_server_ssl(_a, _b) (0)
1138 #define lws_ssl_destroy(_a)
1139 #define lws_context_init_http2_ssl(_a)
1140 #define lws_ssl_capable_read lws_ssl_capable_read_no_ssl
1141 #define lws_ssl_capable_write lws_ssl_capable_write_no_ssl
1142 #define lws_ssl_pending lws_ssl_pending_no_ssl
1143 #define lws_server_socket_service_ssl(_a, _b, _c, _d, _e) (0)
1144 #define lws_ssl_close(_a) (0)
1145 #define lws_ssl_context_destroy(_a)
1146 #define lws_ssl_remove_wsi_from_buffered_list(_a, _b)
1147 #else
1148 #define LWS_SSL_ENABLED(context) (context->use_ssl)
1149 LWS_EXTERN int openssl_websocket_private_data_index;
1150 LWS_EXTERN int
1151 lws_ssl_capable_read(struct lws_context *context,
1152                      struct lws *wsi, unsigned char *buf, int len);
1153 LWS_EXTERN int
1154 lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len);
1155 LWS_EXTERN int
1156 lws_ssl_pending(struct lws *wsi);
1157 LWS_EXTERN int
1158 lws_server_socket_service_ssl(struct lws_context *context, struct lws **wsi,
1159                               struct lws *new_wsi, lws_sockfd_type accept_fd,
1160                               struct lws_pollfd *pollfd);
1161 LWS_EXTERN int
1162 lws_ssl_close(struct lws *wsi);
1163 LWS_EXTERN void
1164 lws_ssl_context_destroy(struct lws_context *context);
1165 LWS_VISIBLE void
1166 lws_ssl_remove_wsi_from_buffered_list(struct lws_context *context,
1167                                       struct lws *wsi);
1168 #ifndef LWS_NO_SERVER
1169 LWS_EXTERN int
1170 lws_context_init_server_ssl(struct lws_context_creation_info *info,
1171                             struct lws_context *context);
1172 #else
1173 #define lws_context_init_server_ssl(_a, _b) (0)
1174 #endif
1175 LWS_EXTERN void
1176 lws_ssl_destroy(struct lws_context *context);
1177
1178 /* HTTP2-related */
1179
1180 #ifdef LWS_USE_HTTP2
1181 LWS_EXTERN void
1182 lws_context_init_http2_ssl(struct lws_context *context);
1183 #else
1184 #define lws_context_init_http2_ssl(_a)
1185 #endif
1186 #endif
1187
1188 LWS_EXTERN int
1189 lws_ssl_capable_read_no_ssl(struct lws_context *context,
1190                             struct lws *wsi, unsigned char *buf, int len);
1191
1192 LWS_EXTERN int
1193 lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len);
1194
1195 LWS_EXTERN int
1196 lws_ssl_pending_no_ssl(struct lws *wsi);
1197
1198 #ifndef LWS_NO_CLIENT
1199 LWS_EXTERN int lws_client_socket_service(struct lws_context *context,
1200                                          struct lws *wsi,
1201                                          struct lws_pollfd *pollfd);
1202 #ifdef LWS_OPENSSL_SUPPORT
1203 LWS_EXTERN int
1204 lws_context_init_client_ssl(struct lws_context_creation_info *info,
1205                             struct lws_context *context);
1206 #else
1207         #define lws_context_init_client_ssl(_a, _b) (0)
1208 #endif
1209 LWS_EXTERN int
1210 lws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len);
1211 LWS_EXTERN void
1212 lws_decode_ssl_error(void);
1213 #else
1214 #define lws_context_init_client_ssl(_a, _b) (0)
1215 #define lws_handshake_client(_a, _b, _c) (0)
1216 #endif
1217 #ifndef LWS_NO_SERVER
1218 LWS_EXTERN int
1219 lws_server_socket_service(struct lws_context *context, struct lws *wsi,
1220                           struct lws_pollfd *pollfd);
1221 LWS_EXTERN int
1222 _lws_rx_flow_control(struct lws *wsi);
1223 LWS_EXTERN int
1224 lws_handshake_server(struct lws_context *context,
1225                      struct lws *wsi, unsigned char **buf, size_t len);
1226 #else
1227 #define lws_server_socket_service(_a, _b, _c) (0)
1228 #define _lws_rx_flow_control(_a) (0)
1229 #define lws_handshake_server(_a, _b, _c, _d) (0)
1230 #endif
1231
1232 LWS_EXTERN int
1233 lws_get_addresses(struct lws_context *context, void *ads, char *name,
1234                   int name_len, char *rip, int rip_len);
1235
1236 /*
1237  * custom allocator
1238  */
1239 LWS_EXTERN void*
1240 lws_realloc(void *ptr, size_t size);
1241
1242 LWS_EXTERN void*
1243 lws_zalloc(size_t size);
1244
1245 #define lws_malloc(S)   lws_realloc(NULL, S)
1246 #define lws_free(P)     lws_realloc(P, 0)
1247 #define lws_free2(P)    do { lws_realloc(P, 0); (P) = NULL; } while(0)
1248
1249 /* lws_plat_ */
1250 LWS_EXTERN void
1251 lws_plat_delete_socket_from_fds(struct lws_context *context,
1252                                 struct lws *wsi, int m);
1253 LWS_EXTERN void
1254 lws_plat_insert_socket_into_fds(struct lws_context *context,
1255                                 struct lws *wsi);
1256 LWS_EXTERN void
1257 lws_plat_service_periodic(struct lws_context *context);
1258
1259 LWS_EXTERN int
1260 lws_plat_change_pollfd(struct lws_context *context, struct lws *wsi,
1261                        struct lws_pollfd *pfd);
1262 LWS_EXTERN int
1263 lws_plat_context_early_init(void);
1264 LWS_EXTERN void
1265 lws_plat_context_early_destroy(struct lws_context *context);
1266 LWS_EXTERN void
1267 lws_plat_context_late_destroy(struct lws_context *context);
1268 LWS_EXTERN int
1269 lws_poll_listen_fd(struct lws_pollfd *fd);
1270 LWS_EXTERN int
1271 lws_plat_service(struct lws_context *context, int timeout_ms);
1272 LWS_EXTERN int
1273 lws_plat_init(struct lws_context *context,
1274               struct lws_context_creation_info *info);
1275 LWS_EXTERN void
1276 lws_plat_drop_app_privileges(struct lws_context_creation_info *info);
1277 LWS_EXTERN unsigned long long
1278 time_in_microseconds(void);
1279 LWS_EXTERN const char *
1280 lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt);
1281
1282 #ifdef __cplusplus
1283 };
1284 #endif