diff --git a/README.test-apps.md b/README.test-apps.md index 240011b8..1437b31f 100644 --- a/README.test-apps.md +++ b/README.test-apps.md @@ -1,3 +1,49 @@ +Overview of lws test apps +========================= + +Are you building a client? You just need to look at the test client +[libwebsockets-test-client](test-server/test-client.c). + +If you are building a standalone server, there are three choices, in order of +preferability. + +1) lwsws + protocol plugins + +Lws provides a generic web server app that can be configured with JSON +config files. https://libwebsockets.org itself uses this method. + +With lwsws handling the serving part, you only need to write an lws protocol +plugin. See [plugin-standalone](plugin-standalone) for an example of how +to do that outside lws itself, using lws public apis. + + $ cmake .. -DLWS_WITH_LWSWS=1 + +See [README.lwsws.md](README.lwsws.md) for information on how to configure +lwsws. + +NOTE this method implies libuv is used by lws, to provide crossplatform +implementations of timers, dynamic lib loading etc for plugins and lwsws. + +2) test-server-v2.0.c + +This method lets you configure web serving in code, instead of using lwsws. + +Plugins are still used, which implies libuv needed. + + $ cmake .. -DLWS_WITH_PLUGINS=1 + +See [test-server-v2.0.c](test-server/test-server-v2.0.c) + +3) protocols in the server app + +This is the original way lws implemented servers, plugins and libuv are not +required, but without plugins separating the protocol code directly, the +combined code is all squidged together and is much less maintainable. + +This method is still supported in lws but all ongoing and future work is +being done in protocol plugins only. + + Notes about lws test apps ========================= diff --git a/doc/html/libwebsockets_8h_source.html b/doc/html/libwebsockets_8h_source.html index 7213fd4e..d96ac8c2 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 #ifdef MBED_OPERATORS
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 <stdint.h>
120 #include <fcntl.h>
121 #else
122 #define _O_RDONLY 0x0000
123 #define O_RDONLY _O_RDONLY
124 #endif
125 
126 // Visual studio older than 2015 and WIN_CE has only _stricmp
127 #if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(_WIN32_WCE)
128 #define strcasecmp _stricmp
129 #else
130 #define strcasecmp stricmp
131 #endif
132 #define getdtablesize() 30000
133 
134 #define LWS_INLINE __inline
135 #define LWS_VISIBLE
136 #define LWS_WARN_UNUSED_RESULT
137 #define LWS_WARN_DEPRECATED
138 
139 #ifdef LWS_DLL
140 #ifdef LWS_INTERNAL
141 #define LWS_EXTERN extern __declspec(dllexport)
142 #else
143 #define LWS_EXTERN extern __declspec(dllimport)
144 #endif
145 #else
146 #define LWS_EXTERN
147 #endif
148 
149 #define LWS_INVALID_FILE INVALID_HANDLE_VALUE
150 #define LWS_O_RDONLY _O_RDONLY
151 
152 #if !defined(_MSC_VER) || _MSC_VER < 1900 /* Visual Studio 2015 already defines this in <stdio.h> */
153 #define snprintf _snprintf
154 #endif
155 
156 #ifndef __func__
157 #define __func__ __FUNCTION__
158 #endif
159 
160 #else /* NOT WIN32 */
161 #include <unistd.h>
162 
163 #if defined(__NetBSD__) || defined(__FreeBSD__)
164 #include <netinet/in.h>
165 #endif
166 
167 #define LWS_INLINE inline
168 #define LWS_O_RDONLY O_RDONLY
169 
170 #ifndef MBED_OPERATORS
171 #include <poll.h>
172 #include <netdb.h>
173 #define LWS_INVALID_FILE -1
174 #else
175 #define getdtablesize() (20)
176 #define LWS_INVALID_FILE NULL
177 #endif
178 
179 #if defined(__GNUC__)
180 
181 /* warn_unused_result attribute only supported by GCC 3.4 or later */
182 #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
183 #define LWS_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
184 #else
185 #define LWS_WARN_UNUSED_RESULT
186 #endif
187 
188 #define LWS_VISIBLE __attribute__((visibility("default")))
189 #define LWS_WARN_DEPRECATED __attribute__ ((deprecated))
190 #else
191 #define LWS_VISIBLE
192 #define LWS_WARN_UNUSED_RESULT
193 #define LWS_WARN_DEPRECATED
194 #endif
195 
196 #if defined(__ANDROID__)
197 #include <unistd.h>
198 #define getdtablesize() sysconf(_SC_OPEN_MAX)
199 #endif
200 
201 #endif
202 
203 #ifdef LWS_USE_LIBEV
204 #include <ev.h>
205 #endif /* LWS_USE_LIBEV */
206 #ifdef LWS_USE_LIBUV
207 #include <uv.h>
208 #endif /* LWS_USE_LIBUV */
209 
210 #ifndef LWS_EXTERN
211 #define LWS_EXTERN extern
212 #endif
213 
214 #ifdef _WIN32
215 #define random rand
216 #else
217 #include <sys/time.h>
218 #include <unistd.h>
219 #endif
220 
221 #ifdef LWS_OPENSSL_SUPPORT
222 
223 #ifdef USE_WOLFSSL
224 #ifdef USE_OLD_CYASSL
225 #include <cyassl/openssl/ssl.h>
226 #include <cyassl/error-ssl.h>
227 #else
228 #include <wolfssl/openssl/ssl.h>
229 #include <wolfssl/error-ssl.h>
230 #endif /* not USE_OLD_CYASSL */
231 #else
232 #if defined(LWS_USE_POLARSSL)
233 #include <polarssl/ssl.h>
235  x509_crt ca;
236  x509_crt certificate;
237  rsa_context key;
238 };
239 typedef struct lws_polarssl_context SSL_CTX;
240 typedef ssl_context SSL;
241 #else
242 #if defined(LWS_USE_MBEDTLS)
243 #include <mbedtls/ssl.h>
244 #else
245 #include <openssl/ssl.h>
246 #include <openssl/err.h>
247 #endif /* not USE_MBEDTLS */
248 #endif /* not USE_POLARSSL */
249 #endif /* not USE_WOLFSSL */
250 #endif
251 
252 
253 #define CONTEXT_PORT_NO_LISTEN -1
254 
265 
267 enum lws_log_levels {
268  LLL_ERR = 1 << 0,
269  LLL_WARN = 1 << 1,
270  LLL_NOTICE = 1 << 2,
271  LLL_INFO = 1 << 3,
272  LLL_DEBUG = 1 << 4,
273  LLL_PARSER = 1 << 5,
274  LLL_HEADER = 1 << 6,
275  LLL_EXT = 1 << 7,
276  LLL_CLIENT = 1 << 8,
277  LLL_LATENCY = 1 << 9,
278 
279  LLL_COUNT = 10 /* set to count of valid flags */
280 };
281 
282 LWS_VISIBLE LWS_EXTERN void _lws_log(int filter, const char *format, ...);
283 LWS_VISIBLE LWS_EXTERN void _lws_logv(int filter, const char *format, va_list vl);
293 LWS_VISIBLE LWS_EXTERN int
294 lwsl_timestamp(int level, char *p, int len);
295 
296 /* notice, warn and log are always compiled in */
297 #define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__)
298 #define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__)
299 #define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__)
300 /*
301  * weaker logging can be deselected at configure time using --disable-debug
302  * that gets rid of the overhead of checking while keeping _warn and _err
303  * active
304  */
305 #ifdef _DEBUG
306 
307 #define lwsl_info(...) _lws_log(LLL_INFO, __VA_ARGS__)
308 #define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__)
309 #define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__)
310 #define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__)
311 #define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__)
312 #define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__)
313 #define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__)
314 
320 LWS_VISIBLE LWS_EXTERN void lwsl_hexdump(void *buf, size_t len);
321 
322 #else /* no debug */
323 
324 #define lwsl_info(...) {}
325 #define lwsl_debug(...) {}
326 #define lwsl_parser(...) {}
327 #define lwsl_header(...) {}
328 #define lwsl_ext(...) {}
329 #define lwsl_client(...) {}
330 #define lwsl_latency(...) {}
331 #define lwsl_hexdump(a, b)
332 
333 #endif
334 
345 LWS_VISIBLE LWS_EXTERN void
346 lws_set_log_level(int level,
347  void (*log_emit_function)(int level, const char *line));
348 
358 LWS_VISIBLE LWS_EXTERN void
359 lwsl_emit_syslog(int level, const char *line);
360 
362 
363 
364 #include <stddef.h>
365 
366 #ifndef lws_container_of
367 #define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M)))
368 #endif
369 
370 
371 struct lws;
372 #ifndef ARRAY_SIZE
373 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
374 #endif
375 
376 /* api change list for user code to test against */
377 
378 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
379 
380 /* the struct lws_protocols has the id field present */
381 #define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
382 
383 /* you can call lws_get_peer_write_allowance */
384 #define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
385 
386 /* extra parameter introduced in 917f43ab821 */
387 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
388 
389 /* File operations stuff exists */
390 #define LWS_FEATURE_FOPS
391 
392 
393 #if defined(_WIN32)
394 typedef SOCKET lws_sockfd_type;
395 typedef HANDLE lws_filefd_type;
396 #define lws_sockfd_valid(sfd) (!!sfd)
397 struct lws_pollfd {
398  lws_sockfd_type fd;
399  SHORT events;
400  SHORT revents;
401 };
402 #else
403 
404 #if defined(MBED_OPERATORS)
405 /* it's a class lws_conn * */
406 typedef void * lws_sockfd_type;
407 typedef void * lws_filefd_type;
408 #define lws_sockfd_valid(sfd) (!!sfd)
409 struct pollfd {
410  lws_sockfd_type fd;
411  short events;
412  short revents;
413 };
414 #define POLLIN 0x0001
415 #define POLLPRI 0x0002
416 #define POLLOUT 0x0004
417 #define POLLERR 0x0008
418 #define POLLHUP 0x0010
419 #define POLLNVAL 0x0020
420 
421 struct lws;
422 
423 void * mbed3_create_tcp_stream_socket(void);
424 void mbed3_delete_tcp_stream_socket(void *sockfd);
425 void mbed3_tcp_stream_bind(void *sock, int port, struct lws *);
426 void mbed3_tcp_stream_accept(void *sock, struct lws *);
427 #else
428 typedef int lws_sockfd_type;
429 typedef int lws_filefd_type;
430 #define lws_sockfd_valid(sfd) (sfd >= 0)
431 #endif
432 
433 #define lws_pollfd pollfd
434 #endif
435 
438 struct lws_pollargs {
439  lws_sockfd_type fd;
440  int events;
442 };
443 
444 struct lws_tokens;
445 struct lws_token_limits;
446 
454 
456 /*
457  * NOTE: These public enums are part of the abi. If you want to add one,
458  * add it at where specified so existing users are unaffected.
459  */
462  LWS_CLOSE_STATUS_NOSTATUS = 0,
524  /****** add new things just above ---^ ******/
525 
526  LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY = 9999,
527 };
528 
541 LWS_VISIBLE LWS_EXTERN void
542 lws_close_reason(struct lws *wsi, enum lws_close_status status,
543  unsigned char *buf, size_t len);
544 
546 
547 struct lws;
548 struct lws_context;
549 /* needed even with extensions disabled for create context */
550 struct lws_extension;
551 
563 
565 
566 /*
567  * NOTE: These public enums are part of the abi. If you want to add one,
568  * add it at where specified so existing users are unaffected.
569  */
773  /* external poll() management support */
836  LWS_CALLBACK_WS_EXT_DEFAULTS = 39,
839  LWS_CALLBACK_CGI = 40,
841  LWS_CALLBACK_CGI_TERMINATED = 41,
843  LWS_CALLBACK_CGI_STDIN_DATA = 42,
845  LWS_CALLBACK_CGI_STDIN_COMPLETED = 43,
847  LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP = 44,
849  LWS_CALLBACK_CLOSED_CLIENT_HTTP = 45,
851  LWS_CALLBACK_RECEIVE_CLIENT_HTTP = 46,
853  LWS_CALLBACK_COMPLETED_CLIENT_HTTP = 47,
855  LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ = 48,
857  LWS_CALLBACK_HTTP_BIND_PROTOCOL = 49,
859  LWS_CALLBACK_HTTP_DROP_PROTOCOL = 50,
861  LWS_CALLBACK_CHECK_ACCESS_RIGHTS = 51,
863  LWS_CALLBACK_PROCESS_HTML = 52,
865  LWS_CALLBACK_ADD_HEADERS = 53,
867  LWS_CALLBACK_SESSION_INFO = 54,
870  LWS_CALLBACK_GS_EVENT = 55,
873  /****** add new things just above ---^ ******/
874 
877 };
878 
879 
880 
896 typedef int
897 lws_callback_function(struct lws *wsi, enum lws_callback_reasons reason,
898  void *user, void *in, size_t len);
900 
910 
912 /*
913  * NOTE: These public enums are part of the abi. If you want to add one,
914  * add it at where specified so existing users are unaffected.
915  */
916 enum lws_extension_callback_reasons {
917  LWS_EXT_CB_SERVER_CONTEXT_CONSTRUCT = 0,
918  LWS_EXT_CB_CLIENT_CONTEXT_CONSTRUCT = 1,
919  LWS_EXT_CB_SERVER_CONTEXT_DESTRUCT = 2,
920  LWS_EXT_CB_CLIENT_CONTEXT_DESTRUCT = 3,
921  LWS_EXT_CB_CONSTRUCT = 4,
922  LWS_EXT_CB_CLIENT_CONSTRUCT = 5,
923  LWS_EXT_CB_CHECK_OK_TO_REALLY_CLOSE = 6,
924  LWS_EXT_CB_CHECK_OK_TO_PROPOSE_EXTENSION = 7,
925  LWS_EXT_CB_DESTROY = 8,
926  LWS_EXT_CB_DESTROY_ANY_WSI_CLOSING = 9,
927  LWS_EXT_CB_ANY_WSI_ESTABLISHED = 10,
928  LWS_EXT_CB_PACKET_RX_PREPARSE = 11,
929  LWS_EXT_CB_PACKET_TX_PRESEND = 12,
930  LWS_EXT_CB_PACKET_TX_DO_SEND = 13,
931  LWS_EXT_CB_HANDSHAKE_REPLY_TX = 14,
932  LWS_EXT_CB_FLUSH_PENDING_TX = 15,
933  LWS_EXT_CB_EXTENDED_PAYLOAD_RX = 16,
934  LWS_EXT_CB_CAN_PROXY_CLIENT_CONNECTION = 17,
935  LWS_EXT_CB_1HZ = 18,
936  LWS_EXT_CB_REQUEST_ON_WRITEABLE = 19,
937  LWS_EXT_CB_IS_WRITEABLE = 20,
938  LWS_EXT_CB_PAYLOAD_TX = 21,
939  LWS_EXT_CB_PAYLOAD_RX = 22,
940  LWS_EXT_CB_OPTION_DEFAULT = 23,
941  LWS_EXT_CB_OPTION_SET = 24,
942  LWS_EXT_CB_OPTION_CONFIRM = 25,
943  LWS_EXT_CB_NAMED_OPTION_SET = 26,
944 
945  /****** add new things just above ---^ ******/
946 };
947 
954  /* Add new things just above here ---^
955  * This is part of the ABI, don't needlessly break compatibility */
956 };
957 
963  const char *name;
966  /* Add new things just above here ---^
967  * This is part of the ABI, don't needlessly break compatibility */
968 };
969 
972  const char *option_name;
974  const char *start;
975  int len;
976 };
977 
1038 typedef int
1039 lws_extension_callback_function(struct lws_context *context,
1040  const struct lws_extension *ext, struct lws *wsi,
1041  enum lws_extension_callback_reasons reason,
1042  void *user, void *in, size_t len);
1043 
1046  const char *name;
1048  const char *client_offer;
1050  /* Add new things just above here ---^
1051  * This is part of the ABI, don't needlessly break compatibility */
1052 };
1053 
1062 LWS_VISIBLE LWS_EXTERN int
1063 lws_set_extension_option(struct lws *wsi, const char *ext_name,
1064  const char *opt_name, const char *opt_val);
1065 
1066 #ifndef LWS_NO_EXTENSIONS
1067 /* lws_get_internal_extensions() - DEPRECATED
1068  *
1069  * \Deprecated There is no longer a set internal extensions table. The table is provided
1070  * by user code along with application-specific settings. See the test
1071  * client and server for how to do.
1072  */
1073 static LWS_INLINE LWS_WARN_DEPRECATED const struct lws_extension *
1074 lws_get_internal_extensions() { return NULL; }
1075 
1086 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1087 lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi,
1088  void *ext_user, const struct lws_ext_options *opts,
1089  const char *o, int len);
1090 #endif
1091 
1104 LWS_EXTERN
1106  struct lws_context *context, const struct lws_extension *ext,
1107  struct lws *wsi, enum lws_extension_callback_reasons reason,
1108  void *user, void *in, size_t len);
1109 
1110 /*
1111  * The internal exts are part of the public abi
1112  * If we add more extensions, publish the callback here ------v
1113  */
1115 
1131 
1136  const char *name;
1157  unsigned int id;
1164  void *user;
1167  /* Add new things just above here ---^
1168  * This is part of the ABI, don't needlessly break compatibility */
1169 };
1170 
1171 struct lws_vhost;
1172 
1181 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
1182 lws_vhost_name_to_protocol(struct lws_vhost *vh, const char *name);
1183 
1193 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
1194 lws_get_protocol(struct lws *wsi);
1195 
1197 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
1198 lws_protocol_get(struct lws *wsi) LWS_WARN_DEPRECATED;
1199 
1210 LWS_VISIBLE LWS_EXTERN void *
1211 lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost, const struct lws_protocols *prot,
1212  int size);
1213 
1223 LWS_VISIBLE LWS_EXTERN void *
1224 lws_protocol_vh_priv_get(struct lws_vhost *vhost, const struct lws_protocols *prot);
1225 
1234 LWS_VISIBLE LWS_EXTERN int
1235 lws_finalize_startup(struct lws_context *context);
1236 
1237 #ifdef LWS_WITH_PLUGINS
1238 
1239 /* PLUGINS implies LIBUV */
1240 
1241 #define LWS_PLUGIN_API_MAGIC 180
1242 
1245  unsigned int api_magic;
1246  const struct lws_protocols *protocols;
1248  const struct lws_extension *extensions;
1250 };
1251 
1252 typedef int (*lws_plugin_init_func)(struct lws_context *,
1253  struct lws_plugin_capability *);
1254 typedef int (*lws_plugin_destroy_func)(struct lws_context *);
1255 
1257 struct lws_plugin {
1258  struct lws_plugin *list;
1259 #if (UV_VERSION_MAJOR > 0)
1260  uv_lib_t lib;
1261 #else
1262  void *l;
1263 #endif
1264  char name[64];
1266 };
1267 
1268 #endif
1269 
1271 
1272 
1281 
1283 #define LWSGS_EMAIL_CONTENT_SIZE 16384
1284 
1286 /* SHA-1 binary and hexified versions */
1288 typedef struct { unsigned char bin[20]; } lwsgw_hash_bin;
1290 typedef struct { char id[41]; } lwsgw_hash;
1291 
1298 };
1299 
1302  char username[32];
1303  char email[100];
1304  char ip[72];
1305  unsigned int mask;
1307  char session[42];
1308 };
1309 
1314 };
1315 
1318  enum lws_gs_event event;
1319  const char *username;
1320  const char *email;
1321 };
1322 
1324 
1325 
1339 
1341 /*
1342  * NOTE: These public enums are part of the abi. If you want to add one,
1343  * add it at where specified so existing users are unaffected.
1344  */
1345 
1349  (1 << 12),
1356  (1 << 12),
1372  (1 << 12),
1377  (1 << 3) |
1378  (1 << 12),
1396  /****** add new things just above ---^ ******/
1397 };
1398 
1399 #define lws_check_opt(c, f) (((c) & (f)) == (f))
1400 
1411  int port;
1416  const char *iface;
1423  const struct lws_protocols *protocols;
1427  const struct lws_extension *extensions;
1435  const char *ssl_cert_filepath;
1445  const char *ssl_ca_filepath;
1447  const char *ssl_cipher_list;
1451  const char *http_proxy_address;
1454  unsigned int http_proxy_port;
1456  int gid;
1458  int uid;
1460  unsigned int options;
1462  void *user;
1465  int ka_time;
1475 #ifdef LWS_OPENSSL_SUPPORT
1481 #else /* maintain structure layout either way */
1483 #endif
1484 
1495  unsigned int count_threads;
1497  unsigned int fd_limit_per_thread;
1501  unsigned int timeout_secs;
1506  const char *ecdh_curve;
1508  const char *vhost_name;
1512  const char * const *plugin_dirs;
1521  const char *log_filepath;
1524  const struct lws_http_mount *mounts;
1526  const char *server_string;
1529  unsigned int pt_serv_buf_size;
1545  /* Add new things just above here ---^
1546  * This is part of the ABI, don't needlessly break compatibility
1547  *
1548  * The below is to ensure later library versions with new
1549  * members added above will see 0 (default) even if the app
1550  * was not built against the newer headers.
1551  */
1552 
1553  void *_unused[8];
1554 };
1555 
1590 LWS_VISIBLE LWS_EXTERN struct lws_context *
1592 
1601 LWS_VISIBLE LWS_EXTERN void
1602 lws_context_destroy(struct lws_context *context);
1603 
1621 LWS_VISIBLE LWS_EXTERN int
1622 lws_set_proxy(struct lws_vhost *vhost, const char *proxy);
1623 
1624 
1625 struct lws_vhost;
1626 
1636 LWS_EXTERN LWS_VISIBLE struct lws_vhost *
1637 lws_create_vhost(struct lws_context *context,
1638  struct lws_context_creation_info *info);
1639 
1654 LWS_VISIBLE LWS_EXTERN int
1655 lwsws_get_config_globals(struct lws_context_creation_info *info, const char *d,
1656  char **config_strings, int *len);
1657 
1673 LWS_VISIBLE LWS_EXTERN int
1674 lwsws_get_config_vhosts(struct lws_context *context,
1675  struct lws_context_creation_info *info, const char *d,
1676  char **config_strings, int *len);
1677 
1679 LWS_VISIBLE LWS_EXTERN struct lws_vhost *
1680 lws_vhost_get(struct lws *wsi) LWS_WARN_DEPRECATED;
1681 
1687 LWS_VISIBLE LWS_EXTERN struct lws_vhost *
1688 lws_get_vhost(struct lws *wsi);
1689 
1697 LWS_VISIBLE LWS_EXTERN int
1698 lws_json_dump_vhost(const struct lws_vhost *vh, char *buf, int len);
1699 
1707 LWS_VISIBLE LWS_EXTERN int
1708 lws_json_dump_context(const struct lws_context *context, char *buf, int len);
1709 
1719 LWS_VISIBLE LWS_EXTERN void *
1720 lws_context_user(struct lws_context *context);
1721 
1727 
1737  const char *name;
1738  const char *value;
1739 };
1740 
1753 };
1754 
1762  const char *mountpoint;
1764  const char *origin;
1766  const char *def;
1768  const char *protocol;
1784  unsigned int auth_mask;
1787  unsigned int cache_reusable:1;
1788  unsigned int cache_revalidate:1;
1789  unsigned int cache_intermediaries:1;
1791  unsigned char origin_protocol;
1792  unsigned char mountpoint_len;
1793 };
1796 
1802 
1808  struct lws_context *context;
1810  const char *address;
1812  int port;
1816  const char *path;
1818  const char *host;
1820  const char *origin;
1822  const char *protocol;
1826  void *userdata;
1830  const char *method;
1833  struct lws *parent_wsi;
1837  const char *uri_replace_from;
1840  const char *uri_replace_to;
1842  struct lws_vhost *vhost;
1845  /* Add new things just above here ---^
1846  * This is part of the ABI, don't needlessly break compatibility
1847  *
1848  * The below is to ensure later library versions with new
1849  * members added above will see 0 (default) even if the app
1850  * was not built against the newer headers.
1851  */
1852 
1853  void *_unused[4];
1854 };
1855 
1862 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
1864 
1885 /* deprecated, use lws_client_connect_via_info() */
1886 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
1887 lws_client_connect(struct lws_context *clients, const char *address,
1888  int port, int ssl_connection, const char *path,
1889  const char *host, const char *origin, const char *protocol,
1890  int ietf_version_or_minus_one) LWS_WARN_DEPRECATED;
1891 /* deprecated, use lws_client_connect_via_info() */
1912 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
1913 lws_client_connect_extended(struct lws_context *clients, const char *address,
1914  int port, int ssl_connection, const char *path,
1915  const char *host, const char *origin,
1916  const char *protocol, int ietf_version_or_minus_one,
1917  void *userdata) LWS_WARN_DEPRECATED;
1918 
1944 LWS_VISIBLE LWS_EXTERN int
1946  struct lws_vhost *vhost);
1947 
1948 LWS_VISIBLE LWS_EXTERN int
1949 lws_http_client_read(struct lws *wsi, char **buf, int *len);
1951 
1959 
1992 LWS_VISIBLE LWS_EXTERN int
1993 lws_service(struct lws_context *context, int timeout_ms);
1994 
2006 LWS_VISIBLE LWS_EXTERN int
2007 lws_service_tsi(struct lws_context *context, int timeout_ms, int tsi);
2008 
2024 LWS_VISIBLE LWS_EXTERN void
2025 lws_cancel_service_pt(struct lws *wsi);
2026 
2038 LWS_VISIBLE LWS_EXTERN void
2039 lws_cancel_service(struct lws_context *context);
2040 
2063 LWS_VISIBLE LWS_EXTERN int
2064 lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd);
2065 
2075 LWS_VISIBLE LWS_EXTERN int
2076 lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,
2077  int tsi);
2078 
2080 
2086 
2093 
2112 LWS_VISIBLE LWS_EXTERN int
2113 lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type,
2114  const char *other_headers, int other_headers_len);
2115 LWS_VISIBLE LWS_EXTERN int
2116 lws_serve_http_file_fragment(struct lws *wsi);
2118 
2129 
2130 enum http_status {
2131  HTTP_STATUS_OK = 200,
2132  HTTP_STATUS_NO_CONTENT = 204,
2133 
2134  HTTP_STATUS_MOVED_PERMANENTLY = 301,
2135  HTTP_STATUS_FOUND = 302,
2136  HTTP_STATUS_SEE_OTHER = 303,
2137 
2138  HTTP_STATUS_BAD_REQUEST = 400,
2139  HTTP_STATUS_UNAUTHORIZED,
2140  HTTP_STATUS_PAYMENT_REQUIRED,
2141  HTTP_STATUS_FORBIDDEN,
2142  HTTP_STATUS_NOT_FOUND,
2143  HTTP_STATUS_METHOD_NOT_ALLOWED,
2144  HTTP_STATUS_NOT_ACCEPTABLE,
2145  HTTP_STATUS_PROXY_AUTH_REQUIRED,
2146  HTTP_STATUS_REQUEST_TIMEOUT,
2147  HTTP_STATUS_CONFLICT,
2148  HTTP_STATUS_GONE,
2149  HTTP_STATUS_LENGTH_REQUIRED,
2150  HTTP_STATUS_PRECONDITION_FAILED,
2151  HTTP_STATUS_REQ_ENTITY_TOO_LARGE,
2152  HTTP_STATUS_REQ_URI_TOO_LONG,
2153  HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE,
2154  HTTP_STATUS_REQ_RANGE_NOT_SATISFIABLE,
2155  HTTP_STATUS_EXPECTATION_FAILED,
2156 
2157  HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,
2158  HTTP_STATUS_NOT_IMPLEMENTED,
2159  HTTP_STATUS_BAD_GATEWAY,
2160  HTTP_STATUS_SERVICE_UNAVAILABLE,
2161  HTTP_STATUS_GATEWAY_TIMEOUT,
2162  HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED,
2163 };
2164 
2166  char *p;
2167  int len;
2168  int max_len;
2169  int final;
2170 };
2171 
2172 typedef const char *(*lws_process_html_state_cb)(void *data, int index);
2173 
2175  char *start;
2176  char swallow[16];
2177  int pos;
2178  void *data;
2179  const char * const *vars;
2182  lws_process_html_state_cb replace;
2183 };
2184 
2189 LWS_VISIBLE LWS_EXTERN int
2191  struct lws_process_html_state *s);
2193 
2226 
2234 struct lws_tokens {
2235  char *token;
2237 };
2238 
2239 /* enum lws_token_indexes
2240  * these have to be kept in sync with lextable.h / minilex.c
2241  *
2242  * NOTE: These public enums are part of the abi. If you want to add one,
2243  * add it at where specified so existing users are unaffected.
2244  */
2245 enum lws_token_indexes {
2246  WSI_TOKEN_GET_URI = 0,
2247  WSI_TOKEN_POST_URI = 1,
2248  WSI_TOKEN_OPTIONS_URI = 2,
2249  WSI_TOKEN_HOST = 3,
2250  WSI_TOKEN_CONNECTION = 4,
2251  WSI_TOKEN_UPGRADE = 5,
2252  WSI_TOKEN_ORIGIN = 6,
2253  WSI_TOKEN_DRAFT = 7,
2254  WSI_TOKEN_CHALLENGE = 8,
2255  WSI_TOKEN_EXTENSIONS = 9,
2256  WSI_TOKEN_KEY1 = 10,
2257  WSI_TOKEN_KEY2 = 11,
2258  WSI_TOKEN_PROTOCOL = 12,
2259  WSI_TOKEN_ACCEPT = 13,
2260  WSI_TOKEN_NONCE = 14,
2261  WSI_TOKEN_HTTP = 15,
2262  WSI_TOKEN_HTTP2_SETTINGS = 16,
2263  WSI_TOKEN_HTTP_ACCEPT = 17,
2264  WSI_TOKEN_HTTP_AC_REQUEST_HEADERS = 18,
2265  WSI_TOKEN_HTTP_IF_MODIFIED_SINCE = 19,
2266  WSI_TOKEN_HTTP_IF_NONE_MATCH = 20,
2267  WSI_TOKEN_HTTP_ACCEPT_ENCODING = 21,
2268  WSI_TOKEN_HTTP_ACCEPT_LANGUAGE = 22,
2269  WSI_TOKEN_HTTP_PRAGMA = 23,
2270  WSI_TOKEN_HTTP_CACHE_CONTROL = 24,
2271  WSI_TOKEN_HTTP_AUTHORIZATION = 25,
2272  WSI_TOKEN_HTTP_COOKIE = 26,
2273  WSI_TOKEN_HTTP_CONTENT_LENGTH = 27,
2274  WSI_TOKEN_HTTP_CONTENT_TYPE = 28,
2275  WSI_TOKEN_HTTP_DATE = 29,
2276  WSI_TOKEN_HTTP_RANGE = 30,
2277  WSI_TOKEN_HTTP_REFERER = 31,
2278  WSI_TOKEN_KEY = 32,
2279  WSI_TOKEN_VERSION = 33,
2280  WSI_TOKEN_SWORIGIN = 34,
2281 
2282  WSI_TOKEN_HTTP_COLON_AUTHORITY = 35,
2283  WSI_TOKEN_HTTP_COLON_METHOD = 36,
2284  WSI_TOKEN_HTTP_COLON_PATH = 37,
2285  WSI_TOKEN_HTTP_COLON_SCHEME = 38,
2286  WSI_TOKEN_HTTP_COLON_STATUS = 39,
2287 
2288  WSI_TOKEN_HTTP_ACCEPT_CHARSET = 40,
2289  WSI_TOKEN_HTTP_ACCEPT_RANGES = 41,
2290  WSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN = 42,
2291  WSI_TOKEN_HTTP_AGE = 43,
2292  WSI_TOKEN_HTTP_ALLOW = 44,
2293  WSI_TOKEN_HTTP_CONTENT_DISPOSITION = 45,
2294  WSI_TOKEN_HTTP_CONTENT_ENCODING = 46,
2295  WSI_TOKEN_HTTP_CONTENT_LANGUAGE = 47,
2296  WSI_TOKEN_HTTP_CONTENT_LOCATION = 48,
2297  WSI_TOKEN_HTTP_CONTENT_RANGE = 49,
2298  WSI_TOKEN_HTTP_ETAG = 50,
2299  WSI_TOKEN_HTTP_EXPECT = 51,
2300  WSI_TOKEN_HTTP_EXPIRES = 52,
2301  WSI_TOKEN_HTTP_FROM = 53,
2302  WSI_TOKEN_HTTP_IF_MATCH = 54,
2303  WSI_TOKEN_HTTP_IF_RANGE = 55,
2304  WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE = 56,
2305  WSI_TOKEN_HTTP_LAST_MODIFIED = 57,
2306  WSI_TOKEN_HTTP_LINK = 58,
2307  WSI_TOKEN_HTTP_LOCATION = 59,
2308  WSI_TOKEN_HTTP_MAX_FORWARDS = 60,
2309  WSI_TOKEN_HTTP_PROXY_AUTHENTICATE = 61,
2310  WSI_TOKEN_HTTP_PROXY_AUTHORIZATION = 62,
2311  WSI_TOKEN_HTTP_REFRESH = 63,
2312  WSI_TOKEN_HTTP_RETRY_AFTER = 64,
2313  WSI_TOKEN_HTTP_SERVER = 65,
2314  WSI_TOKEN_HTTP_SET_COOKIE = 66,
2315  WSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY = 67,
2316  WSI_TOKEN_HTTP_TRANSFER_ENCODING = 68,
2317  WSI_TOKEN_HTTP_USER_AGENT = 69,
2318  WSI_TOKEN_HTTP_VARY = 70,
2319  WSI_TOKEN_HTTP_VIA = 71,
2320  WSI_TOKEN_HTTP_WWW_AUTHENTICATE = 72,
2321 
2322  WSI_TOKEN_PATCH_URI = 73,
2323  WSI_TOKEN_PUT_URI = 74,
2324  WSI_TOKEN_DELETE_URI = 75,
2325 
2326  WSI_TOKEN_HTTP_URI_ARGS = 76,
2327  WSI_TOKEN_PROXY = 77,
2328  WSI_TOKEN_HTTP_X_REAL_IP = 78,
2329  WSI_TOKEN_HTTP1_0 = 79,
2330 
2331  /****** add new things just above ---^ ******/
2332 
2333  /* use token storage to stash these internally, not for
2334  * user use */
2335 
2336  _WSI_TOKEN_CLIENT_SENT_PROTOCOLS,
2337  _WSI_TOKEN_CLIENT_PEER_ADDRESS,
2338  _WSI_TOKEN_CLIENT_URI,
2339  _WSI_TOKEN_CLIENT_HOST,
2340  _WSI_TOKEN_CLIENT_ORIGIN,
2341  _WSI_TOKEN_CLIENT_METHOD,
2342 
2343  /* always last real token index*/
2344  WSI_TOKEN_COUNT,
2345 
2346  /* parser state additions, no storage associated */
2347  WSI_TOKEN_NAME_PART,
2348  WSI_TOKEN_SKIPPING,
2349  WSI_TOKEN_SKIPPING_SAW_CR,
2350  WSI_PARSING_COMPLETE,
2351  WSI_INIT_TOKEN_MUXURL,
2352 };
2353 
2355  unsigned short token_limit[WSI_TOKEN_COUNT];
2356 };
2357 
2363 LWS_VISIBLE LWS_EXTERN const unsigned char *
2364 lws_token_to_string(enum lws_token_indexes token);
2365 
2366 
2375 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2376 lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h);
2377 
2387 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2388 lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx);
2389 
2403 LWS_VISIBLE LWS_EXTERN int
2404 lws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h);
2405 
2423 LWS_VISIBLE LWS_EXTERN int
2424 lws_hdr_copy_fragment(struct lws *wsi, char *dest, int len,
2425  enum lws_token_indexes h, int frag_idx);
2426 
2437 LWS_VISIBLE LWS_EXTERN const char *
2438 lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, int len);
2440 
2455 
2466 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2467 lws_add_http_header_status(struct lws *wsi,
2468  unsigned int code, unsigned char **p,
2469  unsigned char *end);
2482 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2483 lws_add_http_header_by_name(struct lws *wsi, const unsigned char *name,
2484  const unsigned char *value, int length,
2485  unsigned char **p, unsigned char *end);
2499 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2500 lws_add_http_header_by_token(struct lws *wsi, enum lws_token_indexes token,
2501  const unsigned char *value, int length,
2502  unsigned char **p, unsigned char *end);
2513 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2514 lws_add_http_header_content_length(struct lws *wsi,
2515  unsigned long content_length,
2516  unsigned char **p, unsigned char *end);
2526 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2527 lws_finalize_http_header(struct lws *wsi, unsigned char **p,
2528  unsigned char *end);
2530 
2549 
2559 };
2560 
2574 typedef int (*lws_spa_fileupload_cb)(void *data, const char *name,
2575  const char *filename, char *buf, int len,
2576  enum lws_spa_fileupload_states state);
2577 
2580 struct lws_spa;
2581 
2600 LWS_VISIBLE LWS_EXTERN struct lws_spa *
2601 lws_spa_create(struct lws *wsi, const char * const *param_names,
2602  int count_params, int max_storage, lws_spa_fileupload_cb opt_cb,
2603  void *opt_data);
2604 
2612 LWS_VISIBLE LWS_EXTERN int
2613 lws_spa_process(struct lws_spa *spa, const char *in, int len);
2614 
2620 LWS_VISIBLE LWS_EXTERN int
2621 lws_spa_finalize(struct lws_spa *spa);
2622 
2629 LWS_VISIBLE LWS_EXTERN int
2630 lws_spa_get_length(struct lws_spa *spa, int n);
2631 
2637 LWS_VISIBLE LWS_EXTERN const char *
2638 lws_spa_get_string(struct lws_spa *spa, int n);
2639 
2645 LWS_VISIBLE LWS_EXTERN int
2646 lws_spa_destroy(struct lws_spa *spa);
2648 
2659 
2670 LWS_VISIBLE LWS_EXTERN const char *
2671 lws_urlencode(char *escaped, const char *string, int len);
2672 
2673 /*
2674  * URLDECODE 1 / 2
2675  *
2676  * This simple urldecode only operates until the first '\0' and requires the
2677  * data to exist all at once
2678  */
2691 LWS_VISIBLE LWS_EXTERN int
2692 lws_urldecode(char *string, const char *escaped, int len);
2694 
2703 LWS_VISIBLE LWS_EXTERN int
2704 lws_return_http_status(struct lws *wsi, unsigned int code,
2705  const char *html_body);
2706 
2717 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2718 lws_http_redirect(struct lws *wsi, int code, const unsigned char *loc, int len,
2719  unsigned char **p, unsigned char *end);
2720 
2729 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2730 lws_http_transaction_completed(struct lws *wsi);
2732 
2740 
2751 LWS_VISIBLE LWS_EXTERN const char *
2752 lws_sql_purify(char *escaped, const char *string, int len);
2753 
2764 LWS_VISIBLE LWS_EXTERN const char *
2765 lws_json_purify(char *escaped, const char *string, int len);
2767 
2774 
2776 #ifdef LWS_USE_LIBEV
2777 typedef void (lws_ev_signal_cb_t)(EV_P_ struct ev_signal *w, int revents);
2778 
2779 LWS_VISIBLE LWS_EXTERN int
2780 lws_ev_sigint_cfg(struct lws_context *context, int use_ev_sigint,
2781  lws_ev_signal_cb_t *cb);
2782 
2783 LWS_VISIBLE LWS_EXTERN int
2784 lws_ev_initloop(struct lws_context *context, struct ev_loop *loop, int tsi);
2785 
2786 LWS_VISIBLE LWS_EXTERN void
2787 lws_ev_sigint_cb(struct ev_loop *loop, struct ev_signal *watcher, int revents);
2788 #endif /* LWS_USE_LIBEV */
2789 
2791 
2798 #ifdef LWS_USE_LIBUV
2800 LWS_VISIBLE LWS_EXTERN int
2801 lws_uv_sigint_cfg(struct lws_context *context, int use_uv_sigint,
2802  uv_signal_cb cb);
2803 
2804 LWS_VISIBLE LWS_EXTERN void
2805 lws_libuv_run(const struct lws_context *context, int tsi);
2806 
2807 LWS_VISIBLE LWS_EXTERN void
2808 lws_libuv_stop(struct lws_context *context);
2809 
2810 LWS_VISIBLE LWS_EXTERN int
2811 lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi);
2812 
2813 LWS_VISIBLE LWS_EXTERN uv_loop_t *
2814 lws_uv_getloop(struct lws_context *context, int tsi);
2815 
2816 LWS_VISIBLE LWS_EXTERN void
2817 lws_uv_sigint_cb(uv_signal_t *watcher, int signum);
2818 #endif /* LWS_USE_LIBUV */
2819 
2826 
2827 /*
2828  * NOTE: These public enums are part of the abi. If you want to add one,
2829  * add it at where specified so existing users are unaffected.
2830  */
2831 enum pending_timeout {
2832  NO_PENDING_TIMEOUT = 0,
2833  PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE = 1,
2834  PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE = 2,
2835  PENDING_TIMEOUT_ESTABLISH_WITH_SERVER = 3,
2836  PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE = 4,
2837  PENDING_TIMEOUT_AWAITING_PING = 5,
2838  PENDING_TIMEOUT_CLOSE_ACK = 6,
2839  PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE = 7,
2840  PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE = 8,
2841  PENDING_TIMEOUT_SSL_ACCEPT = 9,
2842  PENDING_TIMEOUT_HTTP_CONTENT = 10,
2843  PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND = 11,
2844  PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE = 12,
2845  PENDING_TIMEOUT_SHUTDOWN_FLUSH = 13,
2846  PENDING_TIMEOUT_CGI = 14,
2847  PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE = 15,
2848 
2849  /****** add new things just above ---^ ******/
2850 };
2851 
2861 LWS_VISIBLE LWS_EXTERN void
2862 lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs);
2864 
2870 #if !defined(LWS_SIZEOFPTR)
2871 #define LWS_SIZEOFPTR (sizeof (void *))
2872 #endif
2873 #if !defined(u_int64_t)
2874 #define u_int64_t unsigned long long
2875 #endif
2876 
2877 #if __x86_64__
2878 #define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */
2879 #else
2880 #define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target arch */
2881 #endif
2882 #define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
2883  ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
2884 #define LWS_PRE _LWS_PAD(4 + 10)
2885 /* used prior to 1.7 and retained for backward compatibility */
2886 #define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
2887 #define LWS_SEND_BUFFER_POST_PADDING 0
2888 
2889 /*
2890  * NOTE: These public enums are part of the abi. If you want to add one,
2891  * add it at where specified so existing users are unaffected.
2892  */
2907  /* LWS_WRITE_CLOSE is handled by lws_close_reason() */
2908  LWS_WRITE_PING = 5,
2909  LWS_WRITE_PONG = 6,
2910 
2911  /* Same as write_http but we know this write ends the transaction */
2912  LWS_WRITE_HTTP_FINAL = 7,
2913 
2914  /* HTTP2 */
2915 
2923  /****** add new things just above ---^ ******/
2924 
2925  /* flags */
2926 
2934 };
2935 
2936 
3008 LWS_VISIBLE LWS_EXTERN int
3009 lws_write(struct lws *wsi, unsigned char *buf, size_t len,
3010  enum lws_write_protocol protocol);
3011 
3012 /* helper for case where buffer may be const */
3013 #define lws_write_http(wsi, buf, len) \
3014  lws_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP)
3015 
3017 
3036 
3049 LWS_VISIBLE LWS_EXTERN int
3050 lws_callback_on_writable(struct lws *wsi);
3051 
3065 LWS_VISIBLE LWS_EXTERN int
3066 lws_callback_on_writable_all_protocol(const struct lws_context *context,
3067  const struct lws_protocols *protocol);
3068 
3082 LWS_VISIBLE LWS_EXTERN int
3083 lws_callback_on_writable_all_protocol_vhost(const struct lws_vhost *vhost,
3084  const struct lws_protocols *protocol);
3085 
3098 LWS_VISIBLE LWS_EXTERN int
3099 lws_callback_all_protocol(struct lws_context *context,
3100  const struct lws_protocols *protocol, int reason);
3101 
3114 LWS_VISIBLE LWS_EXTERN int
3115 lws_callback_all_protocol_vhost(struct lws_vhost *vh,
3116  const struct lws_protocols *protocol, int reason);
3117 
3131 LWS_VISIBLE LWS_EXTERN int
3132 lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len);
3133 
3141 LWS_VISIBLE LWS_EXTERN int
3142 lws_get_socket_fd(struct lws *wsi);
3143 
3165 LWS_VISIBLE LWS_EXTERN size_t
3166 lws_get_peer_write_allowance(struct lws *wsi);
3168 
3179 LWS_VISIBLE LWS_EXTERN int
3180 lws_rx_flow_control(struct lws *wsi, int enable);
3181 
3191 LWS_VISIBLE LWS_EXTERN void
3192 lws_rx_flow_allow_all_protocol(const struct lws_context *context,
3193  const struct lws_protocols *protocol);
3194 
3211 LWS_VISIBLE LWS_EXTERN size_t
3212 lws_remaining_packet_payload(struct lws *wsi);
3213 
3214 
3223 
3236 LWS_VISIBLE LWS_EXTERN struct lws *
3237 lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd);
3260 LWS_VISIBLE LWS_EXTERN struct lws *
3261 lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd,
3262  const char *readbuf, size_t len);
3264 
3270 
3281 LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
3282 lws_canonical_hostname(struct lws_context *context);
3283 
3298 LWS_VISIBLE LWS_EXTERN void
3299 lws_get_peer_addresses(struct lws *wsi, lws_sockfd_type fd, char *name,
3300  int name_len, char *rip, int rip_len);
3301 
3312 LWS_VISIBLE LWS_EXTERN const char *
3313 lws_get_peer_simple(struct lws *wsi, char *name, int namelen);
3314 
3326 LWS_VISIBLE LWS_EXTERN int
3327 lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr,
3328  size_t addrlen);
3330 
3336 
3349 LWS_VISIBLE LWS_EXTERN int
3350 lws_get_random(struct lws_context *context, void *buf, int len);
3358 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3359 lws_daemonize(const char *_lock_path);
3365 LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
3367 
3374 LWS_VISIBLE LWS_EXTERN void *
3375 lws_wsi_user(struct lws *wsi);
3376 
3388 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3389 lws_parse_uri(char *p, const char **prot, const char **ads, int *port,
3390  const char **path);
3391 
3395 LWS_VISIBLE LWS_EXTERN unsigned long
3396 lws_now_secs(void);
3397 
3407 LWS_VISIBLE LWS_EXTERN struct lws_context * LWS_WARN_UNUSED_RESULT
3408 lws_get_context(const struct lws *wsi);
3409 
3419 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3420 lws_get_count_threads(struct lws_context *context);
3421 
3429 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
3430 lws_get_parent(const struct lws *wsi);
3431 
3438 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
3439 lws_get_child(const struct lws *wsi);
3440 
3441 
3442 /*
3443  * \deprecated DEPRECATED Note: this is not normally needed as a user api.
3444  * It's provided in case it is
3445  * useful when integrating with other app poll loop service code.
3446  */
3447 LWS_VISIBLE LWS_EXTERN int
3448 lws_read(struct lws *wsi, unsigned char *buf, size_t len);
3449 
3457 LWS_VISIBLE LWS_EXTERN void
3458 lws_set_allocator(void *(*realloc)(void *ptr, size_t size));
3460 
3466 
3473 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3474 lws_send_pipe_choked(struct lws *wsi);
3475 
3480 LWS_VISIBLE LWS_EXTERN int
3481 lws_is_final_fragment(struct lws *wsi);
3482 
3487 LWS_VISIBLE LWS_EXTERN unsigned char
3488 lws_get_reserved_bits(struct lws *wsi);
3489 
3506 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3507 lws_partial_buffered(struct lws *wsi);
3508 
3518 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3519 lws_frame_is_binary(struct lws *wsi);
3520 
3529 LWS_VISIBLE LWS_EXTERN int
3530 lws_is_ssl(struct lws *wsi);
3535 LWS_VISIBLE LWS_EXTERN int
3536 lws_is_cgi(struct lws *wsi);
3538 
3539 
3545 #ifdef LWS_SHA1_USE_OPENSSL_NAME
3547 #define lws_SHA1 SHA1
3548 #else
3549 
3558 LWS_VISIBLE LWS_EXTERN unsigned char *
3559 lws_SHA1(const unsigned char *d, size_t n, unsigned char *md);
3560 #endif
3561 
3571 LWS_VISIBLE LWS_EXTERN int
3572 lws_b64_encode_string(const char *in, int in_len, char *out, int out_size);
3582 LWS_VISIBLE LWS_EXTERN int
3583 lws_b64_decode_string(const char *in, char *out, int out_size);
3585 
3586 
3596 #ifdef LWS_WITH_CGI
3597 enum lws_enum_stdinouterr {
3598  LWS_STDIN = 0,
3599  LWS_STDOUT = 1,
3600  LWS_STDERR = 2,
3601 };
3602 
3603 enum lws_cgi_hdr_state {
3604  LCHS_HEADER,
3605  LCHS_CR1,
3606  LCHS_LF1,
3607  LCHS_CR2,
3608  LCHS_LF2,
3609  LHCS_PAYLOAD,
3610  LCHS_SINGLE_0A,
3611 };
3612 
3614  struct lws **stdwsi;
3615  enum lws_enum_stdinouterr ch;
3616  unsigned char *data;
3617  enum lws_cgi_hdr_state hdr_state;
3618  int len;
3619 };
3620 
3621 
3631 LWS_VISIBLE LWS_EXTERN int
3632 lws_cgi(struct lws *wsi, const char * const *exec_array,
3633  int script_uri_path_len, int timeout_secs,
3634  const struct lws_protocol_vhost_options *mp_cgienv);
3635 
3641 LWS_VISIBLE LWS_EXTERN int
3642 lws_cgi_write_split_stdout_headers(struct lws *wsi);
3643 
3649 LWS_VISIBLE LWS_EXTERN int
3650 lws_cgi_kill(struct lws *wsi);
3651 #endif
3652 
3654 
3671 
3678  lws_filefd_type (*open)(struct lws *wsi, const char *filename,
3679  unsigned long *filelen, int flags);
3683  int (*close)(struct lws *wsi, lws_filefd_type fd);
3685  unsigned long (*seek_cur)(struct lws *wsi, lws_filefd_type fd,
3686  long offset_from_cur_pos);
3688  int (*read)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
3689  unsigned char *buf, unsigned long len);
3691  int (*write)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
3692  unsigned char *buf, unsigned long len);
3695  /* Add new things just above here ---^
3696  * This is part of the ABI, don't needlessly break compatibility */
3697 };
3698 
3704 LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops * LWS_WARN_UNUSED_RESULT
3705 lws_get_fops(struct lws_context *context);
3706 
3715 static LWS_INLINE lws_filefd_type LWS_WARN_UNUSED_RESULT
3716 lws_plat_file_open(struct lws *wsi, const char *filename,
3717  unsigned long *filelen, int flags)
3718 {
3719  return lws_get_fops(lws_get_context(wsi))->open(wsi, filename,
3720  filelen, flags);
3721 }
3722 
3729 static LWS_INLINE int
3730 lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
3731 {
3732  return lws_get_fops(lws_get_context(wsi))->close(wsi, fd);
3733 }
3734 
3742 static LWS_INLINE unsigned long
3743 lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
3744 {
3745  return lws_get_fops(lws_get_context(wsi))->seek_cur(wsi, fd, offset);
3746 }
3756 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
3757 lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
3758  unsigned char *buf, unsigned long len)
3759 {
3760  return lws_get_fops(lws_get_context(wsi))->read(wsi, fd, amount, buf,
3761  len);
3762 }
3772 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
3773 lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
3774  unsigned char *buf, unsigned long len)
3775 {
3776  return lws_get_fops(lws_get_context(wsi))->write(wsi, fd, amount, buf,
3777  len);
3778 }
3780 
3812 #ifdef LWS_WITH_SMTP
3813 
3825 };
3826 
3828 struct lws_email {
3829  void *data;
3831  uv_loop_t *loop;
3834  char email_smtp_ip[32];
3835  char email_helo[32];
3836  char email_from[100];
3837  char email_to[100];
3839  unsigned int max_content_size;
3842  /* Fill all the callbacks before init */
3843 
3844  int (*on_next)(struct lws_email *email);
3849  int (*on_sent)(struct lws_email *email);
3854  int (*on_get_body)(struct lws_email *email, char *buf, int len);
3860  /* private things */
3861  uv_timer_t timeout_email;
3863  uv_connect_t email_connect_req;
3864  uv_tcp_t email_client;
3866  char email_buf[256];
3867  char *content;
3868 };
3869 
3879 LWS_VISIBLE LWS_EXTERN int
3880 lws_email_init(struct lws_email *email, uv_loop_t *loop, int max_content);
3881 
3890 LWS_VISIBLE LWS_EXTERN void
3891 lws_email_check(struct lws_email *email);
3899 LWS_VISIBLE LWS_EXTERN void
3900 lws_email_destroy(struct lws_email *email);
3901 
3902 #endif
3903 
3904 
3905 #ifdef __cplusplus
3906 }
3907 #endif
3908 
3909 #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 #ifdef MBED_OPERATORS
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 <stdint.h>
120 #include <fcntl.h>
121 #else
122 #define _O_RDONLY 0x0000
123 #define O_RDONLY _O_RDONLY
124 #endif
125 
126 // Visual studio older than 2015 and WIN_CE has only _stricmp
127 #if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(_WIN32_WCE)
128 #define strcasecmp _stricmp
129 #else
130 #define strcasecmp stricmp
131 #endif
132 #define getdtablesize() 30000
133 
134 #define LWS_INLINE __inline
135 #define LWS_VISIBLE
136 #define LWS_WARN_UNUSED_RESULT
137 #define LWS_WARN_DEPRECATED
138 
139 #ifdef LWS_DLL
140 #ifdef LWS_INTERNAL
141 #define LWS_EXTERN extern __declspec(dllexport)
142 #else
143 #define LWS_EXTERN extern __declspec(dllimport)
144 #endif
145 #else
146 #define LWS_EXTERN
147 #endif
148 
149 #define LWS_INVALID_FILE INVALID_HANDLE_VALUE
150 #define LWS_O_RDONLY _O_RDONLY
151 
152 #if !defined(_MSC_VER) || _MSC_VER < 1900 /* Visual Studio 2015 already defines this in <stdio.h> */
153 #define snprintf _snprintf
154 #endif
155 
156 #ifndef __func__
157 #define __func__ __FUNCTION__
158 #endif
159 
160 #else /* NOT WIN32 */
161 #include <unistd.h>
162 
163 #if defined(__NetBSD__) || defined(__FreeBSD__)
164 #include <netinet/in.h>
165 #endif
166 
167 #define LWS_INLINE inline
168 #define LWS_O_RDONLY O_RDONLY
169 
170 #ifndef MBED_OPERATORS
171 #include <poll.h>
172 #include <netdb.h>
173 #define LWS_INVALID_FILE -1
174 #else
175 #define getdtablesize() (20)
176 #define LWS_INVALID_FILE NULL
177 #endif
178 
179 #if defined(__GNUC__)
180 
181 /* warn_unused_result attribute only supported by GCC 3.4 or later */
182 #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
183 #define LWS_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
184 #else
185 #define LWS_WARN_UNUSED_RESULT
186 #endif
187 
188 #define LWS_VISIBLE __attribute__((visibility("default")))
189 #define LWS_WARN_DEPRECATED __attribute__ ((deprecated))
190 #else
191 #define LWS_VISIBLE
192 #define LWS_WARN_UNUSED_RESULT
193 #define LWS_WARN_DEPRECATED
194 #endif
195 
196 #if defined(__ANDROID__)
197 #include <unistd.h>
198 #define getdtablesize() sysconf(_SC_OPEN_MAX)
199 #endif
200 
201 #endif
202 
203 #ifdef LWS_USE_LIBEV
204 #include <ev.h>
205 #endif /* LWS_USE_LIBEV */
206 #ifdef LWS_USE_LIBUV
207 #include <uv.h>
208 #endif /* LWS_USE_LIBUV */
209 
210 #ifndef LWS_EXTERN
211 #define LWS_EXTERN extern
212 #endif
213 
214 #ifdef _WIN32
215 #define random rand
216 #else
217 #include <sys/time.h>
218 #include <unistd.h>
219 #endif
220 
221 #ifdef LWS_OPENSSL_SUPPORT
222 
223 #ifdef USE_WOLFSSL
224 #ifdef USE_OLD_CYASSL
225 #include <cyassl/openssl/ssl.h>
226 #include <cyassl/error-ssl.h>
227 #else
228 #include <wolfssl/openssl/ssl.h>
229 #include <wolfssl/error-ssl.h>
230 #endif /* not USE_OLD_CYASSL */
231 #else
232 #if defined(LWS_USE_POLARSSL)
233 #include <polarssl/ssl.h>
235  x509_crt ca;
236  x509_crt certificate;
237  rsa_context key;
238 };
239 typedef struct lws_polarssl_context SSL_CTX;
240 typedef ssl_context SSL;
241 #else
242 #if defined(LWS_USE_MBEDTLS)
243 #include <mbedtls/ssl.h>
244 #else
245 #include <openssl/ssl.h>
246 #include <openssl/err.h>
247 #endif /* not USE_MBEDTLS */
248 #endif /* not USE_POLARSSL */
249 #endif /* not USE_WOLFSSL */
250 #endif
251 
252 
253 #define CONTEXT_PORT_NO_LISTEN -1
254 
265 
267 enum lws_log_levels {
268  LLL_ERR = 1 << 0,
269  LLL_WARN = 1 << 1,
270  LLL_NOTICE = 1 << 2,
271  LLL_INFO = 1 << 3,
272  LLL_DEBUG = 1 << 4,
273  LLL_PARSER = 1 << 5,
274  LLL_HEADER = 1 << 6,
275  LLL_EXT = 1 << 7,
276  LLL_CLIENT = 1 << 8,
277  LLL_LATENCY = 1 << 9,
278 
279  LLL_COUNT = 10 /* set to count of valid flags */
280 };
281 
282 LWS_VISIBLE LWS_EXTERN void _lws_log(int filter, const char *format, ...);
283 LWS_VISIBLE LWS_EXTERN void _lws_logv(int filter, const char *format, va_list vl);
293 LWS_VISIBLE LWS_EXTERN int
294 lwsl_timestamp(int level, char *p, int len);
295 
296 /* notice, warn and log are always compiled in */
297 #define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__)
298 #define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__)
299 #define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__)
300 /*
301  * weaker logging can be deselected at configure time using --disable-debug
302  * that gets rid of the overhead of checking while keeping _warn and _err
303  * active
304  */
305 #ifdef _DEBUG
306 
307 #define lwsl_info(...) _lws_log(LLL_INFO, __VA_ARGS__)
308 #define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__)
309 #define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__)
310 #define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__)
311 #define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__)
312 #define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__)
313 #define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__)
314 
320 LWS_VISIBLE LWS_EXTERN void lwsl_hexdump(void *buf, size_t len);
321 
322 #else /* no debug */
323 
324 #define lwsl_info(...) {}
325 #define lwsl_debug(...) {}
326 #define lwsl_parser(...) {}
327 #define lwsl_header(...) {}
328 #define lwsl_ext(...) {}
329 #define lwsl_client(...) {}
330 #define lwsl_latency(...) {}
331 #define lwsl_hexdump(a, b)
332 
333 #endif
334 
345 LWS_VISIBLE LWS_EXTERN void
346 lws_set_log_level(int level,
347  void (*log_emit_function)(int level, const char *line));
348 
358 LWS_VISIBLE LWS_EXTERN void
359 lwsl_emit_syslog(int level, const char *line);
360 
362 
363 
364 #include <stddef.h>
365 
366 #ifndef lws_container_of
367 #define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M)))
368 #endif
369 
370 
371 struct lws;
372 #ifndef ARRAY_SIZE
373 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
374 #endif
375 
376 /* api change list for user code to test against */
377 
378 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
379 
380 /* the struct lws_protocols has the id field present */
381 #define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
382 
383 /* you can call lws_get_peer_write_allowance */
384 #define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
385 
386 /* extra parameter introduced in 917f43ab821 */
387 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
388 
389 /* File operations stuff exists */
390 #define LWS_FEATURE_FOPS
391 
392 
393 #if defined(_WIN32)
394 typedef SOCKET lws_sockfd_type;
395 typedef HANDLE lws_filefd_type;
396 #define lws_sockfd_valid(sfd) (!!sfd)
397 struct lws_pollfd {
398  lws_sockfd_type fd;
399  SHORT events;
400  SHORT revents;
401 };
402 #else
403 
404 #if defined(MBED_OPERATORS)
405 /* it's a class lws_conn * */
406 typedef void * lws_sockfd_type;
407 typedef void * lws_filefd_type;
408 #define lws_sockfd_valid(sfd) (!!sfd)
409 struct pollfd {
410  lws_sockfd_type fd;
411  short events;
412  short revents;
413 };
414 #define POLLIN 0x0001
415 #define POLLPRI 0x0002
416 #define POLLOUT 0x0004
417 #define POLLERR 0x0008
418 #define POLLHUP 0x0010
419 #define POLLNVAL 0x0020
420 
421 struct lws;
422 
423 void * mbed3_create_tcp_stream_socket(void);
424 void mbed3_delete_tcp_stream_socket(void *sockfd);
425 void mbed3_tcp_stream_bind(void *sock, int port, struct lws *);
426 void mbed3_tcp_stream_accept(void *sock, struct lws *);
427 #else
428 typedef int lws_sockfd_type;
429 typedef int lws_filefd_type;
430 #define lws_sockfd_valid(sfd) (sfd >= 0)
431 #endif
432 
433 #define lws_pollfd pollfd
434 #endif
435 
438 struct lws_pollargs {
439  lws_sockfd_type fd;
440  int events;
442 };
443 
444 struct lws_tokens;
445 struct lws_token_limits;
446 
454 
456 /*
457  * NOTE: These public enums are part of the abi. If you want to add one,
458  * add it at where specified so existing users are unaffected.
459  */
462  LWS_CLOSE_STATUS_NOSTATUS = 0,
524  /****** add new things just above ---^ ******/
525 
526  LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY = 9999,
527 };
528 
541 LWS_VISIBLE LWS_EXTERN void
542 lws_close_reason(struct lws *wsi, enum lws_close_status status,
543  unsigned char *buf, size_t len);
544 
546 
547 struct lws;
548 struct lws_context;
549 /* needed even with extensions disabled for create context */
550 struct lws_extension;
551 
563 
565 
566 /*
567  * NOTE: These public enums are part of the abi. If you want to add one,
568  * add it at where specified so existing users are unaffected.
569  */
773  /* external poll() management support */
836  LWS_CALLBACK_WS_EXT_DEFAULTS = 39,
839  LWS_CALLBACK_CGI = 40,
841  LWS_CALLBACK_CGI_TERMINATED = 41,
843  LWS_CALLBACK_CGI_STDIN_DATA = 42,
845  LWS_CALLBACK_CGI_STDIN_COMPLETED = 43,
847  LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP = 44,
849  LWS_CALLBACK_CLOSED_CLIENT_HTTP = 45,
851  LWS_CALLBACK_RECEIVE_CLIENT_HTTP = 46,
853  LWS_CALLBACK_COMPLETED_CLIENT_HTTP = 47,
855  LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ = 48,
857  LWS_CALLBACK_HTTP_BIND_PROTOCOL = 49,
859  LWS_CALLBACK_HTTP_DROP_PROTOCOL = 50,
861  LWS_CALLBACK_CHECK_ACCESS_RIGHTS = 51,
863  LWS_CALLBACK_PROCESS_HTML = 52,
865  LWS_CALLBACK_ADD_HEADERS = 53,
867  LWS_CALLBACK_SESSION_INFO = 54,
870  LWS_CALLBACK_GS_EVENT = 55,
873  /****** add new things just above ---^ ******/
874 
877 };
878 
879 
880 
896 typedef int
897 lws_callback_function(struct lws *wsi, enum lws_callback_reasons reason,
898  void *user, void *in, size_t len);
900 
910 
912 /*
913  * NOTE: These public enums are part of the abi. If you want to add one,
914  * add it at where specified so existing users are unaffected.
915  */
916 enum lws_extension_callback_reasons {
917  LWS_EXT_CB_SERVER_CONTEXT_CONSTRUCT = 0,
918  LWS_EXT_CB_CLIENT_CONTEXT_CONSTRUCT = 1,
919  LWS_EXT_CB_SERVER_CONTEXT_DESTRUCT = 2,
920  LWS_EXT_CB_CLIENT_CONTEXT_DESTRUCT = 3,
921  LWS_EXT_CB_CONSTRUCT = 4,
922  LWS_EXT_CB_CLIENT_CONSTRUCT = 5,
923  LWS_EXT_CB_CHECK_OK_TO_REALLY_CLOSE = 6,
924  LWS_EXT_CB_CHECK_OK_TO_PROPOSE_EXTENSION = 7,
925  LWS_EXT_CB_DESTROY = 8,
926  LWS_EXT_CB_DESTROY_ANY_WSI_CLOSING = 9,
927  LWS_EXT_CB_ANY_WSI_ESTABLISHED = 10,
928  LWS_EXT_CB_PACKET_RX_PREPARSE = 11,
929  LWS_EXT_CB_PACKET_TX_PRESEND = 12,
930  LWS_EXT_CB_PACKET_TX_DO_SEND = 13,
931  LWS_EXT_CB_HANDSHAKE_REPLY_TX = 14,
932  LWS_EXT_CB_FLUSH_PENDING_TX = 15,
933  LWS_EXT_CB_EXTENDED_PAYLOAD_RX = 16,
934  LWS_EXT_CB_CAN_PROXY_CLIENT_CONNECTION = 17,
935  LWS_EXT_CB_1HZ = 18,
936  LWS_EXT_CB_REQUEST_ON_WRITEABLE = 19,
937  LWS_EXT_CB_IS_WRITEABLE = 20,
938  LWS_EXT_CB_PAYLOAD_TX = 21,
939  LWS_EXT_CB_PAYLOAD_RX = 22,
940  LWS_EXT_CB_OPTION_DEFAULT = 23,
941  LWS_EXT_CB_OPTION_SET = 24,
942  LWS_EXT_CB_OPTION_CONFIRM = 25,
943  LWS_EXT_CB_NAMED_OPTION_SET = 26,
944 
945  /****** add new things just above ---^ ******/
946 };
947 
954  /* Add new things just above here ---^
955  * This is part of the ABI, don't needlessly break compatibility */
956 };
957 
963  const char *name;
966  /* Add new things just above here ---^
967  * This is part of the ABI, don't needlessly break compatibility */
968 };
969 
972  const char *option_name;
974  const char *start;
975  int len;
976 };
977 
1038 typedef int
1039 lws_extension_callback_function(struct lws_context *context,
1040  const struct lws_extension *ext, struct lws *wsi,
1041  enum lws_extension_callback_reasons reason,
1042  void *user, void *in, size_t len);
1043 
1046  const char *name;
1048  const char *client_offer;
1050  /* Add new things just above here ---^
1051  * This is part of the ABI, don't needlessly break compatibility */
1052 };
1053 
1062 LWS_VISIBLE LWS_EXTERN int
1063 lws_set_extension_option(struct lws *wsi, const char *ext_name,
1064  const char *opt_name, const char *opt_val);
1065 
1066 #ifndef LWS_NO_EXTENSIONS
1067 /* lws_get_internal_extensions() - DEPRECATED
1068  *
1069  * \Deprecated There is no longer a set internal extensions table. The table is provided
1070  * by user code along with application-specific settings. See the test
1071  * client and server for how to do.
1072  */
1073 static LWS_INLINE LWS_WARN_DEPRECATED const struct lws_extension *
1074 lws_get_internal_extensions() { return NULL; }
1075 
1086 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1087 lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi,
1088  void *ext_user, const struct lws_ext_options *opts,
1089  const char *o, int len);
1090 #endif
1091 
1104 LWS_EXTERN
1106  struct lws_context *context, const struct lws_extension *ext,
1107  struct lws *wsi, enum lws_extension_callback_reasons reason,
1108  void *user, void *in, size_t len);
1109 
1110 /*
1111  * The internal exts are part of the public abi
1112  * If we add more extensions, publish the callback here ------v
1113  */
1115 
1131 
1136  const char *name;
1157  unsigned int id;
1164  void *user;
1167  /* Add new things just above here ---^
1168  * This is part of the ABI, don't needlessly break compatibility */
1169 };
1170 
1171 struct lws_vhost;
1172 
1181 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
1182 lws_vhost_name_to_protocol(struct lws_vhost *vh, const char *name);
1183 
1193 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
1194 lws_get_protocol(struct lws *wsi);
1195 
1197 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
1198 lws_protocol_get(struct lws *wsi) LWS_WARN_DEPRECATED;
1199 
1210 LWS_VISIBLE LWS_EXTERN void *
1211 lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost, const struct lws_protocols *prot,
1212  int size);
1213 
1223 LWS_VISIBLE LWS_EXTERN void *
1224 lws_protocol_vh_priv_get(struct lws_vhost *vhost, const struct lws_protocols *prot);
1225 
1234 LWS_VISIBLE LWS_EXTERN int
1235 lws_finalize_startup(struct lws_context *context);
1236 
1237 #ifdef LWS_WITH_PLUGINS
1238 
1239 /* PLUGINS implies LIBUV */
1240 
1241 #define LWS_PLUGIN_API_MAGIC 180
1242 
1245  unsigned int api_magic;
1246  const struct lws_protocols *protocols;
1248  const struct lws_extension *extensions;
1250 };
1251 
1252 typedef int (*lws_plugin_init_func)(struct lws_context *,
1253  struct lws_plugin_capability *);
1254 typedef int (*lws_plugin_destroy_func)(struct lws_context *);
1255 
1257 struct lws_plugin {
1258  struct lws_plugin *list;
1259 #if (UV_VERSION_MAJOR > 0)
1260  uv_lib_t lib;
1261 #else
1262  void *l;
1263 #endif
1264  char name[64];
1266 };
1267 
1268 #endif
1269 
1271 
1272 
1281 
1283 #define LWSGS_EMAIL_CONTENT_SIZE 16384
1284 
1286 /* SHA-1 binary and hexified versions */
1288 typedef struct { unsigned char bin[20]; } lwsgw_hash_bin;
1290 typedef struct { char id[41]; } lwsgw_hash;
1291 
1298 };
1299 
1302  char username[32];
1303  char email[100];
1304  char ip[72];
1305  unsigned int mask;
1307  char session[42];
1308 };
1309 
1314 };
1315 
1318  enum lws_gs_event event;
1319  const char *username;
1320  const char *email;
1321 };
1322 
1324 
1325 
1339 
1341 /*
1342  * NOTE: These public enums are part of the abi. If you want to add one,
1343  * add it at where specified so existing users are unaffected.
1344  */
1345 
1349  (1 << 12),
1356  (1 << 12),
1372  (1 << 12),
1377  (1 << 3) |
1378  (1 << 12),
1396  /****** add new things just above ---^ ******/
1397 };
1398 
1399 #define lws_check_opt(c, f) (((c) & (f)) == (f))
1400 
1411  int port;
1416  const char *iface;
1423  const struct lws_protocols *protocols;
1427  const struct lws_extension *extensions;
1435  const char *ssl_cert_filepath;
1445  const char *ssl_ca_filepath;
1447  const char *ssl_cipher_list;
1451  const char *http_proxy_address;
1454  unsigned int http_proxy_port;
1456  int gid;
1458  int uid;
1460  unsigned int options;
1462  void *user;
1465  int ka_time;
1475 #ifdef LWS_OPENSSL_SUPPORT
1481 #else /* maintain structure layout either way */
1483 #endif
1484 
1495  unsigned int count_threads;
1497  unsigned int fd_limit_per_thread;
1501  unsigned int timeout_secs;
1506  const char *ecdh_curve;
1508  const char *vhost_name;
1512  const char * const *plugin_dirs;
1521  const char *log_filepath;
1524  const struct lws_http_mount *mounts;
1526  const char *server_string;
1529  unsigned int pt_serv_buf_size;
1545  /* Add new things just above here ---^
1546  * This is part of the ABI, don't needlessly break compatibility
1547  *
1548  * The below is to ensure later library versions with new
1549  * members added above will see 0 (default) even if the app
1550  * was not built against the newer headers.
1551  */
1552 
1553  void *_unused[8];
1554 };
1555 
1590 LWS_VISIBLE LWS_EXTERN struct lws_context *
1592 
1601 LWS_VISIBLE LWS_EXTERN void
1602 lws_context_destroy(struct lws_context *context);
1603 
1621 LWS_VISIBLE LWS_EXTERN int
1622 lws_set_proxy(struct lws_vhost *vhost, const char *proxy);
1623 
1624 
1625 struct lws_vhost;
1626 
1636 LWS_EXTERN LWS_VISIBLE struct lws_vhost *
1637 lws_create_vhost(struct lws_context *context,
1638  struct lws_context_creation_info *info);
1639 
1654 LWS_VISIBLE LWS_EXTERN int
1655 lwsws_get_config_globals(struct lws_context_creation_info *info, const char *d,
1656  char **config_strings, int *len);
1657 
1673 LWS_VISIBLE LWS_EXTERN int
1674 lwsws_get_config_vhosts(struct lws_context *context,
1675  struct lws_context_creation_info *info, const char *d,
1676  char **config_strings, int *len);
1677 
1679 LWS_VISIBLE LWS_EXTERN struct lws_vhost *
1680 lws_vhost_get(struct lws *wsi) LWS_WARN_DEPRECATED;
1681 
1687 LWS_VISIBLE LWS_EXTERN struct lws_vhost *
1688 lws_get_vhost(struct lws *wsi);
1689 
1697 LWS_VISIBLE LWS_EXTERN int
1698 lws_json_dump_vhost(const struct lws_vhost *vh, char *buf, int len);
1699 
1707 LWS_VISIBLE LWS_EXTERN int
1708 lws_json_dump_context(const struct lws_context *context, char *buf, int len);
1709 
1719 LWS_VISIBLE LWS_EXTERN void *
1720 lws_context_user(struct lws_context *context);
1721 
1727 
1737  const char *name;
1738  const char *value;
1739 };
1740 
1753 };
1754 
1762  const char *mountpoint;
1764  const char *origin;
1766  const char *def;
1768  const char *protocol;
1784  unsigned int auth_mask;
1787  unsigned int cache_reusable:1;
1788  unsigned int cache_revalidate:1;
1789  unsigned int cache_intermediaries:1;
1791  unsigned char origin_protocol;
1792  unsigned char mountpoint_len;
1793 };
1796 
1802 
1808  struct lws_context *context;
1810  const char *address;
1812  int port;
1816  const char *path;
1818  const char *host;
1820  const char *origin;
1822  const char *protocol;
1826  void *userdata;
1830  const char *method;
1833  struct lws *parent_wsi;
1837  const char *uri_replace_from;
1840  const char *uri_replace_to;
1842  struct lws_vhost *vhost;
1845  /* Add new things just above here ---^
1846  * This is part of the ABI, don't needlessly break compatibility
1847  *
1848  * The below is to ensure later library versions with new
1849  * members added above will see 0 (default) even if the app
1850  * was not built against the newer headers.
1851  */
1852 
1853  void *_unused[4];
1854 };
1855 
1862 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
1864 
1885 /* deprecated, use lws_client_connect_via_info() */
1886 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
1887 lws_client_connect(struct lws_context *clients, const char *address,
1888  int port, int ssl_connection, const char *path,
1889  const char *host, const char *origin, const char *protocol,
1890  int ietf_version_or_minus_one) LWS_WARN_DEPRECATED;
1891 /* deprecated, use lws_client_connect_via_info() */
1912 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
1913 lws_client_connect_extended(struct lws_context *clients, const char *address,
1914  int port, int ssl_connection, const char *path,
1915  const char *host, const char *origin,
1916  const char *protocol, int ietf_version_or_minus_one,
1917  void *userdata) LWS_WARN_DEPRECATED;
1918 
1944 LWS_VISIBLE LWS_EXTERN int
1946  struct lws_vhost *vhost);
1947 
1948 LWS_VISIBLE LWS_EXTERN int
1949 lws_http_client_read(struct lws *wsi, char **buf, int *len);
1951 
1959 
1992 LWS_VISIBLE LWS_EXTERN int
1993 lws_service(struct lws_context *context, int timeout_ms);
1994 
2006 LWS_VISIBLE LWS_EXTERN int
2007 lws_service_tsi(struct lws_context *context, int timeout_ms, int tsi);
2008 
2024 LWS_VISIBLE LWS_EXTERN void
2025 lws_cancel_service_pt(struct lws *wsi);
2026 
2038 LWS_VISIBLE LWS_EXTERN void
2039 lws_cancel_service(struct lws_context *context);
2040 
2063 LWS_VISIBLE LWS_EXTERN int
2064 lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd);
2065 
2075 LWS_VISIBLE LWS_EXTERN int
2076 lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,
2077  int tsi);
2078 
2080 
2086 
2093 
2112 LWS_VISIBLE LWS_EXTERN int
2113 lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type,
2114  const char *other_headers, int other_headers_len);
2115 LWS_VISIBLE LWS_EXTERN int
2116 lws_serve_http_file_fragment(struct lws *wsi);
2118 
2129 
2130 enum http_status {
2131  HTTP_STATUS_OK = 200,
2132  HTTP_STATUS_NO_CONTENT = 204,
2133 
2134  HTTP_STATUS_MOVED_PERMANENTLY = 301,
2135  HTTP_STATUS_FOUND = 302,
2136  HTTP_STATUS_SEE_OTHER = 303,
2137 
2138  HTTP_STATUS_BAD_REQUEST = 400,
2139  HTTP_STATUS_UNAUTHORIZED,
2140  HTTP_STATUS_PAYMENT_REQUIRED,
2141  HTTP_STATUS_FORBIDDEN,
2142  HTTP_STATUS_NOT_FOUND,
2143  HTTP_STATUS_METHOD_NOT_ALLOWED,
2144  HTTP_STATUS_NOT_ACCEPTABLE,
2145  HTTP_STATUS_PROXY_AUTH_REQUIRED,
2146  HTTP_STATUS_REQUEST_TIMEOUT,
2147  HTTP_STATUS_CONFLICT,
2148  HTTP_STATUS_GONE,
2149  HTTP_STATUS_LENGTH_REQUIRED,
2150  HTTP_STATUS_PRECONDITION_FAILED,
2151  HTTP_STATUS_REQ_ENTITY_TOO_LARGE,
2152  HTTP_STATUS_REQ_URI_TOO_LONG,
2153  HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE,
2154  HTTP_STATUS_REQ_RANGE_NOT_SATISFIABLE,
2155  HTTP_STATUS_EXPECTATION_FAILED,
2156 
2157  HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,
2158  HTTP_STATUS_NOT_IMPLEMENTED,
2159  HTTP_STATUS_BAD_GATEWAY,
2160  HTTP_STATUS_SERVICE_UNAVAILABLE,
2161  HTTP_STATUS_GATEWAY_TIMEOUT,
2162  HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED,
2163 };
2164 
2166  char *p;
2167  int len;
2168  int max_len;
2169  int final;
2170 };
2171 
2172 typedef const char *(*lws_process_html_state_cb)(void *data, int index);
2173 
2175  char *start;
2176  char swallow[16];
2177  int pos;
2178  void *data;
2179  const char * const *vars;
2182  lws_process_html_state_cb replace;
2183 };
2184 
2189 LWS_VISIBLE LWS_EXTERN int
2191  struct lws_process_html_state *s);
2193 
2226 
2234 struct lws_tokens {
2235  char *token;
2237 };
2238 
2239 /* enum lws_token_indexes
2240  * these have to be kept in sync with lextable.h / minilex.c
2241  *
2242  * NOTE: These public enums are part of the abi. If you want to add one,
2243  * add it at where specified so existing users are unaffected.
2244  */
2245 enum lws_token_indexes {
2246  WSI_TOKEN_GET_URI = 0,
2247  WSI_TOKEN_POST_URI = 1,
2248  WSI_TOKEN_OPTIONS_URI = 2,
2249  WSI_TOKEN_HOST = 3,
2250  WSI_TOKEN_CONNECTION = 4,
2251  WSI_TOKEN_UPGRADE = 5,
2252  WSI_TOKEN_ORIGIN = 6,
2253  WSI_TOKEN_DRAFT = 7,
2254  WSI_TOKEN_CHALLENGE = 8,
2255  WSI_TOKEN_EXTENSIONS = 9,
2256  WSI_TOKEN_KEY1 = 10,
2257  WSI_TOKEN_KEY2 = 11,
2258  WSI_TOKEN_PROTOCOL = 12,
2259  WSI_TOKEN_ACCEPT = 13,
2260  WSI_TOKEN_NONCE = 14,
2261  WSI_TOKEN_HTTP = 15,
2262  WSI_TOKEN_HTTP2_SETTINGS = 16,
2263  WSI_TOKEN_HTTP_ACCEPT = 17,
2264  WSI_TOKEN_HTTP_AC_REQUEST_HEADERS = 18,
2265  WSI_TOKEN_HTTP_IF_MODIFIED_SINCE = 19,
2266  WSI_TOKEN_HTTP_IF_NONE_MATCH = 20,
2267  WSI_TOKEN_HTTP_ACCEPT_ENCODING = 21,
2268  WSI_TOKEN_HTTP_ACCEPT_LANGUAGE = 22,
2269  WSI_TOKEN_HTTP_PRAGMA = 23,
2270  WSI_TOKEN_HTTP_CACHE_CONTROL = 24,
2271  WSI_TOKEN_HTTP_AUTHORIZATION = 25,
2272  WSI_TOKEN_HTTP_COOKIE = 26,
2273  WSI_TOKEN_HTTP_CONTENT_LENGTH = 27,
2274  WSI_TOKEN_HTTP_CONTENT_TYPE = 28,
2275  WSI_TOKEN_HTTP_DATE = 29,
2276  WSI_TOKEN_HTTP_RANGE = 30,
2277  WSI_TOKEN_HTTP_REFERER = 31,
2278  WSI_TOKEN_KEY = 32,
2279  WSI_TOKEN_VERSION = 33,
2280  WSI_TOKEN_SWORIGIN = 34,
2281 
2282  WSI_TOKEN_HTTP_COLON_AUTHORITY = 35,
2283  WSI_TOKEN_HTTP_COLON_METHOD = 36,
2284  WSI_TOKEN_HTTP_COLON_PATH = 37,
2285  WSI_TOKEN_HTTP_COLON_SCHEME = 38,
2286  WSI_TOKEN_HTTP_COLON_STATUS = 39,
2287 
2288  WSI_TOKEN_HTTP_ACCEPT_CHARSET = 40,
2289  WSI_TOKEN_HTTP_ACCEPT_RANGES = 41,
2290  WSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN = 42,
2291  WSI_TOKEN_HTTP_AGE = 43,
2292  WSI_TOKEN_HTTP_ALLOW = 44,
2293  WSI_TOKEN_HTTP_CONTENT_DISPOSITION = 45,
2294  WSI_TOKEN_HTTP_CONTENT_ENCODING = 46,
2295  WSI_TOKEN_HTTP_CONTENT_LANGUAGE = 47,
2296  WSI_TOKEN_HTTP_CONTENT_LOCATION = 48,
2297  WSI_TOKEN_HTTP_CONTENT_RANGE = 49,
2298  WSI_TOKEN_HTTP_ETAG = 50,
2299  WSI_TOKEN_HTTP_EXPECT = 51,
2300  WSI_TOKEN_HTTP_EXPIRES = 52,
2301  WSI_TOKEN_HTTP_FROM = 53,
2302  WSI_TOKEN_HTTP_IF_MATCH = 54,
2303  WSI_TOKEN_HTTP_IF_RANGE = 55,
2304  WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE = 56,
2305  WSI_TOKEN_HTTP_LAST_MODIFIED = 57,
2306  WSI_TOKEN_HTTP_LINK = 58,
2307  WSI_TOKEN_HTTP_LOCATION = 59,
2308  WSI_TOKEN_HTTP_MAX_FORWARDS = 60,
2309  WSI_TOKEN_HTTP_PROXY_AUTHENTICATE = 61,
2310  WSI_TOKEN_HTTP_PROXY_AUTHORIZATION = 62,
2311  WSI_TOKEN_HTTP_REFRESH = 63,
2312  WSI_TOKEN_HTTP_RETRY_AFTER = 64,
2313  WSI_TOKEN_HTTP_SERVER = 65,
2314  WSI_TOKEN_HTTP_SET_COOKIE = 66,
2315  WSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY = 67,
2316  WSI_TOKEN_HTTP_TRANSFER_ENCODING = 68,
2317  WSI_TOKEN_HTTP_USER_AGENT = 69,
2318  WSI_TOKEN_HTTP_VARY = 70,
2319  WSI_TOKEN_HTTP_VIA = 71,
2320  WSI_TOKEN_HTTP_WWW_AUTHENTICATE = 72,
2321 
2322  WSI_TOKEN_PATCH_URI = 73,
2323  WSI_TOKEN_PUT_URI = 74,
2324  WSI_TOKEN_DELETE_URI = 75,
2325 
2326  WSI_TOKEN_HTTP_URI_ARGS = 76,
2327  WSI_TOKEN_PROXY = 77,
2328  WSI_TOKEN_HTTP_X_REAL_IP = 78,
2329  WSI_TOKEN_HTTP1_0 = 79,
2330 
2331  /****** add new things just above ---^ ******/
2332 
2333  /* use token storage to stash these internally, not for
2334  * user use */
2335 
2336  _WSI_TOKEN_CLIENT_SENT_PROTOCOLS,
2337  _WSI_TOKEN_CLIENT_PEER_ADDRESS,
2338  _WSI_TOKEN_CLIENT_URI,
2339  _WSI_TOKEN_CLIENT_HOST,
2340  _WSI_TOKEN_CLIENT_ORIGIN,
2341  _WSI_TOKEN_CLIENT_METHOD,
2342 
2343  /* always last real token index*/
2344  WSI_TOKEN_COUNT,
2345 
2346  /* parser state additions, no storage associated */
2347  WSI_TOKEN_NAME_PART,
2348  WSI_TOKEN_SKIPPING,
2349  WSI_TOKEN_SKIPPING_SAW_CR,
2350  WSI_PARSING_COMPLETE,
2351  WSI_INIT_TOKEN_MUXURL,
2352 };
2353 
2355  unsigned short token_limit[WSI_TOKEN_COUNT];
2356 };
2357 
2363 LWS_VISIBLE LWS_EXTERN const unsigned char *
2364 lws_token_to_string(enum lws_token_indexes token);
2365 
2366 
2375 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2376 lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h);
2377 
2387 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2388 lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx);
2389 
2403 LWS_VISIBLE LWS_EXTERN int
2404 lws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h);
2405 
2423 LWS_VISIBLE LWS_EXTERN int
2424 lws_hdr_copy_fragment(struct lws *wsi, char *dest, int len,
2425  enum lws_token_indexes h, int frag_idx);
2426 
2437 LWS_VISIBLE LWS_EXTERN const char *
2438 lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, int len);
2440 
2455 
2466 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2467 lws_add_http_header_status(struct lws *wsi,
2468  unsigned int code, unsigned char **p,
2469  unsigned char *end);
2482 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2483 lws_add_http_header_by_name(struct lws *wsi, const unsigned char *name,
2484  const unsigned char *value, int length,
2485  unsigned char **p, unsigned char *end);
2499 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2500 lws_add_http_header_by_token(struct lws *wsi, enum lws_token_indexes token,
2501  const unsigned char *value, int length,
2502  unsigned char **p, unsigned char *end);
2513 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2514 lws_add_http_header_content_length(struct lws *wsi,
2515  unsigned long content_length,
2516  unsigned char **p, unsigned char *end);
2526 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2527 lws_finalize_http_header(struct lws *wsi, unsigned char **p,
2528  unsigned char *end);
2530 
2549 
2559 };
2560 
2574 typedef int (*lws_spa_fileupload_cb)(void *data, const char *name,
2575  const char *filename, char *buf, int len,
2576  enum lws_spa_fileupload_states state);
2577 
2580 struct lws_spa;
2581 
2600 LWS_VISIBLE LWS_EXTERN struct lws_spa *
2601 lws_spa_create(struct lws *wsi, const char * const *param_names,
2602  int count_params, int max_storage, lws_spa_fileupload_cb opt_cb,
2603  void *opt_data);
2604 
2612 LWS_VISIBLE LWS_EXTERN int
2613 lws_spa_process(struct lws_spa *spa, const char *in, int len);
2614 
2620 LWS_VISIBLE LWS_EXTERN int
2621 lws_spa_finalize(struct lws_spa *spa);
2622 
2629 LWS_VISIBLE LWS_EXTERN int
2630 lws_spa_get_length(struct lws_spa *spa, int n);
2631 
2637 LWS_VISIBLE LWS_EXTERN const char *
2638 lws_spa_get_string(struct lws_spa *spa, int n);
2639 
2645 LWS_VISIBLE LWS_EXTERN int
2646 lws_spa_destroy(struct lws_spa *spa);
2648 
2659 
2670 LWS_VISIBLE LWS_EXTERN const char *
2671 lws_urlencode(char *escaped, const char *string, int len);
2672 
2673 /*
2674  * URLDECODE 1 / 2
2675  *
2676  * This simple urldecode only operates until the first '\0' and requires the
2677  * data to exist all at once
2678  */
2691 LWS_VISIBLE LWS_EXTERN int
2692 lws_urldecode(char *string, const char *escaped, int len);
2694 
2703 LWS_VISIBLE LWS_EXTERN int
2704 lws_return_http_status(struct lws *wsi, unsigned int code,
2705  const char *html_body);
2706 
2717 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2718 lws_http_redirect(struct lws *wsi, int code, const unsigned char *loc, int len,
2719  unsigned char **p, unsigned char *end);
2720 
2729 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
2730 lws_http_transaction_completed(struct lws *wsi);
2732 
2740 
2751 LWS_VISIBLE LWS_EXTERN const char *
2752 lws_sql_purify(char *escaped, const char *string, int len);
2753 
2764 LWS_VISIBLE LWS_EXTERN const char *
2765 lws_json_purify(char *escaped, const char *string, int len);
2767 
2774 
2776 #ifdef LWS_USE_LIBEV
2777 typedef void (lws_ev_signal_cb_t)(EV_P_ struct ev_signal *w, int revents);
2778 
2779 LWS_VISIBLE LWS_EXTERN int
2780 lws_ev_sigint_cfg(struct lws_context *context, int use_ev_sigint,
2781  lws_ev_signal_cb_t *cb);
2782 
2783 LWS_VISIBLE LWS_EXTERN int
2784 lws_ev_initloop(struct lws_context *context, struct ev_loop *loop, int tsi);
2785 
2786 LWS_VISIBLE LWS_EXTERN void
2787 lws_ev_sigint_cb(struct ev_loop *loop, struct ev_signal *watcher, int revents);
2788 #endif /* LWS_USE_LIBEV */
2789 
2791 
2798 #ifdef LWS_USE_LIBUV
2800 LWS_VISIBLE LWS_EXTERN int
2801 lws_uv_sigint_cfg(struct lws_context *context, int use_uv_sigint,
2802  uv_signal_cb cb);
2803 
2804 LWS_VISIBLE LWS_EXTERN void
2805 lws_libuv_run(const struct lws_context *context, int tsi);
2806 
2807 LWS_VISIBLE LWS_EXTERN void
2808 lws_libuv_stop(struct lws_context *context);
2809 
2810 LWS_VISIBLE LWS_EXTERN int
2811 lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi);
2812 
2813 LWS_VISIBLE LWS_EXTERN uv_loop_t *
2814 lws_uv_getloop(struct lws_context *context, int tsi);
2815 
2816 LWS_VISIBLE LWS_EXTERN void
2817 lws_uv_sigint_cb(uv_signal_t *watcher, int signum);
2818 #endif /* LWS_USE_LIBUV */
2819 
2826 
2827 /*
2828  * NOTE: These public enums are part of the abi. If you want to add one,
2829  * add it at where specified so existing users are unaffected.
2830  */
2831 enum pending_timeout {
2832  NO_PENDING_TIMEOUT = 0,
2833  PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE = 1,
2834  PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE = 2,
2835  PENDING_TIMEOUT_ESTABLISH_WITH_SERVER = 3,
2836  PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE = 4,
2837  PENDING_TIMEOUT_AWAITING_PING = 5,
2838  PENDING_TIMEOUT_CLOSE_ACK = 6,
2839  PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE = 7,
2840  PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE = 8,
2841  PENDING_TIMEOUT_SSL_ACCEPT = 9,
2842  PENDING_TIMEOUT_HTTP_CONTENT = 10,
2843  PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND = 11,
2844  PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE = 12,
2845  PENDING_TIMEOUT_SHUTDOWN_FLUSH = 13,
2846  PENDING_TIMEOUT_CGI = 14,
2847  PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE = 15,
2848 
2849  /****** add new things just above ---^ ******/
2850 };
2851 
2861 LWS_VISIBLE LWS_EXTERN void
2862 lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs);
2864 
2870 #if !defined(LWS_SIZEOFPTR)
2871 #define LWS_SIZEOFPTR (sizeof (void *))
2872 #endif
2873 #if !defined(u_int64_t)
2874 #define u_int64_t unsigned long long
2875 #endif
2876 
2877 #if defined(__x86_64__)
2878 #define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */
2879 #else
2880 #define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target arch */
2881 #endif
2882 #define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
2883  ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
2884 #define LWS_PRE _LWS_PAD(4 + 10)
2885 /* used prior to 1.7 and retained for backward compatibility */
2886 #define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
2887 #define LWS_SEND_BUFFER_POST_PADDING 0
2888 
2889 /*
2890  * NOTE: These public enums are part of the abi. If you want to add one,
2891  * add it at where specified so existing users are unaffected.
2892  */
2907  /* LWS_WRITE_CLOSE is handled by lws_close_reason() */
2908  LWS_WRITE_PING = 5,
2909  LWS_WRITE_PONG = 6,
2910 
2911  /* Same as write_http but we know this write ends the transaction */
2912  LWS_WRITE_HTTP_FINAL = 7,
2913 
2914  /* HTTP2 */
2915 
2923  /****** add new things just above ---^ ******/
2924 
2925  /* flags */
2926 
2934 };
2935 
2936 
3008 LWS_VISIBLE LWS_EXTERN int
3009 lws_write(struct lws *wsi, unsigned char *buf, size_t len,
3010  enum lws_write_protocol protocol);
3011 
3012 /* helper for case where buffer may be const */
3013 #define lws_write_http(wsi, buf, len) \
3014  lws_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP)
3015 
3017 
3036 
3049 LWS_VISIBLE LWS_EXTERN int
3050 lws_callback_on_writable(struct lws *wsi);
3051 
3065 LWS_VISIBLE LWS_EXTERN int
3066 lws_callback_on_writable_all_protocol(const struct lws_context *context,
3067  const struct lws_protocols *protocol);
3068 
3082 LWS_VISIBLE LWS_EXTERN int
3083 lws_callback_on_writable_all_protocol_vhost(const struct lws_vhost *vhost,
3084  const struct lws_protocols *protocol);
3085 
3098 LWS_VISIBLE LWS_EXTERN int
3099 lws_callback_all_protocol(struct lws_context *context,
3100  const struct lws_protocols *protocol, int reason);
3101 
3114 LWS_VISIBLE LWS_EXTERN int
3115 lws_callback_all_protocol_vhost(struct lws_vhost *vh,
3116  const struct lws_protocols *protocol, int reason);
3117 
3131 LWS_VISIBLE LWS_EXTERN int
3132 lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len);
3133 
3141 LWS_VISIBLE LWS_EXTERN int
3142 lws_get_socket_fd(struct lws *wsi);
3143 
3165 LWS_VISIBLE LWS_EXTERN size_t
3166 lws_get_peer_write_allowance(struct lws *wsi);
3168 
3179 LWS_VISIBLE LWS_EXTERN int
3180 lws_rx_flow_control(struct lws *wsi, int enable);
3181 
3191 LWS_VISIBLE LWS_EXTERN void
3192 lws_rx_flow_allow_all_protocol(const struct lws_context *context,
3193  const struct lws_protocols *protocol);
3194 
3211 LWS_VISIBLE LWS_EXTERN size_t
3212 lws_remaining_packet_payload(struct lws *wsi);
3213 
3214 
3223 
3236 LWS_VISIBLE LWS_EXTERN struct lws *
3237 lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd);
3260 LWS_VISIBLE LWS_EXTERN struct lws *
3261 lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd,
3262  const char *readbuf, size_t len);
3264 
3270 
3281 LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
3282 lws_canonical_hostname(struct lws_context *context);
3283 
3298 LWS_VISIBLE LWS_EXTERN void
3299 lws_get_peer_addresses(struct lws *wsi, lws_sockfd_type fd, char *name,
3300  int name_len, char *rip, int rip_len);
3301 
3312 LWS_VISIBLE LWS_EXTERN const char *
3313 lws_get_peer_simple(struct lws *wsi, char *name, int namelen);
3314 
3326 LWS_VISIBLE LWS_EXTERN int
3327 lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr,
3328  size_t addrlen);
3330 
3336 
3349 LWS_VISIBLE LWS_EXTERN int
3350 lws_get_random(struct lws_context *context, void *buf, int len);
3358 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3359 lws_daemonize(const char *_lock_path);
3365 LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
3367 
3374 LWS_VISIBLE LWS_EXTERN void *
3375 lws_wsi_user(struct lws *wsi);
3376 
3388 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3389 lws_parse_uri(char *p, const char **prot, const char **ads, int *port,
3390  const char **path);
3391 
3395 LWS_VISIBLE LWS_EXTERN unsigned long
3396 lws_now_secs(void);
3397 
3407 LWS_VISIBLE LWS_EXTERN struct lws_context * LWS_WARN_UNUSED_RESULT
3408 lws_get_context(const struct lws *wsi);
3409 
3419 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3420 lws_get_count_threads(struct lws_context *context);
3421 
3429 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
3430 lws_get_parent(const struct lws *wsi);
3431 
3438 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
3439 lws_get_child(const struct lws *wsi);
3440 
3441 
3442 /*
3443  * \deprecated DEPRECATED Note: this is not normally needed as a user api.
3444  * It's provided in case it is
3445  * useful when integrating with other app poll loop service code.
3446  */
3447 LWS_VISIBLE LWS_EXTERN int
3448 lws_read(struct lws *wsi, unsigned char *buf, size_t len);
3449 
3457 LWS_VISIBLE LWS_EXTERN void
3458 lws_set_allocator(void *(*realloc)(void *ptr, size_t size));
3460 
3466 
3473 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3474 lws_send_pipe_choked(struct lws *wsi);
3475 
3480 LWS_VISIBLE LWS_EXTERN int
3481 lws_is_final_fragment(struct lws *wsi);
3482 
3487 LWS_VISIBLE LWS_EXTERN unsigned char
3488 lws_get_reserved_bits(struct lws *wsi);
3489 
3506 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3507 lws_partial_buffered(struct lws *wsi);
3508 
3518 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
3519 lws_frame_is_binary(struct lws *wsi);
3520 
3529 LWS_VISIBLE LWS_EXTERN int
3530 lws_is_ssl(struct lws *wsi);
3535 LWS_VISIBLE LWS_EXTERN int
3536 lws_is_cgi(struct lws *wsi);
3538 
3539 
3545 #ifdef LWS_SHA1_USE_OPENSSL_NAME
3547 #define lws_SHA1 SHA1
3548 #else
3549 
3558 LWS_VISIBLE LWS_EXTERN unsigned char *
3559 lws_SHA1(const unsigned char *d, size_t n, unsigned char *md);
3560 #endif
3561 
3571 LWS_VISIBLE LWS_EXTERN int
3572 lws_b64_encode_string(const char *in, int in_len, char *out, int out_size);
3582 LWS_VISIBLE LWS_EXTERN int
3583 lws_b64_decode_string(const char *in, char *out, int out_size);
3585 
3586 
3596 #ifdef LWS_WITH_CGI
3597 enum lws_enum_stdinouterr {
3598  LWS_STDIN = 0,
3599  LWS_STDOUT = 1,
3600  LWS_STDERR = 2,
3601 };
3602 
3603 enum lws_cgi_hdr_state {
3604  LCHS_HEADER,
3605  LCHS_CR1,
3606  LCHS_LF1,
3607  LCHS_CR2,
3608  LCHS_LF2,
3609  LHCS_PAYLOAD,
3610  LCHS_SINGLE_0A,
3611 };
3612 
3614  struct lws **stdwsi;
3615  enum lws_enum_stdinouterr ch;
3616  unsigned char *data;
3617  enum lws_cgi_hdr_state hdr_state;
3618  int len;
3619 };
3620 
3621 
3631 LWS_VISIBLE LWS_EXTERN int
3632 lws_cgi(struct lws *wsi, const char * const *exec_array,
3633  int script_uri_path_len, int timeout_secs,
3634  const struct lws_protocol_vhost_options *mp_cgienv);
3635 
3641 LWS_VISIBLE LWS_EXTERN int
3642 lws_cgi_write_split_stdout_headers(struct lws *wsi);
3643 
3649 LWS_VISIBLE LWS_EXTERN int
3650 lws_cgi_kill(struct lws *wsi);
3651 #endif
3652 
3654 
3671 
3678  lws_filefd_type (*open)(struct lws *wsi, const char *filename,
3679  unsigned long *filelen, int flags);
3683  int (*close)(struct lws *wsi, lws_filefd_type fd);
3685  unsigned long (*seek_cur)(struct lws *wsi, lws_filefd_type fd,
3686  long offset_from_cur_pos);
3688  int (*read)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
3689  unsigned char *buf, unsigned long len);
3691  int (*write)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
3692  unsigned char *buf, unsigned long len);
3695  /* Add new things just above here ---^
3696  * This is part of the ABI, don't needlessly break compatibility */
3697 };
3698 
3704 LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops * LWS_WARN_UNUSED_RESULT
3705 lws_get_fops(struct lws_context *context);
3706 
3715 static LWS_INLINE lws_filefd_type LWS_WARN_UNUSED_RESULT
3716 lws_plat_file_open(struct lws *wsi, const char *filename,
3717  unsigned long *filelen, int flags)
3718 {
3719  return lws_get_fops(lws_get_context(wsi))->open(wsi, filename,
3720  filelen, flags);
3721 }
3722 
3729 static LWS_INLINE int
3730 lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
3731 {
3732  return lws_get_fops(lws_get_context(wsi))->close(wsi, fd);
3733 }
3734 
3742 static LWS_INLINE unsigned long
3743 lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
3744 {
3745  return lws_get_fops(lws_get_context(wsi))->seek_cur(wsi, fd, offset);
3746 }
3756 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
3757 lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
3758  unsigned char *buf, unsigned long len)
3759 {
3760  return lws_get_fops(lws_get_context(wsi))->read(wsi, fd, amount, buf,
3761  len);
3762 }
3772 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
3773 lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
3774  unsigned char *buf, unsigned long len)
3775 {
3776  return lws_get_fops(lws_get_context(wsi))->write(wsi, fd, amount, buf,
3777  len);
3778 }
3780 
3812 #ifdef LWS_WITH_SMTP
3813 
3825 };
3826 
3828 struct lws_email {
3829  void *data;
3831  uv_loop_t *loop;
3834  char email_smtp_ip[32];
3835  char email_helo[32];
3836  char email_from[100];
3837  char email_to[100];
3839  unsigned int max_content_size;
3842  /* Fill all the callbacks before init */
3843 
3844  int (*on_next)(struct lws_email *email);
3849  int (*on_sent)(struct lws_email *email);
3854  int (*on_get_body)(struct lws_email *email, char *buf, int len);
3860  /* private things */
3861  uv_timer_t timeout_email;
3863  uv_connect_t email_connect_req;
3864  uv_tcp_t email_client;
3866  char email_buf[256];
3867  char *content;
3868 };
3869 
3879 LWS_VISIBLE LWS_EXTERN int
3880 lws_email_init(struct lws_email *email, uv_loop_t *loop, int max_content);
3881 
3890 LWS_VISIBLE LWS_EXTERN void
3891 lws_email_check(struct lws_email *email);
3899 LWS_VISIBLE LWS_EXTERN void
3900 lws_email_destroy(struct lws_email *email);
3901 
3902 #endif
3903 
3904 
3905 #ifdef __cplusplus
3906 }
3907 #endif
3908 
3909 #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:3613
size_t rx_buffer_size
Definition: libwebsockets.h:1148
diff --git a/doc/html/md_README.test-apps.html b/doc/html/md_README.test-apps.html index 6ed96c0d..4039ae18 100644 --- a/doc/html/md_README.test-apps.html +++ b/doc/html/md_README.test-apps.html @@ -4,7 +4,7 @@ -libwebsockets: Notes about lws test apps +libwebsockets: Overview of lws test apps @@ -62,10 +62,27 @@ $(document).ready(function(){initNavTree('md_README.test-apps.html','');});
-
Notes about lws test apps
+
Overview of lws test apps
-

