mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-24 15:57:14 +02:00
IDF release/v4.0 08219f3cf
This commit is contained in:
@ -7,24 +7,48 @@
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef _COAP_URI_H_
|
||||
#define _COAP_URI_H_
|
||||
#ifndef COAP_URI_H_
|
||||
#define COAP_URI_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "hashkey.h"
|
||||
#include "str.h"
|
||||
struct coap_pdu_t;
|
||||
|
||||
/**
|
||||
* The scheme specifiers. Secure schemes have an odd numeric value,
|
||||
* others are even.
|
||||
*/
|
||||
enum coap_uri_scheme_t {
|
||||
COAP_URI_SCHEME_COAP=0,
|
||||
COAP_URI_SCHEME_COAPS=1,
|
||||
COAP_URI_SCHEME_COAP_TCP=2,
|
||||
COAP_URI_SCHEME_COAPS_TCP=3
|
||||
};
|
||||
|
||||
/** This mask can be used to check if a parsed URI scheme is secure. */
|
||||
#define COAP_URI_SCHEME_SECURE_MASK 0x01
|
||||
|
||||
/**
|
||||
* Representation of parsed URI. Components may be filled from a string with
|
||||
* coap_split_uri() and can be used as input for option-creation functions.
|
||||
*/
|
||||
typedef struct {
|
||||
str host; /**< host part of the URI */
|
||||
unsigned short port; /**< The port in host byte order */
|
||||
str path; /**< Beginning of the first path segment.
|
||||
Use coap_split_path() to create Uri-Path options */
|
||||
str query; /**< The query part if present */
|
||||
coap_str_const_t host; /**< host part of the URI */
|
||||
uint16_t port; /**< The port in host byte order */
|
||||
coap_str_const_t path; /**< Beginning of the first path segment.
|
||||
Use coap_split_path() to create Uri-Path options */
|
||||
coap_str_const_t query; /**< The query part if present */
|
||||
|
||||
/** The parsed scheme specifier. */
|
||||
enum coap_uri_scheme_t scheme;
|
||||
} coap_uri_t;
|
||||
|
||||
static inline int
|
||||
coap_uri_scheme_is_secure(const coap_uri_t *uri) {
|
||||
return uri && ((uri->scheme & COAP_URI_SCHEME_SECURE_MASK) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new coap_uri_t object from the specified URI. Returns the new
|
||||
* object or NULL on error. The memory allocated by the new coap_uri_t
|
||||
@ -35,7 +59,7 @@ typedef struct {
|
||||
*
|
||||
* @return New URI object or NULL on error.
|
||||
*/
|
||||
coap_uri_t *coap_new_uri(const unsigned char *uri, unsigned int length);
|
||||
coap_uri_t *coap_new_uri(const uint8_t *uri, unsigned int length);
|
||||
|
||||
/**
|
||||
* Clones the specified coap_uri_t object. Thie function allocates sufficient
|
||||
@ -43,18 +67,6 @@ coap_uri_t *coap_new_uri(const unsigned char *uri, unsigned int length);
|
||||
* be released with coap_free(). */
|
||||
coap_uri_t *coap_clone_uri(const coap_uri_t *uri);
|
||||
|
||||
/**
|
||||
* Calculates a hash over the given path and stores the result in
|
||||
* @p key. This function returns @c 0 on error or @c 1 on success.
|
||||
*
|
||||
* @param path The URI path to generate hash for.
|
||||
* @param len The length of @p path.
|
||||
* @param key The output buffer.
|
||||
*
|
||||
* @return @c 1 if @p key was set, @c 0 otherwise.
|
||||
*/
|
||||
int coap_hash_path(const unsigned char *path, size_t len, coap_key_t key);
|
||||
|
||||
/**
|
||||
* @defgroup uri_parse URI Parsing Functions
|
||||
*
|
||||
@ -69,53 +81,67 @@ int coap_hash_path(const unsigned char *path, size_t len, coap_key_t key);
|
||||
* components that are not specified will be set to { 0, 0 }, except for the
|
||||
* port which is set to @c COAP_DEFAULT_PORT. This function returns @p 0 if
|
||||
* parsing succeeded, a value less than zero otherwise.
|
||||
*
|
||||
*
|
||||
* @param str_var The string to split up.
|
||||
* @param len The actual length of @p str_var
|
||||
* @param uri The coap_uri_t object to store the result.
|
||||
* @return @c 0 on success, or < 0 on error.
|
||||
*
|
||||
*/
|
||||
int coap_split_uri(const unsigned char *str_var, size_t len, coap_uri_t *uri);
|
||||
int coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri);
|
||||
|
||||
/**
|
||||
* Splits the given URI path into segments. Each segment is preceded
|
||||
* by an option pseudo-header with delta-value 0 and the actual length
|
||||
* of the respective segment after percent-decoding.
|
||||
*
|
||||
* @param s The path string to split.
|
||||
*
|
||||
* @param s The path string to split.
|
||||
* @param length The actual length of @p s.
|
||||
* @param buf Result buffer for parsed segments.
|
||||
* @param buf Result buffer for parsed segments.
|
||||
* @param buflen Maximum length of @p buf. Will be set to the actual number
|
||||
* of bytes written into buf on success.
|
||||
*
|
||||
*
|
||||
* @return The number of segments created or @c -1 on error.
|
||||
*/
|
||||
int coap_split_path(const unsigned char *s,
|
||||
int coap_split_path(const uint8_t *s,
|
||||
size_t length,
|
||||
unsigned char *buf,
|
||||
size_t *buflen);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Splits the given URI query into segments. Each segment is preceded
|
||||
* by an option pseudo-header with delta-value 0 and the actual length
|
||||
* of the respective query term.
|
||||
*
|
||||
* @param s The query string to split.
|
||||
*
|
||||
* @param s The query string to split.
|
||||
* @param length The actual length of @p s.
|
||||
* @param buf Result buffer for parsed segments.
|
||||
* @param buf Result buffer for parsed segments.
|
||||
* @param buflen Maximum length of @p buf. Will be set to the actual number
|
||||
* of bytes written into buf on success.
|
||||
*
|
||||
*
|
||||
* @return The number of segments created or @c -1 on error.
|
||||
*
|
||||
* @bug This function does not reserve additional space for delta > 12.
|
||||
*/
|
||||
int coap_split_query(const unsigned char *s,
|
||||
int coap_split_query(const uint8_t *s,
|
||||
size_t length,
|
||||
unsigned char *buf,
|
||||
size_t *buflen);
|
||||
|
||||
/**
|
||||
* Extract query string from request PDU according to escape rules in 6.5.8.
|
||||
* @param request Request PDU.
|
||||
* @return Reconstructed and escaped query string part.
|
||||
*/
|
||||
coap_string_t *coap_get_query(const struct coap_pdu_t *request);
|
||||
|
||||
/**
|
||||
* Extract uri_path string from request PDU
|
||||
* @param request Request PDU.
|
||||
* @return Reconstructed and escaped uri path string part.
|
||||
*/
|
||||
coap_string_t *coap_get_uri_path(const struct coap_pdu_t *request);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* _COAP_URI_H_ */
|
||||
#endif /* COAP_URI_H_ */
|
||||
|
Reference in New Issue
Block a user