Permalink
Browse files

Anjay 1.4.0

Features:
- New tools: lwm2m_object_registry.py and anjay_codegen.py, that allow automatic
  generation of object implementation stubs from LwM2M object definition XMLs
- anjay_download() now supports HTTP(S), using the client from avs_commons
- New APIs for querying Anjay's network traffic statistics
- New APIs in attr_storage for direct attribute manipulation:
  - anjay_attr_storage_set_object_attrs()
  - anjay_attr_storage_set_instance_attrs()
  - anjay_attr_storage_set_resource_attrs()
- CoAP implementation base has been refactored and moved to avs_commons, so that
  it can now be used standalone; Anjay code has been refactored accordingly

Bugfixes:
- Fixed a bug that prevented anjay_get_string() from working as documented when
  the buffer was too short
- Fixed conformance with RFC 7252 when sending error responses on observed
  resources (previously the Observe header was erroneously included)
- Fixed various minor bugs found through static code analysis and compilation on
  various platforms

Improvements:
- POSIX dependencies are now better isolated to ease porting onto non-POSIX
  platforms
- Added more documentation, including:
  - New tutorial page (BT4) with general notes on library usage
  - Porting guide for non-POSIX platforms
- Removed some superfluous log messages
  • Loading branch information...
kFYatek committed Sep 8, 2017
1 parent 3a0cc39 commit 8f748398858eae7987bda566431abc1c643a91ba
Showing with 5,202 additions and 9,088 deletions.
  1. +2 −0 .gitignore
  2. +42 −39 CMakeLists.txt
  3. +2 −2 README.md
  4. +1 −1 avs_commons/git
  5. +1 −0 cmake/PosixFeatures.cmake
  6. +1 −0 compat
  7. +2 −1 config/config.h.in
  8. +1 −0 config/posix-config.h.in
  9. +61 −0 demo/demo_cmds.c
  10. +44 −5 demo/objects/ext_dev_info.c
  11. +19 −110 demo/objects/firmware_update.c
  12. +7 −7 demo/objects/ip_ping.c
  13. +0 −1 demo/wget_downloader.c
  14. +1 −0 devconfig
  15. +1 −1 doc/sphinx/source/AdvancedTutorial/AT4.rst
  16. +3 −2 doc/sphinx/source/AdvancedTutorial/AT5.rst
  17. +2 −0 doc/sphinx/source/AdvancedTutorial/AT6.rst
  18. +1 −1 doc/sphinx/source/BasicTutorial/BT2.rst
  19. +10 −12 doc/sphinx/source/BasicTutorial/BT3.rst
  20. +84 −0 doc/sphinx/source/BasicTutorial/BT4.rst
  21. +1 −1 doc/sphinx/source/BasicTutorial/{BT4_CustomObject.rst → BT5_CustomObject.rst}
  22. +27 −0 doc/sphinx/source/BasicTutorial/BT5_CustomObject/Anjay_codegen_note.rst
  23. +2 −0 ...hinx/source/BasicTutorial/{BT4_CustomObject → BT5_CustomObject}/BT_CO1_SingleInstanceReadOnly.rst
  24. +8 −4 ...asicTutorial/{BT4_CustomObject → BT5_CustomObject}/BT_CO2_SingleInstanceExecutableAndReadOnly.rst
  25. +2 −2 .../source/BasicTutorial/{BT4_CustomObject → BT5_CustomObject}/BT_CO3_MultiInstanceReadOnlyFixed.rst
  26. +1 −3 ...phinx/source/BasicTutorial/{BT4_CustomObject → BT5_CustomObject}/BT_CO4_FixedInstanceWritable.rst
  27. +2 −3 ...sphinx/source/BasicTutorial/{BT4_CustomObject → BT5_CustomObject}/BT_CO5_MultiInstanceDynamic.rst
  28. +2 −1 ...x/source/BasicTutorial/{BT4_CustomObject → BT5_CustomObject}/BT_CO6_MultipleResourceInstances.rst
  29. +0 −1 doc/sphinx/source/BasicTutorial/{BT4_CustomObject → BT5_CustomObject}/BT_CO7_BootstrapAwareness.rst
  30. 0 doc/sphinx/source/BasicTutorial/{BT4_CustomObject → BT5_CustomObject}/BT_CO8_Notifications.rst
  31. +0 −50 doc/sphinx/source/Embedded_IP.rst
  32. +174 −0 doc/sphinx/source/PortingGuideForNonPOSIXPlatforms.rst
  33. +50 −0 doc/sphinx/source/Tools.rst
  34. +2 −1 doc/sphinx/source/index.rst
  35. +2 −2 examples/test_examples.md5
  36. +4 −92 include_modules/anjay_modules/time.h
  37. +0 −10 include_modules/anjay_modules/utils.h
  38. +4 −12 include_public/anjay/core.h
  39. +0 −1 include_public/anjay/io.h
  40. +58 −0 include_public/anjay/stats.h
  41. +63 −0 modules/attr_storage/include_public/anjay/attr_storage.h
  42. +244 −60 modules/attr_storage/src/attr_storage.c
  43. +199 −0 modules/attr_storage/src/test/attr_storage.c
  44. +1 −1 modules/persistence/src/persistence.c
  45. +2 −1 modules/security/src/persistence.c
  46. +1 −0 modules/security/src/security.c
  47. +3 −0 modules/security/src/utils.c
  48. +2 −1 modules/server/src/persistence.c
  49. +1 −1 modules/server/src/utils.c
  50. +1 −0 src/access_control.c
  51. +117 −86 src/anjay.c
  52. +2 −2 src/anjay.h
  53. +46 −51 src/coap/block/request.c
  54. +7 −10 src/coap/block/request.h
  55. +17 −19 src/coap/block/response.c
  56. +12 −14 src/coap/block/response.h
  57. +65 −63 src/coap/block/transfer.c
  58. +15 −15 src/coap/block/transfer_impl.h
  59. +0 −145 src/coap/block_builder.c
  60. +0 −106 src/coap/block_builder.h
  61. +0 −58 src/coap/block_utils.c
  62. +0 −72 src/coap/block_utils.h
  63. +3 −7 src/coap/content_format.h
  64. +9 −7 src/coap/id_source/auto.c
  65. +1 −1 src/coap/id_source/auto.h
  66. +5 −3 src/coap/id_source/id_source.h
  67. +4 −4 src/coap/id_source/static.c
  68. +2 −2 src/coap/id_source/static.h
  69. +0 −368 src/coap/msg.c
  70. +0 −325 src/coap/msg.h
  71. +0 −266 src/coap/msg_builder.c
  72. +0 −164 src/coap/msg_builder.h
  73. +0 −385 src/coap/msg_cache.c
  74. +0 −123 src/coap/msg_cache.h
  75. +0 −56 src/coap/msg_identity.h
  76. +0 −217 src/coap/msg_info.c
  77. +0 −201 src/coap/msg_info.h
  78. +0 −123 src/coap/msg_internal.h
  79. +0 −148 src/coap/msg_opt.c
  80. +0 −68 src/coap/msg_opt.h
  81. +0 −220 src/coap/opt.c
  82. +0 −140 src/coap/opt.h
  83. +0 −53 src/coap/parse_utils.h
  84. +0 −346 src/coap/socket.c
  85. +0 −121 src/coap/socket.h
  86. +10 −11 src/coap/stream.h
  87. +80 −95 src/coap/stream/client.c
  88. +11 −27 src/coap/stream/client.h
  89. +58 −38 src/coap/stream/common.c
  90. +18 −7 src/coap/stream/common.h
  91. +11 −11 src/coap/stream/in.c
  92. +9 −7 src/coap/stream/in.h
  93. +33 −35 src/coap/stream/out.c
  94. +16 −17 src/coap/stream/out.h
  95. +136 −159 src/coap/stream/server.c
  96. +13 −22 src/coap/stream/server.h
  97. +58 −64 src/coap/stream/stream.c
  98. +9 −12 src/coap/stream/stream.h
  99. +31 −33 src/coap/test/block_response.c
  100. +0 −505 src/coap/test/msg.c
  101. +0 −450 src/coap/test/msg_builder.c
  102. +0 −327 src/coap/test/msg_cache.c
  103. +0 −62 src/coap/test/opt.c
  104. +72 −171 src/coap/test/servers.c
  105. +9 −11 src/coap/test/servers.h
  106. +0 −129 src/coap/test/socket.c
  107. +118 −126 src/coap/test/stream.c
  108. +42 −67 src/coap/test/utils.h
  109. +0 −35 src/coap/tx_params.c
  110. +0 −108 src/coap/tx_params.h
  111. +50 −35 src/dm.c
  112. +4 −4 src/dm.h
  113. +2 −0 src/dm/attributes.c
  114. +1 −0 src/dm/discover.c
  115. +1 −0 src/dm/handlers.c
  116. +1 −0 src/dm/modules.c
  117. +3 −4 src/dm/query.c
  118. +0 −735 src/downloader.c
  119. +2 −1 src/downloader.h
  120. +584 −0 src/downloader/coap.c
  121. +230 −0 src/downloader/downloader.c
  122. +196 −0 src/downloader/http.c
  123. +78 −0 src/downloader/private.h
  124. +96 −97 src/{ → downloader}/test/downloader.c
  125. 0 src/{ → downloader}/test/downloader_mock.h
  126. +20 −17 src/interface/bootstrap.c
  127. +41 −39 src/interface/register.c
  128. +1 −1 src/interface/test/bootstrap.c
  129. +5 −5 src/io.c
  130. +2 −1 src/io.h
  131. +1 −1 src/io/base64_out.c
  132. +6 −5 src/io/dynamic.c
  133. +13 −12 src/io/json_out.c
  134. +2 −1 src/io/opaque.c
  135. +3 −5 src/io/test/dynamic.c
  136. +14 −1 src/io/test/tlv_in.c
  137. +3 −3 src/io/text.c
  138. +24 −25 src/io/tlv_in.c
  139. +2 −3 src/io/tlv_out.c
  140. +3 −1 src/notify.c
  141. +31 −30 src/observe.c
  142. +2 −2 src/observe.h
  143. +1 −0 src/observe_io.c
  144. +10 −8 src/sched.c
  145. +0 −1 src/sched.h
  146. +1 −0 src/servers/activate.c
  147. +12 −13 src/servers/connection_info.c
  148. +1 −0 src/servers/offline.c
  149. +7 −9 src/servers/register.c
  150. +1 −0 src/servers/reload.c
  151. +1 −0 src/servers/servers.c
  152. +20 −20 src/test/anjay.c
  153. +7 −7 src/test/dm.c
  154. +76 −97 src/test/observe.c
  155. +7 −8 src/test/sched.c
  156. +2 −96 src/test/utils.c
  157. +13 −26 src/utils.c
  158. +0 −6 src/utils.h
  159. +40 −0 test/codegen/CMakeLists.txt
  160. +39 −0 test/codegen/input/execute.xml
  161. +39 −0 test/codegen/input/multiple-object.xml
  162. +169 −0 test/codegen/input/read.xml
  163. +169 −0 test/codegen/input/write.xml
  164. +11 −4 test/fuzz/coap/stream.c
  165. +18 −13 test/fuzz/coap/stream_request.c
  166. +17 −8 test/fuzz/coap/stream_response.c
  167. +2 −1 test/include/anjay_test/coap/stream.h
  168. +14 −4 test/include/anjay_test/dm.h
  169. +16 −35 test/integration/framework/nsh-lwm2m/lwm2m/coap/server.py
  170. +0 −2 test/integration/framework/nsh-lwm2m/pymbedtls/src/pymbedtls.cpp
  171. +109 −56 test/integration/suites/default/firmware_update.py
  172. +20 −0 test/integration/suites/default/observe_attributes.py
  173. +4 −3 test/integration/suites/testfest/dm/firmware_update.py
  174. +9 −5 test/src/coap/stream.c
  175. +9 −8 test/src/mock_clock.c
  176. +0 −24 tools/CMakeLists.txt
  177. +2 −2 tools/analyze
  178. +621 −0 tools/anjay_codegen.py
  179. +4 −3 tools/check-license-headers.py
  180. +0 −642 tools/dtls_echo.c
  181. +18 −8 tools/generate-certs.sh
  182. +96 −0 tools/lwm2m_object_registry.py
  183. +2 −1 travis/centos7/Dockerfile
  184. +1 −1 travis/coverity/Dockerfile
  185. +1 −1 travis/prepare.sh
  186. +1 −1 travis/ubuntu-16.04/Dockerfile
  187. +11 −0 valgrind_test.supp
