diff --git a/.gitignore b/.gitignore index 1a120e10..db59c006 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ config.sub ar-lib libwebsockets.pc build/ +*.swp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d166874..69dc6733 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,13 @@ set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSIO set(CPACK_PACKAGE_VENDOR "andy@warmcat.com") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${PACKAGE_VERSION}") set(SOVERSION "9") +if(NOT CPACK_GENERATOR) + if(UNIX) + set(CPACK_GENERATOR "TGZ") + else() + set(CPACK_GENERATOR "ZIP") + endif() +endif() set(CPACK_SOURCE_GENERATOR "TGZ") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") set(VERSION "${CPACK_PACKAGE_VERSION}") diff --git a/doc/html/libwebsockets_8h_source.html b/doc/html/libwebsockets_8h_source.html index c4d41f7c..583181ce 100644 --- a/doc/html/libwebsockets_8h_source.html +++ b/doc/html/libwebsockets_8h_source.html @@ -71,7 +71,7 @@ $(document).ready(function(){initNavTree('libwebsockets_8h_source.html','');});
libwebsockets.h
-Go to the documentation of this file.
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010-2016 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 
24 #ifndef LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C
25 #define LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C
26 
27 #ifdef __cplusplus
28 #include <cstddef>
29 #include <cstdarg>
30 #ifdef MBED_OPERATORS
31 #include "mbed-drivers/mbed.h"
32 #include "sal-iface-eth/EthernetInterface.h"
33 #include "sockets/TCPListener.h"
34 #include "sal-stack-lwip/lwipv4_init.h"
35 
36 namespace {
37 }
38 using namespace mbed::Sockets::v0;
39 
40 
41 struct sockaddr_in;
42 struct lws;
43 
44 class lws_conn {
45  public:
46  lws_conn():
47  ts(NULL),
48  wsi(NULL),
49  writeable(1),
50  awaiting_on_writeable(0)
51  {
52  }
53 
54 public:
55  void set_wsi(struct lws *_wsi) { wsi = _wsi; }
56  int actual_onRX(Socket *s);
57  void onRX(Socket *s);
58  void onError(Socket *s, socket_error_t err);
59  void onDisconnect(TCPStream *s);
60  void onSent(Socket *s, uint16_t len);
61  void serialized_writeable(struct lws *wsi);
62 
63 public:
64  TCPStream *ts;
65 
66 public:
67  struct lws *wsi;
68  char writeable;
69  char awaiting_on_writeable;
70 };
71 
73 public:
75  srv(SOCKET_STACK_LWIP_IPV4)
76  {
77  srv.setOnError(TCPStream::ErrorHandler_t(this,
79  }
80 
81  void start(const uint16_t port);
83 protected:
84  void onRX(Socket *s);
85  void onError(Socket *s, socket_error_t err);
86  void onIncoming(TCPListener *s, void *impl);
87  void onDisconnect(TCPStream *s);
89 public:
90  TCPListener srv;
91 };
92 
93 #endif
94 
95 extern "C" {
96 #else
97 #include <stdarg.h>
98 #endif
99 
100 #if defined(MBED_OPERATORS) || defined(LWS_WITH_ESP8266)
101 struct sockaddr_in;
102 #define LWS_POSIX 0
103 #else
104 #define LWS_POSIX 1
105 #endif
106 
107 #include "lws_config.h"
108 
109 #if defined(WIN32) || defined(_WIN32)
110 #ifndef WIN32_LEAN_AND_MEAN
111 #define WIN32_LEAN_AND_MEAN
112 #endif
113 
114 #include <winsock2.h>
115 #include <ws2tcpip.h>
116 #include <stddef.h>
117 #include <basetsd.h>
118 #ifndef _WIN32_WCE
119 #include <fcntl.h>
120 #else
121 #define _O_RDONLY 0x0000
122 #define O_RDONLY _O_RDONLY
123 #endif
124 
125 // Visual studio older than 2015 and WIN_CE has only _stricmp
126 #if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(_WIN32_WCE)
127 #define strcasecmp _stricmp
128 #else
129 #define strcasecmp stricmp
130 #endif
131 #define getdtablesize() 30000
132 
133 #define LWS_INLINE __inline
134 #define LWS_VISIBLE
135 #define LWS_WARN_UNUSED_RESULT
136 #define LWS_WARN_DEPRECATED
137 
138 #ifdef LWS_DLL
139 #ifdef LWS_INTERNAL
140 #define LWS_EXTERN extern __declspec(dllexport)
141 #else
142 #define LWS_EXTERN extern __declspec(dllimport)
143 #endif
144 #else
145 #define LWS_EXTERN
146 #endif
147 
148 #define LWS_INVALID_FILE INVALID_HANDLE_VALUE
149 #define LWS_O_RDONLY _O_RDONLY
150 
151 #if !defined(_MSC_VER) || _MSC_VER < 1900 /* Visual Studio 2015 already defines this in <stdio.h> */
152 #define lws_snprintf _snprintf
153 #endif
154 
155 #ifndef __func__
156 #define __func__ __FUNCTION__
157 #endif
158 
159 #else /* NOT WIN32 */
160 #include <unistd.h>
161 
162 #if defined(__NetBSD__) || defined(__FreeBSD__)
163 #include <netinet/in.h>
164 #endif
165 
166 #define LWS_INLINE inline
167 #define LWS_O_RDONLY O_RDONLY
168 
169 #if !defined(MBED_OPERATORS) && !defined(LWS_WITH_ESP8266)
170 #include <poll.h>
171 #include <netdb.h>
172 #define LWS_INVALID_FILE -1
173 #else
174 #define getdtablesize() (20)
175 #define LWS_INVALID_FILE NULL
176 #endif
177 
178 #if defined(__GNUC__)
179 
180 /* warn_unused_result attribute only supported by GCC 3.4 or later */
181 #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
182 #define LWS_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
183 #else
184 #define LWS_WARN_UNUSED_RESULT
185 #endif
186 
187 #define LWS_VISIBLE __attribute__((visibility("default")))
188 #define LWS_WARN_DEPRECATED __attribute__ ((deprecated))
189 #else
190 #define LWS_VISIBLE
191 #define LWS_WARN_UNUSED_RESULT
192 #define LWS_WARN_DEPRECATED
193 #endif
194 
195 #if defined(__ANDROID__)
196 #include <unistd.h>
197 #define getdtablesize() sysconf(_SC_OPEN_MAX)
198 #endif
199 
200 #endif
201 
202 #ifdef LWS_USE_LIBEV
203 #include <ev.h>
204 #endif /* LWS_USE_LIBEV */
205 #ifdef LWS_USE_LIBUV
206 #include <uv.h>
207 #ifdef LWS_HAVE_UV_VERSION_H
208 #include <uv-version.h>
209 #endif
210 #endif /* LWS_USE_LIBUV */
211 
212 #ifndef LWS_EXTERN
213 #define LWS_EXTERN extern
214 #endif
215 
216 #ifdef _WIN32
217 #define random rand
218 #else
219 #include <sys/time.h>
220 #include <unistd.h>
221 #endif
222 
223 #ifdef LWS_OPENSSL_SUPPORT
224 
225 #ifdef USE_WOLFSSL
226 #ifdef USE_OLD_CYASSL
227 #include <cyassl/openssl/ssl.h>
228 #include <cyassl/error-ssl.h>
229 #else
230 #include <wolfssl/openssl/ssl.h>
231 #include <wolfssl/error-ssl.h>
232 #endif /* not USE_OLD_CYASSL */
233 #else
234 #if defined(LWS_USE_POLARSSL)
235 #include <polarssl/ssl.h>
237  x509_crt ca;
238  x509_crt certificate;
239  rsa_context key;
240 };
241 typedef struct lws_polarssl_context SSL_CTX;
242 typedef ssl_context SSL;
243 #else
244 #if defined(LWS_USE_MBEDTLS)
245 #include <mbedtls/ssl.h>
246 #else
247 #include <openssl/ssl.h>
248 #include <openssl/err.h>
249 #endif /* not USE_MBEDTLS */
250 #endif /* not USE_POLARSSL */
251 #endif /* not USE_WOLFSSL */
252 #endif
253 
254 
255 #define CONTEXT_PORT_NO_LISTEN -1
256 
267 
269 enum lws_log_levels {
270  LLL_ERR = 1 << 0,
271  LLL_WARN = 1 << 1,
272  LLL_NOTICE = 1 << 2,
273  LLL_INFO = 1 << 3,
274  LLL_DEBUG = 1 << 4,
275  LLL_PARSER = 1 << 5,
276  LLL_HEADER = 1 << 6,
277  LLL_EXT = 1 << 7,
278  LLL_CLIENT = 1 << 8,
279  LLL_LATENCY = 1 << 9,
280 
281  LLL_COUNT = 10 /* set to count of valid flags */
282 };
283 
284 LWS_VISIBLE LWS_EXTERN void _lws_log(int filter, const char *format, ...);
285 LWS_VISIBLE LWS_EXTERN void _lws_logv(int filter, const char *format, va_list vl);
295 LWS_VISIBLE LWS_EXTERN int
296 lwsl_timestamp(int level, char *p, int len);
297 
298 #define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__)
299 
300 #if !defined(LWS_WITH_NO_LOGS)
301 /* notice, warn and log are always compiled in */
302 #define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__)
303 #define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__)
304 #endif
305 /*
306  * weaker logging can be deselected at configure time using --disable-debug
307  * that gets rid of the overhead of checking while keeping _warn and _err
308  * active
309  */
310 
311 #if defined(LWS_WITH_ESP8266)
312 #undef _DEBUG
313 #endif
314 
315 #ifdef _DEBUG
316 #if defined(LWS_WITH_NO_LOGS)
317 /* notice, warn and log are always compiled in */
318 //#define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__)
319 #define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__)
320 #define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__)
321 #endif
322 #define lwsl_info(...) _lws_log(LLL_INFO, __VA_ARGS__)
323 #define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__)
324 #define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__)
325 #define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__)
326 #define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__)
327 #define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__)
328 #define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__)
329 
335 LWS_VISIBLE LWS_EXTERN void lwsl_hexdump(void *buf, size_t len);
336 
337 #else /* no debug */
338 #if defined(LWS_WITH_NO_LOGS)
339 //#define lwsl_err(...) do {} while(0)
340 #define lwsl_warn(...) do {} while(0)
341 #define lwsl_notice(...) do {} while(0)
342 #endif
343 #define lwsl_info(...) do {} while(0)
344 #define lwsl_debug(...) do {} while(0)
345 #define lwsl_parser(...) do {} while(0)
346 #define lwsl_header(...) do {} while(0)
347 #define lwsl_ext(...) do {} while(0)
348 #define lwsl_client(...) do {} while(0)
349 #define lwsl_latency(...) do {} while(0)
350 #define lwsl_hexdump(a, b)
351 
352 #endif
353 
364 LWS_VISIBLE LWS_EXTERN void
365 lws_set_log_level(int level,
366  void (*log_emit_function)(int level, const char *line));
367 
377 LWS_VISIBLE LWS_EXTERN void
378 lwsl_emit_syslog(int level, const char *line);
379 
381 
382 
383 #include <stddef.h>
384 
385 #ifndef lws_container_of
386 #define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M)))
387 #endif
388 
389 
390 struct lws;
391 #ifndef ARRAY_SIZE
392 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
393 #endif
394 
395 /* api change list for user code to test against */
396 
397 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
398 
399 /* the struct lws_protocols has the id field present */
400 #define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
401 
402 /* you can call lws_get_peer_write_allowance */
403 #define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
404 
405 /* extra parameter introduced in 917f43ab821 */
406 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
407 
408 /* File operations stuff exists */
409 #define LWS_FEATURE_FOPS
410 
411 
412 #if defined(_WIN32)
413 typedef SOCKET lws_sockfd_type;
414 typedef HANDLE lws_filefd_type;
415 #define lws_sockfd_valid(sfd) (!!sfd)
416 struct lws_pollfd {
417  lws_sockfd_type fd;
418  SHORT events;
419  SHORT revents;
420 };
421 #define LWS_POLLHUP (FD_CLOSE)
422 #define LWS_POLLIN (FD_READ | FD_ACCEPT)
423 #define LWS_POLLOUT (FD_WRITE)
424 #else
425 
426 #if defined(MBED_OPERATORS)
427 /* it's a class lws_conn * */
428 typedef void * lws_sockfd_type;
429 typedef void * lws_filefd_type;
430 #define lws_sockfd_valid(sfd) (!!sfd)
431 struct pollfd {
432  lws_sockfd_type fd;
433  short events;
434  short revents;
435 };
436 #define POLLIN 0x0001
437 #define POLLPRI 0x0002
438 #define POLLOUT 0x0004
439 #define POLLERR 0x0008
440 #define POLLHUP 0x0010
441 #define POLLNVAL 0x0020
442 
443 struct lws;
444 
445 void * mbed3_create_tcp_stream_socket(void);
446 void mbed3_delete_tcp_stream_socket(void *sockfd);
447 void mbed3_tcp_stream_bind(void *sock, int port, struct lws *);
448 void mbed3_tcp_stream_accept(void *sock, struct lws *);
449 #else
450 #if defined(LWS_WITH_ESP8266)
451 
452 #include <user_interface.h>
453 #include <espconn.h>
454 
455 typedef struct espconn * lws_sockfd_type;
456 typedef void * lws_filefd_type;
457 #define lws_sockfd_valid(sfd) (!!sfd)
458 struct pollfd {
459  lws_sockfd_type fd;
460  short events;
461  short revents;
462 };
463 #define POLLIN 0x0001
464 #define POLLPRI 0x0002
465 #define POLLOUT 0x0004
466 #define POLLERR 0x0008
467 #define POLLHUP 0x0010
468 #define POLLNVAL 0x0020
469 
470 struct lws_vhost;
471 
472 lws_sockfd_type esp8266_create_tcp_listen_socket(struct lws_vhost *vh);
473 void esp8266_tcp_stream_accept(lws_sockfd_type fd, struct lws *wsi);
474 
475 #include <os_type.h>
476 #include <osapi.h>
477 #include "ets_sys.h"
478 
479 int ets_snprintf(char *str, size_t size, const char *format, ...);
480 #define snprintf ets_snprintf
481 
482 typedef os_timer_t uv_timer_t;
483 typedef void uv_cb_t(uv_timer_t *);
484 
485 void os_timer_disarm(void *);
486 void os_timer_setfn(os_timer_t *, os_timer_func_t *, void *);
487 
488 void ets_timer_arm_new(os_timer_t *, int, int, int);
489 
490 //void os_timer_arm(os_timer_t *, int, int);
491 
492 #define UV_VERSION_MAJOR 1
493 
494 #define lws_uv_getloop(a, b) (NULL)
495 
496 static inline void uv_timer_init(void *l, uv_timer_t *t)
497 {
498  (void)l;
499  memset(t, 0, sizeof(*t));
500  os_timer_disarm(t);
501 }
502 
503 static inline void uv_timer_start(uv_timer_t *t, uv_cb_t *cb, int first, int rep)
504 {
505  os_timer_setfn(t, (os_timer_func_t *)cb, t);
506  /* ms, repeat */
507  os_timer_arm(t, first, !!rep);
508 }
509 
510 static inline void uv_timer_stop(uv_timer_t *t)
511 {
512  os_timer_disarm(t);
513 }
514 
515 #else
516 typedef int lws_sockfd_type;
517 typedef int lws_filefd_type;
518 #define lws_sockfd_valid(sfd) (sfd >= 0)
519 #endif
520 #endif
521 
522 #define lws_pollfd pollfd
523 #define LWS_POLLHUP (POLLHUP|POLLERR)
524 #define LWS_POLLIN (POLLIN)
525 #define LWS_POLLOUT (POLLOUT)
526 #endif
527 
530 struct lws_pollargs {
531  lws_sockfd_type fd;
532  int events;
534 };
535 
536 struct lws_tokens;
537 struct lws_token_limits;
538 
546 
548 /*
549  * NOTE: These public enums are part of the abi. If you want to add one,
550  * add it at where specified so existing users are unaffected.
551  */
554  LWS_CLOSE_STATUS_NOSTATUS = 0,
616  /****** add new things just above ---^ ******/
617 
618  LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY = 9999,
619 };
620 
633 LWS_VISIBLE LWS_EXTERN void
634 lws_close_reason(struct lws *wsi, enum lws_close_status status,
635  unsigned char *buf, size_t len);
636 
638 
639 struct lws;
640 struct lws_context;
641 /* needed even with extensions disabled for create context */
642 struct lws_extension;
643 
655 
657 
658 /*
659  * NOTE: These public enums are part of the abi. If you want to add one,
660  * add it at where specified so existing users are unaffected.
661  */
905  /* external poll() management support */
968  LWS_CALLBACK_WS_EXT_DEFAULTS = 39,
971  LWS_CALLBACK_CGI = 40,
973  LWS_CALLBACK_CGI_TERMINATED = 41,
975  LWS_CALLBACK_CGI_STDIN_DATA = 42,
977  LWS_CALLBACK_CGI_STDIN_COMPLETED = 43,
979  LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP = 44,
981  LWS_CALLBACK_CLOSED_CLIENT_HTTP = 45,
983  LWS_CALLBACK_RECEIVE_CLIENT_HTTP = 46,
985  LWS_CALLBACK_COMPLETED_CLIENT_HTTP = 47,
987  LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ = 48,
989  LWS_CALLBACK_HTTP_BIND_PROTOCOL = 49,
991  LWS_CALLBACK_HTTP_DROP_PROTOCOL = 50,
993  LWS_CALLBACK_CHECK_ACCESS_RIGHTS = 51,
995  LWS_CALLBACK_PROCESS_HTML = 52,
997  LWS_CALLBACK_ADD_HEADERS = 53,
999  LWS_CALLBACK_SESSION_INFO = 54,
1002  LWS_CALLBACK_GS_EVENT = 55,
1019  /****** add new things just above ---^ ******/
1020 
1023 };
1024 
1025 
1026 
1042 typedef int
1043 lws_callback_function(struct lws *wsi, enum lws_callback_reasons reason,
1044  void *user, void *in, size_t len);
1046 
1056 
1058 /*
1059  * NOTE: These public enums are part of the abi. If you want to add one,
1060  * add it at where specified so existing users are unaffected.
1061  */
1062 enum lws_extension_callback_reasons {
1063  LWS_EXT_CB_SERVER_CONTEXT_CONSTRUCT = 0,
1064  LWS_EXT_CB_CLIENT_CONTEXT_CONSTRUCT = 1,
1065  LWS_EXT_CB_SERVER_CONTEXT_DESTRUCT = 2,
1066  LWS_EXT_CB_CLIENT_CONTEXT_DESTRUCT = 3,
1067  LWS_EXT_CB_CONSTRUCT = 4,
1068  LWS_EXT_CB_CLIENT_CONSTRUCT = 5,
1069  LWS_EXT_CB_CHECK_OK_TO_REALLY_CLOSE = 6,
1070  LWS_EXT_CB_CHECK_OK_TO_PROPOSE_EXTENSION = 7,
1071  LWS_EXT_CB_DESTROY = 8,
1072  LWS_EXT_CB_DESTROY_ANY_WSI_CLOSING = 9,
1073  LWS_EXT_CB_ANY_WSI_ESTABLISHED = 10,
1074  LWS_EXT_CB_PACKET_RX_PREPARSE = 11,
1075  LWS_EXT_CB_PACKET_TX_PRESEND = 12,
1076  LWS_EXT_CB_PACKET_TX_DO_SEND = 13,
1077  LWS_EXT_CB_HANDSHAKE_REPLY_TX = 14,
1078  LWS_EXT_CB_FLUSH_PENDING_TX = 15,
1079  LWS_EXT_CB_EXTENDED_PAYLOAD_RX = 16,
1080  LWS_EXT_CB_CAN_PROXY_CLIENT_CONNECTION = 17,
1081  LWS_EXT_CB_1HZ = 18,
1082  LWS_EXT_CB_REQUEST_ON_WRITEABLE = 19,
1083  LWS_EXT_CB_IS_WRITEABLE = 20,
1084  LWS_EXT_CB_PAYLOAD_TX = 21,
1085  LWS_EXT_CB_PAYLOAD_RX = 22,
1086  LWS_EXT_CB_OPTION_DEFAULT = 23,
1087  LWS_EXT_CB_OPTION_SET = 24,
1088  LWS_EXT_CB_OPTION_CONFIRM = 25,
1089  LWS_EXT_CB_NAMED_OPTION_SET = 26,
1090 
1091  /****** add new things just above ---^ ******/
1092 };
1093 
1100  /* Add new things just above here ---^
1101  * This is part of the ABI, don't needlessly break compatibility */
1102 };
1103 
1109  const char *name;
1112  /* Add new things just above here ---^
1113  * This is part of the ABI, don't needlessly break compatibility */
1114 };
1115 
1118  const char *option_name;
1120  const char *start;
1121  int len;
1122 };
1123 
1184 typedef int
1185 lws_extension_callback_function(struct lws_context *context,
1186  const struct lws_extension *ext, struct lws *wsi,
1187  enum lws_extension_callback_reasons reason,
1188  void *user, void *in, size_t len);
1189 
1192  const char *name;
1194  const char *client_offer;
1196  /* Add new things just above here ---^
1197  * This is part of the ABI, don't needlessly break compatibility */
1198 };
1199 
1208 LWS_VISIBLE LWS_EXTERN int
1209 lws_set_extension_option(struct lws *wsi, const char *ext_name,
1210  const char *opt_name, const char *opt_val);
1211 
1212 #ifndef LWS_NO_EXTENSIONS
1213 /* lws_get_internal_extensions() - DEPRECATED
1214  *
1215  * \Deprecated There is no longer a set internal extensions table. The table is provided
1216  * by user code along with application-specific settings. See the test
1217  * client and server for how to do.
1218  */
1219 static LWS_INLINE LWS_WARN_DEPRECATED const struct lws_extension *
1220 lws_get_internal_extensions(void) { return NULL; }
1221 
1232 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1233 lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi,
1234  void *ext_user, const struct lws_ext_options *opts,
1235  const char *o, int len);
1236 #endif
1237 
1250 LWS_EXTERN
1252  struct lws_context *context, const struct lws_extension *ext,
1253  struct lws *wsi, enum lws_extension_callback_reasons reason,
1254  void *user, void *in, size_t len);
1255 
1256 /*
1257  * The internal exts are part of the public abi
1258  * If we add more extensions, publish the callback here ------v
1259  */
1261 
1277 
1282  const char *name;
1303  unsigned int id;
1310  void *user;
1313  /* Add new things just above here ---^
1314  * This is part of the ABI, don't needlessly break compatibility */
1315 };
1316 
1317 struct lws_vhost;
1318 
1327 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
1328 lws_vhost_name_to_protocol(struct lws_vhost *vh, const char *name);
1329 
1339 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
1340 lws_get_protocol(struct lws *wsi);
1341 
1343 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
1344 lws_protocol_get(struct lws *wsi) LWS_WARN_DEPRECATED;
1345 
1356 LWS_VISIBLE LWS_EXTERN void *
1357 lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost, const struct lws_protocols *prot,
1358  int size);
1359 
1369 LWS_VISIBLE LWS_EXTERN void *
1370 lws_protocol_vh_priv_get(struct lws_vhost *vhost, const struct lws_protocols *prot);
1371 
1380 LWS_VISIBLE LWS_EXTERN int
1381 lws_finalize_startup(struct lws_context *context);
1382 
1383 #ifdef LWS_WITH_PLUGINS
1384 
1385 /* PLUGINS implies LIBUV */
1386 
1387 #define LWS_PLUGIN_API_MAGIC 180
1388 
1391  unsigned int api_magic;
1392  const struct lws_protocols *protocols;
1394  const struct lws_extension *extensions;
1396 };
1397 
1398 typedef int (*lws_plugin_init_func)(struct lws_context *,
1399  struct lws_plugin_capability *);
1400 typedef int (*lws_plugin_destroy_func)(struct lws_context *);
1401 
1403 struct lws_plugin {
1404  struct lws_plugin *list;
1405 #if (UV_VERSION_MAJOR > 0)
1406  uv_lib_t lib;
1407 #else
1408  void *l;
1409 #endif
1410  char name[64];
1412 };
1413 
1414 #endif
1415 
1417 
1418 
1427 
1429 #define LWSGS_EMAIL_CONTENT_SIZE 16384
1430 
1432 /* SHA-1 binary and hexified versions */
1434 typedef struct { unsigned char bin[20]; } lwsgw_hash_bin;
1436 typedef struct { char id[41]; } lwsgw_hash;
1437 
1444 };
1445 
1448  char username[32];
1449  char email[100];
1450  char ip[72];
1451  unsigned int mask;
1453  char session[42];
1454 };
1455 
1460 };
1461 
1464  enum lws_gs_event event;
1465  const char *username;
1466  const char *email;
1467 };
1468 
1470 
1471 
1485 
1487 /*
1488  * NOTE: These public enums are part of the abi. If you want to add one,
1489  * add it at where specified so existing users are unaffected.
1490  */
1491 
1495  (1 << 12),
1502  (1 << 12),
1518  (1 << 12),
1523  (1 << 12),
1547  /****** add new things just above ---^ ******/
1548 };
1549 
1550 #define lws_check_opt(c, f) (((c) & (f)) == (f))
1551 
1562  int port;
1567  const char *iface;
1574  const struct lws_protocols *protocols;
1578  const struct lws_extension *extensions;
1586  const char *ssl_cert_filepath;
1596  const char *ssl_ca_filepath;
1598  const char *ssl_cipher_list;
1602  const char *http_proxy_address;
1605  unsigned int http_proxy_port;
1607  int gid;
1609  int uid;
1611  unsigned int options;
1613  void *user;
1616  int ka_time;
1626 #ifdef LWS_OPENSSL_SUPPORT
1632 #else /* maintain structure layout either way */
1634 #endif
1635 
1646  unsigned int count_threads;
1648  unsigned int fd_limit_per_thread;
1652  unsigned int timeout_secs;
1657  const char *ecdh_curve;
1659  const char *vhost_name;
1663  const char * const *plugin_dirs;
1672  const char *log_filepath;
1675  const struct lws_http_mount *mounts;
1677  const char *server_string;
1680  unsigned int pt_serv_buf_size;
1695  unsigned short ws_ping_pong_interval;
1719  /* Add new things just above here ---^
1720  * This is part of the ABI, don't needlessly break compatibility
1721  *
1722  * The below is to ensure later library versions with new
1723  * members added above will see 0 (default) even if the app
1724  * was not built against the newer headers.
1725  */
1726 
1727  void *_unused[8];
1728 };
1729 
1764 LWS_VISIBLE LWS_EXTERN struct lws_context *
1766 
1775 LWS_VISIBLE LWS_EXTERN void
1776 lws_context_destroy(struct lws_context *context);
1777 
1795 LWS_VISIBLE LWS_EXTERN int
1796 lws_set_proxy(struct lws_vhost *vhost, const char *proxy);
1797 
1798 
1799 struct lws_vhost;
1800 
1810 LWS_EXTERN LWS_VISIBLE struct lws_vhost *
1811 lws_create_vhost(struct lws_context *context,
1812  struct lws_context_creation_info *info);
1813 
1828 LWS_VISIBLE LWS_EXTERN int
1829 lwsws_get_config_globals(struct lws_context_creation_info *info, const char *d,
1830  char **config_strings, int *len);
1831 
1847 LWS_VISIBLE LWS_EXTERN int
1848 lwsws_get_config_vhosts(struct lws_context *context,
1849  struct lws_context_creation_info *info, const char *d,
1850  char **config_strings, int *len);
1851 
1853 LWS_VISIBLE LWS_EXTERN struct lws_vhost *
1854 lws_vhost_get(struct lws *wsi) LWS_WARN_DEPRECATED;
1855 
1861 LWS_VISIBLE LWS_EXTERN struct lws_vhost *
1862 lws_get_vhost(struct lws *wsi);
1863 
1871 LWS_VISIBLE LWS_EXTERN int
1872 lws_json_dump_vhost(const struct lws_vhost *vh, char *buf, int len);
1873 
1881 LWS_VISIBLE LWS_EXTERN int
1882 lws_json_dump_context(const struct lws_context *context, char *buf, int len);
1883 
1893 LWS_VISIBLE LWS_EXTERN void *
1894 lws_context_user(struct lws_context *context);
1895 
1901 
1911  const char *name;
1912  const char *value;
1913 };
1914 
1927 };
1928 
1936  const char *mountpoint;
1938  const char *origin;
1940  const char *def;
1942  const char *protocol;
1958  unsigned int auth_mask;
1961  unsigned int cache_reusable:1;
1962  unsigned int cache_revalidate:1;
1963  unsigned int cache_intermediaries:1;
1965  unsigned char origin_protocol;
1966  unsigned char mountpoint_len;
1967 };
1970 
1976 
1984  LCCSCF_USE_SSL = (1 << 0),
1985  LCCSCF_ALLOW_SELFSIGNED = (1 << 1),
1986  LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK = (1 << 2)
1987 };
1988 
1993  struct lws_context *context;
1995  const char *address;
1997  int port;
2001  const char *path;
2003  const char *host;
2005  const char *origin;
2007  const char *protocol;
2011  void *userdata;
2015  const char *method;
2018  struct lws *parent_wsi;
2022  const char *uri_replace_from;
2025  const char *uri_replace_to;
2027  struct lws_vhost *vhost;
2029  struct lws **pwsi;
2041  /* Add new things just above here ---^
2042  * This is part of the ABI, don't needlessly break compatibility
2043  *
2044  * The below is to ensure later library versions with new
2045  * members added above will see 0 (default) even if the app
2046  * was not built against the newer headers.
2047  */
2048 
2049  void *_unused[4];
2050 };
2051 
2059 LWS_VISIBLE LWS_EXTERN struct lws *
2061 
2082 /* deprecated, use lws_client_connect_via_info() */
2083 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
2084 lws_client_connect(struct lws_context *clients, const char *address,
2085  int port, int ssl_connection, const char *path,
2086  const char *host, const char *origin, const char *protocol,
2087  int ietf_version_or_minus_one) LWS_WARN_DEPRECATED;
2088 /* deprecated, use lws_client_connect_via_info() */
2109 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
2110 lws_client_connect_extended(struct lws_context *clients, const char *address,
2111  int port, int ssl_connection, const char *path,
2112  const char *host, const char *origin,
2113  const char *protocol, int ietf_version_or_minus_one,
2114  void *userdata) LWS_WARN_DEPRECATED;
2115 
2141 LWS_VISIBLE LWS_EXTERN int
2143  struct lws_vhost *vhost);
2144 
2145 LWS_VISIBLE LWS_EXTERN int
2146 lws_http_client_read(struct lws *wsi, char **buf, int *len);
2147 
2155 LWS_VISIBLE LWS_EXTERN unsigned int
2156 lws_http_client_http_response(struct lws *wsi);
2157 
2158 LWS_VISIBLE LWS_EXTERN void
2159 lws_client_http_body_pending(struct lws *wsi, int something_left_to_send);
2160 
2181 
2190 
2223 LWS_VISIBLE LWS_EXTERN int
2224 lws_service(struct lws_context *context, int timeout_ms);
2225 
2237 LWS_VISIBLE LWS_EXTERN int
2238 lws_service_tsi(struct lws_context *context, int timeout_ms, int tsi);
2239 
2255 LWS_VISIBLE LWS_EXTERN void
2256 lws_cancel_service_pt(struct lws *wsi);
2257 
2269 LWS_VISIBLE LWS_EXTERN void
2270 lws_cancel_service(struct lws_context *context);
2271 
2298 LWS_VISIBLE LWS_EXTERN int
2299 lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd);
2300 
2310 LWS_VISIBLE LWS_EXTERN int
2311 lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,
2312  int tsi);
2313 
2331 LWS_VISIBLE LWS_EXTERN int
2332 lws_service_adjust_timeout(struct lws_context *context, int timeout_ms, int tsi);
2333 
2334 /* Backwards compatibility */
2335 #define lws_plat_service_tsi lws_service_tsi
2336 
2338 
2344 
2351 
2363 LWS_VISIBLE LWS_EXTERN const char *
2364 lws_get_mimetype(const char *file, const struct lws_http_mount *m);
2365 
2384 LWS_VISIBLE LWS_EXTERN int
2385 lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type,
2386  const char *other_headers, int other_headers_len);
2387 LWS_VISIBLE LWS_EXTERN int
2388 lws_serve_http_file_fragment(struct lws *wsi);
2390 
2401 
2402 enum http_status {
2403  HTTP_STATUS_OK = 200,
2404  HTTP_STATUS_NO_CONTENT = 204,
2405 
2406  HTTP_STATUS_MOVED_PERMANENTLY = 301,
2407  HTTP_STATUS_FOUND = 302,
2408  HTTP_STATUS_SEE_OTHER = 303,
2409 
2410  HTTP_STATUS_BAD_REQUEST = 400,
2411  HTTP_STATUS_UNAUTHORIZED,
2412  HTTP_STATUS_PAYMENT_REQUIRED,
2413  HTTP_STATUS_FORBIDDEN,
2414  HTTP_STATUS_NOT_FOUND,
2415  HTTP_STATUS_METHOD_NOT_ALLOWED,
2416  HTTP_STATUS_NOT_ACCEPTABLE,
2417  HTTP_STATUS_PROXY_AUTH_REQUIRED,
2418  HTTP_STATUS_REQUEST_TIMEOUT,
2419  HTTP_STATUS_CONFLICT,
2420  HTTP_STATUS_GONE,
2421  HTTP_STATUS_LENGTH_REQUIRED,
2422  HTTP_STATUS_PRECONDITION_FAILED,
2423  HTTP_STATUS_REQ_ENTITY_TOO_LARGE,
2424  HTTP_STATUS_REQ_URI_TOO_LONG,
2425  HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE,
2426  HTTP_STATUS_REQ_RANGE_NOT_SATISFIABLE,
2427  HTTP_STATUS_EXPECTATION_FAILED,
2428 
2429  HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,
2430  HTTP_STATUS_NOT_IMPLEMENTED,
2431  HTTP_STATUS_BAD_GATEWAY,
2432  HTTP_STATUS_SERVICE_UNAVAILABLE,
2433  HTTP_STATUS_GATEWAY_TIMEOUT,
2434  HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED,
2435 };
2436 
2438  char *p;
2439  int len;
2440  int max_len;
2441  int final;
2442 };
2443 
2444 typedef const char *(*lws_process_html_state_cb)(void *data, int index);
2445 
2447  char *start;
2448  char swallow[16];
2449  int pos;
2450  void *data;
2451  const char * const *vars;
2454  lws_process_html_state_cb replace;
2455 };
2456 
2461 LWS_VISIBLE LWS_EXTERN int
2463  struct lws_process_html_state *s);
2465 
2498 
2506 struct lws_tokens {
2507  char *token;
2509 };
2510 
2511 /* enum lws_token_indexes
2512  * these have to be kept in sync with lextable.h / minilex.c
2513  *
2514  * NOTE: These public enums are part of the abi. If you want to add one,
2515  * add it at where specified so existing users are unaffected.
2516  */
2517 enum lws_token_indexes {
2518  WSI_TOKEN_GET_URI = 0,
2519  WSI_TOKEN_POST_URI = 1,
2520  WSI_TOKEN_OPTIONS_URI = 2,
2521  WSI_TOKEN_HOST = 3,
2522  WSI_TOKEN_CONNECTION = 4,
2523  WSI_TOKEN_UPGRADE = 5,
2524  WSI_TOKEN_ORIGIN = 6,
2525  WSI_TOKEN_DRAFT = 7,
2526  WSI_TOKEN_CHALLENGE = 8,
2527  WSI_TOKEN_EXTENSIONS = 9,
2528  WSI_TOKEN_KEY1 = 10,
2529  WSI_TOKEN_KEY2 = 11,
2530  WSI_TOKEN_PROTOCOL = 12,
2531  WSI_TOKEN_ACCEPT = 13,
2532  WSI_TOKEN_NONCE = 14,
2533  WSI_TOKEN_HTTP = 15,
2534  WSI_TOKEN_HTTP2_SETTINGS = 16,
2535  WSI_TOKEN_HTTP_ACCEPT = 17,
2536  WSI_TOKEN_HTTP_AC_REQUEST_HEADERS = 18,
2537  WSI_TOKEN_HTTP_IF_MODIFIED_SINCE = 19,
2538  WSI_TOKEN_HTTP_IF_NONE_MATCH = 20,
2539  WSI_TOKEN_HTTP_ACCEPT_ENCODING = 21,
2540  WSI_TOKEN_HTTP_ACCEPT_LANGUAGE = 22,
2541  WSI_TOKEN_HTTP_PRAGMA = 23,
2542  WSI_TOKEN_HTTP_CACHE_CONTROL = 24,
2543  WSI_TOKEN_HTTP_AUTHORIZATION = 25,
2544  WSI_TOKEN_HTTP_COOKIE = 26,
2545  WSI_TOKEN_HTTP_CONTENT_LENGTH = 27,
2546  WSI_TOKEN_HTTP_CONTENT_TYPE = 28,
2547  WSI_TOKEN_HTTP_DATE = 29,
2548  WSI_TOKEN_HTTP_RANGE = 30,
2549  WSI_TOKEN_HTTP_REFERER = 31,
2550  WSI_TOKEN_KEY = 32,
2551  WSI_TOKEN_VERSION = 33,
2552  WSI_TOKEN_SWORIGIN = 34,
2553 
2554  WSI_TOKEN_HTTP_COLON_AUTHORITY = 35,
2555  WSI_TOKEN_HTTP_COLON_METHOD = 36,
2556  WSI_TOKEN_HTTP_COLON_PATH = 37,
2557  WSI_TOKEN_HTTP_COLON_SCHEME = 38,
2558  WSI_TOKEN_HTTP_COLON_STATUS = 39,
2559 
2560  WSI_TOKEN_HTTP_ACCEPT_CHARSET = 40,
2561  WSI_TOKEN_HTTP_ACCEPT_RANGES = 41,
2562  WSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN = 42,
2563  WSI_TOKEN_HTTP_AGE = 43,
2564  WSI_TOKEN_HTTP_ALLOW = 44,
2565  WSI_TOKEN_HTTP_CONTENT_DISPOSITION = 45,
2566  WSI_TOKEN_HTTP_CONTENT_ENCODING = 46,
2567  WSI_TOKEN_HTTP_CONTENT_LANGUAGE = 47,
2568  WSI_TOKEN_HTTP_CONTENT_LOCATION = 48,
2569  WSI_TOKEN_HTTP_CONTENT_RANGE = 49,
2570  WSI_TOKEN_HTTP_ETAG = 50,
2571  WSI_TOKEN_HTTP_EXPECT = 51,
2572  WSI_TOKEN_HTTP_EXPIRES = 52,
2573  WSI_TOKEN_HTTP_FROM = 53,
2574  WSI_TOKEN_HTTP_IF_MATCH = 54,
2575  WSI_TOKEN_HTTP_IF_RANGE = 55,
2576  WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE = 56,
2577  WSI_TOKEN_HTTP_LAST_MODIFIED = 57,
2578  WSI_TOKEN_HTTP_LINK = 58,
2579  WSI_TOKEN_HTTP_LOCATION = 59,
2580  WSI_TOKEN_HTTP_MAX_FORWARDS = 60,
2581  WSI_TOKEN_HTTP_PROXY_AUTHENTICATE = 61,
2582  WSI_TOKEN_HTTP_PROXY_AUTHORIZATION = 62,
2583  WSI_TOKEN_HTTP_REFRESH = 63,
2584  WSI_TOKEN_HTTP_RETRY_AFTER = 64,
2585  WSI_TOKEN_HTTP_SERVER = 65,
2586  WSI_TOKEN_HTTP_SET_COOKIE = 66,
2587  WSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY = 67,
2588  WSI_TOKEN_HTTP_TRANSFER_ENCODING = 68,
2589  WSI_TOKEN_HTTP_USER_AGENT = 69,
2590  WSI_TOKEN_HTTP_VARY = 70,
2591  WSI_TOKEN_HTTP_VIA = 71,
2592  WSI_TOKEN_HTTP_WWW_AUTHENTICATE = 72,
2593 
2594  WSI_TOKEN_PATCH_URI = 73,
2595  WSI_TOKEN_PUT_URI = 74,
2596  WSI_TOKEN_DELETE_URI = 75,
2597 
2598  WSI_TOKEN_HTTP_URI_ARGS = 76,
2599  WSI_TOKEN_PROXY = 77,
2600  WSI_TOKEN_HTTP_X_REAL_IP = 78,
2601  WSI_TOKEN_HTTP1_0 = 79,
2602 
2603  /****** add new things just above ---^ ******/
2604 
2605  /* use token storage to stash these internally, not for
2606  * user use */
2607 
2608  _WSI_TOKEN_CLIENT_SENT_PROTOCOLS,
2609  _WSI_TOKEN_CLIENT_PEER_ADDRESS,
2610  _WSI_TOKEN_CLIENT_URI,
2611  _WSI_TOKEN_CLIENT_HOST,
2612  _WSI_TOKEN_CLIENT_ORIGIN,
2613  _WSI_TOKEN_CLIENT_METHOD,
2614 
2615  /* always last real token index*/
2616  WSI_TOKEN_COUNT,
2617 
2618  /* parser state additions, no storage associated */
2619  WSI_TOKEN_NAME_PART,
2620  WSI_TOKEN_SKIPPING,
2621  WSI_TOKEN_SKIPPING_SAW_CR,
2622  WSI_PARSING_COMPLETE,
2623  WSI_INIT_TOKEN_MUXURL,
2624 };
2625 
2627  unsigned short token_limit[WSI_TOKEN_COUNT];
2628 };
2629 
2635 LWS_VISIBLE LWS_EXTERN const unsigned char *
2636 lws_token_to_string(enum lws_token_indexes token);
2637 
2638 
2647 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2648 lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h);
2649 
2659 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2660 lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx);
2661 
2675 LWS_VISIBLE LWS_EXTERN int
2676 lws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h);
2677 
2695 LWS_VISIBLE LWS_EXTERN int
2696 lws_hdr_copy_fragment(struct lws *wsi, char *dest, int len,
2697  enum lws_token_indexes h, int frag_idx);
2698 
2709 LWS_VISIBLE LWS_EXTERN const char *
2710 lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, int len);
2712 
2727 
2738 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2739 lws_add_http_header_status(struct lws *wsi,
2740  unsigned int code, unsigned char **p,
2741  unsigned char *end);
2754 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2755 lws_add_http_header_by_name(struct lws *wsi, const unsigned char *name,
2756  const unsigned char *value, int length,
2757  unsigned char **p, unsigned char *end);
2771 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2772 lws_add_http_header_by_token(struct lws *wsi, enum lws_token_indexes token,
2773  const unsigned char *value, int length,
2774  unsigned char **p, unsigned char *end);
2785 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2786 lws_add_http_header_content_length(struct lws *wsi,
2787  unsigned long content_length,
2788  unsigned char **p, unsigned char *end);
2798 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2799 lws_finalize_http_header(struct lws *wsi, unsigned char **p,
2800  unsigned char *end);
2802 
2821 
2831 };
2832 
2846 typedef int (*lws_spa_fileupload_cb)(void *data, const char *name,
2847  const char *filename, char *buf, int len,
2848  enum lws_spa_fileupload_states state);
2849 
2852 struct lws_spa;
2853 
2872 LWS_VISIBLE LWS_EXTERN struct lws_spa *
2873 lws_spa_create(struct lws *wsi, const char * const *param_names,
2874  int count_params, int max_storage, lws_spa_fileupload_cb opt_cb,
2875  void *opt_data);
2876 
2884 LWS_VISIBLE LWS_EXTERN int
2885 lws_spa_process(struct lws_spa *spa, const char *in, int len);
2886 
2892 LWS_VISIBLE LWS_EXTERN int
2893 lws_spa_finalize(struct lws_spa *spa);
2894 
2901 LWS_VISIBLE LWS_EXTERN int
2902 lws_spa_get_length(struct lws_spa *spa, int n);
2903 
2909 LWS_VISIBLE LWS_EXTERN const char *
2910 lws_spa_get_string(struct lws_spa *spa, int n);
2911 
2917 LWS_VISIBLE LWS_EXTERN int
2918 lws_spa_destroy(struct lws_spa *spa);
2920 
2931 
2942 LWS_VISIBLE LWS_EXTERN const char *
2943 lws_urlencode(char *escaped, const char *string, int len);
2944 
2945 /*
2946  * URLDECODE 1 / 2
2947  *
2948  * This simple urldecode only operates until the first '\0' and requires the
2949  * data to exist all at once
2950  */
2963 LWS_VISIBLE LWS_EXTERN int
2964 lws_urldecode(char *string, const char *escaped, int len);
2966 
2975 LWS_VISIBLE LWS_EXTERN int
2976 lws_return_http_status(struct lws *wsi, unsigned int code,
2977  const char *html_body);
2978 
2989 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2990 lws_http_redirect(struct lws *wsi, int code, const unsigned char *loc, int len,
2991  unsigned char **p, unsigned char *end);
2992 
3001 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3002 lws_http_transaction_completed(struct lws *wsi);
3004 
3012 
3023 LWS_VISIBLE LWS_EXTERN const char *
3024 lws_sql_purify(char *escaped, const char *string, int len);
3025 
3036 LWS_VISIBLE LWS_EXTERN const char *
3037 lws_json_purify(char *escaped, const char *string, int len);
3039 
3046 
3048 #ifdef LWS_USE_LIBEV
3049 typedef void (lws_ev_signal_cb_t)(EV_P_ struct ev_signal *w, int revents);
3050 
3051 LWS_VISIBLE LWS_EXTERN int
3052 lws_ev_sigint_cfg(struct lws_context *context, int use_ev_sigint,
3053  lws_ev_signal_cb_t *cb);
3054 
3055 LWS_VISIBLE LWS_EXTERN int
3056 lws_ev_initloop(struct lws_context *context, struct ev_loop *loop, int tsi);
3057 
3058 LWS_VISIBLE LWS_EXTERN void
3059 lws_ev_sigint_cb(struct ev_loop *loop, struct ev_signal *watcher, int revents);
3060 #endif /* LWS_USE_LIBEV */
3061 
3063 
3070 #ifdef LWS_USE_LIBUV
3072 LWS_VISIBLE LWS_EXTERN int
3073 lws_uv_sigint_cfg(struct lws_context *context, int use_uv_sigint,
3074  uv_signal_cb cb);
3075 
3076 LWS_VISIBLE LWS_EXTERN void
3077 lws_libuv_run(const struct lws_context *context, int tsi);
3078 
3079 LWS_VISIBLE LWS_EXTERN void
3080 lws_libuv_stop(struct lws_context *context);
3081 
3082 LWS_VISIBLE LWS_EXTERN int
3083 lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi);
3084 
3085 LWS_VISIBLE LWS_EXTERN uv_loop_t *
3086 lws_uv_getloop(struct lws_context *context, int tsi);
3087 
3088 LWS_VISIBLE LWS_EXTERN void
3089 lws_uv_sigint_cb(uv_signal_t *watcher, int signum);
3090 #endif /* LWS_USE_LIBUV */
3091 
3098 
3099 /*
3100  * NOTE: These public enums are part of the abi. If you want to add one,
3101  * add it at where specified so existing users are unaffected.
3102  */
3103 enum pending_timeout {
3104  NO_PENDING_TIMEOUT = 0,
3105  PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE = 1,
3106  PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE = 2,
3107  PENDING_TIMEOUT_ESTABLISH_WITH_SERVER = 3,
3108  PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE = 4,
3109  PENDING_TIMEOUT_AWAITING_PING = 5,
3110  PENDING_TIMEOUT_CLOSE_ACK = 6,
3111  PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE = 7,
3112  PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE = 8,
3113  PENDING_TIMEOUT_SSL_ACCEPT = 9,
3114  PENDING_TIMEOUT_HTTP_CONTENT = 10,
3115  PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND = 11,
3116  PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE = 12,
3117  PENDING_TIMEOUT_SHUTDOWN_FLUSH = 13,
3118  PENDING_TIMEOUT_CGI = 14,
3119  PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE = 15,
3120  PENDING_TIMEOUT_WS_PONG_CHECK_SEND_PING = 16,
3121  PENDING_TIMEOUT_WS_PONG_CHECK_GET_PONG = 17,
3122  PENDING_TIMEOUT_CLIENT_ISSUE_PAYLOAD = 18,
3123 
3124  /****** add new things just above ---^ ******/
3125 };
3126 
3136 LWS_VISIBLE LWS_EXTERN void
3137 lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs);
3139 
3145 #if !defined(LWS_SIZEOFPTR)
3146 #define LWS_SIZEOFPTR (sizeof (void *))
3147 #endif
3148 #if !defined(u_int64_t)
3149 #define u_int64_t unsigned long long
3150 #endif
3151 
3152 #if defined(__x86_64__)
3153 #define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */
3154 #else
3155 #define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target arch */
3156 #endif
3157 #define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
3158  ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
3159 #define LWS_PRE _LWS_PAD(4 + 10)
3160 /* used prior to 1.7 and retained for backward compatibility */
3161 #define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
3162 #define LWS_SEND_BUFFER_POST_PADDING 0
3163 
3164 /*
3165  * NOTE: These public enums are part of the abi. If you want to add one,
3166  * add it at where specified so existing users are unaffected.
3167  */
3182  /* LWS_WRITE_CLOSE is handled by lws_close_reason() */
3183  LWS_WRITE_PING = 5,
3184  LWS_WRITE_PONG = 6,
3185 
3186  /* Same as write_http but we know this write ends the transaction */
3187  LWS_WRITE_HTTP_FINAL = 7,
3188 
3189  /* HTTP2 */
3190 
3198  /****** add new things just above ---^ ******/
3199 
3200  /* flags */
3201 
3209 };
3210 
3211 
3298 LWS_VISIBLE LWS_EXTERN int
3299 lws_write(struct lws *wsi, unsigned char *buf, size_t len,
3300  enum lws_write_protocol protocol);
3301 
3302 /* helper for case where buffer may be const */
3303 #define lws_write_http(wsi, buf, len) \
3304  lws_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP)
3305 
3325 
3338 LWS_VISIBLE LWS_EXTERN int
3339 lws_callback_on_writable(struct lws *wsi);
3340 
3354 LWS_VISIBLE LWS_EXTERN int
3355 lws_callback_on_writable_all_protocol(const struct lws_context *context,
3356  const struct lws_protocols *protocol);
3357 
3371 LWS_VISIBLE LWS_EXTERN int
3372 lws_callback_on_writable_all_protocol_vhost(const struct lws_vhost *vhost,
3373  const struct lws_protocols *protocol);
3374 
3387 LWS_VISIBLE LWS_EXTERN int
3388 lws_callback_all_protocol(struct lws_context *context,
3389  const struct lws_protocols *protocol, int reason);
3390 
3403 LWS_VISIBLE LWS_EXTERN int
3404 lws_callback_all_protocol_vhost(struct lws_vhost *vh,
3405  const struct lws_protocols *protocol, int reason);
3406 
3420 LWS_VISIBLE LWS_EXTERN int
3421 lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len);
3422 
3423 LWS_VISIBLE LWS_EXTERN int
3424 lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
3425  void *user, void *in, size_t len);
3426 
3434 LWS_VISIBLE LWS_EXTERN int
3435 lws_get_socket_fd(struct lws *wsi);
3436 
3458 LWS_VISIBLE LWS_EXTERN size_t
3459 lws_get_peer_write_allowance(struct lws *wsi);
3461 
3472 LWS_VISIBLE LWS_EXTERN int
3473 lws_rx_flow_control(struct lws *wsi, int enable);
3474 
3484 LWS_VISIBLE LWS_EXTERN void
3485 lws_rx_flow_allow_all_protocol(const struct lws_context *context,
3486  const struct lws_protocols *protocol);
3487 
3504 LWS_VISIBLE LWS_EXTERN size_t
3505 lws_remaining_packet_payload(struct lws *wsi);
3506 
3507 
3516 
3529 LWS_VISIBLE LWS_EXTERN struct lws *
3530 lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd);
3553 LWS_VISIBLE LWS_EXTERN struct lws *
3554 lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd,
3555  const char *readbuf, size_t len);
3557 
3563 
3574 LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
3575 lws_canonical_hostname(struct lws_context *context);
3576 
3591 LWS_VISIBLE LWS_EXTERN void
3592 lws_get_peer_addresses(struct lws *wsi, lws_sockfd_type fd, char *name,
3593  int name_len, char *rip, int rip_len);
3594 
3605 LWS_VISIBLE LWS_EXTERN const char *
3606 lws_get_peer_simple(struct lws *wsi, char *name, int namelen);
3607 #ifndef LWS_WITH_ESP8266
3608 
3619 LWS_VISIBLE LWS_EXTERN int
3620 lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr,
3621  size_t addrlen);
3623 #endif
3624 
3630 
3643 LWS_VISIBLE LWS_EXTERN int
3644 lws_snprintf(char *str, size_t size, const char *format, ...);
3645 
3657 LWS_VISIBLE LWS_EXTERN int
3658 lws_get_random(struct lws_context *context, void *buf, int len);
3666 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3667 lws_daemonize(const char *_lock_path);
3673 LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
3675 
3682 LWS_VISIBLE LWS_EXTERN void *
3683 lws_wsi_user(struct lws *wsi);
3684 
3696 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3697 lws_parse_uri(char *p, const char **prot, const char **ads, int *port,
3698  const char **path);
3699 
3703 LWS_VISIBLE LWS_EXTERN unsigned long
3704 lws_now_secs(void);
3705 
3715 LWS_VISIBLE LWS_EXTERN struct lws_context * LWS_WARN_UNUSED_RESULT
3716 lws_get_context(const struct lws *wsi);
3717 
3727 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3728 lws_get_count_threads(struct lws_context *context);
3729 
3737 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
3738 lws_get_parent(const struct lws *wsi);
3739 
3746 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
3747 lws_get_child(const struct lws *wsi);
3748 
3749 
3750 /*
3751  * \deprecated DEPRECATED Note: this is not normally needed as a user api.
3752  * It's provided in case it is
3753  * useful when integrating with other app poll loop service code.
3754  */
3755 LWS_VISIBLE LWS_EXTERN int
3756 lws_read(struct lws *wsi, unsigned char *buf, size_t len);
3757 
3765 LWS_VISIBLE LWS_EXTERN void
3766 lws_set_allocator(void *(*realloc)(void *ptr, size_t size));
3768 
3774 
3781 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3782 lws_send_pipe_choked(struct lws *wsi);
3783 
3788 LWS_VISIBLE LWS_EXTERN int
3789 lws_is_final_fragment(struct lws *wsi);
3790 
3795 LWS_VISIBLE LWS_EXTERN unsigned char
3796 lws_get_reserved_bits(struct lws *wsi);
3797 
3814 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3815 lws_partial_buffered(struct lws *wsi);
3816 
3826 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3827 lws_frame_is_binary(struct lws *wsi);
3828 
3837 LWS_VISIBLE LWS_EXTERN int
3838 lws_is_ssl(struct lws *wsi);
3843 LWS_VISIBLE LWS_EXTERN int
3844 lws_is_cgi(struct lws *wsi);
3846 
3847 
3853 #ifdef LWS_SHA1_USE_OPENSSL_NAME
3855 #define lws_SHA1 SHA1
3856 #else
3857 
3866 LWS_VISIBLE LWS_EXTERN unsigned char *
3867 lws_SHA1(const unsigned char *d, size_t n, unsigned char *md);
3868 #endif
3869 
3879 LWS_VISIBLE LWS_EXTERN int
3880 lws_b64_encode_string(const char *in, int in_len, char *out, int out_size);
3890 LWS_VISIBLE LWS_EXTERN int
3891 lws_b64_decode_string(const char *in, char *out, int out_size);
3893 
3894 
3904 #ifdef LWS_WITH_CGI
3905 enum lws_enum_stdinouterr {
3906  LWS_STDIN = 0,
3907  LWS_STDOUT = 1,
3908  LWS_STDERR = 2,
3909 };
3910 
3911 enum lws_cgi_hdr_state {
3912  LCHS_HEADER,
3913  LCHS_CR1,
3914  LCHS_LF1,
3915  LCHS_CR2,
3916  LCHS_LF2,
3917  LHCS_PAYLOAD,
3918  LCHS_SINGLE_0A,
3919 };
3920 
3922  struct lws **stdwsi;
3923  enum lws_enum_stdinouterr ch;
3924  unsigned char *data;
3925  enum lws_cgi_hdr_state hdr_state;
3926  int len;
3927 };
3928 
3929 
3939 LWS_VISIBLE LWS_EXTERN int
3940 lws_cgi(struct lws *wsi, const char * const *exec_array,
3941  int script_uri_path_len, int timeout_secs,
3942  const struct lws_protocol_vhost_options *mp_cgienv);
3943 
3949 LWS_VISIBLE LWS_EXTERN int
3950 lws_cgi_write_split_stdout_headers(struct lws *wsi);
3951 
3957 LWS_VISIBLE LWS_EXTERN int
3958 lws_cgi_kill(struct lws *wsi);
3959 #endif
3960 
3962 
3979 
3986  lws_filefd_type (*open)(struct lws *wsi, const char *filename,
3987  unsigned long *filelen, int flags);
3991  int (*close)(struct lws *wsi, lws_filefd_type fd);
3993  unsigned long (*seek_cur)(struct lws *wsi, lws_filefd_type fd,
3994  long offset_from_cur_pos);
3996  int (*read)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
3997  unsigned char *buf, unsigned long len);
3999  int (*write)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
4000  unsigned char *buf, unsigned long len);
4003  /* Add new things just above here ---^
4004  * This is part of the ABI, don't needlessly break compatibility */
4005 };
4006 
4012 LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops * LWS_WARN_UNUSED_RESULT
4013 lws_get_fops(struct lws_context *context);
4014 
4023 static LWS_INLINE lws_filefd_type LWS_WARN_UNUSED_RESULT
4024 lws_plat_file_open(struct lws *wsi, const char *filename,
4025  unsigned long *filelen, int flags)
4026 {
4027  return lws_get_fops(lws_get_context(wsi))->open(wsi, filename,
4028  filelen, flags);
4029 }
4030 
4037 static LWS_INLINE int
4038 lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
4039 {
4040  return lws_get_fops(lws_get_context(wsi))->close(wsi, fd);
4041 }
4042 
4050 static LWS_INLINE unsigned long
4051 lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
4052 {
4053  return lws_get_fops(lws_get_context(wsi))->seek_cur(wsi, fd, offset);
4054 }
4064 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
4065 lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
4066  unsigned char *buf, unsigned long len)
4067 {
4068  return lws_get_fops(lws_get_context(wsi))->read(wsi, fd, amount, buf,
4069  len);
4070 }
4080 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
4081 lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
4082  unsigned char *buf, unsigned long len)
4083 {
4084  return lws_get_fops(lws_get_context(wsi))->write(wsi, fd, amount, buf,
4085  len);
4086 }
4088 
4120 #ifdef LWS_WITH_SMTP
4121 
4133 };
4134 
4136 struct lws_email {
4137  void *data;
4139  uv_loop_t *loop;
4142  char email_smtp_ip[32];
4143  char email_helo[32];
4144  char email_from[100];
4145  char email_to[100];
4147  unsigned int max_content_size;
4150  /* Fill all the callbacks before init */
4151 
4152  int (*on_next)(struct lws_email *email);
4157  int (*on_sent)(struct lws_email *email);
4162  int (*on_get_body)(struct lws_email *email, char *buf, int len);
4168  /* private things */
4169  uv_timer_t timeout_email;
4171  uv_connect_t email_connect_req;
4172  uv_tcp_t email_client;
4174  char email_buf[256];
4175  char *content;
4176 };
4177 
4187 LWS_VISIBLE LWS_EXTERN int
4188 lws_email_init(struct lws_email *email, uv_loop_t *loop, int max_content);
4189 
4198 LWS_VISIBLE LWS_EXTERN void
4199 lws_email_check(struct lws_email *email);
4207 LWS_VISIBLE LWS_EXTERN void
4208 lws_email_destroy(struct lws_email *email);
4209 
4210 #endif
4211 
4212 
4213 #ifdef __cplusplus
4214 }
4215 #endif
4216 
4217 #endif
LWS_VISIBLE LWS_EXTERN int lws_spa_destroy(struct lws_spa *spa)
+Go to the documentation of this file.
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010-2016 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 
24 #ifndef LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C
25 #define LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C
26 
27 #ifdef __cplusplus
28 #include <cstddef>
29 #include <cstdarg>
30 #ifdef MBED_OPERATORS
31 #include "mbed-drivers/mbed.h"
32 #include "sal-iface-eth/EthernetInterface.h"
33 #include "sockets/TCPListener.h"
34 #include "sal-stack-lwip/lwipv4_init.h"
35 
36 namespace {
37 }
38 using namespace mbed::Sockets::v0;
39 
40 
41 struct sockaddr_in;
42 struct lws;
43 
44 class lws_conn {
45  public:
46  lws_conn():
47  ts(NULL),
48  wsi(NULL),
49  writeable(1),
50  awaiting_on_writeable(0)
51  {
52  }
53 
54 public:
55  void set_wsi(struct lws *_wsi) { wsi = _wsi; }
56  int actual_onRX(Socket *s);
57  void onRX(Socket *s);
58  void onError(Socket *s, socket_error_t err);
59  void onDisconnect(TCPStream *s);
60  void onSent(Socket *s, uint16_t len);
61  void serialized_writeable(struct lws *wsi);
62 
63 public:
64  TCPStream *ts;
65 
66 public:
67  struct lws *wsi;
68  char writeable;
69  char awaiting_on_writeable;
70 };
71 
73 public:
75  srv(SOCKET_STACK_LWIP_IPV4)
76  {
77  srv.setOnError(TCPStream::ErrorHandler_t(this,
79  }
80 
81  void start(const uint16_t port);
83 protected:
84  void onRX(Socket *s);
85  void onError(Socket *s, socket_error_t err);
86  void onIncoming(TCPListener *s, void *impl);
87  void onDisconnect(TCPStream *s);
89 public:
90  TCPListener srv;
91 };
92 
93 #endif
94 
95 extern "C" {
96 #else
97 #include <stdarg.h>
98 #endif
99 
100 #if defined(MBED_OPERATORS) || defined(LWS_WITH_ESP8266)
101 struct sockaddr_in;
102 #define LWS_POSIX 0
103 #else
104 #define LWS_POSIX 1
105 #endif
106 
107 #include "lws_config.h"
108 
109 #if defined(WIN32) || defined(_WIN32)
110 #ifndef WIN32_LEAN_AND_MEAN
111 #define WIN32_LEAN_AND_MEAN
112 #endif
113 
114 #include <winsock2.h>
115 #include <ws2tcpip.h>
116 #include <stddef.h>
117 #include <basetsd.h>
118 #ifndef _WIN32_WCE
119 #include <fcntl.h>
120 #else
121 #define _O_RDONLY 0x0000
122 #define O_RDONLY _O_RDONLY
123 #endif
124 
125 // Visual studio older than 2015 and WIN_CE has only _stricmp
126 #if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(_WIN32_WCE)
127 #define strcasecmp _stricmp
128 #elif !defined(__MINGW32__)
129 #define strcasecmp stricmp
130 #endif
131 #define getdtablesize() 30000
132 
133 #define LWS_INLINE __inline
134 #define LWS_VISIBLE
135 #define LWS_WARN_UNUSED_RESULT
136 #define LWS_WARN_DEPRECATED
137 
138 #ifdef LWS_DLL
139 #ifdef LWS_INTERNAL
140 #define LWS_EXTERN extern __declspec(dllexport)
141 #else
142 #define LWS_EXTERN extern __declspec(dllimport)
143 #endif
144 #else
145 #define LWS_EXTERN
146 #endif
147 
148 #define LWS_INVALID_FILE INVALID_HANDLE_VALUE
149 #define LWS_O_RDONLY _O_RDONLY
150 
151 #if !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER < 1900) /* Visual Studio 2015 already defines this in <stdio.h> */
152 #define lws_snprintf _snprintf
153 #endif
154 
155 #ifndef __func__
156 #define __func__ __FUNCTION__
157 #endif
158 
159 #else /* NOT WIN32 */
160 #include <unistd.h>
161 
162 #if defined(__NetBSD__) || defined(__FreeBSD__)
163 #include <netinet/in.h>
164 #endif
165 
166 #define LWS_INLINE inline
167 #define LWS_O_RDONLY O_RDONLY
168 
169 #if !defined(MBED_OPERATORS) && !defined(LWS_WITH_ESP8266)
170 #include <poll.h>
171 #include <netdb.h>
172 #define LWS_INVALID_FILE -1
173 #else
174 #define getdtablesize() (20)
175 #define LWS_INVALID_FILE NULL
176 #endif
177 
178 #if defined(__GNUC__)
179 
180 /* warn_unused_result attribute only supported by GCC 3.4 or later */
181 #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
182 #define LWS_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
183 #else
184 #define LWS_WARN_UNUSED_RESULT
185 #endif
186 
187 #define LWS_VISIBLE __attribute__((visibility("default")))
188 #define LWS_WARN_DEPRECATED __attribute__ ((deprecated))
189 #else
190 #define LWS_VISIBLE
191 #define LWS_WARN_UNUSED_RESULT
192 #define LWS_WARN_DEPRECATED
193 #endif
194 
195 #if defined(__ANDROID__)
196 #include <unistd.h>
197 #define getdtablesize() sysconf(_SC_OPEN_MAX)
198 #endif
199 
200 #endif
201 
202 #ifdef LWS_USE_LIBEV
203 #include <ev.h>
204 #endif /* LWS_USE_LIBEV */
205 #ifdef LWS_USE_LIBUV
206 #include <uv.h>
207 #ifdef LWS_HAVE_UV_VERSION_H
208 #include <uv-version.h>
209 #endif
210 #endif /* LWS_USE_LIBUV */
211 
212 #ifndef LWS_EXTERN
213 #define LWS_EXTERN extern
214 #endif
215 
216 #ifdef _WIN32
217 #define random rand
218 #else
219 #include <sys/time.h>
220 #include <unistd.h>
221 #endif
222 
223 #ifdef LWS_OPENSSL_SUPPORT
224 
225 #ifdef USE_WOLFSSL
226 #ifdef USE_OLD_CYASSL
227 #include <cyassl/openssl/ssl.h>
228 #include <cyassl/error-ssl.h>
229 #else
230 #include <wolfssl/openssl/ssl.h>
231 #include <wolfssl/error-ssl.h>
232 #endif /* not USE_OLD_CYASSL */
233 #else
234 #if defined(LWS_USE_POLARSSL)
235 #include <polarssl/ssl.h>
237  x509_crt ca;
238  x509_crt certificate;
239  rsa_context key;
240 };
241 typedef struct lws_polarssl_context SSL_CTX;
242 typedef ssl_context SSL;
243 #else
244 #if defined(LWS_USE_MBEDTLS)
245 #include <mbedtls/ssl.h>
246 #else
247 #include <openssl/ssl.h>
248 #include <openssl/err.h>
249 #endif /* not USE_MBEDTLS */
250 #endif /* not USE_POLARSSL */
251 #endif /* not USE_WOLFSSL */
252 #endif
253 
254 
255 #define CONTEXT_PORT_NO_LISTEN -1
256 
267 
269 enum lws_log_levels {
270  LLL_ERR = 1 << 0,
271  LLL_WARN = 1 << 1,
272  LLL_NOTICE = 1 << 2,
273  LLL_INFO = 1 << 3,
274  LLL_DEBUG = 1 << 4,
275  LLL_PARSER = 1 << 5,
276  LLL_HEADER = 1 << 6,
277  LLL_EXT = 1 << 7,
278  LLL_CLIENT = 1 << 8,
279  LLL_LATENCY = 1 << 9,
280 
281  LLL_COUNT = 10 /* set to count of valid flags */
282 };
283 
284 LWS_VISIBLE LWS_EXTERN void _lws_log(int filter, const char *format, ...);
285 LWS_VISIBLE LWS_EXTERN void _lws_logv(int filter, const char *format, va_list vl);
295 LWS_VISIBLE LWS_EXTERN int
296 lwsl_timestamp(int level, char *p, int len);
297 
298 #define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__)
299 
300 #if !defined(LWS_WITH_NO_LOGS)
301 /* notice, warn and log are always compiled in */
302 #define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__)
303 #define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__)
304 #endif
305 /*
306  * weaker logging can be deselected at configure time using --disable-debug
307  * that gets rid of the overhead of checking while keeping _warn and _err
308  * active
309  */
310 
311 #if defined(LWS_WITH_ESP8266)
312 #undef _DEBUG
313 #endif
314 
315 #ifdef _DEBUG
316 #if defined(LWS_WITH_NO_LOGS)
317 /* notice, warn and log are always compiled in */
318 //#define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__)
319 #define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__)
320 #define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__)
321 #endif
322 #define lwsl_info(...) _lws_log(LLL_INFO, __VA_ARGS__)
323 #define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__)
324 #define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__)
325 #define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__)
326 #define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__)
327 #define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__)
328 #define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__)
329 
335 LWS_VISIBLE LWS_EXTERN void lwsl_hexdump(void *buf, size_t len);
336 
337 #else /* no debug */
338 #if defined(LWS_WITH_NO_LOGS)
339 //#define lwsl_err(...) do {} while(0)
340 #define lwsl_warn(...) do {} while(0)
341 #define lwsl_notice(...) do {} while(0)
342 #endif
343 #define lwsl_info(...) do {} while(0)
344 #define lwsl_debug(...) do {} while(0)
345 #define lwsl_parser(...) do {} while(0)
346 #define lwsl_header(...) do {} while(0)
347 #define lwsl_ext(...) do {} while(0)
348 #define lwsl_client(...) do {} while(0)
349 #define lwsl_latency(...) do {} while(0)
350 #define lwsl_hexdump(a, b)
351 
352 #endif
353 
364 LWS_VISIBLE LWS_EXTERN void
365 lws_set_log_level(int level,
366  void (*log_emit_function)(int level, const char *line));
367 
377 LWS_VISIBLE LWS_EXTERN void
378 lwsl_emit_syslog(int level, const char *line);
379 
381 
382 
383 #include <stddef.h>
384 
385 #ifndef lws_container_of
386 #define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M)))
387 #endif
388 
389 
390 struct lws;
391 #ifndef ARRAY_SIZE
392 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
393 #endif
394 
395 /* api change list for user code to test against */
396 
397 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
398 
399 /* the struct lws_protocols has the id field present */
400 #define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
401 
402 /* you can call lws_get_peer_write_allowance */
403 #define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
404 
405 /* extra parameter introduced in 917f43ab821 */
406 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
407 
408 /* File operations stuff exists */
409 #define LWS_FEATURE_FOPS
410 
411 
412 #if defined(_WIN32)
413 typedef SOCKET lws_sockfd_type;
414 typedef HANDLE lws_filefd_type;
415 #define lws_sockfd_valid(sfd) (!!sfd)
416 struct lws_pollfd {
417  lws_sockfd_type fd;
418  SHORT events;
419  SHORT revents;
420 };
421 #define LWS_POLLHUP (FD_CLOSE)
422 #define LWS_POLLIN (FD_READ | FD_ACCEPT)
423 #define LWS_POLLOUT (FD_WRITE)
424 #else
425 
426 #if defined(MBED_OPERATORS)
427 /* it's a class lws_conn * */
428 typedef void * lws_sockfd_type;
429 typedef void * lws_filefd_type;
430 #define lws_sockfd_valid(sfd) (!!sfd)
431 struct pollfd {
432  lws_sockfd_type fd;
433  short events;
434  short revents;
435 };
436 #define POLLIN 0x0001
437 #define POLLPRI 0x0002
438 #define POLLOUT 0x0004
439 #define POLLERR 0x0008
440 #define POLLHUP 0x0010
441 #define POLLNVAL 0x0020
442 
443 struct lws;
444 
445 void * mbed3_create_tcp_stream_socket(void);
446 void mbed3_delete_tcp_stream_socket(void *sockfd);
447 void mbed3_tcp_stream_bind(void *sock, int port, struct lws *);
448 void mbed3_tcp_stream_accept(void *sock, struct lws *);
449 #else
450 #if defined(LWS_WITH_ESP8266)
451 
452 #include <user_interface.h>
453 #include <espconn.h>
454 
455 typedef struct espconn * lws_sockfd_type;
456 typedef void * lws_filefd_type;
457 #define lws_sockfd_valid(sfd) (!!sfd)
458 struct pollfd {
459  lws_sockfd_type fd;
460  short events;
461  short revents;
462 };
463 #define POLLIN 0x0001
464 #define POLLPRI 0x0002
465 #define POLLOUT 0x0004
466 #define POLLERR 0x0008
467 #define POLLHUP 0x0010
468 #define POLLNVAL 0x0020
469 
470 struct lws_vhost;
471 
472 lws_sockfd_type esp8266_create_tcp_listen_socket(struct lws_vhost *vh);
473 void esp8266_tcp_stream_accept(lws_sockfd_type fd, struct lws *wsi);
474 
475 #include <os_type.h>
476 #include <osapi.h>
477 #include "ets_sys.h"
478 
479 int ets_snprintf(char *str, size_t size, const char *format, ...);
480 #define snprintf ets_snprintf
481 
482 typedef os_timer_t uv_timer_t;
483 typedef void uv_cb_t(uv_timer_t *);
484 
485 void os_timer_disarm(void *);
486 void os_timer_setfn(os_timer_t *, os_timer_func_t *, void *);
487 
488 void ets_timer_arm_new(os_timer_t *, int, int, int);
489 
490 //void os_timer_arm(os_timer_t *, int, int);
491 
492 #define UV_VERSION_MAJOR 1
493 
494 #define lws_uv_getloop(a, b) (NULL)
495 
496 static inline void uv_timer_init(void *l, uv_timer_t *t)
497 {
498  (void)l;
499  memset(t, 0, sizeof(*t));
500  os_timer_disarm(t);
501 }
502 
503 static inline void uv_timer_start(uv_timer_t *t, uv_cb_t *cb, int first, int rep)
504 {
505  os_timer_setfn(t, (os_timer_func_t *)cb, t);
506  /* ms, repeat */
507  os_timer_arm(t, first, !!rep);
508 }
509 
510 static inline void uv_timer_stop(uv_timer_t *t)
511 {
512  os_timer_disarm(t);
513 }
514 
515 #else
516 typedef int lws_sockfd_type;
517 typedef int lws_filefd_type;
518 #define lws_sockfd_valid(sfd) (sfd >= 0)
519 #endif
520 #endif
521 
522 #define lws_pollfd pollfd
523 #define LWS_POLLHUP (POLLHUP|POLLERR)
524 #define LWS_POLLIN (POLLIN)
525 #define LWS_POLLOUT (POLLOUT)
526 #endif
527 
530 struct lws_pollargs {
531  lws_sockfd_type fd;
532  int events;
534 };
535 
536 struct lws_tokens;
537 struct lws_token_limits;
538 
546 
548 /*
549  * NOTE: These public enums are part of the abi. If you want to add one,
550  * add it at where specified so existing users are unaffected.
551  */
554  LWS_CLOSE_STATUS_NOSTATUS = 0,
616  /****** add new things just above ---^ ******/
617 
618  LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY = 9999,
619 };
620 
633 LWS_VISIBLE LWS_EXTERN void
634 lws_close_reason(struct lws *wsi, enum lws_close_status status,
635  unsigned char *buf, size_t len);
636 
638 
639 struct lws;
640 struct lws_context;
641 /* needed even with extensions disabled for create context */
642 struct lws_extension;
643 
655 
657 
658 /*
659  * NOTE: These public enums are part of the abi. If you want to add one,
660  * add it at where specified so existing users are unaffected.
661  */
905  /* external poll() management support */
968  LWS_CALLBACK_WS_EXT_DEFAULTS = 39,
971  LWS_CALLBACK_CGI = 40,
973  LWS_CALLBACK_CGI_TERMINATED = 41,
975  LWS_CALLBACK_CGI_STDIN_DATA = 42,
977  LWS_CALLBACK_CGI_STDIN_COMPLETED = 43,
979  LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP = 44,
981  LWS_CALLBACK_CLOSED_CLIENT_HTTP = 45,
983  LWS_CALLBACK_RECEIVE_CLIENT_HTTP = 46,
985  LWS_CALLBACK_COMPLETED_CLIENT_HTTP = 47,
987  LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ = 48,
989  LWS_CALLBACK_HTTP_BIND_PROTOCOL = 49,
991  LWS_CALLBACK_HTTP_DROP_PROTOCOL = 50,
993  LWS_CALLBACK_CHECK_ACCESS_RIGHTS = 51,
995  LWS_CALLBACK_PROCESS_HTML = 52,
997  LWS_CALLBACK_ADD_HEADERS = 53,
999  LWS_CALLBACK_SESSION_INFO = 54,
1002  LWS_CALLBACK_GS_EVENT = 55,
1019  /****** add new things just above ---^ ******/
1020 
1023 };
1024 
1025 
1026 
1042 typedef int
1043 lws_callback_function(struct lws *wsi, enum lws_callback_reasons reason,
1044  void *user, void *in, size_t len);
1046 
1056 
1058 /*
1059  * NOTE: These public enums are part of the abi. If you want to add one,
1060  * add it at where specified so existing users are unaffected.
1061  */
1062 enum lws_extension_callback_reasons {
1063  LWS_EXT_CB_SERVER_CONTEXT_CONSTRUCT = 0,
1064  LWS_EXT_CB_CLIENT_CONTEXT_CONSTRUCT = 1,
1065  LWS_EXT_CB_SERVER_CONTEXT_DESTRUCT = 2,
1066  LWS_EXT_CB_CLIENT_CONTEXT_DESTRUCT = 3,
1067  LWS_EXT_CB_CONSTRUCT = 4,
1068  LWS_EXT_CB_CLIENT_CONSTRUCT = 5,
1069  LWS_EXT_CB_CHECK_OK_TO_REALLY_CLOSE = 6,
1070  LWS_EXT_CB_CHECK_OK_TO_PROPOSE_EXTENSION = 7,
1071  LWS_EXT_CB_DESTROY = 8,
1072  LWS_EXT_CB_DESTROY_ANY_WSI_CLOSING = 9,
1073  LWS_EXT_CB_ANY_WSI_ESTABLISHED = 10,
1074  LWS_EXT_CB_PACKET_RX_PREPARSE = 11,
1075  LWS_EXT_CB_PACKET_TX_PRESEND = 12,
1076  LWS_EXT_CB_PACKET_TX_DO_SEND = 13,
1077  LWS_EXT_CB_HANDSHAKE_REPLY_TX = 14,
1078  LWS_EXT_CB_FLUSH_PENDING_TX = 15,
1079  LWS_EXT_CB_EXTENDED_PAYLOAD_RX = 16,
1080  LWS_EXT_CB_CAN_PROXY_CLIENT_CONNECTION = 17,
1081  LWS_EXT_CB_1HZ = 18,
1082  LWS_EXT_CB_REQUEST_ON_WRITEABLE = 19,
1083  LWS_EXT_CB_IS_WRITEABLE = 20,
1084  LWS_EXT_CB_PAYLOAD_TX = 21,
1085  LWS_EXT_CB_PAYLOAD_RX = 22,
1086  LWS_EXT_CB_OPTION_DEFAULT = 23,
1087  LWS_EXT_CB_OPTION_SET = 24,
1088  LWS_EXT_CB_OPTION_CONFIRM = 25,
1089  LWS_EXT_CB_NAMED_OPTION_SET = 26,
1090 
1091  /****** add new things just above ---^ ******/
1092 };
1093 
1100  /* Add new things just above here ---^
1101  * This is part of the ABI, don't needlessly break compatibility */
1102 };
1103 
1109  const char *name;
1112  /* Add new things just above here ---^
1113  * This is part of the ABI, don't needlessly break compatibility */
1114 };
1115 
1118  const char *option_name;
1120  const char *start;
1121  int len;
1122 };
1123 
1184 typedef int
1185 lws_extension_callback_function(struct lws_context *context,
1186  const struct lws_extension *ext, struct lws *wsi,
1187  enum lws_extension_callback_reasons reason,
1188  void *user, void *in, size_t len);
1189 
1192  const char *name;
1194  const char *client_offer;
1196  /* Add new things just above here ---^
1197  * This is part of the ABI, don't needlessly break compatibility */
1198 };
1199 
1208 LWS_VISIBLE LWS_EXTERN int
1209 lws_set_extension_option(struct lws *wsi, const char *ext_name,
1210  const char *opt_name, const char *opt_val);
1211 
1212 #ifndef LWS_NO_EXTENSIONS
1213 /* lws_get_internal_extensions() - DEPRECATED
1214  *
1215  * \Deprecated There is no longer a set internal extensions table. The table is provided
1216  * by user code along with application-specific settings. See the test
1217  * client and server for how to do.
1218  */
1219 static LWS_INLINE LWS_WARN_DEPRECATED const struct lws_extension *
1220 lws_get_internal_extensions(void) { return NULL; }
1221 
1232 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1233 lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi,
1234  void *ext_user, const struct lws_ext_options *opts,
1235  const char *o, int len);
1236 #endif
1237 
1250 LWS_EXTERN
1252  struct lws_context *context, const struct lws_extension *ext,
1253  struct lws *wsi, enum lws_extension_callback_reasons reason,
1254  void *user, void *in, size_t len);
1255 
1256 /*
1257  * The internal exts are part of the public abi
1258  * If we add more extensions, publish the callback here ------v
1259  */
1261 
1277 
1282  const char *name;
1303  unsigned int id;
1310  void *user;
1313  /* Add new things just above here ---^
1314  * This is part of the ABI, don't needlessly break compatibility */
1315 };
1316 
1317 struct lws_vhost;
1318 
1327 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
1328 lws_vhost_name_to_protocol(struct lws_vhost *vh, const char *name);
1329 
1339 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
1340 lws_get_protocol(struct lws *wsi);
1341 
1343 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
1344 lws_protocol_get(struct lws *wsi) LWS_WARN_DEPRECATED;
1345 
1356 LWS_VISIBLE LWS_EXTERN void *
1357 lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost, const struct lws_protocols *prot,
1358  int size);
1359 
1369 LWS_VISIBLE LWS_EXTERN void *
1370 lws_protocol_vh_priv_get(struct lws_vhost *vhost, const struct lws_protocols *prot);
1371 
1380 LWS_VISIBLE LWS_EXTERN int
1381 lws_finalize_startup(struct lws_context *context);
1382 
1383 #ifdef LWS_WITH_PLUGINS
1384 
1385 /* PLUGINS implies LIBUV */
1386 
1387 #define LWS_PLUGIN_API_MAGIC 180
1388 
1391  unsigned int api_magic;
1392  const struct lws_protocols *protocols;
1394  const struct lws_extension *extensions;
1396 };
1397 
1398 typedef int (*lws_plugin_init_func)(struct lws_context *,
1399  struct lws_plugin_capability *);
1400 typedef int (*lws_plugin_destroy_func)(struct lws_context *);
1401 
1403 struct lws_plugin {
1404  struct lws_plugin *list;
1405 #if (UV_VERSION_MAJOR > 0)
1406  uv_lib_t lib;
1407 #else
1408  void *l;
1409 #endif
1410  char name[64];
1412 };
1413 
1414 #endif
1415 
1417 
1418 
1427 
1429 #define LWSGS_EMAIL_CONTENT_SIZE 16384
1430 
1432 /* SHA-1 binary and hexified versions */
1434 typedef struct { unsigned char bin[20]; } lwsgw_hash_bin;
1436 typedef struct { char id[41]; } lwsgw_hash;
1437 
1444 };
1445 
1448  char username[32];
1449  char email[100];
1450  char ip[72];
1451  unsigned int mask;
1453  char session[42];
1454 };
1455 
1460 };
1461 
1464  enum lws_gs_event event;
1465  const char *username;
1466  const char *email;
1467 };
1468 
1470 
1471 
1485 
1487 /*
1488  * NOTE: These public enums are part of the abi. If you want to add one,
1489  * add it at where specified so existing users are unaffected.
1490  */
1491 
1495  (1 << 12),
1502  (1 << 12),
1518  (1 << 12),
1523  (1 << 12),
1547  /****** add new things just above ---^ ******/
1548 };
1549 
1550 #define lws_check_opt(c, f) (((c) & (f)) == (f))
1551 
1562  int port;
1567  const char *iface;
1574  const struct lws_protocols *protocols;
1578  const struct lws_extension *extensions;
1586  const char *ssl_cert_filepath;
1596  const char *ssl_ca_filepath;
1598  const char *ssl_cipher_list;
1602  const char *http_proxy_address;
1605  unsigned int http_proxy_port;
1607  int gid;
1609  int uid;
1611  unsigned int options;
1613  void *user;
1616  int ka_time;
1626 #ifdef LWS_OPENSSL_SUPPORT
1632 #else /* maintain structure layout either way */
1634 #endif
1635 
1646  unsigned int count_threads;
1648  unsigned int fd_limit_per_thread;
1652  unsigned int timeout_secs;
1657  const char *ecdh_curve;
1659  const char *vhost_name;
1663  const char * const *plugin_dirs;
1672  const char *log_filepath;
1675  const struct lws_http_mount *mounts;
1677  const char *server_string;
1680  unsigned int pt_serv_buf_size;
1695  unsigned short ws_ping_pong_interval;
1719  /* Add new things just above here ---^
1720  * This is part of the ABI, don't needlessly break compatibility
1721  *
1722  * The below is to ensure later library versions with new
1723  * members added above will see 0 (default) even if the app
1724  * was not built against the newer headers.
1725  */
1726 
1727  void *_unused[8];
1728 };
1729 
1764 LWS_VISIBLE LWS_EXTERN struct lws_context *
1766 
1775 LWS_VISIBLE LWS_EXTERN void
1776 lws_context_destroy(struct lws_context *context);
1777 
1795 LWS_VISIBLE LWS_EXTERN int
1796 lws_set_proxy(struct lws_vhost *vhost, const char *proxy);
1797 
1798 
1799 struct lws_vhost;
1800 
1810 LWS_EXTERN LWS_VISIBLE struct lws_vhost *
1811 lws_create_vhost(struct lws_context *context,
1812  struct lws_context_creation_info *info);
1813 
1828 LWS_VISIBLE LWS_EXTERN int
1829 lwsws_get_config_globals(struct lws_context_creation_info *info, const char *d,
1830  char **config_strings, int *len);
1831 
1847 LWS_VISIBLE LWS_EXTERN int
1848 lwsws_get_config_vhosts(struct lws_context *context,
1849  struct lws_context_creation_info *info, const char *d,
1850  char **config_strings, int *len);
1851 
1853 LWS_VISIBLE LWS_EXTERN struct lws_vhost *
1854 lws_vhost_get(struct lws *wsi) LWS_WARN_DEPRECATED;
1855 
1861 LWS_VISIBLE LWS_EXTERN struct lws_vhost *
1862 lws_get_vhost(struct lws *wsi);
1863 
1871 LWS_VISIBLE LWS_EXTERN int
1872 lws_json_dump_vhost(const struct lws_vhost *vh, char *buf, int len);
1873 
1881 LWS_VISIBLE LWS_EXTERN int
1882 lws_json_dump_context(const struct lws_context *context, char *buf, int len);
1883 
1893 LWS_VISIBLE LWS_EXTERN void *
1894 lws_context_user(struct lws_context *context);
1895 
1901 
1911  const char *name;
1912  const char *value;
1913 };
1914 
1927 };
1928 
1936  const char *mountpoint;
1938  const char *origin;
1940  const char *def;
1942  const char *protocol;
1958  unsigned int auth_mask;
1961  unsigned int cache_reusable:1;
1962  unsigned int cache_revalidate:1;
1963  unsigned int cache_intermediaries:1;
1965  unsigned char origin_protocol;
1966  unsigned char mountpoint_len;
1967 };
1970 
1976 
1984  LCCSCF_USE_SSL = (1 << 0),
1985  LCCSCF_ALLOW_SELFSIGNED = (1 << 1),
1986  LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK = (1 << 2)
1987 };
1988 
1993  struct lws_context *context;
1995  const char *address;
1997  int port;
2001  const char *path;
2003  const char *host;
2005  const char *origin;
2007  const char *protocol;
2011  void *userdata;
2015  const char *method;
2018  struct lws *parent_wsi;
2022  const char *uri_replace_from;
2025  const char *uri_replace_to;
2027  struct lws_vhost *vhost;
2029  struct lws **pwsi;
2041  /* Add new things just above here ---^
2042  * This is part of the ABI, don't needlessly break compatibility
2043  *
2044  * The below is to ensure later library versions with new
2045  * members added above will see 0 (default) even if the app
2046  * was not built against the newer headers.
2047  */
2048 
2049  void *_unused[4];
2050 };
2051 
2059 LWS_VISIBLE LWS_EXTERN struct lws *
2061 
2082 /* deprecated, use lws_client_connect_via_info() */
2083 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
2084 lws_client_connect(struct lws_context *clients, const char *address,
2085  int port, int ssl_connection, const char *path,
2086  const char *host, const char *origin, const char *protocol,
2087  int ietf_version_or_minus_one) LWS_WARN_DEPRECATED;
2088 /* deprecated, use lws_client_connect_via_info() */
2109 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
2110 lws_client_connect_extended(struct lws_context *clients, const char *address,
2111  int port, int ssl_connection, const char *path,
2112  const char *host, const char *origin,
2113  const char *protocol, int ietf_version_or_minus_one,
2114  void *userdata) LWS_WARN_DEPRECATED;
2115 
2141 LWS_VISIBLE LWS_EXTERN int
2143  struct lws_vhost *vhost);
2144 
2145 LWS_VISIBLE LWS_EXTERN int
2146 lws_http_client_read(struct lws *wsi, char **buf, int *len);
2147 
2155 LWS_VISIBLE LWS_EXTERN unsigned int
2156 lws_http_client_http_response(struct lws *wsi);
2157 
2158 LWS_VISIBLE LWS_EXTERN void
2159 lws_client_http_body_pending(struct lws *wsi, int something_left_to_send);
2160 
2181 
2190 
2223 LWS_VISIBLE LWS_EXTERN int
2224 lws_service(struct lws_context *context, int timeout_ms);
2225 
2237 LWS_VISIBLE LWS_EXTERN int
2238 lws_service_tsi(struct lws_context *context, int timeout_ms, int tsi);
2239 
2255 LWS_VISIBLE LWS_EXTERN void
2256 lws_cancel_service_pt(struct lws *wsi);
2257 
2269 LWS_VISIBLE LWS_EXTERN void
2270 lws_cancel_service(struct lws_context *context);
2271 
2298 LWS_VISIBLE LWS_EXTERN int
2299 lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd);
2300 
2310 LWS_VISIBLE LWS_EXTERN int
2311 lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,
2312  int tsi);
2313 
2331 LWS_VISIBLE LWS_EXTERN int
2332 lws_service_adjust_timeout(struct lws_context *context, int timeout_ms, int tsi);
2333 
2334 /* Backwards compatibility */
2335 #define lws_plat_service_tsi lws_service_tsi
2336 
2338 
2344 
2351 
2363 LWS_VISIBLE LWS_EXTERN const char *
2364 lws_get_mimetype(const char *file, const struct lws_http_mount *m);
2365 
2384 LWS_VISIBLE LWS_EXTERN int
2385 lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type,
2386  const char *other_headers, int other_headers_len);
2387 LWS_VISIBLE LWS_EXTERN int
2388 lws_serve_http_file_fragment(struct lws *wsi);
2390 
2401 
2402 enum http_status {
2403  HTTP_STATUS_OK = 200,
2404  HTTP_STATUS_NO_CONTENT = 204,
2405 
2406  HTTP_STATUS_MOVED_PERMANENTLY = 301,
2407  HTTP_STATUS_FOUND = 302,
2408  HTTP_STATUS_SEE_OTHER = 303,
2409 
2410  HTTP_STATUS_BAD_REQUEST = 400,
2411  HTTP_STATUS_UNAUTHORIZED,
2412  HTTP_STATUS_PAYMENT_REQUIRED,
2413  HTTP_STATUS_FORBIDDEN,
2414  HTTP_STATUS_NOT_FOUND,
2415  HTTP_STATUS_METHOD_NOT_ALLOWED,
2416  HTTP_STATUS_NOT_ACCEPTABLE,
2417  HTTP_STATUS_PROXY_AUTH_REQUIRED,
2418  HTTP_STATUS_REQUEST_TIMEOUT,
2419  HTTP_STATUS_CONFLICT,
2420  HTTP_STATUS_GONE,
2421  HTTP_STATUS_LENGTH_REQUIRED,
2422  HTTP_STATUS_PRECONDITION_FAILED,
2423  HTTP_STATUS_REQ_ENTITY_TOO_LARGE,
2424  HTTP_STATUS_REQ_URI_TOO_LONG,
2425  HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE,
2426  HTTP_STATUS_REQ_RANGE_NOT_SATISFIABLE,
2427  HTTP_STATUS_EXPECTATION_FAILED,
2428 
2429  HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,
2430  HTTP_STATUS_NOT_IMPLEMENTED,
2431  HTTP_STATUS_BAD_GATEWAY,
2432  HTTP_STATUS_SERVICE_UNAVAILABLE,
2433  HTTP_STATUS_GATEWAY_TIMEOUT,
2434  HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED,
2435 };
2436 
2438  char *p;
2439  int len;
2440  int max_len;
2441  int final;
2442 };
2443 
2444 typedef const char *(*lws_process_html_state_cb)(void *data, int index);
2445 
2447  char *start;
2448  char swallow[16];
2449  int pos;
2450  void *data;
2451  const char * const *vars;
2454  lws_process_html_state_cb replace;
2455 };
2456 
2461 LWS_VISIBLE LWS_EXTERN int
2463  struct lws_process_html_state *s);
2465 
2498 
2506 struct lws_tokens {
2507  char *token;
2509 };
2510 
2511 /* enum lws_token_indexes
2512  * these have to be kept in sync with lextable.h / minilex.c
2513  *
2514  * NOTE: These public enums are part of the abi. If you want to add one,
2515  * add it at where specified so existing users are unaffected.
2516  */
2517 enum lws_token_indexes {
2518  WSI_TOKEN_GET_URI = 0,
2519  WSI_TOKEN_POST_URI = 1,
2520  WSI_TOKEN_OPTIONS_URI = 2,
2521  WSI_TOKEN_HOST = 3,
2522  WSI_TOKEN_CONNECTION = 4,
2523  WSI_TOKEN_UPGRADE = 5,
2524  WSI_TOKEN_ORIGIN = 6,
2525  WSI_TOKEN_DRAFT = 7,
2526  WSI_TOKEN_CHALLENGE = 8,
2527  WSI_TOKEN_EXTENSIONS = 9,
2528  WSI_TOKEN_KEY1 = 10,
2529  WSI_TOKEN_KEY2 = 11,
2530  WSI_TOKEN_PROTOCOL = 12,
2531  WSI_TOKEN_ACCEPT = 13,
2532  WSI_TOKEN_NONCE = 14,
2533  WSI_TOKEN_HTTP = 15,
2534  WSI_TOKEN_HTTP2_SETTINGS = 16,
2535  WSI_TOKEN_HTTP_ACCEPT = 17,
2536  WSI_TOKEN_HTTP_AC_REQUEST_HEADERS = 18,
2537  WSI_TOKEN_HTTP_IF_MODIFIED_SINCE = 19,
2538  WSI_TOKEN_HTTP_IF_NONE_MATCH = 20,
2539  WSI_TOKEN_HTTP_ACCEPT_ENCODING = 21,
2540  WSI_TOKEN_HTTP_ACCEPT_LANGUAGE = 22,
2541  WSI_TOKEN_HTTP_PRAGMA = 23,
2542  WSI_TOKEN_HTTP_CACHE_CONTROL = 24,
2543  WSI_TOKEN_HTTP_AUTHORIZATION = 25,
2544  WSI_TOKEN_HTTP_COOKIE = 26,
2545  WSI_TOKEN_HTTP_CONTENT_LENGTH = 27,
2546  WSI_TOKEN_HTTP_CONTENT_TYPE = 28,
2547  WSI_TOKEN_HTTP_DATE = 29,
2548  WSI_TOKEN_HTTP_RANGE = 30,
2549  WSI_TOKEN_HTTP_REFERER = 31,
2550  WSI_TOKEN_KEY = 32,
2551  WSI_TOKEN_VERSION = 33,
2552  WSI_TOKEN_SWORIGIN = 34,
2553 
2554  WSI_TOKEN_HTTP_COLON_AUTHORITY = 35,
2555  WSI_TOKEN_HTTP_COLON_METHOD = 36,
2556  WSI_TOKEN_HTTP_COLON_PATH = 37,
2557  WSI_TOKEN_HTTP_COLON_SCHEME = 38,
2558  WSI_TOKEN_HTTP_COLON_STATUS = 39,
2559 
2560  WSI_TOKEN_HTTP_ACCEPT_CHARSET = 40,
2561  WSI_TOKEN_HTTP_ACCEPT_RANGES = 41,
2562  WSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN = 42,
2563  WSI_TOKEN_HTTP_AGE = 43,
2564  WSI_TOKEN_HTTP_ALLOW = 44,
2565  WSI_TOKEN_HTTP_CONTENT_DISPOSITION = 45,
2566  WSI_TOKEN_HTTP_CONTENT_ENCODING = 46,
2567  WSI_TOKEN_HTTP_CONTENT_LANGUAGE = 47,
2568  WSI_TOKEN_HTTP_CONTENT_LOCATION = 48,
2569  WSI_TOKEN_HTTP_CONTENT_RANGE = 49,
2570  WSI_TOKEN_HTTP_ETAG = 50,
2571  WSI_TOKEN_HTTP_EXPECT = 51,
2572  WSI_TOKEN_HTTP_EXPIRES = 52,
2573  WSI_TOKEN_HTTP_FROM = 53,
2574  WSI_TOKEN_HTTP_IF_MATCH = 54,
2575  WSI_TOKEN_HTTP_IF_RANGE = 55,
2576  WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE = 56,
2577  WSI_TOKEN_HTTP_LAST_MODIFIED = 57,
2578  WSI_TOKEN_HTTP_LINK = 58,
2579  WSI_TOKEN_HTTP_LOCATION = 59,
2580  WSI_TOKEN_HTTP_MAX_FORWARDS = 60,
2581  WSI_TOKEN_HTTP_PROXY_AUTHENTICATE = 61,
2582  WSI_TOKEN_HTTP_PROXY_AUTHORIZATION = 62,
2583  WSI_TOKEN_HTTP_REFRESH = 63,
2584  WSI_TOKEN_HTTP_RETRY_AFTER = 64,
2585  WSI_TOKEN_HTTP_SERVER = 65,
2586  WSI_TOKEN_HTTP_SET_COOKIE = 66,
2587  WSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY = 67,
2588  WSI_TOKEN_HTTP_TRANSFER_ENCODING = 68,
2589  WSI_TOKEN_HTTP_USER_AGENT = 69,
2590  WSI_TOKEN_HTTP_VARY = 70,
2591  WSI_TOKEN_HTTP_VIA = 71,
2592  WSI_TOKEN_HTTP_WWW_AUTHENTICATE = 72,
2593 
2594  WSI_TOKEN_PATCH_URI = 73,
2595  WSI_TOKEN_PUT_URI = 74,
2596  WSI_TOKEN_DELETE_URI = 75,
2597 
2598  WSI_TOKEN_HTTP_URI_ARGS = 76,
2599  WSI_TOKEN_PROXY = 77,
2600  WSI_TOKEN_HTTP_X_REAL_IP = 78,
2601  WSI_TOKEN_HTTP1_0 = 79,
2602 
2603  /****** add new things just above ---^ ******/
2604 
2605  /* use token storage to stash these internally, not for
2606  * user use */
2607 
2608  _WSI_TOKEN_CLIENT_SENT_PROTOCOLS,
2609  _WSI_TOKEN_CLIENT_PEER_ADDRESS,
2610  _WSI_TOKEN_CLIENT_URI,
2611  _WSI_TOKEN_CLIENT_HOST,
2612  _WSI_TOKEN_CLIENT_ORIGIN,
2613  _WSI_TOKEN_CLIENT_METHOD,
2614 
2615  /* always last real token index*/
2616  WSI_TOKEN_COUNT,
2617 
2618  /* parser state additions, no storage associated */
2619  WSI_TOKEN_NAME_PART,
2620  WSI_TOKEN_SKIPPING,
2621  WSI_TOKEN_SKIPPING_SAW_CR,
2622  WSI_PARSING_COMPLETE,
2623  WSI_INIT_TOKEN_MUXURL,
2624 };
2625 
2627  unsigned short token_limit[WSI_TOKEN_COUNT];
2628 };
2629 
2635 LWS_VISIBLE LWS_EXTERN const unsigned char *
2636 lws_token_to_string(enum lws_token_indexes token);
2637 
2638 
2647 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2648 lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h);
2649 
2659 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2660 lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx);
2661 
2675 LWS_VISIBLE LWS_EXTERN int
2676 lws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h);
2677 
2695 LWS_VISIBLE LWS_EXTERN int
2696 lws_hdr_copy_fragment(struct lws *wsi, char *dest, int len,
2697  enum lws_token_indexes h, int frag_idx);
2698 
2709 LWS_VISIBLE LWS_EXTERN const char *
2710 lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, int len);
2712 
2727 
2738 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2739 lws_add_http_header_status(struct lws *wsi,
2740  unsigned int code, unsigned char **p,
2741  unsigned char *end);
2754 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2755 lws_add_http_header_by_name(struct lws *wsi, const unsigned char *name,
2756  const unsigned char *value, int length,
2757  unsigned char **p, unsigned char *end);
2771 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2772 lws_add_http_header_by_token(struct lws *wsi, enum lws_token_indexes token,
2773  const unsigned char *value, int length,
2774  unsigned char **p, unsigned char *end);
2785 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2786 lws_add_http_header_content_length(struct lws *wsi,
2787  unsigned long content_length,
2788  unsigned char **p, unsigned char *end);
2798 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2799 lws_finalize_http_header(struct lws *wsi, unsigned char **p,
2800  unsigned char *end);
2802 
2821 
2831 };
2832 
2846 typedef int (*lws_spa_fileupload_cb)(void *data, const char *name,
2847  const char *filename, char *buf, int len,
2848  enum lws_spa_fileupload_states state);
2849 
2852 struct lws_spa;
2853 
2872 LWS_VISIBLE LWS_EXTERN struct lws_spa *
2873 lws_spa_create(struct lws *wsi, const char * const *param_names,
2874  int count_params, int max_storage, lws_spa_fileupload_cb opt_cb,
2875  void *opt_data);
2876 
2884 LWS_VISIBLE LWS_EXTERN int
2885 lws_spa_process(struct lws_spa *spa, const char *in, int len);
2886 
2892 LWS_VISIBLE LWS_EXTERN int
2893 lws_spa_finalize(struct lws_spa *spa);
2894 
2901 LWS_VISIBLE LWS_EXTERN int
2902 lws_spa_get_length(struct lws_spa *spa, int n);
2903 
2909 LWS_VISIBLE LWS_EXTERN const char *
2910 lws_spa_get_string(struct lws_spa *spa, int n);
2911 
2917 LWS_VISIBLE LWS_EXTERN int
2918 lws_spa_destroy(struct lws_spa *spa);
2920 
2931 
2942 LWS_VISIBLE LWS_EXTERN const char *
2943 lws_urlencode(char *escaped, const char *string, int len);
2944 
2945 /*
2946  * URLDECODE 1 / 2
2947  *
2948  * This simple urldecode only operates until the first '\0' and requires the
2949  * data to exist all at once
2950  */
2963 LWS_VISIBLE LWS_EXTERN int
2964 lws_urldecode(char *string, const char *escaped, int len);
2966 
2975 LWS_VISIBLE LWS_EXTERN int
2976 lws_return_http_status(struct lws *wsi, unsigned int code,
2977  const char *html_body);
2978 
2989 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2990 lws_http_redirect(struct lws *wsi, int code, const unsigned char *loc, int len,
2991  unsigned char **p, unsigned char *end);
2992 
3001 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3002 lws_http_transaction_completed(struct lws *wsi);
3004 
3012 
3023 LWS_VISIBLE LWS_EXTERN const char *
3024 lws_sql_purify(char *escaped, const char *string, int len);
3025 
3036 LWS_VISIBLE LWS_EXTERN const char *
3037 lws_json_purify(char *escaped, const char *string, int len);
3039 
3046 
3048 #ifdef LWS_USE_LIBEV
3049 typedef void (lws_ev_signal_cb_t)(EV_P_ struct ev_signal *w, int revents);
3050 
3051 LWS_VISIBLE LWS_EXTERN int
3052 lws_ev_sigint_cfg(struct lws_context *context, int use_ev_sigint,
3053  lws_ev_signal_cb_t *cb);
3054 
3055 LWS_VISIBLE LWS_EXTERN int
3056 lws_ev_initloop(struct lws_context *context, struct ev_loop *loop, int tsi);
3057 
3058 LWS_VISIBLE LWS_EXTERN void
3059 lws_ev_sigint_cb(struct ev_loop *loop, struct ev_signal *watcher, int revents);
3060 #endif /* LWS_USE_LIBEV */
3061 
3063 
3070 #ifdef LWS_USE_LIBUV
3072 LWS_VISIBLE LWS_EXTERN int
3073 lws_uv_sigint_cfg(struct lws_context *context, int use_uv_sigint,
3074  uv_signal_cb cb);
3075 
3076 LWS_VISIBLE LWS_EXTERN void
3077 lws_libuv_run(const struct lws_context *context, int tsi);
3078 
3079 LWS_VISIBLE LWS_EXTERN void
3080 lws_libuv_stop(struct lws_context *context);
3081 
3082 LWS_VISIBLE LWS_EXTERN int
3083 lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi);
3084 
3085 LWS_VISIBLE LWS_EXTERN uv_loop_t *
3086 lws_uv_getloop(struct lws_context *context, int tsi);
3087 
3088 LWS_VISIBLE LWS_EXTERN void
3089 lws_uv_sigint_cb(uv_signal_t *watcher, int signum);
3090 #endif /* LWS_USE_LIBUV */
3091 
3098 
3099 /*
3100  * NOTE: These public enums are part of the abi. If you want to add one,
3101  * add it at where specified so existing users are unaffected.
3102  */
3103 enum pending_timeout {
3104  NO_PENDING_TIMEOUT = 0,
3105  PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE = 1,
3106  PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE = 2,
3107  PENDING_TIMEOUT_ESTABLISH_WITH_SERVER = 3,
3108  PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE = 4,
3109  PENDING_TIMEOUT_AWAITING_PING = 5,
3110  PENDING_TIMEOUT_CLOSE_ACK = 6,
3111  PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE = 7,
3112  PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE = 8,
3113  PENDING_TIMEOUT_SSL_ACCEPT = 9,
3114  PENDING_TIMEOUT_HTTP_CONTENT = 10,
3115  PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND = 11,
3116  PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE = 12,
3117  PENDING_TIMEOUT_SHUTDOWN_FLUSH = 13,
3118  PENDING_TIMEOUT_CGI = 14,
3119  PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE = 15,
3120  PENDING_TIMEOUT_WS_PONG_CHECK_SEND_PING = 16,
3121  PENDING_TIMEOUT_WS_PONG_CHECK_GET_PONG = 17,
3122  PENDING_TIMEOUT_CLIENT_ISSUE_PAYLOAD = 18,
3123 
3124  /****** add new things just above ---^ ******/
3125 };
3126 
3136 LWS_VISIBLE LWS_EXTERN void
3137 lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs);
3139 
3145 #if !defined(LWS_SIZEOFPTR)
3146 #define LWS_SIZEOFPTR (sizeof (void *))
3147 #endif
3148 #if !defined(u_int64_t)
3149 #define u_int64_t unsigned long long
3150 #endif
3151 
3152 #if defined(__x86_64__)
3153 #define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */
3154 #else
3155 #define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target arch */
3156 #endif
3157 #define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
3158  ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
3159 #define LWS_PRE _LWS_PAD(4 + 10)
3160 /* used prior to 1.7 and retained for backward compatibility */
3161 #define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
3162 #define LWS_SEND_BUFFER_POST_PADDING 0
3163 
3164 /*
3165  * NOTE: These public enums are part of the abi. If you want to add one,
3166  * add it at where specified so existing users are unaffected.
3167  */
3182  /* LWS_WRITE_CLOSE is handled by lws_close_reason() */
3183  LWS_WRITE_PING = 5,
3184  LWS_WRITE_PONG = 6,
3185 
3186  /* Same as write_http but we know this write ends the transaction */
3187  LWS_WRITE_HTTP_FINAL = 7,
3188 
3189  /* HTTP2 */
3190 
3198  /****** add new things just above ---^ ******/
3199 
3200  /* flags */
3201 
3209 };
3210 
3211 
3298 LWS_VISIBLE LWS_EXTERN int
3299 lws_write(struct lws *wsi, unsigned char *buf, size_t len,
3300  enum lws_write_protocol protocol);
3301 
3302 /* helper for case where buffer may be const */
3303 #define lws_write_http(wsi, buf, len) \
3304  lws_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP)
3305 
3325 
3338 LWS_VISIBLE LWS_EXTERN int
3339 lws_callback_on_writable(struct lws *wsi);
3340 
3354 LWS_VISIBLE LWS_EXTERN int
3355 lws_callback_on_writable_all_protocol(const struct lws_context *context,
3356  const struct lws_protocols *protocol);
3357 
3371 LWS_VISIBLE LWS_EXTERN int
3372 lws_callback_on_writable_all_protocol_vhost(const struct lws_vhost *vhost,
3373  const struct lws_protocols *protocol);
3374 
3387 LWS_VISIBLE LWS_EXTERN int
3388 lws_callback_all_protocol(struct lws_context *context,
3389  const struct lws_protocols *protocol, int reason);
3390 
3403 LWS_VISIBLE LWS_EXTERN int
3404 lws_callback_all_protocol_vhost(struct lws_vhost *vh,
3405  const struct lws_protocols *protocol, int reason);
3406 
3420 LWS_VISIBLE LWS_EXTERN int
3421 lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len);
3422 
3423 LWS_VISIBLE LWS_EXTERN int
3424 lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
3425  void *user, void *in, size_t len);
3426 
3434 LWS_VISIBLE LWS_EXTERN int
3435 lws_get_socket_fd(struct lws *wsi);
3436 
3458 LWS_VISIBLE LWS_EXTERN size_t
3459 lws_get_peer_write_allowance(struct lws *wsi);
3461 
3472 LWS_VISIBLE LWS_EXTERN int
3473 lws_rx_flow_control(struct lws *wsi, int enable);
3474 
3484 LWS_VISIBLE LWS_EXTERN void
3485 lws_rx_flow_allow_all_protocol(const struct lws_context *context,
3486  const struct lws_protocols *protocol);
3487 
3504 LWS_VISIBLE LWS_EXTERN size_t
3505 lws_remaining_packet_payload(struct lws *wsi);
3506 
3507 
3516 
3529 LWS_VISIBLE LWS_EXTERN struct lws *
3530 lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd);
3553 LWS_VISIBLE LWS_EXTERN struct lws *
3554 lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd,
3555  const char *readbuf, size_t len);
3557 
3563 
3574 LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
3575 lws_canonical_hostname(struct lws_context *context);
3576 
3591 LWS_VISIBLE LWS_EXTERN void
3592 lws_get_peer_addresses(struct lws *wsi, lws_sockfd_type fd, char *name,
3593  int name_len, char *rip, int rip_len);
3594 
3605 LWS_VISIBLE LWS_EXTERN const char *
3606 lws_get_peer_simple(struct lws *wsi, char *name, int namelen);
3607 #ifndef LWS_WITH_ESP8266
3608 
3619 LWS_VISIBLE LWS_EXTERN int
3620 lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr,
3621  size_t addrlen);
3623 #endif
3624 
3630 
3643 LWS_VISIBLE LWS_EXTERN int
3644 lws_snprintf(char *str, size_t size, const char *format, ...);
3645 
3657 LWS_VISIBLE LWS_EXTERN int
3658 lws_get_random(struct lws_context *context, void *buf, int len);
3666 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3667 lws_daemonize(const char *_lock_path);
3673 LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
3675 
3682 LWS_VISIBLE LWS_EXTERN void *
3683 lws_wsi_user(struct lws *wsi);
3684 
3696 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3697 lws_parse_uri(char *p, const char **prot, const char **ads, int *port,
3698  const char **path);
3699 
3703 LWS_VISIBLE LWS_EXTERN unsigned long
3704 lws_now_secs(void);
3705 
3715 LWS_VISIBLE LWS_EXTERN struct lws_context * LWS_WARN_UNUSED_RESULT
3716 lws_get_context(const struct lws *wsi);
3717 
3727 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3728 lws_get_count_threads(struct lws_context *context);
3729 
3737 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
3738 lws_get_parent(const struct lws *wsi);
3739 
3746 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
3747 lws_get_child(const struct lws *wsi);
3748 
3749 
3750 /*
3751  * \deprecated DEPRECATED Note: this is not normally needed as a user api.
3752  * It's provided in case it is
3753  * useful when integrating with other app poll loop service code.
3754  */
3755 LWS_VISIBLE LWS_EXTERN int
3756 lws_read(struct lws *wsi, unsigned char *buf, size_t len);
3757 
3765 LWS_VISIBLE LWS_EXTERN void
3766 lws_set_allocator(void *(*realloc)(void *ptr, size_t size));
3768 
3774 
3781 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3782 lws_send_pipe_choked(struct lws *wsi);
3783 
3788 LWS_VISIBLE LWS_EXTERN int
3789 lws_is_final_fragment(struct lws *wsi);
3790 
3795 LWS_VISIBLE LWS_EXTERN unsigned char
3796 lws_get_reserved_bits(struct lws *wsi);
3797 
3814 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3815 lws_partial_buffered(struct lws *wsi);
3816 
3826 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3827 lws_frame_is_binary(struct lws *wsi);
3828 
3837 LWS_VISIBLE LWS_EXTERN int
3838 lws_is_ssl(struct lws *wsi);
3843 LWS_VISIBLE LWS_EXTERN int
3844 lws_is_cgi(struct lws *wsi);
3846 
3847 
3853 #ifdef LWS_SHA1_USE_OPENSSL_NAME
3855 #define lws_SHA1 SHA1
3856 #else
3857 
3866 LWS_VISIBLE LWS_EXTERN unsigned char *
3867 lws_SHA1(const unsigned char *d, size_t n, unsigned char *md);
3868 #endif
3869 
3879 LWS_VISIBLE LWS_EXTERN int
3880 lws_b64_encode_string(const char *in, int in_len, char *out, int out_size);
3890 LWS_VISIBLE LWS_EXTERN int
3891 lws_b64_decode_string(const char *in, char *out, int out_size);
3893 
3894 
3904 #ifdef LWS_WITH_CGI
3905 enum lws_enum_stdinouterr {
3906  LWS_STDIN = 0,
3907  LWS_STDOUT = 1,
3908  LWS_STDERR = 2,
3909 };
3910 
3911 enum lws_cgi_hdr_state {
3912  LCHS_HEADER,
3913  LCHS_CR1,
3914  LCHS_LF1,
3915  LCHS_CR2,
3916  LCHS_LF2,
3917  LHCS_PAYLOAD,
3918  LCHS_SINGLE_0A,
3919 };
3920 
3922  struct lws **stdwsi;
3923  enum lws_enum_stdinouterr ch;
3924  unsigned char *data;
3925  enum lws_cgi_hdr_state hdr_state;
3926  int len;
3927 };
3928 
3929 
3939 LWS_VISIBLE LWS_EXTERN int
3940 lws_cgi(struct lws *wsi, const char * const *exec_array,
3941  int script_uri_path_len, int timeout_secs,
3942  const struct lws_protocol_vhost_options *mp_cgienv);
3943 
3949 LWS_VISIBLE LWS_EXTERN int
3950 lws_cgi_write_split_stdout_headers(struct lws *wsi);
3951 
3957 LWS_VISIBLE LWS_EXTERN int
3958 lws_cgi_kill(struct lws *wsi);
3959 #endif
3960 
3962 
3979 
3986  lws_filefd_type (*open)(struct lws *wsi, const char *filename,
3987  unsigned long *filelen, int flags);
3991  int (*close)(struct lws *wsi, lws_filefd_type fd);
3993  unsigned long (*seek_cur)(struct lws *wsi, lws_filefd_type fd,
3994  long offset_from_cur_pos);
3996  int (*read)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
3997  unsigned char *buf, unsigned long len);
3999  int (*write)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
4000  unsigned char *buf, unsigned long len);
4003  /* Add new things just above here ---^
4004  * This is part of the ABI, don't needlessly break compatibility */
4005 };
4006 
4012 LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops * LWS_WARN_UNUSED_RESULT
4013 lws_get_fops(struct lws_context *context);
4014 
4023 static LWS_INLINE lws_filefd_type LWS_WARN_UNUSED_RESULT
4024 lws_plat_file_open(struct lws *wsi, const char *filename,
4025  unsigned long *filelen, int flags)
4026 {
4027  return lws_get_fops(lws_get_context(wsi))->open(wsi, filename,
4028  filelen, flags);
4029 }
4030 
4037 static LWS_INLINE int
4038 lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
4039 {
4040  return lws_get_fops(lws_get_context(wsi))->close(wsi, fd);
4041 }
4042 
4050 static LWS_INLINE unsigned long
4051 lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
4052 {
4053  return lws_get_fops(lws_get_context(wsi))->seek_cur(wsi, fd, offset);
4054 }
4064 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
4065 lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
4066  unsigned char *buf, unsigned long len)
4067 {
4068  return lws_get_fops(lws_get_context(wsi))->read(wsi, fd, amount, buf,
4069  len);
4070 }
4080 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
4081 lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
4082  unsigned char *buf, unsigned long len)
4083 {
4084  return lws_get_fops(lws_get_context(wsi))->write(wsi, fd, amount, buf,
4085  len);
4086 }
4088 
4120 #ifdef LWS_WITH_SMTP
4121 
4133 };
4134 
4136 struct lws_email {
4137  void *data;
4139  uv_loop_t *loop;
4142  char email_smtp_ip[32];
4143  char email_helo[32];
4144  char email_from[100];
4145  char email_to[100];
4147  unsigned int max_content_size;
4150  /* Fill all the callbacks before init */
4151 
4152  int (*on_next)(struct lws_email *email);
4157  int (*on_sent)(struct lws_email *email);
4162  int (*on_get_body)(struct lws_email *email, char *buf, int len);
4168  /* private things */
4169  uv_timer_t timeout_email;
4171  uv_connect_t email_connect_req;
4172  uv_tcp_t email_client;
4174  char email_buf[256];
4175  char *content;
4176 };
4177 
4187 LWS_VISIBLE LWS_EXTERN int
4188 lws_email_init(struct lws_email *email, uv_loop_t *loop, int max_content);
4189 
4198 LWS_VISIBLE LWS_EXTERN void
4199 lws_email_check(struct lws_email *email);
4207 LWS_VISIBLE LWS_EXTERN void
4208 lws_email_destroy(struct lws_email *email);
4209 
4210 #endif
4211 
4212 
4213 #ifdef __cplusplus
4214 }
4215 #endif
4216 
4217 #endif
LWS_VISIBLE LWS_EXTERN int lws_spa_destroy(struct lws_spa *spa)
LWS_VISIBLE LWS_EXTERN const char * lws_json_purify(char *escaped, const char *string, int len)
Definition: libwebsockets.h:3921
size_t rx_buffer_size
Definition: libwebsockets.h:1294
diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 28615667..a65486d0 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -125,7 +125,7 @@ struct sockaddr_in; // Visual studio older than 2015 and WIN_CE has only _stricmp #if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(_WIN32_WCE) #define strcasecmp _stricmp -#else +#elif !defined(__MINGW32__) #define strcasecmp stricmp #endif #define getdtablesize() 30000 @@ -148,7 +148,7 @@ struct sockaddr_in; #define LWS_INVALID_FILE INVALID_HANDLE_VALUE #define LWS_O_RDONLY _O_RDONLY -#if !defined(_MSC_VER) || _MSC_VER < 1900 /* Visual Studio 2015 already defines this in */ +#if !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER < 1900) /* Visual Studio 2015 already defines this in */ #define lws_snprintf _snprintf #endif diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index f4a5d5e7..67d64b01 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -291,6 +291,10 @@ lws_plat_get_peer_simple(struct lws *wsi, char *name, int namelen); static inline int compatible_close(int fd) { return close(fd); } #endif +#if defined(WIN32) || defined(_WIN32) +#include +#endif + #if defined(MBED_OPERATORS) #undef compatible_close #define compatible_close(fd) mbed3_delete_tcp_stream_socket(fd) diff --git a/win32port/win32helpers/gettimeofday.h b/win32port/win32helpers/gettimeofday.h index 6208dccc..33e7a750 100644 --- a/win32port/win32helpers/gettimeofday.h +++ b/win32port/win32helpers/gettimeofday.h @@ -1,6 +1,8 @@ #ifndef _GET_TIME_OF_DAY_H #define _GET_TIME_OF_DAY_H +#include + #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 #else @@ -18,9 +20,8 @@ struct timezone int tz_dsttime; /* type of dst correction */ }; +#endif + int gettimeofday(struct timeval *tv, struct timezone *tz); #endif - - -#endif