From 224dae56a379aa309fca261d61e7e356b14a536f Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 4 Jan 2018 20:11:38 -0800 Subject: Fix some more leaks, add a generic URL parser. --- tests/ws.c | 101 +++++++++++++++++++++++++++---------------------------------- 1 file changed, 45 insertions(+), 56 deletions(-) (limited to 'tests/ws.c') 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); } -- cgit v1.2.3-70-g09d2