mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
net/nanocoap: Move NANOCOAP_URI_MAX to 'CONFIG_' namespace
This commit is contained in:
parent
c84576ef6e
commit
4052c01e85
@ -24,7 +24,7 @@ static const uint8_t block2_mcu[] = " board with a ";
|
|||||||
static ssize_t _echo_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len, void *context)
|
static ssize_t _echo_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len, void *context)
|
||||||
{
|
{
|
||||||
(void)context;
|
(void)context;
|
||||||
char uri[NANOCOAP_URI_MAX];
|
char uri[CONFIG_NANOCOAP_URI_MAX];
|
||||||
|
|
||||||
if (coap_get_uri_path(pkt, (uint8_t *)uri) <= 0) {
|
if (coap_get_uri_path(pkt, (uint8_t *)uri) <= 0) {
|
||||||
return coap_reply_simple(pkt, COAP_CODE_INTERNAL_SERVER_ERROR, buf,
|
return coap_reply_simple(pkt, COAP_CODE_INTERNAL_SERVER_ERROR, buf,
|
||||||
|
@ -132,8 +132,8 @@ extern "C" {
|
|||||||
* @brief Maximum length of a resource path string read from or written to
|
* @brief Maximum length of a resource path string read from or written to
|
||||||
* a message
|
* a message
|
||||||
*/
|
*/
|
||||||
#ifndef NANOCOAP_URI_MAX
|
#ifndef CONFIG_NANOCOAP_URI_MAX
|
||||||
#define NANOCOAP_URI_MAX (64)
|
#define CONFIG_NANOCOAP_URI_MAX (64)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -516,18 +516,18 @@ static inline ssize_t coap_get_location_query(const coap_pkt_t *pkt,
|
|||||||
* This function decodes the pkt's URI option into a "/"-separated and
|
* This function decodes the pkt's URI option into a "/"-separated and
|
||||||
* '\0'-terminated string.
|
* '\0'-terminated string.
|
||||||
*
|
*
|
||||||
* Caller must ensure @p target can hold at least NANOCOAP_URI_MAX bytes!
|
* Caller must ensure @p target can hold at least CONFIG_NANOCOAP_URI_MAX bytes!
|
||||||
*
|
*
|
||||||
* @param[in] pkt pkt to work on
|
* @param[in] pkt pkt to work on
|
||||||
* @param[out] target buffer for target URI
|
* @param[out] target buffer for target URI
|
||||||
*
|
*
|
||||||
* @returns -ENOSPC if URI option is larger than NANOCOAP_URI_MAX
|
* @returns -ENOSPC if URI option is larger than CONFIG_NANOCOAP_URI_MAX
|
||||||
* @returns nr of bytes written to @p target (including '\0')
|
* @returns nr of bytes written to @p target (including '\0')
|
||||||
*/
|
*/
|
||||||
static inline ssize_t coap_get_uri_path(const coap_pkt_t *pkt, uint8_t *target)
|
static inline ssize_t coap_get_uri_path(const coap_pkt_t *pkt, uint8_t *target)
|
||||||
{
|
{
|
||||||
return coap_opt_get_string(pkt, COAP_OPT_URI_PATH, target,
|
return coap_opt_get_string(pkt, COAP_OPT_URI_PATH, target,
|
||||||
NANOCOAP_URI_MAX, '/');
|
CONFIG_NANOCOAP_URI_MAX, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -536,18 +536,18 @@ static inline ssize_t coap_get_uri_path(const coap_pkt_t *pkt, uint8_t *target)
|
|||||||
* This function decodes the pkt's URI_QUERY option into a "&"-separated and
|
* This function decodes the pkt's URI_QUERY option into a "&"-separated and
|
||||||
* '\0'-terminated string.
|
* '\0'-terminated string.
|
||||||
*
|
*
|
||||||
* Caller must ensure @p target can hold at least NANOCOAP_URI_MAX bytes!
|
* Caller must ensure @p target can hold at least CONFIG_NANOCOAP_URI_MAX bytes!
|
||||||
*
|
*
|
||||||
* @param[in] pkt pkt to work on
|
* @param[in] pkt pkt to work on
|
||||||
* @param[out] target buffer for target URI
|
* @param[out] target buffer for target URI
|
||||||
*
|
*
|
||||||
* @returns -ENOSPC if URI option is larger than NANOCOAP_URI_MAX
|
* @returns -ENOSPC if URI option is larger than CONFIG_NANOCOAP_URI_MAX
|
||||||
* @returns nr of bytes written to @p target (including '\0')
|
* @returns nr of bytes written to @p target (including '\0')
|
||||||
*/
|
*/
|
||||||
static inline ssize_t coap_get_uri_query(const coap_pkt_t *pkt, uint8_t *target)
|
static inline ssize_t coap_get_uri_query(const coap_pkt_t *pkt, uint8_t *target)
|
||||||
{
|
{
|
||||||
return coap_opt_get_string(pkt, COAP_OPT_URI_QUERY, target,
|
return coap_opt_get_string(pkt, COAP_OPT_URI_QUERY, target,
|
||||||
NANOCOAP_URI_MAX, '&');
|
CONFIG_NANOCOAP_URI_MAX, '&');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,8 +48,8 @@
|
|||||||
static char *_regif_buf;
|
static char *_regif_buf;
|
||||||
static size_t _regif_buf_len;
|
static size_t _regif_buf_len;
|
||||||
|
|
||||||
static char _rd_loc[NANOCOAP_URI_MAX];
|
static char _rd_loc[CONFIG_NANOCOAP_URI_MAX];
|
||||||
static char _rd_regif[NANOCOAP_URI_MAX];
|
static char _rd_regif[CONFIG_NANOCOAP_URI_MAX];
|
||||||
static sock_udp_ep_t _rd_remote;
|
static sock_udp_ep_t _rd_remote;
|
||||||
|
|
||||||
static mutex_t _mutex = MUTEX_INIT;
|
static mutex_t _mutex = MUTEX_INIT;
|
||||||
|
@ -379,7 +379,7 @@ static int _find_resource(coap_pkt_t *pdu, const coap_resource_t **resource_ptr,
|
|||||||
/* Find path for CoAP msg among listener resources and execute callback. */
|
/* Find path for CoAP msg among listener resources and execute callback. */
|
||||||
gcoap_listener_t *listener = _coap_state.listeners;
|
gcoap_listener_t *listener = _coap_state.listeners;
|
||||||
|
|
||||||
uint8_t uri[NANOCOAP_URI_MAX];
|
uint8_t uri[CONFIG_NANOCOAP_URI_MAX];
|
||||||
if (coap_get_uri_path(pdu, uri) <= 0) {
|
if (coap_get_uri_path(pdu, uri) <= 0) {
|
||||||
return GCOAP_RESOURCE_NO_PATH;
|
return GCOAP_RESOURCE_NO_PATH;
|
||||||
}
|
}
|
||||||
|
@ -395,7 +395,7 @@ ssize_t coap_tree_handler(coap_pkt_t *pkt, uint8_t *resp_buf,
|
|||||||
{
|
{
|
||||||
coap_method_flags_t method_flag = coap_method2flag(coap_get_code_detail(pkt));
|
coap_method_flags_t method_flag = coap_method2flag(coap_get_code_detail(pkt));
|
||||||
|
|
||||||
uint8_t uri[NANOCOAP_URI_MAX];
|
uint8_t uri[CONFIG_NANOCOAP_URI_MAX];
|
||||||
if (coap_get_uri_path(pkt, uri) <= 0) {
|
if (coap_get_uri_path(pkt, uri) <= 0) {
|
||||||
return -EBADMSG;
|
return -EBADMSG;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ int _cord_ep_handler(int argc, char **argv)
|
|||||||
printf("usage: %s discover <server address>\n", argv[0]);
|
printf("usage: %s discover <server address>\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
char regif[NANOCOAP_URI_MAX];
|
char regif[CONFIG_NANOCOAP_URI_MAX];
|
||||||
sock_udp_ep_t remote;
|
sock_udp_ep_t remote;
|
||||||
if (make_sock_ep(&remote, argv[2]) < 0) {
|
if (make_sock_ep(&remote, argv[2]) < 0) {
|
||||||
printf("error: unable to parse address\n");
|
printf("error: unable to parse address\n");
|
||||||
|
@ -88,7 +88,7 @@ static void test_gcoap__client_get_req(void)
|
|||||||
coap_get_total_hdr_len(&pdu));
|
coap_get_total_hdr_len(&pdu));
|
||||||
TEST_ASSERT_EQUAL_INT(COAP_TYPE_NON, coap_get_type(&pdu));
|
TEST_ASSERT_EQUAL_INT(COAP_TYPE_NON, coap_get_type(&pdu));
|
||||||
|
|
||||||
char uri[NANOCOAP_URI_MAX] = {0};
|
char uri[CONFIG_NANOCOAP_URI_MAX] = {0};
|
||||||
coap_get_uri_path(&pdu, (uint8_t *)&uri[0]);
|
coap_get_uri_path(&pdu, (uint8_t *)&uri[0]);
|
||||||
TEST_ASSERT_EQUAL_STRING(&path[0], &uri[0]);
|
TEST_ASSERT_EQUAL_STRING(&path[0], &uri[0]);
|
||||||
TEST_ASSERT_EQUAL_INT(0, pdu.payload_len);
|
TEST_ASSERT_EQUAL_INT(0, pdu.payload_len);
|
||||||
@ -198,7 +198,7 @@ static void test_gcoap__client_get_path_defer(void)
|
|||||||
|
|
||||||
coap_parse(&pdu, buf, len);
|
coap_parse(&pdu, buf, len);
|
||||||
|
|
||||||
char uri[NANOCOAP_URI_MAX] = {0};
|
char uri[CONFIG_NANOCOAP_URI_MAX] = {0};
|
||||||
coap_get_uri_path(&pdu, (uint8_t *)&uri[0]);
|
coap_get_uri_path(&pdu, (uint8_t *)&uri[0]);
|
||||||
TEST_ASSERT_EQUAL_STRING(&path[0], &uri[0]);
|
TEST_ASSERT_EQUAL_STRING(&path[0], &uri[0]);
|
||||||
}
|
}
|
||||||
@ -238,7 +238,7 @@ static void test_gcoap__server_get_req(void)
|
|||||||
TEST_ASSERT_EQUAL_INT(COAP_TYPE_NON, coap_get_type(&pdu));
|
TEST_ASSERT_EQUAL_INT(COAP_TYPE_NON, coap_get_type(&pdu));
|
||||||
TEST_ASSERT_EQUAL_INT(0, pdu.payload_len);
|
TEST_ASSERT_EQUAL_INT(0, pdu.payload_len);
|
||||||
|
|
||||||
char uri[NANOCOAP_URI_MAX] = {0};
|
char uri[CONFIG_NANOCOAP_URI_MAX] = {0};
|
||||||
coap_get_uri_path(&pdu, (uint8_t *)&uri[0]);
|
coap_get_uri_path(&pdu, (uint8_t *)&uri[0]);
|
||||||
TEST_ASSERT_EQUAL_STRING("/cli/stats", &uri[0]);
|
TEST_ASSERT_EQUAL_STRING("/cli/stats", &uri[0]);
|
||||||
}
|
}
|
||||||
|
@ -223,13 +223,13 @@ static void test_nanocoap__get_max_path(void)
|
|||||||
len = coap_opt_add_string(&pkt, COAP_OPT_URI_PATH, &path[0], '/');
|
len = coap_opt_add_string(&pkt, COAP_OPT_URI_PATH, &path[0], '/');
|
||||||
TEST_ASSERT_EQUAL_INT(uri_opt_len, len);
|
TEST_ASSERT_EQUAL_INT(uri_opt_len, len);
|
||||||
|
|
||||||
char uri[NANOCOAP_URI_MAX] = {0};
|
char uri[CONFIG_NANOCOAP_URI_MAX] = {0};
|
||||||
coap_get_uri_path(&pkt, (uint8_t *)&uri[0]);
|
coap_get_uri_path(&pkt, (uint8_t *)&uri[0]);
|
||||||
TEST_ASSERT_EQUAL_STRING((char *)path, (char *)uri);
|
TEST_ASSERT_EQUAL_STRING((char *)path, (char *)uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Builds on get_req test, to test path longer than NANOCOAP_URI_MAX. We
|
* Builds on get_req test, to test path longer than CONFIG_NANOCOAP_URI_MAX. We
|
||||||
* expect coap_get_uri_path() to return -ENOSPC.
|
* expect coap_get_uri_path() to return -ENOSPC.
|
||||||
*/
|
*/
|
||||||
static void test_nanocoap__get_path_too_long(void)
|
static void test_nanocoap__get_path_too_long(void)
|
||||||
@ -250,7 +250,7 @@ static void test_nanocoap__get_path_too_long(void)
|
|||||||
len = coap_opt_add_string(&pkt, COAP_OPT_URI_PATH, &path[0], '/');
|
len = coap_opt_add_string(&pkt, COAP_OPT_URI_PATH, &path[0], '/');
|
||||||
TEST_ASSERT_EQUAL_INT(uri_opt_len, len);
|
TEST_ASSERT_EQUAL_INT(uri_opt_len, len);
|
||||||
|
|
||||||
char uri[NANOCOAP_URI_MAX] = {0};
|
char uri[CONFIG_NANOCOAP_URI_MAX] = {0};
|
||||||
int get_len = coap_get_uri_path(&pkt, (uint8_t *)&uri[0]);
|
int get_len = coap_get_uri_path(&pkt, (uint8_t *)&uri[0]);
|
||||||
TEST_ASSERT_EQUAL_INT(-ENOSPC, get_len);
|
TEST_ASSERT_EQUAL_INT(-ENOSPC, get_len);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user