plat change to build selection by cmake
[platform/upstream/libwebsockets.git] / lib / private-libwebsockets.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2013 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
22 /* System introspection configs */
23 #ifdef CMAKE_BUILD
24 #include "lws_config.h"
25 #else
26 #if defined(WIN32) || defined(_WIN32)
27 #define inline __inline
28 #include <tchar.h>
29 #include <mstcpip.h>
30 #ifdef _WIN32_WCE
31 #define vsnprintf _vsnprintf
32 #endif
33
34 #else /* not WIN32 */
35 #include "config.h"
36
37 #endif /* not WIN32 */
38 #endif /* not CMAKE */
39
40 #ifdef HAVE_SYS_TYPES_H
41 #include <sys/types.h>
42 #endif
43
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
47 #include <time.h>
48 #include <ctype.h>
49 #include <limits.h>
50 #include <stdarg.h>
51
52 #ifdef HAVE_SYS_STAT_H
53 #include <sys/stat.h>
54 #endif
55
56 #if defined(WIN32) || defined(_WIN32)
57 #define LWS_NO_DAEMONIZE
58 #define LWS_ERRNO WSAGetLastError()
59 #define LWS_EAGAIN WSAEWOULDBLOCK
60 #define LWS_EALREADY WSAEALREADY
61 #define LWS_EINPROGRESS WSAEINPROGRESS
62 #define LWS_EINTR WSAEINTR
63 #define LWS_EISCONN WSAEISCONN
64 #define LWS_EWOULDBLOCK WSAEWOULDBLOCK
65 #define LWS_POLLHUP (FD_CLOSE)
66 #define LWS_POLLIN (FD_READ | FD_ACCEPT)
67 #define LWS_POLLOUT (FD_WRITE)
68 #define MSG_NOSIGNAL 0
69 #define SHUT_RDWR SD_BOTH
70 #define SOL_TCP IPPROTO_TCP
71
72 #define compatible_close(fd) closesocket(fd)
73 #define compatible_file_close(fd) CloseHandle(fd)
74 #define compatible_file_seek_cur(fd, offset) SetFilePointer(fd, offset, FILE_CURRENT)
75 #define compatible_file_read(amount, fd, buf, len) {\
76         DWORD _amount; \
77         if (!ReadFile(fd, buf, len, &amount, NULL)) \
78                 amount = -1; \
79         else \
80                 amount = _amount; \
81         }
82 #define lws_set_blocking_send(wsi) wsi->sock_send_blocking = TRUE
83 #include <winsock2.h>
84 #include <windows.h>
85 #define LWS_INVALID_FILE INVALID_HANDLE_VALUE
86 #else /* not windows --> */
87 #include <errno.h>
88 #include <fcntl.h>
89 #include <netdb.h>
90 #include <signal.h>
91 #include <strings.h>
92 #include <unistd.h>
93 #include <sys/types.h>
94 #include <sys/socket.h>
95 #ifdef LWS_BUILTIN_GETIFADDRS
96  #include <getifaddrs.h>
97 #else
98  #include <ifaddrs.h>
99 #endif
100 #include <sys/syslog.h>
101 #include <sys/un.h>
102 #include <sys/socket.h>
103 #include <netdb.h>
104 #ifndef LWS_NO_FORK
105 #ifdef HAVE_SYS_PRCTL_H
106 #include <sys/prctl.h>
107 #endif
108 #endif
109 #include <netinet/in.h>
110 #include <netinet/tcp.h>
111 #include <arpa/inet.h>
112 #include <poll.h>
113 #ifdef LWS_USE_LIBEV
114 #include <ev.h>
115 #endif /* LWS_USE_LIBEV */
116
117 #include <sys/mman.h>
118 #include <sys/time.h>
119
120 #define LWS_ERRNO errno
121 #define LWS_EAGAIN EAGAIN
122 #define LWS_EALREADY EALREADY
123 #define LWS_EINPROGRESS EINPROGRESS
124 #define LWS_EINTR EINTR
125 #define LWS_EISCONN EISCONN
126 #define LWS_EWOULDBLOCK EWOULDBLOCK
127 #define LWS_INVALID_FILE -1
128 #define LWS_POLLHUP (POLLHUP|POLLERR)
129 #define LWS_POLLIN (POLLIN)
130 #define LWS_POLLOUT (POLLOUT)
131 #define compatible_close(fd) close(fd)
132 #define compatible_file_close(fd) close(fd)
133 #define compatible_file_seek_cur(fd, offset) lseek(fd, offset, SEEK_CUR)
134 #define compatible_file_read(amount, fd, buf, len) \
135                 amount = read(fd, buf, len);
136 #define lws_set_blocking_send(wsi)
137 #endif
138
139 #ifndef HAVE_BZERO
140 #define bzero(b, len) (memset((b), '\0', (len)), (void) 0)
141 #endif
142
143 #ifndef HAVE_STRERROR
144 #define strerror(x) ""
145 #endif
146
147 #ifdef LWS_OPENSSL_SUPPORT
148 #ifdef USE_CYASSL
149 #include <cyassl/openssl/ssl.h>
150 #include <cyassl/error.h>
151 unsigned char *
152 SHA1(const unsigned char *d, size_t n, unsigned char *md);
153 #else
154 #include <openssl/ssl.h>
155 #include <openssl/evp.h>
156 #include <openssl/err.h>
157 #include <openssl/md5.h>
158 #include <openssl/sha.h>
159 #endif /* not USE_CYASSL */
160 #endif
161
162 #include "libwebsockets.h"
163
164 #if defined(WIN32) || defined(_WIN32)
165
166 #ifndef BIG_ENDIAN
167 #define BIG_ENDIAN    4321  /* to show byte order (taken from gcc) */
168 #endif
169 #ifndef LITTLE_ENDIAN
170 #define LITTLE_ENDIAN 1234
171 #endif
172 #ifndef BYTE_ORDER
173 #define BYTE_ORDER LITTLE_ENDIAN
174 #endif
175 typedef unsigned __int64 u_int64_t;
176
177 #undef __P
178 #ifndef __P
179 #if __STDC__
180 #define __P(protos) protos
181 #else
182 #define __P(protos) ()
183 #endif
184 #endif
185
186 #else
187
188 #include <sys/stat.h>
189 #include <sys/cdefs.h>
190 #include <sys/time.h>
191
192 #if defined(__APPLE__)
193 #include <machine/endian.h>
194 #elif defined(__FreeBSD__)
195 #include <sys/endian.h>
196 #elif defined(__linux__)
197 #include <endian.h>
198 #endif
199
200 #if !defined(BYTE_ORDER)
201 # define BYTE_ORDER __BYTE_ORDER
202 #endif
203 #if !defined(LITTLE_ENDIAN)
204 # define LITTLE_ENDIAN __LITTLE_ENDIAN
205 #endif
206 #if !defined(BIG_ENDIAN)
207 # define BIG_ENDIAN __BIG_ENDIAN
208 #endif
209
210 #endif
211
212 /*
213  * Mac OSX as well as iOS do not define the MSG_NOSIGNAL flag,
214  * but happily have something equivalent in the SO_NOSIGPIPE flag.
215  */
216 #ifdef __APPLE__
217 #define MSG_NOSIGNAL SO_NOSIGPIPE
218 #endif
219
220 #ifndef LWS_MAX_HEADER_LEN
221 #define LWS_MAX_HEADER_LEN 1024
222 #endif
223 #ifndef LWS_MAX_PROTOCOLS
224 #define LWS_MAX_PROTOCOLS 5
225 #endif
226 #ifndef LWS_MAX_EXTENSIONS_ACTIVE
227 #define LWS_MAX_EXTENSIONS_ACTIVE 3
228 #endif
229 #ifndef SPEC_LATEST_SUPPORTED
230 #define SPEC_LATEST_SUPPORTED 13
231 #endif
232 #ifndef AWAITING_TIMEOUT
233 #define AWAITING_TIMEOUT 5
234 #endif
235 #ifndef CIPHERS_LIST_STRING
236 #define CIPHERS_LIST_STRING "DEFAULT"
237 #endif
238 #ifndef LWS_SOMAXCONN
239 #define LWS_SOMAXCONN SOMAXCONN
240 #endif
241
242 #define MAX_WEBSOCKET_04_KEY_LEN 128
243 #define LWS_MAX_SOCKET_IO_BUF 4096
244
245 #ifndef SYSTEM_RANDOM_FILEPATH
246 #define SYSTEM_RANDOM_FILEPATH "/dev/urandom"
247 #endif
248 #ifndef LWS_MAX_ZLIB_CONN_BUFFER
249 #define LWS_MAX_ZLIB_CONN_BUFFER (64 * 1024)
250 #endif
251
252 /*
253  * if not in a connection storm, check for incoming
254  * connections this many normal connection services
255  */
256 #define LWS_LISTEN_SERVICE_MODULO 10
257
258 enum lws_websocket_opcodes_07 {
259         LWS_WS_OPCODE_07__CONTINUATION = 0,
260         LWS_WS_OPCODE_07__TEXT_FRAME = 1,
261         LWS_WS_OPCODE_07__BINARY_FRAME = 2,
262
263         LWS_WS_OPCODE_07__NOSPEC__MUX = 7,
264
265         /* control extensions 8+ */
266
267         LWS_WS_OPCODE_07__CLOSE = 8,
268         LWS_WS_OPCODE_07__PING = 9,
269         LWS_WS_OPCODE_07__PONG = 0xa,
270 };
271
272
273 enum lws_connection_states {
274         WSI_STATE_HTTP,
275         WSI_STATE_HTTP_ISSUING_FILE,
276         WSI_STATE_HTTP_HEADERS,
277         WSI_STATE_HTTP_BODY,
278         WSI_STATE_DEAD_SOCKET,
279         WSI_STATE_ESTABLISHED,
280         WSI_STATE_CLIENT_UNCONNECTED,
281         WSI_STATE_RETURNED_CLOSE_ALREADY,
282         WSI_STATE_AWAITING_CLOSE_ACK,
283 };
284
285 enum lws_rx_parse_state {
286         LWS_RXPS_NEW,
287
288         LWS_RXPS_04_MASK_NONCE_1,
289         LWS_RXPS_04_MASK_NONCE_2,
290         LWS_RXPS_04_MASK_NONCE_3,
291
292         LWS_RXPS_04_FRAME_HDR_1,
293         LWS_RXPS_04_FRAME_HDR_LEN,
294         LWS_RXPS_04_FRAME_HDR_LEN16_2,
295         LWS_RXPS_04_FRAME_HDR_LEN16_1,
296         LWS_RXPS_04_FRAME_HDR_LEN64_8,
297         LWS_RXPS_04_FRAME_HDR_LEN64_7,
298         LWS_RXPS_04_FRAME_HDR_LEN64_6,
299         LWS_RXPS_04_FRAME_HDR_LEN64_5,
300         LWS_RXPS_04_FRAME_HDR_LEN64_4,
301         LWS_RXPS_04_FRAME_HDR_LEN64_3,
302         LWS_RXPS_04_FRAME_HDR_LEN64_2,
303         LWS_RXPS_04_FRAME_HDR_LEN64_1,
304
305         LWS_RXPS_07_COLLECT_FRAME_KEY_1,
306         LWS_RXPS_07_COLLECT_FRAME_KEY_2,
307         LWS_RXPS_07_COLLECT_FRAME_KEY_3,
308         LWS_RXPS_07_COLLECT_FRAME_KEY_4,
309
310         LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED
311 };
312
313
314 enum connection_mode {
315         LWS_CONNMODE_HTTP_SERVING,
316         LWS_CONNMODE_HTTP_SERVING_ACCEPTED, /* actual HTTP service going on */
317         LWS_CONNMODE_PRE_WS_SERVING_ACCEPT,
318
319         LWS_CONNMODE_WS_SERVING,
320         LWS_CONNMODE_WS_CLIENT,
321
322         /* transient, ssl delay hiding */
323         LWS_CONNMODE_SSL_ACK_PENDING,
324
325         /* transient modes */
326         LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT,
327         LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY,
328         LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE,
329         LWS_CONNMODE_WS_CLIENT_WAITING_SSL,
330         LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY,
331         LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT,
332         LWS_CONNMODE_WS_CLIENT_PENDING_CANDIDATE_CHILD,
333
334         /* special internal types */
335         LWS_CONNMODE_SERVER_LISTENER,
336 };
337
338 enum {
339         LWS_RXFLOW_ALLOW = (1 << 0),
340         LWS_RXFLOW_PENDING_CHANGE = (1 << 1),
341 };
342
343 struct libwebsocket_protocols;
344 struct libwebsocket;
345
346 #ifdef LWS_USE_LIBEV
347 struct lws_io_watcher {
348         struct ev_io watcher;
349         struct libwebsocket_context* context;
350 };
351
352 struct lws_signal_watcher {
353         struct ev_signal watcher;
354         struct libwebsocket_context* context;
355 };
356 #endif /* LWS_USE_LIBEV */
357
358 struct libwebsocket_context {
359 #ifdef _WIN32
360         WSAEVENT *events;
361 #endif
362         struct libwebsocket_pollfd *fds;
363         struct libwebsocket **lws_lookup; /* fd to wsi */
364         int fds_count;
365 #ifdef LWS_USE_LIBEV
366         struct ev_loop* io_loop;
367         struct lws_io_watcher w_accept;
368         struct lws_signal_watcher w_sigint;
369 #endif /* LWS_USE_LIBEV */
370         int max_fds;
371         int listen_port;
372         const char *iface;
373         char http_proxy_address[128];
374         char canonical_hostname[128];
375         unsigned int http_proxy_port;
376         unsigned int options;
377         time_t last_timeout_check_s;
378
379         /*
380          * usable by anything in the service code, but only if the scope
381          * does not last longer than the service action (since next service
382          * of any socket can likewise use it and overwrite)
383          */
384         unsigned char service_buffer[LWS_MAX_SOCKET_IO_BUF];
385
386         int started_with_parent;
387
388         int fd_random;
389         int listen_service_modulo;
390         int listen_service_count;
391         int listen_service_fd;
392         int listen_service_extraseen;
393
394         /*
395          * set to the Thread ID that's doing the service loop just before entry
396          * to poll indicates service thread likely idling in poll()
397          * volatile because other threads may check it as part of processing
398          * for pollfd event change.
399          */
400         volatile int service_tid;
401 #ifndef _WIN32
402         int dummy_pipe_fds[2];
403 #endif
404
405         int ka_time;
406         int ka_probes;
407         int ka_interval;
408
409 #ifdef LWS_LATENCY
410         unsigned long worst_latency;
411         char worst_latency_info[256];
412 #endif
413
414 #ifdef LWS_OPENSSL_SUPPORT
415         int use_ssl;
416         int allow_non_ssl_on_ssl_port;
417         SSL_CTX *ssl_ctx;
418         SSL_CTX *ssl_client_ctx;
419 #endif
420         struct libwebsocket_protocols *protocols;
421         int count_protocols;
422 #ifndef LWS_NO_EXTENSIONS
423         struct libwebsocket_extension *extensions;
424 #endif
425         void *user_space;
426 };
427
428 #ifdef LWS_USE_LIBEV
429 #define LWS_LIBEV_ENABLED(context) (context->options & LWS_SERVER_OPTION_LIBEV)
430 #else
431 #define LWS_LIBEV_ENABLED(context) (0)
432 #endif
433
434 #ifdef LWS_USE_IPV6
435 #define LWS_IPV6_ENABLED(context) (!(context->options & LWS_SERVER_OPTION_DISABLE_IPV6))
436 #else
437 #define LWS_IPV6_ENABLED(context) (0)
438 #endif
439
440 enum uri_path_states {
441         URIPS_IDLE,
442         URIPS_SEEN_SLASH,
443         URIPS_SEEN_SLASH_DOT,
444         URIPS_SEEN_SLASH_DOT_DOT,
445         URIPS_ARGUMENTS,
446 };
447
448 enum uri_esc_states {
449         URIES_IDLE,
450         URIES_SEEN_PERCENT,
451         URIES_SEEN_PERCENT_H1,
452 };
453
454 /*
455  * This is totally opaque to code using the library.  It's exported as a
456  * forward-reference pointer-only declaration; the user can use the pointer with
457  * other APIs to get information out of it.
458  */
459
460 struct lws_fragments {
461         unsigned short offset;
462         unsigned short len;
463         unsigned char next_frag_index;
464 };
465
466 struct allocated_headers {
467         unsigned short next_frag_index;
468         unsigned short pos;
469         unsigned char frag_index[WSI_TOKEN_COUNT];
470         struct lws_fragments frags[WSI_TOKEN_COUNT * 2];
471         char data[LWS_MAX_HEADER_LEN];
472 #ifndef LWS_NO_CLIENT
473         char initial_handshake_hash_base64[30];
474         unsigned short c_port;
475 #endif
476 };
477
478 struct _lws_http_mode_related {
479         struct allocated_headers *ah; /* mirroring  _lws_header_related */
480 #if defined(WIN32) || defined(_WIN32)
481         HANDLE fd;
482 #else
483         int fd;
484 #endif
485         unsigned long filepos;
486         unsigned long filelen;
487
488         int content_length;
489         int content_length_seen;
490         int body_index;
491         unsigned char *post_buffer;
492 };
493
494 struct _lws_header_related {
495         struct allocated_headers *ah;
496         short lextable_pos;
497         unsigned char parser_state; /* enum lws_token_indexes */
498         enum uri_path_states ups;
499         enum uri_esc_states ues;
500         char esc_stash;
501 };
502
503 struct _lws_websocket_related {
504         char *rx_user_buffer;
505         int rx_user_buffer_head;
506         unsigned char frame_masking_nonce_04[4];
507         unsigned char frame_mask_index;
508         size_t rx_packet_length;
509         unsigned char opcode;
510         unsigned int final:1;
511         unsigned char rsv;
512         unsigned int frame_is_binary:1;
513         unsigned int all_zero_nonce:1;
514         short close_reason; /* enum lws_close_status */
515         unsigned char *rxflow_buffer;
516         int rxflow_len;
517         int rxflow_pos;
518         unsigned int rxflow_change_to:2;
519         unsigned int this_frame_masked:1;
520         unsigned int inside_frame:1; /* next write will be more of frame */
521         unsigned int clean_buffer:1; /* buffer not rewritten by extension */
522 };
523
524 struct libwebsocket {
525
526         /* lifetime members */
527
528 #ifdef LWS_USE_LIBEV
529     struct lws_io_watcher w_read;
530     struct lws_io_watcher w_write;
531 #endif /* LWS_USE_LIBEV */
532         const struct libwebsocket_protocols *protocol;
533 #ifndef LWS_NO_EXTENSIONS
534         struct libwebsocket_extension *
535                                    active_extensions[LWS_MAX_EXTENSIONS_ACTIVE];
536         void *active_extensions_user[LWS_MAX_EXTENSIONS_ACTIVE];
537         unsigned char count_active_extensions;
538         unsigned int extension_data_pending:1;
539 #endif
540         unsigned char ietf_spec_revision;
541
542         char mode; /* enum connection_mode */
543         char state; /* enum lws_connection_states */
544         char lws_rx_parse_state; /* enum lws_rx_parse_state */
545         char rx_frame_type; /* enum libwebsocket_write_protocol */
546
547         unsigned int hdr_parsing_completed:1;
548
549         char pending_timeout; /* enum pending_timeout */
550         time_t pending_timeout_limit;
551
552         int sock;
553         int position_in_fds_table;
554 #ifdef LWS_LATENCY
555         unsigned long action_start;
556         unsigned long latency_start;
557 #endif
558
559         /* truncated send handling */
560         unsigned char *truncated_send_malloc; /* non-NULL means buffering in progress */
561         unsigned int truncated_send_allocation; /* size of malloc */
562         unsigned int truncated_send_offset; /* where we are in terms of spilling */
563         unsigned int truncated_send_len; /* how much is buffered */
564
565         void *user_space;
566
567         /* members with mutually exclusive lifetimes are unionized */
568
569         union u {
570                 struct _lws_http_mode_related http;
571                 struct _lws_header_related hdr;
572                 struct _lws_websocket_related ws;
573         } u;
574
575 #ifdef LWS_OPENSSL_SUPPORT
576         SSL *ssl;
577         BIO *client_bio;
578         unsigned int use_ssl:2;
579 #endif
580
581 #ifdef _WIN32
582         BOOL sock_send_blocking;
583 #endif
584 };
585
586 LWS_EXTERN void
587 libwebsocket_close_and_free_session(struct libwebsocket_context *context,
588                                struct libwebsocket *wsi, enum lws_close_status);
589
590 #ifndef LWS_LATENCY
591 static inline void lws_latency(struct libwebsocket_context *context,
592                 struct libwebsocket *wsi, const char *action,
593                                          int ret, int completion) { while (0); }
594 static inline void lws_latency_pre(struct libwebsocket_context *context,
595                                         struct libwebsocket *wsi) { while (0); }
596 #else
597 #define lws_latency_pre(_context, _wsi) lws_latency(_context, _wsi, NULL, 0, 0)
598 extern void
599 lws_latency(struct libwebsocket_context *context,
600                         struct libwebsocket *wsi, const char *action,
601                                                        int ret, int completion);
602 #endif
603
604 LWS_EXTERN int
605 libwebsocket_client_rx_sm(struct libwebsocket *wsi, unsigned char c);
606
607 LWS_EXTERN int
608 libwebsocket_parse(struct libwebsocket *wsi, unsigned char c);
609
610 LWS_EXTERN int
611 libwebsocket_interpret_incoming_packet(struct libwebsocket *wsi,
612                                                 unsigned char *buf, size_t len);
613
614 LWS_EXTERN int
615 lws_b64_selftest(void);
616
617 LWS_EXTERN struct libwebsocket *
618 wsi_from_fd(struct libwebsocket_context *context, int fd);
619
620 LWS_EXTERN int
621 insert_wsi_socket_into_fds(struct libwebsocket_context *context,
622                                                       struct libwebsocket *wsi);
623
624 LWS_EXTERN int
625 lws_issue_raw(struct libwebsocket *wsi, unsigned char *buf, size_t len);
626
627
628 LWS_EXTERN int
629 libwebsocket_service_timeout_check(struct libwebsocket_context *context,
630                                     struct libwebsocket *wsi, unsigned int sec);
631
632 LWS_EXTERN struct libwebsocket *
633 libwebsocket_client_connect_2(struct libwebsocket_context *context,
634         struct libwebsocket *wsi);
635
636 LWS_EXTERN struct libwebsocket *
637 libwebsocket_create_new_server_wsi(struct libwebsocket_context *context);
638
639 LWS_EXTERN char *
640 libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
641                 struct libwebsocket *wsi, char *pkt);
642
643 LWS_EXTERN int
644 lws_handle_POLLOUT_event(struct libwebsocket_context *context,
645                               struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd);
646 #ifndef LWS_NO_EXTENSIONS
647 LWS_EXTERN int
648 lws_any_extension_handled(struct libwebsocket_context *context,
649                           struct libwebsocket *wsi,
650                           enum libwebsocket_extension_callback_reasons r,
651                           void *v, size_t len);
652
653 LWS_EXTERN int
654 lws_ext_callback_for_each_active(struct libwebsocket *wsi, int reason,
655                                                     void *buf, int len);
656 LWS_EXTERN int
657 lws_ext_callback_for_each_extension_type(
658                 struct libwebsocket_context *context, struct libwebsocket *wsi,
659                         int reason, void *arg, int len);
660 #else
661 #define lws_any_extension_handled(_a, _b, _c, _d, _e) (0)
662 #define lws_ext_callback_for_each_active(_a, _b, _c, _d) (0)
663 #define lws_ext_callback_for_each_extension_type(_a, _b, _c, _d, _e) (0)
664 #endif
665
666 LWS_EXTERN int
667 lws_client_interpret_server_handshake(struct libwebsocket_context *context,
668                 struct libwebsocket *wsi);
669
670 LWS_EXTERN int
671 libwebsocket_rx_sm(struct libwebsocket *wsi, unsigned char c);
672
673 LWS_EXTERN int
674 lws_issue_raw_ext_access(struct libwebsocket *wsi,
675                                                 unsigned char *buf, size_t len);
676
677 LWS_EXTERN int
678 _libwebsocket_rx_flow_control(struct libwebsocket *wsi);
679
680 LWS_EXTERN int
681 user_callback_handle_rxflow(callback_function,
682                 struct libwebsocket_context *context,
683                         struct libwebsocket *wsi,
684                          enum libwebsocket_callback_reasons reason, void *user,
685                                                           void *in, size_t len);
686
687 LWS_EXTERN int
688 lws_plat_set_socket_options(struct libwebsocket_context *context, int fd);
689
690 LWS_EXTERN int
691 lws_allocate_header_table(struct libwebsocket *wsi);
692
693 LWS_EXTERN char *
694 lws_hdr_simple_ptr(struct libwebsocket *wsi, enum lws_token_indexes h);
695
696 LWS_EXTERN int
697 lws_hdr_simple_create(struct libwebsocket *wsi,
698                                 enum lws_token_indexes h, const char *s);
699
700 LWS_EXTERN int
701 libwebsocket_ensure_user_space(struct libwebsocket *wsi);
702
703 LWS_EXTERN int
704 lws_change_pollfd(struct libwebsocket *wsi, int _and, int _or);
705
706 #ifndef LWS_NO_SERVER
707 LWS_EXTERN int handshake_0405(struct libwebsocket_context *context,
708                                                       struct libwebsocket *wsi);
709 #endif
710
711 #ifndef LWS_NO_DAEMONIZE
712 LWS_EXTERN int get_daemonize_pid();
713 #endif
714
715 extern int interface_to_sa(struct libwebsocket_context *context,
716                 const char *ifname, struct sockaddr_in *addr, size_t addrlen);
717
718 #ifdef _WIN32
719 LWS_EXTERN HANDLE lws_plat_open_file(const char* filename, unsigned long* filelen);
720 #else
721 LWS_EXTERN int lws_plat_open_file(const char* filename, unsigned long* filelen);
722 #endif
723
724 #ifndef LWS_OPENSSL_SUPPORT
725
726 unsigned char *
727 SHA1(const unsigned char *d, size_t n, unsigned char *md);
728
729 #else
730
731 LWS_EXTERN int openssl_websocket_private_data_index;
732
733 #endif