diff options
| author | Gregor Burger <gregor.burger@bhs-technologies.com> | 2018-11-20 11:48:03 +0100 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-11-22 12:28:27 -0800 |
| commit | d6bb25e1e0a25cb5aa781ac4f90b513fd5624f50 (patch) | |
| tree | f081a6868a6c3d88b4df64ef20a38fb3e83925d1 /src/supplemental | |
| parent | 8a9fd805d96201c780610b765f9e6dd9f2eda642 (diff) | |
| download | nng-d6bb25e1e0a25cb5aa781ac4f90b513fd5624f50.tar.gz nng-d6bb25e1e0a25cb5aa781ac4f90b513fd5624f50.tar.bz2 nng-d6bb25e1e0a25cb5aa781ac4f90b513fd5624f50.zip | |
move all public headers to include/nng/ folder
This change makes embedding nng + nggpp (or other projects depending on
nng) in cmake easier. The header files are moved to a separate include
directory. This also makes installation of the headers easier, and
allows clearer identification of private vs public heade files.
Some additional cleanups were performed by @gedamore, but the main
credit for this change belongs with @gregorburger.
Diffstat (limited to 'src/supplemental')
| -rw-r--r-- | src/supplemental/http/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | src/supplemental/http/http.h | 528 | ||||
| -rw-r--r-- | src/supplemental/http/http_api.h | 4 | ||||
| -rw-r--r-- | src/supplemental/http/http_client.c | 2 | ||||
| -rw-r--r-- | src/supplemental/http/http_conn.c | 2 | ||||
| -rw-r--r-- | src/supplemental/http/http_public.c | 4 | ||||
| -rw-r--r-- | src/supplemental/http/http_server.c | 2 | ||||
| -rw-r--r-- | src/supplemental/tls/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | src/supplemental/tls/mbedtls/tls.c | 2 | ||||
| -rw-r--r-- | src/supplemental/tls/none/tls.c | 2 | ||||
| -rw-r--r-- | src/supplemental/tls/tls.h | 112 | ||||
| -rw-r--r-- | src/supplemental/util/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | src/supplemental/util/options.c | 2 | ||||
| -rw-r--r-- | src/supplemental/util/options.h | 48 | ||||
| -rw-r--r-- | src/supplemental/util/platform.c | 2 | ||||
| -rw-r--r-- | src/supplemental/util/platform.h | 106 |
16 files changed, 19 insertions, 816 deletions
diff --git a/src/supplemental/http/CMakeLists.txt b/src/supplemental/http/CMakeLists.txt index 0fe9e7c5..2b8696b6 100644 --- a/src/supplemental/http/CMakeLists.txt +++ b/src/supplemental/http/CMakeLists.txt @@ -13,9 +13,9 @@ if (NNG_ENABLE_HTTP) set(NNG_SUPP_HTTP ON) endif() mark_as_advanced(NNG_ENABLE_HTTP) - -set(_HDRS supplemental/http/http.h) -set(_SRCS ${_HDRS} supplemental/http/http_public.c supplemental/http/http_api.h) +set(_SRCS supplemental/http/http_public.c + ${PROJECT_SOURCE_DIR}/include/nng/supplemental/http/http.h + supplemental/http/http_api.h) if (NNG_SUPP_HTTP) set(_DEFS -DNNG_SUPP_HTTP) @@ -30,4 +30,3 @@ endif() set(NNG_DEFS ${NNG_DEFS} ${_DEFS} PARENT_SCOPE) set(NNG_SRCS ${NNG_SRCS} ${_SRCS} PARENT_SCOPE) -set(NNG_HDRS ${NNG_HDRS} ${_HDRS} PARENT_SCOPE) diff --git a/src/supplemental/http/http.h b/src/supplemental/http/http.h deleted file mode 100644 index d0854981..00000000 --- a/src/supplemental/http/http.h +++ /dev/null @@ -1,528 +0,0 @@ -// -// 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 -// file was obtained (LICENSE.txt). A copy of the license may also be -// found online at https://opensource.org/licenses/MIT. -// - -#ifndef NNG_SUPPLEMENTAL_HTTP_HTTP_H -#define NNG_SUPPLEMENTAL_HTTP_HTTP_H - -// HTTP API. Only present if HTTP support compiled into the library. -// Functions will return NNG_ENOTSUP (or NULL or 0 as appropriate) -// if the library lacks support for HTTP. - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdint.h> - -struct nng_tls_config; - -// HTTP status codes. This list is not exhaustive. -enum nng_http_status { - NNG_HTTP_STATUS_CONTINUE = 100, - NNG_HTTP_STATUS_SWITCHING = 101, - NNG_HTTP_STATUS_PROCESSING = 102, - NNG_HTTP_STATUS_OK = 200, - NNG_HTTP_STATUS_CREATED = 201, - NNG_HTTP_STATUS_ACCEPTED = 202, - NNG_HTTP_STATUS_NOT_AUTHORITATIVE = 203, - NNG_HTTP_STATUS_NO_CONTENT = 204, - NNG_HTTP_STATUS_RESET_CONTENT = 205, - NNG_HTTP_STATUS_PARTIAL_CONTENT = 206, - NNG_HTTP_STATUS_MULTI_STATUS = 207, - NNG_HTTP_STATUS_ALREADY_REPORTED = 208, - NNG_HTTP_STATUS_IM_USED = 226, - NNG_HTTP_STATUS_MULTIPLE_CHOICES = 300, - NNG_HTTP_STATUS_STATUS_MOVED_PERMANENTLY = 301, - NNG_HTTP_STATUS_FOUND = 302, - NNG_HTTP_STATUS_SEE_OTHER = 303, - NNG_HTTP_STATUS_NOT_MODIFIED = 304, - NNG_HTTP_STATUS_USE_PROXY = 305, - NNG_HTTP_STATUS_TEMPORARY_REDIRECT = 307, - NNG_HTTP_STATUS_PERMANENT_REDIRECT = 308, - NNG_HTTP_STATUS_BAD_REQUEST = 400, - NNG_HTTP_STATUS_UNAUTHORIZED = 401, - NNG_HTTP_STATUS_PAYMENT_REQUIRED = 402, - NNG_HTTP_STATUS_FORBIDDEN = 403, - NNG_HTTP_STATUS_NOT_FOUND = 404, - NNG_HTTP_STATUS_METHOD_NOT_ALLOWED = 405, - NNG_HTTP_STATUS_NOT_ACCEPTABLE = 406, - NNG_HTTP_STATUS_PROXY_AUTH_REQUIRED = 407, - NNG_HTTP_STATUS_REQUEST_TIMEOUT = 408, - NNG_HTTP_STATUS_CONFLICT = 409, - NNG_HTTP_STATUS_GONE = 410, - NNG_HTTP_STATUS_LENGTH_REQUIRED = 411, - NNG_HTTP_STATUS_PRECONDITION_FAILED = 412, - NNG_HTTP_STATUS_PAYLOAD_TOO_LARGE = 413, - NNG_HTTP_STATUS_ENTITY_TOO_LONG = 414, - NNG_HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE = 415, - NNG_HTTP_STATUS_RANGE_NOT_SATISFIABLE = 416, - NNG_HTTP_STATUS_EXPECTATION_FAILED = 417, - NNG_HTTP_STATUS_TEAPOT = 418, - NNG_HTTP_STATUS_UNPROCESSABLE_ENTITY = 422, - NNG_HTTP_STATUS_LOCKED = 423, - NNG_HTTP_STATUS_FAILED_DEPENDENCY = 424, - NNG_HTTP_STATUS_UPGRADE_REQUIRED = 426, - NNG_HTTP_STATUS_PRECONDITION_REQUIRED = 428, - NNG_HTTP_STATUS_TOO_MANY_REQUESTS = 429, - NNG_HTTP_STATUS_HEADERS_TOO_LARGE = 431, - NNG_HTTP_STATUS_UNAVAIL_LEGAL_REASONS = 451, - NNG_HTTP_STATUS_INTERNAL_SERVER_ERROR = 500, - NNG_HTTP_STATUS_NOT_IMPLEMENTED = 501, - NNG_HTTP_STATUS_BAD_GATEWAY = 502, - NNG_HTTP_STATUS_SERVICE_UNAVAILABLE = 503, - NNG_HTTP_STATUS_GATEWAY_TIMEOUT = 504, - NNG_HTTP_STATUS_HTTP_VERSION_NOT_SUPP = 505, - NNG_HTTP_STATUS_VARIANT_ALSO_NEGOTIATES = 506, - NNG_HTTP_STATUS_INSUFFICIENT_STORAGE = 507, - NNG_HTTP_STATUS_LOOP_DETECTED = 508, - NNG_HTTP_STATUS_NOT_EXTENDED = 510, - NNG_HTTP_STATUS_NETWORK_AUTH_REQUIRED = 511, -}; - -// nng_http_req represents an HTTP request. -typedef struct nng_http_req nng_http_req; - -// nng_http_req_alloc creates a vanilla HTTP request object. The object is -// initialized with the given URL object for an HTTP/1.1 GET request by -// default. It also adds the Host: header required for HTTP/1.1. If the -// url is NULL, then the uri and Host: header are uninitialized, and will -// need to be set explicitly. -NNG_DECL int nng_http_req_alloc(nng_http_req **, const nng_url *); - -// nng_http_req_free frees an HTTP request object. -NNG_DECL void nng_http_req_free(nng_http_req *); - -// nng_http_req_get_method returns the method. -NNG_DECL const char *nng_http_req_get_method(nng_http_req *); - -// nng_http_req_get_version returns the version, usually HTTP/1.1. -NNG_DECL const char *nng_http_req_get_version(nng_http_req *); - -// nng_http_req_get_uri returns the "abs-uri", which is URL without -// the scheme, host, or port. -NNG_DECL const char *nng_http_req_get_uri(nng_http_req *); - -// nng_http_req_set_header sets an HTTP header, replacing any previous value -// that might have been present. -NNG_DECL int nng_http_req_set_header( - nng_http_req *, const char *, const char *); - -// nng_http_req_add_header adds an HTTP header, without disrupting any other -// with the same name that might have been present. -NNG_DECL int nng_http_req_add_header( - nng_http_req *, const char *, const char *); - -// nng_http_req_del_header deletes all occurrences of a named header. -NNG_DECL int nng_http_req_del_header(nng_http_req *, const char *); - -// nng_http_req_get_header looks up a header with the named, returns NULL -// if not found. -NNG_DECL const char *nng_http_req_get_header(nng_http_req *, const char *); - -// nng_http_req_set_method is used to change the method of a request. -// The method should be an upper case HTTP method, like POST, or DELETE. -// Null sets the default ("GET"). -NNG_DECL int nng_http_req_set_method(nng_http_req *, const char *); - -// nng_http_req_set_version is used to change the version of a request. -// Normally the version is "HTTP/1.1". Note that the framework does -// not support HTTP/2 at all. Null sets the default ("HTTP/1.1"). -NNG_DECL int nng_http_req_set_version(nng_http_req *, const char *); - -// nng_http_req_set_uri is used to change the URI of a request. This -// should be an "abs-uri", that is a path, plus query and fragment if -// needed. The scheme, host, and port don't belong here. The URI should -// start with a leading '/' per HTTP. -NNG_DECL int nng_http_req_set_uri(nng_http_req *, const char *); - -// nng_http_req_set_data adds entity data to the request. The -// data object must persist (so only really useful for static data). -// The content-length header is updated as well, but the caller should -// probably set the content-type header. -NNG_DECL int nng_http_req_set_data(nng_http_req *, const void *, size_t); - -// nng_http_req_copy_data adds entity data to the response. A private -// copy of the data is made (will be freed with the request). -// The content-length header is updated as well, but the caller should -// probably set the content-type header. -NNG_DECL int nng_http_req_copy_data(nng_http_req *, const void *, size_t); - -// nng_http_req_get_data gets the data for the response. -NNG_DECL void nng_http_req_get_data(nng_http_req *, void **, size_t *); - -// nng_http_res represents an HTTP response. -typedef struct nng_http_res nng_http_res; - -// nng_http_res_alloc creates a vanilla HTTP response object. The object is -// initialized for an HTTP/1.1 200 OK response by default. -NNG_DECL int nng_http_res_alloc(nng_http_res **); - -// nng_http_res_alloc_error creates an error HTTP response object. The object -// is initialized for an HTTP/1.1 response, and contains an associated -// generic HTML error page. -NNG_DECL int nng_http_res_alloc_error(nng_http_res **, uint16_t); - -// nng_http_res_free frees an HTTP response object. -NNG_DECL void nng_http_res_free(nng_http_res *); - -// nng_http_res_get_status returns the HTTP status code from the server. -NNG_DECL uint16_t nng_http_res_get_status(nng_http_res *); - -// nng_http_res_set_status sets the HTTP status code. -NNG_DECL int nng_http_res_set_status(nng_http_res *, uint16_t); - -// nng_http_res_get_reason returns the human readable status message -// that the server responds (or responded) with. -NNG_DECL const char *nng_http_res_get_reason(nng_http_res *); - -// nng_http_res_set_rason sets the human readable status message. -// NULL means that a default reason is used based on the status code. -NNG_DECL int nng_http_res_set_reason(nng_http_res *, const char *); - -// nng_http_res_set_header sets an HTTP header, replacing any previous value -// that might have been present. -NNG_DECL int nng_http_res_set_header( - nng_http_res *, const char *, const char *); - -// nng_http_res_add_header adds an HTTP header, without disrupting any other -// with the same name that might have been present. -NNG_DECL int nng_http_res_add_header( - nng_http_res *, const char *, const char *); - -// nng_http_res_del_header deletes all occurrences of a named header. -NNG_DECL int nng_http_res_del_header(nng_http_res *, const char *); - -// nng_http_res_get_header looks up a header with the named, returns NULL -// if not found. -NNG_DECL const char *nng_http_res_get_header(nng_http_res *, const char *); - -// nng_http_res_set_version is used to change the version of a response. -// Normally the version is "HTTP/1.1". Note that the framework does -// not support HTTP/2 at all. NULL sets the default ("HTTP/1.1"). -NNG_DECL int nng_http_res_set_version(nng_http_res *, const char *); - -// nng_http_res_get_version returns the version, usually HTTP/1.1. -NNG_DECL const char *nng_http_res_get_version(nng_http_res *); - -// nng_http_res_get_data gets the data for the response. -NNG_DECL void nng_http_res_get_data(nng_http_res *, void **, size_t *); - -// nng_http_res_set_data adds entity data to the response. The -// data object must persist (so only really useful for static data). -// The content-length header is updated as well, but the caller should -// probably set the content-type header. -NNG_DECL int nng_http_res_set_data(nng_http_res *, const void *, size_t); - -// nng_http_res_copy_data adds entity data to the response. A private -// copy of the data is made (will be freed with the request). -// The content-length header is updated as well, but the caller should -// probably set the content-type header. -NNG_DECL int nng_http_res_copy_data(nng_http_res *, const void *, size_t); - -// An nng_http_conn represents an underlying "connection". It may be -// a TCP channel, or a TLS channel, but the main thing is that this is -// normally only used for exchanging HTTP requests and responses. -typedef struct nng_http_conn nng_http_conn; - -// nng_http_conn_close closes the underlying channel. Applications should -// not use this channel after this operation is performed. -NNG_DECL void nng_http_conn_close(nng_http_conn *); - -// nng_http_conn_read attempts to read data from the connection. This -// completes as soon as at least one byte is read; it does not wait -// for the entire aio to be filled. -NNG_DECL void nng_http_conn_read(nng_http_conn *, nng_aio *); - -// nng_http_conn_read_all is like nng_http_conn_read, but it does not -// finish until either all the requested data is read, or an error occurs. -NNG_DECL void nng_http_conn_read_all(nng_http_conn *, nng_aio *); - -// nng_http_conn_write attempts to write data, but it can write less -// than the amount requested. (It completes as soon as at least one -// byte is written.) -NNG_DECL void nng_http_conn_write(nng_http_conn *, nng_aio *); - -// nng_http_conn_write_all is like nng_http_conn_write, but it does not -// finish until either all the requested data is written, or an error occurs. -NNG_DECL void nng_http_conn_write_all(nng_http_conn *, nng_aio *); - -// nng_http_conn_write_req writes the entire request. It will also write any -// data that has been attached. -NNG_DECL void nng_http_conn_write_req( - nng_http_conn *, nng_http_req *, nng_aio *); - -// nng_http_conn_write_res writes the entire response. It will also write any -// data that has been attached. -NNG_DECL void nng_http_conn_write_res( - nng_http_conn *, nng_http_res *, nng_aio *); - -// nng_http_conn_read_req reads an entire request, EXCEPT for any entity -// data. The caller is responsible for processing the headers in the request -// and reading any submitted entity data itself. -NNG_DECL void nng_http_conn_read_req( - nng_http_conn *, nng_http_req *, nng_aio *); - -// nng_http_conn_read_res reads an entire response, EXCEPT for any entity -// data. The caller is responsible for processing the headers in the response -// and reading any submitted entity data itself. -NNG_DECL void nng_http_conn_read_res( - nng_http_conn *, nng_http_res *, nng_aio *); - -// nng_http_req_reset resets the request to an initially allocated state. -NNG_DECL void nng_http_req_reset(nng_http_req *); - -// nng_http_res_reset resets the response to an initially allocated state. -NNG_DECL void nng_http_res_reset(nng_http_res *); - -// nng_http_handler is a handler used on the server side to handle HTTP -// requests coming into a specific URL. -typedef struct nng_http_handler nng_http_handler; - -// nng_http_handler_alloc creates a server handler object, for the supplied -// absolute URI (path only) with the callback. By default the handler -// is assumed to handle only GET requests (and implictly HEAD requests -// as well.) -// -// 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. -// -// The callback function will receive the following arguments (via -// nng_aio_get_input(): nng_http_request *, nng_http_handler *, and -// nng_http_conn *. The first is a request object, for convenience. -// The second is the handler, from which the callback can obtain any other -// data it has set. The final is the http connection, which can be used -// to hijack the session. -// -// Upon completion, the handler should store an nng_http_res * as the -// first output using nng_aio_set_output. If it does not do so, or supplies -// NULL, then it must send a response itself. -// -// The callback should return 0 in most circumstances; if it returns anything -// other than 0 then the connection is terminated (after possibly sending -// a 500 error response to the client.) -NNG_DECL int nng_http_handler_alloc( - nng_http_handler **, const char *, void (*)(nng_aio *)); - -// nng_http_handler_free frees the handler. This actually just drops a -// reference count on the handler, as it may be in use by an existing -// server. The server will also call this when it is destroyed. -NNG_DECL void nng_http_handler_free(nng_http_handler *); - -// nng_http_handler_alloc_file creates a "file" based handler, that -// serves up static content from the given file path. The content-type -// supplied is determined from the file name using a simple built-in map. -NNG_DECL int nng_http_handler_alloc_file( - nng_http_handler **, const char *, const char *); - -// nng_http_handler_alloc_static creates a static-content handler. -// The last argument is the content-type, which may be NULL (in which case -// "application/octet-stream" is assumed.) -NNG_DECL int nng_http_handler_alloc_static( - nng_http_handler **, const char *, const void *, size_t, const char *); - -// nng_http_handler_alloc_redirect creates an HTTP redirect handler. -// The status is given, along with the new URL. If the status is 0, -// then 301 will be used instead. -NNG_DECL int nng_http_handler_alloc_redirect( - nng_http_handler **, const char *, uint16_t, const char *); - -// nng_http_handler_alloc_file creates a "directory" based handler, that -// serves up static content from the given directory tree. Directories -// that contain an index.html or index.htm file use that file for the -// directory content, otherwise a suitable error page is returned (the server -// does not generate index pages automatically.) The content-type for -// files is determined from the file name using a simple built-in map. -NNG_DECL int nng_http_handler_alloc_directory( - nng_http_handler **, const char *, const char *); - -// nng_http_handler_set_method sets the method that the handler will be -// called for. By default this is GET. If NULL is supplied for the -// method, then the handler is executed regardless of method, and must -// inspect the method itself. -NNG_DECL int nng_http_handler_set_method(nng_http_handler *, const char *); - -// nng_http_handler_set_host sets the Host: that the handler will be -// called for (to allow for virtual hosts). If the value is NULL (the -// default, then the Host: header is not considered when matching the -// handler.) Note that the Host: header must match *exactly* (except -// that case is not considered.) -NNG_DECL int nng_http_handler_set_host(nng_http_handler *, const char *); - -// nng_http_handler_collect_body is used to indicate the server should -// check for, and process, data sent by the client, which will be attached -// to the request. If this is false, then the handler will need to check -// for and process any content data. By default the server will accept -// up to 1MB. If the client attempts to send more data than requested, -// then a 400 Bad Request will be sent back to the client. To set an -// unlimited value, use (size_t)-1. To preclude the client from sending -// *any* data, use 0. (The static and file handlers use 0 by default.) -NNG_DECL int nng_http_handler_collect_body(nng_http_handler *, bool, size_t); - -// nng_http_handler_set_tree indicates that the handler is being registered -// for a heirarchical tree, rather than just a single path, so it will be -// called for all child paths supplied. By default the handler is only -// called for an exact path match. -NNG_DECL int nng_http_handler_set_tree(nng_http_handler *); - -// nng_http_handler_set_data is used to store additional data, along with -// a possible clean up routine. (The clean up is a custom deallocator and -// will be called with the supplied data as an argument, when the handler -// is being deallocated.) -NNG_DECL int nng_http_handler_set_data( - nng_http_handler *, void *, void (*)(void *)); - -// nng_http_handler_get_data returns the data that was previously stored. -NNG_DECL void *nng_http_handler_get_data(nng_http_handler *); - -// nng_http_server is a handle to an HTTP server instance. Servers -// only serve a single port / address at this time. - -typedef struct nng_http_server nng_http_server; - -// nng_http_server_hold gets a server structure, using the address determined -// from the URL. If a server already exists, then a hold is placed on it, and -// that instance is returned. If no such server exists, then a new instance -// is created. -NNG_DECL int nng_http_server_hold(nng_http_server **, const nng_url *); - -// nng_http_server_release releases the hold on the server. If this is the -// last instance of the server, then it is shutdown and resources are freed. -NNG_DECL void nng_http_server_release(nng_http_server *); - -// nng_http_server_start starts the server handling HTTP. Once this is -// called, it will not be possible to change certain parameters (such as -// any TLS configuration). -NNG_DECL int nng_http_server_start(nng_http_server *); - -// nng_http_server_stop stops the server. No new client connections are -// accepted after this returns. Once a server is stopped fully, the -// instance will no longer be returned by nng_http_server_hold, as the -// server may not be reused. -NNG_DECL void nng_http_server_stop(nng_http_server *); - -// nng_http_server_add_handler registers a handler on the server. -// This function will return NNG_EADDRINUSE if a conflicting handler -// is already registered (i.e. a handler with the same value for Host, -// Method, and URL.) -NNG_DECL int nng_http_server_add_handler( - nng_http_server *, nng_http_handler *); - -// nni_http_del_handler removes the given handler. The caller is -// responsible for finalizing it afterwards. If the handler was not found -// (not registered), NNG_ENOENT is returned. In this case it is unsafe -// to make assumptions about the validity of the handler. -NNG_DECL int nng_http_server_del_handler( - nng_http_server *, nng_http_handler *); - -// nng_http_server_set_tls adds a TLS configuration to the server, -// and enables the use of it. This returns NNG_EBUSY if the server is -// already started. This wipes out the entire TLS configuration on the -// 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 *, 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 *, struct nng_tls_config **); - -// nng_http_server_set_error_page sets a custom error page (HTML) content -// to be sent for the given error code. This is used when the error is -// generated internally by the framework, or when the application returns -// the response back to the server via the handler's aio, and the response -// was allocated with nng_http_res_alloc_error. If the response was not -// allocated this way, or the application writes the response itself instead -// of letting the server do so, then this setting will be ignored. -NNG_DECL int nng_http_server_set_error_page( - nng_http_server *, uint16_t, const char *); - -// nng_http_server_set_error_file works like nng_http_server_error_page, -// except that the content is loaded from the named file path. The contents -// are loaded at the time this function is called, so this function should be -// called anytime the contents of the named file have changed. -NNG_DECL int nng_http_server_set_error_file( - nng_http_server *, uint16_t, const char *); - -// nng_http_server_res_error takes replaces the body of the response with -// a custom error page previously set for the server, using the status -// of the response. The response must have the status set first using -// nng_http_res_set_status or implicitly via nng_http_res_alloc_error. -NNG_DECL int nng_http_server_res_error(nng_http_server *, nng_http_res *); - -// 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 -// (such as in the case of websocket). The caller is responsible for the -// final disposal of the associated nng_http_conn. 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.) - -NNG_DECL int nng_http_hijack(nng_http_conn *); - -// nng_http_client represents a "client" object. Clients can be used -// to create HTTP connections. At present, connections are not cached -// or reused, but that could change in the future. -typedef struct nng_http_client nng_http_client; - -// nng_http_client_alloc allocates a client object, associated with -// the given URL. -NNG_DECL int nng_http_client_alloc(nng_http_client **, const nng_url *); - -// nng_http_client_free frees the client. Connections created by the -// the client are not necessarily closed. -NNG_DECL void nng_http_client_free(nng_http_client *); - -// nng_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. -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 *, 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 -// is established, the associated nng_http_conn object pointer is returned -// in the first (index 0) output for the aio. -NNG_DECL void nng_http_client_connect(nng_http_client *, nng_aio *); - -// nng_http_conn_transact 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 close -// 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. -NNG_DECL void nng_http_conn_transact( - nng_http_conn *, nng_http_req *, nng_http_res *, nng_aio *); - -// nng_http_client_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. -NNG_DECL void nng_http_client_transact( - nng_http_client *, nng_http_req *, nng_http_res *, nng_aio *); - -#ifdef __cplusplus -} -#endif - -#endif // NNG_H diff --git a/src/supplemental/http/http_api.h b/src/supplemental/http/http_api.h index fdee70e9..a13348be 100644 --- a/src/supplemental/http/http_api.h +++ b/src/supplemental/http/http_api.h @@ -12,9 +12,9 @@ #define NNG_SUPPLEMENTAL_HTTP_HTTP_API_H #include "core/nng_impl.h" -#include "supplemental/tls/tls.h" +#include "nng/supplemental/tls/tls.h" -#include "supplemental/http/http.h" +#include "nng/supplemental/http/http.h" // This represents the "internal" HTTP API. It should not be used // or exposed to applications directly. diff --git a/src/supplemental/http/http_client.c b/src/supplemental/http/http_client.c index c70b7a63..798cbe14 100644 --- a/src/supplemental/http/http_client.c +++ b/src/supplemental/http/http_client.c @@ -14,7 +14,7 @@ #include <string.h> #include "core/nng_impl.h" -#include "supplemental/tls/tls.h" +#include "nng/supplemental/tls/tls.h" #include "supplemental/tls/tls_api.h" #include "http_api.h" diff --git a/src/supplemental/http/http_conn.c b/src/supplemental/http/http_conn.c index d00bd910..4d57281f 100644 --- a/src/supplemental/http/http_conn.c +++ b/src/supplemental/http/http_conn.c @@ -13,7 +13,7 @@ #include <string.h> #include "core/nng_impl.h" -#include "supplemental/tls/tls.h" +#include "nng/supplemental/tls/tls.h" #include "supplemental/tls/tls_api.h" #include "http_api.h" diff --git a/src/supplemental/http/http_public.c b/src/supplemental/http/http_public.c index 50ef03fa..3152c41f 100644 --- a/src/supplemental/http/http_public.c +++ b/src/supplemental/http/http_public.c @@ -9,9 +9,9 @@ // #include "core/nng_impl.h" -#include "http.h" +#include "nng/supplemental/http/http.h" #include "http_api.h" -#include "supplemental/tls/tls.h" +#include "nng/supplemental/tls/tls.h" // Symbols in this file are "public" versions of the HTTP API. // These are suitable for exposure to applications. diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c index b7ca9f7e..a6343d87 100644 --- a/src/supplemental/http/http_server.c +++ b/src/supplemental/http/http_server.c @@ -15,7 +15,7 @@ #include <string.h> #include "core/nng_impl.h" -#include "supplemental/tls/tls.h" +#include "nng/supplemental/tls/tls.h" #include "supplemental/tls/tls_api.h" #include "http_api.h" diff --git a/src/supplemental/tls/CMakeLists.txt b/src/supplemental/tls/CMakeLists.txt index 111ff70f..8fed1df1 100644 --- a/src/supplemental/tls/CMakeLists.txt +++ b/src/supplemental/tls/CMakeLists.txt @@ -13,8 +13,7 @@ if (NNG_SUPP_TLS) set(_DEFS -DNNG_SUPP_TLS) endif() -set(_SRCS supplemental/tls/tls.h) -set(_HDRS supplemental/tls/tls.h) +set(_SRCS ${PROJECT_SOURCE_DIR}/include/nng/supplemental/tls/tls.h) # For now we only support the ARM mbedTLS library. if (NNG_SUPP_TLS_MBEDTLS) @@ -36,12 +35,10 @@ endif() list(APPEND NNG_DEFS ${_DEFS}) list(APPEND NNG_SRCS ${_SRCS}) -list(APPEND NNG_HDRS ${_HDRS}) list(APPEND NNG_LIBS ${_LIBS}) list(APPEND NNG_INCS ${_INCS}) set(NNG_DEFS ${NNG_DEFS} PARENT_SCOPE) set(NNG_SRCS ${NNG_SRCS} PARENT_SCOPE) -set(NNG_HDRS ${NNG_HDRS} PARENT_SCOPE) set(NNG_LIBS ${NNG_LIBS} PARENT_SCOPE) set(NNG_INCS ${NNG_INCS} PARENT_SCOPE) diff --git a/src/supplemental/tls/mbedtls/tls.c b/src/supplemental/tls/mbedtls/tls.c index f7431ac6..c01ff2ed 100644 --- a/src/supplemental/tls/mbedtls/tls.c +++ b/src/supplemental/tls/mbedtls/tls.c @@ -28,7 +28,7 @@ #include "core/nng_impl.h" -#include "supplemental/tls/tls.h" +#include "nng/supplemental/tls/tls.h" #include "supplemental/tls/tls_api.h" // Implementation note. This implementation buffers data between the TLS diff --git a/src/supplemental/tls/none/tls.c b/src/supplemental/tls/none/tls.c index d7968758..e9d84e19 100644 --- a/src/supplemental/tls/none/tls.c +++ b/src/supplemental/tls/none/tls.c @@ -17,7 +17,7 @@ // We provide stub functions only to satisfy linkage. #include "core/nng_impl.h" -#include "supplemental/tls/tls.h" +#include "nng/supplemental/tls/tls.h" #include "supplemental/tls/tls_api.h" void diff --git a/src/supplemental/tls/tls.h b/src/supplemental/tls/tls.h deleted file mode 100644 index 5983f3b6..00000000 --- a/src/supplemental/tls/tls.h +++ /dev/null @@ -1,112 +0,0 @@ -// -// 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 -// file was obtained (LICENSE.txt). A copy of the license may also be -// found online at https://opensource.org/licenses/MIT. -// - -#ifndef NNG_SUPPLEMENTAL_TLS_TLS_H -#define NNG_SUPPLEMENTAL_TLS_TLS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stddef.h> -#include <stdint.h> - -// Note that TLS functions may be stubbed out if TLS is not enabled in -// the build. - -// For some transports, we need TLS configuration, including certificates -// and so forth. A TLS configuration cannot be changed once it is in use. -typedef struct nng_tls_config nng_tls_config; - -typedef enum nng_tls_mode { - NNG_TLS_MODE_CLIENT = 0, - NNG_TLS_MODE_SERVER = 1, -} nng_tls_mode; - -typedef enum nng_tls_auth_mode { - NNG_TLS_AUTH_MODE_NONE = 0, // No verification is performed - NNG_TLS_AUTH_MODE_OPTIONAL = 1, // Verify cert if presented - NNG_TLS_AUTH_MODE_REQUIRED = 2, // Verify cert, close if invalid -} nng_tls_auth_mode; - -// nng_tls_config_alloc creates a TLS configuration using -// reasonable defaults. This configuration can be shared -// with multiple pipes or services/servers. -NNG_DECL int nng_tls_config_alloc(nng_tls_config **, nng_tls_mode); - -// nng_tls_config_hold increments the reference count on the TLS -// configuration object. The hold can be dropped by calling -// nng_tls_config_free later. -NNG_DECL void nng_tls_config_hold(nng_tls_config *); - -// nng_tls_config_free drops the reference count on the TLS -// configuration object, and if zero, deallocates it. -NNG_DECL void nng_tls_config_free(nng_tls_config *); - -// nng_tls_config_server_name sets the server name. This is -// called by clients to set the name that the server supplied -// certificate should be matched against. This can also cause -// the SNI to be sent to the server to tell it which cert to -// use if it supports more than one. -NNG_DECL int nng_tls_config_server_name(nng_tls_config *, const char *); - -// nng_tls_config_ca_cert configures one or more CAs used for validation -// of peer certificates. Multiple CAs (and their chains) may be configured -// by either calling this multiple times, or by specifying a list of -// certificates as concatenated data. The final argument is an optional CRL -// (revokation list) for the CA, also in PEM. Both PEM strings are ASCIIZ -// format (except that the CRL may be NULL). -NNG_DECL int nng_tls_config_ca_chain( - nng_tls_config *, const char *, const char *); - -// nng_tls_config_own_cert is used to load our own certificate and public -// key. For servers, this may be called more than once to configure multiple -// different keys, for example with different algorithms depending on what -// the peer supports. On the client, only a single option is available. -// The first two arguments are the cert (or validation chain) and the -// key as PEM format ASCIIZ strings. The final argument is an optional -// password and may be NULL. -NNG_DECL int nng_tls_config_own_cert( - nng_tls_config *, const char *, const char *, const char *); - -// nng_tls_config_key is used to pass our own private key. -NNG_DECL int nng_tls_config_key(nng_tls_config *, const uint8_t *, size_t); - -// nng_tls_config_pass is used to pass a password used to decrypt -// private keys that are encrypted. -NNG_DECL int nng_tls_config_pass(nng_tls_config *, const char *); - -// nng_tls_config_auth_mode is used to configure the authentication mode use. -// The default is that servers have this off (i.e. no client authentication) -// and clients have it on (they verify the server), which matches typical -// practice. -NNG_DECL int nng_tls_config_auth_mode(nng_tls_config *, nng_tls_auth_mode); - -// nng_tls_config_ca_file is used to pass a CA chain and optional CRL -// via the filesystem. If CRL data is present, it must be contained -// in the file, along with the CA certificate data. The format is PEM. -// The path name must be a legal file name. -NNG_DECL int nng_tls_config_ca_file(nng_tls_config *, const char *); - -// nng_tls_config_cert_key_file is used to pass our own certificate and -// private key data via the filesystem. Both the key and certificate -// must be present as PEM blocks in the same file. A password is used to -// decrypt the private key if it is encrypted and the password supplied is not -// NULL. This may be called multiple times on servers, but only once on a -// client. (Servers can support multiple different certificates and keys for -// different cryptographic algorithms. Clients only get one.) -NNG_DECL int nng_tls_config_cert_key_file( - nng_tls_config *, const char *, const char *); - -#ifdef __cplusplus -} -#endif - -#endif // NNG_SUPPLEMENTAL_TLS_TLS_H diff --git a/src/supplemental/util/CMakeLists.txt b/src/supplemental/util/CMakeLists.txt index c61d8a09..64374d69 100644 --- a/src/supplemental/util/CMakeLists.txt +++ b/src/supplemental/util/CMakeLists.txt @@ -8,8 +8,9 @@ # found online at https://opensource.org/licenses/MIT. # -set(_SRCS supplemental/util/options.c supplemental/util/platform.c) -set(_HDRS supplemental/util/options.h supplemental/util/platform.h) +set(_SRCS supplemental/util/options.c + ${PROJECT_SOURCE_DIR}/include/nng/supplemental/util/options.h + supplemental/util/platform.c + ${PROJECT_SOURCE_DIR}/include/nng/supplemental/util/platform.h) set(NNG_SRCS ${NNG_SRCS} ${_SRCS} PARENT_SCOPE) -set(NNG_HDRS ${NNG_HDRS} ${_HDRS} PARENT_SCOPE) diff --git a/src/supplemental/util/options.c b/src/supplemental/util/options.c index 711635e2..c8dafed8 100644 --- a/src/supplemental/util/options.c +++ b/src/supplemental/util/options.c @@ -12,7 +12,7 @@ #include <string.h> #include "core/nng_impl.h" -#include "supplemental/util/options.h" +#include "nng/supplemental/util/options.h" // Call with optidx set to 1 to start parsing. int diff --git a/src/supplemental/util/options.h b/src/supplemental/util/options.h deleted file mode 100644 index 83969a90..00000000 --- a/src/supplemental/util/options.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// 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 -// file was obtained (LICENSE.txt). A copy of the license may also be -// found online at https://opensource.org/licenses/MIT. -// - -#ifndef NNG_SUPPLEMENTAL_UTIL_OPTIONS_H -#define NNG_SUPPLEMENTAL_UTIL_OPTIONS_H - -#include <stdbool.h> - -#ifdef __cplusplus -extern "C" { -#endif - -// This is a relatively simple "options parsing" library, used to -// parse command line options. We would use getopt(3), but there are -// two problems with getopt(3). First, it isn't available on all -// platforms (especially Win32), and second, it doesn't support long -// options. We *exclusively* support long options. POSIX style -// short option clustering is *NOT* supported. - -struct nng_optspec { - const char *o_name; // Long style name (may be NULL for short only) - int o_short; // Short option (no clustering!) - int o_val; // Value stored on a good parse (>0) - bool o_arg; // Option takes an argument if true -}; - -typedef struct nng_optspec nng_optspec; - -// Call with *optidx set to 1 to start parsing for a standard program. -// The val will store the value of the matched "o_val", optarg will be -// set to match the option string, and optidx will be increment appropriately. -// Returns -1 when the end of options is reached, 0 on success, or -// NNG_EINVAL if the option parse is invalid for any reason. -NNG_DECL int nng_opts_parse(int argc, char *const *argv, - const nng_optspec *opts, int *val, char **optarg, int *optidx); - -#ifdef __cplusplus -} -#endif - -#endif // NNG_SUPPLEMENTAL_UTIL_OPTIONS_H diff --git a/src/supplemental/util/platform.c b/src/supplemental/util/platform.c index 691ce867..138e8b0b 100644 --- a/src/supplemental/util/platform.c +++ b/src/supplemental/util/platform.c @@ -12,7 +12,7 @@ #include <string.h> #include "core/nng_impl.h" -#include "supplemental/util/platform.h" +#include "nng/supplemental/util/platform.h" nng_time nng_clock(void) diff --git a/src/supplemental/util/platform.h b/src/supplemental/util/platform.h deleted file mode 100644 index 0fcc7d16..00000000 --- a/src/supplemental/util/platform.h +++ /dev/null @@ -1,106 +0,0 @@ -// -// 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 -// file was obtained (LICENSE.txt). A copy of the license may also be -// found online at https://opensource.org/licenses/MIT. -// - -#ifndef NNG_SUPPLEMENTAL_UTIL_PLATFORM_H -#define NNG_SUPPLEMENTAL_UTIL_PLATFORM_H - -// The declarations in this file are provided to assist with application -// portability. Conceptually these APIs are based on work we have already -// done for NNG internals, and we find that they are useful in building -// portable applications. - -// If it is more natural to use native system APIs like pthreads or C11 -// APIs or Windows APIs, then by all means please feel free to simply -// ignore this. - -#include <stddef.h> -#include <stdint.h> - -#ifdef __cplusplus -extern "C" { -#endif - -// nng_time represents an absolute time since some arbitrary point in the -// past, measured in milliseconds. The values are always positive. -typedef uint64_t nng_time; - -// Return an absolute time from some arbitrary point. The value is -// provided in milliseconds, and is of limited resolution based on the -// system clock. (Do not use it for fine grained performance measurements.) -NNG_DECL nng_time nng_clock(void); - -// Sleep for specified msecs. -NNG_DECL void nng_msleep(nng_duration); - -// nng_thread is a handle to a "thread", which may be a real system -// thread, or a coroutine on some platforms. -typedef struct nng_thread nng_thread; - -// Create and start a thread. Note that on some platforms, this might -// actually be a coroutine, with limitations about what system APIs -// you can call. Therefore, these threads should only be used with the -// I/O APIs provided by nng. The thread runs until completion. -NNG_DECL int nng_thread_create(nng_thread **, void (*)(void *), void *); - -// Destroy a thread (waiting for it to complete.) When this function -// returns all resources for the thread are cleaned up. -NNG_DECL void nng_thread_destroy(nng_thread *); - -// nng_mtx represents a mutex, which is a simple, non-retrant, boolean lock. -typedef struct nng_mtx nng_mtx; - -// nng_mtx_alloc allocates a mutex structure. -NNG_DECL int nng_mtx_alloc(nng_mtx **); - -// nng_mtx_free frees the mutex. It most not be locked. -NNG_DECL void nng_mtx_free(nng_mtx *); - -// nng_mtx_lock locks the mutex; if it is already locked it will block -// until it can be locked. If the caller already holds the lock, the -// results are undefined (a panic may occur). -NNG_DECL void nng_mtx_lock(nng_mtx *); - -// nng_mtx_unlock unlocks a previously locked mutex. It is an error to -// call this on a mutex which is not owned by caller. -NNG_DECL void nng_mtx_unlock(nng_mtx *); - -// nng_cv is a condition variable. It is always allocated with an -// associated mutex, which must be held when waiting for it, or -// when signaling it. -typedef struct nng_cv nng_cv; - -NNG_DECL int nng_cv_alloc(nng_cv **, nng_mtx *); - -// nng_cv_free frees the condition variable. -NNG_DECL void nng_cv_free(nng_cv *); - -// nng_cv_wait waits until the condition variable is "signaled". -NNG_DECL void nng_cv_wait(nng_cv *); - -// nng_cv_until waits until either the condition is signaled, or -// the timeout expires. It returns NNG_ETIMEDOUT in that case. -NNG_DECL int nng_cv_until(nng_cv *, nng_time); - -// nng_cv_wake wakes all threads waiting on the condition. -NNG_DECL void nng_cv_wake(nng_cv *); - -// nng_cv_wake1 wakes only one thread waiting on the condition. This may -// reduce the thundering herd problem, but care must be taken to ensure -// that no waiter starves forvever. -NNG_DECL void nng_cv_wake1(nng_cv *); - -// nng_random returns a "strong" (cryptographic sense) random number. -NNG_DECL uint32_t nng_random(void); - -#ifdef __cplusplus -} -#endif - -#endif // NNG_SUPPLEMENTAL_UTIL_PLATFORM_H |
