From de3e7c913dd4e5ad71f84d70846782b3d18ea9c5 Mon Sep 17 00:00:00 2001 From: Michael Haberler Date: Sun, 10 Aug 2014 02:37:43 +0200 Subject: [PATCH] ws/protocol name: make a zero-length protocol name match any requested proto if an empty string as protocol name in struct libwebsocket_protocols is specified, it will match any protocol the client requested. A later FILTER_PROTOCOL_CONNECTION callback can then be used to sort out details, like setting options in the user session structure based on the actual proto name. --- lib/server.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/server.c b/lib/server.c index 51537659e..09f35213c 100644 --- a/lib/server.c +++ b/lib/server.c @@ -395,6 +395,16 @@ int lws_handshake_server(struct libwebsocket_context *context, while (context->protocols[n].callback) { if (!wsi->protocol->name) continue; + /* a zero-length protocol name always matches + * later, a FILTER_PROTOCOL_CONNECTION callback + * can sort out what to with the offered names + */ + if (*(wsi->protocol->name) == 0) { + lwsl_info("protocol wildcard match %d\n", n); + wsi->protocol = &context->protocols[n]; + hit = 1; + break; + } if (!strcmp(context->protocols[n].name, protocol_name)) { lwsl_info("prot match %d\n", n);