aboutsummaryrefslogtreecommitdiff
path: root/tests/ws.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-01-04 20:11:38 -0800
committerGarrett D'Amore <garrett@damore.org>2018-01-05 11:20:50 -0800
commit224dae56a379aa309fca261d61e7e356b14a536f (patch)
tree8194d33029d3595457d424a0f2f57fe2d2139199 /tests/ws.c
parent2ea7ae1ae5755ab72833fdea0dcf8e13e4d91d0d (diff)
downloadnng-224dae56a379aa309fca261d61e7e356b14a536f.tar.gz
nng-224dae56a379aa309fca261d61e7e356b14a536f.tar.bz2
nng-224dae56a379aa309fca261d61e7e356b14a536f.zip
Fix some more leaks, add a generic URL parser.
Diffstat (limited to 'tests/ws.c')
-rw-r--r--tests/ws.c101
1 files changed, 45 insertions, 56 deletions
diff --git a/tests/ws.c b/tests/ws.c
index aa2ba56e..386c0690 100644
--- a/tests/ws.c
+++ b/tests/ws.c
@@ -24,65 +24,54 @@
static int
check_props_v4(nng_msg *msg, nng_listener l, nng_dialer d)
{
- nng_pipe p;
- size_t z;
+ nng_pipe p;
+ size_t z;
+ nng_sockaddr la;
+ nng_sockaddr ra;
+ char * buf;
+ size_t len;
+
p = nng_msg_get_pipe(msg);
So(p > 0);
- Convey("Local address property works", {
- nng_sockaddr la;
- z = sizeof(nng_sockaddr);
- So(nng_pipe_getopt(p, NNG_OPT_LOCADDR, &la, &z) == 0);
- So(z == sizeof(la));
- So(la.s_un.s_family == NNG_AF_INET);
- So(la.s_un.s_in.sa_port == htons(trantest_port - 1));
- So(la.s_un.s_in.sa_port != 0);
- So(la.s_un.s_in.sa_addr == htonl(0x7f000001));
- });
-
- Convey("Remote address property works", {
- nng_sockaddr ra;
- z = sizeof(nng_sockaddr);
- So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == 0);
- So(z == sizeof(ra));
- So(ra.s_un.s_family == NNG_AF_INET);
- So(ra.s_un.s_in.sa_port != 0);
- So(ra.s_un.s_in.sa_addr == htonl(0x7f000001));
- });
-
- Convey("Request header property works", {
- char * buf;
- size_t len;
- z = 0;
- buf = NULL;
- So(nng_pipe_getopt(p, NNG_OPT_WS_REQUEST_HEADERS, buf, &z) ==
- 0);
- So(z > 0);
- len = z;
- So((buf = nni_alloc(len)) != NULL);
- So(nng_pipe_getopt(p, NNG_OPT_WS_REQUEST_HEADERS, buf, &z) ==
- 0);
- So(strstr(buf, "Sec-WebSocket-Key") != NULL);
- So(z == len);
- nni_free(buf, len);
- });
-
- Convey("Response header property works", {
- char * buf;
- size_t len;
- z = 0;
- buf = NULL;
- So(nng_pipe_getopt(p, NNG_OPT_WS_RESPONSE_HEADERS, buf, &z) ==
- 0);
- So(z > 0);
- len = z;
- So((buf = nni_alloc(len)) != NULL);
- So(nng_pipe_getopt(p, NNG_OPT_WS_RESPONSE_HEADERS, buf, &z) ==
- 0);
- So(strstr(buf, "Sec-WebSocket-Accept") != NULL);
- So(z == len);
- nni_free(buf, len);
- });
+ z = sizeof(nng_sockaddr);
+ So(nng_pipe_getopt(p, NNG_OPT_LOCADDR, &la, &z) == 0);
+ So(z == sizeof(la));
+ So(la.s_un.s_family == NNG_AF_INET);
+ So(la.s_un.s_in.sa_port == htons(trantest_port - 1));
+ So(la.s_un.s_in.sa_port != 0);
+ So(la.s_un.s_in.sa_addr == htonl(0x7f000001));
+
+ z = sizeof(nng_sockaddr);
+ So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == 0);
+ So(z == sizeof(ra));
+ So(ra.s_un.s_family == NNG_AF_INET);
+ So(ra.s_un.s_in.sa_port != 0);
+ So(ra.s_un.s_in.sa_addr == htonl(0x7f000001));
+
+ // Request Header
+ z = 0;
+ buf = NULL;
+ So(nng_pipe_getopt(p, NNG_OPT_WS_REQUEST_HEADERS, buf, &z) == 0);
+ So(z > 0);
+ len = z;
+ So((buf = nni_alloc(len)) != NULL);
+ So(nng_pipe_getopt(p, NNG_OPT_WS_REQUEST_HEADERS, buf, &z) == 0);
+ So(strstr(buf, "Sec-WebSocket-Key") != NULL);
+ So(z == len);
+ nni_free(buf, len);
+
+ // Response Header
+ z = 0;
+ buf = NULL;
+ So(nng_pipe_getopt(p, NNG_OPT_WS_RESPONSE_HEADERS, buf, &z) == 0);
+ So(z > 0);
+ len = z;
+ So((buf = nni_alloc(len)) != NULL);
+ So(nng_pipe_getopt(p, NNG_OPT_WS_RESPONSE_HEADERS, buf, &z) == 0);
+ So(strstr(buf, "Sec-WebSocket-Accept") != NULL);
+ So(z == len);
+ nni_free(buf, len);
return (0);
}