lws_parse_uri fix test client use and add more docs
authorAndy Green <andy.green@linaro.org>
Sat, 6 Feb 2016 23:28:21 +0000 (07:28 +0800)
committerAndy Green <andy.green@linaro.org>
Sat, 6 Feb 2016 23:28:21 +0000 (07:28 +0800)
https://github.com/warmcat/libwebsockets/issues/414

Signed-off-by: Andy Green <andy.green@linaro.org>
lib/libwebsockets.c
test-server/test-client.c

index 8ef3bad..7cdc333 100644 (file)
@@ -1184,8 +1184,9 @@ lws_check_utf8(unsigned char *state, unsigned char *buf, size_t len)
 }
 
 /**
- * lws_parse_uri:      cut up https:/xxx:yyy/zzz into pieces
+ * lws_parse_uri:      cut up prot:/ads:port/path into pieces
  *                     Notice it does so by dropping '\0' into input string
+ *                     and the leading / on the path is consequently lost
  *
  * @p:                 incoming uri string.. will get written to
  * @prot:              result pointer for protocol part (https://)
index 1222ccc..709f0b2 100644 (file)
@@ -274,7 +274,8 @@ int main(int argc, char **argv)
        struct lws_context_creation_info info;
        struct lws_client_connect_info i;
        struct lws_context *context;
-       const char *prot;
+       const char *prot, *p;
+       char path[300];
 
        memset(&info, 0, sizeof info);
 
@@ -323,12 +324,18 @@ int main(int argc, char **argv)
        memset(&i, 0, sizeof(i));
 
        i.port = port;
-       if (lws_parse_uri(argv[optind], &prot, &i.address, &i.port, &i.path))
+       if (lws_parse_uri(argv[optind], &prot, &i.address, &i.port, &p))
                goto usage;
 
-       if (!strcmp(prot, "http://") || !strcmp(prot, "ws://"))
+       /* add back the leading / on path */
+       path[0] = '/';
+       strncpy(path + 1, p, sizeof(path) - 2);
+       path[sizeof(path) - 1] = '\0';
+       i.path = path;
+
+       if (!strcmp(prot, "http") || !strcmp(prot, "ws"))
                use_ssl = 0;
-       if (!strcmp(prot, "https://") || !strcmp(prot, "wss://"))
+       if (!strcmp(prot, "https") || !strcmp(prot, "wss"))
                use_ssl = 1;
 
        /*