Permalink
Browse files

Anjay 1.3.3

Features:
- Implemented anjay_download() API for asynchronous CoAP(S) downloads
- Added anjay_download example code
- Added support for CoAP firmware download in demo application

Bugfixes:
- Fixed Register/Update transport when changing Binding
- Fixed lt/gt/st semantics according to
  OpenMobileAlliance/OMA_LwM2M_for_Developers#191
- Fixed handling of unrelated BLOCK2 requests during a block-wise Read
- Disallowed Write-Attributes requests if the server does not have Read
  access rights
- Fixed build instructions for OS X in README

Improvements:
- Added packet capture in Python tests
- Added compilation instructions for Android
- Made missing scan-build a fatal error if static analysis was enabled
  with a CMake flag
- Integrated Coverity scan with Travis build
- Allowed configuration of CoAP transmission parameters in anjay_new()
  • Loading branch information...
dextero committed Jul 27, 2017
1 parent f60498a commit 3a0cc39ef47c777fd3dda676bf21415f05710f16
Showing with 5,792 additions and 2,235 deletions.
  1. +3 −4 .gitmodules
  2. +42 −20 .travis.yml
  3. +16 −9 CMakeLists.txt
  4. +15 −5 README.md
  5. +1 −1 avs_commons/git
  6. +1 −2 cmake/anjay-config.cmake.in
  7. +1 −0 config/config.h.in
  8. +66 −0 demo/demo_cmds.c
  9. +131 −23 demo/objects/firmware_update.c
  10. +5 −1 devconfig
  11. +1 −1 doc/sphinx/source/AdvancedTutorial/AT5.rst
  12. +28 −0 doc/sphinx/source/AdvancedTutorial/AT6.rst
  13. +2 −2 doc/sphinx/source/BasicTutorial/BT3.rst
  14. +1 −1 doc/sphinx/source/BasicTutorial/BT4_CustomObject/BT_CO8_Notifications.rst
  15. +79 −1 doc/sphinx/source/Compiling_client_applications.rst
  16. +11 −18 doc/sphinx/source/LwM2M.rst
  17. +13 −13 examples/test_examples.md5
  18. +1 −1 examples/tutorial/AT1/src/main.c
  19. +1 −1 examples/tutorial/AT2/src/main.c
  20. +1 −1 examples/tutorial/AT3-cert/src/main.c
  21. +1 −1 examples/tutorial/AT3-psk/src/main.c
  22. +1 −1 examples/tutorial/AT4/src/main.c
  23. +1 −1 examples/tutorial/BT3/src/main.c
  24. +1 −0 examples/tutorial/CMakeLists.txt
  25. +1 −1 examples/tutorial/custom-object/bootstrap-awareness/src/main.c
  26. +1 −1 examples/tutorial/custom-object/multi-instance-dynamic/src/main.c
  27. +1 −1 examples/tutorial/custom-object/multi-instance-resources-dynamic/src/main.c
  28. +1 −1 examples/tutorial/custom-object/notifications/src/main.c
  29. +1 −1 examples/tutorial/custom-object/read-only-multiple-fixed/src/main.c
  30. +1 −1 examples/tutorial/custom-object/read-only-with-executable/src/main.c
  31. +1 −1 examples/tutorial/custom-object/read-only/src/main.c
  32. +1 −1 examples/tutorial/custom-object/writable-multiple-fixed-transactional/src/main.c
  33. +1 −1 examples/tutorial/custom-object/writable-multiple-fixed/src/main.c
  34. +14 −0 examples/tutorial/downloader/CMakeLists.txt
  35. +168 −0 examples/tutorial/downloader/src/main.c
  36. +16 −0 include_modules/anjay_modules/dm.h
  37. +4 −8 include_modules/anjay_modules/notify.h
  38. +1 −0 include_public/anjay/anjay.h
  39. +56 −0 include_public/anjay/core.h
  40. +161 −0 include_public/anjay/download.h
  41. +5 −5 modules/access_control/src/handlers.c
  42. +6 −1 modules/access_control/src/test/access_control.c
  43. +1 −0 modules/attr_storage/src/persistence.c
  44. +165 −124 src/anjay.c
  45. +8 −5 src/anjay.h
  46. +13 −11 src/coap/block/request.c
  47. +22 −14 src/coap/block/response.c
  48. +13 −5 src/coap/block/response.h
  49. +11 −16 src/coap/block/transfer.c
  50. +6 −2 src/coap/block/transfer_impl.h
  51. +58 −0 src/coap/block_utils.c
  52. +72 −0 src/coap/block_utils.h
  53. +47 −0 src/coap/content_format.h
  54. +3 −39 src/coap/msg.c
  55. +26 −63 src/coap/msg.h
  56. +4 −4 src/coap/msg_cache.c
  57. +2 −1 src/coap/msg_cache.h
  58. +56 −0 src/coap/msg_identity.h
  59. +1 −0 src/coap/msg_info.c
  60. +1 −41 src/coap/msg_info.h
  61. +148 −0 src/coap/msg_opt.c
  62. +68 −0 src/coap/msg_opt.h
  63. +2 −0 src/coap/opt.c
  64. +22 −2 src/coap/opt.h
  65. +5 −31 src/coap/{utils.h → parse_utils.h}
  66. +83 −8 src/coap/socket.c
  67. +32 −3 src/coap/socket.h
  68. +14 −45 src/coap/stream.h
  69. +9 −9 src/coap/stream/client.c
  70. +6 −130 src/coap/stream/common.c
  71. +0 −77 src/coap/stream/common.h
  72. +1 −1 src/coap/stream/in.c
  73. +1 −1 src/coap/stream/out.h
  74. +35 −21 src/coap/stream/server.c
  75. +12 −0 src/coap/stream/server.h
  76. +14 −160 src/coap/stream/stream.c
  77. +2 −1 src/coap/test/block_response.c
  78. +26 −14 src/coap/test/msg.c
  79. +2 −0 src/coap/test/msg_builder.c
  80. +21 −21 src/coap/test/msg_cache.c
  81. +32 −27 src/coap/test/stream.c
  82. +196 −3 src/coap/test/utils.h
  83. +35 −0 src/coap/tx_params.c
  84. +108 −0 src/coap/tx_params.h
  85. +0 −47 src/coap/utils.c
  86. +157 −149 src/dm.c
  87. +73 −28 src/dm.h
  88. +20 −27 src/dm/discover.c
  89. +3 −9 src/dm/discover.h
  90. +735 −0 src/downloader.c
  91. +97 −0 src/downloader.h
  92. +52 −52 src/interface/bootstrap.c
  93. +1 −1 src/interface/bootstrap.h
  94. +58 −53 src/interface/register.c
  95. +3 −6 src/interface/register.h
  96. +2 −4 src/interface/test/bootstrap.c
  97. +1 −0 src/io.c
  98. +1 −0 src/io.h
  99. +5 −2 src/io/dynamic.c
  100. +1 −0 src/io/json_out.c
  101. +1 −0 src/io/opaque.c
  102. +1 −0 src/io/text.c
  103. +1 −0 src/io/tlv_out.c
  104. +7 −11 src/notify.c
  105. +62 −125 src/observe.c
  106. +4 −10 src/observe.h
  107. +6 −0 src/sched.h
  108. +16 −5 src/servers.h
  109. +92 −65 src/servers/connection_info.c
  110. +51 −28 src/servers/register.c
  111. +2 −0 src/servers/servers.c
  112. +151 −145 src/test/anjay.c
  113. +57 −33 src/test/dm.c
  114. +849 −0 src/test/downloader.c
  115. +26 −0 src/test/downloader_mock.h
  116. +0 −54 src/test/mock_coap_stream.h
  117. +0 −125 src/test/mock_coap_stream_impl.h
  118. +64 −43 src/test/observe.c
  119. +41 −0 src/utils.c
  120. +16 −0 src/utils.h
  121. +140 −0 test/integration/framework/coap_file_server.py
  122. +2 −2 test/integration/framework/nsh-lwm2m/lwm2m/coap/option.py
  123. +7 −2 test/integration/framework/nsh-lwm2m/lwm2m/coap/packet.py
  124. +6 −0 test/integration/framework/nsh-lwm2m/lwm2m/coap/server.py
  125. +40 −18 test/integration/framework/nsh-lwm2m/lwm2m/messages.py
  126. +3 −2 test/integration/framework/nsh-lwm2m/lwm2m/tlv.py
  127. +37 −12 test/integration/framework/nsh-lwm2m/pymbedtls/src/pymbedtls.cpp
  128. +191 −38 test/integration/framework/test_suite.py
  129. +17 −5 test/integration/suites/default/access_control.py
  130. +45 −1 test/integration/suites/default/block_response.py
  131. +25 −63 test/integration/suites/default/bootstrap_client.py
  132. +1 −1 test/integration/suites/default/bootstrap_factory.py
  133. +1 −1 test/integration/suites/default/bootstrap_server.py
  134. +4 −6 test/integration/suites/default/bootstrap_transaction.py
  135. +1 −1 test/integration/suites/default/buffer_sizes.py
  136. +202 −0 test/integration/suites/default/coap_download.py
  137. +50 −1 test/integration/suites/default/firmware_update.py
  138. +5 −11 test/integration/suites/default/modify_servers.py
  139. +4 −1 test/integration/suites/default/msg_cache.py
  140. +1 −1 test/integration/suites/default/register.py
  141. +35 −4 test/integration/suites/default/update.py
  142. +5 −15 test/integration/suites/default/uri_change_update.py
  143. +1 −1 test/integration/suites/testfest/register.py
  144. +5 −7 test/integration/suites/testfest/security.py
  145. +15 −9 tools/analyze
  146. +1 −1 tools/coverage
  147. +8 −0 tools/utils.sh
  148. +34 −0 travis/coverity/Dockerfile
  149. +4 −1 travis/run.sh
