Skip to content

Commit

Permalink
MERGECOMMIT: gcoap: Add file server RIOT-OS#14397
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn authored and fjmolinas committed Apr 15, 2022
1 parent 37bd6c5 commit ba1ad62
Show file tree
Hide file tree
Showing 7 changed files with 548 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ endif
ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
FILTER += xtimer
endif
ifneq (,$(filter coapfileserver,$(USEMODULE)))
DIRS += net/application_layer/coapfileserver
endif

DIRS += $(dir $(wildcard $(addsuffix /Makefile, $(filter-out $(FILTER), $(USEMODULE)))))

Expand Down
4 changes: 4 additions & 0 deletions sys/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,10 @@ ifneq (,$(filter devfs,$(USEMODULE)))
USEMODULE += vfs
endif

ifneq (,$(filter coapfileserver,$(USEMODULE)))
USEMODULE += vfs
endif

ifneq (,$(filter vfs_default,$(USEMODULE)))
USEMODULE += vfs
DEFAULT_MODULE += vfs_auto_mount
Expand Down
1 change: 1 addition & 0 deletions sys/include/net/coap.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extern "C" {
* @{
*/
#define COAP_OPT_URI_HOST (3)
#define COAP_OPT_ETAG (4)
#define COAP_OPT_OBSERVE (6)
#define COAP_OPT_LOCATION_PATH (8)
#define COAP_OPT_URI_PATH (11)
Expand Down
71 changes: 71 additions & 0 deletions sys/include/net/coapfileserver.h
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 */

/** @} */
5 changes: 5 additions & 0 deletions sys/net/application_layer/coapfileserver/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MODULE = coapfileserver

SRC = coapfileserver.c

include $(RIOTBASE)/Makefile.base
Loading

0 comments on commit ba1ad62

Please sign in to comment.