From 05d17a7989acf846285dc7e46d554513bd215cc2 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Thu, 18 Jan 2018 16:45:33 +0800 Subject: [PATCH] Support ssl Signed-off-by: Jianhui Zhao --- src/main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index badeaf2..edaf44c 100755 --- a/src/main.c +++ b/src/main.c @@ -275,7 +275,7 @@ static void do_connect() uloop_timeout_cancel(&keepalive_timer); TRY: - gcl = uwsc_new(server_url); + gcl = uwsc_new_ssl(server_url, NULL, false); if (!gcl) { if (uloop_cancelled || !auto_reconnect) { uloop_end(); @@ -331,6 +331,7 @@ static void usage(const char *prog) " -a # Auto reconnect to the server\n" " -v # verbose\n" " -d # Adding a description to the device(Maximum 126 bytes)\n" + " -s # SSL on" , prog); exit(1); } @@ -343,8 +344,9 @@ int main(int argc, char **argv) const char *description = NULL; int port = 0; bool verbose = false; + bool ssl = false; - while ((opt = getopt(argc, argv, "i:h:p:I:avd:")) != -1) { + while ((opt = getopt(argc, argv, "i:h:p:I:avd:s")) != -1) { switch (opt) { case 'i': @@ -374,6 +376,9 @@ int main(int argc, char **argv) usage(argv[0]); } break; + case 's': + ssl = true; + break; default: /* '?' */ usage(argv[0]); } @@ -418,7 +423,7 @@ int main(int argc, char **argv) if (description) urlencode(buf, sizeof(buf), description, strlen(description)); - snprintf(server_url, sizeof(server_url), "ws://%s:%d/ws/device?did=%s&des=%s", host, port, did, buf); + snprintf(server_url, sizeof(server_url), "ws%s://%s:%d/ws/device?did=%s&des=%s", ssl ? "s" : "", host, port, did, buf); do_connect();