Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kconfig: Expose net/sock/util configurations #12944

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion makefiles/suit.v4.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SUIT_NOTIFY_VERSION ?= latest
SUIT_NOTIFY_MANIFEST ?= $(APPLICATION)-riot.suitv4_signed.$(SUIT_NOTIFY_VERSION).bin

# Long manifest names require more buffer space when parsing
export CFLAGS += -DSOCK_URLPATH_MAXLEN=128
export CFLAGS += -DCONFIG_SOCK_URLPATH_MAXLEN=128

SUIT_VENDOR ?= "riot-os.org"
SUIT_SEQNR ?= $(APP_VER)
Expand Down
18 changes: 9 additions & 9 deletions sys/include/net/sock/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint, char *addr_str, uint16_t *por
* "host.name:1234" and "/url/path".
*
* @note Caller has to make sure hostport and urlpath can hold the results!
* Make sure to provide space for @ref SOCK_HOSTPORT_MAXLEN respectively
* @ref SOCK_URLPATH_MAXLEN bytes, if pointers are not NULL.
* Scheme part of the URL is limited to @ref SOCK_SCHEME_MAXLEN length.
* Make sure to provide space for @ref CONFIG_SOCK_HOSTPORT_MAXLEN respectively
* @ref CONFIG_SOCK_URLPATH_MAXLEN bytes, if pointers are not NULL.
* Scheme part of the URL is limited to @ref CONFIG_SOCK_SCHEME_MAXLEN length.
*
* @pre `url != NULL`
*
Expand Down Expand Up @@ -109,22 +109,22 @@ bool sock_udp_ep_equal(const sock_udp_ep_t *a, const sock_udp_ep_t *b);
*
* Ensures a hard limit on the string iterator
* */
#ifndef SOCK_SCHEME_MAXLEN
#define SOCK_SCHEME_MAXLEN (16U)
#ifndef CONFIG_SOCK_SCHEME_MAXLEN
#define CONFIG_SOCK_SCHEME_MAXLEN (16U)
#endif

/**
* @brief maximum length of host:port part for sock_urlsplit()
*/
#ifndef SOCK_HOSTPORT_MAXLEN
#define SOCK_HOSTPORT_MAXLEN (64U)
#ifndef CONFIG_SOCK_HOSTPORT_MAXLEN
#define CONFIG_SOCK_HOSTPORT_MAXLEN (64U)
#endif

/**
* @brief maximum length path for sock_urlsplit()
*/
#ifndef SOCK_URLPATH_MAXLEN
#define SOCK_URLPATH_MAXLEN (64U)
#ifndef CONFIG_SOCK_URLPATH_MAXLEN
#define CONFIG_SOCK_URLPATH_MAXLEN (64U)
#endif

/** @} */
Expand Down
1 change: 1 addition & 0 deletions sys/net/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
menu "Networking"

rsource "gnrc/Kconfig"
rsource "sock/Kconfig"

endmenu # Networking
31 changes: 31 additions & 0 deletions sys/net/sock/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2019 HAW Hamburg
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#
menuconfig KCONFIG_MODULE_SOCK_UTIL
bool "Configure SOCK utility functions"
depends on MODULE_SOCK_UTIL

if KCONFIG_MODULE_SOCK_UTIL

config SOCK_SCHEME_MAXLEN
int "Maximum length of the scheme part"
default 16
help
This value is used in sock_urlsplit().

config SOCK_HOSTPORT_MAXLEN
int "Maximum length of host:port part"
default 64
help
This value is used in sock_urlsplit().

config SOCK_URLPATH_MAXLEN
int "Maximum path length"
default 64
help
This value is used in sock_urlsplit().

endif # KCONFIG_MODULE_SOCK_UTIL
14 changes: 7 additions & 7 deletions sys/net/sock/sock_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint, char *addr_str, uint16_t *por

static char* _find_hoststart(const char *url)
{
/* Increment SOCK_SCHEME_MAXLEN due to comparison with the colon after the
/* Increment CONFIG_SOCK_SCHEME_MAXLEN due to comparison with the colon after the
* scheme part
*/
size_t remaining = SOCK_SCHEME_MAXLEN + 1;
size_t remaining = CONFIG_SOCK_SCHEME_MAXLEN + 1;
char *urlpos = (char*)url;
while(*urlpos && remaining) {
remaining--;
Expand All @@ -103,7 +103,7 @@ static char* _find_hoststart(const char *url)

static char* _find_pathstart(const char *url)
{
size_t remaining = SOCK_HOSTPORT_MAXLEN;
size_t remaining = CONFIG_SOCK_HOSTPORT_MAXLEN;
char *urlpos = (char*)url;
while(*urlpos && remaining) {
remaining--;
Expand All @@ -127,9 +127,9 @@ int sock_urlsplit(const char *url, char *hostport, char *urlpath)

if (hostport) {
size_t hostlen = pathstart - hoststart;
/* hostlen must be smaller SOCK_HOSTPORT_MAXLEN to have space for the null
/* hostlen must be smaller CONFIG_SOCK_HOSTPORT_MAXLEN to have space for the null
* terminator */
if (hostlen > SOCK_HOSTPORT_MAXLEN - 1) {
if (hostlen > CONFIG_SOCK_HOSTPORT_MAXLEN - 1) {
return -EOVERFLOW;
}
memcpy(hostport, hoststart, hostlen);
Expand All @@ -138,7 +138,7 @@ int sock_urlsplit(const char *url, char *hostport, char *urlpath)

if (urlpath) {
size_t pathlen = strlen(pathstart);
if (pathlen > SOCK_URLPATH_MAXLEN - 1) {
if (pathlen > CONFIG_SOCK_URLPATH_MAXLEN - 1) {
return -EOVERFLOW;
}
memcpy(urlpath, pathstart, pathlen);
Expand All @@ -153,7 +153,7 @@ int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
char *hoststart = (char*)str;
char *hostend;

char hostbuf[SOCK_HOSTPORT_MAXLEN];
char hostbuf[CONFIG_SOCK_HOSTPORT_MAXLEN];

memset(ep_out, 0, sizeof(sock_udp_ep_t));

Expand Down
4 changes: 2 additions & 2 deletions sys/suit/coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ int suit_coap_get_blockwise_url(const char *url,
coap_blksize_t blksize,
coap_blockwise_cb_t callback, void *arg)
{
char hostport[SOCK_HOSTPORT_MAXLEN];
char urlpath[SOCK_URLPATH_MAXLEN];
char hostport[CONFIG_SOCK_HOSTPORT_MAXLEN];
char urlpath[CONFIG_SOCK_URLPATH_MAXLEN];
sock_udp_ep_t remote;

if (strncmp(url, "coap://", 7)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/tests-sock_util/tests-sock_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
#define TEST_STR2EP_INVALID "[2001:db8:a:b:c:d:e:f:1]"
#define TEST_STR2EP_INVALID2 "[2001:db8:a:b:c:d:e:f]:66000"

static char addr[SOCK_URLPATH_MAXLEN];
static char urlpath[SOCK_URLPATH_MAXLEN];
static char addr[CONFIG_SOCK_URLPATH_MAXLEN];
static char urlpath[CONFIG_SOCK_URLPATH_MAXLEN];


static void setup(void)
Expand Down