Skip to content

Commit

Permalink
Anjay 1.3.3
Browse files Browse the repository at this point in the history
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
Marcin Radomski committed Jul 27, 2017
1 parent f60498a commit 3a0cc39
Show file tree
Hide file tree
Showing 149 changed files with 5,792 additions and 2,235 deletions.
7 changes: 3 additions & 4 deletions .gitmodules
@@ -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
62 changes: 42 additions & 20 deletions .travis.yml
Expand Up @@ -23,68 +23,90 @@ osx_image: xcode8.2
services:
- docker

env:
global:
# COVERITY_SCAN_TOKEN
- secure: "nD0RN+Vc6bzdRHLSUb2flx3Z0ggigeflPpudi1EarjDXthJeW0W6yvEiQMavdBBiOGwkbYn+BAOpPT4RxRUyEgbejBoBbI9cl9Km7C1qhc5tlWEsH3gmAdX1vuwwtpHI3d9lTm03tCKPEd1xzMZ2zpmsFvSFbWUOaKBzzr9BbHoupFshQDIrmGjUReAH00GBWNFebbTImbKAqZGiFJHV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xm4qrsFESU6QuHFExO4XFcghY4iZaapYpZKxARGWXamGwsoYFhoQkMeILTQJot+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

Expand Down
25 changes: 16 additions & 9 deletions CMakeLists.txt
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
20 changes: 15 additions & 5 deletions README.md
@@ -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?

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions cmake/anjay-config.cmake.in
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions config/config.h.in
Expand Up @@ -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
Expand Down
66 changes: 66 additions & 0 deletions demo/demo_cmds.c
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3a0cc39

Please sign in to comment.