Testing server with a browser

+

Are you building a client? You just need to look at the test client libwebsockets-test-client.

+

If you are building a standalone server, there are three choices, in order of preferability.

+

1) lwsws + protocol plugins

+

Lws provides a generic web server app that can be configured with JSON config files. https://libwebsockets.org itself uses this method.

+

With lwsws handling the serving part, you only need to write an lws protocol plugin. See [plugin-standalone](plugin-standalone) for an example of how to do that outside lws itself, using lws public apis.

+

$ cmake .. -DLWS_WITH_LWSWS=1

+

See README.lwsws.md for information on how to configure lwsws.

+

NOTE this method implies libuv is used by lws, to provide crossplatform implementations of timers, dynamic lib loading etc for plugins and lwsws.

+

2) test-server-v2.0.c

+

This method lets you configure web serving in code, instead of using lwsws.

+

Plugins are still used, which implies libuv needed.

+

$ cmake .. -DLWS_WITH_PLUGINS=1

+

See test-server-v2.0.c

+

3) protocols in the server app

+

This is the original way lws implemented servers, plugins and libuv are not required, but without plugins separating the protocol code directly, the combined code is all squidged together and is much less maintainable.

+

This method is still supported in lws but all ongoing and future work is being done in protocol plugins only.

+

Notes about lws test apps

