From ced5170d6532f427f6750eee274288ceaffe05b5 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 23 Jan 2018 22:03:06 -0800 Subject: fixes #222 Public URL API --- src/core/defs.h | 2 +- src/nng.c | 18 ++++++++++++++++++ src/nng.h | 29 +++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) (limited to 'src') 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 -- cgit v1.2.3-70-g09d2