-
Notifications
You must be signed in to change notification settings - Fork 2k
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
gcoap: Add file server #14397
Closed
Closed
gcoap: Add file server #14397
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2bc74a6
coapfileserver: New module to serve VFS via CoAP
chrysn abe369f
coap: Add ETag code from RFC7252
chrysn 4ae2c60
coapfileserver: Add support for ETag
chrysn 5ac9898
coapfileserver: Serve files blockwise
chrysn 7d02c94
coapfileserver: Error handling
chrysn ab858b4
coapfileserver: Cling to filesystem example
chrysn 73b2ccf
coapfileserver: Work around different slash conventions
chrysn 1c3f63f
coapfileserver: Hide . and ..
chrysn 604dc91
coapfileserver: Work around missing stat in fatfs
chrysn 527d37a
coapfileserver: Server links with correct trailing slashes
chrysn 893874c
coapfileserver: Adopt different reading of RFC6690
chrysn 87072a2
fixup! coapfileserver: New module to serve VFS via CoAP
chrysn 92ea550
fixup! coapfileserver: New module to serve VFS via CoAP
chrysn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (C) 2020 chrysn | ||
* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* @ingroup net_coapfileserver | ||
* @{ | ||
* | ||
* @file | ||
* @brief Resource handler for the CoAP file system server | ||
* | ||
* @author chrysn <chrysn@fsfe.org> | ||
* | ||
* @} | ||
*/ | ||
|
||
#ifndef NET_COAPFILESERVER_H | ||
#define NET_COAPFILESERVER_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <net/nanocoap.h> | ||
|
||
/** File server starting point | ||
* | ||
* This struct needs to be present at the ctx of a coapfileserver_handler entry | ||
* in a resource list. | ||
* | ||
*/ | ||
struct coapfileserver_entry { | ||
/** Path in the VFS that should be served. | ||
* | ||
* This does not need a trailing slash. */ | ||
char *nameprefix; | ||
/** Number of leading path components to ignore as they are the common prefix. | ||
* | ||
* If the file server is bound to the "/" resource, make this 0; if there | ||
* is an entry | ||
* | ||
* ``{ "/files/sd", COAP_GET | COAP_MATCH_SUBTREE, coapfileserver_handler, files_sd }`` | ||
* | ||
* then ``files_sd.strip_path`` needs to be 2. | ||
* | ||
* */ | ||
uint8_t strip_path; | ||
}; | ||
|
||
/** | ||
* File server handler | ||
* | ||
* Serve a directory from the VFS as a CoAP resource tree. | ||
* | ||
* @p ctx pointer to a @ref coapfileserver_entry | ||
* | ||
* @see net_coapfileserver | ||
*/ | ||
ssize_t coapfileserver_handler(coap_pkt_t *pdu, uint8_t *buf, size_t len, void *ctx); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* NET_COAPFILESERVER_H */ | ||
|
||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,5 @@ | ||||||
MODULE = coapfileserver | ||||||
|
||||||
SRC = coapfileserver.c | ||||||
|
||||||
Comment on lines
+2
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed, the file should be included automatically:
Suggested change
|
||||||
include $(RIOTBASE)/Makefile.base |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to move this to an auto-init function? Is there a reason why this needs to be registered from the application?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only if it were to be made configurable as to the file system entry point and to the coap entry point -- we really shouldn't pick resource names on users' CoAP servers. (And there'd still need to allow manual management for things like ACLs, or when different mount points need different treatment on the CoAP side, eg. w/rt writability).
AFAIK we currently don't do any automatically inserted CoAP resources (other than /.well-known/core). Doing that efficiently would mean putting sorted entries into an array, AFAICT that can't be done even with XFA (#15002) and'd thus need pre-sorting by wherethroughever the configured paths are set. (For example, if coapfileserver did this and so did a hypothetical resourcedirectory, they'd need to be put as ["/.well-known/core", "/coapfileserver", "/rd"] with the one set of names but as ["/.well-known/core", "/cord-server", "/files"] with others).
I'll give it a try, but it may result in an "I'd rather do this as a next step".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I was thinking as well on making the entry point configurable.
Yeah, that's true. Maybe if we could adapt the path matching function on nanocoap we could get rid of the alphabetical ordering constraint? In any case, if that's needed it would be work for a follow up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, meant the gcoap matching, that's the one that enforces this.