private-lib-core.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. /*
  2. * libwebsockets - small server side websockets and web server implementation
  3. *
  4. * Copyright (C) 2010 - 2019 Andy Green <[email protected]>
  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. #if !defined(__LWS_PRIVATE_LIB_CORE_H__)
  25. #define __LWS_PRIVATE_LIB_CORE_H__
  26. #include "lws_config.h"
  27. #include "lws_config_private.h"
  28. #if defined(LWS_WITH_CGI) && defined(LWS_HAVE_VFORK) && \
  29. !defined(NO_GNU_SOURCE_THIS_TIME) && !defined(_GNU_SOURCE)
  30. #define _GNU_SOURCE
  31. #endif
  32. /*
  33. #if !defined(_POSIX_C_SOURCE)
  34. #define _POSIX_C_SOURCE 200112L
  35. #endif
  36. */
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <time.h>
  41. #include <ctype.h>
  42. #include <limits.h>
  43. #include <stdarg.h>
  44. #include <errno.h>
  45. #ifdef LWS_HAVE_INTTYPES_H
  46. #include <inttypes.h>
  47. #endif
  48. #include <assert.h>
  49. #ifdef LWS_HAVE_SYS_TYPES_H
  50. #include <sys/types.h>
  51. #endif
  52. #if defined(LWS_HAVE_SYS_STAT_H) && !defined(LWS_PLAT_OPTEE)
  53. #include <sys/stat.h>
  54. #endif
  55. #if LWS_MAX_SMP > 1 || defined(LWS_WITH_SYS_SMD)
  56. /* https://stackoverflow.com/questions/33557506/timespec-redefinition-error */
  57. #define HAVE_STRUCT_TIMESPEC
  58. #include <pthread.h>
  59. #else
  60. #if !defined(pid_t) && defined(WIN32)
  61. #define pid_t int
  62. #endif
  63. #endif
  64. #ifndef LWS_DEF_HEADER_LEN
  65. #define LWS_DEF_HEADER_LEN 4096
  66. #endif
  67. #ifndef LWS_DEF_HEADER_POOL
  68. #define LWS_DEF_HEADER_POOL 4
  69. #endif
  70. #ifndef LWS_MAX_PROTOCOLS
  71. #define LWS_MAX_PROTOCOLS 5
  72. #endif
  73. #ifndef LWS_MAX_EXTENSIONS_ACTIVE
  74. #define LWS_MAX_EXTENSIONS_ACTIVE 1
  75. #endif
  76. #ifndef LWS_MAX_EXT_OFFERS
  77. #define LWS_MAX_EXT_OFFERS 8
  78. #endif
  79. #ifndef SPEC_LATEST_SUPPORTED
  80. #define SPEC_LATEST_SUPPORTED 13
  81. #endif
  82. #ifndef CIPHERS_LIST_STRING
  83. #define CIPHERS_LIST_STRING "DEFAULT"
  84. #endif
  85. #ifndef LWS_SOMAXCONN
  86. #define LWS_SOMAXCONN SOMAXCONN
  87. #endif
  88. #define MAX_WEBSOCKET_04_KEY_LEN 128
  89. #ifndef SYSTEM_RANDOM_FILEPATH
  90. #define SYSTEM_RANDOM_FILEPATH "/dev/urandom"
  91. #endif
  92. #define LWS_H2_RX_SCRATCH_SIZE 512
  93. #define lws_socket_is_valid(x) (x != LWS_SOCK_INVALID)
  94. #ifndef LWS_HAVE_STRERROR
  95. #define strerror(x) ""
  96. #endif
  97. /*
  98. *
  99. * ------ private platform defines ------
  100. *
  101. */
  102. #if defined(LWS_PLAT_FREERTOS)
  103. #include "private-lib-plat-freertos.h"
  104. #else
  105. #if defined(WIN32) || defined(_WIN32)
  106. #include "private-lib-plat-windows.h"
  107. #else
  108. #if defined(LWS_PLAT_OPTEE)
  109. #include "private-lib-plat.h"
  110. #else
  111. #include "private-lib-plat-unix.h"
  112. #endif
  113. #endif
  114. #endif
  115. /*
  116. *
  117. * ------ public api ------
  118. *
  119. */
  120. #include "libwebsockets.h"
  121. /*
  122. * Generic bidi tx credit management
  123. */
  124. struct lws_tx_credit {
  125. int32_t tx_cr; /* our credit to write peer */
  126. int32_t peer_tx_cr_est; /* peer's credit to write us */
  127. int32_t manual_initial_tx_credit;
  128. uint8_t skint; /* unable to write anything */
  129. uint8_t manual;
  130. };
  131. #ifdef LWS_WITH_IPV6
  132. #if defined(WIN32) || defined(_WIN32)
  133. #include <iphlpapi.h>
  134. #else
  135. #include <net/if.h>
  136. #endif
  137. #endif
  138. #undef X509_NAME
  139. #if defined(LWS_WITH_TLS)
  140. #include "private-lib-tls.h"
  141. #endif
  142. #if defined(WIN32) || defined(_WIN32)
  143. // Visual studio older than 2015 and WIN_CE has only _stricmp
  144. #if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(_WIN32_WCE)
  145. #define strcasecmp _stricmp
  146. #define strncasecmp _strnicmp
  147. #elif !defined(__MINGW32__)
  148. #define strcasecmp stricmp
  149. #define strncasecmp strnicmp
  150. #endif
  151. #define getdtablesize() 30000
  152. #endif
  153. #ifndef LWS_ARRAY_SIZE
  154. #define LWS_ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
  155. #endif
  156. #ifdef __cplusplus
  157. extern "C" {
  158. #endif
  159. #define lws_safe_modulo(_a, _b) ((_b) ? ((_a) % (_b)) : 0)
  160. #if defined(__clang__)
  161. #define lws_memory_barrier() __sync_synchronize()
  162. #elif defined(__GNUC__)
  163. #define lws_memory_barrier() __sync_synchronize()
  164. #else
  165. #define lws_memory_barrier()
  166. #endif
  167. struct lws_ring {
  168. void *buf;
  169. void (*destroy_element)(void *element);
  170. uint32_t buflen;
  171. uint32_t element_len;
  172. uint32_t head;
  173. uint32_t oldest_tail;
  174. };
  175. struct lws_protocols;
  176. struct lws;
  177. #if defined(LWS_WITH_NETWORK) /* network */
  178. #include "private-lib-event-libs.h"
  179. #if defined(LWS_WITH_SECURE_STREAMS)
  180. #include "private-lib-secure-streams.h"
  181. #endif
  182. #if defined(LWS_WITH_SYS_SMD)
  183. #include "private-lib-system-smd.h"
  184. #endif
  185. struct lws_foreign_thread_pollfd {
  186. struct lws_foreign_thread_pollfd *next;
  187. int fd_index;
  188. int _and;
  189. int _or;
  190. };
  191. #endif /* network */
  192. #if defined(LWS_WITH_NETWORK)
  193. #include "private-lib-core-net.h"
  194. #endif
  195. struct lws_deferred_free
  196. {
  197. struct lws_deferred_free *next;
  198. time_t deadline;
  199. void *payload;
  200. };
  201. struct lws_system_blob {
  202. union {
  203. struct lws_buflist *bl;
  204. struct {
  205. const uint8_t *ptr;
  206. size_t len;
  207. } direct;
  208. } u;
  209. char is_direct;
  210. };
  211. typedef struct lws_attach_item {
  212. lws_dll2_t list;
  213. lws_attach_cb_t cb;
  214. void *opaque;
  215. lws_system_states_t state;
  216. } lws_attach_item_t;
  217. /*
  218. * the rest is managed per-context, that includes
  219. *
  220. * - processwide single fd -> wsi lookup
  221. * - contextwide headers pool
  222. */
  223. struct lws_context {
  224. #if defined(LWS_WITH_SERVER)
  225. char canonical_hostname[96];
  226. #endif
  227. #if defined(LWS_WITH_FILE_OPS)
  228. struct lws_plat_file_ops fops_platform;
  229. #endif
  230. #if defined(LWS_WITH_ZIP_FOPS)
  231. struct lws_plat_file_ops fops_zip;
  232. #endif
  233. lws_system_blob_t system_blobs[LWS_SYSBLOB_TYPE_COUNT];
  234. #if defined(LWS_WITH_SYS_SMD)
  235. lws_smd_t smd;
  236. #endif
  237. #if defined(LWS_WITH_NETWORK)
  238. struct lws_context_per_thread pt[LWS_MAX_SMP];
  239. lws_retry_bo_t default_retry;
  240. lws_sorted_usec_list_t sul_system_state;
  241. #if defined(LWS_PLAT_FREERTOS)
  242. struct sockaddr_in frt_pipe_si;
  243. #endif
  244. #if defined(LWS_WITH_HTTP2)
  245. struct http2_settings set;
  246. #endif
  247. #if defined(LWS_WITH_SERVER_STATUS)
  248. struct lws_conn_stats conn_stats;
  249. #endif
  250. #if LWS_MAX_SMP > 1
  251. struct lws_mutex_refcount mr;
  252. #endif
  253. #if defined(LWS_WITH_NETWORK)
  254. /*
  255. * LWS_WITH_NETWORK =====>
  256. */
  257. #if defined(LWS_WITH_EVENT_LIBS)
  258. struct lws_plugin *evlib_plugin_list;
  259. void *evlib_ctx; /* overallocated */
  260. #endif
  261. #if defined(LWS_WITH_TLS)
  262. struct lws_context_tls tls;
  263. #endif
  264. #if defined(LWS_WITH_DRIVERS)
  265. lws_netdevs_t netdevs;
  266. #endif
  267. #if defined(LWS_WITH_SYS_ASYNC_DNS)
  268. lws_async_dns_t async_dns;
  269. #endif
  270. #if defined(LWS_WITH_SYS_NTPCLIENT)
  271. void *ntpclient_priv;
  272. #endif
  273. #if defined(LWS_WITH_SECURE_STREAMS)
  274. struct lws_ss_handle *hss_fetch_policy;
  275. #if defined(LWS_WITH_SECURE_STREAMS_SYS_AUTH_API_AMAZON_COM)
  276. struct lws_ss_handle *hss_auth;
  277. lws_sorted_usec_list_t sul_api_amazon_com;
  278. lws_sorted_usec_list_t sul_api_amazon_com_kick;
  279. #endif
  280. #if !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY)
  281. struct lws_ss_x509 *server_der_list;
  282. #endif
  283. #endif
  284. #if defined(LWS_WITH_SYS_STATE)
  285. lws_state_manager_t mgr_system;
  286. lws_state_notify_link_t protocols_notify;
  287. #endif
  288. #if defined (LWS_WITH_SYS_DHCP_CLIENT)
  289. lws_dll2_owner_t dhcpc_owner;
  290. /**< list of ifaces with dhcpc */
  291. #endif
  292. /* pointers */
  293. struct lws_vhost *vhost_list;
  294. struct lws_vhost *no_listener_vhost_list;
  295. struct lws_vhost *vhost_pending_destruction_list;
  296. struct lws_vhost *vhost_system;
  297. #if defined(LWS_WITH_SERVER)
  298. const char *server_string;
  299. #endif
  300. const struct lws_event_loop_ops *event_loop_ops;
  301. #endif
  302. #if defined(LWS_WITH_TLS)
  303. const struct lws_tls_ops *tls_ops;
  304. #endif
  305. #if defined(LWS_WITH_DETAILED_LATENCY)
  306. det_lat_buf_cb_t detailed_latency_cb;
  307. #endif
  308. #if defined(LWS_WITH_PLUGINS)
  309. struct lws_plugin *plugin_list;
  310. #endif
  311. #ifdef _WIN32
  312. /* different implementation between unix and windows */
  313. struct lws_fd_hashtable fd_hashtable[FD_HASHTABLE_MODULUS];
  314. #else
  315. struct lws **lws_lookup;
  316. #endif
  317. /*
  318. * <====== LWS_WITH_NETWORK end
  319. */
  320. #endif /* NETWORK */
  321. #if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)
  322. const char *ss_proxy_bind;
  323. const char *ss_proxy_address;
  324. #endif
  325. #if defined(LWS_WITH_FILE_OPS)
  326. const struct lws_plat_file_ops *fops;
  327. #endif
  328. struct lws_context **pcontext_finalize;
  329. #if !defined(LWS_PLAT_FREERTOS)
  330. const char *username, *groupname;
  331. #endif
  332. #if defined(LWS_WITH_DETAILED_LATENCY)
  333. const char *detailed_latency_filepath;
  334. #endif
  335. #if defined(LWS_AMAZON_RTOS) && defined(LWS_WITH_MBEDTLS)
  336. mbedtls_entropy_context mec;
  337. mbedtls_ctr_drbg_context mcdc;
  338. #endif
  339. struct lws_deferred_free *deferred_free_list;
  340. #if defined(LWS_WITH_THREADPOOL)
  341. struct lws_threadpool *tp_list_head;
  342. #endif
  343. #if defined(LWS_WITH_PEER_LIMITS)
  344. struct lws_peer **pl_hash_table;
  345. struct lws_peer *peer_wait_list;
  346. lws_peer_limits_notify_t pl_notify_cb;
  347. time_t next_cull;
  348. #endif
  349. const lws_system_ops_t *system_ops;
  350. #if defined(LWS_WITH_SECURE_STREAMS)
  351. #if !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY)
  352. const char *pss_policies_json;
  353. struct lwsac *ac_policy;
  354. void *pol_args;
  355. #endif
  356. const lws_ss_policy_t *pss_policies;
  357. #if defined(LWS_WITH_SSPLUGINS)
  358. const lws_ss_plugin_t **pss_plugins;
  359. #endif
  360. #endif
  361. void *external_baggage_free_on_destroy;
  362. const struct lws_token_limits *token_limits;
  363. void *user_space;
  364. #if defined(LWS_WITH_SERVER)
  365. const struct lws_protocol_vhost_options *reject_service_keywords;
  366. lws_reload_func deprecation_cb;
  367. #endif
  368. #if !defined(LWS_PLAT_FREERTOS)
  369. void (*eventlib_signal_cb)(void *event_lib_handle, int signum);
  370. #endif
  371. #if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP)
  372. cap_value_t caps[4];
  373. char count_caps;
  374. #endif
  375. lws_usec_t time_up; /* monotonic */
  376. uint64_t options;
  377. time_t last_ws_ping_pong_check_s;
  378. #if defined(LWS_PLAT_FREERTOS)
  379. unsigned long time_last_state_dump;
  380. uint32_t last_free_heap;
  381. #endif
  382. int max_fds;
  383. #if !defined(LWS_NO_DAEMONIZE)
  384. pid_t started_with_parent;
  385. #endif
  386. #if !defined(LWS_PLAT_FREERTOS)
  387. int uid, gid;
  388. int count_event_loop_static_asset_handles;
  389. int fd_random;
  390. int count_cgi_spawned;
  391. #endif
  392. #if defined(LWS_WITH_DETAILED_LATENCY)
  393. int latencies_fd;
  394. #endif
  395. int count_wsi_allocated;
  396. unsigned int fd_limit_per_thread;
  397. unsigned int timeout_secs;
  398. unsigned int pt_serv_buf_size;
  399. int max_http_header_data;
  400. int max_http_header_pool;
  401. int simultaneous_ssl_restriction;
  402. int simultaneous_ssl;
  403. #if defined(LWS_WITH_PEER_LIMITS)
  404. uint32_t pl_hash_elements; /* protected by context->lock */
  405. uint32_t count_peers; /* protected by context->lock */
  406. unsigned short ip_limit_ah;
  407. unsigned short ip_limit_wsi;
  408. #endif
  409. unsigned int deprecated:1;
  410. unsigned int inside_context_destroy:1;
  411. unsigned int being_destroyed:1;
  412. unsigned int being_destroyed1:1;
  413. unsigned int being_destroyed2:1;
  414. unsigned int requested_kill:1;
  415. unsigned int protocol_init_done:1;
  416. unsigned int doing_protocol_init:1;
  417. unsigned int done_protocol_destroy_cb:1;
  418. unsigned int finalize_destroy_after_internal_loops_stopped:1;
  419. unsigned int max_fds_unrelated_to_ulimit:1;
  420. unsigned int policy_updated:1;
  421. short count_threads;
  422. short plugin_protocol_count;
  423. short plugin_extension_count;
  424. short server_string_len;
  425. unsigned short deprecation_pending_listen_close_count;
  426. #if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)
  427. uint16_t ss_proxy_port;
  428. #endif
  429. uint8_t max_fi;
  430. uint8_t udp_loss_sim_tx_pc;
  431. uint8_t udp_loss_sim_rx_pc;
  432. uint8_t captive_portal_detect;
  433. uint8_t captive_portal_detect_type;
  434. #if defined(LWS_WITH_STATS)
  435. uint8_t updated;
  436. #endif
  437. };
  438. int
  439. lws_check_deferred_free(struct lws_context *context, int tsi, int force);
  440. #define lws_get_context_protocol(ctx, x) ctx->vhost_list->protocols[x]
  441. #define lws_get_vh_protocol(vh, x) vh->protocols[x]
  442. int
  443. lws_jws_base64_enc(const char *in, size_t in_len, char *out, size_t out_max);
  444. void
  445. lws_vhost_destroy1(struct lws_vhost *vh);
  446. #if defined(LWS_PLAT_FREERTOS)
  447. LWS_EXTERN int
  448. lws_find_string_in_file(const char *filename, const char *str, int stringlen);
  449. #endif
  450. signed char char_to_hex(const char c);
  451. #if defined(LWS_WITH_NETWORK)
  452. int
  453. lws_system_do_attach(struct lws_context_per_thread *pt);
  454. #endif
  455. struct lws_buflist {
  456. struct lws_buflist *next;
  457. size_t len;
  458. size_t pos;
  459. };
  460. LWS_EXTERN char *
  461. lws_strdup(const char *s);
  462. LWS_EXTERN int log_level;
  463. LWS_EXTERN int
  464. lws_b64_selftest(void);
  465. #ifndef LWS_NO_DAEMONIZE
  466. LWS_EXTERN pid_t get_daemonize_pid();
  467. #else
  468. #define get_daemonize_pid() (0)
  469. #endif
  470. LWS_EXTERN void lwsl_emit_stderr(int level, const char *line);
  471. #if !defined(LWS_WITH_TLS)
  472. #define LWS_SSL_ENABLED(context) (0)
  473. #define lws_context_init_server_ssl(_a, _b) (0)
  474. #define lws_ssl_destroy(_a)
  475. #define lws_context_init_alpn(_a)
  476. #define lws_ssl_capable_read lws_ssl_capable_read_no_ssl
  477. #define lws_ssl_capable_write lws_ssl_capable_write_no_ssl
  478. #define lws_ssl_pending lws_ssl_pending_no_ssl
  479. #define lws_server_socket_service_ssl(_b, _c, _d) (0)
  480. #define lws_ssl_close(_a) (0)
  481. #define lws_ssl_context_destroy(_a)
  482. #define lws_ssl_SSL_CTX_destroy(_a)
  483. #define lws_ssl_remove_wsi_from_buffered_list(_a)
  484. #define __lws_ssl_remove_wsi_from_buffered_list(_a)
  485. #define lws_context_init_ssl_library(_a)
  486. #define lws_context_deinit_ssl_library(_a)
  487. #define lws_tls_check_all_cert_lifetimes(_a)
  488. #define lws_tls_acme_sni_cert_destroy(_a)
  489. #endif
  490. #if LWS_MAX_SMP > 1
  491. #define lws_context_lock(c, reason) lws_mutex_refcount_lock(&c->mr, reason)
  492. #define lws_context_unlock(c) lws_mutex_refcount_unlock(&c->mr)
  493. static LWS_INLINE void
  494. lws_vhost_lock(struct lws_vhost *vhost)
  495. {
  496. pthread_mutex_lock(&vhost->lock);
  497. }
  498. static LWS_INLINE void
  499. lws_vhost_unlock(struct lws_vhost *vhost)
  500. {
  501. pthread_mutex_unlock(&vhost->lock);
  502. }
  503. #else
  504. #define lws_pt_mutex_init(_a) (void)(_a)
  505. #define lws_pt_mutex_destroy(_a) (void)(_a)
  506. #define lws_pt_lock(_a, b) (void)(_a)
  507. #define lws_pt_assert_lock_held(_a) (void)(_a)
  508. #define lws_pt_unlock(_a) (void)(_a)
  509. #define lws_context_lock(_a, _b) (void)(_a)
  510. #define lws_context_unlock(_a) (void)(_a)
  511. #define lws_vhost_lock(_a) (void)(_a)
  512. #define lws_vhost_unlock(_a) (void)(_a)
  513. #define lws_pt_stats_lock(_a) (void)(_a)
  514. #define lws_pt_stats_unlock(_a) (void)(_a)
  515. #endif
  516. LWS_EXTERN int LWS_WARN_UNUSED_RESULT
  517. lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len);
  518. LWS_EXTERN int LWS_WARN_UNUSED_RESULT
  519. lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len);
  520. LWS_EXTERN int LWS_WARN_UNUSED_RESULT
  521. lws_ssl_pending_no_ssl(struct lws *wsi);
  522. int
  523. lws_tls_check_cert_lifetime(struct lws_vhost *vhost);
  524. int lws_jws_selftest(void);
  525. int lws_jwe_selftest(void);
  526. int
  527. lws_protocol_init(struct lws_context *context);
  528. int
  529. lws_bind_protocol(struct lws *wsi, const struct lws_protocols *p,
  530. const char *reason);
  531. const struct lws_protocol_vhost_options *
  532. lws_vhost_protocol_options(struct lws_vhost *vh, const char *name);
  533. const struct lws_http_mount *
  534. lws_find_mount(struct lws *wsi, const char *uri_ptr, int uri_len);
  535. /*
  536. * custom allocator
  537. */
  538. LWS_EXTERN void *
  539. lws_realloc(void *ptr, size_t size, const char *reason);
  540. LWS_EXTERN void * LWS_WARN_UNUSED_RESULT
  541. lws_zalloc(size_t size, const char *reason);
  542. #ifdef LWS_PLAT_OPTEE
  543. void *lws_malloc(size_t size, const char *reason);
  544. void lws_free(void *p);
  545. #define lws_free_set_NULL(P) do { lws_free(P); (P) = NULL; } while(0)
  546. #else
  547. #define lws_malloc(S, R) lws_realloc(NULL, S, R)
  548. #define lws_free(P) lws_realloc(P, 0, "lws_free")
  549. #define lws_free_set_NULL(P) do { lws_realloc(P, 0, "free"); (P) = NULL; } while(0)
  550. #endif
  551. int
  552. lws_create_event_pipes(struct lws_context *context);
  553. int
  554. lws_plat_apply_FD_CLOEXEC(int n);
  555. const struct lws_plat_file_ops *
  556. lws_vfs_select_fops(const struct lws_plat_file_ops *fops, const char *vfs_path,
  557. const char **vpath);
  558. /* lws_plat_ */
  559. LWS_EXTERN int
  560. lws_plat_context_early_init(void);
  561. LWS_EXTERN void
  562. lws_plat_context_early_destroy(struct lws_context *context);
  563. LWS_EXTERN void
  564. lws_plat_context_late_destroy(struct lws_context *context);
  565. LWS_EXTERN int
  566. lws_plat_init(struct lws_context *context,
  567. const struct lws_context_creation_info *info);
  568. LWS_EXTERN int
  569. lws_plat_drop_app_privileges(struct lws_context *context, int actually_drop);
  570. #if defined(LWS_WITH_UNIX_SOCK) && !defined(WIN32)
  571. int
  572. lws_plat_user_colon_group_to_ids(const char *u_colon_g, uid_t *puid, gid_t *pgid);
  573. #endif
  574. int
  575. lws_plat_ntpclient_config(struct lws_context *context);
  576. int
  577. lws_plat_ifname_to_hwaddr(int fd, const char *ifname, uint8_t *hwaddr, int len);
  578. LWS_EXTERN int
  579. lws_check_byte_utf8(unsigned char state, unsigned char c);
  580. LWS_EXTERN int LWS_WARN_UNUSED_RESULT
  581. lws_check_utf8(unsigned char *state, unsigned char *buf, size_t len);
  582. LWS_EXTERN int alloc_file(struct lws_context *context, const char *filename,
  583. uint8_t **buf, lws_filepos_t *amount);
  584. void lws_msleep(unsigned int);
  585. void
  586. lws_context_destroy2(struct lws_context *context);
  587. #if !defined(PRIu64)
  588. #define PRIu64 "llu"
  589. #endif
  590. #if defined(LWS_WITH_ABSTRACT)
  591. #include "private-lib-abstract.h"
  592. #endif
  593. #ifdef __cplusplus
  594. };
  595. #endif
  596. #endif