diff options
Diffstat (limited to 'src/supplemental/http')
| -rw-r--r-- | src/supplemental/http/http.h | 14 | ||||
| -rw-r--r-- | src/supplemental/http/http_api.h | 13 | ||||
| -rw-r--r-- | src/supplemental/http/http_client.c | 18 | ||||
| -rw-r--r-- | src/supplemental/http/http_conn.c | 81 | ||||
| -rw-r--r-- | src/supplemental/http/http_public.c | 8 |
5 files changed, 74 insertions, 60 deletions
diff --git a/src/supplemental/http/http.h b/src/supplemental/http/http.h index 470ffbfa..f6a45df7 100644 --- a/src/supplemental/http/http.h +++ b/src/supplemental/http/http.h @@ -21,7 +21,7 @@ extern "C" { #include <stdint.h> -typedef struct nng_tls_config nng_tls_config; +struct nng_tls_config; // HTTP status codes. This list is not exhaustive. enum nng_http_status { @@ -398,12 +398,14 @@ NNG_DECL int nng_http_server_del_handler( // server client, so the caller must have configured it reasonably. // This API is not recommended unless the caller needs complete control // over the TLS configuration. -NNG_DECL int nng_http_server_set_tls(nng_http_server *, nng_tls_config *); +NNG_DECL int nng_http_server_set_tls( + nng_http_server *, struct nng_tls_config *); // nng_http_server_get_tls obtains the TLS configuration if one is present, // or returns NNG_EINVAL. The TLS configuration is invalidated if the // nng_http_server_set_tls function is called, so be careful. -NNG_DECL int nng_http_server_get_tls(nng_http_server *, nng_tls_config **); +NNG_DECL int nng_http_server_get_tls( + nng_http_server *, struct nng_tls_config **); // nng_http_hijack is intended to be called by a handler that wishes to // take over the processing of the HTTP session -- usually to change protocols @@ -435,12 +437,14 @@ NNG_DECL void nng_http_client_free(nng_http_client *); // the entire TLS configuration on the client, so the caller must have // configured it reasonably. This API is not recommended unless the // caller needs complete control over the TLS configuration. -NNG_DECL int nng_http_client_set_tls(nng_http_client *, nng_tls_config *); +NNG_DECL int nng_http_client_set_tls( + nng_http_client *, struct nng_tls_config *); // nng_http_client_get_tls obtains the TLS configuration if one is present, // or returns NNG_EINVAL. The supplied TLS configuration object may // be invalidated by any future calls to nni_http_client_set_tls. -NNG_DECL int nng_http_client_get_tls(nng_http_client *, nng_tls_config **); +NNG_DECL int nng_http_client_get_tls( + nng_http_client *, struct nng_tls_config **); // nng_http_client_connect establishes a new connection with the server // named in the URL used when the client was created. Once the connection diff --git a/src/supplemental/http/http_api.h b/src/supplemental/http/http_api.h index 8de859b4..f1a5c0fa 100644 --- a/src/supplemental/http/http_api.h +++ b/src/supplemental/http/http_api.h @@ -65,7 +65,8 @@ extern void *nni_http_conn_get_ctx(nni_http_conn *); // They should only be used by the server or client HTTP implementations, // and are not for use by other code. extern int nni_http_conn_init_tcp(nni_http_conn **, void *); -extern int nni_http_conn_init_tls(nni_http_conn **, nng_tls_config *, void *); +extern int nni_http_conn_init_tls( + nni_http_conn **, struct nng_tls_config *, void *); extern void nni_http_conn_close(nni_http_conn *); extern void nni_http_conn_fini(nni_http_conn *); @@ -153,12 +154,13 @@ extern int nni_http_server_del_handler(nni_http_server *, nni_http_handler *); // server client, so the caller must have configured it reasonably. // This API is not recommended unless the caller needs complete control // over the TLS configuration. -extern int nni_http_server_set_tls(nni_http_server *, nng_tls_config *); +extern int nni_http_server_set_tls(nni_http_server *, struct nng_tls_config *); // nni_http_server_get_tls obtains the TLS configuration if one is present, // or returns NNG_EINVAL. The TLS configuration is invalidated if the // nni_http_server_set_tls function is called, so be careful. -extern int nni_http_server_get_tls(nni_http_server *, nng_tls_config **); +extern int nni_http_server_get_tls( + nni_http_server *, struct nng_tls_config **); // nni_http_server_start starts listening on the supplied port. extern int nni_http_server_start(nni_http_server *); @@ -273,12 +275,13 @@ extern void nni_http_client_fini(nni_http_client *); // the entire TLS configuration on the client, so the caller must have // configured it reasonably. This API is not recommended unless the // caller needs complete control over the TLS configuration. -extern int nni_http_client_set_tls(nni_http_client *, nng_tls_config *); +extern int nni_http_client_set_tls(nni_http_client *, struct nng_tls_config *); // nni_http_client_get_tls obtains the TLS configuration if one is present, // or returns NNG_EINVAL. The supplied TLS configuration object may // be invalidated by any future calls to nni_http_client_set_tls. -extern int nni_http_client_get_tls(nni_http_client *, nng_tls_config **); +extern int nni_http_client_get_tls( + nni_http_client *, struct nng_tls_config **); extern void nni_http_client_connect(nni_http_client *, nni_aio *); diff --git a/src/supplemental/http/http_client.c b/src/supplemental/http/http_client.c index 2a9be4bb..a2427009 100644 --- a/src/supplemental/http/http_client.c +++ b/src/supplemental/http/http_client.c @@ -20,12 +20,12 @@ #include "http_api.h" struct nng_http_client { - nni_list aios; - nni_mtx mtx; - bool closed; - nng_tls_config * tls; - nni_aio * connaio; - nni_plat_tcp_ep *tep; + nni_list aios; + nni_mtx mtx; + bool closed; + struct nng_tls_config *tls; + nni_aio * connaio; + nni_plat_tcp_ep * tep; }; static void @@ -182,10 +182,10 @@ nni_http_client_init(nni_http_client **cp, const nni_url *url) } int -nni_http_client_set_tls(nni_http_client *c, nng_tls_config *tls) +nni_http_client_set_tls(nni_http_client *c, struct nng_tls_config *tls) { #ifdef NNG_SUPP_TLS - nng_tls_config *old; + struct nng_tls_config *old; nni_mtx_lock(&c->mtx); old = c->tls; c->tls = tls; @@ -205,7 +205,7 @@ nni_http_client_set_tls(nni_http_client *c, nng_tls_config *tls) } int -nni_http_client_get_tls(nni_http_client *c, nng_tls_config **tlsp) +nni_http_client_get_tls(nni_http_client *c, struct nng_tls_config **tlsp) { #ifdef NNG_SUPP_TLS nni_mtx_lock(&c->mtx); diff --git a/src/supplemental/http/http_conn.c b/src/supplemental/http/http_conn.c index a3039d0d..0de40e10 100644 --- a/src/supplemental/http/http_conn.c +++ b/src/supplemental/http/http_conn.c @@ -36,14 +36,21 @@ enum write_flavor { HTTP_WR_RES, }; +typedef void (*http_read_fn)(void *, nni_aio *); +typedef void (*http_write_fn)(void *, nni_aio *); +typedef void (*http_close_fn)(void *); +typedef void (*http_fini_fn)(void *); +typedef bool (*http_verified_fn)(void *); +typedef int (*http_addr_fn)(void *, nni_sockaddr *); + typedef struct nni_http_tran { - void (*h_read)(void *, nni_aio *); - void (*h_write)(void *, nni_aio *); - int (*h_sock_addr)(void *, nni_sockaddr *); - int (*h_peer_addr)(void *, nni_sockaddr *); - bool (*h_verified)(void *); - void (*h_close)(void *); - void (*h_fini)(void *); + http_read_fn h_read; + http_write_fn h_write; + http_addr_fn h_sock_addr; + http_addr_fn h_peer_addr; + http_verified_fn h_verified; + http_close_fn h_close; + http_fini_fn h_fini; } nni_http_tran; #define SET_RD_FLAVOR(aio, f) \ @@ -54,20 +61,18 @@ typedef struct nni_http_tran { #define GET_WR_FLAVOR(aio) (int) ((intptr_t) nni_aio_get_prov_extra(aio, 0)) struct nng_http_conn { - void *sock; - void (*rd)(void *, nni_aio *); - void (*wr)(void *, nni_aio *); - int (*sock_addr)(void *, nni_sockaddr *); - int (*peer_addr)(void *, nni_sockaddr *); - bool (*verified)(void *); - void (*close)(void *); - void (*fini)(void *); - - void *ctx; - bool closed; - - nni_list rdq; // high level http read requests - nni_list wrq; // high level http write requests + void * sock; + http_read_fn rd; + http_write_fn wr; + http_addr_fn sock_addr; + http_addr_fn peer_addr; + http_verified_fn verified; + http_close_fn close; + http_fini_fn fini; + void * ctx; + bool closed; + nni_list rdq; // high level http read requests + nni_list wrq; // high level http write requests nni_aio *rd_uaio; // user aio for read nni_aio *wr_uaio; // user aio for write @@ -715,13 +720,13 @@ nni_http_verified_tcp(void *arg) } static nni_http_tran http_tcp_ops = { - .h_read = (void *) nni_plat_tcp_pipe_recv, - .h_write = (void *) nni_plat_tcp_pipe_send, - .h_close = (void *) nni_plat_tcp_pipe_close, - .h_fini = (void *) nni_plat_tcp_pipe_fini, - .h_sock_addr = (void *) nni_plat_tcp_pipe_sockname, - .h_peer_addr = (void *) nni_plat_tcp_pipe_peername, - .h_verified = nni_http_verified_tcp, + .h_read = (http_read_fn) nni_plat_tcp_pipe_recv, + .h_write = (http_write_fn) nni_plat_tcp_pipe_send, + .h_close = (http_close_fn) nni_plat_tcp_pipe_close, + .h_fini = (http_fini_fn) nni_plat_tcp_pipe_fini, + .h_sock_addr = (http_addr_fn) nni_plat_tcp_pipe_sockname, + .h_peer_addr = (http_addr_fn) nni_plat_tcp_pipe_peername, + .h_verified = (http_verified_fn) nni_http_verified_tcp, }; int @@ -732,17 +737,18 @@ nni_http_conn_init_tcp(nni_http_conn **connp, void *tcp) #ifdef NNG_SUPP_TLS static nni_http_tran http_tls_ops = { - .h_read = (void *) nni_tls_recv, - .h_write = (void *) nni_tls_send, - .h_close = (void *) nni_tls_close, - .h_fini = (void *) nni_tls_fini, - .h_sock_addr = (void *) nni_tls_sockname, - .h_peer_addr = (void *) nni_tls_peername, - .h_verified = (void *) nni_tls_verified, + .h_read = (http_read_fn) nni_tls_recv, + .h_write = (http_write_fn) nni_tls_send, + .h_close = (http_close_fn) nni_tls_close, + .h_fini = (http_fini_fn) nni_tls_fini, + .h_sock_addr = (http_addr_fn) nni_tls_sockname, + .h_peer_addr = (http_addr_fn) nni_tls_peername, + .h_verified = (http_verified_fn) nni_tls_verified, }; int -nni_http_conn_init_tls(nni_http_conn **connp, nng_tls_config *cfg, void *tcp) +nni_http_conn_init_tls( + nni_http_conn **connp, struct nng_tls_config *cfg, void *tcp) { nni_tls *tls; int rv; @@ -756,7 +762,8 @@ nni_http_conn_init_tls(nni_http_conn **connp, nng_tls_config *cfg, void *tcp) } #else int -nni_http_conn_init_tls(nni_http_conn **connp, nng_tls_config *cfg, void *tcp) +nni_http_conn_init_tls( + nni_http_conn **connp, struct nng_tls_config *cfg, void *tcp) { NNI_ARG_UNUSED(connp); NNI_ARG_UNUSED(cfg); diff --git a/src/supplemental/http/http_public.c b/src/supplemental/http/http_public.c index 7aae45b2..40d4a19c 100644 --- a/src/supplemental/http/http_public.c +++ b/src/supplemental/http/http_public.c @@ -676,7 +676,7 @@ nng_http_server_del_handler(nng_http_server *srv, nng_http_handler *h) } int -nng_http_server_set_tls(nng_http_server *srv, nng_tls_config *cfg) +nng_http_server_set_tls(nng_http_server *srv, struct nng_tls_config *cfg) { #if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) return (nni_http_server_set_tls(srv, cfg)); @@ -688,7 +688,7 @@ nng_http_server_set_tls(nng_http_server *srv, nng_tls_config *cfg) } int -nng_http_server_get_tls(nng_http_server *srv, nng_tls_config **cfgp) +nng_http_server_get_tls(nng_http_server *srv, struct nng_tls_config **cfgp) { #if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) return (nni_http_server_get_tls(srv, cfgp)); @@ -734,7 +734,7 @@ nng_http_client_free(nng_http_client *cli) } int -nng_http_client_set_tls(nng_http_client *cli, nng_tls_config *cfg) +nng_http_client_set_tls(nng_http_client *cli, struct nng_tls_config *cfg) { #if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) return (nni_http_client_set_tls(cli, cfg)); @@ -746,7 +746,7 @@ nng_http_client_set_tls(nng_http_client *cli, nng_tls_config *cfg) } int -nng_http_client_get_tls(nng_http_client *cli, nng_tls_config **cfgp) +nng_http_client_get_tls(nng_http_client *cli, struct nng_tls_config **cfgp) { #if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) return (nni_http_client_get_tls(cli, cfgp)); |
