mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/shell: ncget: make use of nanocoap_link_format_get()
This commit is contained in:
parent
7b7c63b638
commit
f06c76348a
@ -216,6 +216,7 @@ endif
|
||||
ifneq (,$(filter shell_cmd_nanocoap_vfs,$(USEMODULE)))
|
||||
USEMODULE += nanocoap_vfs
|
||||
USEMODULE += vfs_util
|
||||
USEMODULE += nanocoap_link_format
|
||||
endif
|
||||
ifneq (,$(filter shell_cmd_netstats_neighbor,$(USEMODULE)))
|
||||
USEMODULE += netstats_neighbor
|
||||
|
@ -23,8 +23,10 @@
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "net/nanocoap/link_format.h"
|
||||
#include "net/nanocoap_sock.h"
|
||||
#include "net/nanocoap_vfs.h"
|
||||
|
||||
#include "shell.h"
|
||||
#include "vfs_default.h"
|
||||
#include "vfs_util.h"
|
||||
@ -48,6 +50,21 @@ static bool _is_dir(const char *url)
|
||||
return url[len - 1] == '/';
|
||||
}
|
||||
|
||||
static int _resource_cb(char *entry, void *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
|
||||
char *start = strchr(entry, '<');
|
||||
if (start) {
|
||||
char *end = strchr(entry, '>');
|
||||
*end = '\0';
|
||||
entry = start + 1;
|
||||
}
|
||||
|
||||
puts(entry);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _print_cb(void *arg, size_t offset, uint8_t *buf, size_t len, int more)
|
||||
{
|
||||
(void)arg;
|
||||
@ -61,41 +78,6 @@ static int _print_cb(void *arg, size_t offset, uint8_t *buf, size_t len, int mor
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _print_dir_cb(void *arg, size_t offset, uint8_t *buf, size_t len, int more)
|
||||
{
|
||||
(void)offset;
|
||||
(void)more;
|
||||
|
||||
struct dir_list_ctx *ctx = arg;
|
||||
|
||||
char *end = (char *)buf + len;
|
||||
for (char *c = (char *)buf; c < end; ++c) {
|
||||
if (ctx->cur) {
|
||||
if (*c == '>' || ctx->cur == ctx->end) {
|
||||
*ctx->cur = 0;
|
||||
puts(ctx->buf);
|
||||
ctx->cur = NULL;
|
||||
} else {
|
||||
*ctx->cur++ = *c;
|
||||
}
|
||||
} else if (*c == '<') {
|
||||
ctx->cur = ctx->buf;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _print_dir(const char *url, char *buf, size_t len)
|
||||
{
|
||||
struct dir_list_ctx ctx = {
|
||||
.buf = buf,
|
||||
.end = buf + len,
|
||||
};
|
||||
return nanocoap_get_blockwise_url(url, CONFIG_NANOCOAP_BLOCKSIZE_DEFAULT,
|
||||
_print_dir_cb, &ctx);
|
||||
}
|
||||
|
||||
static int _nanocoap_get_handler(int argc, char **argv)
|
||||
{
|
||||
int res;
|
||||
@ -109,7 +91,7 @@ static int _nanocoap_get_handler(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (_is_dir(url) && argc < 3) {
|
||||
res = _print_dir(url, buffer, sizeof(buffer));
|
||||
res = nanocoap_link_format_get_url(url, _resource_cb, NULL);
|
||||
if (res) {
|
||||
printf("Request failed: %s\n", strerror(-res));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user