mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-15 01:23:49 +01:00
Merge pull request #20655 from benpicco/nanocoap_link_format_get-fix
nanocoap_link_format: don't drop characters in fragmented entries
This commit is contained in:
commit
19effe1020
@ -58,16 +58,21 @@ static int _dirlist_cb(void *arg, size_t offset, uint8_t *buf, size_t len, int m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*c == ',' || ctx->cur == ctx->end) {
|
bool found_end = false;
|
||||||
int res;
|
if (*c == ',') {
|
||||||
|
found_end = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*ctx->cur++ = *c;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found_end || ctx->cur == ctx->end) {
|
||||||
*ctx->cur = 0;
|
*ctx->cur = 0;
|
||||||
res = ctx->cb(ctx->buf, ctx->ctx);
|
int res = ctx->cb(ctx->buf, ctx->ctx);
|
||||||
ctx->cur = ctx->buf;
|
ctx->cur = ctx->buf;
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
*ctx->cur++ = *c;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +90,7 @@ int nanocoap_link_format_get(nanocoap_sock_t *sock, const char *path,
|
|||||||
char buffer[CONFIG_NANOCOAP_QS_MAX];
|
char buffer[CONFIG_NANOCOAP_QS_MAX];
|
||||||
struct dir_list_ctx ctx = {
|
struct dir_list_ctx ctx = {
|
||||||
.buf = buffer,
|
.buf = buffer,
|
||||||
.end = buffer + sizeof(buffer) - 1,
|
.end = buffer + sizeof(buffer),
|
||||||
.cur = buffer,
|
.cur = buffer,
|
||||||
.cb = cb,
|
.cb = cb,
|
||||||
.ctx = arg,
|
.ctx = arg,
|
||||||
|
|||||||
@ -52,16 +52,31 @@ static bool _is_dir(const char *url)
|
|||||||
|
|
||||||
static int _resource_cb(char *entry, void *ctx)
|
static int _resource_cb(char *entry, void *ctx)
|
||||||
{
|
{
|
||||||
(void)ctx;
|
bool *too_long = ctx;
|
||||||
|
char *start, *end;
|
||||||
|
|
||||||
char *start = strchr(entry, '<');
|
if (*too_long) {
|
||||||
if (start) {
|
goto find_end;
|
||||||
char *end = strchr(entry, '>');
|
}
|
||||||
*end = '\0';
|
|
||||||
entry = start + 1;
|
start = strchr(entry, '<');
|
||||||
|
if (start == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
entry = start + 1;
|
||||||
|
|
||||||
|
find_end:
|
||||||
|
end = strchr(entry, '>');
|
||||||
|
if (end == NULL) {
|
||||||
|
*too_long = true;
|
||||||
|
printf("%s", entry);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*too_long = false;
|
||||||
|
*end = '\0';
|
||||||
|
puts(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
puts(entry);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +106,8 @@ static int _nanocoap_get_handler(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_is_dir(url) && argc < 3) {
|
if (_is_dir(url) && argc < 3) {
|
||||||
res = nanocoap_link_format_get_url(url, _resource_cb, NULL);
|
bool _ctx = false;
|
||||||
|
res = nanocoap_link_format_get_url(url, _resource_cb, &_ctx);
|
||||||
if (res) {
|
if (res) {
|
||||||
printf("Request failed: %s\n", strerror(-res));
|
printf("Request failed: %s\n", strerror(-res));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user