From bfc6fdad62218e33a95f347d83e0728be54fa46a Mon Sep 17 00:00:00 2001 From: Pasquale Boemio Date: Fri, 26 Apr 2013 21:52:54 +0200 Subject: [PATCH 1/3] added case path null --- easywsclient.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/easywsclient.cpp b/easywsclient.cpp index 31ac572..b3b7591 100644 --- a/easywsclient.cpp +++ b/easywsclient.cpp @@ -265,6 +265,8 @@ WebSocket::pointer WebSocket::from_url(std::string url) { else if (sscanf(url.c_str(), "ws://%[^/]/%s", host, path) == 2) { port = 80; } + else if (sscanf(url.c_str(), "ws://%[^:]:%d", host, &port) == 2) { + } else { fprintf(stderr, "ERROR: Could not parse WebSocket url: %s\n", url.c_str()); return NULL; From d6b8dc8c41c2fa7ff3dc7c9d07c49186b95c0788 Mon Sep 17 00:00:00 2001 From: Pasquale Boemio Date: Fri, 26 Apr 2013 22:20:48 +0200 Subject: [PATCH 2/3] added "no path in url" parser case --- easywsclient.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/easywsclient.cpp b/easywsclient.cpp index b3b7591..24a45e0 100644 --- a/easywsclient.cpp +++ b/easywsclient.cpp @@ -281,7 +281,12 @@ WebSocket::pointer WebSocket::from_url(std::string url) { char line[256]; int status; int i; - snprintf(line, 256, "GET /%s HTTP/1.1\r\n", path); ::send(sockfd, line, strlen(line), 0); + if(path) { + snprintf(line, 256, "GET /%s HTTP/1.1\r\n", path); ::send(sockfd, line, strlen(line), 0); + } + else { + snprintf(line, 256, "GET / HTTP/1.1\r\n", path); ::send(sockfd, line, strlen(line), 0); + } snprintf(line, 256, "Host: %s:%d\r\n", host, port); ::send(sockfd, line, strlen(line), 0); snprintf(line, 256, "Upgrade: websocket\r\n", host, port); ::send(sockfd, line, strlen(line), 0); snprintf(line, 256, "Connection: Upgrade\r\n", host, port); ::send(sockfd, line, strlen(line), 0); From 54cd4023cb9a55b11783f80dc9805e265fe498e8 Mon Sep 17 00:00:00 2001 From: Pasquale Boemio Date: Fri, 26 Apr 2013 22:27:52 +0200 Subject: [PATCH 3/3] unused decision! --- easywsclient.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/easywsclient.cpp b/easywsclient.cpp index 24a45e0..b3b7591 100644 --- a/easywsclient.cpp +++ b/easywsclient.cpp @@ -281,12 +281,7 @@ WebSocket::pointer WebSocket::from_url(std::string url) { char line[256]; int status; int i; - if(path) { - snprintf(line, 256, "GET /%s HTTP/1.1\r\n", path); ::send(sockfd, line, strlen(line), 0); - } - else { - snprintf(line, 256, "GET / HTTP/1.1\r\n", path); ::send(sockfd, line, strlen(line), 0); - } + snprintf(line, 256, "GET /%s HTTP/1.1\r\n", path); ::send(sockfd, line, strlen(line), 0); snprintf(line, 256, "Host: %s:%d\r\n", host, port); ::send(sockfd, line, strlen(line), 0); snprintf(line, 256, "Upgrade: websocket\r\n", host, port); ::send(sockfd, line, strlen(line), 0); snprintf(line, 256, "Connection: Upgrade\r\n", host, port); ::send(sockfd, line, strlen(line), 0);