From 0733610c0e4398dd0e61289c6ca064a97db5454f Mon Sep 17 00:00:00 2001 From: Joerg Pommnitz Date: Mon, 10 Oct 2016 20:10:39 +0800 Subject: [PATCH] some compilers need void param explicitly --- doc/html/libwebsockets_8h_source.html | 2 +- lib/libwebsockets.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/html/libwebsockets_8h_source.html b/doc/html/libwebsockets_8h_source.html index 6f99323..c8e2c23 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() { 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;
1711  /* Add new things just above here ---^
1712  * This is part of the ABI, don't needlessly break compatibility
1713  *
1714  * The below is to ensure later library versions with new
1715  * members added above will see 0 (default) even if the app
1716  * was not built against the newer headers.
1717  */
1718 
1719  void *_unused[8];
1720 };
1721 
1756 LWS_VISIBLE LWS_EXTERN struct lws_context *
1758 
1767 LWS_VISIBLE LWS_EXTERN void
1768 lws_context_destroy(struct lws_context *context);
1769 
1787 LWS_VISIBLE LWS_EXTERN int
1788 lws_set_proxy(struct lws_vhost *vhost, const char *proxy);
1789 
1790 
1791 struct lws_vhost;
1792 
1802 LWS_EXTERN LWS_VISIBLE struct lws_vhost *
1803 lws_create_vhost(struct lws_context *context,
1804  struct lws_context_creation_info *info);
1805 
1820 LWS_VISIBLE LWS_EXTERN int
1821 lwsws_get_config_globals(struct lws_context_creation_info *info, const char *d,
1822  char **config_strings, int *len);
1823 
1839 LWS_VISIBLE LWS_EXTERN int
1840 lwsws_get_config_vhosts(struct lws_context *context,
1841  struct lws_context_creation_info *info, const char *d,
1842  char **config_strings, int *len);
1843 
1845 LWS_VISIBLE LWS_EXTERN struct lws_vhost *
1846 lws_vhost_get(struct lws *wsi) LWS_WARN_DEPRECATED;
1847 
1853 LWS_VISIBLE LWS_EXTERN struct lws_vhost *
1854 lws_get_vhost(struct lws *wsi);
1855 
1863 LWS_VISIBLE LWS_EXTERN int
1864 lws_json_dump_vhost(const struct lws_vhost *vh, char *buf, int len);
1865 
1873 LWS_VISIBLE LWS_EXTERN int
1874 lws_json_dump_context(const struct lws_context *context, char *buf, int len);
1875 
1885 LWS_VISIBLE LWS_EXTERN void *
1886 lws_context_user(struct lws_context *context);
1887 
1893 
1903  const char *name;
1904  const char *value;
1905 };
1906 
1919 };
1920 
1928  const char *mountpoint;
1930  const char *origin;
1932  const char *def;
1934  const char *protocol;
1950  unsigned int auth_mask;
1953  unsigned int cache_reusable:1;
1954  unsigned int cache_revalidate:1;
1955  unsigned int cache_intermediaries:1;
1957  unsigned char origin_protocol;
1958  unsigned char mountpoint_len;
1959 };
1962 
1968 
1976  LCCSCF_USE_SSL = (1 << 0),
1977  LCCSCF_ALLOW_SELFSIGNED = (1 << 1),
1978  LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK = (1 << 2)
1979 };
1980 
1985  struct lws_context *context;
1987  const char *address;
1989  int port;
1993  const char *path;
1995  const char *host;
1997  const char *origin;
1999  const char *protocol;
2003  void *userdata;
2007  const char *method;
2010  struct lws *parent_wsi;
2014  const char *uri_replace_from;
2017  const char *uri_replace_to;
2019  struct lws_vhost *vhost;
2021  struct lws **pwsi;
2033  /* Add new things just above here ---^
2034  * This is part of the ABI, don't needlessly break compatibility
2035  *
2036  * The below is to ensure later library versions with new
2037  * members added above will see 0 (default) even if the app
2038  * was not built against the newer headers.
2039  */
2040 
2041  void *_unused[4];
2042 };
2043 
2051 LWS_VISIBLE LWS_EXTERN struct lws *
2053 
2074 /* deprecated, use lws_client_connect_via_info() */
2075 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
2076 lws_client_connect(struct lws_context *clients, const char *address,
2077  int port, int ssl_connection, const char *path,
2078  const char *host, const char *origin, const char *protocol,
2079  int ietf_version_or_minus_one) LWS_WARN_DEPRECATED;
2080 /* deprecated, use lws_client_connect_via_info() */
2101 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
2102 lws_client_connect_extended(struct lws_context *clients, const char *address,
2103  int port, int ssl_connection, const char *path,
2104  const char *host, const char *origin,
2105  const char *protocol, int ietf_version_or_minus_one,
2106  void *userdata) LWS_WARN_DEPRECATED;
2107 
2133 LWS_VISIBLE LWS_EXTERN int
2135  struct lws_vhost *vhost);
2136 
2137 LWS_VISIBLE LWS_EXTERN int
2138 lws_http_client_read(struct lws *wsi, char **buf, int *len);
2139 
2140 LWS_VISIBLE LWS_EXTERN void
2141 lws_client_http_body_pending(struct lws *wsi, int something_left_to_send);
2142 
2163 
2172 
2205 LWS_VISIBLE LWS_EXTERN int
2206 lws_service(struct lws_context *context, int timeout_ms);
2207 
2219 LWS_VISIBLE LWS_EXTERN int
2220 lws_service_tsi(struct lws_context *context, int timeout_ms, int tsi);
2221 
2237 LWS_VISIBLE LWS_EXTERN void
2238 lws_cancel_service_pt(struct lws *wsi);
2239 
2251 LWS_VISIBLE LWS_EXTERN void
2252 lws_cancel_service(struct lws_context *context);
2253 
2280 LWS_VISIBLE LWS_EXTERN int
2281 lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd);
2282 
2292 LWS_VISIBLE LWS_EXTERN int
2293 lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,
2294  int tsi);
2295 
2313 LWS_VISIBLE LWS_EXTERN int
2314 lws_service_adjust_timeout(struct lws_context *context, int timeout_ms, int tsi);
2315 
2331 LWS_EXTERN LWS_VISIBLE int
2332 lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi);
2333 
2335 
2341 
2348 
2360 LWS_VISIBLE LWS_EXTERN const char *
2361 lws_get_mimetype(const char *file, const struct lws_http_mount *m);
2362 
2381 LWS_VISIBLE LWS_EXTERN int
2382 lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type,
2383  const char *other_headers, int other_headers_len);
2384 LWS_VISIBLE LWS_EXTERN int
2385 lws_serve_http_file_fragment(struct lws *wsi);
2387 
2398 
2399 enum http_status {
2400  HTTP_STATUS_OK = 200,
2401  HTTP_STATUS_NO_CONTENT = 204,
2402 
2403  HTTP_STATUS_MOVED_PERMANENTLY = 301,
2404  HTTP_STATUS_FOUND = 302,
2405  HTTP_STATUS_SEE_OTHER = 303,
2406 
2407  HTTP_STATUS_BAD_REQUEST = 400,
2408  HTTP_STATUS_UNAUTHORIZED,
2409  HTTP_STATUS_PAYMENT_REQUIRED,
2410  HTTP_STATUS_FORBIDDEN,
2411  HTTP_STATUS_NOT_FOUND,
2412  HTTP_STATUS_METHOD_NOT_ALLOWED,
2413  HTTP_STATUS_NOT_ACCEPTABLE,
2414  HTTP_STATUS_PROXY_AUTH_REQUIRED,
2415  HTTP_STATUS_REQUEST_TIMEOUT,
2416  HTTP_STATUS_CONFLICT,
2417  HTTP_STATUS_GONE,
2418  HTTP_STATUS_LENGTH_REQUIRED,
2419  HTTP_STATUS_PRECONDITION_FAILED,
2420  HTTP_STATUS_REQ_ENTITY_TOO_LARGE,
2421  HTTP_STATUS_REQ_URI_TOO_LONG,
2422  HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE,
2423  HTTP_STATUS_REQ_RANGE_NOT_SATISFIABLE,
2424  HTTP_STATUS_EXPECTATION_FAILED,
2425 
2426  HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,
2427  HTTP_STATUS_NOT_IMPLEMENTED,
2428  HTTP_STATUS_BAD_GATEWAY,
2429  HTTP_STATUS_SERVICE_UNAVAILABLE,
2430  HTTP_STATUS_GATEWAY_TIMEOUT,
2431  HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED,
2432 };
2433 
2435  char *p;
2436  int len;
2437  int max_len;
2438  int final;
2439 };
2440 
2441 typedef const char *(*lws_process_html_state_cb)(void *data, int index);
2442 
2444  char *start;
2445  char swallow[16];
2446  int pos;
2447  void *data;
2448  const char * const *vars;
2451  lws_process_html_state_cb replace;
2452 };
2453 
2458 LWS_VISIBLE LWS_EXTERN int
2460  struct lws_process_html_state *s);
2462 
2495 
2503 struct lws_tokens {
2504  char *token;
2506 };
2507 
2508 /* enum lws_token_indexes
2509  * these have to be kept in sync with lextable.h / minilex.c
2510  *
2511  * NOTE: These public enums are part of the abi. If you want to add one,
2512  * add it at where specified so existing users are unaffected.
2513  */
2514 enum lws_token_indexes {
2515  WSI_TOKEN_GET_URI = 0,
2516  WSI_TOKEN_POST_URI = 1,
2517  WSI_TOKEN_OPTIONS_URI = 2,
2518  WSI_TOKEN_HOST = 3,
2519  WSI_TOKEN_CONNECTION = 4,
2520  WSI_TOKEN_UPGRADE = 5,
2521  WSI_TOKEN_ORIGIN = 6,
2522  WSI_TOKEN_DRAFT = 7,
2523  WSI_TOKEN_CHALLENGE = 8,
2524  WSI_TOKEN_EXTENSIONS = 9,
2525  WSI_TOKEN_KEY1 = 10,
2526  WSI_TOKEN_KEY2 = 11,
2527  WSI_TOKEN_PROTOCOL = 12,
2528  WSI_TOKEN_ACCEPT = 13,
2529  WSI_TOKEN_NONCE = 14,
2530  WSI_TOKEN_HTTP = 15,
2531  WSI_TOKEN_HTTP2_SETTINGS = 16,
2532  WSI_TOKEN_HTTP_ACCEPT = 17,
2533  WSI_TOKEN_HTTP_AC_REQUEST_HEADERS = 18,
2534  WSI_TOKEN_HTTP_IF_MODIFIED_SINCE = 19,
2535  WSI_TOKEN_HTTP_IF_NONE_MATCH = 20,
2536  WSI_TOKEN_HTTP_ACCEPT_ENCODING = 21,
2537  WSI_TOKEN_HTTP_ACCEPT_LANGUAGE = 22,
2538  WSI_TOKEN_HTTP_PRAGMA = 23,
2539  WSI_TOKEN_HTTP_CACHE_CONTROL = 24,
2540  WSI_TOKEN_HTTP_AUTHORIZATION = 25,
2541  WSI_TOKEN_HTTP_COOKIE = 26,
2542  WSI_TOKEN_HTTP_CONTENT_LENGTH = 27,
2543  WSI_TOKEN_HTTP_CONTENT_TYPE = 28,
2544  WSI_TOKEN_HTTP_DATE = 29,
2545  WSI_TOKEN_HTTP_RANGE = 30,
2546  WSI_TOKEN_HTTP_REFERER = 31,
2547  WSI_TOKEN_KEY = 32,
2548  WSI_TOKEN_VERSION = 33,
2549  WSI_TOKEN_SWORIGIN = 34,
2550 
2551  WSI_TOKEN_HTTP_COLON_AUTHORITY = 35,
2552  WSI_TOKEN_HTTP_COLON_METHOD = 36,
2553  WSI_TOKEN_HTTP_COLON_PATH = 37,
2554  WSI_TOKEN_HTTP_COLON_SCHEME = 38,
2555  WSI_TOKEN_HTTP_COLON_STATUS = 39,
2556 
2557  WSI_TOKEN_HTTP_ACCEPT_CHARSET = 40,
2558  WSI_TOKEN_HTTP_ACCEPT_RANGES = 41,
2559  WSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN = 42,
2560  WSI_TOKEN_HTTP_AGE = 43,
2561  WSI_TOKEN_HTTP_ALLOW = 44,
2562  WSI_TOKEN_HTTP_CONTENT_DISPOSITION = 45,
2563  WSI_TOKEN_HTTP_CONTENT_ENCODING = 46,
2564  WSI_TOKEN_HTTP_CONTENT_LANGUAGE = 47,
2565  WSI_TOKEN_HTTP_CONTENT_LOCATION = 48,
2566  WSI_TOKEN_HTTP_CONTENT_RANGE = 49,
2567  WSI_TOKEN_HTTP_ETAG = 50,
2568  WSI_TOKEN_HTTP_EXPECT = 51,
2569  WSI_TOKEN_HTTP_EXPIRES = 52,
2570  WSI_TOKEN_HTTP_FROM = 53,
2571  WSI_TOKEN_HTTP_IF_MATCH = 54,
2572  WSI_TOKEN_HTTP_IF_RANGE = 55,
2573  WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE = 56,
2574  WSI_TOKEN_HTTP_LAST_MODIFIED = 57,
2575  WSI_TOKEN_HTTP_LINK = 58,
2576  WSI_TOKEN_HTTP_LOCATION = 59,
2577  WSI_TOKEN_HTTP_MAX_FORWARDS = 60,
2578  WSI_TOKEN_HTTP_PROXY_AUTHENTICATE = 61,
2579  WSI_TOKEN_HTTP_PROXY_AUTHORIZATION = 62,
2580  WSI_TOKEN_HTTP_REFRESH = 63,
2581  WSI_TOKEN_HTTP_RETRY_AFTER = 64,
2582  WSI_TOKEN_HTTP_SERVER = 65,
2583  WSI_TOKEN_HTTP_SET_COOKIE = 66,
2584  WSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY = 67,
2585  WSI_TOKEN_HTTP_TRANSFER_ENCODING = 68,
2586  WSI_TOKEN_HTTP_USER_AGENT = 69,
2587  WSI_TOKEN_HTTP_VARY = 70,
2588  WSI_TOKEN_HTTP_VIA = 71,
2589  WSI_TOKEN_HTTP_WWW_AUTHENTICATE = 72,
2590 
2591  WSI_TOKEN_PATCH_URI = 73,
2592  WSI_TOKEN_PUT_URI = 74,
2593  WSI_TOKEN_DELETE_URI = 75,
2594 
2595  WSI_TOKEN_HTTP_URI_ARGS = 76,
2596  WSI_TOKEN_PROXY = 77,
2597  WSI_TOKEN_HTTP_X_REAL_IP = 78,
2598  WSI_TOKEN_HTTP1_0 = 79,
2599 
2600  /****** add new things just above ---^ ******/
2601 
2602  /* use token storage to stash these internally, not for
2603  * user use */
2604 
2605  _WSI_TOKEN_CLIENT_SENT_PROTOCOLS,
2606  _WSI_TOKEN_CLIENT_PEER_ADDRESS,
2607  _WSI_TOKEN_CLIENT_URI,
2608  _WSI_TOKEN_CLIENT_HOST,
2609  _WSI_TOKEN_CLIENT_ORIGIN,
2610  _WSI_TOKEN_CLIENT_METHOD,
2611 
2612  /* always last real token index*/
2613  WSI_TOKEN_COUNT,
2614 
2615  /* parser state additions, no storage associated */
2616  WSI_TOKEN_NAME_PART,
2617  WSI_TOKEN_SKIPPING,
2618  WSI_TOKEN_SKIPPING_SAW_CR,
2619  WSI_PARSING_COMPLETE,
2620  WSI_INIT_TOKEN_MUXURL,
2621 };
2622 
2624  unsigned short token_limit[WSI_TOKEN_COUNT];
2625 };
2626 
2632 LWS_VISIBLE LWS_EXTERN const unsigned char *
2633 lws_token_to_string(enum lws_token_indexes token);
2634 
2635 
2644 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2645 lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h);
2646 
2656 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2657 lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx);
2658 
2672 LWS_VISIBLE LWS_EXTERN int
2673 lws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h);
2674 
2692 LWS_VISIBLE LWS_EXTERN int
2693 lws_hdr_copy_fragment(struct lws *wsi, char *dest, int len,
2694  enum lws_token_indexes h, int frag_idx);
2695 
2706 LWS_VISIBLE LWS_EXTERN const char *
2707 lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, int len);
2709 
2724 
2735 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2736 lws_add_http_header_status(struct lws *wsi,
2737  unsigned int code, unsigned char **p,
2738  unsigned char *end);
2751 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2752 lws_add_http_header_by_name(struct lws *wsi, const unsigned char *name,
2753  const unsigned char *value, int length,
2754  unsigned char **p, unsigned char *end);
2768 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2769 lws_add_http_header_by_token(struct lws *wsi, enum lws_token_indexes token,
2770  const unsigned char *value, int length,
2771  unsigned char **p, unsigned char *end);
2782 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2783 lws_add_http_header_content_length(struct lws *wsi,
2784  unsigned long content_length,
2785  unsigned char **p, unsigned char *end);
2795 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2796 lws_finalize_http_header(struct lws *wsi, unsigned char **p,
2797  unsigned char *end);
2799 
2818 
2828 };
2829 
2843 typedef int (*lws_spa_fileupload_cb)(void *data, const char *name,
2844  const char *filename, char *buf, int len,
2845  enum lws_spa_fileupload_states state);
2846 
2849 struct lws_spa;
2850 
2869 LWS_VISIBLE LWS_EXTERN struct lws_spa *
2870 lws_spa_create(struct lws *wsi, const char * const *param_names,
2871  int count_params, int max_storage, lws_spa_fileupload_cb opt_cb,
2872  void *opt_data);
2873 
2881 LWS_VISIBLE LWS_EXTERN int
2882 lws_spa_process(struct lws_spa *spa, const char *in, int len);
2883 
2889 LWS_VISIBLE LWS_EXTERN int
2890 lws_spa_finalize(struct lws_spa *spa);
2891 
2898 LWS_VISIBLE LWS_EXTERN int
2899 lws_spa_get_length(struct lws_spa *spa, int n);
2900 
2906 LWS_VISIBLE LWS_EXTERN const char *
2907 lws_spa_get_string(struct lws_spa *spa, int n);
2908 
2914 LWS_VISIBLE LWS_EXTERN int
2915 lws_spa_destroy(struct lws_spa *spa);
2917 
2928 
2939 LWS_VISIBLE LWS_EXTERN const char *
2940 lws_urlencode(char *escaped, const char *string, int len);
2941 
2942 /*
2943  * URLDECODE 1 / 2
2944  *
2945  * This simple urldecode only operates until the first '\0' and requires the
2946  * data to exist all at once
2947  */
2960 LWS_VISIBLE LWS_EXTERN int
2961 lws_urldecode(char *string, const char *escaped, int len);
2963 
2972 LWS_VISIBLE LWS_EXTERN int
2973 lws_return_http_status(struct lws *wsi, unsigned int code,
2974  const char *html_body);
2975 
2986 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2987 lws_http_redirect(struct lws *wsi, int code, const unsigned char *loc, int len,
2988  unsigned char **p, unsigned char *end);
2989 
2998 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2999 lws_http_transaction_completed(struct lws *wsi);
3001 
3009 
3020 LWS_VISIBLE LWS_EXTERN const char *
3021 lws_sql_purify(char *escaped, const char *string, int len);
3022 
3033 LWS_VISIBLE LWS_EXTERN const char *
3034 lws_json_purify(char *escaped, const char *string, int len);
3036 
3043 
3045 #ifdef LWS_USE_LIBEV
3046 typedef void (lws_ev_signal_cb_t)(EV_P_ struct ev_signal *w, int revents);
3047 
3048 LWS_VISIBLE LWS_EXTERN int
3049 lws_ev_sigint_cfg(struct lws_context *context, int use_ev_sigint,
3050  lws_ev_signal_cb_t *cb);
3051 
3052 LWS_VISIBLE LWS_EXTERN int
3053 lws_ev_initloop(struct lws_context *context, struct ev_loop *loop, int tsi);
3054 
3055 LWS_VISIBLE LWS_EXTERN void
3056 lws_ev_sigint_cb(struct ev_loop *loop, struct ev_signal *watcher, int revents);
3057 #endif /* LWS_USE_LIBEV */
3058 
3060 
3067 #ifdef LWS_USE_LIBUV
3069 LWS_VISIBLE LWS_EXTERN int
3070 lws_uv_sigint_cfg(struct lws_context *context, int use_uv_sigint,
3071  uv_signal_cb cb);
3072 
3073 LWS_VISIBLE LWS_EXTERN void
3074 lws_libuv_run(const struct lws_context *context, int tsi);
3075 
3076 LWS_VISIBLE LWS_EXTERN void
3077 lws_libuv_stop(struct lws_context *context);
3078 
3079 LWS_VISIBLE LWS_EXTERN int
3080 lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi);
3081 
3082 LWS_VISIBLE LWS_EXTERN uv_loop_t *
3083 lws_uv_getloop(struct lws_context *context, int tsi);
3084 
3085 LWS_VISIBLE LWS_EXTERN void
3086 lws_uv_sigint_cb(uv_signal_t *watcher, int signum);
3087 #endif /* LWS_USE_LIBUV */
3088 
3095 
3096 /*
3097  * NOTE: These public enums are part of the abi. If you want to add one,
3098  * add it at where specified so existing users are unaffected.
3099  */
3100 enum pending_timeout {
3101  NO_PENDING_TIMEOUT = 0,
3102  PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE = 1,
3103  PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE = 2,
3104  PENDING_TIMEOUT_ESTABLISH_WITH_SERVER = 3,
3105  PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE = 4,
3106  PENDING_TIMEOUT_AWAITING_PING = 5,
3107  PENDING_TIMEOUT_CLOSE_ACK = 6,
3108  PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE = 7,
3109  PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE = 8,
3110  PENDING_TIMEOUT_SSL_ACCEPT = 9,
3111  PENDING_TIMEOUT_HTTP_CONTENT = 10,
3112  PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND = 11,
3113  PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE = 12,
3114  PENDING_TIMEOUT_SHUTDOWN_FLUSH = 13,
3115  PENDING_TIMEOUT_CGI = 14,
3116  PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE = 15,
3117  PENDING_TIMEOUT_WS_PONG_CHECK_SEND_PING = 16,
3118  PENDING_TIMEOUT_WS_PONG_CHECK_GET_PONG = 17,
3119  PENDING_TIMEOUT_CLIENT_ISSUE_PAYLOAD = 18,
3120 
3121  /****** add new things just above ---^ ******/
3122 };
3123 
3133 LWS_VISIBLE LWS_EXTERN void
3134 lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs);
3136 
3142 #if !defined(LWS_SIZEOFPTR)
3143 #define LWS_SIZEOFPTR (sizeof (void *))
3144 #endif
3145 #if !defined(u_int64_t)
3146 #define u_int64_t unsigned long long
3147 #endif
3148 
3149 #if defined(__x86_64__)
3150 #define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */
3151 #else
3152 #define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target arch */
3153 #endif
3154 #define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
3155  ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
3156 #define LWS_PRE _LWS_PAD(4 + 10)
3157 /* used prior to 1.7 and retained for backward compatibility */
3158 #define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
3159 #define LWS_SEND_BUFFER_POST_PADDING 0
3160 
3161 /*
3162  * NOTE: These public enums are part of the abi. If you want to add one,
3163  * add it at where specified so existing users are unaffected.
3164  */
3179  /* LWS_WRITE_CLOSE is handled by lws_close_reason() */
3180  LWS_WRITE_PING = 5,
3181  LWS_WRITE_PONG = 6,
3182 
3183  /* Same as write_http but we know this write ends the transaction */
3184  LWS_WRITE_HTTP_FINAL = 7,
3185 
3186  /* HTTP2 */
3187 
3195  /****** add new things just above ---^ ******/
3196 
3197  /* flags */
3198 
3206 };
3207 
3208 
3295 LWS_VISIBLE LWS_EXTERN int
3296 lws_write(struct lws *wsi, unsigned char *buf, size_t len,
3297  enum lws_write_protocol protocol);
3298 
3299 /* helper for case where buffer may be const */
3300 #define lws_write_http(wsi, buf, len) \
3301  lws_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP)
3302 
3322 
3335 LWS_VISIBLE LWS_EXTERN int
3336 lws_callback_on_writable(struct lws *wsi);
3337 
3351 LWS_VISIBLE LWS_EXTERN int
3352 lws_callback_on_writable_all_protocol(const struct lws_context *context,
3353  const struct lws_protocols *protocol);
3354 
3368 LWS_VISIBLE LWS_EXTERN int
3369 lws_callback_on_writable_all_protocol_vhost(const struct lws_vhost *vhost,
3370  const struct lws_protocols *protocol);
3371 
3384 LWS_VISIBLE LWS_EXTERN int
3385 lws_callback_all_protocol(struct lws_context *context,
3386  const struct lws_protocols *protocol, int reason);
3387 
3400 LWS_VISIBLE LWS_EXTERN int
3401 lws_callback_all_protocol_vhost(struct lws_vhost *vh,
3402  const struct lws_protocols *protocol, int reason);
3403 
3417 LWS_VISIBLE LWS_EXTERN int
3418 lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len);
3419 
3420 LWS_VISIBLE LWS_EXTERN int
3421 lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
3422  void *user, void *in, size_t len);
3423 
3431 LWS_VISIBLE LWS_EXTERN int
3432 lws_get_socket_fd(struct lws *wsi);
3433 
3455 LWS_VISIBLE LWS_EXTERN size_t
3456 lws_get_peer_write_allowance(struct lws *wsi);
3458 
3469 LWS_VISIBLE LWS_EXTERN int
3470 lws_rx_flow_control(struct lws *wsi, int enable);
3471 
3481 LWS_VISIBLE LWS_EXTERN void
3482 lws_rx_flow_allow_all_protocol(const struct lws_context *context,
3483  const struct lws_protocols *protocol);
3484 
3501 LWS_VISIBLE LWS_EXTERN size_t
3502 lws_remaining_packet_payload(struct lws *wsi);
3503 
3504 
3513 
3526 LWS_VISIBLE LWS_EXTERN struct lws *
3527 lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd);
3550 LWS_VISIBLE LWS_EXTERN struct lws *
3551 lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd,
3552  const char *readbuf, size_t len);
3554 
3560 
3571 LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
3572 lws_canonical_hostname(struct lws_context *context);
3573 
3588 LWS_VISIBLE LWS_EXTERN void
3589 lws_get_peer_addresses(struct lws *wsi, lws_sockfd_type fd, char *name,
3590  int name_len, char *rip, int rip_len);
3591 
3602 LWS_VISIBLE LWS_EXTERN const char *
3603 lws_get_peer_simple(struct lws *wsi, char *name, int namelen);
3604 #ifndef LWS_WITH_ESP8266
3605 
3616 LWS_VISIBLE LWS_EXTERN int
3617 lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr,
3618  size_t addrlen);
3620 #endif
3621 
3627 
3640 LWS_VISIBLE LWS_EXTERN int
3641 lws_snprintf(char *str, size_t size, const char *format, ...);
3642 
3654 LWS_VISIBLE LWS_EXTERN int
3655 lws_get_random(struct lws_context *context, void *buf, int len);
3663 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3664 lws_daemonize(const char *_lock_path);
3670 LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
3672 
3679 LWS_VISIBLE LWS_EXTERN void *
3680 lws_wsi_user(struct lws *wsi);
3681 
3693 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3694 lws_parse_uri(char *p, const char **prot, const char **ads, int *port,
3695  const char **path);
3696 
3700 LWS_VISIBLE LWS_EXTERN unsigned long
3701 lws_now_secs(void);
3702 
3712 LWS_VISIBLE LWS_EXTERN struct lws_context * LWS_WARN_UNUSED_RESULT
3713 lws_get_context(const struct lws *wsi);
3714 
3724 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3725 lws_get_count_threads(struct lws_context *context);
3726 
3734 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
3735 lws_get_parent(const struct lws *wsi);
3736 
3743 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
3744 lws_get_child(const struct lws *wsi);
3745 
3746 
3747 /*
3748  * \deprecated DEPRECATED Note: this is not normally needed as a user api.
3749  * It's provided in case it is
3750  * useful when integrating with other app poll loop service code.
3751  */
3752 LWS_VISIBLE LWS_EXTERN int
3753 lws_read(struct lws *wsi, unsigned char *buf, size_t len);
3754 
3762 LWS_VISIBLE LWS_EXTERN void
3763 lws_set_allocator(void *(*realloc)(void *ptr, size_t size));
3765 
3771 
3778 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3779 lws_send_pipe_choked(struct lws *wsi);
3780 
3785 LWS_VISIBLE LWS_EXTERN int
3786 lws_is_final_fragment(struct lws *wsi);
3787 
3792 LWS_VISIBLE LWS_EXTERN unsigned char
3793 lws_get_reserved_bits(struct lws *wsi);
3794 
3811 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3812 lws_partial_buffered(struct lws *wsi);
3813 
3823 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3824 lws_frame_is_binary(struct lws *wsi);
3825 
3834 LWS_VISIBLE LWS_EXTERN int
3835 lws_is_ssl(struct lws *wsi);
3840 LWS_VISIBLE LWS_EXTERN int
3841 lws_is_cgi(struct lws *wsi);
3843 
3844 
3850 #ifdef LWS_SHA1_USE_OPENSSL_NAME
3852 #define lws_SHA1 SHA1
3853 #else
3854 
3863 LWS_VISIBLE LWS_EXTERN unsigned char *
3864 lws_SHA1(const unsigned char *d, size_t n, unsigned char *md);
3865 #endif
3866 
3876 LWS_VISIBLE LWS_EXTERN int
3877 lws_b64_encode_string(const char *in, int in_len, char *out, int out_size);
3887 LWS_VISIBLE LWS_EXTERN int
3888 lws_b64_decode_string(const char *in, char *out, int out_size);
3890 
3891 
3901 #ifdef LWS_WITH_CGI
3902 enum lws_enum_stdinouterr {
3903  LWS_STDIN = 0,
3904  LWS_STDOUT = 1,
3905  LWS_STDERR = 2,
3906 };
3907 
3908 enum lws_cgi_hdr_state {
3909  LCHS_HEADER,
3910  LCHS_CR1,
3911  LCHS_LF1,
3912  LCHS_CR2,
3913  LCHS_LF2,
3914  LHCS_PAYLOAD,
3915  LCHS_SINGLE_0A,
3916 };
3917 
3919  struct lws **stdwsi;
3920  enum lws_enum_stdinouterr ch;
3921  unsigned char *data;
3922  enum lws_cgi_hdr_state hdr_state;
3923  int len;
3924 };
3925 
3926 
3936 LWS_VISIBLE LWS_EXTERN int
3937 lws_cgi(struct lws *wsi, const char * const *exec_array,
3938  int script_uri_path_len, int timeout_secs,
3939  const struct lws_protocol_vhost_options *mp_cgienv);
3940 
3946 LWS_VISIBLE LWS_EXTERN int
3947 lws_cgi_write_split_stdout_headers(struct lws *wsi);
3948 
3954 LWS_VISIBLE LWS_EXTERN int
3955 lws_cgi_kill(struct lws *wsi);
3956 #endif
3957 
3959 
3976 
3983  lws_filefd_type (*open)(struct lws *wsi, const char *filename,
3984  unsigned long *filelen, int flags);
3988  int (*close)(struct lws *wsi, lws_filefd_type fd);
3990  unsigned long (*seek_cur)(struct lws *wsi, lws_filefd_type fd,
3991  long offset_from_cur_pos);
3993  int (*read)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
3994  unsigned char *buf, unsigned long len);
3996  int (*write)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
3997  unsigned char *buf, unsigned long len);
4000  /* Add new things just above here ---^
4001  * This is part of the ABI, don't needlessly break compatibility */
4002 };
4003 
4009 LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops * LWS_WARN_UNUSED_RESULT
4010 lws_get_fops(struct lws_context *context);
4011 
4020 static LWS_INLINE lws_filefd_type LWS_WARN_UNUSED_RESULT
4021 lws_plat_file_open(struct lws *wsi, const char *filename,
4022  unsigned long *filelen, int flags)
4023 {
4024  return lws_get_fops(lws_get_context(wsi))->open(wsi, filename,
4025  filelen, flags);
4026 }
4027 
4034 static LWS_INLINE int
4035 lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
4036 {
4037  return lws_get_fops(lws_get_context(wsi))->close(wsi, fd);
4038 }
4039 
4047 static LWS_INLINE unsigned long
4048 lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
4049 {
4050  return lws_get_fops(lws_get_context(wsi))->seek_cur(wsi, fd, offset);
4051 }
4061 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
4062 lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
4063  unsigned char *buf, unsigned long len)
4064 {
4065  return lws_get_fops(lws_get_context(wsi))->read(wsi, fd, amount, buf,
4066  len);
4067 }
4077 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
4078 lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
4079  unsigned char *buf, unsigned long len)
4080 {
4081  return lws_get_fops(lws_get_context(wsi))->write(wsi, fd, amount, buf,
4082  len);
4083 }
4085 
4117 #ifdef LWS_WITH_SMTP
4118 
4130 };
4131 
4133 struct lws_email {
4134  void *data;
4136  uv_loop_t *loop;
4139  char email_smtp_ip[32];
4140  char email_helo[32];
4141  char email_from[100];
4142  char email_to[100];
4144  unsigned int max_content_size;
4147  /* Fill all the callbacks before init */
4148 
4149  int (*on_next)(struct lws_email *email);
4154  int (*on_sent)(struct lws_email *email);
4159  int (*on_get_body)(struct lws_email *email, char *buf, int len);
4165  /* private things */
4166  uv_timer_t timeout_email;
4168  uv_connect_t email_connect_req;
4169  uv_tcp_t email_client;
4171  char email_buf[256];
4172  char *content;
4173 };
4174 
4184 LWS_VISIBLE LWS_EXTERN int
4185 lws_email_init(struct lws_email *email, uv_loop_t *loop, int max_content);
4186 
4195 LWS_VISIBLE LWS_EXTERN void
4196 lws_email_check(struct lws_email *email);
4204 LWS_VISIBLE LWS_EXTERN void
4205 lws_email_destroy(struct lws_email *email);
4206 
4207 #endif
4208 
4209 
4210 #ifdef __cplusplus
4211 }
4212 #endif
4213 
4214 #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 #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;
1711  /* Add new things just above here ---^
1712  * This is part of the ABI, don't needlessly break compatibility
1713  *
1714  * The below is to ensure later library versions with new
1715  * members added above will see 0 (default) even if the app
1716  * was not built against the newer headers.
1717  */
1718 
1719  void *_unused[8];
1720 };
1721 
1756 LWS_VISIBLE LWS_EXTERN struct lws_context *
1758 
1767 LWS_VISIBLE LWS_EXTERN void
1768 lws_context_destroy(struct lws_context *context);
1769 
1787 LWS_VISIBLE LWS_EXTERN int
1788 lws_set_proxy(struct lws_vhost *vhost, const char *proxy);
1789 
1790 
1791 struct lws_vhost;
1792 
1802 LWS_EXTERN LWS_VISIBLE struct lws_vhost *
1803 lws_create_vhost(struct lws_context *context,
1804  struct lws_context_creation_info *info);
1805 
1820 LWS_VISIBLE LWS_EXTERN int
1821 lwsws_get_config_globals(struct lws_context_creation_info *info, const char *d,
1822  char **config_strings, int *len);
1823 
1839 LWS_VISIBLE LWS_EXTERN int
1840 lwsws_get_config_vhosts(struct lws_context *context,
1841  struct lws_context_creation_info *info, const char *d,
1842  char **config_strings, int *len);
1843 
1845 LWS_VISIBLE LWS_EXTERN struct lws_vhost *
1846 lws_vhost_get(struct lws *wsi) LWS_WARN_DEPRECATED;
1847 
1853 LWS_VISIBLE LWS_EXTERN struct lws_vhost *
1854 lws_get_vhost(struct lws *wsi);
1855 
1863 LWS_VISIBLE LWS_EXTERN int
1864 lws_json_dump_vhost(const struct lws_vhost *vh, char *buf, int len);
1865 
1873 LWS_VISIBLE LWS_EXTERN int
1874 lws_json_dump_context(const struct lws_context *context, char *buf, int len);
1875 
1885 LWS_VISIBLE LWS_EXTERN void *
1886 lws_context_user(struct lws_context *context);
1887 
1893 
1903  const char *name;
1904  const char *value;
1905 };
1906 
1919 };
1920 
1928  const char *mountpoint;
1930  const char *origin;
1932  const char *def;
1934  const char *protocol;
1950  unsigned int auth_mask;
1953  unsigned int cache_reusable:1;
1954  unsigned int cache_revalidate:1;
1955  unsigned int cache_intermediaries:1;
1957  unsigned char origin_protocol;
1958  unsigned char mountpoint_len;
1959 };
1962 
1968 
1976  LCCSCF_USE_SSL = (1 << 0),
1977  LCCSCF_ALLOW_SELFSIGNED = (1 << 1),
1978  LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK = (1 << 2)
1979 };
1980 
1985  struct lws_context *context;
1987  const char *address;
1989  int port;
1993  const char *path;
1995  const char *host;
1997  const char *origin;
1999  const char *protocol;
2003  void *userdata;
2007  const char *method;
2010  struct lws *parent_wsi;
2014  const char *uri_replace_from;
2017  const char *uri_replace_to;
2019  struct lws_vhost *vhost;
2021  struct lws **pwsi;
2033  /* Add new things just above here ---^
2034  * This is part of the ABI, don't needlessly break compatibility
2035  *
2036  * The below is to ensure later library versions with new
2037  * members added above will see 0 (default) even if the app
2038  * was not built against the newer headers.
2039  */
2040 
2041  void *_unused[4];
2042 };
2043 
2051 LWS_VISIBLE LWS_EXTERN struct lws *
2053 
2074 /* deprecated, use lws_client_connect_via_info() */
2075 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
2076 lws_client_connect(struct lws_context *clients, const char *address,
2077  int port, int ssl_connection, const char *path,
2078  const char *host, const char *origin, const char *protocol,
2079  int ietf_version_or_minus_one) LWS_WARN_DEPRECATED;
2080 /* deprecated, use lws_client_connect_via_info() */
2101 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
2102 lws_client_connect_extended(struct lws_context *clients, const char *address,
2103  int port, int ssl_connection, const char *path,
2104  const char *host, const char *origin,
2105  const char *protocol, int ietf_version_or_minus_one,
2106  void *userdata) LWS_WARN_DEPRECATED;
2107 
2133 LWS_VISIBLE LWS_EXTERN int
2135  struct lws_vhost *vhost);
2136 
2137 LWS_VISIBLE LWS_EXTERN int
2138 lws_http_client_read(struct lws *wsi, char **buf, int *len);
2139 
2140 LWS_VISIBLE LWS_EXTERN void
2141 lws_client_http_body_pending(struct lws *wsi, int something_left_to_send);
2142 
2163 
2172 
2205 LWS_VISIBLE LWS_EXTERN int
2206 lws_service(struct lws_context *context, int timeout_ms);
2207 
2219 LWS_VISIBLE LWS_EXTERN int
2220 lws_service_tsi(struct lws_context *context, int timeout_ms, int tsi);
2221 
2237 LWS_VISIBLE LWS_EXTERN void
2238 lws_cancel_service_pt(struct lws *wsi);
2239 
2251 LWS_VISIBLE LWS_EXTERN void
2252 lws_cancel_service(struct lws_context *context);
2253 
2280 LWS_VISIBLE LWS_EXTERN int
2281 lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd);
2282 
2292 LWS_VISIBLE LWS_EXTERN int
2293 lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,
2294  int tsi);
2295 
2313 LWS_VISIBLE LWS_EXTERN int
2314 lws_service_adjust_timeout(struct lws_context *context, int timeout_ms, int tsi);
2315 
2331 LWS_EXTERN LWS_VISIBLE int
2332 lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi);
2333 
2335 
2341 
2348 
2360 LWS_VISIBLE LWS_EXTERN const char *
2361 lws_get_mimetype(const char *file, const struct lws_http_mount *m);
2362 
2381 LWS_VISIBLE LWS_EXTERN int
2382 lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type,
2383  const char *other_headers, int other_headers_len);
2384 LWS_VISIBLE LWS_EXTERN int
2385 lws_serve_http_file_fragment(struct lws *wsi);
2387 
2398 
2399 enum http_status {
2400  HTTP_STATUS_OK = 200,
2401  HTTP_STATUS_NO_CONTENT = 204,
2402 
2403  HTTP_STATUS_MOVED_PERMANENTLY = 301,
2404  HTTP_STATUS_FOUND = 302,
2405  HTTP_STATUS_SEE_OTHER = 303,
2406 
2407  HTTP_STATUS_BAD_REQUEST = 400,
2408  HTTP_STATUS_UNAUTHORIZED,
2409  HTTP_STATUS_PAYMENT_REQUIRED,
2410  HTTP_STATUS_FORBIDDEN,
2411  HTTP_STATUS_NOT_FOUND,
2412  HTTP_STATUS_METHOD_NOT_ALLOWED,
2413  HTTP_STATUS_NOT_ACCEPTABLE,
2414  HTTP_STATUS_PROXY_AUTH_REQUIRED,
2415  HTTP_STATUS_REQUEST_TIMEOUT,
2416  HTTP_STATUS_CONFLICT,
2417  HTTP_STATUS_GONE,
2418  HTTP_STATUS_LENGTH_REQUIRED,
2419  HTTP_STATUS_PRECONDITION_FAILED,
2420  HTTP_STATUS_REQ_ENTITY_TOO_LARGE,
2421  HTTP_STATUS_REQ_URI_TOO_LONG,
2422  HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE,
2423  HTTP_STATUS_REQ_RANGE_NOT_SATISFIABLE,
2424  HTTP_STATUS_EXPECTATION_FAILED,
2425 
2426  HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,
2427  HTTP_STATUS_NOT_IMPLEMENTED,
2428  HTTP_STATUS_BAD_GATEWAY,
2429  HTTP_STATUS_SERVICE_UNAVAILABLE,
2430  HTTP_STATUS_GATEWAY_TIMEOUT,
2431  HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED,
2432 };
2433 
2435  char *p;
2436  int len;
2437  int max_len;
2438  int final;
2439 };
2440 
2441 typedef const char *(*lws_process_html_state_cb)(void *data, int index);
2442 
2444  char *start;
2445  char swallow[16];
2446  int pos;
2447  void *data;
2448  const char * const *vars;
2451  lws_process_html_state_cb replace;
2452 };
2453 
2458 LWS_VISIBLE LWS_EXTERN int
2460  struct lws_process_html_state *s);
2462 
2495 
2503 struct lws_tokens {
2504  char *token;
2506 };
2507 
2508 /* enum lws_token_indexes
2509  * these have to be kept in sync with lextable.h / minilex.c
2510  *
2511  * NOTE: These public enums are part of the abi. If you want to add one,
2512  * add it at where specified so existing users are unaffected.
2513  */
2514 enum lws_token_indexes {
2515  WSI_TOKEN_GET_URI = 0,
2516  WSI_TOKEN_POST_URI = 1,
2517  WSI_TOKEN_OPTIONS_URI = 2,
2518  WSI_TOKEN_HOST = 3,
2519  WSI_TOKEN_CONNECTION = 4,
2520  WSI_TOKEN_UPGRADE = 5,
2521  WSI_TOKEN_ORIGIN = 6,
2522  WSI_TOKEN_DRAFT = 7,
2523  WSI_TOKEN_CHALLENGE = 8,
2524  WSI_TOKEN_EXTENSIONS = 9,
2525  WSI_TOKEN_KEY1 = 10,
2526  WSI_TOKEN_KEY2 = 11,
2527  WSI_TOKEN_PROTOCOL = 12,
2528  WSI_TOKEN_ACCEPT = 13,
2529  WSI_TOKEN_NONCE = 14,
2530  WSI_TOKEN_HTTP = 15,
2531  WSI_TOKEN_HTTP2_SETTINGS = 16,
2532  WSI_TOKEN_HTTP_ACCEPT = 17,
2533  WSI_TOKEN_HTTP_AC_REQUEST_HEADERS = 18,
2534  WSI_TOKEN_HTTP_IF_MODIFIED_SINCE = 19,
2535  WSI_TOKEN_HTTP_IF_NONE_MATCH = 20,
2536  WSI_TOKEN_HTTP_ACCEPT_ENCODING = 21,
2537  WSI_TOKEN_HTTP_ACCEPT_LANGUAGE = 22,
2538  WSI_TOKEN_HTTP_PRAGMA = 23,
2539  WSI_TOKEN_HTTP_CACHE_CONTROL = 24,
2540  WSI_TOKEN_HTTP_AUTHORIZATION = 25,
2541  WSI_TOKEN_HTTP_COOKIE = 26,
2542  WSI_TOKEN_HTTP_CONTENT_LENGTH = 27,
2543  WSI_TOKEN_HTTP_CONTENT_TYPE = 28,
2544  WSI_TOKEN_HTTP_DATE = 29,
2545  WSI_TOKEN_HTTP_RANGE = 30,
2546  WSI_TOKEN_HTTP_REFERER = 31,
2547  WSI_TOKEN_KEY = 32,
2548  WSI_TOKEN_VERSION = 33,
2549  WSI_TOKEN_SWORIGIN = 34,
2550 
2551  WSI_TOKEN_HTTP_COLON_AUTHORITY = 35,
2552  WSI_TOKEN_HTTP_COLON_METHOD = 36,
2553  WSI_TOKEN_HTTP_COLON_PATH = 37,
2554  WSI_TOKEN_HTTP_COLON_SCHEME = 38,
2555  WSI_TOKEN_HTTP_COLON_STATUS = 39,
2556 
2557  WSI_TOKEN_HTTP_ACCEPT_CHARSET = 40,
2558  WSI_TOKEN_HTTP_ACCEPT_RANGES = 41,
2559  WSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN = 42,
2560  WSI_TOKEN_HTTP_AGE = 43,
2561  WSI_TOKEN_HTTP_ALLOW = 44,
2562  WSI_TOKEN_HTTP_CONTENT_DISPOSITION = 45,
2563  WSI_TOKEN_HTTP_CONTENT_ENCODING = 46,
2564  WSI_TOKEN_HTTP_CONTENT_LANGUAGE = 47,
2565  WSI_TOKEN_HTTP_CONTENT_LOCATION = 48,
2566  WSI_TOKEN_HTTP_CONTENT_RANGE = 49,
2567  WSI_TOKEN_HTTP_ETAG = 50,
2568  WSI_TOKEN_HTTP_EXPECT = 51,
2569  WSI_TOKEN_HTTP_EXPIRES = 52,
2570  WSI_TOKEN_HTTP_FROM = 53,
2571  WSI_TOKEN_HTTP_IF_MATCH = 54,
2572  WSI_TOKEN_HTTP_IF_RANGE = 55,
2573  WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE = 56,
2574  WSI_TOKEN_HTTP_LAST_MODIFIED = 57,
2575  WSI_TOKEN_HTTP_LINK = 58,
2576  WSI_TOKEN_HTTP_LOCATION = 59,
2577  WSI_TOKEN_HTTP_MAX_FORWARDS = 60,
2578  WSI_TOKEN_HTTP_PROXY_AUTHENTICATE = 61,
2579  WSI_TOKEN_HTTP_PROXY_AUTHORIZATION = 62,
2580  WSI_TOKEN_HTTP_REFRESH = 63,
2581  WSI_TOKEN_HTTP_RETRY_AFTER = 64,
2582  WSI_TOKEN_HTTP_SERVER = 65,
2583  WSI_TOKEN_HTTP_SET_COOKIE = 66,
2584  WSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY = 67,
2585  WSI_TOKEN_HTTP_TRANSFER_ENCODING = 68,
2586  WSI_TOKEN_HTTP_USER_AGENT = 69,
2587  WSI_TOKEN_HTTP_VARY = 70,
2588  WSI_TOKEN_HTTP_VIA = 71,
2589  WSI_TOKEN_HTTP_WWW_AUTHENTICATE = 72,
2590 
2591  WSI_TOKEN_PATCH_URI = 73,
2592  WSI_TOKEN_PUT_URI = 74,
2593  WSI_TOKEN_DELETE_URI = 75,
2594 
2595  WSI_TOKEN_HTTP_URI_ARGS = 76,
2596  WSI_TOKEN_PROXY = 77,
2597  WSI_TOKEN_HTTP_X_REAL_IP = 78,
2598  WSI_TOKEN_HTTP1_0 = 79,
2599 
2600  /****** add new things just above ---^ ******/
2601 
2602  /* use token storage to stash these internally, not for
2603  * user use */
2604 
2605  _WSI_TOKEN_CLIENT_SENT_PROTOCOLS,
2606  _WSI_TOKEN_CLIENT_PEER_ADDRESS,
2607  _WSI_TOKEN_CLIENT_URI,
2608  _WSI_TOKEN_CLIENT_HOST,
2609  _WSI_TOKEN_CLIENT_ORIGIN,
2610  _WSI_TOKEN_CLIENT_METHOD,
2611 
2612  /* always last real token index*/
2613  WSI_TOKEN_COUNT,
2614 
2615  /* parser state additions, no storage associated */
2616  WSI_TOKEN_NAME_PART,
2617  WSI_TOKEN_SKIPPING,
2618  WSI_TOKEN_SKIPPING_SAW_CR,
2619  WSI_PARSING_COMPLETE,
2620  WSI_INIT_TOKEN_MUXURL,
2621 };
2622 
2624  unsigned short token_limit[WSI_TOKEN_COUNT];
2625 };
2626 
2632 LWS_VISIBLE LWS_EXTERN const unsigned char *
2633 lws_token_to_string(enum lws_token_indexes token);
2634 
2635 
2644 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2645 lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h);
2646 
2656 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2657 lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx);
2658 
2672 LWS_VISIBLE LWS_EXTERN int
2673 lws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h);
2674 
2692 LWS_VISIBLE LWS_EXTERN int
2693 lws_hdr_copy_fragment(struct lws *wsi, char *dest, int len,
2694  enum lws_token_indexes h, int frag_idx);
2695 
2706 LWS_VISIBLE LWS_EXTERN const char *
2707 lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, int len);
2709 
2724 
2735 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2736 lws_add_http_header_status(struct lws *wsi,
2737  unsigned int code, unsigned char **p,
2738  unsigned char *end);
2751 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2752 lws_add_http_header_by_name(struct lws *wsi, const unsigned char *name,
2753  const unsigned char *value, int length,
2754  unsigned char **p, unsigned char *end);
2768 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2769 lws_add_http_header_by_token(struct lws *wsi, enum lws_token_indexes token,
2770  const unsigned char *value, int length,
2771  unsigned char **p, unsigned char *end);
2782 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2783 lws_add_http_header_content_length(struct lws *wsi,
2784  unsigned long content_length,
2785  unsigned char **p, unsigned char *end);
2795 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2796 lws_finalize_http_header(struct lws *wsi, unsigned char **p,
2797  unsigned char *end);
2799 
2818 
2828 };
2829 
2843 typedef int (*lws_spa_fileupload_cb)(void *data, const char *name,
2844  const char *filename, char *buf, int len,
2845  enum lws_spa_fileupload_states state);
2846 
2849 struct lws_spa;
2850 
2869 LWS_VISIBLE LWS_EXTERN struct lws_spa *
2870 lws_spa_create(struct lws *wsi, const char * const *param_names,
2871  int count_params, int max_storage, lws_spa_fileupload_cb opt_cb,
2872  void *opt_data);
2873 
2881 LWS_VISIBLE LWS_EXTERN int
2882 lws_spa_process(struct lws_spa *spa, const char *in, int len);
2883 
2889 LWS_VISIBLE LWS_EXTERN int
2890 lws_spa_finalize(struct lws_spa *spa);
2891 
2898 LWS_VISIBLE LWS_EXTERN int
2899 lws_spa_get_length(struct lws_spa *spa, int n);
2900 
2906 LWS_VISIBLE LWS_EXTERN const char *
2907 lws_spa_get_string(struct lws_spa *spa, int n);
2908 
2914 LWS_VISIBLE LWS_EXTERN int
2915 lws_spa_destroy(struct lws_spa *spa);
2917 
2928 
2939 LWS_VISIBLE LWS_EXTERN const char *
2940 lws_urlencode(char *escaped, const char *string, int len);
2941 
2942 /*
2943  * URLDECODE 1 / 2
2944  *
2945  * This simple urldecode only operates until the first '\0' and requires the
2946  * data to exist all at once
2947  */
2960 LWS_VISIBLE LWS_EXTERN int
2961 lws_urldecode(char *string, const char *escaped, int len);
2963 
2972 LWS_VISIBLE LWS_EXTERN int
2973 lws_return_http_status(struct lws *wsi, unsigned int code,
2974  const char *html_body);
2975 
2986 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2987 lws_http_redirect(struct lws *wsi, int code, const unsigned char *loc, int len,
2988  unsigned char **p, unsigned char *end);
2989 
2998 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2999 lws_http_transaction_completed(struct lws *wsi);
3001 
3009 
3020 LWS_VISIBLE LWS_EXTERN const char *
3021 lws_sql_purify(char *escaped, const char *string, int len);
3022 
3033 LWS_VISIBLE LWS_EXTERN const char *
3034 lws_json_purify(char *escaped, const char *string, int len);
3036 
3043 
3045 #ifdef LWS_USE_LIBEV
3046 typedef void (lws_ev_signal_cb_t)(EV_P_ struct ev_signal *w, int revents);
3047 
3048 LWS_VISIBLE LWS_EXTERN int
3049 lws_ev_sigint_cfg(struct lws_context *context, int use_ev_sigint,
3050  lws_ev_signal_cb_t *cb);
3051 
3052 LWS_VISIBLE LWS_EXTERN int
3053 lws_ev_initloop(struct lws_context *context, struct ev_loop *loop, int tsi);
3054 
3055 LWS_VISIBLE LWS_EXTERN void
3056 lws_ev_sigint_cb(struct ev_loop *loop, struct ev_signal *watcher, int revents);
3057 #endif /* LWS_USE_LIBEV */
3058 
3060 
3067 #ifdef LWS_USE_LIBUV
3069 LWS_VISIBLE LWS_EXTERN int
3070 lws_uv_sigint_cfg(struct lws_context *context, int use_uv_sigint,
3071  uv_signal_cb cb);
3072 
3073 LWS_VISIBLE LWS_EXTERN void
3074 lws_libuv_run(const struct lws_context *context, int tsi);
3075 
3076 LWS_VISIBLE LWS_EXTERN void
3077 lws_libuv_stop(struct lws_context *context);
3078 
3079 LWS_VISIBLE LWS_EXTERN int
3080 lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi);
3081 
3082 LWS_VISIBLE LWS_EXTERN uv_loop_t *
3083 lws_uv_getloop(struct lws_context *context, int tsi);
3084 
3085 LWS_VISIBLE LWS_EXTERN void
3086 lws_uv_sigint_cb(uv_signal_t *watcher, int signum);
3087 #endif /* LWS_USE_LIBUV */
3088 
3095 
3096 /*
3097  * NOTE: These public enums are part of the abi. If you want to add one,
3098  * add it at where specified so existing users are unaffected.
3099  */
3100 enum pending_timeout {
3101  NO_PENDING_TIMEOUT = 0,
3102  PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE = 1,
3103  PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE = 2,
3104  PENDING_TIMEOUT_ESTABLISH_WITH_SERVER = 3,
3105  PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE = 4,
3106  PENDING_TIMEOUT_AWAITING_PING = 5,
3107  PENDING_TIMEOUT_CLOSE_ACK = 6,
3108  PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE = 7,
3109  PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE = 8,
3110  PENDING_TIMEOUT_SSL_ACCEPT = 9,
3111  PENDING_TIMEOUT_HTTP_CONTENT = 10,
3112  PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND = 11,
3113  PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE = 12,
3114  PENDING_TIMEOUT_SHUTDOWN_FLUSH = 13,
3115  PENDING_TIMEOUT_CGI = 14,
3116  PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE = 15,
3117  PENDING_TIMEOUT_WS_PONG_CHECK_SEND_PING = 16,
3118  PENDING_TIMEOUT_WS_PONG_CHECK_GET_PONG = 17,
3119  PENDING_TIMEOUT_CLIENT_ISSUE_PAYLOAD = 18,
3120 
3121  /****** add new things just above ---^ ******/
3122 };
3123 
3133 LWS_VISIBLE LWS_EXTERN void
3134 lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs);
3136 
3142 #if !defined(LWS_SIZEOFPTR)
3143 #define LWS_SIZEOFPTR (sizeof (void *))
3144 #endif
3145 #if !defined(u_int64_t)
3146 #define u_int64_t unsigned long long
3147 #endif
3148 
3149 #if defined(__x86_64__)
3150 #define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */
3151 #else
3152 #define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target arch */
3153 #endif
3154 #define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
3155  ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
3156 #define LWS_PRE _LWS_PAD(4 + 10)
3157 /* used prior to 1.7 and retained for backward compatibility */
3158 #define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
3159 #define LWS_SEND_BUFFER_POST_PADDING 0
3160 
3161 /*
3162  * NOTE: These public enums are part of the abi. If you want to add one,
3163  * add it at where specified so existing users are unaffected.
3164  */
3179  /* LWS_WRITE_CLOSE is handled by lws_close_reason() */
3180  LWS_WRITE_PING = 5,
3181  LWS_WRITE_PONG = 6,
3182 
3183  /* Same as write_http but we know this write ends the transaction */
3184  LWS_WRITE_HTTP_FINAL = 7,
3185 
3186  /* HTTP2 */
3187 
3195  /****** add new things just above ---^ ******/
3196 
3197  /* flags */
3198 
3206 };
3207 
3208 
3295 LWS_VISIBLE LWS_EXTERN int
3296 lws_write(struct lws *wsi, unsigned char *buf, size_t len,
3297  enum lws_write_protocol protocol);
3298 
3299 /* helper for case where buffer may be const */
3300 #define lws_write_http(wsi, buf, len) \
3301  lws_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP)
3302 
3322 
3335 LWS_VISIBLE LWS_EXTERN int
3336 lws_callback_on_writable(struct lws *wsi);
3337 
3351 LWS_VISIBLE LWS_EXTERN int
3352 lws_callback_on_writable_all_protocol(const struct lws_context *context,
3353  const struct lws_protocols *protocol);
3354 
3368 LWS_VISIBLE LWS_EXTERN int
3369 lws_callback_on_writable_all_protocol_vhost(const struct lws_vhost *vhost,
3370  const struct lws_protocols *protocol);
3371 
3384 LWS_VISIBLE LWS_EXTERN int
3385 lws_callback_all_protocol(struct lws_context *context,
3386  const struct lws_protocols *protocol, int reason);
3387 
3400 LWS_VISIBLE LWS_EXTERN int
3401 lws_callback_all_protocol_vhost(struct lws_vhost *vh,
3402  const struct lws_protocols *protocol, int reason);
3403 
3417 LWS_VISIBLE LWS_EXTERN int
3418 lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len);
3419 
3420 LWS_VISIBLE LWS_EXTERN int
3421 lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
3422  void *user, void *in, size_t len);
3423 
3431 LWS_VISIBLE LWS_EXTERN int
3432 lws_get_socket_fd(struct lws *wsi);
3433 
3455 LWS_VISIBLE LWS_EXTERN size_t
3456 lws_get_peer_write_allowance(struct lws *wsi);
3458 
3469 LWS_VISIBLE LWS_EXTERN int
3470 lws_rx_flow_control(struct lws *wsi, int enable);
3471 
3481 LWS_VISIBLE LWS_EXTERN void
3482 lws_rx_flow_allow_all_protocol(const struct lws_context *context,
3483  const struct lws_protocols *protocol);
3484 
3501 LWS_VISIBLE LWS_EXTERN size_t
3502 lws_remaining_packet_payload(struct lws *wsi);
3503 
3504 
3513 
3526 LWS_VISIBLE LWS_EXTERN struct lws *
3527 lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd);
3550 LWS_VISIBLE LWS_EXTERN struct lws *
3551 lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd,
3552  const char *readbuf, size_t len);
3554 
3560 
3571 LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
3572 lws_canonical_hostname(struct lws_context *context);
3573 
3588 LWS_VISIBLE LWS_EXTERN void
3589 lws_get_peer_addresses(struct lws *wsi, lws_sockfd_type fd, char *name,
3590  int name_len, char *rip, int rip_len);
3591 
3602 LWS_VISIBLE LWS_EXTERN const char *
3603 lws_get_peer_simple(struct lws *wsi, char *name, int namelen);
3604 #ifndef LWS_WITH_ESP8266
3605 
3616 LWS_VISIBLE LWS_EXTERN int
3617 lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr,
3618  size_t addrlen);
3620 #endif
3621 
3627 
3640 LWS_VISIBLE LWS_EXTERN int
3641 lws_snprintf(char *str, size_t size, const char *format, ...);
3642 
3654 LWS_VISIBLE LWS_EXTERN int
3655 lws_get_random(struct lws_context *context, void *buf, int len);
3663 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3664 lws_daemonize(const char *_lock_path);
3670 LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
3672 
3679 LWS_VISIBLE LWS_EXTERN void *
3680 lws_wsi_user(struct lws *wsi);
3681 
3693 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3694 lws_parse_uri(char *p, const char **prot, const char **ads, int *port,
3695  const char **path);
3696 
3700 LWS_VISIBLE LWS_EXTERN unsigned long
3701 lws_now_secs(void);
3702 
3712 LWS_VISIBLE LWS_EXTERN struct lws_context * LWS_WARN_UNUSED_RESULT
3713 lws_get_context(const struct lws *wsi);
3714 
3724 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3725 lws_get_count_threads(struct lws_context *context);
3726 
3734 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
3735 lws_get_parent(const struct lws *wsi);
3736 
3743 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
3744 lws_get_child(const struct lws *wsi);
3745 
3746 
3747 /*
3748  * \deprecated DEPRECATED Note: this is not normally needed as a user api.
3749  * It's provided in case it is
3750  * useful when integrating with other app poll loop service code.
3751  */
3752 LWS_VISIBLE LWS_EXTERN int
3753 lws_read(struct lws *wsi, unsigned char *buf, size_t len);
3754 
3762 LWS_VISIBLE LWS_EXTERN void
3763 lws_set_allocator(void *(*realloc)(void *ptr, size_t size));
3765 
3771 
3778 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3779 lws_send_pipe_choked(struct lws *wsi);
3780 
3785 LWS_VISIBLE LWS_EXTERN int
3786 lws_is_final_fragment(struct lws *wsi);
3787 
3792 LWS_VISIBLE LWS_EXTERN unsigned char
3793 lws_get_reserved_bits(struct lws *wsi);
3794 
3811 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3812 lws_partial_buffered(struct lws *wsi);
3813 
3823 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3824 lws_frame_is_binary(struct lws *wsi);
3825 
3834 LWS_VISIBLE LWS_EXTERN int
3835 lws_is_ssl(struct lws *wsi);
3840 LWS_VISIBLE LWS_EXTERN int
3841 lws_is_cgi(struct lws *wsi);
3843 
3844 
3850 #ifdef LWS_SHA1_USE_OPENSSL_NAME
3852 #define lws_SHA1 SHA1
3853 #else
3854 
3863 LWS_VISIBLE LWS_EXTERN unsigned char *
3864 lws_SHA1(const unsigned char *d, size_t n, unsigned char *md);
3865 #endif
3866 
3876 LWS_VISIBLE LWS_EXTERN int
3877 lws_b64_encode_string(const char *in, int in_len, char *out, int out_size);
3887 LWS_VISIBLE LWS_EXTERN int
3888 lws_b64_decode_string(const char *in, char *out, int out_size);
3890 
3891 
3901 #ifdef LWS_WITH_CGI
3902 enum lws_enum_stdinouterr {
3903  LWS_STDIN = 0,
3904  LWS_STDOUT = 1,
3905  LWS_STDERR = 2,
3906 };
3907 
3908 enum lws_cgi_hdr_state {
3909  LCHS_HEADER,
3910  LCHS_CR1,
3911  LCHS_LF1,
3912  LCHS_CR2,
3913  LCHS_LF2,
3914  LHCS_PAYLOAD,
3915  LCHS_SINGLE_0A,
3916 };
3917 
3919  struct lws **stdwsi;
3920  enum lws_enum_stdinouterr ch;
3921  unsigned char *data;
3922  enum lws_cgi_hdr_state hdr_state;
3923  int len;
3924 };
3925 
3926 
3936 LWS_VISIBLE LWS_EXTERN int
3937 lws_cgi(struct lws *wsi, const char * const *exec_array,
3938  int script_uri_path_len, int timeout_secs,
3939  const struct lws_protocol_vhost_options *mp_cgienv);
3940 
3946 LWS_VISIBLE LWS_EXTERN int
3947 lws_cgi_write_split_stdout_headers(struct lws *wsi);
3948 
3954 LWS_VISIBLE LWS_EXTERN int
3955 lws_cgi_kill(struct lws *wsi);
3956 #endif
3957 
3959 
3976 
3983  lws_filefd_type (*open)(struct lws *wsi, const char *filename,
3984  unsigned long *filelen, int flags);
3988  int (*close)(struct lws *wsi, lws_filefd_type fd);
3990  unsigned long (*seek_cur)(struct lws *wsi, lws_filefd_type fd,
3991  long offset_from_cur_pos);
3993  int (*read)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
3994  unsigned char *buf, unsigned long len);
3996  int (*write)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
3997  unsigned char *buf, unsigned long len);
4000  /* Add new things just above here ---^
4001  * This is part of the ABI, don't needlessly break compatibility */
4002 };
4003 
4009 LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops * LWS_WARN_UNUSED_RESULT
4010 lws_get_fops(struct lws_context *context);
4011 
4020 static LWS_INLINE lws_filefd_type LWS_WARN_UNUSED_RESULT
4021 lws_plat_file_open(struct lws *wsi, const char *filename,
4022  unsigned long *filelen, int flags)
4023 {
4024  return lws_get_fops(lws_get_context(wsi))->open(wsi, filename,
4025  filelen, flags);
4026 }
4027 
4034 static LWS_INLINE int
4035 lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
4036 {
4037  return lws_get_fops(lws_get_context(wsi))->close(wsi, fd);
4038 }
4039 
4047 static LWS_INLINE unsigned long
4048 lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
4049 {
4050  return lws_get_fops(lws_get_context(wsi))->seek_cur(wsi, fd, offset);
4051 }
4061 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
4062 lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
4063  unsigned char *buf, unsigned long len)
4064 {
4065  return lws_get_fops(lws_get_context(wsi))->read(wsi, fd, amount, buf,
4066  len);
4067 }
4077 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
4078 lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
4079  unsigned char *buf, unsigned long len)
4080 {
4081  return lws_get_fops(lws_get_context(wsi))->write(wsi, fd, amount, buf,
4082  len);
4083 }
4085 
4117 #ifdef LWS_WITH_SMTP
4118 
4130 };
4131 
4133 struct lws_email {
4134  void *data;
4136  uv_loop_t *loop;
4139  char email_smtp_ip[32];
4140  char email_helo[32];
4141  char email_from[100];
4142  char email_to[100];
4144  unsigned int max_content_size;
4147  /* Fill all the callbacks before init */
4148 
4149  int (*on_next)(struct lws_email *email);
4154  int (*on_sent)(struct lws_email *email);
4159  int (*on_get_body)(struct lws_email *email, char *buf, int len);
4165  /* private things */
4166  uv_timer_t timeout_email;
4168  uv_connect_t email_connect_req;
4169  uv_tcp_t email_client;
4171  char email_buf[256];
4172  char *content;
4173 };
4174 
4184 LWS_VISIBLE LWS_EXTERN int
4185 lws_email_init(struct lws_email *email, uv_loop_t *loop, int max_content);
4186 
4195 LWS_VISIBLE LWS_EXTERN void
4196 lws_email_check(struct lws_email *email);
4204 LWS_VISIBLE LWS_EXTERN void
4205 lws_email_destroy(struct lws_email *email);
4206 
4207 #endif
4208 
4209 
4210 #ifdef __cplusplus
4211 }
4212 #endif
4213 
4214 #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:3918
size_t rx_buffer_size
Definition: libwebsockets.h:1294
diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 3551ea8..a4fe758 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -1217,7 +1217,7 @@ lws_set_extension_option(struct lws *wsi, const char *ext_name, * client and server for how to do. */ static LWS_INLINE LWS_WARN_DEPRECATED const struct lws_extension * -lws_get_internal_extensions() { return NULL; } +lws_get_internal_extensions(void) { return NULL; } /** * lws_ext_parse_options() - deal with parsing negotiated extension options -- 2.7.4