View
@@ -25,6 +25,7 @@ CPackSourceConfig.cmake
CTestTestfile.cmake
Testing/
config.h
posix-config.h
anjay-*.cmake
Doxyfile
/doc/sphinx/source/conf.py
@@ -39,6 +40,7 @@ Makefile
tags
.ycm_extra_conf.py
.ycm_extra_conf.pyc
/test/codegen/*.c
/test/integration/build
__pycache__/
.gdb_history
View
@@ -26,7 +26,7 @@ if(WITH_FUZZ_TESTS)
endif()
project(anjay C)
set(ANJAY_VERSION "1.3.3" CACHE STRING "Anjay library version")
set(ANJAY_VERSION "1.4.0" CACHE STRING "Anjay library version")
set(ANJAY_BINARY_VERSION 1.0.0)
set(ANJAY_BUILD_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/output")
@@ -52,25 +52,40 @@ include(TestBigEndian)
test_big_endian(ANJAY_BIG_ENDIAN)
# compilation flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
if(NOT APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_POSIX_C_SOURCE=200809L")
if(NOT CMAKE_VERSION VERSION_LESS 3.1)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_EXTENSIONS OFF)
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
endif()
option(WITH_EXTRA_WARNINGS "Enable extra compilation warnings" OFF)
if(WITH_EXTRA_WARNINGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Wextra -Winit-self -Wmissing-declarations -Wc++-compat -Wsign-conversion -Wconversion -Wcast-qual -Wno-variadic-macros -Wno-long-long")
endif()
option(WITH_DEMO "Compile DEMO applications" ON)
option(WITH_POSIX "Enable use of system-installed POSIX APIs" ON)
if(WITH_POSIX)
# macOS is weird and _POSIX_C_SOURCE causes a lot of things to disappear
if(NOT APPLE)
add_definitions(-D_POSIX_C_SOURCE=200809L)
set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200809L)
endif()
else()
set(POSIX_COMPAT_HEADER "" CACHE STRING "POSIX compatibility header path")
endif()
include(${CMAKE_CURRENT_LIST_DIR}/cmake/PosixFeatures.cmake)
cmake_dependent_option(WITH_DEMO "Compile DEMO applications" ON WITH_POSIX OFF)
option(WITH_LIBRARY_SHARED "Compile Anjay as shared library" ON)
option(WITH_ACCESS_CONTROL "Enable core support for Access Control mechanism" ON)
option(WITH_BLOCK_DOWNLOAD "Enable support for CoAP(S) downloads" ON)
option(WITH_BLOCK_RECEIVE "Enable support for receiving CoAP BLOCK transfers" ON)
option(WITH_BLOCK_SEND "Enable support for sending data in CoAP BLOCK mode" ON)
option(WITH_BOOTSTRAP "Enable LwM2M Bootstrap Interface support" ON)
option(WITH_DISCOVER "Enable support for LwM2M Discover operation" ON)
option(WITH_DOWNLOADER "Enable support for downloader API" ON)
option(WITH_OBSERVE "Enable support for Information Reporting interface (Observe)" ON)
if(WITH_OBSERVE)
option(WITH_CON_ATTR
@@ -79,14 +94,17 @@ endif()
option(WITH_LEGACY_CONTENT_FORMAT_SUPPORT
"Enable support for pre-LwM2M 1.0 CoAP Content-Format values (1541-1543)" OFF)
option(WITH_JSON "Enable support for JSON content format (output only)" OFF)
option(WITH_MESSAGE_CACHE "Enable support for message caching to detect and automatically handle duplicate messages" ON)
cmake_dependent_option(WITH_BLOCK_DOWNLOAD "Enable support for CoAP(S) downloads" ON WITH_DOWNLOADER OFF)
cmake_dependent_option(WITH_HTTP_DOWNLOAD "Enable support for HTTP(S) downloads" OFF WITH_DOWNLOADER OFF)
option(WITH_AVS_LOG "Enable logging support" ON)
cmake_dependent_option(AVS_LOG_WITH_TRACE "Enable TRACE level logging" OFF WITH_AVS_LOG OFF)
cmake_dependent_option(WITH_INTERNAL_LOGS "Enable logging from inside AVSystem Commons libraries" ON WITH_AVS_LOG OFF)
cmake_dependent_option(WITH_INTERNAL_TRACE "Enable TRACE-level logs inside AVSystem Commons libraries" ON AVS_LOG_WITH_TRACE OFF)
option(WITH_NET_STATS "Enable measuring amount of LwM2M traffic" ON)
# -fvisibility, #pragma GCC visibility
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CMakeTmp/visibility.c
@@ -135,13 +153,6 @@ endmacro()
################# CODE #########################################################
set(CORE_SOURCES
src/coap/msg.c
src/coap/msg_info.c
src/coap/msg_builder.c
src/coap/msg_opt.c
src/coap/block_builder.c
src/coap/opt.c
src/coap/socket.c
src/coap/id_source/auto.c
src/coap/id_source/static.c
src/coap/stream/client.c
@@ -150,8 +161,6 @@ set(CORE_SOURCES
src/coap/stream/out.c
src/coap/stream/server.c
src/coap/stream/stream.c
src/coap/block_utils.c
src/coap/tx_params.c
src/interface/register.c
src/io/base64_out.c
src/io/dynamic.c
@@ -181,8 +190,17 @@ set(CORE_SOURCES
if(WITH_ACCESS_CONTROL)
set(CORE_SOURCES ${CORE_SOURCES} src/access_control.c)
endif()
if(WITH_DOWNLOADER)
set(CORE_SOURCES ${CORE_SOURCES}
src/downloader/downloader.c)
endif()
if(WITH_BLOCK_DOWNLOAD)
set(CORE_SOURCES ${CORE_SOURCES} src/downloader.c)
set(CORE_SOURCES ${CORE_SOURCES}
src/downloader/coap.c)
endif()
if(WITH_HTTP_DOWNLOAD)
set(CORE_SOURCES ${CORE_SOURCES}
src/downloader/http.c)
endif()
if(WITH_BLOCK_SEND)
set(CORE_SOURCES ${CORE_SOURCES}
@@ -205,37 +223,22 @@ if(WITH_JSON)
set(CORE_SOURCES ${CORE_SOURCES}
src/io/json_out.c)
endif()
if(WITH_MESSAGE_CACHE)
set(CORE_SOURCES ${CORE_SOURCES} src/coap/msg_cache.c)
endif()
set(CORE_PRIVATE_HEADERS
src/access_control.h
src/coap/block/request.h
src/coap/block/response.h
src/coap/block/transfer.h
src/coap/block/transfer_impl.h
src/coap/block_builder.h
src/coap/id_source/id_source.h
src/coap/id_source/auto.h
src/coap/id_source/static.h
src/coap/log.h
src/coap/msg.h
src/coap/msg_builder.h
src/coap/msg_info.h
src/coap/msg_internal.h
src/coap/msg_opt.h
src/coap/opt.h
src/coap/socket.h
src/coap/stream.h
src/coap/stream/client.h
src/coap/stream/common.h
src/coap/stream/in.h
src/coap/stream/out.h
src/coap/stream/server.h
src/coap/stream/stream.h
src/coap/parse_utils.h
src/coap/block_utils.h
src/coap/tx_params.h
src/dm.h
src/dm/attributes.h
src/dm/discover.h
@@ -348,7 +351,10 @@ set(DEPS_LIBRARIES "")
set(DEPS_LIBRARIES_WEAK "")
# avs_commons required components.
set(AVS_COMMONS_COMPONENTS algorithm list vector rbtree buffer net stream utils)
set(AVS_COMMONS_COMPONENTS algorithm coap list vector rbtree buffer net stream utils)
if(WITH_HTTP_DOWNLOAD)
list(APPEND AVS_COMMONS_COMPONENTS http)
endif()
foreach(_component ${AVS_COMMONS_COMPONENTS})
string(TOUPPER ${_component} _component_uppercase)
@@ -416,6 +422,8 @@ include_directories(${PUBLIC_INCLUDE_DIRS}
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config/config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/config/config.h")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config/posix-config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/config/posix-config.h")
include_directories("${CMAKE_CURRENT_BINARY_DIR}/config")
if(WITH_LIBRARY_SHARED)
@@ -465,10 +473,6 @@ endif()
################# TEST ########################################################
if(WITH_AVS_UNIT)
add_subdirectory(tools)
endif()
macro(add_anjay_test NAME)
add_executable(${NAME}_test EXCLUDE_FROM_ALL ${ARGN})
target_link_libraries(${NAME}_test avs_unit dl)
@@ -556,11 +560,10 @@ endif()
if(WITH_AVS_UNIT)
include_directories(test/include)
add_anjay_test(${PROJECT_NAME} ${ABSOLUTE_TEST_SOURCES})
add_dependencies(${PROJECT_NAME}_test dtls_echo_server)
target_link_libraries(${PROJECT_NAME}_test ${DEPS_LIBRARIES} ${DEPS_LIBRARIES_WEAK})
endif()
option(WITH_INTEGRATION_TESTS "Enable integration tests" OFF)
cmake_dependent_option(WITH_INTEGRATION_TESTS "Enable integration tests" OFF WITH_DEMO OFF)
if(WITH_INTEGRATION_TESTS)
add_subdirectory(test/integration)
endif()
View
@@ -109,7 +109,7 @@ To install everything on Ubuntu 16.04 LTS:
``` sh
sudo apt-get install git build-essential cmake libmbedtls-dev wget
# Optionally for tests:
sudo apt-get install libpython3-dev libssl-dev python3 clang
sudo apt-get install libpython3-dev libssl-dev python3 python3-cryptography python3-sphinx clang
```
Or on macOS Sierra with [Homebrew](https://brew.sh/):
@@ -118,7 +118,7 @@ Or on macOS Sierra with [Homebrew](https://brew.sh/):
brew install cmake mbedtls wget
# Optionally for tests:
brew install python3 openssl llvm
pip3 install sphinx sphinx_rtd_theme
pip3 install cryptography sphinx sphinx_rtd_theme
```
### Running the demo client
Submodule git updated 181 files
View
1 compat
View
@@ -42,10 +42,11 @@
#cmakedefine WITH_BOOTSTRAP
#cmakedefine WITH_DISCOVER
#cmakedefine WITH_OBSERVE
#cmakedefine WITH_HTTP_DOWNLOAD
#cmakedefine WITH_JSON
#cmakedefine WITH_CON_ATTR
#cmakedefine WITH_LEGACY_CONTENT_FORMAT_SUPPORT
#cmakedefine WITH_MESSAGE_CACHE
#cmakedefine WITH_NET_STATS
#define ANJAY_MAX_PK_OR_IDENTITY_SIZE @MAX_PK_OR_IDENTITY_SIZE@
#define ANJAY_MAX_SERVER_PK_OR_IDENTITY_SIZE @MAX_SERVER_PK_OR_IDENTITY_SIZE@
View
View
@@ -21,6 +21,7 @@
#include <ctype.h>
#include <string.h>
#include <anjay/attr_storage.h>
#include <anjay/security.h>
static int parse_ssid(const char *text,
@@ -302,6 +303,63 @@ static void cmd_download(anjay_demo_t *demo, const char *args_string) {
}
}
static void cmd_set_attrs(anjay_demo_t *demo, const char *args_string) {
char path[strlen(args_string) + 1];
int path_len = 0;
if (sscanf(args_string, "%s%n", path, &path_len) != 1) {
goto error;
}
const char *args = args_string + path_len;
anjay_dm_resource_attributes_t attrs = ANJAY_RES_ATTRIBS_EMPTY;
const char *pmin = strstr(args, "pmin=");
const char *pmax = strstr(args, "pmax=");
const char *lt = strstr(args, "lt=");
const char *gt = strstr(args, "gt=");
const char *st = strstr(args, "st=");
if (pmin) {
(void) sscanf(pmin, "pmin=%ld", &attrs.common.min_period);
}
if (pmax) {
(void) sscanf(pmax, "pmax=%ld", &attrs.common.max_period);
}
if (lt) {
(void) sscanf(lt, "lt=%lf", &attrs.less_than);
}
if (gt) {
(void) sscanf(gt, "gt=%lf", &attrs.greater_than);
}
if (st) {
(void) sscanf(st, "st=%lf", &attrs.step);
}
int oid, iid, rid;
switch (sscanf(path, "/%d/%d/%d", &oid, &iid, &rid)) {
case 3:
if (anjay_attr_storage_set_resource_attrs(
demo->anjay, 1, (anjay_oid_t) oid, (anjay_iid_t) iid,
(anjay_rid_t) rid, &attrs)) {
demo_log(ERROR, "failed to set resource level attributes");
}
return;
case 2:
if (anjay_attr_storage_set_instance_attrs(
demo->anjay, 1, (anjay_oid_t) oid, (anjay_iid_t) iid,
&attrs.common)) {
demo_log(ERROR, "failed to set instance level attributes");
}
return;
case 1:
if (anjay_attr_storage_set_object_attrs(
demo->anjay, 1, (anjay_oid_t) oid, &attrs.common)) {
demo_log(ERROR, "failed to set object level attributes");
}
return;
}
error:
demo_log(ERROR, "bad syntax - see help");
}
static void cmd_help(anjay_demo_t *demo, const char *args_string);
struct cmd_handler_def {
@@ -344,6 +402,9 @@ static const struct cmd_handler_def COMMAND_HANDLERS[] = {
CMD_HANDLER("download", "url target_file [psk_identity psk_key]",
cmd_download,
"Download a file from given CoAP URL to target_file."),
CMD_HANDLER("set-attrs", "", cmd_set_attrs,
"Syntax [/x [/y [/z] ] ] [pmin,pmax,lt,gt,st] - e.g. "
"/x/y pmin=3,pmax=4"),
CMD_HANDLER("help", "", cmd_help, "Prints this message")
};
#undef CMD_HANDLER
Oops, something went wrong.

0 comments on commit 8f74839

Please sign in to comment.