|
NAMEcoap_proxy, coap_proxy_forward_request, coap_proxy_forward_response, coap_verify_proxy_scheme_supported - Work with CoAP proxies SYNOPSIS#include <coap3/coap.h> int coap_proxy_forward_request(coap_session_t *session, const coap_pdu_t *request, coap_pdu_t *response, coap_resource_t *resource, coap_cache_key_t *cache_key, coap_proxy_server_list_t *server_list); coap_response_t coap_proxy_forward_response(coap_session_t *session, const coap_pdu_t *received_, coap_cache_key_t **cache_key); int coap_verify_proxy_scheme_supported(coap_uri_scheme_t scheme); For specific (D)TLS library support, link with -lcoap-3-notls, -lcoap-3-gnutls, -lcoap-3-openssl, -lcoap-3-mbedtls, -lcoap-3-wolfssl or -lcoap-3-tinydtls. Otherwise, link with -lcoap-3 to get the default (D)TLS library support. DESCRIPTIONTo simplify some of the CoAP proxy requirements, some of the proxy forwarding functionality is provided by libcoap. The resourse handlers to handle forward or reverse proxy requests are defined using coap_resource_proxy_uri_init2(3) or coap_resource_reverse_proxy_init*(3). FUNCTIONSFunction: coap_proxy_forward_request() The coap_proxy_forward_request() function is called from a request handler when the request needs to be forwarded to an upstream server with a possible change in protocol. Function: coap_proxy_forward_response() The coap_proxy_forward_response() function is used to cleanup / free any information set up by the coap_startup() function and should be the last coap_*() function called. The only safe function that can be called after coap_cleanup() is coap_startup() to re-initialize the libcoap logic. NOTE: Calling coap_cleanup() in one thread while continuing to use other coap_*() function calls in a different thread is not supported - even if they are using a different coap_context_t. NOTE: All other libcoap cleanups should called prior to coap_cleanup(), e.g. coap_free_context(3). Function: coap_verify_proxy_scheme_supported() The coap_proxy_forward_request() function is called from a request handler when the request needs to be forwarded to an upstream server with a possible change in protocol. RETURN VALUEScoap_proxy_forward_request() and coap_verify_proxy_scheme_supported() return 1 on success and 0 on failure. coap_proxy_forward_response() returns one of COAP_RESPONSE_OK or COAP_RESPONSE_FAIL. EXAMPLESForward Proxy Set Up #include <coap3/coap.h>
static size_t proxy_host_name_count = 0;
static const char **proxy_host_name_list = NULL;
static coap_proxy_server_list_t forward_proxy = { NULL, 0, 0, COAP_PROXY_FORWARD, 0, 300};
static void
hnd_forward_proxy_uri(coap_resource_t *resource,
Reverse Proxy Set Up #include <coap3/coap.h>
static coap_proxy_server_list_t reverse_proxy = { NULL, 0, 0, COAP_PROXY_REVERSE_STRIP, 0, 10};
static void
hnd_reverse_proxy_uri(coap_resource_t *resource,
FURTHER INFORMATIONSee "RFC7252: The Constrained Application Protocol (CoAP)" for further information. BUGSPlease raise an issue on GitHub at https://github.com/obgm/libcoap/issues to report any bugs. Please raise a Pull Request at https://github.com/obgm/libcoap/pulls for any fixes. AUTHORSThe libcoap project <libcoap-developers@lists.sourceforge.net>
|