+

Testing server with a browser

If you run libwebsockets-test-server and point your browser (eg, Chrome) to

    http://127.0.0.1:7681
 

It will fetch a script in the form of test.html, and then run the script in there on the browser to open a websocket connection. Incrementing numbers should appear in the browser display.

By default the test server logs to both stderr and syslog, you can control what is logged using -d <log level>, see later.

diff --git a/doc/html/navtreedata.js b/doc/html/navtreedata.js index db36b872..66d4e104 100644 --- a/doc/html/navtreedata.js +++ b/doc/html/navtreedata.js @@ -6,7 +6,7 @@ var NAVTREE = [ "Notes about lwsws", "md_README.lwsws.html", null ], [ "Notes about coding with lws", "md_README.coding.html", null ], [ "Notes about generic-sessions Plugin", "md_README.generic-sessions.html", null ], - [ "Notes about lws test apps", "md_README.test-apps.html", null ], + [ "Overview of lws test apps", "md_README.test-apps.html", null ], [ "Deprecated List", "deprecated.html", null ], [ "Modules", "modules.html", "modules" ], [ "Data Structures", "annotated.html", [ diff --git a/doc/html/pages.html b/doc/html/pages.html index a5b8e0f5..880af1c5 100644 --- a/doc/html/pages.html +++ b/doc/html/pages.html @@ -71,7 +71,7 @@ $(document).ready(function(){initNavTree('pages.html','');});  Notes about lwsws  Notes about coding with lws  Notes about generic-sessions Plugin - Notes about lws test apps + Overview of lws test apps  Deprecated List
diff --git a/doc/latex/md_README.test-apps.tex b/doc/latex/md_README.test-apps.tex index 50881a38..76c7844f 100644 --- a/doc/latex/md_README.test-apps.tex +++ b/doc/latex/md_README.test-apps.tex @@ -1,3 +1,37 @@ +Are you building a client? You just need to look at the test client \href{test-server/test-client.c}{\tt libwebsockets-\/test-\/client}. + +If you are building a standalone server, there are three choices, in order of preferability. + +1) lwsws + protocol plugins + +Lws provides a generic web server app that can be configured with J\+S\+ON config files. \href{https://libwebsockets.org}{\tt https\+://libwebsockets.\+org} itself uses this method. + +With lwsws handling the serving part, you only need to write an lws protocol plugin. See \mbox{[}plugin-\/standalone\mbox{]}(plugin-\/standalone) for an example of how to do that outside lws itself, using lws public apis. + +\$ cmake .. -\/\+D\+L\+W\+S\+\_\+\+W\+I\+T\+H\+\_\+\+L\+W\+S\+WS=1 + +See \hyperlink{md_README.lwsws}{R\+E\+A\+D\+ME.lwsws.md} for information on how to configure lwsws. + +N\+O\+TE this method implies libuv is used by lws, to provide crossplatform implementations of timers, dynamic lib loading etc for plugins and lwsws. + +2) test-\/server-\/v2.\+0.\+c + +This method lets you configure web serving in code, instead of using lwsws. + +Plugins are still used, which implies libuv needed. + +\$ cmake .. -\/\+D\+L\+W\+S\+\_\+\+W\+I\+T\+H\+\_\+\+P\+L\+U\+G\+I\+NS=1 + +See \href{test-server/test-server-v2.0.c}{\tt test-\/server-\/v2.\+0.\+c} + +3) protocols in the server app + +This is the original way lws implemented servers, plugins and libuv are not required, but without plugins separating the protocol code directly, the combined code is all squidged together and is much less maintainable. + +This method is still supported in lws but all ongoing and future work is being done in protocol plugins only. + +\section*{Notes about lws test apps } + \subsection*{Testing server with a browser } If you run \href{test-server/test-server.c}{\tt libwebsockets-\/test-\/server} and point your browser (eg, Chrome) to \begin{DoxyVerb} http://127.0.0.1:7681 diff --git a/doc/latex/refman.tex b/doc/latex/refman.tex index 9e297790..8a9f9e3f 100644 --- a/doc/latex/refman.tex +++ b/doc/latex/refman.tex @@ -155,7 +155,7 @@ \label{md_README.generic-sessions} \hypertarget{md_README.generic-sessions}{} \input{md_README.generic-sessions} -\chapter{Notes about lws test apps} +\chapter{Overview of lws test apps} \label{md_README.test-apps} \hypertarget{md_README.test-apps}{} \input{md_README.test-apps} diff --git a/lib/server.c b/lib/server.c index 4d49f836..5d4b246e 100644 --- a/lib/server.c +++ b/lib/server.c @@ -870,7 +870,7 @@ lws_http_action(struct lws *wsi) } else { /* deferred cleanup and reset to protocols[0] */ - lwsl_notice("no hit\n"); + lwsl_info("no hit\n"); if (lws_bind_protocol(wsi, &wsi->vhost->protocols[0])) return 1; @@ -1853,7 +1853,7 @@ lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, O_RDONLY); if (wsi->u.http.fd == LWS_INVALID_FILE) { - lwsl_err("Unable to open '%s'\n", file); + lwsl_info("Unable to open '%s'\n", file); lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL); return -1; diff --git a/test-server/test-server-http.c b/test-server/test-server-http.c index 875a0a87..cdd136df 100644 --- a/test-server/test-server-http.c +++ b/test-server/test-server-http.c @@ -209,7 +209,7 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, switch (reason) { case LWS_CALLBACK_HTTP: - lwsl_notice("lws_http_serve: %s\n",in); + lwsl_info("lws_http_serve: %s\n",in); if (debug_level & LLL_INFO) { dump_handshake_info(wsi); @@ -223,11 +223,8 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, } { - char name[100], rip[50]; - lws_get_peer_addresses(wsi, lws_get_socket_fd(wsi), name, - sizeof(name), rip, sizeof(rip)); - sprintf(buf, "%s (%s)", name, rip); - lwsl_notice("HTTP connect from %s\n", buf); + lws_get_peer_simple(wsi, buf, sizeof(buf)); + lwsl_info("HTTP connect from %s\n", buf); } if (len < 1) { @@ -497,7 +494,7 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, return 1; goto try_to_reuse; case LWS_CALLBACK_HTTP_DROP_PROTOCOL: - lwsl_notice("LWS_CALLBACK_HTTP_DROP_PROTOCOL\n"); + lwsl_debug("LWS_CALLBACK_HTTP_DROP_PROTOCOL\n"); /* called when our wsi user_space is going to be destroyed */ if (pss->spa) { diff --git a/test-server/test-server.c b/test-server/test-server.c index 505df01a..85b9c1bb 100644 --- a/test-server/test-server.c +++ b/test-server/test-server.c @@ -135,7 +135,7 @@ test_server_fops_open(struct lws *wsi, const char *filename, /* call through to original platform implementation */ n = fops_plat.open(wsi, filename, filelen, flags); - lwsl_notice("%s: opening %s, ret %ld, len %lu\n", __func__, filename, + lwsl_info("%s: opening %s, ret %ld, len %lu\n", __func__, filename, (long)n, *filelen); return n;