mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-05 20:02:19 +03:00
Uri-Path-Abbrev: Initial IETF Draft support
https://datatracker.ietf.org/doc/html/draft-ietf-core-uri-path-abbrev-04
This commit is contained in:
1 parent
e4297c9c89
commit
783b5317ca
27 files changed
+585
-56
No files matched your search
@@ -128,6 +128,7 @@ typedef enum coap_request_t {
|
||||
#define COAP_OPTION_OSCORE 9 /* C_____U, *, 0-255 B, RFC8613 */
|
||||
#define COAP_OPTION_URI_PATH 11 /* CU-RE__, String, 0-255 B, RFC7252 */
|
||||
#define COAP_OPTION_CONTENT_FORMAT 12 /* ____E__, uint, 0-2 B, RFC7252 */
|
||||
#define COAP_OPTION_URI_PATH_ABB 13 /* C___E__, uint, 0-4 B, RFC TBD */
|
||||
#define COAP_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
|
||||
/* COAP_OPTION_MAXAGE default 60 seconds if not set */
|
||||
#define COAP_OPTION_MAXAGE 14 /* _U-_E_U, uint, 0-4 B, RFC7252 */
|
||||
@@ -373,6 +374,11 @@ typedef enum coap_pdu_code_t {
|
||||
COAP_SIGNALING_CODE_ABORT = COAP_SIGNALING_ABORT
|
||||
} coap_pdu_code_t;
|
||||
|
||||
typedef enum {
|
||||
COAP_BOOL_FALSE,
|
||||
COAP_BOOL_TRUE
|
||||
} coap_bool_t;
|
||||
|
||||
/**
|
||||
* Creates a new CoAP PDU with at least enough storage space for the given
|
||||
* @p size maximum message size. The function returns a pointer to the
|
||||
|
||||
@@ -428,6 +428,7 @@ coap_pdu_release_lkd(coap_pdu_t *pdu) {
|
||||
* @param token The token to use in this duplicated PDU.
|
||||
* @param drop_options A list of options not to copy into the duplicated PDU.
|
||||
* If @c NULL, then all options are copied across.
|
||||
* @param expand_opt_abb If COAP_BOOL_TRUE, try to expand out Uri-Path-Abbrev.
|
||||
*
|
||||
* @return The duplicated PDU or @c NULL if failure.
|
||||
*/
|
||||
@@ -435,7 +436,8 @@ coap_pdu_t *coap_pdu_duplicate_lkd(const coap_pdu_t *old_pdu,
|
||||
coap_session_t *session,
|
||||
size_t token_length,
|
||||
const uint8_t *token,
|
||||
coap_opt_filter_t *drop_options);
|
||||
coap_opt_filter_t *drop_options,
|
||||
coap_bool_t expand_opt_abb);
|
||||
|
||||
/**
|
||||
* Increment reference counter on a pdu to stop it prematurely getting freed off
|
||||
|
||||
@@ -268,6 +268,16 @@ void coap_proxy_del_req(coap_proxy_entry_t *proxy_entry, coap_proxy_req_t *prox
|
||||
void coap_delete_proxy_subscriber(coap_session_t *session, coap_bin_const_t *token,
|
||||
coap_mid_t mid, coap_proxy_subs_delete_t type);
|
||||
|
||||
/**
|
||||
* coap_proxy_log_entry() is used to log a proxy status
|
||||
*
|
||||
* @param incoming The incoming proxy session.
|
||||
* @param pdu The request PDU.
|
||||
* @param upstream_token The token used for the ongoing session.
|
||||
* @param type The change update type.
|
||||
*/
|
||||
void coap_proxy_log_entry(coap_session_t *incoming, const coap_pdu_t *pdu,
|
||||
coap_bin_const_t *upstream_token, const char *type);
|
||||
/** @} */
|
||||
|
||||
#define PROXY_CACHE_ADD(e, obj) \
|
||||
|
||||
@@ -232,6 +232,7 @@ struct coap_session_t {
|
||||
coap_tick_t doing_first_timeout; /**< If doing_first, when to timeout */
|
||||
coap_pdu_t *doing_first_pdu; /**< If doing fist, PDU to retry sending */
|
||||
#endif /* COAP_CLIENT_SUPPORT */
|
||||
uint8_t no_path_abbrev; /**< Set is remote does not support Uri-Path-Abbrev */
|
||||
coap_mid_t remote_test_mid; /**< mid used for checking remote
|
||||
support */
|
||||
uint32_t max_token_size; /**< Largest token size supported RFC8974 */
|
||||
|
||||
@@ -82,6 +82,12 @@ typedef struct {
|
||||
enum coap_uri_scheme_t scheme;
|
||||
} coap_uri_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t upa_value; /**< The Uri-Path-Abbrev option value */
|
||||
const char *upa_path; /**< The Uri-Path-Abbrev option path representation
|
||||
(withouot the leading '/') */
|
||||
} coap_upa_abbrev_t;
|
||||
|
||||
static inline int
|
||||
coap_uri_scheme_is_secure(const coap_uri_t *uri) {
|
||||
return uri && ((uri->scheme & COAP_URI_SCHEME_SECURE_MASK) != 0);
|
||||
@@ -230,6 +236,32 @@ int coap_uri_into_options(const coap_uri_t *uri, const coap_address_t *dst,
|
||||
int coap_uri_into_optlist(const coap_uri_t *uri, const coap_address_t *dst,
|
||||
coap_optlist_t **optlist_chain,
|
||||
int create_port_host_opt);
|
||||
/**
|
||||
* Takes a coap_uri_t and then adds CoAP options into the @p optlist_chain.
|
||||
* If the port is not the default port and create_port_host_opt is not 0, then
|
||||
* the Uri-Port option is added to the @p optlist_chain.
|
||||
* If the dst defines an address that does not match the host in uri->host and
|
||||
* is not 0, then the Uri-Host option is added to the @p optlist_chain.
|
||||
* Any path or query are broken down into the individual segment Uri-Path
|
||||
* or Uri-Path-Abbrev (if mapping match) or Uri-Query options and added to
|
||||
* the @p optlist_chain.
|
||||
*
|
||||
* @param uri The coap_uri_t object.
|
||||
* @param dst The destination, or NULL if URI_HOST not to be added.
|
||||
* @param optlist_chain Where to store the chain of options.
|
||||
* @param create_port_host_opt @c 1 if port/host option to be added
|
||||
* (if non-default) else @c 0.
|
||||
* @param mapping A path mapping to value for Uri-Path-Abbrev table or NULL.
|
||||
* (path does not have the leading '/').
|
||||
* @param count Number of Uri-Path-Abbrev table entries.
|
||||
*
|
||||
* @return @c 1 on success, @c 0 if error.
|
||||
*
|
||||
*/
|
||||
int coap_uri_into_optlist_abbrev(const coap_uri_t *uri, const coap_address_t *dst,
|
||||
coap_optlist_t **optlist_chain,
|
||||
int create_port_host_opt,
|
||||
coap_upa_abbrev_t *mapping, uint32_t count);
|
||||
|
||||
/**
|
||||
* Splits the given URI path into segments. Each segment is preceded
|
||||
@@ -269,6 +301,28 @@ int coap_split_path(const uint8_t *path,
|
||||
int coap_path_into_optlist(const uint8_t *path, size_t length,
|
||||
coap_option_num_t optnum,
|
||||
coap_optlist_t **optlist_chain);
|
||||
/**
|
||||
* Splits the given URI path into '/' separate segments, and then adds
|
||||
* the Uri-Path / Location-Path option for each segment to the @p optlist_chain.
|
||||
*
|
||||
* Note: any segments that are just '.' or '..' are stripped out.
|
||||
*
|
||||
* @param path The path string to split.
|
||||
* @param length The actual length of @p path.
|
||||
* @param optnum The CoAP option (COAP_OPTION_URI_PATH or
|
||||
* COAP_OPTION_LOCATION_PATH)
|
||||
* @param optlist_chain The chain of optlists to add to. optlist_chain
|
||||
* parent is to be NULL or a previous set of optlists.
|
||||
* @param mapping A path mapping to value for Uri-Path-Abbrev table or NULL.
|
||||
* (path does not have the leading '/').
|
||||
* @param count Number of Uri-Path-Abbrev table entries.
|
||||
*
|
||||
* @return @c 1 on success else @c 0 if error.
|
||||
*/
|
||||
int coap_path_into_optlist_abbrev(const uint8_t *path, size_t length,
|
||||
coap_option_num_t optnum,
|
||||
coap_optlist_t **optlist_chain,
|
||||
coap_upa_abbrev_t *mapping, uint32_t count);
|
||||
|
||||
/**
|
||||
* Splits the given URI query into segments. Each segment is preceded
|
||||
@@ -327,6 +381,27 @@ coap_string_t *coap_get_query(const coap_pdu_t *request);
|
||||
*/
|
||||
coap_string_t *coap_get_uri_path(const coap_pdu_t *request);
|
||||
|
||||
/**
|
||||
* Define a Path to use if an Uri-Path-Abbrev option fails and the client
|
||||
* is to retry the request using Uri-Path instread of Uri-Path-Abbrev.
|
||||
*
|
||||
* @param mapping A path mapping to value for Uri-Path-Abbrev table or NULL
|
||||
if the previous mapping is to be cleared.
|
||||
* (path does not have the leading '/').
|
||||
* @param count Number of Uri-Path-Abbrev table entries.
|
||||
*/
|
||||
void coap_upa_client_fallback(coap_upa_abbrev_t *mapping, uint32_t count);
|
||||
|
||||
/**
|
||||
* Define a Path to use on receipt of an Uri-Path-Abbrev option value.
|
||||
*
|
||||
* @param mapping A path mapping to value for Uri-Path-Abbrev table or NULL
|
||||
if the previous mapping is to be cleared.
|
||||
* (path does not have the leading '/').
|
||||
* @param count Number of Uri-Path-Abbrev table entries.
|
||||
*/
|
||||
void coap_upa_server_mapping(coap_upa_abbrev_t *mapping, uint32_t count);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -35,7 +35,16 @@ typedef struct {
|
||||
coap_uri_scheme_t scheme; /**< scheme */
|
||||
} coap_uri_info_t;
|
||||
|
||||
typedef struct coap_upa_chain_t {
|
||||
struct coap_upa_chain_t *next; /**< Next entry in the chain */
|
||||
uint32_t upa_value; /**< The Uri-Path-Abbrev option value */
|
||||
char *upa_path; /**< The Uri-Path-Abbrev option path representation
|
||||
(withouot the leading '/') */
|
||||
} coap_upa_chain_t;
|
||||
|
||||
extern coap_uri_info_t coap_uri_scheme[COAP_URI_SCHEME_LAST];
|
||||
extern coap_upa_chain_t *coap_upa_client_fallback_chain;
|
||||
extern coap_upa_chain_t *coap_upa_server_mapping_chain;
|
||||
|
||||
/**
|
||||
* replace any % hex definitions with the actual character.
|
||||
@@ -45,6 +54,36 @@ extern coap_uri_info_t coap_uri_scheme[COAP_URI_SCHEME_LAST];
|
||||
*/
|
||||
void coap_replace_percents(coap_optlist_t *optlist);
|
||||
|
||||
/**
|
||||
* Determine the expanded Uri-Path-Abbrev option value.
|
||||
*
|
||||
* @param chain Chain holding the information.
|
||||
* @param value The Uri-Path-Abbrev numeric value
|
||||
*
|
||||
* @return The expanded textual path or @c NULL if not found.
|
||||
*/
|
||||
const char *coap_map_abbrev_uri_path(coap_upa_chain_t *chain, uint32_t value);
|
||||
|
||||
/*
|
||||
* See if the specifiec path with length is on the UPA chain.
|
||||
*
|
||||
* @param chain The UPA chain to check against.
|
||||
* @param path The URI path to match (without the leading /).
|
||||
* @param length The length of the URI path.
|
||||
* @param value The resoultant match value.
|
||||
*
|
||||
* @return 1 if a match, else 0.
|
||||
*/
|
||||
int coap_map_uri_path_abbrev(coap_upa_chain_t *chain, const char *path, size_t length,
|
||||
uint32_t *value);
|
||||
|
||||
/**
|
||||
* Clean up a UPA chain.
|
||||
*
|
||||
* @param chain The chain to delete.
|
||||
*/
|
||||
void coap_delete_upa_chain(coap_upa_chain_t *chain);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in new issue
Block a user