diff --git a/CMakeLists.txt b/CMakeLists.txt index 5494a5e6..7edbc1e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,7 @@ option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" ON) option(LWS_IPV6 "Compile with support for ipv6" OFF) option(LWS_WITH_HTTP2 "Compile with support for http2" OFF) option(LWS_MBED3 "Platform is MBED3" OFF) +option(LWS_WITH_OLD_API_WRAPPERS "Compile with binary compatibility with pre-v1.6 apis" OFF) if (DEFINED YOTTA_WEBSOCKETS_VERSION_STRING) @@ -1088,6 +1089,7 @@ message(" LWS_USE_LIBEV = ${LWS_USE_LIBEV}") message(" LWS_IPV6 = ${LWS_IPV6}") message(" LWS_WITH_HTTP2 = ${LWS_WITH_HTTP2}") message(" LWS_MBED3 = ${LWS_MBED3}") +message(" LWS_WITH_OLD_API_WRAPPERS = ${LWS_WITH_OLD_API_WRAPPERS}") message("---------------------------------------------------------------------") # These will be available to parent projects including libwebsockets using add_subdirectory() diff --git a/changelog b/changelog index eb41a60d..583f8dd1 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,27 @@ Changelog --------- +User api changes +---------------- + +Several older apis start with libwebsocket_ or libwebsockets_ while newer ones +all begin lws_. These apis have been changed to all begin with lws_. + +However compatibility defines have been added in libwebsockets.h, so it is +perfectly build-compatible with older sources using the old api names. + +If you are using lws with a distro, or otherwise can't rebuild the user code, +you should add + + -DLWS_WITH_OLD_API_WRAPPERS=1 + +to your cmake args. This builds lws with all the old apis as wrappers around +the new apis, so the library still exports the old apis. + +In this way you can have lws export both the new and old apis simultaneously +for compatibility. + + v1.5-chrome47-firefox41 ======================= diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index a4fb792b..fa1fc435 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -940,3 +940,299 @@ lws_union_transition(struct libwebsocket *wsi, enum connection_mode mode) memset(&wsi->u, 0, sizeof(wsi->u)); wsi->mode = mode; } + + +#ifdef LWS_WITH_OLD_API_WRAPPERS + +/* + * To maintain .so abi, also produce wrappers using old api naming. + * + * This is disabled by default, use "LWS_WITH_OLD_API_WRAPPERS" on cmake to + * enable. + * + * You only need these if you have existing binary applications using the old + * api names and you don't want to / can't recompile them against new lws. + * With these new lws .so is compatible with old and new api names. + * + * If you can recompile your application (using old api names still) against + * current lws, you don't need these compatibility helpers since + * libwebsockets.h will map them at compile time. + */ + +#undef libwebsocket_create_context +LWS_VISIBLE LWS_EXTERN struct libwebsocket_context * +libwebsocket_create_context(struct lws_context_creation_info *info) +{ + return lws_create_context(info); +} + +#undef libwebsocket_set_proxy +LWS_VISIBLE LWS_EXTERN int +libwebsocket_set_proxy(struct libwebsocket_context *context, const char *proxy) +{ + return lws_set_proxy(context, proxy); +} + +#undef libwebsocket_context_destroy +LWS_VISIBLE LWS_EXTERN void +libwebsocket_context_destroy(struct libwebsocket_context *context) +{ + lws_context_destroy(context); +} + +#undef libwebsocket_service +LWS_VISIBLE LWS_EXTERN int +libwebsocket_service(struct libwebsocket_context *context, int timeout_ms) +{ + return lws_service(context, timeout_ms); +} + +#undef libwebsocket_cancel_service +LWS_VISIBLE LWS_EXTERN void +libwebsocket_cancel_service(struct libwebsocket_context *context) +{ + lws_cancel_service(context); +} + +#ifdef LWS_USE_LIBEV +#undef libwebsocket_sigint_cfg +LWS_VISIBLE LWS_EXTERN int +libwebsocket_sigint_cfg( + struct libwebsocket_context *context, + int use_ev_sigint, + lws_ev_signal_cb* cb) +{ + return lws_sigint_cfg(context, use_ev_sigint, cb); +} + +#undef libwebsocket_initloop +LWS_VISIBLE LWS_EXTERN int +libwebsocket_initloop(struct libwebsocket_context *context, struct ev_loop *loop) +{ + return lws_initloop(context, loop); +} + +#undef libwebsocket_sigint_cb +LWS_VISIBLE void +libwebsocket_sigint_cb( + struct ev_loop *loop, struct ev_signal *watcher, int revents) +{ + lws_sigint_cb(loop, watcher, revents); +} +#endif /* LWS_USE_LIBEV */ + +#undef libwebsocket_service_fd +LWS_VISIBLE LWS_EXTERN int +libwebsocket_service_fd(struct libwebsocket_context *context, + struct libwebsocket_pollfd *pollfd) +{ + return lws_service_fd(context, pollfd); +} + +#undef libwebsocket_context_user +LWS_VISIBLE LWS_EXTERN void * +libwebsocket_context_user(struct libwebsocket_context *context) +{ + return lws_context_user(context); +} + +#undef libwebsocket_set_timeout +LWS_VISIBLE LWS_EXTERN void +libwebsocket_set_timeout(struct libwebsocket *wsi, + enum pending_timeout reason, int secs) +{ + lws_set_timeout(wsi, reason, secs); +} + +#undef libwebsocket_write +LWS_VISIBLE LWS_EXTERN int +libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf, size_t len, + enum lws_write_protocol protocol) +{ + return lws_write(wsi, buf, len, protocol); +} + +#undef libwebsockets_serve_http_file_fragment +LWS_VISIBLE LWS_EXTERN int +libwebsockets_serve_http_file_fragment(struct libwebsocket_context *context, + struct libwebsocket *wsi) +{ + return lws_serve_http_file_fragment(context, wsi); +} + +#undef libwebsockets_serve_http_file +LWS_VISIBLE LWS_EXTERN int +libwebsockets_serve_http_file(struct libwebsocket_context *context, + struct libwebsocket *wsi, const char *file, + const char *content_type, const char *other_headers, + int other_headers_len) +{ + return lws_serve_http_file(context, wsi, file, content_type, + other_headers, other_headers_len); +} + +#undef libwebsockets_return_http_status +LWS_VISIBLE LWS_EXTERN int +libwebsockets_return_http_status( + struct libwebsocket_context *context, + struct libwebsocket *wsi, unsigned int code, + const char *html_body) +{ + return lws_return_http_status(context, wsi, code, html_body); +} + +#undef libwebsockets_get_protocol +LWS_VISIBLE LWS_EXTERN const struct libwebsocket_protocols * +libwebsockets_get_protocol(struct libwebsocket *wsi) +{ + return lws_get_protocol(wsi); +} + +#undef libwebsocket_callback_on_writable_all_protocol +LWS_VISIBLE LWS_EXTERN int +libwebsocket_callback_on_writable_all_protocol( + const struct libwebsocket_protocols *protocol) +{ + return lws_callback_on_writable_all_protocol(protocol); +} + +#undef libwebsocket_callback_on_writable +LWS_VISIBLE LWS_EXTERN int +libwebsocket_callback_on_writable(struct libwebsocket_context *context, + struct libwebsocket *wsi) +{ + return lws_callback_on_writable(context, wsi); +} + +#undef libwebsocket_callback_all_protocol +LWS_VISIBLE LWS_EXTERN int +libwebsocket_callback_all_protocol( + const struct libwebsocket_protocols *protocol, int reason) +{ + return lws_callback_all_protocol(protocol, reason); +} + +#undef libwebsocket_get_socket_fd +LWS_VISIBLE LWS_EXTERN int +libwebsocket_get_socket_fd(struct libwebsocket *wsi) +{ + return lws_get_socket_fd(wsi); +} + +#undef libwebsocket_is_final_fragment +LWS_VISIBLE LWS_EXTERN int +libwebsocket_is_final_fragment(struct libwebsocket *wsi) +{ + return lws_is_final_fragment(wsi); +} + +#undef libwebsocket_get_reserved_bits +LWS_VISIBLE LWS_EXTERN unsigned char +libwebsocket_get_reserved_bits(struct libwebsocket *wsi) +{ + return lws_get_reserved_bits(wsi); +} + +#undef libwebsocket_rx_flow_control +LWS_VISIBLE LWS_EXTERN int +libwebsocket_rx_flow_control(struct libwebsocket *wsi, int enable) +{ + return lws_rx_flow_control(wsi, enable); +} + +#undef libwebsocket_rx_flow_allow_all_protocol +LWS_VISIBLE LWS_EXTERN void +libwebsocket_rx_flow_allow_all_protocol(const struct libwebsocket_protocols *protocol) +{ + lws_rx_flow_allow_all_protocol(protocol); +} + +#undef libwebsockets_remaining_packet_payload +LWS_VISIBLE LWS_EXTERN size_t +libwebsockets_remaining_packet_payload(struct libwebsocket *wsi) +{ + return lws_remaining_packet_payload(wsi); +} + +#undef libwebsocket_client_connect +LWS_VISIBLE LWS_EXTERN struct libwebsocket * +libwebsocket_client_connect(struct libwebsocket_context *clients, + const char *address, + int port, + int ssl_connection, + const char *path, + const char *host, + const char *origin, + const char *protocol, + int ietf_version_or_minus_one) +{ + return lws_client_connect(clients, address, port, ssl_connection, + path, host, origin, protocol, ietf_version_or_minus_one); +} +LWS_VISIBLE LWS_EXTERN struct libwebsocket * +libwebsocket_client_connect_extended(struct libwebsocket_context *clients, + const char *address, + int port, + int ssl_connection, + const char *path, + const char *host, + const char *origin, + const char *protocol, + int ietf_version_or_minus_one, void *userdata) +{ + return lws_client_connect_extended(clients, address, port, ssl_connection, + path, host, origin, protocol, ietf_version_or_minus_one, + userdata); +} + +#undef libwebsocket_canonical_hostname +LWS_VISIBLE LWS_EXTERN const char * +libwebsocket_canonical_hostname(struct libwebsocket_context *context) +{ + return lws_canonical_hostname(context); +} + +#undef libwebsockets_get_peer_addresses +LWS_VISIBLE LWS_EXTERN void +libwebsockets_get_peer_addresses(struct libwebsocket_context *context, + struct libwebsocket *wsi, lws_sockfd_type fd, char *name, + int name_len, char *rip, int rip_len) +{ + lws_get_peer_addresses(context, wsi, fd, name, name_len, rip, rip_len); +} + +#undef libwebsockets_get_random +LWS_VISIBLE LWS_EXTERN int +libwebsockets_get_random(struct libwebsocket_context *context, void *buf, int len) +{ + return lws_get_random(context, buf, len); +} + +#ifndef LWS_SHA1_USE_OPENSSL_NAME +#undef libwebsockets_SHA1 +LWS_VISIBLE LWS_EXTERN unsigned char * +libwebsockets_SHA1(const unsigned char *d, size_t n, unsigned char *md) +{ + return lws_SHA1(d, n, md); +} +#endif + +#undef libwebsocket_read +LWS_VISIBLE LWS_EXTERN int +libwebsocket_read(struct libwebsocket_context *context, struct libwebsocket *wsi, + unsigned char *buf, size_t len) +{ + return lws_read(context, wsi, buf, len); +} + +#ifndef LWS_NO_EXTENSIONS +#undef libwebsocket_get_internal_extensions +LWS_VISIBLE LWS_EXTERN struct libwebsocket_extension * +libwebsocket_get_internal_extensions() +{ + return lws_get_internal_extensions(); +} +#endif + +#endif + diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 812bcd38..96978808 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -1325,7 +1325,7 @@ lws_sigint_cb( LWS_VISIBLE LWS_EXTERN int lws_service_fd(struct libwebsocket_context *context, - struct libwebsocket_pollfd *pollfd); + struct libwebsocket_pollfd *pollfd); LWS_VISIBLE LWS_EXTERN void * lws_context_user(struct libwebsocket_context *context); @@ -1510,12 +1510,12 @@ lws_canonical_hostname(struct libwebsocket_context *context); LWS_VISIBLE LWS_EXTERN void lws_get_peer_addresses(struct libwebsocket_context *context, - struct libwebsocket *wsi, lws_sockfd_type fd, char *name, int name_len, - char *rip, int rip_len); + struct libwebsocket *wsi, lws_sockfd_type fd, + char *name, int name_len, + char *rip, int rip_len); LWS_VISIBLE LWS_EXTERN int -lws_get_random(struct libwebsocket_context *context, - void *buf, int len); +lws_get_random(struct libwebsocket_context *context, void *buf, int len); LWS_VISIBLE LWS_EXTERN int lws_daemonize(const char *_lock_path); diff --git a/lws_config.h.in b/lws_config.h.in index 4c3c3b98..13622fbc 100644 --- a/lws_config.h.in +++ b/lws_config.h.in @@ -62,4 +62,7 @@ /* use SHA1() not internal libwebsockets_SHA1 */ #cmakedefine LWS_SHA1_USE_OPENSSL_NAME +/* whether to provide pre v1.6 compatibility wrappers */ +#cmakedefine LWS_WITH_OLD_API_WRAPPERS + ${LWS_SIZEOFPTR_CODE}