diff --git a/lib/client-handshake.c b/lib/client-handshake.c index 474ee2c8..76b2fbdd 100644 --- a/lib/client-handshake.c +++ b/lib/client-handshake.c @@ -545,8 +545,21 @@ lws_client_connect(struct lws_context *context, const char *address, const char *host, const char *origin, const char *protocol, int ietf_version_or_minus_one) { - return lws_client_connect_extended(context, address, port, ssl_connection, - path, host, origin, protocol, - ietf_version_or_minus_one, NULL); + struct lws_client_connect_info i; + + memset(&i, 0, sizeof(i)); + + i.context = context; + i.address = address; + i.port = port; + i.ssl_connection = ssl_connection; + i.path = path; + i.host = host; + i.origin = origin; + i.protocol = protocol; + i.ietf_version_or_minus_one = ietf_version_or_minus_one; + i.userdata = NULL; + + return lws_client_connect_via_info(&i); } diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 9b663527..47a034bf 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -122,6 +122,7 @@ struct sockaddr_in; #define LWS_INLINE __inline #define LWS_VISIBLE #define LWS_WARN_UNUSED_RESULT +#define LWS_WARN_DEPRECATED #ifdef LWS_DLL #ifdef LWS_INTERNAL @@ -154,9 +155,11 @@ struct sockaddr_in; #if defined(__GNUC__) #define LWS_VISIBLE __attribute__((visibility("default"))) #define LWS_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) +#define LWS_WARN_DEPRECATED __attribute__ ((deprecated)) #else #define LWS_VISIBLE #define LWS_WARN_UNUSED_RESULT +#define LWS_WARN_DEPRECATED #endif #if defined(__ANDROID__) @@ -1661,14 +1664,14 @@ LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT lws_client_connect(struct lws_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); + int ietf_version_or_minus_one) LWS_WARN_DEPRECATED; /* deprecated, use lws_client_connect_via_info() */ LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT lws_client_connect_extended(struct lws_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); + void *userdata) LWS_WARN_DEPRECATED; LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT lws_client_connect_via_info(struct lws_client_connect_info * ccinfo); @@ -1832,8 +1835,14 @@ LWS_VISIBLE LWS_EXTERN int lws_read(struct lws *wsi, unsigned char *buf, size_t len); #ifndef LWS_NO_EXTENSIONS -/* deprecated */ -#define lws_get_internal_extensions() NULL +/* Deprecated + * + * There is no longer a set internal extensions table. The table is provided + * by user code along with application-specific settings. See the test + * client and server for how to do. + */ +static LWS_INLINE LWS_WARN_DEPRECATED const struct lws_extension * +lws_get_internal_extensions() { return NULL; } LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi, void *ext_user, const struct lws_ext_options *opts, diff --git a/test-server/test-fraggle.c b/test-server/test-fraggle.c index 43c69e7b..7fe4bd96 100644 --- a/test-server/test-fraggle.c +++ b/test-server/test-fraggle.c @@ -134,7 +134,7 @@ callback_fraggle(struct lws *wsi, enum lws_callback_reasons reason, case FRAGSTATE_START_MESSAGE: lws_get_random(lws_get_context(wsi), &ran, sizeof(ran)); - psf->packets_left = (ran % 1024) + 1; + psf->packets_left = (ran & 1023) + 1; fprintf(stderr, "Spamming %d random fragments\n", psf->packets_left); psf->sum = 0; @@ -153,7 +153,7 @@ callback_fraggle(struct lws *wsi, enum lws_callback_reasons reason, */ lws_get_random(lws_get_context(wsi), &ran, sizeof(ran)); - chunk = (ran % 8000) + 1; + chunk = (ran & 511) + 1; psf->total_message += chunk; lws_get_random(lws_get_context(wsi), bp, chunk); @@ -239,6 +239,20 @@ static struct lws_protocols protocols[] = { } }; +static const struct lws_extension exts[] = { + { + "permessage-deflate", + lws_extension_callback_pm_deflate, + "permessage-deflate; client_no_context_takeover; client_max_window_bits" + }, + { + "deflate-frame", + lws_extension_callback_pm_deflate, + "deflate_frame" + }, + { NULL, NULL, NULL /* terminator */ } +}; + static struct option options[] = { { "help", no_argument, NULL, 'h' }, { "debug", required_argument, NULL, 'd' }, @@ -256,10 +270,10 @@ int main(int argc, char **argv) int use_ssl = 0; struct lws_context *context; int opts = 0; - char interface_name[128] = ""; + char interface_name[128] = "", ads_port[300]; const char *iface = NULL; struct lws *wsi; - const char *address; + const char *address = NULL; int server_port = port; struct lws_context_creation_info info; @@ -311,12 +325,13 @@ int main(int argc, char **argv) info.port = server_port; info.iface = iface; info.protocols = protocols; -#ifndef LWS_NO_EXTENSIONS - info.extensions = lws_get_internal_extensions(); -#endif + info.extensions = exts; + if (use_ssl) { - info.ssl_cert_filepath = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.pem"; - info.ssl_private_key_filepath = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.key.pem"; + info.ssl_cert_filepath = LOCAL_RESOURCE_PATH + "/libwebsockets-test-server.pem"; + info.ssl_private_key_filepath = LOCAL_RESOURCE_PATH + "/libwebsockets-test-server.key.pem"; } info.gid = -1; info.uid = -1; @@ -329,12 +344,23 @@ int main(int argc, char **argv) } if (client) { + struct lws_client_connect_info i; + address = argv[optind]; - fprintf(stderr, "Connecting to %s:%u\n", address, port); - wsi = lws_client_connect(context, address, - port, use_ssl, "/", address, - "origin", protocols[PROTOCOL_FRAGGLE].name, - -1); + sprintf(ads_port, "%s:%u", address, port & 65535); + memset(&i, 0, sizeof(i)); + i.context = context; + i.address = address; + i.port = port; + i.ssl_connection = use_ssl; + i.path = "/"; + i.host = ads_port; + i.origin = ads_port; + i.protocol = protocols[PROTOCOL_FRAGGLE].name; + i.client_exts = exts; + + lwsl_notice("Connecting to %s:%u\n", address, port); + wsi = lws_client_connect_via_info(&i); if (wsi == NULL) { fprintf(stderr, "Client connect to server failed\n"); goto bail; diff --git a/test-server/test-ping.c b/test-server/test-ping.c index 297dbb54..9a8a2773 100644 --- a/test-server/test-ping.c +++ b/test-server/test-ping.c @@ -298,6 +298,20 @@ static struct lws_protocols protocols[] = { } }; +static const struct lws_extension exts[] = { + { + "permessage-deflate", + lws_extension_callback_pm_deflate, + "permessage-deflate; client_no_context_takeover; client_max_window_bits" + }, + { + "deflate-frame", + lws_extension_callback_pm_deflate, + "deflate_frame" + }, + { NULL, NULL, NULL /* terminator */ } +}; + static struct option options[] = { { "help", no_argument, NULL, 'h' }, { "debug", required_argument, NULL, 'd' }, @@ -331,7 +345,7 @@ int main(int argc, char **argv) int port = 7681; int use_ssl = 0; struct lws_context *context; - char protocol_name[256]; + char protocol_name[256], ads_port[300]; char ip[30]; #ifndef _WIN32 struct sigaction sa; @@ -342,15 +356,13 @@ int main(int argc, char **argv) unsigned long l; int ietf_version = -1; struct lws_context_creation_info info; + struct lws_client_connect_info i; memset(&info, 0, sizeof info); if (argc < 2) goto usage; - address = argv[1]; - optind++; - while (n >= 0) { n = getopt_long(argc, argv, "v:kr:hmfts:n:i:p:d:", options, NULL); if (n < 0) @@ -425,9 +437,8 @@ int main(int argc, char **argv) info.port = CONTEXT_PORT_NO_LISTEN; info.protocols = protocols; -#ifndef LWS_NO_EXTENSIONS - info.extensions = lws_get_internal_extensions(); -#endif + info.extensions = exts; + info.gid = -1; info.uid = -1; @@ -439,14 +450,25 @@ int main(int argc, char **argv) /* create client websockets using dumb increment protocol */ + address = argv[optind]; + sprintf(ads_port, "%s:%u", address, port & 65535); + lwsl_notice("Connecting to %s...\n", ads_port); + memset(&i, 0, sizeof(i)); + i.context = context; + i.address = address; + i.port = port; + i.ssl_connection = use_ssl; + i.path = "/"; + i.host = ads_port; + i.origin = ads_port; + i.protocol = protocols[PROTOCOL_LWS_MIRROR].name; + i.client_exts = exts; + i.ietf_version_or_minus_one = ietf_version; + for (n = 0; n < clients; n++) { - ping_wsi[n] = lws_client_connect(context, address, - port, use_ssl, "/", address, - "origin", protocols[PROTOCOL_LWS_MIRROR].name, - ietf_version); + ping_wsi[n] = lws_client_connect_via_info(&i); if (ping_wsi[n] == NULL) { - fprintf(stderr, "client connection %d failed to " - "connect\n", n); + lwsl_err("client %d failed to connect\n", n); return 1; } } diff --git a/test-server/test-server-libev.c b/test-server/test-server-libev.c index 609d24aa..0af1d9b1 100644 --- a/test-server/test-server-libev.c +++ b/test-server/test-server-libev.c @@ -123,6 +123,19 @@ static struct lws_protocols protocols[] = { { NULL, NULL, 0, 0 } /* terminator */ }; +static const struct lws_extension exts[] = { + { + "permessage-deflate", + lws_extension_callback_pm_deflate, + "permessage-deflate; client_no_context_takeover; client_max_window_bits" + }, + { + "deflate-frame", + lws_extension_callback_pm_deflate, + "deflate_frame" + }, + { NULL, NULL, NULL /* terminator */ } +}; /* this shows how to override the lws file operations. You don't need * to do any of this unless you have a reason (eg, want to serve @@ -296,9 +309,7 @@ int main(int argc, char **argv) info.iface = iface; info.protocols = protocols; -#ifndef LWS_NO_EXTENSIONS - info.extensions = lws_get_internal_extensions(); -#endif + info.extensions = exts; info.ssl_cert_filepath = NULL; info.ssl_private_key_filepath = NULL; diff --git a/test-server/test-server-pthreads.c b/test-server/test-server-pthreads.c index 92497165..5793bee3 100644 --- a/test-server/test-server-pthreads.c +++ b/test-server/test-server-pthreads.c @@ -151,7 +151,7 @@ static const struct lws_extension exts[] = { { "permessage-deflate", lws_extension_callback_pm_deflate, - "permessage-deflate" + "permessage-deflate; client_no_context_takeover; client_max_window_bits" }, { "deflate-frame", @@ -305,9 +305,7 @@ int main(int argc, char **argv) info.iface = iface; info.protocols = protocols; -#ifndef LWS_NO_EXTENSIONS - info.extensions = lws_get_internal_extensions(); -#endif + info.extensions = exts; info.ssl_cert_filepath = NULL; info.ssl_private_key_filepath = NULL;