diff options
Diffstat (limited to 'src/supplemental')
| -rw-r--r-- | src/supplemental/http/CMakeLists.txt | 16 | ||||
| -rw-r--r-- | src/supplemental/http/http_api.h | 181 | ||||
| -rw-r--r-- | src/supplemental/http/http_client.c | 50 | ||||
| -rw-r--r-- | src/supplemental/http/http_conn.c | 132 | ||||
| -rw-r--r-- | src/supplemental/http/http_msg.c | 22 | ||||
| -rw-r--r-- | src/supplemental/http/http_public.c | 514 | ||||
| -rw-r--r-- | src/supplemental/http/http_server.c | 90 | ||||
| -rw-r--r-- | src/supplemental/http/http_stubs.c | 431 | ||||
| -rw-r--r-- | src/supplemental/websocket/websocket.c | 28 |
9 files changed, 622 insertions, 842 deletions
diff --git a/src/supplemental/http/CMakeLists.txt b/src/supplemental/http/CMakeLists.txt index 31a544a9..9f85631b 100644 --- a/src/supplemental/http/CMakeLists.txt +++ b/src/supplemental/http/CMakeLists.txt @@ -11,13 +11,9 @@ option (NNG_ENABLE_HTTP "Enable HTTP API" ON) if (NNG_ENABLE_HTTP) set(NNG_SUPP_HTTP ON) -endif() -mark_as_advanced(NNG_ENABLE_HTTP) - -nng_sources(http_public.c http_api.h) - -nng_defines_if(NNG_SUPP_HTTP NNG_SUPP_HTTP) -nng_sources_if(NNG_SUPP_HTTP + nng_defines(NNG_SUPP_HTTP) + nng_sources( + http_api.h http_client.c http_chunk.c http_conn.c @@ -25,4 +21,8 @@ nng_sources_if(NNG_SUPP_HTTP http_public.c http_schemes.c http_server.c) -nng_test_if(NNG_SUPP_HTTP http_server_test) + nng_test(http_server_test) +else() + nng_sources(http_stubs.c) +endif() +mark_as_advanced(NNG_ENABLE_HTTP) diff --git a/src/supplemental/http/http_api.h b/src/supplemental/http/http_api.h index c2fd5eec..425828ed 100644 --- a/src/supplemental/http/http_api.h +++ b/src/supplemental/http/http_api.h @@ -24,9 +24,7 @@ typedef struct nng_http_req nni_http_req; typedef struct nng_http_res nni_http_res; -typedef struct nng_http_conn nni_http_conn; typedef struct nng_http_server nni_http_server; -typedef struct nng_http_client nni_http_client; typedef struct nng_http_chunk nni_http_chunk; typedef struct nng_http_chunks nni_http_chunks; @@ -66,15 +64,14 @@ extern void *nni_http_chunk_data(nni_http_chunk *); extern nng_err nni_http_chunks_parse( nni_http_chunks *, void *, size_t, size_t *); -extern void nni_http_read_chunks( - nni_http_conn *, nni_http_chunks *, nni_aio *); +extern void nni_http_read_chunks(nng_http *, nni_http_chunks *, nni_aio *); -extern nni_http_req *nni_http_conn_req(nni_http_conn *); -extern nni_http_res *nni_http_conn_res(nni_http_conn *); +extern nni_http_req *nni_http_conn_req(nng_http *); +extern nni_http_res *nni_http_conn_res(nng_http *); // Private to the server. (Used to support session hijacking.) -extern void nni_http_conn_set_ctx(nni_http_conn *, void *); -extern void *nni_http_conn_get_ctx(nni_http_conn *); +extern void nni_http_conn_set_ctx(nng_http *, void *); +extern void *nni_http_conn_get_ctx(nng_http *); // An HTTP connection is a connection over which messages are exchanged. // Generally, clients send request messages, and then read responses. @@ -82,8 +79,8 @@ extern void *nni_http_conn_get_ctx(nni_http_conn *); // require a 1:1 mapping between request and response here -- the application // is responsible for dealing with that. // -// We only support HTTP/1.1, though using the nni_http_conn_read and -// nni_http_conn_write low level methods, it is possible to write an upgrader +// We only support HTTP/1.1, though using the nni_http_read and +// nni_http_write low level methods, it is possible to write an upgrader // (such as websocket!) that might support e.g. HTTP/2 or reading data that // follows a legacy HTTP/1.0 message. // @@ -96,7 +93,7 @@ extern void *nni_http_conn_get_ctx(nni_http_conn *); extern nng_err nni_http_init(nng_http **, nng_stream *, bool); extern void nni_http_conn_close(nng_http *); -extern void nni_http_conn_fini(nni_http_conn *); +extern void nni_http_conn_fini(nng_http *); extern int nni_http_conn_getopt( nng_http *, const char *, void *, size_t *, nni_type); @@ -105,30 +102,21 @@ extern int nni_http_conn_getopt( // Note that the iovs of the aio's are clobbered by these methods -- callers // must not use them for any other purpose. -extern void nni_http_write_req(nni_http_conn *, nni_aio *); -extern void nni_http_read_res(nni_http_conn *, nni_aio *); -extern void nni_http_read_req(nni_http_conn *, nni_aio *); -extern void nni_http_write_res(nni_http_conn *, nni_aio *); -extern void nni_http_read_discard(nni_http_conn *, size_t, nni_aio *); +extern void nni_http_write_req(nng_http *, nni_aio *); +extern void nni_http_read_res(nng_http *, nni_aio *); +extern void nni_http_read_req(nng_http *, nni_aio *); +extern void nni_http_write_res(nng_http *, nni_aio *); +extern void nni_http_read_discard(nng_http *, size_t, nni_aio *); extern nng_err nni_http_req_alloc_data(nni_http_req *, size_t); extern nng_err nni_http_res_alloc_data(nni_http_res *, size_t); extern bool nni_http_is_error(nng_http *); -extern void nni_http_read(nni_http_conn *, nni_aio *); -extern void nni_http_read_full(nni_http_conn *, nni_aio *); -extern void nni_http_write(nni_http_conn *, nni_aio *); -extern void nni_http_write_full(nni_http_conn *, nni_aio *); - -extern nng_err nni_http_add_header(nng_http *, const char *, const char *); -extern nng_err nni_http_set_header(nng_http *, const char *, const char *); -extern void nni_http_del_header(nng_http *, const char *); -extern const char *nni_http_get_header(nng_http *, const char *); - -extern void nni_http_get_body(nng_http *, void **, size_t *); -extern void nni_http_set_body(nng_http *, void *, size_t); -extern nng_err nni_http_copy_body(nng_http *, const void *, size_t); +extern void nni_http_read(nng_http *, nni_aio *); +extern void nni_http_read_full(nng_http *, nni_aio *); +extern void nni_http_write(nng_http *, nni_aio *); +extern void nni_http_write_full(nng_http *, nni_aio *); // prune body clears the outgoing body (0 bytes), but leaves content-length // intact if present for the benefit of HEAD. @@ -207,153 +195,32 @@ extern nng_err nni_http_server_set_error_page( // of the res. The res must have the status set first. extern nng_err nni_http_server_error(nni_http_server *, nng_http *); -// nni_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 -// (such as in the case of websocket). The caller is responsible for obtaining -// and disposal of the associated nni_http session. Also, this completely -// disassociates the http session from the server, so the server may be -// stopped or destroyed without affecting the hijacked session. Note also -// that the hijacker will need to issue any HTTP reply itself. Finally, -// when a session is hijacked, the caller is also responsible for disposing -// of the request structure. (Some hijackers may keep the request for -// further processing.) -extern nng_err nni_http_hijack(nni_http_conn *); - -// nni_http_handler_alloc creates a server handler object, for the supplied -// URI (path only) with the callback. -// -// Note that methods which modify a handler cannot be called while the handler -// is registered with the server, and that a handler can only be registered -// once per server. -extern nng_err nni_http_handler_alloc( - nng_http_handler **, const char *, nng_http_handler_func); - -// nni_http_handler_creates a handler with a function to serve -// up a file named in the last argument. -extern nng_err nni_http_handler_file( - nng_http_handler **, const char *, const char *, const char *); - -// nni_http_handler_directory serves up an entire -// directory tree. The content types are determined from the built-in -// content type list. Actual directories are required to contain a -// file called index.html or index.htm. We do not generate directory -// listings for security reasons. -extern nng_err nni_http_handler_directory( - nng_http_handler **, const char *, const char *); - -// nni_http_handler_static creates a handler that serves up static -// content supplied, with the Content-Type supplied in the final argument. -extern nng_err nni_http_handler_static( - nng_http_handler **, const char *, const void *, size_t, const char *); - -// nni_http_handler_redirect creates a handler that redirects the request. -extern nng_err nni_http_handler_redirect( - nng_http_handler **, const char *, nng_http_status, const char *); - -// nni_http_handler_free destroys a handler. This should only be done before -// the handler is added, or after it is deleted. The server automatically -// calls this for any handlers still registered with it if it is destroyed. -extern void nni_http_handler_free(nng_http_handler *); - -// nni_http_handler_collect_body informs the server that it should collect -// the entitty data associated with the client request, and sets the maximum -// size to accept. -extern void nni_http_handler_collect_body(nng_http_handler *, bool, size_t); - -// nni_http_handler_set_tree marks the handler as servicing the entire -// tree (e.g. a directory), rather than just a leaf node. The handler -// will probably need to inspect the URL of the request. -extern void nni_http_handler_set_tree(nng_http_handler *); - -// nni_http_handler_set_host limits the handler to only being called for -// the given Host: field. This can be used to set up multiple virtual -// hosts. Note that host names must match exactly. If NULL or an empty -// string is specified, then the client's Host: field is ignored. (The -// supplied value for the Host is copied by this function.) When supplying -// a hostname, do not include a value for the port number; we do not match -// on port number as we assume that clients MUST have gotten that part right -// as we do not support virtual hosting on multiple separate ports; the -// server only listens on a single port. -extern void nni_http_handler_set_host(nng_http_handler *, const char *); - -// nni_http_handler_set_method limits the handler to only being called -// for the given HTTP method. By default a handler is called for GET -// methods only (and HEAD, which is handled internally.) Handlers can -// be specified for any valid HTTP method. A handler may set the value -// NULL here, to be called for any HTTP method. In such a case, the handler -// is obligated to inspect the method. (Note: the passed method must be -// in upper case and should come from a statically allocated string; the -// server does not make its own copy.) -extern void nni_http_handler_set_method(nng_http_handler *, const char *); - -// nni_http_handler_set_data sets an opaque data element on the handler, -// which will be available to the handler function as argument. -// The callback is an optional destructor, and will be called with the -// data as its argument, when the handler is being destroyed. -extern void nni_http_handler_set_data(nng_http_handler *, void *, nni_cb); - -// nni_http_handler_get_uri returns the URI set on the handler. -extern const char *nni_http_handler_get_uri(nng_http_handler *); - // Client stuff. -extern nng_err nni_http_client_init(nni_http_client **, const nng_url *); -extern void nni_http_client_fini(nni_http_client *); - // nni_http_client_set_tls sets the TLS configuration. This wipes out // 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 nng_err nni_http_client_set_tls( - nni_http_client *, struct nng_tls_config *); + nng_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 nng_err nni_http_client_get_tls( - nni_http_client *, struct nng_tls_config **); + nng_http_client *, struct nng_tls_config **); extern int nni_http_client_set( - nni_http_client *, const char *, const void *buf, size_t, nni_type); + nng_http_client *, const char *, const void *buf, size_t, nni_type); extern int nni_http_client_get( - nni_http_client *, const char *, void *, size_t *, nni_type); - -extern void nni_http_client_connect(nni_http_client *, nni_aio *); - -// nni_http_transact_conn is used to perform a round-trip exchange (i.e. a -// single HTTP transaction). It will not automatically close the connection, -// unless some kind of significant error occurs. The caller should dispose -// of the connection if the aio does not complete successfully. -// Note that this will fail with NNG_ENOTSUP if the server attempts to reply -// with a chunked transfer encoding. The request and response used are the -// ones associated with the connection. -extern void nni_http_transact_conn(nni_http_conn *, nni_aio *); - -// nni_http_transact is used to execute a single transaction to a server. -// The connection is opened, and will be closed when the transaction is -// complete. Note that this will fail with NNG_ENOTSUP if the server attempts -// to reply with a chunked transfer encoding. -extern void nni_http_transact( - nni_http_client *, nni_http_req *, nni_http_res *, nni_aio *); + nng_http_client *, const char *, void *, size_t *, nni_type); // nni_http_stream_scheme returns the underlying stream scheme for a given // upper layer scheme. extern const char *nni_http_stream_scheme(const char *); // Private method used for the server. -extern bool nni_http_res_sent(nni_http_conn *conn); - -extern const char *nni_http_get_version(nng_http *conn); -extern int nni_http_set_version(nng_http *conn, const char *vers); - -extern void nni_http_set_method(nng_http *conn, const char *method); -extern const char *nni_http_get_method(nng_http *conn); - -extern void nni_http_set_status( - nng_http *conn, nng_http_status status, const char *reason); - -extern nng_http_status nni_http_get_status(nng_http *); -extern const char *nni_http_get_reason(nng_http *); +extern bool nni_http_res_sent(nng_http *conn); // nni_http_set_error flags an error using the built in HTML page. // unless body is not NULL. To pass no content, pass an empty string for body. @@ -366,10 +233,6 @@ extern nng_err nni_http_set_error(nng_http *conn, nng_http_status status, extern nng_err nni_http_set_redirect(nng_http *conn, nng_http_status status, const char *reason, const char *dest); -extern nng_err nni_http_set_uri( - nng_http *conn, const char *uri, const char *query); -extern const char *nni_http_get_uri(nng_http *conn); - extern void nni_http_set_host(nng_http *conn, const char *); extern void nni_http_set_content_type(nng_http *conn, const char *); extern void nni_http_conn_reset(nng_http *conn); diff --git a/src/supplemental/http/http_client.c b/src/supplemental/http/http_client.c index 1f5d8fbd..aee46458 100644 --- a/src/supplemental/http/http_client.c +++ b/src/supplemental/http/http_client.c @@ -31,7 +31,7 @@ struct nng_http_client { }; static void -http_dial_start(nni_http_client *c) +http_dial_start(nng_http_client *c) { if (nni_list_empty(&c->aios)) { return; @@ -42,11 +42,11 @@ http_dial_start(nni_http_client *c) static void http_dial_cb(void *arg) { - nni_http_client *c = arg; + nng_http_client *c = arg; nni_aio *aio; nng_err rv; nng_stream *stream; - nni_http_conn *conn; + nng_http *conn; nni_mtx_lock(&c->mtx); rv = nni_aio_result(&c->aio); @@ -90,7 +90,7 @@ http_dial_cb(void *arg) } void -nni_http_client_fini(nni_http_client *c) +nng_http_client_free(nng_http_client *c) { nni_aio_stop(&c->aio); nng_stream_dialer_stop(c->dialer); @@ -101,10 +101,10 @@ nni_http_client_fini(nni_http_client *c) } nng_err -nni_http_client_init(nni_http_client **cp, const nng_url *url) +nng_http_client_alloc(nng_http_client **cp, const nng_url *url) { nng_err rv; - nni_http_client *c; + nng_http_client *c; nng_url my_url; const char *scheme; @@ -139,7 +139,7 @@ nni_http_client_init(nni_http_client **cp, const nng_url *url) url->u_port); } if ((rv = nng_stream_dialer_alloc_url(&c->dialer, &my_url)) != 0) { - nni_http_client_fini(c); + nng_http_client_free(c); return (rv); } @@ -148,19 +148,19 @@ nni_http_client_init(nni_http_client **cp, const nng_url *url) } nng_err -nni_http_client_set_tls(nni_http_client *c, nng_tls_config *tls) +nng_http_client_set_tls(nng_http_client *c, nng_tls_config *tls) { return (nng_stream_dialer_set_tls(c->dialer, tls)); } nng_err -nni_http_client_get_tls(nni_http_client *c, nng_tls_config **tlsp) +nng_http_client_get_tls(nng_http_client *c, nng_tls_config **tlsp) { return (nng_stream_dialer_get_tls(c->dialer, tlsp)); } int -nni_http_client_set(nni_http_client *c, const char *name, const void *buf, +nni_http_client_set(nng_http_client *c, const char *name, const void *buf, size_t sz, nni_type t) { // We have no local options, but we just pass them straight through. @@ -169,7 +169,7 @@ nni_http_client_set(nni_http_client *c, const char *name, const void *buf, int nni_http_client_get( - nni_http_client *c, const char *name, void *buf, size_t *szp, nni_type t) + nng_http_client *c, const char *name, void *buf, size_t *szp, nni_type t) { return (nni_stream_dialer_get(c->dialer, name, buf, szp, t)); } @@ -177,7 +177,7 @@ nni_http_client_get( static void http_dial_cancel(nni_aio *aio, void *arg, int rv) { - nni_http_client *c = arg; + nng_http_client *c = arg; nni_mtx_lock(&c->mtx); if (nni_aio_list_active(aio)) { nni_aio_list_remove(aio); @@ -190,7 +190,7 @@ http_dial_cancel(nni_aio *aio, void *arg, int rv) } void -nni_http_client_connect(nni_http_client *c, nni_aio *aio) +nng_http_client_connect(nng_http_client *c, nni_aio *aio) { nni_aio_reset(aio); nni_mtx_lock(&c->mtx); @@ -215,8 +215,8 @@ typedef enum http_txn_state { typedef struct http_txn { nni_aio aio; // lower level aio nni_list aios; // upper level aio(s) -- maximum one - nni_http_client *client; - nni_http_conn *conn; + nng_http_client *client; + nng_http *conn; nni_http_res *res; nni_http_chunks *chunks; http_txn_state state; @@ -293,8 +293,8 @@ http_txn_cb(void *arg) // Detect chunked encoding. You poor bastard. (Only if not // HEAD.) - if ((strcmp(nni_http_get_method(txn->conn), "HEAD") != 0) && - ((str = nni_http_get_header( + if ((strcmp(nng_http_get_method(txn->conn), "HEAD") != 0) && + ((str = nng_http_get_header( txn->conn, "Transfer-Encoding")) != NULL) && (strstr(str, "chunked") != NULL)) { @@ -309,8 +309,8 @@ http_txn_cb(void *arg) return; } - if ((strcmp(nni_http_get_method(txn->conn), "HEAD") == 0) || - ((str = nni_http_get_header( + if ((strcmp(nng_http_get_method(txn->conn), "HEAD") == 0) || + ((str = nng_http_get_header( txn->conn, "Content-Length")) == NULL) || ((len = (uint64_t) strtoull(str, &end, 10)) == 0) || (end == NULL) || (*end != '\0')) { @@ -326,8 +326,8 @@ http_txn_cb(void *arg) NNG_OK) { goto error; } - nni_http_get_body(txn->conn, &iov.iov_buf, &iov.iov_len); - nni_aio_set_iov(&txn->aio, 1, &iov); + nng_http_get_body(txn->conn, &iov.iov_buf, &iov.iov_len); + nng_aio_set_iov(&txn->aio, 1, &iov); txn->state = HTTP_RECVING_BODY; nni_http_read_full(txn->conn, &txn->aio); nni_mtx_unlock(&http_txn_lk); @@ -347,7 +347,7 @@ http_txn_cb(void *arg) if ((rv = nni_http_res_alloc_data(txn->res, sz)) != 0) { goto error; } - nni_http_get_body(txn->conn, (void **) &dst, &sz); + nng_http_get_body(txn->conn, (void **) &dst, &sz); while ((chunk = nni_http_chunks_iter(txn->chunks, chunk)) != NULL) { memcpy(dst, nni_http_chunk_data(chunk), @@ -378,13 +378,13 @@ http_txn_cancel(nni_aio *aio, void *arg, int rv) nni_mtx_unlock(&http_txn_lk); } -// nni_http_transact_conn sends a request to an HTTP server, and reads the +// nng_http_transact sends a request to an HTTP server, and reads the // response. It also attempts to read any associated data. Note that // at present it can only read data that comes in normally, as support // for Chunked Transfer Encoding is missing. Note that cancelling the aio // is generally fatal to the connection. void -nni_http_transact_conn(nni_http_conn *conn, nni_aio *aio) +nng_http_transact(nng_http *conn, nni_aio *aio) { http_txn *txn; @@ -401,7 +401,7 @@ nni_http_transact_conn(nni_http_conn *conn, nni_aio *aio) txn->state = HTTP_SENDING; nni_http_res_reset(txn->res); - nni_http_set_status(txn->conn, 0, NULL); + nng_http_set_status(txn->conn, 0, NULL); nni_mtx_lock(&http_txn_lk); if (!nni_aio_start(aio, http_txn_cancel, txn)) { diff --git a/src/supplemental/http/http_conn.c b/src/supplemental/http/http_conn.c index 00961852..ec8adb0c 100644 --- a/src/supplemental/http/http_conn.c +++ b/src/supplemental/http/http_conn.c @@ -102,19 +102,19 @@ nni_http_conn_res(nng_http *conn) } void -nni_http_conn_set_ctx(nni_http_conn *conn, void *ctx) +nni_http_conn_set_ctx(nng_http *conn, void *ctx) { conn->ctx = ctx; } void * -nni_http_conn_get_ctx(nni_http_conn *conn) +nni_http_conn_get_ctx(nng_http *conn) { return (conn->ctx); } static void -http_close(nni_http_conn *conn) +http_close(nng_http *conn) { // Call with lock held. nni_aio *aio; @@ -152,7 +152,7 @@ http_close(nni_http_conn *conn) } void -nni_http_conn_close(nni_http_conn *conn) +nni_http_conn_close(nng_http *conn) { nni_mtx_lock(&conn->mtx); http_close(conn); @@ -163,7 +163,7 @@ nni_http_conn_close(nni_http_conn *conn) // beginning, so that the next read can go at the end. This avoids the problem // of dealing with a read that might wrap. static void -http_buf_pull_up(nni_http_conn *conn) +http_buf_pull_up(nng_http *conn) { if (conn->rd_get != 0) { memmove(conn->buf, conn->buf + conn->rd_get, @@ -175,7 +175,7 @@ http_buf_pull_up(nni_http_conn *conn) // http_rd_buf attempts to satisfy the read from data in the buffer. static nng_err -http_rd_buf(nni_http_conn *conn, nni_aio *aio) +http_rd_buf(nng_http *conn, nni_aio *aio) { size_t cnt = conn->rd_put - conn->rd_get; size_t n; @@ -324,7 +324,7 @@ http_rd_buf(nni_http_conn *conn, nni_aio *aio) } static void -http_rd_start(nni_http_conn *conn) +http_rd_start(nng_http *conn) { for (;;) { nni_aio *aio; @@ -363,13 +363,13 @@ http_rd_start(nni_http_conn *conn) static void http_rd_cb(void *arg) { - nni_http_conn *conn = arg; - nni_aio *aio = &conn->rd_aio; - nni_aio *uaio; - size_t cnt; - nng_err rv; - unsigned niov; - nni_iov *iov; + nng_http *conn = arg; + nni_aio *aio = &conn->rd_aio; + nni_aio *uaio; + size_t cnt; + nng_err rv; + unsigned niov; + nni_iov *iov; nni_mtx_lock(&conn->mtx); @@ -436,7 +436,7 @@ http_rd_cb(void *arg) static void http_rd_cancel(nni_aio *aio, void *arg, int rv) { - nni_http_conn *conn = arg; + nng_http *conn = arg; nni_mtx_lock(&conn->mtx); if (aio == conn->rd_uaio) { @@ -451,7 +451,7 @@ http_rd_cancel(nni_aio *aio, void *arg, int rv) } static void -http_rd_submit(nni_http_conn *conn, nni_aio *aio, enum read_flavor flavor) +http_rd_submit(nng_http *conn, nni_aio *aio, enum read_flavor flavor) { nni_aio_reset(aio); if (conn->closed) { @@ -469,7 +469,7 @@ http_rd_submit(nni_http_conn *conn, nni_aio *aio, enum read_flavor flavor) } static void -http_wr_start(nni_http_conn *conn) +http_wr_start(nng_http *conn) { nni_aio *aio; nni_iov *iov; @@ -492,11 +492,11 @@ http_wr_start(nni_http_conn *conn) static void http_wr_cb(void *arg) { - nni_http_conn *conn = arg; - nni_aio *aio = &conn->wr_aio; - nni_aio *uaio; - nng_err rv; - size_t n; + nng_http *conn = arg; + nni_aio *aio = &conn->wr_aio; + nni_aio *uaio; + nng_err rv; + size_t n; nni_mtx_lock(&conn->mtx); @@ -551,7 +551,7 @@ done: static void http_wr_cancel(nni_aio *aio, void *arg, int rv) { - nni_http_conn *conn = arg; + nng_http *conn = arg; nni_mtx_lock(&conn->mtx); if (aio == conn->wr_uaio) { @@ -566,7 +566,7 @@ http_wr_cancel(nni_aio *aio, void *arg, int rv) } static void -http_wr_submit(nni_http_conn *conn, nni_aio *aio, enum write_flavor flavor) +http_wr_submit(nng_http *conn, nni_aio *aio, enum write_flavor flavor) { nni_aio_reset(aio); if (conn->closed) { @@ -597,12 +597,12 @@ nni_http_conn_reset(nng_http *conn) nni_strfree(conn->uri); } conn->uri = NULL; - nni_http_set_version(conn, NNG_HTTP_VERSION_1_1); - nni_http_set_status(conn, 0, NULL); + nng_http_set_version(conn, NNG_HTTP_VERSION_1_1); + nng_http_set_status(conn, 0, NULL); } void -nni_http_read_req(nni_http_conn *conn, nni_aio *aio) +nni_http_read_req(nng_http *conn, nni_aio *aio) { // clear the sent flag (used for the server) conn->res_sent = false; @@ -613,7 +613,7 @@ nni_http_read_req(nni_http_conn *conn, nni_aio *aio) } void -nni_http_read_res(nni_http_conn *conn, nni_aio *aio) +nni_http_read_res(nng_http *conn, nni_aio *aio) { nni_mtx_lock(&conn->mtx); http_rd_submit(conn, aio, HTTP_RD_RES); @@ -621,7 +621,7 @@ nni_http_read_res(nni_http_conn *conn, nni_aio *aio) } void -nni_http_read_chunks(nni_http_conn *conn, nni_http_chunks *cl, nni_aio *aio) +nni_http_read_chunks(nng_http *conn, nni_http_chunks *cl, nni_aio *aio) { nni_aio_set_prov_data(aio, cl); @@ -632,7 +632,7 @@ nni_http_read_chunks(nni_http_conn *conn, nni_http_chunks *cl, nni_aio *aio) } void -nni_http_read_full(nni_http_conn *conn, nni_aio *aio) +nni_http_read_full(nng_http *conn, nni_aio *aio) { nni_aio_set_prov_data(aio, NULL); @@ -652,7 +652,7 @@ nni_http_read_discard(nng_http *conn, size_t discard, nng_aio *aio) } void -nni_http_read(nni_http_conn *conn, nni_aio *aio) +nni_http_read(nng_http *conn, nni_aio *aio) { nni_aio_set_prov_data(aio, NULL); @@ -692,13 +692,13 @@ http_snprintf(nng_http *conn, char *buf, size_t sz) if (conn->client) { len = snprintf(buf, sz, "%s %s %s\r\n", - nni_http_get_method(conn), nni_http_get_uri(conn), - nni_http_get_version(conn)); + nng_http_get_method(conn), nng_http_get_uri(conn), + nng_http_get_version(conn)); hdrs = &conn->req.data.hdrs; } else { len = snprintf(buf, sz, "%s %d %s\r\n", - nni_http_get_version(conn), nni_http_get_status(conn), - nni_http_get_reason(conn)); + nng_http_get_version(conn), nng_http_get_status(conn), + nng_http_get_reason(conn)); hdrs = &conn->res.data.hdrs; } @@ -819,7 +819,7 @@ nni_http_write_res(nng_http *conn, nni_aio *aio) } void -nni_http_write(nni_http_conn *conn, nni_aio *aio) +nni_http_write(nng_http *conn, nni_aio *aio) { nni_mtx_lock(&conn->mtx); http_wr_submit(conn, aio, HTTP_WR_RAW); @@ -827,7 +827,7 @@ nni_http_write(nni_http_conn *conn, nni_aio *aio) } void -nni_http_write_full(nni_http_conn *conn, nni_aio *aio) +nni_http_write_full(nng_http *conn, nni_aio *aio) { nni_mtx_lock(&conn->mtx); http_wr_submit(conn, aio, HTTP_WR_FULL); @@ -835,13 +835,13 @@ nni_http_write_full(nni_http_conn *conn, nni_aio *aio) } const char * -nni_http_get_version(nng_http *conn) +nng_http_get_version(nng_http *conn) { return (conn->vers); } -int -nni_http_set_version(nng_http *conn, const char *vers) +nng_err +nng_http_set_version(nng_http *conn, const char *vers) { static const char *http_versions[] = { // for efficiency, we order in most likely first @@ -864,7 +864,7 @@ nni_http_set_version(nng_http *conn, const char *vers) } void -nni_http_set_method(nng_http *conn, const char *method) +nng_http_set_method(nng_http *conn, const char *method) { if (method == NULL) { method = "GET"; @@ -875,13 +875,13 @@ nni_http_set_method(nng_http *conn, const char *method) } const char * -nni_http_get_method(nng_http *conn) +nng_http_get_method(nng_http *conn) { return (conn->meth); } nng_http_status -nni_http_get_status(nng_http *conn) +nng_http_get_status(nng_http *conn) { return (conn->code ? conn->code : NNG_HTTP_STATUS_OK); } @@ -987,13 +987,13 @@ nni_http_reason(nng_http_status code) } const char * -nni_http_get_reason(nng_http *conn) +nng_http_get_reason(nng_http *conn) { return (conn->rsn ? conn->rsn : nni_http_reason(conn->code)); } void -nni_http_set_status(nng_http *conn, nng_http_status status, const char *reason) +nng_http_set_status(nng_http *conn, nng_http_status status, const char *reason) { conn->code = status; char *dup = NULL; @@ -1043,8 +1043,8 @@ http_conn_set_error(nng_http *conn, nng_http_status status, const char *reason, conn->iserr = true; - nni_http_set_status(conn, status, reason); - reason = nni_http_get_reason(conn); + nng_http_set_status(conn, status, reason); + reason = nng_http_get_reason(conn); if (body == NULL) { snprintf(content, sizeof(content), prefix, status, reason, @@ -1074,7 +1074,7 @@ http_conn_set_error(nng_http *conn, nng_http_status status, const char *reason, if (strlen(body) > 0) { nni_http_set_content_type(conn, "text/html; charset=UTF-8"); // if the follow fails, live with it (ENOMEM, so no body). - (void) nni_http_copy_body(conn, body, strlen(body)); + (void) nng_http_copy_body(conn, body, strlen(body)); } return (0); } @@ -1103,7 +1103,7 @@ nni_http_set_redirect(nng_http *conn, nng_http_status status, } else if ((loc = nni_strdup(redirect)) == NULL) { return (NNG_ENOMEM); } - (void) nni_http_del_header(conn, "Location"); + (void) nng_http_del_header(conn, "Location"); nni_list_node_remove(&conn->location.node); nni_http_free_header(&conn->location); conn->location.name = "Location"; @@ -1151,13 +1151,13 @@ nni_http_set_content_type(nng_http *conn, const char *ctype) } const char * -nni_http_get_uri(nng_http *conn) +nng_http_get_uri(nng_http *conn) { return ((conn->uri && conn->uri[0]) ? conn->uri : "/"); } nng_err -nni_http_set_uri(nng_http *conn, const char *uri, const char *query) +nng_http_set_uri(nng_http *conn, const char *uri, const char *query) { size_t needed; const char *fmt; @@ -1298,7 +1298,7 @@ http_set_known_header(nng_http *conn, const char *key, const char *val) } nng_err -nni_http_add_header(nng_http *conn, const char *key, const char *val) +nng_http_add_header(nng_http *conn, const char *key, const char *val) { if (http_set_known_header(conn, key, val)) { return (NNG_OK); @@ -1318,7 +1318,7 @@ nni_http_set_static_header( headers = &conn->res.data.hdrs; } - nni_http_del_header(conn, key); + nng_http_del_header(conn, key); nni_list_node_remove(&h->node); h->alloc_header = false; h->static_name = true; @@ -1329,7 +1329,7 @@ nni_http_set_static_header( } nng_err -nni_http_set_header(nng_http *conn, const char *key, const char *val) +nng_http_set_header(nng_http *conn, const char *key, const char *val) { if (http_set_known_header(conn, key, val)) { return (0); @@ -1351,7 +1351,7 @@ http_del_header_one(nni_list *hdrs, const char *key) } void -nni_http_del_header(nng_http *conn, const char *key) +nng_http_del_header(nng_http *conn, const char *key) { nni_list *hdrs = conn->client ? &conn->req.data.hdrs : &conn->res.data.hdrs; @@ -1373,7 +1373,7 @@ http_get_header(const nni_list *hdrs, const char *key) } const char * -nni_http_get_header(nng_http *conn, const char *key) +nng_http_get_header(nng_http *conn, const char *key) { if (conn->client) { return (http_get_header(&conn->res.data.hdrs, key)); @@ -1383,7 +1383,7 @@ nni_http_get_header(nng_http *conn, const char *key) } void -nni_http_get_body(nng_http *conn, void **datap, size_t *sizep) +nng_http_get_body(nng_http *conn, void **datap, size_t *sizep) { if (conn->client) { *datap = conn->res.data.data; @@ -1430,7 +1430,7 @@ http_copy_data(nni_http_entity *entity, const void *data, size_t size) } void -nni_http_set_body(nng_http *conn, void *data, size_t size) +nng_http_set_body(nng_http *conn, void *data, size_t size) { if (conn->client) { http_set_data(&conn->req.data, data, size); @@ -1453,7 +1453,7 @@ nni_http_prune_body(nng_http *conn) } nng_err -nni_http_copy_body(nng_http *conn, const void *data, size_t size) +nng_http_copy_body(nng_http *conn, const void *data, size_t size) { nng_err rv; if (conn->client) { @@ -1469,7 +1469,7 @@ nni_http_copy_body(nng_http *conn, const void *data, size_t size) int nni_http_conn_getopt( - nni_http_conn *conn, const char *name, void *buf, size_t *szp, nni_type t) + nng_http *conn, const char *name, void *buf, size_t *szp, nni_type t) { int rv; nni_mtx_lock(&conn->mtx); @@ -1483,7 +1483,7 @@ nni_http_conn_getopt( } void -nni_http_conn_fini(nni_http_conn *conn) +nni_http_conn_fini(nng_http *conn) { nni_aio_stop(&conn->wr_aio); nni_aio_stop(&conn->rd_aio); @@ -1505,9 +1505,9 @@ nni_http_conn_fini(nni_http_conn *conn) } static nng_err -http_init(nni_http_conn **connp, nng_stream *data, bool client) +http_init(nng_http **connp, nng_stream *data, bool client) { - nni_http_conn *conn; + nng_http *conn; if ((conn = NNI_ALLOC_STRUCT(conn)) == NULL) { return (NNG_ENOMEM); @@ -1518,8 +1518,8 @@ http_init(nni_http_conn **connp, nng_stream *data, bool client) nni_aio_list_init(&conn->wrq); nni_http_req_init(&conn->req); nni_http_res_init(&conn->res); - nni_http_set_version(conn, NNG_HTTP_VERSION_1_1); - nni_http_set_method(conn, "GET"); + nng_http_set_version(conn, NNG_HTTP_VERSION_1_1); + nng_http_set_method(conn, "GET"); if ((conn->buf = nni_alloc(HTTP_BUFSIZE)) == NULL) { nni_http_conn_fini(conn); @@ -1549,7 +1549,7 @@ nni_http_init(nng_http **connp, nng_stream *stream, bool client) // private to the HTTP framework, used on the server bool -nni_http_res_sent(nni_http_conn *conn) +nni_http_res_sent(nng_http *conn) { return (conn->res_sent); } diff --git a/src/supplemental/http/http_msg.c b/src/supplemental/http/http_msg.c index 09470e31..17fb000a 100644 --- a/src/supplemental/http/http_msg.c +++ b/src/supplemental/http/http_msg.c @@ -142,7 +142,7 @@ http_parse_header(nng_http *conn, void *line) end--; } - return (nni_http_add_header(conn, key, val)); + return (nng_http_add_header(conn, key, val)); } void @@ -207,39 +207,39 @@ http_req_parse_line(nng_http *conn, void *line) char *uri; char *version; - if (nni_http_get_status(conn) >= NNG_HTTP_STATUS_BAD_REQUEST) { + if (nng_http_get_status(conn) >= NNG_HTTP_STATUS_BAD_REQUEST) { // we've already failed it, nothing else for us to do return (NNG_OK); } method = line; if ((uri = strchr(method, ' ')) == NULL) { - nni_http_set_status(conn, NNG_HTTP_STATUS_BAD_REQUEST, NULL); + nng_http_set_status(conn, NNG_HTTP_STATUS_BAD_REQUEST, NULL); return (NNG_OK); } *uri = '\0'; uri++; if ((version = strchr(uri, ' ')) == NULL) { - nni_http_set_status(conn, NNG_HTTP_STATUS_BAD_REQUEST, NULL); + nng_http_set_status(conn, NNG_HTTP_STATUS_BAD_REQUEST, NULL); return (NNG_OK); } *version = '\0'; version++; if (nni_url_canonify_uri(uri) != 0) { - nni_http_set_status(conn, NNG_HTTP_STATUS_BAD_REQUEST, NULL); + nng_http_set_status(conn, NNG_HTTP_STATUS_BAD_REQUEST, NULL); return (NNG_OK); } - if (nni_http_set_version(conn, version)) { - nni_http_set_status( + if (nng_http_set_version(conn, version)) { + nng_http_set_status( conn, NNG_HTTP_STATUS_HTTP_VERSION_NOT_SUPP, NULL); return (NNG_OK); } - nni_http_set_method(conn, method); + nng_http_set_method(conn, method); // this one only can fail due to ENOMEM - return (nni_http_set_uri(conn, uri, NULL)); + return (nng_http_set_uri(conn, uri, NULL)); } static nng_err @@ -268,9 +268,9 @@ http_res_parse_line(nng_http *conn, uint8_t *line) return (NNG_EPROTO); } - nni_http_set_status(conn, (uint16_t) status, reason); + nng_http_set_status(conn, (uint16_t) status, reason); - return (nni_http_set_version(conn, version)); + return (nng_http_set_version(conn, version)); } // nni_http_req_parse parses a request (but not any attached entity data). diff --git a/src/supplemental/http/http_public.c b/src/supplemental/http/http_public.c index 054080c0..4331831a 100644 --- a/src/supplemental/http/http_public.c +++ b/src/supplemental/http/http_public.c @@ -15,642 +15,128 @@ // Symbols in this file are "public" versions of the HTTP API. // These are suitable for exposure to applications. -const char * -nng_http_get_header(nng_http *conn, const char *key) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_get_header(conn, key)); -#else - NNI_ARG_UNUSED(conn); - NNI_ARG_UNUSED(key); - return (NULL); -#endif -} - -nng_err -nng_http_set_header(nng_http *conn, const char *key, const char *val) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_set_header(conn, key, val)); -#else - NNI_ARG_UNUSED(conn); - NNI_ARG_UNUSED(key); - NNI_ARG_UNUSED(val); - return (NNG_ENOTSUP); -#endif -} - -nng_err -nng_http_add_header(nng_http *conn, const char *key, const char *val) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_add_header(conn, key, val)); -#else - NNI_ARG_UNUSED(conn); - NNI_ARG_UNUSED(key); - NNI_ARG_UNUSED(val); - return (NNG_ENOTSUP); -#endif -} - -void -nng_http_del_header(nng_http *conn, const char *key) -{ -#ifdef NNG_SUPP_HTTP - nni_http_del_header(conn, key); -#else - NNI_ARG_UNUSED(conn); - NNI_ARG_UNUSED(key); -#endif -} - -void -nng_http_set_body(nng_http *conn, void *data, size_t sz) -{ -#ifdef NNG_SUPP_HTTP - nni_http_set_body(conn, data, sz); -#else - NNI_ARG_UNUSED(conn); - NNI_ARG_UNUSED(data); - NNI_ARG_UNUSED(sz); - return (NNG_ENOTSUP); -#endif -} - -nng_err -nng_http_copy_body(nng_http *conn, const void *data, size_t len) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_copy_body(conn, data, len)); -#else - NNI_ARG_UNUSED(conn); - NNI_ARG_UNUSED(data); - NNI_ARG_UNUSED(len); - return (NNG_ENOTSUP); -#endif -} - -void -nng_http_get_body(nng_http *conn, void **datap, size_t *lenp) -{ -#ifdef NNG_SUPP_HTTP - nni_http_get_body(conn, datap, lenp); -#else - NNI_ARG_UNUSED(conn); - NNI_ARG_UNUSED(datap); - NNI_ARG_UNUSED(lenp); -#endif -} - -const char * -nng_http_get_uri(nng_http *conn) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_get_uri(conn)); -#else - NNI_ARG_UNUSED(req); - return (NULL); -#endif -} - -nng_err -nng_http_set_uri(nng_http *conn, const char *uri, const char *query) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_set_uri(conn, uri, query)); -#else - NNI_ARG_UNUSED(conn); - NNI_ARG_UNUSED(uri); - NNI_ARG_UNUSED(query); - return (NNG_ENOTSUP); -#endif -} - -const char * -nng_http_get_version(nng_http *conn) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_get_version(conn)); -#else - NNI_ARG_UNUSED(res); - return (NULL); -#endif -} - -void -nng_http_set_status(nng_http *conn, nng_http_status status, const char *reason) -{ -#ifdef NNG_SUPP_HTTP - nni_http_set_status(conn, status, reason); -#else - NNI_ARG_UNUSED(res); - NNI_ARG_UNUSED(status); - NNI_ARG_UNUSED(reason); -#endif -} - -nng_http_status -nng_http_get_status(nng_http *conn) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_get_status(conn)); -#else - NNI_ARG_UNUSED(res); - NNI_ARG_UNUSED(status); - return (0); -#endif -} - -const char * -nng_http_get_reason(nng_http *conn) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_get_reason(conn)); -#else - NNI_ARG_UNUSED(res); - NNI_ARG_UNUSED(status); - return (0); -#endif -} - -nng_err -nng_http_set_version(nng_http *conn, const char *version) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_set_version(conn, version)); -#else - return (NNG_ENOTSUP); -#endif -} - -void -nng_http_set_method(nng_http *conn, const char *method) -{ -#ifdef NNG_SUPP_HTTP - nni_http_set_method(conn, method); -#else - NNI_ARG_UNUSED(conn); - NNI_ARG_UNUSED(method); -#endif -} - -const char * -nng_http_get_method(nng_http *conn) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_get_method(conn)); -#else - NNI_ARG_UNUSED(conn); - return (NULL); -#endif -} - void nng_http_close(nng_http *conn) { -#ifdef NNG_SUPP_HTTP // API version of this closes *and* frees the structure. nni_http_conn_fini(conn); -#else - NNI_ARG_UNUSED(conn); -#endif } void nng_http_read(nng_http *conn, nng_aio *aio) { -#ifdef NNG_SUPP_HTTP nni_http_read(conn, aio); -#else - NNI_ARG_UNUSED(conn); - nni_aio_finish_error(aio, NNG_ENOTSUP); -#endif } void nng_http_read_all(nng_http *conn, nng_aio *aio) { -#ifdef NNG_SUPP_HTTP nni_http_read_full(conn, aio); -#else - NNI_ARG_UNUSED(conn); - nni_aio_finish_error(aio, NNG_ENOTSUP); -#endif } void nng_http_write(nng_http *conn, nng_aio *aio) { -#ifdef NNG_SUPP_HTTP nni_http_write(conn, aio); -#else - NNI_ARG_UNUSED(conn); - nni_aio_finish_error(aio, NNG_ENOTSUP); -#endif } void nng_http_write_all(nng_http *conn, nng_aio *aio) { -#ifdef NNG_SUPP_HTTP nni_http_write_full(conn, aio); -#else - NNI_ARG_UNUSED(conn); - NNI_ARG_UNUSED(aio); -#endif } void nng_http_write_request(nng_http *conn, nng_aio *aio) { -#ifdef NNG_SUPP_HTTP nni_http_write_req(conn, aio); -#else - NNI_ARG_UNUSED(conn); - nni_aio_finish_error(aio, NNG_ENOTSUP); -#endif } void nng_http_write_response(nng_http *conn, nng_aio *aio) { -#ifdef NNG_SUPP_HTTP nni_http_write_res(conn, aio); -#else - NNI_ARG_UNUSED(conn); - nni_aio_finish_error(aio, NNG_ENOTSUP); -#endif } void nng_http_read_response(nng_http *conn, nng_aio *aio) { -#ifdef NNG_SUPP_HTTP nni_http_read_res(conn, aio); -#else - NNI_ARG_UNUSED(conn); - NNI_ARG_UNUSED(res); - nni_aio_finish_error(aio, NNG_ENOTSUP); -#endif -} - -nng_err -nng_http_handler_alloc( - nng_http_handler **hp, const char *uri, nng_http_handler_func cb) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_handler_alloc(hp, uri, cb)); -#else - NNI_ARG_UNUSED(hp); - NNI_ARG_UNUSED(uri); - NNI_ARG_UNUSED(cb); - return (NNG_ENOTSUP); -#endif -} - -void -nng_http_handler_free(nng_http_handler *h) -{ -#ifdef NNG_SUPP_HTTP - nni_http_handler_free(h); -#else - NNI_ARG_UNUSED(h); -#endif -} - -nng_err -nng_http_handler_file(nng_http_handler **hp, const char *uri, const char *path, - const char *ctype) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_handler_file(hp, uri, path, ctype)); -#else - NNI_ARG_UNUSED(hp); - NNI_ARG_UNUSED(uri); - NNI_ARG_UNUSED(path); - return (NNG_ENOTSUP); -#endif -} - -nng_err -nng_http_handler_directory( - nng_http_handler **hp, const char *uri, const char *path) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_handler_directory(hp, uri, path)); -#else - NNI_ARG_UNUSED(hp); - NNI_ARG_UNUSED(uri); - NNI_ARG_UNUSED(path); - return (NNG_ENOTSUP); -#endif -} - -nng_err -nng_http_handler_redirect(nng_http_handler **hp, const char *uri, - nng_http_status status, const char *where) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_handler_redirect(hp, uri, status, where)); -#else - NNI_ARG_UNUSED(hp); - NNI_ARG_UNUSED(uri); - NNI_ARG_UNUSED(status); - NNI_ARG_UNUSED(where); - return (NNG_ENOTSUP); -#endif -} - -nng_err -nng_http_handler_static(nng_http_handler **hp, const char *uri, - const void *data, size_t size, const char *ctype) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_handler_static(hp, uri, data, size, ctype)); -#else - NNI_ARG_UNUSED(hp); - NNI_ARG_UNUSED(uri); - NNI_ARG_UNUSED(data); - NNI_ARG_UNUSED(size); - NNI_ARG_UNUSED(ctype); - return (NNG_ENOTSUP); -#endif -} - -void -nng_http_handler_set_method(nng_http_handler *h, const char *meth) -{ -#ifdef NNG_SUPP_HTTP - nni_http_handler_set_method(h, meth); -#else - NNI_ARG_UNUSED(h); - NNI_ARG_UNUSED(meth); -#endif -} - -void -nng_http_handler_collect_body(nng_http_handler *h, bool want, size_t len) -{ -#ifdef NNG_SUPP_HTTP - nni_http_handler_collect_body(h, want, len); -#else - NNI_ARG_UNUSED(h); - NNI_ARG_UNUSED(want); - NNI_ARG_UNUSED(len); -#endif -} - -void -nng_http_handler_set_host(nng_http_handler *h, const char *host) -{ -#ifdef NNG_SUPP_HTTP - nni_http_handler_set_host(h, host); -#else - NNI_ARG_UNUSED(h); - NNI_ARG_UNUSED(host); -#endif -} - -void -nng_http_handler_set_tree(nng_http_handler *h) -{ -#ifdef NNG_SUPP_HTTP - nni_http_handler_set_tree(h); -#else - NNI_ARG_UNUSED(h); -#endif -} - -void -nng_http_handler_set_data(nng_http_handler *h, void *dat, void (*dtor)(void *)) -{ -#ifdef NNG_SUPP_HTTP - nni_http_handler_set_data(h, dat, dtor); -#else - NNI_ARG_UNUSED(h); - NNI_ARG_UNUSED(dat); - NNI_ARG_UNUSED(dtor); -#endif } nng_err nng_http_server_hold(nng_http_server **srvp, const nng_url *url) { -#ifdef NNG_SUPP_HTTP return (nni_http_server_init(srvp, url)); -#else - NNI_ARG_UNUSED(srvp); - NNI_ARG_UNUSED(url); - return (NNG_ENOTSUP); -#endif } void nng_http_server_release(nng_http_server *srv) { -#ifdef NNG_SUPP_HTTP nni_http_server_fini(srv); -#else - NNI_ARG_UNUSED(srv); -#endif } nng_err nng_http_server_start(nng_http_server *srv) { -#ifdef NNG_SUPP_HTTP return (nni_http_server_start(srv)); -#else - NNI_ARG_UNUSED(srv); - return (NNG_ENOTSUP); -#endif } void nng_http_server_stop(nng_http_server *srv) { -#ifdef NNG_SUPP_HTTP nni_http_server_stop(srv); -#else - NNI_ARG_UNUSED(srv); -#endif } nng_err nng_http_server_add_handler(nng_http_server *srv, nng_http_handler *h) { -#ifdef NNG_SUPP_HTTP return (nni_http_server_add_handler(srv, h)); -#else - NNI_ARG_UNUSED(srv); - NNI_ARG_UNUSED(h); - return (NNG_ENOTSUP); -#endif } nng_err nng_http_server_del_handler(nng_http_server *srv, nng_http_handler *h) { -#ifdef NNG_SUPP_HTTP return (nni_http_server_del_handler(srv, h)); -#else - NNI_ARG_UNUSED(srv); - NNI_ARG_UNUSED(h); - return (NNG_ENOTSUP); -#endif } nng_err nng_http_server_set_error_page( nng_http_server *srv, nng_http_status code, const char *body) { -#ifdef NNG_SUPP_HTTP return (nni_http_server_set_error_page(srv, code, body)); -#else - NNI_ARG_UNUSED(srv); - NNI_ARG_UNUSED(code); - NNI_ARG_UNUSED(body); - return (NNG_ENOTSUP); -#endif } nng_err nng_http_server_set_tls(nng_http_server *srv, nng_tls_config *cfg) { -#if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) return (nni_http_server_set_tls(srv, cfg)); -#else - NNI_ARG_UNUSED(srv); - NNI_ARG_UNUSED(cfg); - return (NNG_ENOTSUP); -#endif } nng_err nng_http_server_get_tls(nng_http_server *srv, nng_tls_config **cfg) { -#if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) return (nni_http_server_get_tls(srv, cfg)); -#else - NNI_ARG_UNUSED(srv); - NNI_ARG_UNUSED(cfg); - return (NNG_ENOTSUP); -#endif } nng_err nng_http_server_get_addr(nng_http_server *srv, nng_sockaddr *addr) { -#ifdef NNG_SUPP_HTTP size_t size = sizeof(nng_sockaddr); if (srv == NULL || addr == NULL) return NNG_EINVAL; return (nni_http_server_get( srv, NNG_OPT_LOCADDR, addr, &size, NNI_TYPE_SOCKADDR)); -#else - NNI_ARG_UNUSED(srv); - NNI_ARG_UNUSED(addr); - return (NNG_ENOTSUP); -#endif } nng_err nng_http_server_error(nng_http_server *srv, nng_http *conn) { -#ifdef NNG_SUPP_HTTP return (nni_http_server_error(srv, conn)); -#else - NNI_ARG_UNUSED(srv); - NNI_ARG_UNUSED(res); - return (NNG_ENOTSUP); -#endif -} - -nng_err -nng_http_hijack(nng_http *conn) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_hijack(conn)); -#else - NNI_ARG_UNUSED(conn); - return (NNG_ENOTSUP); -#endif -} - -nng_err -nng_http_client_alloc(nng_http_client **clip, const nng_url *url) -{ -#ifdef NNG_SUPP_HTTP - return (nni_http_client_init(clip, url)); -#else - NNI_ARG_UNUSED(clip); - NNI_ARG_UNUSED(url); - return (NNG_ENOTSUP); -#endif -} - -void -nng_http_client_free(nng_http_client *cli) -{ -#ifdef NNG_SUPP_HTTP - nni_http_client_fini(cli); -#else - NNI_ARG_UNUSED(cli); -#endif -} - -nng_err -nng_http_client_set_tls(nng_http_client *cli, nng_tls_config *cfg) -{ -#if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) - return (nni_http_client_set_tls(cli, cfg)); -#else - NNI_ARG_UNUSED(cli); - NNI_ARG_UNUSED(cfg); - return (NNG_ENOTSUP); -#endif -} - -nng_err -nng_http_client_get_tls(nng_http_client *cli, nng_tls_config **cfgp) -{ -#if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) - return (nni_http_client_get_tls(cli, cfgp)); -#else - NNI_ARG_UNUSED(cli); - NNI_ARG_UNUSED(cfgp); - return (NNG_ENOTSUP); -#endif -} - -void -nng_http_client_connect(nng_http_client *cli, nng_aio *aio) -{ -#ifdef NNG_SUPP_HTTP - nni_http_client_connect(cli, aio); -#else - NNI_ARG_UNUSED(cli); - nni_aio_finish_error(aio, NNG_ENOTSUP); -#endif -} - -void -nng_http_transact(nng_http *conn, nng_aio *aio) -{ -#ifdef NNG_SUPP_HTTP - nni_http_transact_conn(conn, aio); -#else - NNI_ARG_UNUSED(conn); - nni_aio_finish_error(aio, NNG_ENOTSUP); -#endif } void nng_http_reset(nng_http *conn) { -#ifdef NNG_SUPP_HTTP nni_http_conn_reset(conn); -#else - NNI_ARG_UNUSED(req); -#endif } diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c index 725e824f..717f9a55 100644 --- a/src/supplemental/http/http_server.c +++ b/src/supplemental/http/http_server.c @@ -48,8 +48,8 @@ struct nng_http_handler { typedef struct http_sconn { nni_list_node node; - nni_http_conn *conn; - nni_http_server *server; + nng_http *conn; + nng_http_server *server; nng_http_handler *handler; // set if we deferred to read body nng_http_handler *release; // set if we dispatched handler bool close; @@ -115,7 +115,7 @@ http_handler_fini(void *arg) } void -nni_http_handler_free(nng_http_handler *h) +nng_http_handler_free(nng_http_handler *h) { if (h) { nni_refcnt_rele(&h->ref); @@ -123,7 +123,7 @@ nni_http_handler_free(nng_http_handler *h) } nng_err -nni_http_handler_alloc( +nng_http_handler_alloc( nng_http_handler **hp, const char *uri, nng_http_handler_func cb) { nng_http_handler *h; @@ -152,14 +152,14 @@ nni_http_handler_alloc( } void -nni_http_handler_collect_body(nng_http_handler *h, bool want, size_t maxbody) +nng_http_handler_collect_body(nng_http_handler *h, bool want, size_t maxbody) { h->getbody = want; h->maxbody = maxbody; } void -nni_http_handler_set_data(nng_http_handler *h, void *data, nni_cb dtor) +nng_http_handler_set_data(nng_http_handler *h, void *data, nni_cb dtor) { NNI_ASSERT(!nni_atomic_get_bool(&h->busy)); h->data = data; @@ -167,7 +167,7 @@ nni_http_handler_set_data(nng_http_handler *h, void *data, nni_cb dtor) } const char * -nni_http_handler_get_uri(nng_http_handler *h) +nng_http_handler_get_uri(nng_http_handler *h) { if (strlen(h->uri) == 0) { return ("/"); @@ -176,14 +176,14 @@ nni_http_handler_get_uri(nng_http_handler *h) } void -nni_http_handler_set_tree(nng_http_handler *h) +nng_http_handler_set_tree(nng_http_handler *h) { NNI_ASSERT(!nni_atomic_get_bool(&h->busy)); h->tree = true; } void -nni_http_handler_set_host(nng_http_handler *h, const char *host) +nng_http_handler_set_host(nng_http_handler *h, const char *host) { NNI_ASSERT(!nni_atomic_get_bool(&h->busy)); @@ -217,7 +217,7 @@ nni_http_handler_set_host(nng_http_handler *h, const char *host) } void -nni_http_handler_set_method(nng_http_handler *h, const char *method) +nng_http_handler_set_method(nng_http_handler *h, const char *method) { NNI_ASSERT(!nni_atomic_get_bool(&h->busy)); if (method == NULL) { @@ -266,7 +266,7 @@ http_sc_reap(void *arg) static void http_sconn_close(http_sconn *sc) { - nni_http_conn *conn; + nng_http *conn; if (nni_atomic_flag_test_and_set(&sc->closed)) { return; @@ -346,7 +346,7 @@ http_sconn_error(http_sconn *sc, nng_http_status err) } nng_err -nni_http_hijack(nni_http_conn *conn) +nng_http_hijack(nng_http *conn) { http_sconn *sc; @@ -488,7 +488,7 @@ http_sconn_rxdone(void *arg) // If the connection was 1.0, or a connection: close was // requested, then mark this close on our end. - if ((val = nni_http_get_header(sc->conn, "Connection")) != NULL) { + if ((val = nng_http_get_header(sc->conn, "Connection")) != NULL) { // HTTP 1.1 says these have to be case insensitive if (nni_strcasestr(val, "close") != NULL) { // In theory this could falsely match some other weird @@ -501,7 +501,7 @@ http_sconn_rxdone(void *arg) } sc->unconsumed_body = 0; - if ((cls = nni_http_get_header(sc->conn, "Content-Length")) != NULL) { + if ((cls = nng_http_get_header(sc->conn, "Content-Length")) != NULL) { char *end; sc->unconsumed_body = strtoull(cls, &end, 10); if ((end == NULL) && (*end != '\0')) { @@ -511,7 +511,7 @@ http_sconn_rxdone(void *arg) } } - host = nni_http_get_header(sc->conn, "Host"); + host = nng_http_get_header(sc->conn, "Host"); if ((host == NULL) && (needhost)) { // Per RFC 2616 14.23 we have to send 400 status here. http_sconn_error(sc, NNG_HTTP_STATUS_BAD_REQUEST); @@ -548,7 +548,7 @@ http_sconn_rxdone(void *arg) break; } // So, what about the method? - val = nni_http_get_method(sc->conn); + val = nng_http_get_method(sc->conn); if (strcmp(val, h->method) == 0) { break; } @@ -614,8 +614,8 @@ finish: // make sure the response is freshly initialized nni_http_res_reset(nni_http_conn_res(sc->conn)); - nni_http_set_version(sc->conn, NNG_HTTP_VERSION_1_1); - nni_http_set_status(sc->conn, 0, NULL); + nng_http_set_version(sc->conn, NNG_HTTP_VERSION_1_1); + nng_http_set_status(sc->conn, 0, NULL); nni_refcnt_hold(&h->ref); h->cb(sc->conn, h->data, &sc->cbaio); @@ -656,14 +656,14 @@ http_sconn_cbdone(void *arg) const char *val; const char *method; nng_http_status status; - val = nni_http_get_header(sc->conn, "Connection"); - status = nni_http_get_status(sc->conn); - method = nni_http_get_method(sc->conn); + val = nng_http_get_header(sc->conn, "Connection"); + status = nng_http_get_status(sc->conn); + method = nng_http_get_method(sc->conn); if ((val != NULL) && (strstr(val, "close") != NULL)) { sc->close = true; } if (sc->close) { - nni_http_set_header(sc->conn, "Connection", "close"); + nng_http_set_header(sc->conn, "Connection", "close"); } if ((strcmp(method, "HEAD") == 0) && status >= 200 && status <= 299) { @@ -996,7 +996,7 @@ nni_http_server_error(nni_http_server *s, nng_http *conn) { http_error *epage; char *body = NULL; - nng_http_status code = nni_http_get_status(conn); + nng_http_status code = nng_http_get_status(conn); nng_err rv; nni_mtx_lock(&s->errors_mtx); @@ -1193,8 +1193,8 @@ http_handle_file(nng_http *conn, void *arg, nni_aio *aio) nni_aio_finish(aio, NNG_OK, 0); return; } - if (((rv = nni_http_set_header(conn, "Content-Type", ctype)) != 0) || - ((rv = nni_http_copy_body(conn, data, size)) != 0)) { + if (((rv = nng_http_set_header(conn, "Content-Type", ctype)) != 0) || + ((rv = nng_http_copy_body(conn, data, size)) != 0)) { nni_free(data, size); nni_aio_finish_error(aio, rv); return; @@ -1219,7 +1219,7 @@ http_file_free(void *arg) } nng_err -nni_http_handler_file(nng_http_handler **hpp, const char *uri, +nng_http_handler_file(nng_http_handler **hpp, const char *uri, const char *path, const char *ctype) { nng_http_handler *h; @@ -1244,15 +1244,15 @@ nni_http_handler_file(nng_http_handler **hpp, const char *uri, return (NNG_ENOMEM); } - if ((rv = nni_http_handler_alloc(&h, uri, http_handle_file)) != 0) { + if ((rv = nng_http_handler_alloc(&h, uri, http_handle_file)) != 0) { http_file_free(hf); return (rv); } - nni_http_handler_set_data(h, hf, http_file_free); + nng_http_handler_set_data(h, hf, http_file_free); // We don't permit a body for getting a file. - nni_http_handler_collect_body(h, true, 0); + nng_http_handler_collect_body(h, true, 0); *hpp = h; return (NNG_OK); @@ -1267,7 +1267,7 @@ http_handle_dir(nng_http *conn, void *arg, nng_aio *aio) http_file *hf = arg; const char *path = hf->path; const char *base = hf->base; - const char *uri = nni_http_get_uri(conn); + const char *uri = nng_http_get_uri(conn); const char *ctype; char *dst; size_t len; @@ -1384,7 +1384,7 @@ http_handle_dir(nng_http *conn, void *arg, nng_aio *aio) } nng_err -nni_http_handler_directory( +nng_http_handler_directory( nng_http_handler **hpp, const char *uri, const char *path) { http_file *hf; @@ -1400,7 +1400,7 @@ nni_http_handler_directory( return (NNG_ENOMEM); } - if ((rv = nni_http_handler_alloc(&h, uri, http_handle_dir)) != 0) { + if ((rv = nng_http_handler_alloc(&h, uri, http_handle_dir)) != 0) { http_file_free(hf); return (rv); } @@ -1429,7 +1429,7 @@ http_handle_redirect(nng_http *conn, void *data, nng_aio *aio) const char *uri; base = hr->from; // base uri - uri = nni_http_get_uri(conn); + uri = nng_http_get_uri(conn); // If we are doing a full tree, then include the entire suffix. if (strncmp(uri, base, strlen(base)) == 0) { @@ -1447,7 +1447,7 @@ http_handle_redirect(nng_http *conn, void *data, nng_aio *aio) // keeps us from having to consume the entity body, we can just // discard it. if (((rv = nni_http_set_redirect(conn, hr->code, NULL, loc)) != 0) || - ((rv = nni_http_set_header(conn, "Connection", "close")) != 0)) { + ((rv = nng_http_set_header(conn, "Connection", "close")) != 0)) { if (loc != hr->where) { nni_strfree(loc); } @@ -1476,7 +1476,7 @@ http_redirect_free(void *arg) } nng_err -nni_http_handler_redirect(nng_http_handler **hpp, const char *uri, +nng_http_handler_redirect(nng_http_handler **hpp, const char *uri, nng_http_status status, const char *where) { nng_http_handler *h; @@ -1496,19 +1496,19 @@ nni_http_handler_redirect(nng_http_handler **hpp, const char *uri, } hr->code = status; - if ((rv = nni_http_handler_alloc(&h, uri, http_handle_redirect)) != + if ((rv = nng_http_handler_alloc(&h, uri, http_handle_redirect)) != 0) { http_redirect_free(hr); return (rv); } - nni_http_handler_set_method(h, NULL); + nng_http_handler_set_method(h, NULL); - nni_http_handler_set_data(h, hr, http_redirect_free); + nng_http_handler_set_data(h, hr, http_redirect_free); // We don't need to collect the body at all, because the handler // just discards the content and closes the connection. - nni_http_handler_collect_body(h, false, 0); + nng_http_handler_collect_body(h, false, 0); *hpp = h; return (NNG_OK); @@ -1531,8 +1531,8 @@ http_handle_static(nng_http *conn, void *data, nni_aio *aio) } // this cannot fail (no dynamic allocation) - (void) nni_http_set_header(conn, "Content-Type", ctype); - nni_http_set_body(conn, hs->data, hs->size); + (void) nng_http_set_header(conn, "Content-Type", ctype); + nng_http_set_body(conn, hs->data, hs->size); nng_http_set_status(conn, NNG_HTTP_STATUS_OK, NULL); @@ -1552,7 +1552,7 @@ http_static_free(void *arg) } nng_err -nni_http_handler_static(nng_http_handler **hpp, const char *uri, +nng_http_handler_static(nng_http_handler **hpp, const char *uri, const void *data, size_t size, const char *ctype) { nng_http_handler *h; @@ -1570,15 +1570,15 @@ nni_http_handler_static(nng_http_handler **hpp, const char *uri, hs->size = size; memcpy(hs->data, data, size); - if ((rv = nni_http_handler_alloc(&h, uri, http_handle_static)) != 0) { + if ((rv = nng_http_handler_alloc(&h, uri, http_handle_static)) != 0) { http_static_free(hs); return (rv); } - nni_http_handler_set_data(h, hs, http_static_free); + nng_http_handler_set_data(h, hs, http_static_free); // We don't permit a body for getting static data. - nni_http_handler_collect_body(h, true, 0); + nng_http_handler_collect_body(h, true, 0); *hpp = h; return (NNG_OK); diff --git a/src/supplemental/http/http_stubs.c b/src/supplemental/http/http_stubs.c new file mode 100644 index 00000000..f2684e08 --- /dev/null +++ b/src/supplemental/http/http_stubs.c @@ -0,0 +1,431 @@ +// +// Copyright 2025 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 +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +#include "core/defs.h" +#include "nng/http.h" + +// Stubs for common API functions. +// +const char * +nng_http_get_header(nng_http *conn, const char *key) +{ + NNI_ARG_UNUSED(conn); + NNI_ARG_UNUSED(key); + return (NULL); +} + +nng_err +nng_http_set_header(nng_http *conn, const char *key, const char *val) +{ + NNI_ARG_UNUSED(conn); + NNI_ARG_UNUSED(key); + NNI_ARG_UNUSED(val); + return (NNG_ENOTSUP); +} + +nng_err +nng_http_add_header(nng_http *conn, const char *key, const char *val) +{ + NNI_ARG_UNUSED(conn); + NNI_ARG_UNUSED(key); + NNI_ARG_UNUSED(val); + return (NNG_ENOTSUP); +} + +void +nng_http_del_header(nng_http *conn, const char *key) +{ + NNI_ARG_UNUSED(conn); + NNI_ARG_UNUSED(key); +} + +void +nng_http_set_body(nng_http *conn, void *data, size_t sz) +{ + NNI_ARG_UNUSED(conn); + NNI_ARG_UNUSED(data); + NNI_ARG_UNUSED(sz); +} + +nng_err +nng_http_copy_body(nng_http *conn, const void *data, size_t len) +{ + NNI_ARG_UNUSED(conn); + NNI_ARG_UNUSED(data); + NNI_ARG_UNUSED(len); + return (NNG_ENOTSUP); +} + +void +nng_http_get_body(nng_http *conn, void **datap, size_t *lenp) +{ + NNI_ARG_UNUSED(conn); + NNI_ARG_UNUSED(datap); + NNI_ARG_UNUSED(lenp); +} + +const char * +nng_http_get_uri(nng_http *conn) +{ + NNI_ARG_UNUSED(conn); + return (NULL); +} + +nng_err +nng_http_set_uri(nng_http *conn, const char *uri, const char *query) +{ + NNI_ARG_UNUSED(conn); + NNI_ARG_UNUSED(uri); + NNI_ARG_UNUSED(query); + return (NNG_ENOTSUP); +} + +const char * +nng_http_get_version(nng_http *conn) +{ + NNI_ARG_UNUSED(conn); + return (NULL); +} + +void +nng_http_set_status(nng_http *conn, nng_http_status status, const char *reason) +{ + NNI_ARG_UNUSED(conn); + NNI_ARG_UNUSED(status); + NNI_ARG_UNUSED(reason); +} + +nng_http_status +nng_http_get_status(nng_http *conn) +{ + NNI_ARG_UNUSED(conn); + return (0); +} + +const char * +nng_http_get_reason(nng_http *conn) +{ + NNI_ARG_UNUSED(conn); + return (NULL); +} + +nng_err +nng_http_set_version(nng_http *conn, const char *version) +{ + NNI_ARG_UNUSED(conn); + NNI_ARG_UNUSED(version); + return (NNG_ENOTSUP); +} + +void +nng_http_set_method(nng_http *conn, const char *method) +{ + NNI_ARG_UNUSED(conn); + NNI_ARG_UNUSED(method); +} + +const char * +nng_http_get_method(nng_http *conn) +{ + NNI_ARG_UNUSED(conn); + return (NULL); +} + +void +nng_http_close(nng_http *conn) +{ + NNI_ARG_UNUSED(conn); +} + +void +nng_http_read(nng_http *conn, nng_aio *aio) +{ + NNI_ARG_UNUSED(conn); + nng_aio_finish(aio, NNG_ENOTSUP); +} + +void +nng_http_read_all(nng_http *conn, nng_aio *aio) +{ + NNI_ARG_UNUSED(conn); + nng_aio_finish(aio, NNG_ENOTSUP); +} + +void +nng_http_write(nng_http *conn, nng_aio *aio) +{ + NNI_ARG_UNUSED(conn); + nng_aio_finish(aio, NNG_ENOTSUP); +} + +void +nng_http_write_all(nng_http *conn, nng_aio *aio) +{ + NNI_ARG_UNUSED(conn); + nng_aio_finish(aio, NNG_ENOTSUP); +} + +void +nng_http_write_request(nng_http *conn, nng_aio *aio) +{ + NNI_ARG_UNUSED(conn); + nng_aio_finish(aio, NNG_ENOTSUP); +} + +void +nng_http_write_response(nng_http *conn, nng_aio *aio) +{ + NNI_ARG_UNUSED(conn); + nng_aio_finish(aio, NNG_ENOTSUP); +} + +void +nng_http_read_response(nng_http *conn, nng_aio *aio) +{ + NNI_ARG_UNUSED(conn); + nng_aio_finish(aio, NNG_ENOTSUP); +} + +nng_err +nng_http_handler_alloc( + nng_http_handler **hp, const char *uri, nng_http_handler_func cb) +{ + NNI_ARG_UNUSED(hp); + NNI_ARG_UNUSED(uri); + NNI_ARG_UNUSED(cb); + return (NNG_ENOTSUP); +} + +void +nng_http_handler_free(nng_http_handler *h) +{ + NNI_ARG_UNUSED(h); +} + +nng_err +nng_http_handler_file(nng_http_handler **hp, const char *uri, const char *path, + const char *ctype) +{ + NNI_ARG_UNUSED(hp); + NNI_ARG_UNUSED(uri); + NNI_ARG_UNUSED(path); + NNI_ARG_UNUSED(ctype); + return (NNG_ENOTSUP); +} + +nng_err +nng_http_handler_directory( + nng_http_handler **hp, const char *uri, const char *path) +{ + NNI_ARG_UNUSED(hp); + NNI_ARG_UNUSED(uri); + NNI_ARG_UNUSED(path); + return (NNG_ENOTSUP); +} + +nng_err +nng_http_handler_redirect(nng_http_handler **hp, const char *uri, + nng_http_status status, const char *where) +{ + NNI_ARG_UNUSED(hp); + NNI_ARG_UNUSED(uri); + NNI_ARG_UNUSED(status); + NNI_ARG_UNUSED(where); + return (NNG_ENOTSUP); +} + +nng_err +nng_http_handler_static(nng_http_handler **hp, const char *uri, + const void *data, size_t size, const char *ctype) +{ + NNI_ARG_UNUSED(hp); + NNI_ARG_UNUSED(uri); + NNI_ARG_UNUSED(data); + NNI_ARG_UNUSED(size); + NNI_ARG_UNUSED(ctype); + return (NNG_ENOTSUP); +} + +void +nng_http_handler_set_method(nng_http_handler *h, const char *meth) +{ + NNI_ARG_UNUSED(h); + NNI_ARG_UNUSED(meth); +} + +void +nng_http_handler_collect_body(nng_http_handler *h, bool want, size_t len) +{ + NNI_ARG_UNUSED(h); + NNI_ARG_UNUSED(want); + NNI_ARG_UNUSED(len); +} + +void +nng_http_handler_set_host(nng_http_handler *h, const char *host) +{ + NNI_ARG_UNUSED(h); + NNI_ARG_UNUSED(host); +} + +void +nng_http_handler_set_tree(nng_http_handler *h) +{ + NNI_ARG_UNUSED(h); +} + +void +nng_http_handler_set_data(nng_http_handler *h, void *dat, void (*dtor)(void *)) +{ + NNI_ARG_UNUSED(h); + NNI_ARG_UNUSED(dat); + NNI_ARG_UNUSED(dtor); +} + +nng_err +nng_http_server_hold(nng_http_server **srvp, const nng_url *url) +{ + NNI_ARG_UNUSED(srvp); + NNI_ARG_UNUSED(url); + return (NNG_ENOTSUP); +} + +void +nng_http_server_release(nng_http_server *srv) +{ + NNI_ARG_UNUSED(srv); +} + +nng_err +nng_http_server_start(nng_http_server *srv) +{ + NNI_ARG_UNUSED(srv); + return (NNG_ENOTSUP); +} + +void +nng_http_server_stop(nng_http_server *srv) +{ + NNI_ARG_UNUSED(srv); +} + +nng_err +nng_http_server_add_handler(nng_http_server *srv, nng_http_handler *h) +{ + NNI_ARG_UNUSED(srv); + NNI_ARG_UNUSED(h); + return (NNG_ENOTSUP); +} + +nng_err +nng_http_server_del_handler(nng_http_server *srv, nng_http_handler *h) +{ + NNI_ARG_UNUSED(srv); + NNI_ARG_UNUSED(h); + return (NNG_ENOTSUP); +} + +nng_err +nng_http_server_set_error_page( + nng_http_server *srv, nng_http_status code, const char *body) +{ + NNI_ARG_UNUSED(srv); + NNI_ARG_UNUSED(code); + NNI_ARG_UNUSED(body); + return (NNG_ENOTSUP); +} + +nng_err +nng_http_server_set_tls(nng_http_server *srv, nng_tls_config *cfg) +{ + NNI_ARG_UNUSED(srv); + NNI_ARG_UNUSED(cfg); +} + +nng_err +nng_http_server_get_tls(nng_http_server *srv, nng_tls_config **cfg) +{ + NNI_ARG_UNUSED(srv); + NNI_ARG_UNUSED(cfg); + return (NNG_ENOTSUP); +} + +nng_err +nng_http_server_get_addr(nng_http_server *srv, nng_sockaddr *addr) +{ + NNI_ARG_UNUSED(srv); + NNI_ARG_UNUSED(addr); + return (NNG_ENOTSUP); +} + +nng_err +nng_http_server_error(nng_http_server *srv, nng_http *conn) +{ + NNI_ARG_UNUSED(srv); + NNI_ARG_UNUSED(conn); + return (NNG_ENOTSUP); +} + +nng_err +nng_http_hijack(nng_http *conn) +{ + NNI_ARG_UNUSED(conn); + return (NNG_ENOTSUP); +} + +nng_err +nng_http_client_alloc(nng_http_client **clip, const nng_url *url) +{ + NNI_ARG_UNUSED(clip); + NNI_ARG_UNUSED(url); + return (NNG_ENOTSUP); +} + +void +nng_http_client_free(nng_http_client *cli) +{ + NNI_ARG_UNUSED(cli); +} + +nng_err +nng_http_client_set_tls(nng_http_client *cli, nng_tls_config *cfg) +{ + NNI_ARG_UNUSED(cli); + NNI_ARG_UNUSED(cfg); + return (NNG_ENOTSUP); +} + +nng_err +nng_http_client_get_tls(nng_http_client *cli, nng_tls_config **cfgp) +{ + NNI_ARG_UNUSED(cli); + NNI_ARG_UNUSED(cfgp); + return (NNG_ENOTSUP); +} + +void +nng_http_client_connect(nng_http_client *cli, nng_aio *aio) +{ + NNI_ARG_UNUSED(cli); + nng_aio_finish(aio, NNG_ENOTSUP); +} + +void +nng_http_transact(nng_http *conn, nng_aio *aio) +{ + NNI_ARG_UNUSED(conn); + nng_aio_finish(aio, NNG_ENOTSUP); +} + +void +nng_http_reset(nng_http *conn) +{ + NNI_ARG_UNUSED(conn); +} diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c index 08b3a071..f40fbb4a 100644 --- a/src/supplemental/websocket/websocket.c +++ b/src/supplemental/websocket/websocket.c @@ -121,7 +121,7 @@ struct nni_ws_dialer { nng_stream_dialer ops; nni_http_req *req; nni_http_res *res; - nni_http_client *client; + nng_http_client *client; nni_mtx mtx; nni_cv cv; char *proto; @@ -1279,7 +1279,7 @@ ws_http_cb_dialer(nni_ws *ws, nni_aio *aio) return; } - status = nni_http_get_status(ws->http); + status = nng_http_get_status(ws->http); switch (status) { case NNG_HTTP_STATUS_SWITCHING: break; @@ -1585,7 +1585,7 @@ ws_handler(nng_http *conn, void *arg, nng_aio *aio) nni_list_append(&l->reply, ws); nng_http_write_response(conn, &ws->httpaio); - (void) nni_http_hijack(conn); + (void) nng_http_hijack(conn); nni_aio_set_output(aio, 0, NULL); nni_aio_finish(aio, 0, 0); nni_mtx_unlock(&l->mtx); @@ -2026,8 +2026,8 @@ nni_ws_listener_alloc(nng_stream_listener **wslp, const nng_url *url) return (rv); } - nni_http_handler_set_host(l->handler, host); - nni_http_handler_set_data(l->handler, l, 0); + nng_http_handler_set_host(l->handler, host); + nng_http_handler_set_data(l->handler, l, 0); if ((rv = nni_http_server_init(&l->server, url)) != 0) { ws_listener_free(l); @@ -2103,7 +2103,7 @@ ws_conn_cb(void *arg) nni_base64_encode(raw, 16, ws->keybuf, 24); ws->keybuf[24] = '\0'; - if ((rv = nni_http_set_uri( + if ((rv = nng_http_set_uri( ws->http, d->url->u_path, d->url->u_query)) != 0) { goto err; } @@ -2123,7 +2123,7 @@ ws_conn_cb(void *arg) } NNI_LIST_FOREACH (&d->headers, hdr) { - if ((rv = nni_http_set_header( + if ((rv = nng_http_set_header( ws->http, hdr->name, hdr->value)) != 0) { goto err; } @@ -2186,7 +2186,7 @@ ws_dialer_free(void *arg) NNI_FREE_STRUCT(hdr); } if (d->client) { - nni_http_client_fini(d->client); + nng_http_client_free(d->client); } if (d->url) { nng_url_free(d->url); @@ -2243,7 +2243,7 @@ ws_dialer_dial(void *arg, nni_aio *aio) ws->recv_text = d->recv_text; ws->send_text = d->send_text; nni_list_append(&d->wspend, ws); - nni_http_client_connect(d->client, &ws->connaio); + nng_http_client_connect(d->client, &ws->connaio); nni_mtx_unlock(&d->mtx); } @@ -2510,14 +2510,14 @@ static int ws_dialer_get_tls(void *arg, nng_tls_config **cfgp) { nni_ws_dialer *d = arg; - return (nni_http_client_get_tls(d->client, cfgp)); + return (nng_http_client_get_tls(d->client, cfgp)); } static int ws_dialer_set_tls(void *arg, nng_tls_config *cfg) { nni_ws_dialer *d = arg; - return (nni_http_client_set_tls(d->client, cfg)); + return (nng_http_client_set_tls(d->client, cfg)); } int @@ -2540,7 +2540,7 @@ nni_ws_dialer_alloc(nng_stream_dialer **dp, const nng_url *url) return (rv); } - if ((rv = nni_http_client_init(&d->client, url)) != 0) { + if ((rv = nng_http_client_alloc(&d->client, url)) != 0) { ws_dialer_free(d); return (rv); } @@ -2666,7 +2666,7 @@ static int ws_get_request_uri(void *arg, void *buf, size_t *szp, nni_type t) { nni_ws *ws = arg; - return (nni_copyout_str(nni_http_get_uri(ws->http), buf, szp, t)); + return (nni_copyout_str(nng_http_get_uri(ws->http), buf, szp, t)); } static int @@ -2716,7 +2716,7 @@ ws_get_header(nni_ws *ws, const char *nm, void *buf, size_t *szp, nni_type t) { const char *s; nm += strlen(NNG_OPT_WS_HEADER); - s = nni_http_get_header(ws->http, nm); + s = nng_http_get_header(ws->http, nm); if (s == NULL) { return (NNG_ENOENT); } |
