• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  */
24 
25 #if !defined(__LWS_CORE_NET_PRIVATE_H__)
26 #define __LWS_CORE_NET_PRIVATE_H__
27 
28 #if !defined(_POSIX_C_SOURCE)
29 #define _POSIX_C_SOURCE 200112L
30 #endif
31 
32 /*
33  * Generic pieces needed to manage muxable stream protocols like h2
34  */
35 
36 struct lws_muxable {
37 	struct lws	*parent_wsi;
38 	struct lws	*child_list;
39 	struct lws	*sibling_list;
40 
41 	unsigned int	my_sid;
42 	unsigned int	child_count;
43 
44 	uint32_t	highest_sid;
45 
46 	uint8_t		requested_POLLOUT;
47 };
48 
49 #include "private-lib-roles.h"
50 
51 #ifdef LWS_WITH_IPV6
52 #if defined(WIN32) || defined(_WIN32)
53 #include <iphlpapi.h>
54 #else
55 #include <net/if.h>
56 #endif
57 #endif
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 /*
64  * All lws_tls...() functions must return this type, converting the
65  * native backend result and doing the extra work to determine which one
66  * as needed.
67  *
68  * Native TLS backend return codes are NOT ALLOWED outside the backend.
69  *
70  * Non-SSL mode also uses these types.
71  */
72 enum lws_ssl_capable_status {
73 	LWS_SSL_CAPABLE_ERROR			= -1, /* it failed */
74 	LWS_SSL_CAPABLE_DONE			= 0,  /* it succeeded */
75 	LWS_SSL_CAPABLE_MORE_SERVICE_READ	= -2, /* retry WANT_READ */
76 	LWS_SSL_CAPABLE_MORE_SERVICE_WRITE	= -3, /* retry WANT_WRITE */
77 	LWS_SSL_CAPABLE_MORE_SERVICE		= -4, /* general retry */
78 };
79 
80 
81 /*
82  *
83  *  ------ roles ------
84  *
85  */
86 
87 /* null-terminated array of pointers to roles lws built with */
88 extern const struct lws_role_ops *available_roles[];
89 
90 #define LWS_FOR_EVERY_AVAILABLE_ROLE_START(xx) { \
91 		const struct lws_role_ops **ppxx = available_roles; \
92 		while (*ppxx) { \
93 			const struct lws_role_ops *xx = *ppxx++;
94 
95 #define LWS_FOR_EVERY_AVAILABLE_ROLE_END }}
96 
97 /*
98  *
99  *  ------ event_loop ops ------
100  *
101  */
102 
103 /* enums of socks version */
104 enum socks_version {
105 	SOCKS_VERSION_4 = 4,
106 	SOCKS_VERSION_5 = 5
107 };
108 
109 /* enums of subnegotiation version */
110 enum socks_subnegotiation_version {
111 	SOCKS_SUBNEGOTIATION_VERSION_1 = 1,
112 };
113 
114 /* enums of socks commands */
115 enum socks_command {
116 	SOCKS_COMMAND_CONNECT = 1,
117 	SOCKS_COMMAND_BIND = 2,
118 	SOCKS_COMMAND_UDP_ASSOCIATE = 3
119 };
120 
121 /* enums of socks address type */
122 enum socks_atyp {
123 	SOCKS_ATYP_IPV4 = 1,
124 	SOCKS_ATYP_DOMAINNAME = 3,
125 	SOCKS_ATYP_IPV6 = 4
126 };
127 
128 /* enums of socks authentication methods */
129 enum socks_auth_method {
130 	SOCKS_AUTH_NO_AUTH = 0,
131 	SOCKS_AUTH_GSSAPI = 1,
132 	SOCKS_AUTH_USERNAME_PASSWORD = 2
133 };
134 
135 /* enums of subnegotiation status */
136 enum socks_subnegotiation_status {
137 	SOCKS_SUBNEGOTIATION_STATUS_SUCCESS = 0,
138 };
139 
140 /* enums of socks request reply */
141 enum socks_request_reply {
142 	SOCKS_REQUEST_REPLY_SUCCESS = 0,
143 	SOCKS_REQUEST_REPLY_FAILURE_GENERAL = 1,
144 	SOCKS_REQUEST_REPLY_CONNECTION_NOT_ALLOWED = 2,
145 	SOCKS_REQUEST_REPLY_NETWORK_UNREACHABLE = 3,
146 	SOCKS_REQUEST_REPLY_HOST_UNREACHABLE = 4,
147 	SOCKS_REQUEST_REPLY_CONNECTION_REFUSED = 5,
148 	SOCKS_REQUEST_REPLY_TTL_EXPIRED = 6,
149 	SOCKS_REQUEST_REPLY_COMMAND_NOT_SUPPORTED = 7,
150 	SOCKS_REQUEST_REPLY_ATYP_NOT_SUPPORTED = 8
151 };
152 
153 /* enums used to generate socks messages */
154 enum socks_msg_type {
155 	/* greeting */
156 	SOCKS_MSG_GREETING,
157 	/* credential, user name and password */
158 	SOCKS_MSG_USERNAME_PASSWORD,
159 	/* connect command */
160 	SOCKS_MSG_CONNECT
161 };
162 
163 enum {
164 	LWS_RXFLOW_ALLOW = (1 << 0),
165 	LWS_RXFLOW_PENDING_CHANGE = (1 << 1),
166 };
167 
168 typedef enum lws_parser_return {
169 	LPR_FORBIDDEN	= -2,
170 	LPR_FAIL	= -1,
171 	LPR_OK		= 0,
172 	LPR_DO_FALLBACK = 2,
173 } lws_parser_return_t;
174 
175 enum pmd_return {
176 	PMDR_UNKNOWN,
177 	PMDR_DID_NOTHING,
178 	PMDR_HAS_PENDING,
179 	PMDR_EMPTY_NONFINAL,
180 	PMDR_EMPTY_FINAL,
181 
182 	PMDR_FAILED = -1
183 };
184 
185 #if defined(LWS_WITH_PEER_LIMITS)
186 struct lws_peer {
187 	struct lws_peer *next;
188 	struct lws_peer *peer_wait_list;
189 
190 	time_t time_created;
191 	time_t time_closed_all;
192 
193 	uint8_t addr[32];
194 	uint32_t hash;
195 	uint32_t count_wsi;
196 	uint32_t total_wsi;
197 
198 #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
199 	struct lws_peer_role_http http;
200 #endif
201 
202 	uint8_t af;
203 };
204 #endif
205 
206 enum {
207 	LWS_EV_READ = (1 << 0),
208 	LWS_EV_WRITE = (1 << 1),
209 	LWS_EV_START = (1 << 2),
210 	LWS_EV_STOP = (1 << 3),
211 
212 	LWS_EV_PREPARE_DELETION = (1u << 31),
213 };
214 
215 #ifdef LWS_WITH_IPV6
216 #define LWS_IPV6_ENABLED(vh) \
217 	(!lws_check_opt(vh->context->options, LWS_SERVER_OPTION_DISABLE_IPV6) && \
218 	 !lws_check_opt(vh->options, LWS_SERVER_OPTION_DISABLE_IPV6))
219 #else
220 #define LWS_IPV6_ENABLED(context) (0)
221 #endif
222 
223 #ifdef LWS_WITH_UNIX_SOCK
224 #define LWS_UNIX_SOCK_ENABLED(vhost) \
225 	(vhost->options & LWS_SERVER_OPTION_UNIX_SOCK)
226 #else
227 #define LWS_UNIX_SOCK_ENABLED(vhost) (0)
228 #endif
229 
230 enum uri_path_states {
231 	URIPS_IDLE,
232 	URIPS_SEEN_SLASH,
233 	URIPS_SEEN_SLASH_DOT,
234 	URIPS_SEEN_SLASH_DOT_DOT,
235 };
236 
237 enum uri_esc_states {
238 	URIES_IDLE,
239 	URIES_SEEN_PERCENT,
240 	URIES_SEEN_PERCENT_H1,
241 };
242 
243 #if defined(LWS_WITH_CLIENT)
244 
245 enum {
246 	CIS_ADDRESS,
247 	CIS_PATH,
248 	CIS_HOST,
249 	CIS_ORIGIN,
250 	CIS_PROTOCOL,
251 	CIS_METHOD,
252 	CIS_IFACE,
253 	CIS_ALPN,
254 
255 
256 	CIS_COUNT
257 };
258 
259 struct client_info_stash {
260 	char *cis[CIS_COUNT];
261 	void *opaque_user_data; /* not allocated or freed by lws */
262 };
263 #endif
264 
265 #if defined(LWS_WITH_UDP)
266 #define lws_wsi_is_udp(___wsi) (!!___wsi->udp)
267 #endif
268 
269 #define LWS_H2_FRAME_HEADER_LENGTH 9
270 
271 int
272 __lws_sul_insert(lws_dll2_owner_t *own, lws_sorted_usec_list_t *sul,
273 		 lws_usec_t us);
274 
275 lws_usec_t
276 __lws_sul_service_ripe(lws_dll2_owner_t *own, lws_usec_t usnow);
277 
278 struct lws_timed_vh_protocol {
279 	struct lws_timed_vh_protocol	*next;
280 	lws_sorted_usec_list_t		sul;
281 	const struct lws_protocols	*protocol;
282 	struct lws_vhost *vhost; /* only used for pending processing */
283 	int				reason;
284 	int				tsi_req;
285 };
286 
287 /*
288  * lws_dsh
289 */
290 
291 typedef struct lws_dsh_obj_head {
292 	lws_dll2_owner_t		owner;
293 	int				kind;
294 } lws_dsh_obj_head_t;
295 
296 typedef struct lws_dsh_obj {
297 	lws_dll2_t			list;	/* must be first */
298 	struct lws_dsh	  		*dsh;	/* invalid when on free list */
299 	size_t				size;	/* invalid when on free list */
300 	size_t				asize;
301 } lws_dsh_obj_t;
302 
303 typedef struct lws_dsh {
304 	lws_dll2_t			list;
305 	uint8_t				*buf;
306 	lws_dsh_obj_head_t		*oha;	/* array of object heads/kind */
307 	size_t				buffer_size;
308 	size_t				locally_in_use;
309 	size_t				locally_free;
310 	int				count_kinds;
311 	uint8_t				being_destroyed;
312 	/*
313 	 * Overallocations at create:
314 	 *
315 	 *  - the buffer itself
316 	 *  - the object heads array
317 	 */
318 } lws_dsh_t;
319 
320 /*
321  * lws_async_dns
322  */
323 
324 typedef struct lws_async_dns {
325 	lws_sockaddr46 		sa46; /* nameserver */
326 	lws_dll2_owner_t	waiting;
327 	lws_dll2_owner_t	cached;
328 	struct lws		*wsi;
329 	time_t			time_set_server;
330 	char			dns_server_set;
331 } lws_async_dns_t;
332 
333 typedef enum {
334 	LADNS_CONF_SERVER_UNKNOWN				= -1,
335 	LADNS_CONF_SERVER_SAME,
336 	LADNS_CONF_SERVER_CHANGED
337 } lws_async_dns_server_check_t;
338 
339 #if defined(LWS_WITH_SYS_ASYNC_DNS)
340 void
341 lws_aysnc_dns_completed(struct lws *wsi, void *sa, size_t salen,
342 			lws_async_dns_retcode_t ret);
343 #endif
344 void
345 lws_async_dns_cancel(struct lws *wsi);
346 
347 /*
348  * so we can have n connections being serviced simultaneously,
349  * these things need to be isolated per-thread.
350  */
351 
352 struct lws_context_per_thread {
353 #if LWS_MAX_SMP > 1
354 	pthread_mutex_t lock_stats;
355 	struct lws_mutex_refcount mr;
356 	pthread_t self;
357 #endif
358 	struct lws_dll2_owner dll_buflist_owner;  /* guys with pending rxflow */
359 	struct lws_dll2_owner seq_owner;	   /* list of lws_sequencer-s */
360 	lws_dll2_owner_t      attach_owner;	/* pending lws_attach */
361 
362 #if defined(LWS_WITH_SECURE_STREAMS)
363 	lws_dll2_owner_t ss_owner;
364 #endif
365 #if defined(LWS_WITH_SECURE_STREAMS_PROXY_API) || \
366     defined(LWS_WITH_SECURE_STREAMS_THREAD_API)
367 	lws_dll2_owner_t ss_dsh_owner;
368 	lws_dll2_owner_t ss_client_owner;
369 #endif
370 
371 	struct lws_dll2_owner pt_sul_owner;
372 
373 #if defined (LWS_WITH_SEQUENCER)
374 	lws_sorted_usec_list_t sul_seq_heartbeat;
375 #endif
376 #if (defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)) && defined(LWS_WITH_SERVER)
377 	lws_sorted_usec_list_t sul_ah_lifecheck;
378 #endif
379 #if defined(LWS_WITH_TLS) && defined(LWS_WITH_SERVER)
380 	lws_sorted_usec_list_t sul_tls;
381 #endif
382 #if defined(LWS_PLAT_UNIX)
383 	lws_sorted_usec_list_t sul_plat;
384 #endif
385 #if defined(LWS_ROLE_CGI)
386 	lws_sorted_usec_list_t sul_cgi;
387 #endif
388 #if defined(LWS_WITH_STATS)
389 	uint64_t lws_stats[LWSSTATS_SIZE];
390 	int updated;
391 	lws_sorted_usec_list_t sul_stats;
392 #endif
393 #if defined(LWS_WITH_PEER_LIMITS)
394 	lws_sorted_usec_list_t sul_peer_limits;
395 #endif
396 
397 #if defined(LWS_WITH_TLS)
398 	struct lws_pt_tls tls;
399 #endif
400 	struct lws *fake_wsi;	/* used for callbacks where there's no wsi */
401 
402 	struct lws_context *context;
403 
404 	/*
405 	 * usable by anything in the service code, but only if the scope
406 	 * does not last longer than the service action (since next service
407 	 * of any socket can likewise use it and overwrite)
408 	 */
409 	unsigned char *serv_buf;
410 
411 	struct lws_pollfd *fds;
412 	volatile struct lws_foreign_thread_pollfd * volatile foreign_pfd_list;
413 #ifdef _WIN32
414 	WSAEVENT events;
415 	CRITICAL_SECTION interrupt_lock;
416 #endif
417 	lws_sockfd_type dummy_pipe_fds[2];
418 	struct lws *pipe_wsi;
419 
420 	/* --- role based members --- */
421 
422 #if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS)
423 	struct lws_pt_role_ws ws;
424 #endif
425 #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
426 	struct lws_pt_role_http http;
427 #endif
428 #if defined(LWS_ROLE_DBUS)
429 	struct lws_pt_role_dbus dbus;
430 #endif
431 	/* --- event library based members --- */
432 
433 #if defined(LWS_WITH_LIBEV)
434 	struct lws_pt_eventlibs_libev ev;
435 #endif
436 #if defined(LWS_WITH_LIBUV)
437 	struct lws_pt_eventlibs_libuv uv;
438 #endif
439 #if defined(LWS_WITH_LIBEVENT)
440 	struct lws_pt_eventlibs_libevent event;
441 #endif
442 #if defined(LWS_WITH_GLIB)
443 	struct lws_pt_eventlibs_glib glib;
444 #endif
445 
446 #if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || \
447     defined(LWS_WITH_LIBEVENT) || defined(LWS_WITH_GLIB)
448 	struct lws_signal_watcher w_sigint;
449 #endif
450 
451 #if defined(LWS_WITH_DETAILED_LATENCY)
452 	lws_usec_t	ust_left_poll;
453 #endif
454 
455 	/* --- */
456 
457 	unsigned long count_conns;
458 	unsigned int fds_count;
459 
460 	/*
461 	 * set to the Thread ID that's doing the service loop just before entry
462 	 * to poll indicates service thread likely idling in poll()
463 	 * volatile because other threads may check it as part of processing
464 	 * for pollfd event change.
465 	 */
466 	volatile int service_tid;
467 	int service_tid_detected;
468 
469 	volatile unsigned char inside_poll;
470 	volatile unsigned char foreign_spinlock;
471 
472 	unsigned char tid;
473 
474 	unsigned char inside_service:1;
475 	unsigned char inside_lws_service:1;
476 	unsigned char event_loop_foreign:1;
477 	unsigned char event_loop_destroy_processing_done:1;
478 	unsigned char destroy_self:1;
479 	unsigned char is_destroyed:1;
480 #ifdef _WIN32
481 	unsigned char interrupt_requested:1;
482 #endif
483 };
484 
485 #if defined(LWS_WITH_SERVER_STATUS)
486 struct lws_conn_stats {
487 	unsigned long long rx, tx;
488 	unsigned long h1_conn, h1_trans, h2_trans, ws_upg, h2_alpn, h2_subs,
489 		      h2_upg, rejected, mqtt_subs;
490 };
491 #endif
492 
493 /*
494  * virtual host -related context information
495  *   vhostwide SSL context
496  *   vhostwide proxy
497  *
498  * hierarchy:
499  *
500  * context -> vhost -> wsi
501  *
502  * incoming connection non-SSL vhost binding:
503  *
504  *    listen socket -> wsi -> select vhost after first headers
505  *
506  * incoming connection SSL vhost binding:
507  *
508  *    SSL SNI -> wsi -> bind after SSL negotiation
509  */
510 
511 struct lws_vhost {
512 #if defined(LWS_WITH_CLIENT) && defined(LWS_CLIENT_HTTP_PROXYING)
513 	char proxy_basic_auth_token[128];
514 #endif
515 #if LWS_MAX_SMP > 1
516 	pthread_mutex_t lock;
517 	char close_flow_vs_tsi[LWS_MAX_SMP];
518 #endif
519 
520 #if defined(LWS_ROLE_H2)
521 	struct lws_vhost_role_h2 h2;
522 #endif
523 #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
524 	struct lws_vhost_role_http http;
525 #endif
526 #if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS)
527 	struct lws_vhost_role_ws ws;
528 #endif
529 
530 #if defined(LWS_WITH_SOCKS5)
531 	char socks_proxy_address[128];
532 	char socks_user[96];
533 	char socks_password[96];
534 #endif
535 #if defined(LWS_WITH_LIBEV)
536 	struct lws_io_watcher w_accept;
537 #endif
538 #if defined(LWS_WITH_SERVER_STATUS)
539 	struct lws_conn_stats conn_stats;
540 #endif
541 
542 	uint64_t options;
543 
544 	struct lws_context *context;
545 	struct lws_vhost *vhost_next;
546 
547 	const lws_retry_bo_t *retry_policy;
548 
549 	struct lws *lserv_wsi;
550 	const char *name;
551 	const char *iface;
552 	const char *listen_accept_role;
553 	const char *listen_accept_protocol;
554 	const char *unix_socket_perms;
555 
556 	void (*finalize)(struct lws_vhost *vh, void *arg);
557 	void *finalize_arg;
558 
559 	const struct lws_protocols *protocols;
560 	void **protocol_vh_privs;
561 	const struct lws_protocol_vhost_options *pvo;
562 	const struct lws_protocol_vhost_options *headers;
563 	struct lws_dll2_owner *same_vh_protocol_owner;
564 	struct lws_vhost *no_listener_vhost_list;
565 	struct lws_dll2_owner abstract_instances_owner;		/* vh lock */
566 
567 #if defined(LWS_WITH_CLIENT)
568 	struct lws_dll2_owner dll_cli_active_conns_owner;
569 #endif
570 	struct lws_dll2_owner vh_awaiting_socket_owner;
571 
572 #if defined(LWS_WITH_TLS)
573 	struct lws_vhost_tls tls;
574 #endif
575 
576 	struct lws_timed_vh_protocol *timed_vh_protocol_list;
577 	void *user;
578 
579 	int listen_port;
580 #if !defined(LWS_PLAT_FREERTOS) && !defined(OPTEE_TA) && !defined(WIN32)
581 	int bind_iface;
582 #endif
583 
584 #if defined(LWS_WITH_SOCKS5)
585 	unsigned int socks_proxy_port;
586 #endif
587 	int count_protocols;
588 	int ka_time;
589 	int ka_probes;
590 	int ka_interval;
591 	int keepalive_timeout;
592 	int timeout_secs_ah_idle;
593 
594 	int count_bound_wsi;
595 
596 #ifdef LWS_WITH_ACCESS_LOG
597 	int log_fd;
598 #endif
599 
600 	uint8_t allocated_vhost_protocols:1;
601 	uint8_t created_vhost_protocols:1;
602 	uint8_t being_destroyed:1;
603 	uint8_t from_ss_policy:1;
604 
605 	unsigned char default_protocol_index;
606 	unsigned char raw_protocol_index;
607 };
608 
609 void
610 __lws_vhost_destroy2(struct lws_vhost *vh);
611 
612 #define mux_to_wsi(_m) lws_container_of(_m, struct lws, mux)
613 
614 void
615 lws_wsi_mux_insert(struct lws *wsi, struct lws *parent_wsi, int sid);
616 int
617 lws_wsi_mux_mark_parents_needing_writeable(struct lws *wsi);
618 struct lws *
619 lws_wsi_mux_move_child_to_tail(struct lws **wsi2);
620 int
621 lws_wsi_mux_action_pending_writeable_reqs(struct lws *wsi);
622 
623 void
624 lws_wsi_mux_dump_children(struct lws *wsi);
625 
626 void
627 lws_wsi_mux_close_children(struct lws *wsi, int reason);
628 
629 void
630 lws_wsi_mux_sibling_disconnect(struct lws *wsi);
631 
632 void
633 lws_wsi_mux_dump_waiting_children(struct lws *wsi);
634 
635 int
636 lws_wsi_mux_apply_queue(struct lws *wsi);
637 
638 /*
639  * struct lws
640  */
641 
642 struct lws {
643 	/* structs */
644 
645 #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
646 	struct _lws_http_mode_related	http;
647 #endif
648 #if defined(LWS_ROLE_H2)
649 	struct _lws_h2_related		h2;
650 #endif
651 #if defined(LWS_ROLE_WS)
652 	struct _lws_websocket_related	*ws; /* allocated if we upgrade to ws */
653 #endif
654 #if defined(LWS_ROLE_DBUS)
655 	struct _lws_dbus_mode_related	dbus;
656 #endif
657 #if defined(LWS_ROLE_MQTT)
658 	struct _lws_mqtt_related	*mqtt;
659 #endif
660 
661 #if defined(LWS_ROLE_H2) || defined(LWS_ROLE_MQTT)
662 	struct lws_muxable		mux;
663 	struct lws_tx_credit		txc;
664 #endif
665 
666 	/* lifetime members */
667 
668 #if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || \
669     defined(LWS_WITH_LIBEVENT) || defined(LWS_WITH_GLIB)
670 	struct lws_io_watcher		w_read;
671 #endif
672 #if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBEVENT)
673 	struct lws_io_watcher		w_write;
674 #endif
675 
676 #if defined(LWS_WITH_DETAILED_LATENCY)
677 	lws_detlat_t	detlat;
678 #endif
679 
680 	lws_sorted_usec_list_t		sul_timeout;
681 	lws_sorted_usec_list_t		sul_hrtimer;
682 	lws_sorted_usec_list_t		sul_validity;
683 
684 	struct lws_dll2			dll_buflist; /* guys with pending rxflow */
685 	struct lws_dll2			same_vh_protocol;
686 	struct lws_dll2			vh_awaiting_socket;
687 #if defined(LWS_WITH_SYS_ASYNC_DNS)
688 	struct lws_dll2			adns; /* on adns list of guys to tell result */
689 	lws_async_dns_cb_t		adns_cb; /* callback with result */
690 #endif
691 #if defined(LWS_WITH_CLIENT)
692 	struct lws_dll2			dll_cli_active_conns;
693 	struct lws_dll2			dll2_cli_txn_queue;
694 	struct lws_dll2_owner		dll2_cli_txn_queue_owner;
695 #endif
696 
697 #if defined(LWS_WITH_ACCESS_LOG)
698 	char simple_ip[(8 * 5)];
699 #endif
700 	/* pointers */
701 
702 	struct lws_context		*context;
703 	struct lws_vhost		*vhost;
704 	struct lws			*parent; /* points to parent, if any */
705 	struct lws			*child_list; /* points to first child */
706 	struct lws			*sibling_list; /* subsequent children at same level */
707 	const struct lws_role_ops	*role_ops;
708 	const struct lws_protocols	*protocol;
709 	struct lws_sequencer		*seq;	/* associated sequencer if any */
710 	const lws_retry_bo_t		*retry_policy;
711 
712 #if defined(LWS_WITH_THREADPOOL)
713 	struct lws_threadpool_task	*tp_task;
714 #endif
715 
716 #if defined(LWS_WITH_PEER_LIMITS)
717 	struct lws_peer			*peer;
718 #endif
719 
720 #if defined(LWS_WITH_UDP)
721 	struct lws_udp			*udp;
722 #endif
723 #if defined(LWS_WITH_CLIENT)
724 	struct client_info_stash	*stash;
725 	char				*cli_hostname_copy;
726 	const struct addrinfo		*dns_results;
727 	const struct addrinfo		*dns_results_next;
728 #endif
729 	void				*user_space;
730 	void				*opaque_parent_data;
731 	void				*opaque_user_data;
732 
733 	struct lws_buflist		*buflist; /* input-side buflist */
734 	struct lws_buflist		*buflist_out; /* output-side buflist */
735 
736 #if defined(LWS_WITH_TLS)
737 	struct lws_lws_tls		tls;
738 #endif
739 
740 	lws_sock_file_fd_type		desc; /* .filefd / .sockfd */
741 #if defined(LWS_WITH_STATS)
742 	uint64_t active_writable_req_us;
743 #if defined(LWS_WITH_TLS)
744 	uint64_t accept_start_us;
745 #endif
746 #endif
747 	lws_wsi_state_t			wsistate;
748 	lws_wsi_state_t			wsistate_pre_close;
749 
750 	/* ints */
751 #define LWS_NO_FDS_POS (-1)
752 	int				position_in_fds_table;
753 
754 #if defined(LWS_WITH_CLIENT)
755 	int				chunk_remaining;
756 	int				flags;
757 #endif
758 	unsigned int			cache_secs;
759 
760 	unsigned int			hdr_parsing_completed:1;
761 	unsigned int			mux_substream:1;
762 	unsigned int			upgraded_to_http2:1;
763 	unsigned int			mux_stream_immortal:1;
764 	unsigned int			h2_stream_carries_ws:1; /* immortal set as well */
765 	unsigned int			h2_stream_carries_sse:1; /* immortal set as well */
766 	unsigned int			h2_acked_settings:1;
767 	unsigned int			seen_nonpseudoheader:1;
768 	unsigned int			listener:1;
769 	unsigned int			pf_packet:1;
770 	unsigned int			do_broadcast:1;
771 	unsigned int			user_space_externally_allocated:1;
772 	unsigned int			socket_is_permanently_unusable:1;
773 	unsigned int			rxflow_change_to:2;
774 	unsigned int			conn_stat_done:1;
775 	unsigned int			cache_reuse:1;
776 	unsigned int			cache_revalidate:1;
777 	unsigned int			cache_intermediaries:1;
778 	unsigned int			favoured_pollin:1;
779 	unsigned int			sending_chunked:1;
780 	unsigned int			interpreting:1;
781 	unsigned int			already_did_cce:1;
782 	unsigned int			told_user_closed:1;
783 	unsigned int			told_event_loop_closed:1;
784 	unsigned int			waiting_to_send_close_frame:1;
785 	unsigned int			close_needs_ack:1;
786 	unsigned int			ipv6:1;
787 	unsigned int			parent_pending_cb_on_writable:1;
788 	unsigned int			cgi_stdout_zero_length:1;
789 	unsigned int			seen_zero_length_recv:1;
790 	unsigned int			rxflow_will_be_applied:1;
791 	unsigned int			event_pipe:1;
792 	unsigned int			handling_404:1;
793 	unsigned int			protocol_bind_balance:1;
794 	unsigned int			unix_skt:1;
795 	unsigned int			close_when_buffered_out_drained:1;
796 	unsigned int			h1_ws_proxied:1;
797 	unsigned int			proxied_ws_parent:1;
798 	unsigned int			do_bind:1;
799 	unsigned int			oom4:1;
800 	unsigned int			validity_hup:1;
801 	unsigned int			skip_fallback:1;
802 
803 	unsigned int			could_have_pending:1; /* detect back-to-back writes */
804 	unsigned int			outer_will_close:1;
805 	unsigned int			shadow:1; /* we do not control fd lifecycle at all */
806 
807 #ifdef LWS_WITH_ACCESS_LOG
808 	unsigned int			access_log_pending:1;
809 #endif
810 #if defined(LWS_WITH_CLIENT)
811 	unsigned int			do_ws:1; /* whether we are doing http or ws flow */
812 	unsigned int			chunked:1; /* if the clientside connection is chunked */
813 	unsigned int			client_rx_avail:1;
814 	unsigned int			client_http_body_pending:1;
815 	unsigned int			transaction_from_pipeline_queue:1;
816 	unsigned int			keepalive_active:1;
817 	unsigned int			keepalive_rejected:1;
818 	unsigned int			redirected_to_get:1;
819 	unsigned int			client_pipeline:1;
820 	unsigned int			client_h2_alpn:1;
821 	unsigned int			client_mux_substream:1;
822 	unsigned int			client_mux_migrated:1;
823 	unsigned int			client_subsequent_mime_part:1;
824 	unsigned int                    client_no_follow_redirect:1;
825 	unsigned int                    client_suppress_CONNECTION_ERROR:1;
826 	/**< because the client connection creation api is still the parent of
827 	 * this activity, and will report the failure */
828 #endif
829 
830 #ifdef _WIN32
831 	unsigned int sock_send_blocking:1;
832 #endif
833 
834 	uint16_t			ocport, c_port;
835 	uint16_t			retry;
836 
837 	/* chars */
838 
839 	char lws_rx_parse_state; /* enum lws_rx_parse_state */
840 	char rx_frame_type; /* enum lws_write_protocol */
841 	char pending_timeout; /* enum pending_timeout */
842 	char tsi; /* thread service index we belong to */
843 	char protocol_interpret_idx;
844 	char redirects;
845 	uint8_t rxflow_bitmap;
846 	uint8_t bound_vhost_index;
847 	uint8_t lsp_channel; /* which of stdin/out/err */
848 #ifdef LWS_WITH_CGI
849 	char hdr_state;
850 #endif
851 #if defined(LWS_WITH_CLIENT)
852 	char chunk_parser; /* enum lws_chunk_parser */
853 	uint8_t addrinfo_idx;
854 	uint8_t sys_tls_client_cert;
855 #endif
856 #if defined(LWS_WITH_CGI) || defined(LWS_WITH_CLIENT)
857 	char reason_bf; /* internal writeable callback reason bitfield */
858 #endif
859 #if defined(LWS_WITH_STATS) && defined(LWS_WITH_TLS)
860 	char seen_rx;
861 #endif
862 	uint8_t immortal_substream_count;
863 	/* volatile to make sure code is aware other thread can change */
864 	volatile char handling_pollout;
865 	volatile char leave_pollout_active;
866 #if LWS_MAX_SMP > 1
867 	volatile char undergoing_init_from_other_pt;
868 #endif
869 
870 };
871 
872 #define lws_is_flowcontrolled(w) (!!(wsi->rxflow_bitmap))
873 
874 #if defined(LWS_WITH_SPAWN)
875 
876 #if defined(WIN32) || defined(_WIN32)
877 #else
878 #include <sys/wait.h>
879 #include <sys/times.h>
880 #endif
881 
882 struct lws_spawn_piped {
883 
884 	struct lws_spawn_piped_info	info;
885 
886 	struct lws_dll2			dll;
887 	lws_sorted_usec_list_t		sul;
888 
889 	struct lws			*stdwsi[3];
890 	int				pipe_fds[3][2];
891 	int				count_log_lines;
892 
893 	lws_usec_t			created; /* set by lws_spawn_piped() */
894 	lws_usec_t			reaped;
895 
896 	lws_usec_t			accounting[4];
897 
898 	pid_t				child_pid;
899 
900 	siginfo_t			si;
901 
902 	uint8_t				pipes_alive:2;
903 	uint8_t				we_killed_him_timeout:1;
904 	uint8_t				we_killed_him_spew:1;
905 	uint8_t				ungraceful:1;
906 };
907 
908 void
909 lws_spawn_piped_destroy(struct lws_spawn_piped **lsp);
910 
911 int
912 lws_spawn_reap(struct lws_spawn_piped *lsp);
913 
914 #endif
915 
916 void
917 lws_service_do_ripe_rxflow(struct lws_context_per_thread *pt);
918 
919 const struct lws_role_ops *
920 lws_role_by_name(const char *name);
921 
922 int
923 lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port,
924 		const char *iface, int ipv6_allowed);
925 
926 #if defined(LWS_WITH_IPV6)
927 unsigned long
928 lws_get_addr_scope(const char *ipaddr);
929 #endif
930 
931 void
932 lws_close_free_wsi(struct lws *wsi, enum lws_close_status, const char *caller);
933 void
934 __lws_close_free_wsi(struct lws *wsi, enum lws_close_status, const char *caller);
935 
936 void
937 __lws_free_wsi(struct lws *wsi);
938 
939 #if LWS_MAX_SMP > 1
940 
941 static LWS_INLINE void
lws_pt_mutex_init(struct lws_context_per_thread * pt)942 lws_pt_mutex_init(struct lws_context_per_thread *pt)
943 {
944 	lws_mutex_refcount_init(&pt->mr);
945 	pthread_mutex_init(&pt->lock_stats, NULL);
946 }
947 
948 static LWS_INLINE void
lws_pt_mutex_destroy(struct lws_context_per_thread * pt)949 lws_pt_mutex_destroy(struct lws_context_per_thread *pt)
950 {
951 	pthread_mutex_destroy(&pt->lock_stats);
952 	lws_mutex_refcount_destroy(&pt->mr);
953 }
954 
955 #define lws_pt_lock(pt, reason) lws_mutex_refcount_lock(&pt->mr, reason)
956 #define lws_pt_unlock(pt) lws_mutex_refcount_unlock(&pt->mr)
957 
958 static LWS_INLINE void
lws_pt_stats_lock(struct lws_context_per_thread * pt)959 lws_pt_stats_lock(struct lws_context_per_thread *pt)
960 {
961 	pthread_mutex_lock(&pt->lock_stats);
962 }
963 
964 static LWS_INLINE void
lws_pt_stats_unlock(struct lws_context_per_thread * pt)965 lws_pt_stats_unlock(struct lws_context_per_thread *pt)
966 {
967 	pthread_mutex_unlock(&pt->lock_stats);
968 }
969 #endif
970 
971 /*
972  * EXTENSIONS
973  */
974 
975 #if defined(LWS_WITHOUT_EXTENSIONS)
976 #define lws_any_extension_handled(_a, _b, _c, _d) (0)
977 #define lws_ext_cb_active(_a, _b, _c, _d) (0)
978 #define lws_ext_cb_all_exts(_a, _b, _c, _d, _e) (0)
979 #define lws_issue_raw_ext_access lws_issue_raw
980 #define lws_context_init_extensions(_a, _b)
981 #endif
982 
983 int LWS_WARN_UNUSED_RESULT
984 lws_client_interpret_server_handshake(struct lws *wsi);
985 
986 int LWS_WARN_UNUSED_RESULT
987 lws_ws_rx_sm(struct lws *wsi, char already_processed, unsigned char c);
988 
989 int LWS_WARN_UNUSED_RESULT
990 lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len);
991 
992 void
993 lws_role_transition(struct lws *wsi, enum lwsi_role role, enum lwsi_state state,
994 		    const struct lws_role_ops *ops);
995 
996 int
997 lws_http_to_fallback(struct lws *wsi, unsigned char *buf, size_t len);
998 
999 int LWS_WARN_UNUSED_RESULT
1000 user_callback_handle_rxflow(lws_callback_function, struct lws *wsi,
1001 			    enum lws_callback_reasons reason, void *user,
1002 			    void *in, size_t len);
1003 
1004 int
1005 lws_plat_set_nonblocking(lws_sockfd_type fd);
1006 
1007 int
1008 lws_plat_set_socket_options(struct lws_vhost *vhost, lws_sockfd_type fd,
1009 			    int unix_skt);
1010 
1011 int
1012 lws_plat_check_connection_error(struct lws *wsi);
1013 
1014 int LWS_WARN_UNUSED_RESULT
1015 lws_header_table_attach(struct lws *wsi, int autoservice);
1016 
1017 int
1018 lws_header_table_detach(struct lws *wsi, int autoservice);
1019 int
1020 __lws_header_table_detach(struct lws *wsi, int autoservice);
1021 
1022 void
1023 lws_header_table_reset(struct lws *wsi, int autoservice);
1024 
1025 void
1026 __lws_header_table_reset(struct lws *wsi, int autoservice);
1027 
1028 char * LWS_WARN_UNUSED_RESULT
1029 lws_hdr_simple_ptr(struct lws *wsi, enum lws_token_indexes h);
1030 
1031 int LWS_WARN_UNUSED_RESULT
1032 lws_hdr_simple_create(struct lws *wsi, enum lws_token_indexes h, const char *s);
1033 
1034 int LWS_WARN_UNUSED_RESULT
1035 lws_ensure_user_space(struct lws *wsi);
1036 
1037 int LWS_WARN_UNUSED_RESULT
1038 lws_change_pollfd(struct lws *wsi, int _and, int _or);
1039 
1040 #if defined(LWS_WITH_SERVER)
1041  int _lws_vhost_init_server(const struct lws_context_creation_info *info,
1042 			      struct lws_vhost *vhost);
1043  LWS_EXTERN struct lws_vhost *
1044  lws_select_vhost(struct lws_context *context, int port, const char *servername);
1045  LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1046  lws_parse_ws(struct lws *wsi, unsigned char **buf, size_t len);
1047  LWS_EXTERN void
1048  lws_server_get_canonical_hostname(struct lws_context *context,
1049 				   const struct lws_context_creation_info *info);
1050 #else
1051  #define _lws_vhost_init_server(_a, _b) (0)
1052  #define lws_parse_ws(_a, _b, _c) (0)
1053  #define lws_server_get_canonical_hostname(_a, _b)
1054 #endif
1055 
1056 int
1057 __remove_wsi_socket_from_fds(struct lws *wsi);
1058 
1059 enum {
1060 	LWSRXFC_ERROR = -1,
1061 	LWSRXFC_CACHED = 0,
1062 	LWSRXFC_ADDITIONAL = 1,
1063 	LWSRXFC_TRIMMED = 2,
1064 };
1065 
1066 
1067 int
1068 _lws_plat_service_forced_tsi(struct lws_context *context, int tsi);
1069 
1070 int
1071 lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len);
1072 
1073 int
1074 lws_service_flag_pending(struct lws_context *context, int tsi);
1075 
1076 static LWS_INLINE int
lws_has_buffered_out(struct lws * wsi)1077 lws_has_buffered_out(struct lws *wsi) { return !!wsi->buflist_out; }
1078 
1079 int LWS_WARN_UNUSED_RESULT
1080 lws_ws_client_rx_sm(struct lws *wsi, unsigned char c);
1081 
1082 lws_parser_return_t LWS_WARN_UNUSED_RESULT
1083 lws_parse(struct lws *wsi, unsigned char *buf, int *len);
1084 
1085 int LWS_WARN_UNUSED_RESULT
1086 lws_parse_urldecode(struct lws *wsi, uint8_t *_c);
1087 
1088 int LWS_WARN_UNUSED_RESULT
1089 lws_http_action(struct lws *wsi);
1090 
1091 void
1092 __lws_close_free_wsi_final(struct lws *wsi);
1093 void
1094 lws_libuv_closehandle(struct lws *wsi);
1095 int
1096 lws_libuv_check_watcher_active(struct lws *wsi);
1097 
1098 LWS_VISIBLE LWS_EXTERN int
1099 lws_plat_plugins_init(struct lws_context * context, const char * const *d);
1100 
1101 LWS_VISIBLE LWS_EXTERN int
1102 lws_plat_plugins_destroy(struct lws_context * context);
1103 
1104 struct lws *
1105 lws_adopt_socket_vhost(struct lws_vhost *vh, lws_sockfd_type accept_fd);
1106 
1107 void
1108 lws_vhost_bind_wsi(struct lws_vhost *vh, struct lws *wsi);
1109 void
1110 lws_vhost_unbind_wsi(struct lws *wsi);
1111 
1112 void
1113 __lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs);
1114 int
1115 __lws_change_pollfd(struct lws *wsi, int _and, int _or);
1116 
1117 
1118 int
1119 lws_callback_as_writeable(struct lws *wsi);
1120 
1121 int
1122 lws_role_call_client_bind(struct lws *wsi,
1123 			  const struct lws_client_connect_info *i);
1124 void
1125 lws_remove_child_from_any_parent(struct lws *wsi);
1126 
1127 char *
1128 lws_generate_client_ws_handshake(struct lws *wsi, char *p, const char *conn1);
1129 int
1130 lws_client_ws_upgrade(struct lws *wsi, const char **cce);
1131 int
1132 lws_create_client_ws_object(const struct lws_client_connect_info *i,
1133 			    struct lws *wsi);
1134 int
1135 lws_alpn_comma_to_openssl(const char *comma, uint8_t *os, int len);
1136 int
1137 lws_role_call_alpn_negotiated(struct lws *wsi, const char *alpn);
1138 int
1139 lws_tls_server_conn_alpn(struct lws *wsi);
1140 
1141 int
1142 lws_ws_client_rx_sm_block(struct lws *wsi, unsigned char **buf, size_t len);
1143 void
1144 lws_destroy_event_pipe(struct lws *wsi);
1145 
1146 /* socks */
1147 int
1148 lws_socks5c_generate_msg(struct lws *wsi, enum socks_msg_type type, ssize_t *msg_len);
1149 
1150 #if defined(LWS_WITH_SERVER_STATUS)
1151 void
1152 lws_sum_stats(const struct lws_context *ctx, struct lws_conn_stats *cs);
1153 #endif
1154 
1155 int
1156 __lws_timed_callback_remove(struct lws_vhost *vh, struct lws_timed_vh_protocol *p);
1157 
1158 int LWS_WARN_UNUSED_RESULT
1159 __insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi);
1160 
1161 int LWS_WARN_UNUSED_RESULT
1162 lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len);
1163 
1164 lws_usec_t
1165 __lws_seq_timeout_check(struct lws_context_per_thread *pt, lws_usec_t usnow);
1166 
1167 lws_usec_t
1168 __lws_ss_timeout_check(struct lws_context_per_thread *pt, lws_usec_t usnow);
1169 
1170 struct lws * LWS_WARN_UNUSED_RESULT
1171 lws_client_connect_2_dnsreq(struct lws *wsi);
1172 
1173 LWS_VISIBLE struct lws * LWS_WARN_UNUSED_RESULT
1174 lws_client_reset(struct lws **wsi, int ssl, const char *address, int port,
1175 		 const char *path, const char *host, char weak);
1176 
1177 struct lws * LWS_WARN_UNUSED_RESULT
1178 lws_create_new_server_wsi(struct lws_vhost *vhost, int fixed_tsi);
1179 
1180 char * LWS_WARN_UNUSED_RESULT
1181 lws_generate_client_handshake(struct lws *wsi, char *pkt);
1182 
1183 int
1184 lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd);
1185 
1186 struct lws *
1187 lws_http_client_connect_via_info2(struct lws *wsi);
1188 
1189 
1190 #if defined(LWS_WITH_CLIENT)
1191 int
1192 lws_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd);
1193 
1194 int LWS_WARN_UNUSED_RESULT
1195 lws_http_transaction_completed_client(struct lws *wsi);
1196 #if !defined(LWS_WITH_TLS)
1197 	#define lws_context_init_client_ssl(_a, _b) (0)
1198 #endif
1199 void
1200 lws_decode_ssl_error(void);
1201 #else
1202 #define lws_context_init_client_ssl(_a, _b) (0)
1203 #endif
1204 
1205 int
1206 __lws_rx_flow_control(struct lws *wsi);
1207 
1208 int
1209 _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa);
1210 
1211 #if defined(LWS_WITH_SERVER)
1212 int
1213 lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len);
1214 #else
1215 #define lws_server_socket_service(_b, _c) (0)
1216 #define lws_handshake_server(_a, _b, _c) (0)
1217 #endif
1218 
1219 #ifdef LWS_WITH_ACCESS_LOG
1220 int
1221 lws_access_log(struct lws *wsi);
1222 void
1223 lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int len, int meth);
1224 #else
1225 #define lws_access_log(_a)
1226 #endif
1227 
1228 #if defined(_DEBUG)
1229 void
1230 lws_wsi_txc_describe(struct lws_tx_credit *txc, const char *at, uint32_t sid);
1231 #else
1232 #define lws_wsi_txc_describe(x, y, z) { (void)x; }
1233 #endif
1234 
1235 int
1236 lws_wsi_txc_check_skint(struct lws_tx_credit *txc, int32_t tx_cr);
1237 
1238 int
1239 lws_wsi_txc_report_manual_txcr_in(struct lws *wsi, int32_t bump);
1240 
1241 void
1242 lws_mux_mark_immortal(struct lws *wsi);
1243 void
1244 lws_http_close_immortal(struct lws *wsi);
1245 
1246 int
1247 lws_cgi_kill_terminated(struct lws_context_per_thread *pt);
1248 
1249 void
1250 lws_cgi_remove_and_kill(struct lws *wsi);
1251 
1252 void
1253 lws_plat_delete_socket_from_fds(struct lws_context *context,
1254 				struct lws *wsi, int m);
1255 void
1256 lws_plat_insert_socket_into_fds(struct lws_context *context,
1257 				struct lws *wsi);
1258 
1259 int
1260 lws_plat_change_pollfd(struct lws_context *context, struct lws *wsi,
1261 		       struct lws_pollfd *pfd);
1262 
1263 
1264 int
1265 lws_plat_pipe_create(struct lws *wsi);
1266 int
1267 lws_plat_pipe_signal(struct lws *wsi);
1268 void
1269 lws_plat_pipe_close(struct lws *wsi);
1270 
1271 void
1272 lws_addrinfo_clean(struct lws *wsi);
1273 
1274 void
1275 lws_add_wsi_to_draining_ext_list(struct lws *wsi);
1276 void
1277 lws_remove_wsi_from_draining_ext_list(struct lws *wsi);
1278 int
1279 lws_poll_listen_fd(struct lws_pollfd *fd);
1280 int
1281 lws_plat_service(struct lws_context *context, int timeout_ms);
1282 LWS_VISIBLE int
1283 _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi);
1284 
1285 int
1286 lws_pthread_self_to_tsi(struct lws_context *context);
1287 const char * LWS_WARN_UNUSED_RESULT
1288 lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt);
1289 int LWS_WARN_UNUSED_RESULT
1290 lws_plat_inet_pton(int af, const char *src, void *dst);
1291 
1292 void
1293 lws_same_vh_protocol_remove(struct lws *wsi);
1294 void
1295 __lws_same_vh_protocol_remove(struct lws *wsi);
1296 void
1297 lws_same_vh_protocol_insert(struct lws *wsi, int n);
1298 
1299 void
1300 lws_seq_destroy_all_on_pt(struct lws_context_per_thread *pt);
1301 
1302 int
1303 lws_broadcast(struct lws_context_per_thread *pt, int reason, void *in, size_t len);
1304 
1305 #if defined(LWS_WITH_STATS)
1306  void
1307  lws_stats_bump(struct lws_context_per_thread *pt, int i, uint64_t bump);
1308  void
1309  lws_stats_max(struct lws_context_per_thread *pt, int index, uint64_t val);
1310 #else
lws_stats_bump(struct lws_context_per_thread * pt,int index,uint64_t bump)1311  static LWS_INLINE uint64_t lws_stats_bump(
1312 		struct lws_context_per_thread *pt, int index, uint64_t bump) {
1313 	(void)pt; (void)index; (void)bump; return 0; }
lws_stats_max(struct lws_context_per_thread * pt,int index,uint64_t val)1314  static LWS_INLINE uint64_t lws_stats_max(
1315 		struct lws_context_per_thread *pt, int index, uint64_t val) {
1316 	(void)pt; (void)index; (void)val; return 0; }
1317 #endif
1318 
1319 
1320 
1321 #if defined(LWS_WITH_PEER_LIMITS)
1322 void
1323 lws_peer_track_wsi_close(struct lws_context *context, struct lws_peer *peer);
1324 int
1325 lws_peer_confirm_ah_attach_ok(struct lws_context *context,
1326 			      struct lws_peer *peer);
1327 void
1328 lws_peer_track_ah_detach(struct lws_context *context, struct lws_peer *peer);
1329 void
1330 lws_peer_cull_peer_wait_list(struct lws_context *context);
1331 struct lws_peer *
1332 lws_get_or_create_peer(struct lws_vhost *vhost, lws_sockfd_type sockfd);
1333 void
1334 lws_peer_add_wsi(struct lws_context *context, struct lws_peer *peer,
1335 		 struct lws *wsi);
1336 void
1337 lws_peer_dump_from_wsi(struct lws *wsi);
1338 #endif
1339 
1340 #ifdef LWS_WITH_HUBBUB
1341 hubbub_error
1342 html_parser_cb(const hubbub_token *token, void *pw);
1343 #endif
1344 
1345 int
1346 lws_threadpool_tsi_context(struct lws_context *context, int tsi);
1347 
1348 void
1349 __lws_wsi_remove_from_sul(struct lws *wsi);
1350 
1351 void
1352 lws_validity_confirmed(struct lws *wsi);
1353 void
1354 _lws_validity_confirmed_role(struct lws *wsi);
1355 
1356 int
1357 lws_seq_pt_init(struct lws_context_per_thread *pt);
1358 
1359 int
1360 lws_buflist_aware_read(struct lws_context_per_thread *pt, struct lws *wsi,
1361 		       struct lws_tokens *ebuf, char fr, const char *hint);
1362 int
1363 lws_buflist_aware_finished_consuming(struct lws *wsi, struct lws_tokens *ebuf,
1364 				     int used, int buffered, const char *hint);
1365 
1366 extern const struct lws_protocols protocol_abs_client_raw_skt,
1367 				  protocol_abs_client_unit_test;
1368 
1369 void
1370 __lws_reset_wsi(struct lws *wsi);
1371 
1372 void
1373 lws_inform_client_conn_fail(struct lws *wsi, void *arg, size_t len);
1374 
1375 #if defined(LWS_WITH_SYS_ASYNC_DNS)
1376 lws_async_dns_server_check_t
1377 lws_plat_asyncdns_init(struct lws_context *context, lws_sockaddr46 *sa);
1378 int
1379 lws_async_dns_init(struct lws_context *context);
1380 void
1381 lws_async_dns_deinit(lws_async_dns_t *dns);
1382 #endif
1383 
1384 int
1385 lws_protocol_init_vhost(struct lws_vhost *vh, int *any);
1386 int
1387 _lws_generic_transaction_completed_active_conn(struct lws **wsi);
1388 
1389 #define ACTIVE_CONNS_SOLO 0
1390 #define ACTIVE_CONNS_MUXED 1
1391 #define ACTIVE_CONNS_QUEUED 2
1392 #define ACTIVE_CONNS_FAILED 3
1393 
1394 int
1395 lws_vhost_active_conns(struct lws *wsi, struct lws **nwsi, const char *adsin);
1396 
1397 const char *
1398 lws_wsi_client_stash_item(struct lws *wsi, int stash_idx, int hdr_idx);
1399 
1400 int
1401 lws_plat_BINDTODEVICE(lws_sockfd_type fd, const char *ifname);
1402 
1403 int
1404 lws_socks5c_ads_server(struct lws_vhost *vh,
1405 		       const struct lws_context_creation_info *info);
1406 
1407 int
1408 lws_socks5c_handle_state(struct lws *wsi, struct lws_pollfd *pollfd,
1409 			 const char **pcce);
1410 
1411 int
1412 lws_socks5c_greet(struct lws *wsi, const char **pcce);
1413 
1414 enum {
1415 	LW5CHS_RET_RET0,
1416 	LW5CHS_RET_BAIL3,
1417 	LW5CHS_RET_STARTHS,
1418 	LW5CHS_RET_NOTHING
1419 };
1420 
1421 #ifdef __cplusplus
1422 };
1423 #endif
1424 
1425 #endif
1426