summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-01-23 22:03:06 -0800
committerGarrett D'Amore <garrett@damore.org>2018-01-23 22:03:06 -0800
commitced5170d6532f427f6750eee274288ceaffe05b5 (patch)
tree477ec98b087a6f9d59460943dedfb5249dcc9aba /src
parentb2800c58d63dc1b53557ea9294b323c3b1f90dab (diff)
downloadnng-ced5170d6532f427f6750eee274288ceaffe05b5.tar.gz
nng-ced5170d6532f427f6750eee274288ceaffe05b5.tar.bz2
nng-ced5170d6532f427f6750eee274288ceaffe05b5.zip
fixes #222 Public URL API
Diffstat (limited to 'src')
-rw-r--r--src/core/defs.h2
-rw-r--r--src/nng.c18
-rw-r--r--src/nng.h29
3 files changed, 48 insertions, 1 deletions
diff --git a/src/core/defs.h b/src/core/defs.h
index d4a8a740..cecb4825 100644
--- a/src/core/defs.h
+++ b/src/core/defs.h
@@ -33,6 +33,7 @@ typedef struct nng_msg nni_msg;
typedef struct nng_sockaddr nni_sockaddr;
typedef struct nng_event nni_event;
typedef struct nng_notify nni_notify;
+typedef struct nng_url nni_url;
// These are our own names.
typedef struct nni_socket nni_sock;
@@ -43,7 +44,6 @@ typedef struct nni_tran_ep nni_tran_ep;
typedef struct nni_tran_ep_option nni_tran_ep_option;
typedef struct nni_tran_pipe nni_tran_pipe;
typedef struct nni_tran_pipe_option nni_tran_pipe_option;
-typedef struct nni_url nni_url;
typedef struct nni_proto_sock_ops nni_proto_sock_ops;
typedef struct nni_proto_pipe_ops nni_proto_pipe_ops;
diff --git a/src/nng.c b/src/nng.c
index 509bb333..addfc06a 100644
--- a/src/nng.c
+++ b/src/nng.c
@@ -1176,3 +1176,21 @@ nng_thread_destroy(void *arg)
NNI_FREE_STRUCT(thr);
}
+
+int
+nng_url_parse(nng_url **result, const char *ustr)
+{
+ return (nni_url_parse(result, ustr));
+}
+
+void
+nng_url_free(nng_url *url)
+{
+ nni_url_free(url);
+}
+
+int
+nng_url_clone(nng_url **dstp, const nng_url *src)
+{
+ return (nni_url_clone(dstp, src));
+} \ No newline at end of file
diff --git a/src/nng.h b/src/nng.h
index 26e851eb..a25cb25c 100644
--- a/src/nng.h
+++ b/src/nng.h
@@ -710,6 +710,35 @@ NNG_DECL int nng_tls_config_ca_file(nng_tls_config *, const char *);
NNG_DECL int nng_tls_config_cert_key_file(
nng_tls_config *, const char *, const char *);
+// URL support. We frequently want to process a URL, and these methods
+// give us a convenient way of doing so.
+
+typedef struct nng_url {
+ char *u_rawurl; // never NULL
+ char *u_scheme; // never NULL
+ char *u_userinfo; // will be NULL if not specified
+ char *u_host; // including colon and port
+ char *u_hostname; // name only, will be "" if not specified
+ char *u_port; // port, will be "" if not specified
+ 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
+} nng_url;
+
+// nng_url_parse parses a URL string into a structured form.
+// Note that the u_port member will be filled out with a numeric
+// port if one isn't specified and a default port is appropriate for
+// the scheme. The URL structure is allocated, along with individual
+// members. It can be freed with nng_url_free.
+NNG_DECL int nng_url_parse(nng_url **, const char *);
+
+// nng_url_free frees a URL structure that was created by nng_url_parse9().
+NNG_DECL void nng_url_free(nng_url *);
+
+// nng_url_clone clones a URL structure.
+NNG_DECL int nng_url_clone(nng_url **, const nng_url *);
+
#ifdef __cplusplus
}
#endif