aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-01-05 14:44:10 -0800
committerGarrett D'Amore <garrett@damore.org>2018-01-05 15:17:27 -0800
commit1b2f22fd68a2e50cabdfe2e036096cc9e7a05a1f (patch)
tree95fc90338cbe38a46e561511604cf8ed079934fd /src/core
parent224dae56a379aa309fca261d61e7e356b14a536f (diff)
downloadnng-1b2f22fd68a2e50cabdfe2e036096cc9e7a05a1f.tar.gz
nng-1b2f22fd68a2e50cabdfe2e036096cc9e7a05a1f.tar.bz2
nng-1b2f22fd68a2e50cabdfe2e036096cc9e7a05a1f.zip
Convert existing websocket and http code to use new URL framework.
This also fixes a use-after-free bug in the HTTP framework, where the handler could be deleted why callbacks were still using it. (We now reference count the handlers.)
Diffstat (limited to 'src/core')
-rw-r--r--src/core/transport.c70
-rw-r--r--src/core/transport.h8
-rw-r--r--src/core/url.c13
-rw-r--r--src/core/url.h3
4 files changed, 15 insertions, 79 deletions
diff --git a/src/core/transport.c b/src/core/transport.c
index 9c129a72..0891ec8c 100644
--- a/src/core/transport.c
+++ b/src/core/transport.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -106,72 +106,6 @@ nni_tran_find(const char *addr)
return (NULL);
}
-// nni_tran_parse_host_port is a convenience routine to parse the host portion
-// of a URL (which includes a DNS name or IP address and an optional service
-// name or port, separated by a colon) into its host and port name parts. It
-// understands IPv6 address literals when surrounded by brackets ([]).
-// If either component is empty, then NULL is passed back for the value,
-// otherwise a string suitable for freeing with nni_strfree is supplied.
-int
-nni_tran_parse_host_port(const char *pair, char **hostp, char **portp)
-{
- const char *hstart;
- const char *pstart;
- char * host;
- char * port;
- size_t hlen, plen;
-
- if (pair[0] == '[') {
- hstart = pair + 1;
- hlen = 0;
- while (hstart[hlen] != ']') {
- if (hstart[hlen] == '\0') {
- return (NNG_EADDRINVAL);
- }
- hlen++;
- }
- pstart = hstart + hlen + 1; // skip over the trailing ']'
- } else {
- // Normal thing.
- hstart = pair;
- hlen = 0;
- while ((hstart[hlen] != ':') && (hstart[hlen] != '\0')) {
- hlen++;
- }
- pstart = hstart + hlen;
- }
- if (pstart[0] == ':') {
- pstart++;
- }
- plen = strlen(pstart);
-
- host = NULL;
- if (hostp) {
- if ((hlen > 1) || ((hlen == 1) && (*hstart != '*'))) {
- if ((host = nni_alloc(hlen + 1)) == NULL) {
- return (NNG_ENOMEM);
- }
- memcpy(host, hstart, hlen);
- host[hlen] = '\0';
- }
- }
-
- port = NULL;
- if ((plen != 0) && (portp)) {
- if ((port = nni_strdup(pstart)) == NULL) {
- nni_strfree(host);
- return (NNG_ENOMEM);
- }
- }
- if (hostp) {
- *hostp = host;
- }
- if (portp) {
- *portp = port;
- }
- return (0);
-}
-
int
nni_tran_chkopt(const char *name, const void *v, size_t sz)
{
diff --git a/src/core/transport.h b/src/core/transport.h
index 3098bd1a..9a6dc31d 100644
--- a/src/core/transport.h
+++ b/src/core/transport.h
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -162,10 +162,6 @@ struct nni_tran_pipe {
nni_tran_pipe_option *p_options;
};
-// Utility for transports.
-
-extern int nni_tran_parse_host_port(const char *, char **, char **);
-
// These APIs are used by the framework internally, and not for use by
// transport implementations.
extern nni_tran *nni_tran_find(const char *);
diff --git a/src/core/url.c b/src/core/url.c
index 8dee5219..8cb5a2e7 100644
--- a/src/core/url.c
+++ b/src/core/url.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -250,13 +250,17 @@ nni_url_parse(nni_url **urlp, const char *raw)
}
if ((url->u_host = nni_alloc(len + 1)) == NULL) {
- nni_url_free(url);
- return (NNG_ENOMEM);
+ rv = NNG_ENOMEM;
+ goto error;
}
memcpy(url->u_host, s, len);
url->u_host[len] = '\0';
s += len;
+ if ((url->u_rawpath = nni_strdup(s)) == NULL) {
+ rv = NNG_ENOMEM;
+ goto error;
+ }
for (len = 0; (c = s[len]) != '\0'; len++) {
if ((c == '?') || (c == '#')) {
break;
@@ -363,5 +367,6 @@ nni_url_free(nni_url *url)
nni_strfree(url->u_path);
nni_strfree(url->u_query);
nni_strfree(url->u_fragment);
+ nni_strfree(url->u_rawpath);
NNI_FREE_STRUCT(url);
} \ No newline at end of file
diff --git a/src/core/url.h b/src/core/url.h
index ee336b1d..91054dcb 100644
--- a/src/core/url.h
+++ b/src/core/url.h
@@ -1,5 +1,5 @@
//
-// Copyright 2018 Garrett D'Amore <garrett@damore.org>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -23,6 +23,7 @@ struct nni_url {
char *u_path; // path, will be "" if not specified
char *u_query; // without '?', will be NULL if not specified
char *u_fragment; // without '#', will be NULL if not specified
+ char *u_rawpath; // includes query and fragment, "" if not specified
};
extern int nni_url_parse(nni_url **, const char *path);