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