2 * libwebsockets - small server side websockets and web server implementation
4 * Copyright (C) 2010-2014 Andy Green <andy@warmcat.com>
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.
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.
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,
22 #include "private-libwebsockets.h"
24 int log_level = LLL_ERR | LLL_WARN | LLL_NOTICE;
25 static void (*lwsl_emit)(int level, const char *line) = lwsl_emit_stderr;
27 static const char * const log_level_names[] = {
41 lws_free_wsi(struct lws *wsi)
46 /* Protocol user data may be allocated either internally by lws
47 * or by specified the user.
48 * We should only free what we allocated. */
49 if (wsi->protocol && wsi->protocol->per_session_data_size &&
50 wsi->user_space && !wsi->user_space_externally_allocated)
51 lws_free(wsi->user_space);
53 lws_free2(wsi->rxflow_buffer);
54 lws_free2(wsi->truncated_send_malloc);
55 lws_free_header_table(wsi);
60 lws_close_and_free_session(struct lws_context *context,
61 struct lws *wsi, enum lws_close_status reason)
63 int n, m, ret, old_state;
64 struct lws_tokens eff_buf;
65 unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 2 +
66 LWS_SEND_BUFFER_POST_PADDING];
71 old_state = wsi->state;
73 if (wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED &&
74 wsi->u.http.fd != LWS_INVALID_FILE) {
75 lwsl_debug("closing http file\n");
76 lws_plat_file_close(&context->fops, wsi->u.http.fd);
77 wsi->u.http.fd = LWS_INVALID_FILE;
78 context->protocols[0].callback(context, wsi,
79 LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0);
81 if (wsi->socket_is_permanently_unusable ||
82 reason == LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY)
83 goto just_kill_connection;
86 case WSI_STATE_DEAD_SOCKET:
89 /* we tried the polite way... */
90 case WSI_STATE_AWAITING_CLOSE_ACK:
91 goto just_kill_connection;
93 case WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE:
94 if (wsi->truncated_send_len) {
95 lws_callback_on_writable(context, wsi);
98 lwsl_info("wsi %p completed WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE\n", wsi);
99 goto just_kill_connection;
101 if (wsi->truncated_send_len) {
102 lwsl_info("wsi %p entering WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE\n", wsi);
103 wsi->state = WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE;
104 lws_set_timeout(wsi, PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE, 5);
110 wsi->u.ws.close_reason = reason;
112 if (wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT ||
113 wsi->mode == LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE)
114 goto just_kill_connection;
116 if (wsi->mode == LWS_CONNMODE_HTTP_SERVING)
117 context->protocols[0].callback(context, wsi,
118 LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0);
121 * are his extensions okay with him closing? Eg he might be a mux
122 * parent and just his ch1 aspect is closing?
125 if (lws_ext_callback_for_each_active(wsi,
126 LWS_EXT_CALLBACK_CHECK_OK_TO_REALLY_CLOSE, NULL, 0) > 0) {
127 lwsl_ext("extension vetoed close\n");
132 * flush any tx pending from extensions, since we may send close packet
133 * if there are problems with send, just nuke the connection
138 eff_buf.token = NULL;
139 eff_buf.token_len = 0;
141 /* show every extension the new incoming data */
143 m = lws_ext_callback_for_each_active(wsi,
144 LWS_EXT_CALLBACK_FLUSH_PENDING_TX, &eff_buf, 0);
146 lwsl_ext("Extension reports fatal error\n");
147 goto just_kill_connection;
151 * at least one extension told us he has more
152 * to spill, so we will go around again after
156 /* assuming they left us something to send, send it */
158 if (eff_buf.token_len)
159 if (lws_issue_raw(wsi, (unsigned char *)eff_buf.token,
160 eff_buf.token_len) !=
162 lwsl_debug("close: ext spill failed\n");
163 goto just_kill_connection;
168 * signal we are closing, lws_write will
169 * add any necessary version-specific stuff. If the write fails,
170 * no worries we are closing anyway. If we didn't initiate this
171 * close, then our state has been changed to
172 * WSI_STATE_RETURNED_CLOSE_ALREADY and we will skip this.
174 * Likewise if it's a second call to close this connection after we
175 * sent the close indication to the peer already, we are in state
176 * WSI_STATE_AWAITING_CLOSE_ACK and will skip doing this a second time.
179 if (old_state == WSI_STATE_ESTABLISHED &&
180 reason != LWS_CLOSE_STATUS_NOSTATUS &&
181 reason != LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY) {
183 lwsl_debug("sending close indication...\n");
185 /* make valgrind happy */
186 memset(buf, 0, sizeof(buf));
187 n = lws_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING + 2],
191 * we have sent a nice protocol level indication we
192 * now wish to close, we should not send anything more
194 wsi->state = WSI_STATE_AWAITING_CLOSE_ACK;
197 * ...and we should wait for a reply for a bit
200 lws_set_timeout(wsi, PENDING_TIMEOUT_CLOSE_ACK, 1);
201 lwsl_debug("sent close indication, awaiting ack\n");
206 lwsl_info("close: sending close packet failed, hanging up\n");
208 /* else, the send failed and we should just hang up */
211 just_kill_connection:
213 lwsl_debug("close: just_kill_connection\n");
216 * we won't be servicing or receiving anything further from this guy
217 * delete socket from the internal poll list if still present
219 lws_ssl_remove_wsi_from_buffered_list(context, wsi);
221 /* checking return redundant since we anyway close */
222 remove_wsi_socket_from_fds(context, wsi);
224 wsi->state = WSI_STATE_DEAD_SOCKET;
226 lws_free2(wsi->rxflow_buffer);
227 lws_free_header_table(wsi);
229 if ((old_state == WSI_STATE_ESTABLISHED ||
230 wsi->mode == LWS_CONNMODE_WS_SERVING ||
231 wsi->mode == LWS_CONNMODE_WS_CLIENT)) {
233 lws_free2(wsi->u.ws.rx_user_buffer);
235 if (wsi->truncated_send_malloc)
236 /* not going to be completed... nuke it */
237 lws_free2(wsi->truncated_send_malloc);
239 if (wsi->u.ws.ping_payload_buf) {
240 lws_free2(wsi->u.ws.ping_payload_buf);
241 wsi->u.ws.ping_payload_alloc = 0;
242 wsi->u.ws.ping_payload_len = 0;
243 wsi->u.ws.ping_pending_flag = 0;
247 /* tell the user it's all over for this guy */
249 if (wsi->protocol && wsi->protocol->callback &&
250 ((old_state == WSI_STATE_ESTABLISHED) ||
251 (old_state == WSI_STATE_RETURNED_CLOSE_ALREADY) ||
252 (old_state == WSI_STATE_AWAITING_CLOSE_ACK) ||
253 (old_state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE))) {
254 lwsl_debug("calling back CLOSED\n");
255 wsi->protocol->callback(context, wsi, LWS_CALLBACK_CLOSED,
256 wsi->user_space, NULL, 0);
257 } else if (wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED) {
258 lwsl_debug("calling back CLOSED_HTTP\n");
259 context->protocols[0].callback(context, wsi,
260 LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0 );
261 } else if (wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY ||
262 wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT) {
263 lwsl_debug("Connection closed before server reply\n");
264 context->protocols[0].callback(context, wsi,
265 LWS_CALLBACK_CLIENT_CONNECTION_ERROR,
266 wsi->user_space, NULL, 0);
268 lwsl_debug("not calling back closed mode=%d state=%d\n",
269 wsi->mode, old_state);
271 /* deallocate any active extension contexts */
273 if (lws_ext_callback_for_each_active(wsi, LWS_EXT_CALLBACK_DESTROY,
275 lwsl_warn("extension destruction failed\n");
276 #ifndef LWS_NO_EXTENSIONS
277 for (n = 0; n < wsi->count_active_extensions; n++)
278 lws_free(wsi->active_extensions_user[n]);
281 * inform all extensions in case they tracked this guy out of band
282 * even though not active on him specifically
284 if (lws_ext_callback_for_each_extension_type(context, wsi,
285 LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING, NULL, 0) < 0)
286 lwsl_warn("ext destroy wsi failed\n");
288 if (!lws_ssl_close(wsi) && lws_socket_is_valid(wsi->sock)) {
290 n = shutdown(wsi->sock, SHUT_RDWR);
292 lwsl_debug("closing: shutdown ret %d\n", LWS_ERRNO);
294 n = compatible_close(wsi->sock);
296 lwsl_debug("closing: close ret %d\n", LWS_ERRNO);
299 compatible_close(wsi->sock);
301 wsi->sock = LWS_SOCK_INVALID;
304 /* outermost destroy notification for wsi (user_space still intact) */
305 context->protocols[0].callback(context, wsi, LWS_CALLBACK_WSI_DESTROY,
306 wsi->user_space, NULL, 0);
312 lws_get_addresses(struct lws_context *context, void *ads, char *name,
313 int name_len, char *rip, int rip_len)
316 struct addrinfo ai, *res;
317 struct sockaddr_in addr4;
322 addr4.sin_family = AF_UNSPEC;
325 if (LWS_IPV6_ENABLED(context)) {
326 if (!lws_plat_inet_ntop(AF_INET6, &((struct sockaddr_in6 *)ads)->sin6_addr, rip, rip_len)) {
327 lwsl_err("inet_ntop", strerror(LWS_ERRNO));
331 // Strip off the IPv4 to IPv6 header if one exists
332 if (strncmp(rip, "::ffff:", 7) == 0)
333 memmove(rip, rip + 7, strlen(rip) - 6);
335 getnameinfo((struct sockaddr *)ads,
336 sizeof(struct sockaddr_in6), name,
337 name_len, NULL, 0, 0);
343 struct addrinfo *result;
345 memset(&ai, 0, sizeof ai);
346 ai.ai_family = PF_UNSPEC;
347 ai.ai_socktype = SOCK_STREAM;
348 ai.ai_flags = AI_CANONNAME;
350 if (getnameinfo((struct sockaddr *)ads,
351 sizeof(struct sockaddr_in),
352 name, name_len, NULL, 0, 0))
358 if (getaddrinfo(name, NULL, &ai, &result))
362 while (addr4.sin_family == AF_UNSPEC && res) {
363 switch (res->ai_family) {
365 addr4.sin_addr = ((struct sockaddr_in *)res->ai_addr)->sin_addr;
366 addr4.sin_family = AF_INET;
372 freeaddrinfo(result);
375 if (addr4.sin_family == AF_UNSPEC)
378 lws_plat_inet_ntop(AF_INET, &addr4.sin_addr, rip, rip_len);
394 * lws_get_peer_addresses() - Get client address information
395 * @context: Libwebsockets context
396 * @wsi: Local struct lws associated with
397 * @fd: Connection socket descriptor
398 * @name: Buffer to take client address name
399 * @name_len: Length of client address name buffer
400 * @rip: Buffer to take client address IP dotted quad
401 * @rip_len: Length of client address IP buffer
403 * This function fills in @name and @rip with the name and IP of
404 * the client connected with socket descriptor @fd. Names may be
405 * truncated if there is not enough room. If either cannot be
406 * determined, they will be returned as valid zero-length strings.
410 lws_get_peer_addresses(struct lws_context *context, struct lws *wsi,
411 lws_sockfd_type fd, char *name, int name_len,
412 char *rip, int rip_len)
417 struct sockaddr_in6 sin6;
419 struct sockaddr_in sin4;
426 lws_latency_pre(context, wsi);
429 if (LWS_IPV6_ENABLED(context)) {
439 if (getpeername(fd, p, &len) < 0) {
440 lwsl_warn("getpeername: %s\n", strerror(LWS_ERRNO));
444 ret = lws_get_addresses(context, p, name, name_len, rip, rip_len);
447 lws_latency(context, wsi, "lws_get_peer_addresses", ret, 1);
460 * lws_context_user() - get the user data associated with the context
461 * @context: Websocket context
463 * This returns the optional user allocation that can be attached to
464 * the context the sockets live in at context_create time. It's a way
465 * to let all sockets serviced in the same context share data without
466 * using globals statics in the user code.
469 lws_context_user(struct lws_context *context)
471 return context->user_space;
476 * lws_callback_all_protocol() - Callback all connections using
477 * the given protocol with the given reason
479 * @protocol: Protocol whose connections will get callbacks
480 * @reason: Callback reason index
484 lws_callback_all_protocol(const struct lws_protocols *protocol, int reason)
486 struct lws_context *context = protocol->owning_server;
490 for (n = 0; n < context->fds_count; n++) {
491 wsi = wsi_from_fd(context, context->fds[n].fd);
494 if (wsi->protocol == protocol)
495 protocol->callback(context, wsi,
496 reason, wsi->user_space, NULL, 0);
503 * lws_set_timeout() - marks the wsi as subject to a timeout
505 * You will not need this unless you are doing something special
507 * @wsi: Websocket connection instance
508 * @reason: timeout reason
509 * @secs: how many seconds
513 lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs)
519 wsi->pending_timeout_limit = now + secs;
520 wsi->pending_timeout = reason;
527 * lws_get_socket_fd() - returns the socket file descriptor
529 * You will not need this unless you are doing something special
531 * @wsi: Websocket connection instance
535 lws_get_socket_fd(struct lws *wsi)
544 lws_latency(struct lws_context *context, struct lws *wsi, const char *action,
545 int ret, int completed)
547 unsigned long long u;
550 u = time_in_microseconds();
553 wsi->latency_start = u;
554 if (!wsi->action_start)
555 wsi->action_start = u;
559 if (wsi->action_start == wsi->latency_start)
561 "Completion first try lat %lluus: %p: ret %d: %s\n",
562 u - wsi->latency_start,
563 (void *)wsi, ret, action);
566 "Completion %lluus: lat %lluus: %p: ret %d: %s\n",
567 u - wsi->action_start,
568 u - wsi->latency_start,
569 (void *)wsi, ret, action);
570 wsi->action_start = 0;
572 sprintf(buf, "lat %lluus: %p: ret %d: %s\n",
573 u - wsi->latency_start, (void *)wsi, ret, action);
575 if (u - wsi->latency_start > context->worst_latency) {
576 context->worst_latency = u - wsi->latency_start;
577 strcpy(context->worst_latency_info, buf);
579 lwsl_latency("%s", buf);
586 * lws_rx_flow_control() - Enable and disable socket servicing for
589 * If the output side of a server process becomes choked, this allows flow
590 * control for the input side.
592 * @wsi: Websocket connection instance to get callback for
593 * @enable: 0 = disable read servicing for this connection, 1 = enable
597 lws_rx_flow_control(struct lws *wsi, int enable)
599 if (enable == (wsi->rxflow_change_to & LWS_RXFLOW_ALLOW))
602 lwsl_info("%s: (0x%p, %d)\n", __func__, wsi, enable);
603 wsi->rxflow_change_to = LWS_RXFLOW_PENDING_CHANGE | !!enable;
609 * lws_rx_flow_allow_all_protocol() - Allow all connections with this protocol to receive
611 * When the user server code realizes it can accept more input, it can
612 * call this to have the RX flow restriction removed from all connections using
613 * the given protocol.
615 * @protocol: all connections using this protocol will be allowed to receive
619 lws_rx_flow_allow_all_protocol(const struct lws_protocols *protocol)
621 struct lws_context *context = protocol->owning_server;
625 for (n = 0; n < context->fds_count; n++) {
626 wsi = wsi_from_fd(context, context->fds[n].fd);
629 if (wsi->protocol == protocol)
630 lws_rx_flow_control(wsi, LWS_RXFLOW_ALLOW);
636 * lws_canonical_hostname() - returns this host's hostname
638 * This is typically used by client code to fill in the host parameter
639 * when making a client connection. You can only call it after the context
642 * @context: Websocket context
644 LWS_VISIBLE extern const char *
645 lws_canonical_hostname(struct lws_context *context)
647 return (const char *)context->canonical_hostname;
650 int user_callback_handle_rxflow(callback_function callback_function,
651 struct lws_context *context, struct lws *wsi,
652 enum lws_callback_reasons reason, void *user,
653 void *in, size_t len)
657 n = callback_function(context, wsi, reason, user, in, len);
659 n = _lws_rx_flow_control(wsi);
666 * lws_set_proxy() - Setups proxy to lws_context.
667 * @context: pointer to struct lws_context you want set proxy to
668 * @proxy: pointer to c string containing proxy in format address:port
670 * Returns 0 if proxy string was parsed and proxy was setup.
671 * Returns -1 if @proxy is NULL or has incorrect format.
673 * This is only required if your OS does not provide the http_proxy
674 * environment variable (eg, OSX)
676 * IMPORTANT! You should call this function right after creation of the
677 * lws_context and before call to connect. If you call this
678 * function after connect behavior is undefined.
679 * This function will override proxy settings made on lws_context
680 * creation with genenv() call.
684 lws_set_proxy(struct lws_context *context, const char *proxy)
692 p = strchr(proxy, '@');
693 if (p) { /* auth is around */
695 if ((unsigned int)(p - proxy) > sizeof(authstring) - 1)
698 strncpy(authstring, proxy, p - proxy);
699 // null termination not needed on input
700 if (lws_b64_encode_string(authstring, (p - proxy),
701 context->proxy_basic_auth_token,
702 sizeof context->proxy_basic_auth_token) < 0)
705 lwsl_notice(" Proxy auth in use\n");
709 context->proxy_basic_auth_token[0] = '\0';
711 strncpy(context->http_proxy_address, proxy,
712 sizeof(context->http_proxy_address) - 1);
713 context->http_proxy_address[
714 sizeof(context->http_proxy_address) - 1] = '\0';
716 p = strchr(context->http_proxy_address, ':');
717 if (!p && !context->http_proxy_port) {
718 lwsl_err("http_proxy needs to be ads:port\n");
724 context->http_proxy_port = atoi(p + 1);
728 lwsl_notice(" Proxy %s:%u\n", context->http_proxy_address,
729 context->http_proxy_port);
734 lwsl_err("proxy auth too long\n");
740 * lws_get_protocol() - Returns a protocol pointer from a websocket
742 * @wsi: pointer to struct websocket you want to know the protocol of
745 * Some apis can act on all live connections of a given protocol,
746 * this is how you can get a pointer to the active protocol if needed.
749 LWS_VISIBLE const struct lws_protocols *
750 lws_get_protocol(struct lws *wsi)
752 return wsi->protocol;
756 lws_is_final_fragment(struct lws *wsi)
758 return wsi->u.ws.final;
761 LWS_VISIBLE unsigned char
762 lws_get_reserved_bits(struct lws *wsi)
764 return wsi->u.ws.rsv;
768 lws_ensure_user_space(struct lws *wsi)
770 lwsl_info("%s: %p protocol %p\n", __func__, wsi, wsi->protocol);
774 /* allocate the per-connection user memory (if any) */
776 if (wsi->protocol->per_session_data_size && !wsi->user_space) {
777 wsi->user_space = lws_zalloc(wsi->protocol->per_session_data_size);
778 if (wsi->user_space == NULL) {
779 lwsl_err("Out of memory for conn user space\n");
783 lwsl_info("%s: %p protocol pss %u, user_space=%d\n",
784 __func__, wsi, wsi->protocol->per_session_data_size,
790 LWS_VISIBLE void lwsl_emit_stderr(int level, const char *line)
792 unsigned long long now;
797 for (n = 0; n < LLL_COUNT; n++) {
798 if (level != (1 << n))
800 now = time_in_microseconds() / 100;
801 sprintf(buf, "[%llu:%04d] %s: ",
802 (unsigned long long) now / 10000,
803 (int)(now % 10000), log_level_names[n]);
807 fprintf(stderr, "%s%s", buf, line);
811 LWS_VISIBLE void _lws_logv(int filter, const char *format, va_list vl)
815 if (!(log_level & filter))
818 vsnprintf(buf, sizeof(buf), format, vl);
819 buf[sizeof(buf) - 1] = '\0';
821 lwsl_emit(filter, buf);
824 LWS_VISIBLE void _lws_log(int filter, const char *format, ...)
828 va_start(ap, format);
829 _lws_logv(filter, format, ap);
834 * lws_set_log_level() - Set the logging bitfield
835 * @level: OR together the LLL_ debug contexts you want output from
836 * @log_emit_function: NULL to leave it as it is, or a user-supplied
837 * function to perform log string emission instead of
838 * the default stderr one.
840 * log level defaults to "err", "warn" and "notice" contexts enabled and
841 * emission on stderr.
844 LWS_VISIBLE void lws_set_log_level(int level,
845 void (*func)(int level, const char *line))
853 * lws_use_ssl() - Find out if connection is using SSL
854 * @wsi: websocket connection to check
856 * Returns 0 if the connection is not using SSL, 1 if using SSL and
857 * using verified cert, and 2 if using SSL but the cert was not
858 * checked (appears for client wsi told to skip check on connection)
861 lws_is_ssl(struct lws *wsi)
863 #ifdef LWS_OPENSSL_SUPPORT
872 * lws_partial_buffered() - find out if lws buffered the last write
873 * @wsi: websocket connection to check
875 * Returns 1 if you cannot use lws_write because the last
876 * write on this connection is still buffered, and can't be cleared without
877 * returning to the service loop and waiting for the connection to be
880 * If you will try to do >1 lws_write call inside a single
881 * WRITEABLE callback, you must check this after every write and bail if
882 * set, ask for a new writeable callback and continue writing from there.
884 * This is never set at the start of a writeable callback, but any write
889 lws_partial_buffered(struct lws *wsi)
891 return !!wsi->truncated_send_len;
894 void lws_set_protocol_write_pending(struct lws_context *context,
896 enum lws_pending_protocol_send pend)
898 lwsl_info("setting pps %d\n", pend);
901 lwsl_err("pps overwrite\n");
903 lws_rx_flow_control(wsi, 0);
904 lws_callback_on_writable(context, wsi);
908 lws_get_peer_write_allowance(struct lws *wsi)
911 /* only if we are using HTTP2 on this connection */
912 if (wsi->mode != LWS_CONNMODE_HTTP2_SERVING)
914 /* user is only interested in how much he can send, or that he can't */
915 if (wsi->u.http2.tx_credit <= 0)
918 return wsi->u.http2.tx_credit;
926 lws_union_transition(struct lws *wsi, enum connection_mode mode)
928 memset(&wsi->u, 0, sizeof(wsi->u));
932 LWS_VISIBLE struct lws_plat_file_ops *
933 lws_get_fops(struct lws_context *context)
935 return &context->fops;
938 #ifdef LWS_WITH_OLD_API_WRAPPERS
941 * To maintain .so abi, also produce wrappers using old api naming.
943 * This is disabled by default, use "LWS_WITH_OLD_API_WRAPPERS" on cmake to
946 * You only need these if you have existing binary applications using the old
947 * api names and you don't want to / can't recompile them against new lws.
948 * With these new lws .so is compatible with old and new api names.
950 * If you can recompile your application (using old api names still) against
951 * current lws, you don't need these compatibility helpers since
952 * libwebsockets.h will map them at compile time.
957 #undef libwebsocket_create_context
958 LWS_VISIBLE LWS_EXTERN struct lws_context *
959 libwebsocket_create_context(struct lws_context_creation_info *info)
961 return lws_create_context(info);
964 #undef libwebsocket_set_proxy
965 LWS_VISIBLE LWS_EXTERN int
966 libwebsocket_set_proxy(struct lws_context *context, const char *proxy)
968 return lws_set_proxy(context, proxy);
971 #undef libwebsocket_context_destroy
972 LWS_VISIBLE LWS_EXTERN void
973 libwebsocket_context_destroy(struct lws_context *context)
975 lws_context_destroy(context);
978 #undef libwebsocket_service
979 LWS_VISIBLE LWS_EXTERN int
980 libwebsocket_service(struct lws_context *context, int timeout_ms)
982 return lws_service(context, timeout_ms);
985 #undef libwebsocket_cancel_service
986 LWS_VISIBLE LWS_EXTERN void
987 libwebsocket_cancel_service(struct lws_context *context)
989 lws_cancel_service(context);
993 #undef libwebsocket_sigint_cfg
994 LWS_VISIBLE LWS_EXTERN int
995 libwebsocket_sigint_cfg(struct lws_context *context, int use_ev_sigint,
996 lws_ev_signal_cb* cb)
998 return lws_sigint_cfg(context, use_ev_sigint, cb);
1001 #undef libwebsocket_initloop
1002 LWS_VISIBLE LWS_EXTERN int
1003 libwebsocket_initloop(struct lws_context *context, struct ev_loop *loop)
1005 return lws_initloop(context, loop);
1008 #undef libwebsocket_sigint_cb
1010 libwebsocket_sigint_cb(
1011 struct ev_loop *loop, struct ev_signal *watcher, int revents)
1013 lws_sigint_cb(loop, watcher, revents);
1015 #endif /* LWS_USE_LIBEV */
1017 #undef libwebsocket_service_fd
1018 LWS_VISIBLE LWS_EXTERN int
1019 libwebsocket_service_fd(struct lws_context *context,
1020 struct lws_pollfd *pollfd)
1022 return lws_service_fd(context, pollfd);
1025 #undef libwebsocket_context_user
1026 LWS_VISIBLE LWS_EXTERN void *
1027 libwebsocket_context_user(struct lws_context *context)
1029 return lws_context_user(context);
1032 #undef libwebsocket_set_timeout
1033 LWS_VISIBLE LWS_EXTERN void
1034 libwebsocket_set_timeout(struct lws *wsi,
1035 enum pending_timeout reason, int secs)
1037 lws_set_timeout(wsi, reason, secs);
1040 #undef libwebsocket_write
1041 LWS_VISIBLE LWS_EXTERN int
1042 libwebsocket_write(struct lws *wsi, unsigned char *buf, size_t len,
1043 enum lws_write_protocol protocol)
1045 return lws_write(wsi, buf, len, protocol);
1048 #undef libwebsockets_serve_http_file_fragment
1049 LWS_VISIBLE LWS_EXTERN int
1050 libwebsockets_serve_http_file_fragment(struct lws_context *context,
1053 return lws_serve_http_file_fragment(context, wsi);
1056 #undef libwebsockets_serve_http_file
1057 LWS_VISIBLE LWS_EXTERN int
1058 libwebsockets_serve_http_file(struct lws_context *context,
1059 struct lws *wsi, const char *file,
1060 const char *content_type, const char *other_headers,
1061 int other_headers_len)
1063 return lws_serve_http_file(context, wsi, file, content_type,
1064 other_headers, other_headers_len);
1067 #undef libwebsockets_return_http_status
1068 LWS_VISIBLE LWS_EXTERN int
1069 libwebsockets_return_http_status(
1070 struct lws_context *context,
1071 struct lws *wsi, unsigned int code,
1072 const char *html_body)
1074 return lws_return_http_status(context, wsi, code, html_body);
1077 #undef libwebsockets_get_protocol
1078 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
1079 libwebsockets_get_protocol(struct lws *wsi)
1081 return lws_get_protocol(wsi);
1084 #undef libwebsocket_callback_on_writable_all_protocol
1085 LWS_VISIBLE LWS_EXTERN int
1086 libwebsocket_callback_on_writable_all_protocol(
1087 const struct lws_protocols *protocol)
1089 return lws_callback_on_writable_all_protocol(protocol);
1092 #undef libwebsocket_callback_on_writable
1093 LWS_VISIBLE LWS_EXTERN int
1094 libwebsocket_callback_on_writable(struct lws_context *context,
1097 return lws_callback_on_writable(context, wsi);
1100 #undef libwebsocket_callback_all_protocol
1101 LWS_VISIBLE LWS_EXTERN int
1102 libwebsocket_callback_all_protocol(
1103 const struct lws_protocols *protocol, int reason)
1105 return lws_callback_all_protocol(protocol, reason);
1108 #undef libwebsocket_get_socket_fd
1109 LWS_VISIBLE LWS_EXTERN int
1110 libwebsocket_get_socket_fd(struct lws *wsi)
1112 return lws_get_socket_fd(wsi);
1115 #undef libwebsocket_is_final_fragment
1116 LWS_VISIBLE LWS_EXTERN int
1117 libwebsocket_is_final_fragment(struct lws *wsi)
1119 return lws_is_final_fragment(wsi);
1122 #undef libwebsocket_get_reserved_bits
1123 LWS_VISIBLE LWS_EXTERN unsigned char
1124 libwebsocket_get_reserved_bits(struct lws *wsi)
1126 return lws_get_reserved_bits(wsi);
1129 #undef libwebsocket_rx_flow_control
1130 LWS_VISIBLE LWS_EXTERN int
1131 libwebsocket_rx_flow_control(struct lws *wsi, int enable)
1133 return lws_rx_flow_control(wsi, enable);
1136 #undef libwebsocket_rx_flow_allow_all_protocol
1137 LWS_VISIBLE LWS_EXTERN void
1138 libwebsocket_rx_flow_allow_all_protocol(const struct lws_protocols *protocol)
1140 lws_rx_flow_allow_all_protocol(protocol);
1143 #undef libwebsockets_remaining_packet_payload
1144 LWS_VISIBLE LWS_EXTERN size_t
1145 libwebsockets_remaining_packet_payload(struct lws *wsi)
1147 return lws_remaining_packet_payload(wsi);
1150 #undef libwebsocket_client_connect
1151 LWS_VISIBLE LWS_EXTERN struct lws *
1152 libwebsocket_client_connect(struct lws_context *clients,
1153 const char *address,
1159 const char *protocol,
1160 int ietf_version_or_minus_one)
1162 return lws_client_connect(clients, address, port, ssl_connection,
1163 path, host, origin, protocol, ietf_version_or_minus_one);
1165 LWS_VISIBLE LWS_EXTERN struct lws *
1166 libwebsocket_client_connect_extended(struct lws_context *clients,
1167 const char *address,
1173 const char *protocol,
1174 int ietf_version_or_minus_one, void *userdata)
1176 return lws_client_connect_extended(clients, address, port, ssl_connection,
1177 path, host, origin, protocol, ietf_version_or_minus_one,
1181 #undef libwebsocket_canonical_hostname
1182 LWS_VISIBLE LWS_EXTERN const char *
1183 libwebsocket_canonical_hostname(struct lws_context *context)
1185 return lws_canonical_hostname(context);
1188 #undef libwebsockets_get_peer_addresses
1189 LWS_VISIBLE LWS_EXTERN void
1190 libwebsockets_get_peer_addresses(struct lws_context *context,
1191 struct lws *wsi, lws_sockfd_type fd, char *name,
1192 int name_len, char *rip, int rip_len)
1194 lws_get_peer_addresses(context, wsi, fd, name, name_len, rip, rip_len);
1197 #undef libwebsockets_get_random
1198 LWS_VISIBLE LWS_EXTERN int
1199 libwebsockets_get_random(struct lws_context *context, void *buf, int len)
1201 return lws_get_random(context, buf, len);
1204 #ifndef LWS_SHA1_USE_OPENSSL_NAME
1205 #undef libwebsockets_SHA1
1206 LWS_VISIBLE LWS_EXTERN unsigned char *
1207 libwebsockets_SHA1(const unsigned char *d, size_t n, unsigned char *md)
1209 return lws_SHA1(d, n, md);
1213 #undef libwebsocket_read
1214 LWS_VISIBLE LWS_EXTERN int
1215 libwebsocket_read(struct lws_context *context, struct lws *wsi,
1216 unsigned char *buf, size_t len)
1218 return lws_read(context, wsi, buf, len);
1221 #ifndef LWS_NO_EXTENSIONS
1222 #undef libwebsocket_get_internal_extensions
1223 LWS_VISIBLE LWS_EXTERN struct lws_extension *
1224 libwebsocket_get_internal_extensions()
1226 return lws_get_internal_extensions();