View
@@ -1,7 +1,6 @@
[submodule "test/integration/framework/nsh-lwm2m/pymbedtls/src/pybind11"]
path = test/integration/framework/nsh-lwm2m/pymbedtls/src/pybind11
url = https://github.com/pybind/pybind11.git
ignore = untracked
[submodule "avs_commons/git"]
path = avs_commons/git
url = git://github.com/AVSystem/avs_commons.git
[submodule "test/integration/framework/nsh-lwm2m/pymbedtls/src/pybind11"]
path = test/integration/framework/nsh-lwm2m/pymbedtls/src/pybind11
url = https://github.com/pybind/pybind11.git
View
@@ -23,68 +23,90 @@ osx_image: xcode8.2
services:
- docker
env:
global:
# COVERITY_SCAN_TOKEN
- secure: "nD0RN+Vc6bzdRHLSUb2flx3Z0ggigeflPpudi1EarjDXthJeW0W6yvEiQMavdBBiOGwkbYn+BAOpPT4RxRUyEgbejBoBbI9cl9Km7C1qhc5tlWEsH3gmAdX1vuwwtpHI3d9lTm03tCKPEd1xzMZ2zpmsFvSFbWUOaKBzzr9BbHoupFshQDIrmGjUReAH00GBWNFebbTImbKAqZGiFJHVIJ/0sgdsGpcr1Yaq36DKWv5/JYALaei/G+p0/sXGWs8HXv8bESoa9+i6Kh5/KSdZORQ6mXj3MrEfAt0KjKAe9Ld0EE6JwySLTFEBplRxj43GT4np8UtOD8XYX3NI5i2icVBf25KUBoDdSB4P8LO5oHxgH+04UWi787KOwa/jifFSGBt3YHGxVVPOj/SuQKqRELcZ4snj9wOWaMmIfVYzH7Ar6hsWAAVyB+j22notZoAuMtkE22z4hrsld8JbWwJyq4PWxQyYZZrq+6BXbFby3muuguavuAaFTr/4lj2BX/6ZLnv5VbUwkd9Qsylddf8Cpz/lnVb8DD1NK4ZfkIH4r6kt4GC7fkTI1lyLpb9sfiHJyf7DF+OsZBn5T6t9x3v9gUkTCMWfiLOcNEjOvb+8GoOtI3Yda8ngzz3Ca0l+bBOV1pcD+2AVKMdSlZk5OG4wc4xGBVQxAUNfdCpVbT8/7vg="
# COVERITY_EMAIL
- secure: "EZTeRk2ZMKN3O3wye6O3nfCDAheuYwEcg/wODoltYfRo9I9lB0XSy9HBXwwd0/NVa5lQRI1ZvNzE9kfqDMx32brXeBOzP31PNFmQUQ47Fl8eEyJ8PCkUTVs8UWosRcsU0xVSZa6PW6OzV/CrYyPNceCwnJL73d8e1b5oCYIkEc2C4wAG922EqBwPP9r1exbztkU4dGB7u7b+MkLv+ymBz57SAV9AGx7hn8B4c0SjP8gWS5u/yoXfy8Ybfez4iQwN+PI7gkemxdBB0n5QmCj7WEm7iEhI7SWXfifC27DSYhH6qihlvIJWBegB+2CjHUd18Fd3HGrSUORzHqNG3gC11g+lk6zbNXbcuuP4/U475D/EOvQJSGIROrHk0qTQ+G8BGywLuDghtFNwTdK4RoB76ZkSvErXr2GghQQw3IBVzWp+Dz4ZEdiRVMXVBiPa8RuA5DqCnU5iqrcGcsFcsHpH3qJ/fuGa0AxQEKqM3MlEBupMmtHOsQ6s9QDWZUvzEtva1iRKz4fyFYCqaT7rvPkn22WtvdemNLR6kD3evRkSv7Z1SY5ZcgYtVut98hCVYwxm4qrsFESU6QuHFExO4XFcghY4iZaapYpZKxARGWXamGwsoYFhoQkMeILTQJot+4XKFxTwRTbglOJCbEbzRet2OdrXtDLfDDc8RT6ouex2DXM="
matrix:
include:
- os: osx
env: DEVCONFIG_FLAGS=--with-asan
- stage: test
os: osx
env: DEVCONFIG_FLAGS="--with-asan --without-analysis"
- os: linux
- stage: test
os: linux
env: ANJAY_CC=gcc-4.7
ANJAY_CXX=g++
PYMBEDTLS_CC=gcc
DEVCONFIG_FLAGS=--with-valgrind
DEVCONFIG_FLAGS="--with-valgrind --without-analysis"
DOCKER_IMAGE=ubuntu-16.04
- os: linux
- stage: test
os: linux
env: ANJAY_CC=gcc-4.8
ANJAY_CXX=g++
PYMBEDTLS_CC=gcc
DEVCONFIG_FLAGS=--with-valgrind
DEVCONFIG_FLAGS="--with-valgrind --without-analysis"
DOCKER_IMAGE=ubuntu-16.04
- os: linux
- stage: test
os: linux
env: ANJAY_CC=gcc-4.9
ANJAY_CXX=g++
PYMBEDTLS_CC=gcc
DEVCONFIG_FLAGS=--with-valgrind
DEVCONFIG_FLAGS="--with-valgrind --without-analysis"
DOCKER_IMAGE=ubuntu-16.04
- os: linux
- stage: test
os: linux
env: ANJAY_CC=gcc-5
ANJAY_CXX=g++-5
DEVCONFIG_FLAGS=--with-valgrind
DEVCONFIG_FLAGS="--with-valgrind --without-analysis"
DOCKER_IMAGE=ubuntu-16.04
- os: linux
- stage: test
os: linux
env: ANJAY_CC=clang-3.5
ANJAY_CXX=clang++-3.5
DEVCONFIG_FLAGS=--with-valgrind
DEVCONFIG_FLAGS="--with-valgrind --without-analysis"
DOCKER_IMAGE=ubuntu-16.04
- os: linux
- stage: test
os: linux
env: ANJAY_CC=clang-3.6
ANJAY_CXX=clang++-3.6
DEVCONFIG_FLAGS=--with-valgrind
DEVCONFIG_FLAGS="--with-valgrind --without-analysis"
DOCKER_IMAGE=ubuntu-16.04
- os: linux
- stage: test
os: linux
env: ANJAY_CC=clang-3.7
ANJAY_CXX=clang++-3.7
DEVCONFIG_FLAGS=--with-valgrind
DEVCONFIG_FLAGS="--with-valgrind --without-analysis"
DOCKER_IMAGE=ubuntu-16.04
- os: linux
- stage: test
os: linux
env: ANJAY_CC=clang-3.8
ANJAY_CXX=clang++-3.8
DEVCONFIG_FLAGS=--with-valgrind
DEVCONFIG_FLAGS="--with-valgrind --without-analysis"
DOCKER_IMAGE=ubuntu-16.04
- os: linux
- stage: test
os: linux
env: ANJAY_CC=gcc
ANJAY_CXX=g++
DEVCONFIG_FLAGS=--with-valgrind -DPython_ADDITIONAL_VERSIONS=3.5
DEVCONFIG_FLAGS="--with-valgrind --without-analysis"
DOCKER_IMAGE=centos7
- stage: coverity
os: linux
env: DOCKER_IMAGE=coverity
DEVCONFIG_FLAGS="--without-analysis"
before_script:
- source travis/prepare.sh
View
@@ -26,7 +26,7 @@ if(WITH_FUZZ_TESTS)
endif()
project(anjay C)
set(ANJAY_VERSION "1.3.2" CACHE STRING "Anjay library version")
set(ANJAY_VERSION "1.3.3" CACHE STRING "Anjay library version")
set(ANJAY_BINARY_VERSION 1.0.0)
set(ANJAY_BUILD_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/output")
@@ -66,6 +66,7 @@ option(WITH_DEMO "Compile DEMO applications" ON)
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)
@@ -82,10 +83,10 @@ option(WITH_MESSAGE_CACHE "Enable support for message caching to detect and auto
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)
if(WITH_AVS_LOG)
option(AVS_LOG_WITH_TRACE "Enable TRACE level logging" OFF)
endif()
# -fvisibility, #pragma GCC visibility
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CMakeTmp/visibility.c
@@ -137,6 +138,7 @@ 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
@@ -148,7 +150,8 @@ set(CORE_SOURCES
src/coap/stream/out.c
src/coap/stream/server.c
src/coap/stream/stream.c
src/coap/utils.c
src/coap/block_utils.c
src/coap/tx_params.c
src/interface/register.c
src/io/base64_out.c
src/io/dynamic.c
@@ -178,6 +181,9 @@ set(CORE_SOURCES
if(WITH_ACCESS_CONTROL)
set(CORE_SOURCES ${CORE_SOURCES} src/access_control.c)
endif()
if(WITH_BLOCK_DOWNLOAD)
set(CORE_SOURCES ${CORE_SOURCES} src/downloader.c)
endif()
if(WITH_BLOCK_SEND)
set(CORE_SOURCES ${CORE_SOURCES}
src/coap/block/response.c
@@ -217,6 +223,7 @@ set(CORE_PRIVATE_HEADERS
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
@@ -226,7 +233,9 @@ set(CORE_PRIVATE_HEADERS
src/coap/stream/out.h
src/coap/stream/server.h
src/coap/stream/stream.h
src/coap/utils.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
@@ -279,8 +288,6 @@ set(TEST_SOURCES
src/coap/test/block_response.c
src/interface/test/bootstrap_mock.h
src/io/test/bigdata.h
src/test/mock_coap_stream.h
src/test/mock_coap_stream_impl.h
src/test/observe_mock.h
test/src/coap/stream.c
test/src/coap/socket.c
@@ -667,7 +674,7 @@ option(WITH_STATIC_ANALYSIS "Perform static analysis of the codebase on `make ch
if(WITH_STATIC_ANALYSIS)
find_program(SCAN_BUILD_BINARY scan-build)
if(NOT SCAN_BUILD_BINARY)
message(WARNING "scan-build not found; specify path with -DSCAN_BUILD_BINARY or disable static analysis with -DWITH_STATIC_ANALYSIS=OFF")
message(FATAL_ERROR "scan-build not found; specify path with -DSCAN_BUILD_BINARY or disable static analysis with -DWITH_STATIC_ANALYSIS=OFF")
else()
add_custom_target(analyze
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tools/analyze"
View
@@ -1,6 +1,7 @@
# Anjay LwM2M library [<img align="right" height="50px" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSoiMy6rnzARUEdR0OjHmPGxTeiAMLBFlUYwIB9baWYWmuUwTbo">](http://www.avsystem.com/)
[![Build Status](https://travis-ci.org/AVSystem/Anjay.svg?branch=master)](https://travis-ci.org/AVSystem/Anjay)
[![Coverity Status](https://scan.coverity.com/projects/13206/badge.svg)](https://scan.coverity.com/projects/avsystem-anjay)
## What is Anjay?
@@ -100,22 +101,24 @@ More details about OMA LwM2M: [Brief introduction to LwM2M](https://AVSystem.git
- Optional dependencies (required for tests):
- C++ compiler with C++11 support,
- [Python 3.5+](https://www.python.org/),
- [pybind11](https://github.com/pybind/pybind11) - included in the repository as a subproject.
- [pybind11](https://github.com/pybind/pybind11) - included in the repository as a subproject,
- [scan-build](https://clang-analyzer.llvm.org/scan-build.html) - for static analysis.
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
sudo apt-get install libpython3-dev libssl-dev python3 clang
```
Or on macOS Sierra with [Homebrew](https://brew.sh/):
``` sh
brew install cmake mbedtls wget
# Optionally for tests:
brew install python3
brew install python3 openssl llvm
pip3 install sphinx sphinx_rtd_theme
```
### Running the demo client
@@ -169,12 +172,19 @@ To start the demo client:
**NOTE**: When establishing a DTLS connection, the URI MUST use "coaps://". In NoSec mode (default), the URI MUST use "<coap://>".
Running tests:
Running tests on Linux:
``` sh
./devconfig && make check
```
Running tests on macOS Sierra:
``` sh
# If the scan-build script is located somewhere else, then you need to
# specify a different SCAN_BUILD_BINARY. Below, we are assumming scan-build
# comes from an llvm package, installed via homebrew.
./devconfig -DSCAN_BUILD_BINARY=/usr/local/Cellar/llvm/*/bin/scan-build && make check
```
## License
See [LICENSE](LICENSE) file.
@@ -16,8 +16,7 @@ set(ANJAY_VERSION "@ANJAY_VERSION@")
get_filename_component(CURR_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
find_package(avs_commons REQUIRED COMPONENTS @AVS_COMMONS_COMPONENTS@
HINTS "${CURR_DIR}/../.." NO_DEFAULT_PATH)
find_package(avs_commons REQUIRED COMPONENTS @AVS_COMMONS_COMPONENTS@)
include(${CURR_DIR}/@PROJECT_NAME@-targets.cmake)
View
@@ -36,6 +36,7 @@
#cmakedefine WITH_ACCESS_CONTROL
#cmakedefine WITH_AVS_LOG
#cmakedefine WITH_BLOCK_DOWNLOAD
#cmakedefine WITH_BLOCK_RECEIVE
#cmakedefine WITH_BLOCK_SEND
#cmakedefine WITH_BOOTSTRAP
View
@@ -239,6 +239,69 @@ static void cmd_unregister_object(anjay_demo_t *demo, const char *args_string) {
demo_log(ERROR, "No such object to unregister: %d", oid);
}
static int dl_write_next_block(anjay_t *anjay,
const uint8_t *data,
size_t data_size,
const anjay_etag_t *etag,
void *user_data) {
(void) anjay;
(void) etag;
FILE *f = (FILE *) user_data;
if (fwrite(data, data_size, 1, f) != 1) {
demo_log(ERROR, "fwrite() failed");
return -1;
}
return 0;
}
static void dl_finished(anjay_t *anjay,
int result,
void *user_data) {
(void) anjay;
fclose((FILE *)user_data);
demo_log(INFO, "download finished, result == %d", result);
}
static void cmd_download(anjay_demo_t *demo, const char *args_string) {
char url[256];
char target_file[256];
char psk_identity[256] = "";
char psk_key[256] = "";
if (sscanf(args_string, "%255s %255s %255s %255s", url, target_file,
psk_identity, psk_key) < 2) {
demo_log(ERROR, "invalid URL or target file in: %s", args_string);
return;
}
FILE *f = fopen(target_file, "wb");
if (!f) {
demo_log(ERROR, "could not open file: %s", target_file);
return;
}
avs_net_psk_t psk = {
.psk = psk_key,
.psk_size = strlen(psk_key),
.identity = psk_identity,
.identity_size = strlen(psk_identity)
};
anjay_download_config_t cfg = {
.url = url,
.on_next_block = dl_write_next_block,
.on_download_finished = dl_finished,
.user_data = f,
.security_info = avs_net_security_info_from_psk(psk)
};
if (anjay_download(demo->anjay, &cfg) == NULL) {
demo_log(ERROR, "could not schedule download");
fclose(f);
}
}
static void cmd_help(anjay_demo_t *demo, const char *args_string);
struct cmd_handler_def {
@@ -278,6 +341,9 @@ static const struct cmd_handler_def COMMAND_HANDLERS[] = {
"Executes anjay_notify_* on a specified path"),
CMD_HANDLER("unregister-object", "oid", cmd_unregister_object,
"Unregister an LwM2M Object"),
CMD_HANDLER("download", "url target_file [psk_identity psk_key]",
cmd_download,
"Download a file from given CoAP URL to target_file."),
CMD_HANDLER("help", "", cmd_help, "Prints this message")
};
#undef CMD_HANDLER
Oops, something went wrong.

0 comments on commit 3a0cc39

Please sign in to comment.