From 393b268e159a40b23bc63464f4d04d5be09e070f Mon Sep 17 00:00:00 2001 From: jacqueline Date: Sat, 21 Jan 2023 14:04:56 +1100 Subject: [PATCH] Vendor tinycbor, since v5 no longer includes it --- lib/cbor/CMakeLists.txt | 22 + lib/cbor/LICENSE | 21 + lib/cbor/README.md | 13 + lib/cbor/idf_component.yml | 5 + lib/cbor/port/include/cbor.h | 2 + lib/cbor/test/CMakeLists.txt | 4 + lib/cbor/test/test.c | 230 ++ lib/cbor/tinycbor/.appveyor.yml | 28 + lib/cbor/tinycbor/.gitattributes | 4 + lib/cbor/tinycbor/.gitignore | 81 + lib/cbor/tinycbor/.tag | 1 + lib/cbor/tinycbor/.travis.yml | 92 + lib/cbor/tinycbor/Doxyfile | 49 + lib/cbor/tinycbor/LICENSE | 21 + lib/cbor/tinycbor/Makefile | 250 +++ lib/cbor/tinycbor/README | 13 + lib/cbor/tinycbor/TODO | 25 + lib/cbor/tinycbor/VERSION | 1 + lib/cbor/tinycbor/examples/examples.pro | 2 + lib/cbor/tinycbor/examples/simplereader.c | 185 ++ lib/cbor/tinycbor/examples/simplereader.pro | 3 + lib/cbor/tinycbor/scripts/maketag.pl | 91 + lib/cbor/tinycbor/scripts/update-docs.sh | 52 + lib/cbor/tinycbor/src/cbor.dox | 123 ++ lib/cbor/tinycbor/src/cbor.h | 724 +++++++ lib/cbor/tinycbor/src/cborencoder.c | 689 ++++++ .../src/cborencoder_close_container_checked.c | 57 + lib/cbor/tinycbor/src/cborencoder_float.c | 42 + lib/cbor/tinycbor/src/cborerrorstrings.c | 188 ++ lib/cbor/tinycbor/src/cborinternal_p.h | 316 +++ lib/cbor/tinycbor/src/cborjson.h | 62 + lib/cbor/tinycbor/src/cborparser.c | 1529 +++++++++++++ lib/cbor/tinycbor/src/cborparser_dup_string.c | 119 ++ lib/cbor/tinycbor/src/cborparser_float.c | 54 + lib/cbor/tinycbor/src/cborpretty.c | 579 +++++ lib/cbor/tinycbor/src/cborpretty_stdio.c | 87 + lib/cbor/tinycbor/src/cbortojson.c | 709 +++++++ lib/cbor/tinycbor/src/cborvalidation.c | 657 ++++++ lib/cbor/tinycbor/src/compilersupport_p.h | 205 ++ lib/cbor/tinycbor/src/open_memstream.c | 114 + lib/cbor/tinycbor/src/parsetags.pl | 116 + lib/cbor/tinycbor/src/src.pri | 26 + lib/cbor/tinycbor/src/tags.txt | 23 + lib/cbor/tinycbor/src/tinycbor-version.h | 3 + lib/cbor/tinycbor/src/tinycbor.pro | 10 + lib/cbor/tinycbor/src/utf8_p.h | 104 + lib/cbor/tinycbor/tests/.gitignore | 15 + lib/cbor/tinycbor/tests/c90/c90.pro | 7 + lib/cbor/tinycbor/tests/c90/tst_c90.c | 30 + lib/cbor/tinycbor/tests/cpp/cpp.pro | 5 + lib/cbor/tinycbor/tests/cpp/tst_cpp.cpp | 44 + lib/cbor/tinycbor/tests/encoder/data.cpp | 346 +++ lib/cbor/tinycbor/tests/encoder/encoder.pro | 9 + .../tinycbor/tests/encoder/tst_encoder.cpp | 609 ++++++ lib/cbor/tinycbor/tests/parser/data.cpp | 607 ++++++ lib/cbor/tinycbor/tests/parser/parser.pro | 10 + lib/cbor/tinycbor/tests/parser/tst_parser.cpp | 1888 +++++++++++++++++ lib/cbor/tinycbor/tests/tests.pro | 3 + lib/cbor/tinycbor/tests/tojson/tojson.pro | 8 + lib/cbor/tinycbor/tests/tojson/tst_tojson.cpp | 721 +++++++ lib/cbor/tinycbor/tinycbor.pc.in | 11 + lib/cbor/tinycbor/tools/cbordump/cbordump.c | 164 ++ lib/cbor/tinycbor/tools/cbordump/cbordump.pro | 10 + lib/cbor/tinycbor/tools/json2cbor/json2cbor.c | 493 +++++ .../tinycbor/tools/json2cbor/json2cbor.pro | 20 + tools/cmake/common.cmake | 1 + 66 files changed, 12732 insertions(+) create mode 100644 lib/cbor/CMakeLists.txt create mode 100644 lib/cbor/LICENSE create mode 100644 lib/cbor/README.md create mode 100644 lib/cbor/idf_component.yml create mode 100644 lib/cbor/port/include/cbor.h create mode 100644 lib/cbor/test/CMakeLists.txt create mode 100644 lib/cbor/test/test.c create mode 100644 lib/cbor/tinycbor/.appveyor.yml create mode 100644 lib/cbor/tinycbor/.gitattributes create mode 100644 lib/cbor/tinycbor/.gitignore create mode 100644 lib/cbor/tinycbor/.tag create mode 100644 lib/cbor/tinycbor/.travis.yml create mode 100644 lib/cbor/tinycbor/Doxyfile create mode 100644 lib/cbor/tinycbor/LICENSE create mode 100644 lib/cbor/tinycbor/Makefile create mode 100644 lib/cbor/tinycbor/README create mode 100644 lib/cbor/tinycbor/TODO create mode 100644 lib/cbor/tinycbor/VERSION create mode 100644 lib/cbor/tinycbor/examples/examples.pro create mode 100644 lib/cbor/tinycbor/examples/simplereader.c create mode 100644 lib/cbor/tinycbor/examples/simplereader.pro create mode 100644 lib/cbor/tinycbor/scripts/maketag.pl create mode 100755 lib/cbor/tinycbor/scripts/update-docs.sh create mode 100644 lib/cbor/tinycbor/src/cbor.dox create mode 100644 lib/cbor/tinycbor/src/cbor.h create mode 100644 lib/cbor/tinycbor/src/cborencoder.c create mode 100644 lib/cbor/tinycbor/src/cborencoder_close_container_checked.c create mode 100644 lib/cbor/tinycbor/src/cborencoder_float.c create mode 100644 lib/cbor/tinycbor/src/cborerrorstrings.c create mode 100644 lib/cbor/tinycbor/src/cborinternal_p.h create mode 100644 lib/cbor/tinycbor/src/cborjson.h create mode 100644 lib/cbor/tinycbor/src/cborparser.c create mode 100644 lib/cbor/tinycbor/src/cborparser_dup_string.c create mode 100644 lib/cbor/tinycbor/src/cborparser_float.c create mode 100644 lib/cbor/tinycbor/src/cborpretty.c create mode 100644 lib/cbor/tinycbor/src/cborpretty_stdio.c create mode 100644 lib/cbor/tinycbor/src/cbortojson.c create mode 100644 lib/cbor/tinycbor/src/cborvalidation.c create mode 100644 lib/cbor/tinycbor/src/compilersupport_p.h create mode 100644 lib/cbor/tinycbor/src/open_memstream.c create mode 100755 lib/cbor/tinycbor/src/parsetags.pl create mode 100644 lib/cbor/tinycbor/src/src.pri create mode 100644 lib/cbor/tinycbor/src/tags.txt create mode 100644 lib/cbor/tinycbor/src/tinycbor-version.h create mode 100644 lib/cbor/tinycbor/src/tinycbor.pro create mode 100644 lib/cbor/tinycbor/src/utf8_p.h create mode 100644 lib/cbor/tinycbor/tests/.gitignore create mode 100644 lib/cbor/tinycbor/tests/c90/c90.pro create mode 100644 lib/cbor/tinycbor/tests/c90/tst_c90.c create mode 100644 lib/cbor/tinycbor/tests/cpp/cpp.pro create mode 100644 lib/cbor/tinycbor/tests/cpp/tst_cpp.cpp create mode 100644 lib/cbor/tinycbor/tests/encoder/data.cpp create mode 100644 lib/cbor/tinycbor/tests/encoder/encoder.pro create mode 100644 lib/cbor/tinycbor/tests/encoder/tst_encoder.cpp create mode 100644 lib/cbor/tinycbor/tests/parser/data.cpp create mode 100644 lib/cbor/tinycbor/tests/parser/parser.pro create mode 100644 lib/cbor/tinycbor/tests/parser/tst_parser.cpp create mode 100644 lib/cbor/tinycbor/tests/tests.pro create mode 100644 lib/cbor/tinycbor/tests/tojson/tojson.pro create mode 100644 lib/cbor/tinycbor/tests/tojson/tst_tojson.cpp create mode 100644 lib/cbor/tinycbor/tinycbor.pc.in create mode 100644 lib/cbor/tinycbor/tools/cbordump/cbordump.c create mode 100644 lib/cbor/tinycbor/tools/cbordump/cbordump.pro create mode 100644 lib/cbor/tinycbor/tools/json2cbor/json2cbor.c create mode 100644 lib/cbor/tinycbor/tools/json2cbor/json2cbor.pro diff --git a/lib/cbor/CMakeLists.txt b/lib/cbor/CMakeLists.txt new file mode 100644 index 00000000..657184f7 --- /dev/null +++ b/lib/cbor/CMakeLists.txt @@ -0,0 +1,22 @@ +idf_component_register(SRCS "tinycbor/src/cborencoder_close_container_checked.c" + "tinycbor/src/cborencoder.c" + "tinycbor/src/cborencoder_float.c" + "tinycbor/src/cborerrorstrings.c" + "tinycbor/src/cborparser_dup_string.c" + "tinycbor/src/cborparser.c" + "tinycbor/src/cborparser_float.c" + "tinycbor/src/cborpretty_stdio.c" + "tinycbor/src/cborpretty.c" + "tinycbor/src/cbortojson.c" + "tinycbor/src/cborvalidation.c" + "tinycbor/src/open_memstream.c" + INCLUDE_DIRS "port/include" + PRIV_INCLUDE_DIRS "tinycbor/src") + +# for open_memstream.c +set_source_files_properties(tinycbor/src/open_memstream.c PROPERTIES COMPILE_DEFINITIONS "__linux__") + +# workaround for the fact that we are passing -ffreestanding to Clang +if(CMAKE_C_COMPILER_ID MATCHES "Clang") + target_compile_options(${COMPONENT_LIB} PRIVATE "-U __STDC_HOSTED__") +endif() diff --git a/lib/cbor/LICENSE b/lib/cbor/LICENSE new file mode 100644 index 00000000..4aad977c --- /dev/null +++ b/lib/cbor/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Intel Corporation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/lib/cbor/README.md b/lib/cbor/README.md new file mode 100644 index 00000000..167efa06 --- /dev/null +++ b/lib/cbor/README.md @@ -0,0 +1,13 @@ +Concise Binary Object Representation (CBOR) Library +--------------------------------------------------- + +To build TinyCBOR: + + make + +If you want to change the compiler or pass extra compiler flags: + + make CC=clang CFLAGS="-m32 -Oz" LDFLAGS="-m32" + +Documentation: https://intel.github.io/tinycbor/current/ + diff --git a/lib/cbor/idf_component.yml b/lib/cbor/idf_component.yml new file mode 100644 index 00000000..8d5b32c3 --- /dev/null +++ b/lib/cbor/idf_component.yml @@ -0,0 +1,5 @@ +dependencies: + idf: '>=4.3' +description: 'CBOR: Concise Binary Object Representation Library' +url: https://github.com/espressif/idf-extra-components/tree/master/cbor +version: 0.6.0 diff --git a/lib/cbor/port/include/cbor.h b/lib/cbor/port/include/cbor.h new file mode 100644 index 00000000..c8e6ccf4 --- /dev/null +++ b/lib/cbor/port/include/cbor.h @@ -0,0 +1,2 @@ +#include "../../tinycbor/src/cbor.h" +#include "../../tinycbor/src/cborjson.h" diff --git a/lib/cbor/test/CMakeLists.txt b/lib/cbor/test/CMakeLists.txt new file mode 100644 index 00000000..b39a409b --- /dev/null +++ b/lib/cbor/test/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register(SRC_DIRS "." + PRIV_INCLUDE_DIRS "." + REQUIRES unity + PRIV_REQUIRES cmock cbor) diff --git a/lib/cbor/test/test.c b/lib/cbor/test/test.c new file mode 100644 index 00000000..eef53b1c --- /dev/null +++ b/lib/cbor/test/test.c @@ -0,0 +1,230 @@ +/* + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#include +#include + +#include "unity.h" +#if __has_include("esp_random.h") +#include "esp_random.h" +#else +#include "esp_system.h" +#endif + +#include "cbor.h" + +#define CBOR_CHECK(a, str, goto_tag, ret_value, ...) \ + do \ + { \ + if ((a) != CborNoError) \ + { \ + printf("%s(%d): " str, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + ret = ret_value; \ + goto goto_tag; \ + } \ + } while (0) + +static void indent(int nestingLevel) +{ + while (nestingLevel--) { + printf(" "); + } +} + +static void dumpbytes(const uint8_t *buf, size_t len) +{ + while (len--) { + printf("%02X ", *buf++); + } +} + +/** + * Decode CBOR data manuallly + */ +static CborError example_dump_cbor_buffer(CborValue *it, int nestingLevel) +{ + CborError ret = CborNoError; + while (!cbor_value_at_end(it)) { + CborType type = cbor_value_get_type(it); + + indent(nestingLevel); + switch (type) { + case CborArrayType: { + CborValue recursed; + assert(cbor_value_is_container(it)); + puts("Array["); + ret = cbor_value_enter_container(it, &recursed); + CBOR_CHECK(ret, "enter container failed", err, ret); + ret = example_dump_cbor_buffer(&recursed, nestingLevel + 1); + CBOR_CHECK(ret, "recursive dump failed", err, ret); + ret = cbor_value_leave_container(it, &recursed); + CBOR_CHECK(ret, "leave container failed", err, ret); + indent(nestingLevel); + puts("]"); + continue; + } + case CborMapType: { + CborValue recursed; + assert(cbor_value_is_container(it)); + puts("Map{"); + ret = cbor_value_enter_container(it, &recursed); + CBOR_CHECK(ret, "enter container failed", err, ret); + ret = example_dump_cbor_buffer(&recursed, nestingLevel + 1); + CBOR_CHECK(ret, "recursive dump failed", err, ret); + ret = cbor_value_leave_container(it, &recursed); + CBOR_CHECK(ret, "leave container failed", err, ret); + indent(nestingLevel); + puts("}"); + continue; + } + case CborIntegerType: { + int64_t val; + ret = cbor_value_get_int64(it, &val); + CBOR_CHECK(ret, "parse int64 failed", err, ret); + printf("%lld\n", (long long)val); + break; + } + case CborByteStringType: { + uint8_t *buf; + size_t n; + ret = cbor_value_dup_byte_string(it, &buf, &n, it); + CBOR_CHECK(ret, "parse byte string failed", err, ret); + dumpbytes(buf, n); + puts(""); + free(buf); + continue; + } + case CborTextStringType: { + char *buf; + size_t n; + ret = cbor_value_dup_text_string(it, &buf, &n, it); + CBOR_CHECK(ret, "parse text string failed", err, ret); + puts(buf); + free(buf); + continue; + } + case CborTagType: { + CborTag tag; + ret = cbor_value_get_tag(it, &tag); + CBOR_CHECK(ret, "parse tag failed", err, ret); + printf("Tag(%lld)\n", (long long)tag); + break; + } + case CborSimpleType: { + uint8_t type; + ret = cbor_value_get_simple_type(it, &type); + CBOR_CHECK(ret, "parse simple type failed", err, ret); + printf("simple(%u)\n", type); + break; + } + case CborNullType: + puts("null"); + break; + case CborUndefinedType: + puts("undefined"); + break; + case CborBooleanType: { + bool val; + ret = cbor_value_get_boolean(it, &val); + CBOR_CHECK(ret, "parse boolean type failed", err, ret); + puts(val ? "true" : "false"); + break; + } + case CborHalfFloatType: { + uint16_t val; + ret = cbor_value_get_half_float(it, &val); + CBOR_CHECK(ret, "parse half float type failed", err, ret); + printf("__f16(%04x)\n", val); + break; + } + case CborFloatType: { + float val; + ret = cbor_value_get_float(it, &val); + CBOR_CHECK(ret, "parse float type failed", err, ret); + printf("%g\n", val); + break; + } + case CborDoubleType: { + double val; + ret = cbor_value_get_double(it, &val); + CBOR_CHECK(ret, "parse double float type failed", err, ret); + printf("%g\n", val); + break; + } + case CborInvalidType: { + ret = CborErrorUnknownType; + CBOR_CHECK(ret, "unknown cbor type", err, ret); + break; + } + } + + ret = cbor_value_advance_fixed(it); + CBOR_CHECK(ret, "fix value failed", err, ret); + } + return CborNoError; +err: + return ret; +} + + +TEST_CASE("CBOR example", "[cbor]") +{ + CborEncoder root_encoder; + CborParser root_parser; + CborValue it; + uint8_t buf[100]; + + // Initialize the outermost cbor encoder + cbor_encoder_init(&root_encoder, buf, sizeof(buf), 0); + + // Create an array containing several items + CborEncoder array_encoder; + CborEncoder map_encoder; + cbor_encoder_create_array(&root_encoder, &array_encoder, 5); // [ + // 1. Create a map containing several pairs + cbor_encoder_create_map(&array_encoder, &map_encoder, 3); // { + // chip:esp32 + cbor_encode_text_stringz(&map_encoder, "chip"); + cbor_encode_text_stringz(&map_encoder, "esp32"); + // unicore:false + cbor_encode_text_stringz(&map_encoder, "unicore"); + cbor_encode_boolean(&map_encoder, false); + // ip:[192,168,1,100] + cbor_encode_text_stringz(&map_encoder, "ip"); + CborEncoder array2; + cbor_encoder_create_array(&map_encoder, &array2, 4); // [ + // Encode several numbers + cbor_encode_uint(&array2, 192); + cbor_encode_uint(&array2, 168); + cbor_encode_uint(&array2, 1); + cbor_encode_uint(&array2, 100); + cbor_encoder_close_container(&map_encoder, &array2); // ] + cbor_encoder_close_container(&array_encoder, &map_encoder); // } + // 2. Encode float number + cbor_encode_float(&array_encoder, 3.14); + // 3. Encode simple value + cbor_encode_simple_value(&array_encoder, 99); + // 4. Encode a string + cbor_encode_text_stringz(&array_encoder, "2019-07-10 09:00:00+0000"); + // 5. Encode a undefined value + cbor_encode_undefined(&array_encoder); + cbor_encoder_close_container(&root_encoder, &array_encoder); // ] + + // If error happend when encoding, then this value should be meaningless + printf("encoded buffer size %d", cbor_encoder_get_buffer_size(&root_encoder, buf)); + + // Initialize the cbor parser and the value iterator + cbor_parser_init(buf, sizeof(buf), 0, &root_parser, &it); + + printf("convert CBOR to JSON"); + // Dump the values in JSON format + cbor_value_to_json(stdout, &it, 0); + puts(""); + + printf("decode CBOR manually: "); + // Decode CBOR data manully + TEST_ESP_OK(example_dump_cbor_buffer(&it, 0)); +} + diff --git a/lib/cbor/tinycbor/.appveyor.yml b/lib/cbor/tinycbor/.appveyor.yml new file mode 100644 index 00000000..ef47797e --- /dev/null +++ b/lib/cbor/tinycbor/.appveyor.yml @@ -0,0 +1,28 @@ +version: 0.6-build-{build} +pull_requests: + do_not_increment_build_number: true +image: +- Visual Studio 2017 +- Visual Studio 2019 +install: +- cmd: >- + if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" (call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86) & (set QTDIR=C:\Qt\5.13\msvc2017) + + if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2019" (call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64) & (set QTDIR=C:\Qt\6.1\msvc2019_64) + + set path=%PATH%;%QTDIR%\bin +build_script: +- cmd: >- + nmake -f Makefile.nmake -nologo CFLAGS="-W3 -Os -MDd" + + cd tests + + qmake CONFIG-=release CONFIG+=debug + + nmake -nologo -s +test_script: +- cmd: >- + nmake -s -nologo TESTARGS=-silent check +artifacts: +- path: lib\tinycbor.lib +deploy: off diff --git a/lib/cbor/tinycbor/.gitattributes b/lib/cbor/tinycbor/.gitattributes new file mode 100644 index 00000000..76ed2567 --- /dev/null +++ b/lib/cbor/tinycbor/.gitattributes @@ -0,0 +1,4 @@ +.tag export-subst +.gitignore export-ignore +.gitattributes export-ignore +.appveyor.yml text diff --git a/lib/cbor/tinycbor/.gitignore b/lib/cbor/tinycbor/.gitignore new file mode 100644 index 00000000..3272de33 --- /dev/null +++ b/lib/cbor/tinycbor/.gitignore @@ -0,0 +1,81 @@ +# Frequent generated files +callgrind.out.* +pcviewer.cfg +*~ +*.a +*.la +*.core +*.d +*.dylib +*.moc +*.o +*.obj +*.orig +*.swp +*.rej +*.so +*.so.* +*.pbxuser +*.mode1 +*.mode1v3 +*_pch.h.cpp +*_resource.rc +.#* +*.*# +core +.qmake.cache +.qmake.stash +.qmake.vars +.device.vars +tags +.DS_Store +*.debug +Makefile* +*.prl +*.app +*.pro.user* +*.qmlproject.user* +*.gcov +*.gcda +*.gcno +*.flc +.*.swp +tinycbor.pc + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.vcxproj +*.vcxproj.filters +*.vcxproj.user +*.exe.embed.manifest +*.exe_manifest.rc +*.exe_manifest.res + +# MinGW generated files +*.Debug +*.Release + +# INTEGRITY generated files +*.gpj +*.int +*.ael +*.dla +*.dnm +*.dep +*.map + +bin +doc +lib +src/cjson +src/doxygen.log +!/Makefile +.config diff --git a/lib/cbor/tinycbor/.tag b/lib/cbor/tinycbor/.tag new file mode 100644 index 00000000..6828f88d --- /dev/null +++ b/lib/cbor/tinycbor/.tag @@ -0,0 +1 @@ +$Format:%H$ diff --git a/lib/cbor/tinycbor/.travis.yml b/lib/cbor/tinycbor/.travis.yml new file mode 100644 index 00000000..4df21cb7 --- /dev/null +++ b/lib/cbor/tinycbor/.travis.yml @@ -0,0 +1,92 @@ +env: + - BUILD_DOCS=false +jobs: + include: + - # only build docs on main + if: branch = main + env: BUILD_DOCS=true + +language: cpp +matrix: + include: + - os: linux + dist: xenial + addons: + apt: + sources: + - sourceline: 'ppa:beineri/opt-qt-5.12.1-xenial' + packages: + - qt512base valgrind + - doxygen + env: + - QMAKESPEC=linux-g++ + - EVAL="CC=gcc && CXX=g++" + - CFLAGS="-Os" + - LDFLAGS="-Wl,--no-undefined -lm" + - QMAKEFLAGS="-config release" + - QT_NO_CPU_FEATURE=rdrnd + - os: linux + dist: xenial + addons: + apt: + sources: + - sourceline: 'ppa:beineri/opt-qt-5.12.1-xenial' + packages: + - qt512base + env: + - QMAKESPEC=linux-clang + - EVAL="CC=clang && CXX=clang++" + - CFLAGS="-Oz" + - LDFLAGS="-Wl,--no-undefined -lm" + - QMAKEFLAGS="-config release" + - MAKEFLAGS=-s + - TESTARGS=-silent + - os: linux + dist: xenial + env: + - QMAKESPEC=linux-gcc-freestanding + - EVAL="CXX=false" + - CFLAGS="-ffreestanding -Os" + - LDFLAGS="-Wl,--no-undefined -lm" + - os: linux + dist: xenial + env: + - QMAKESPEC=linux-gcc-no-math + - EVAL="CXX=false && touch src/math.h src/float.h" + - CFLAGS="-ffreestanding -DCBOR_NO_FLOATING_POINT -Os" + - LDFLAGS="-Wl,--no-undefined" + - LDLIBS="" + - os: osx + env: + - QMAKESPEC=macx-clang + - CFLAGS="-Oz" + - QMAKEFLAGS="-config debug" + - MAKEFLAGS=-s + - TESTARGS=-silent + - PATH=/usr/local/opt/qt5/bin:$PATH +install: + - if [ "${TRAVIS_OS_NAME}" != "linux" ]; then + brew update; + brew install qt5; + fi +script: + - PATH=`echo /opt/qt*/bin`:$PATH + - eval "$EVAL" + - make -s -f Makefile.configure configure | tee .config + - make -k + CFLAGS="$CFLAGS -march=native -g1 -Wall -Wextra -Werror" + CPPFLAGS="-DNDEBUG -DCBOR_ENCODER_WRITER_CONTROL=-1 -DCBOR_PARSER_READER_CONTROL=-1" + lib/libtinycbor.a + - size lib/libtinycbor.a | tee sizes + - make -s clean + - make -k + CFLAGS="$CFLAGS -O0 -g" + LDFLAGS="$LDFLAGS" ${LDLIBS+LDLIBS="$LDLIBS"} + - grep -q freestanding-pass .config || make + QMAKEFLAGS="$QMAKEFLAGS QMAKE_CXX=$CXX" + tests/Makefile + - grep -q freestanding-pass .config || + (cd tests && make TESTARGS=-silent check -k + TESTRUNNER=`which valgrind 2>/dev/null`) + - make -s clean + - ! [ $BUILD_DOCS ] || ./scripts/update-docs.sh diff --git a/lib/cbor/tinycbor/Doxyfile b/lib/cbor/tinycbor/Doxyfile new file mode 100644 index 00000000..a7263c2f --- /dev/null +++ b/lib/cbor/tinycbor/Doxyfile @@ -0,0 +1,49 @@ +PROJECT_NAME = "TinyCBOR $(VERSION) API" +OUTPUT_DIRECTORY = ../doc +ABBREVIATE_BRIEF = +SHORT_NAMES = YES +JAVADOC_AUTOBRIEF = YES +QT_AUTOBRIEF = YES +TAB_SIZE = 8 +ALIASES = "value=\arg \c" +OPTIMIZE_OUTPUT_FOR_C = YES +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = NO +HIDE_UNDOC_MEMBERS = YES +HIDE_UNDOC_CLASSES = YES +GENERATE_TODOLIST = NO +GENERATE_TESTLIST = NO +GENERATE_BUGLIST = NO +GENERATE_DEPRECATEDLIST= NO +SHOW_USED_FILES = NO +WARN_IF_UNDOCUMENTED = NO +WARN_LOGFILE = doxygen.log +INPUT = . +FILE_PATTERNS = *.h \ + *.c \ + *.dox +EXCLUDE_PATTERNS = *_p.h +STRIP_CODE_COMMENTS = NO +REFERENCED_BY_RELATION = YES +IGNORE_PREFIX = cbor_ \ + Cbor +HTML_TIMESTAMP = NO +GENERATE_HTMLHELP = YES +GENERATE_CHI = YES +BINARY_TOC = YES +TOC_EXPAND = YES +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest +SEARCHENGINE = NO +GENERATE_LATEX = NO +COMPACT_LATEX = YES +MACRO_EXPANSION = YES +PREDEFINED = DOXYGEN \ + CBOR_INLINE_API= +CLASS_DIAGRAMS = NO +CLASS_GRAPH = NO +COLLABORATION_GRAPH = NO +GROUP_GRAPHS = NO +INCLUDE_GRAPH = NO +INCLUDED_BY_GRAPH = NO +GRAPHICAL_HIERARCHY = NO +DIRECTORY_GRAPH = NO diff --git a/lib/cbor/tinycbor/LICENSE b/lib/cbor/tinycbor/LICENSE new file mode 100644 index 00000000..4aad977c --- /dev/null +++ b/lib/cbor/tinycbor/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Intel Corporation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/lib/cbor/tinycbor/Makefile b/lib/cbor/tinycbor/Makefile new file mode 100644 index 00000000..948e3faf --- /dev/null +++ b/lib/cbor/tinycbor/Makefile @@ -0,0 +1,250 @@ +# Variables: +prefix = /usr/local +exec_prefix = $(prefix) +bindir = $(exec_prefix)/bin +libdir = $(exec_prefix)/lib +includedir = $(prefix)/include +pkgconfigdir = $(libdir)/pkgconfig + +CFLAGS = -Wall -Wextra +LDFLAGS_GCSECTIONS = -Wl,--gc-sections +LDFLAGS += $(if $(gc_sections-pass),$(LDFLAGS_GCSECTIONS)) +LDLIBS = -lm + +GIT_ARCHIVE = git archive --prefix="$(PACKAGE)/" -9 +INSTALL = install +INSTALL_DATA = $(INSTALL) -m 644 +INSTALL_PROGRAM = $(INSTALL) -m 755 +QMAKE = qmake +MKDIR = mkdir -p +RMDIR = rmdir +SED = sed + +# Our sources +TINYCBOR_HEADERS = src/cbor.h src/cborjson.h src/tinycbor-version.h +TINYCBOR_FREESTANDING_SOURCES = \ + src/cborerrorstrings.c \ + src/cborencoder.c \ + src/cborencoder_close_container_checked.c \ + src/cborencoder_float.c \ + src/cborparser.c \ + src/cborparser_float.c \ + src/cborpretty.c \ +# +CBORDUMP_SOURCES = tools/cbordump/cbordump.c + +BUILD_SHARED = $(shell file -L /bin/sh 2>/dev/null | grep -q ELF && echo 1) +BUILD_STATIC = 1 + +ifneq ($(BUILD_STATIC),1) +ifneq ($(BUILD_SHARED),1) + $(error error: BUILD_STATIC and BUILD_SHARED can not be both disabled) +endif +endif + +INSTALL_TARGETS += $(bindir)/cbordump +ifeq ($(BUILD_SHARED),1) +BINLIBRARY=lib/libtinycbor.so +INSTALL_TARGETS += $(libdir)/libtinycbor.so.$(VERSION) +endif +ifeq ($(BUILD_STATIC),1) +BINLIBRARY=lib/libtinycbor.a +INSTALL_TARGETS += $(libdir)/libtinycbor.a +endif +INSTALL_TARGETS += $(pkgconfigdir)/tinycbor.pc +INSTALL_TARGETS += $(TINYCBOR_HEADERS:src/%=$(includedir)/tinycbor/%) + +# setup VPATH +MAKEFILE := $(lastword $(MAKEFILE_LIST)) +SRCDIR := $(dir $(MAKEFILE)) +VPATH = $(SRCDIR):$(SRCDIR)/src + +# Our version +GIT_DIR := $(strip $(shell git -C $(SRCDIR). rev-parse --git-dir 2> /dev/null)) +VERSION = $(shell cat $(SRCDIR)VERSION) +SOVERSION = $(shell cut -f1-2 -d. $(SRCDIR)VERSION) +PACKAGE = tinycbor-$(VERSION) + +# Check that QMAKE is Qt 5 +ifeq ($(origin QMAKE),file) + check_qmake = $(strip $(shell $(1) -query QT_VERSION 2>/dev/null | cut -b1)) + ifneq ($(call check_qmake,$(QMAKE)),5) + QMAKE := qmake -qt5 + ifneq ($(call check_qmake,$(QMAKE)),5) + QMAKE := qmake-qt5 + ifneq ($(call check_qmake,$(QMAKE)),5) + QMAKE := @echo >&2 $(MAKEFILE): Cannot find a Qt 5 qmake; false + endif + endif + endif +endif + +-include .config + +ifeq ($(wildcard .config),) + $(info .config file not yet created) +endif + +ifeq ($(freestanding-pass),1) +TINYCBOR_SOURCES = $(TINYCBOR_FREESTANDING_SOURCES) +else +TINYCBOR_SOURCES = \ + $(TINYCBOR_FREESTANDING_SOURCES) \ + src/cborparser_dup_string.c \ + src/cborpretty_stdio.c \ + src/cbortojson.c \ + src/cborvalidation.c \ +# +# if open_memstream is unavailable on the system, try to implement our own +# version using funopen or fopencookie +ifeq ($(open_memstream-pass),) + ifeq ($(funopen-pass)$(fopencookie-pass),) + CFLAGS += -DWITHOUT_OPEN_MEMSTREAM + ifeq ($(wildcard .config),.config) + $(warning warning: funopen and fopencookie unavailable, open_memstream can not be implemented and conversion to JSON will not work properly!) + endif + else + TINYCBOR_SOURCES += src/open_memstream.c + endif +endif +endif + +# json2cbor depends on an external library (cjson) +ifneq ($(cjson-pass)$(system-cjson-pass),) + JSON2CBOR_SOURCES = tools/json2cbor/json2cbor.c + INSTALL_TARGETS += $(bindir)/json2cbor + ifeq ($(system-cjson-pass),1) + LDFLAGS_CJSON = -lcjson + else + JSON2CBOR_SOURCES += src/cjson/cJSON.c + json2cbor_CCFLAGS = -I$(SRCDIR)src/cjson + endif +endif + +# Rules +all: .config \ + $(if $(subst 0,,$(BUILD_STATIC)),lib/libtinycbor.a) \ + $(if $(subst 0,,$(BUILD_SHARED)),lib/libtinycbor.so) \ + $(if $(freestanding-pass),,bin/cbordump) \ + tinycbor.pc +all: $(if $(JSON2CBOR_SOURCES),bin/json2cbor) +check: tests/Makefile | $(BINLIBRARY) + $(MAKE) -C tests check +silentcheck: | $(BINLIBRARY) + TESTARGS=-silent $(MAKE) -f $(MAKEFILE) -s check +configure: .config +.config: Makefile.configure + $(MAKE) -f $(SRCDIR)Makefile.configure OUT='>&9' configure 9> $@ + +lib/libtinycbor-freestanding.a: $(TINYCBOR_FREESTANDING_SOURCES:.c=.o) + @$(MKDIR) -p lib + $(AR) cqs $@ $^ + +lib/libtinycbor.a: $(TINYCBOR_SOURCES:.c=.o) + @$(MKDIR) -p lib + $(AR) cqs $@ $^ + +lib/libtinycbor.so: $(TINYCBOR_SOURCES:.c=.pic.o) + @$(MKDIR) -p lib + $(CC) -shared -Wl,-soname,libtinycbor.so.$(SOVERSION) -o lib/libtinycbor.so.$(VERSION) $(LDFLAGS) $^ $(LDLIBS) + cd lib ; ln -sf libtinycbor.so.$(VERSION) libtinycbor.so ; ln -sf libtinycbor.so.$(VERSION) libtinycbor.so.$(SOVERSION) + +bin/cbordump: $(CBORDUMP_SOURCES:.c=.o) $(BINLIBRARY) + @$(MKDIR) -p bin + $(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) + +bin/json2cbor: $(JSON2CBOR_SOURCES:.c=.o) $(BINLIBRARY) + @$(MKDIR) -p bin + $(CC) -o $@ $(LDFLAGS) $^ $(LDFLAGS_CJSON) $(LDLIBS) + +tinycbor.pc: tinycbor.pc.in + $(SED) > $@ < $< \ + -e 's,@prefix@,$(prefix),' \ + -e 's,@exec_prefix@,$(exec_prefix),' \ + -e 's,@libdir@,$(libdir),' \ + -e 's,@includedir@,$(includedir),' \ + -e 's,@version@,$(VERSION),' + +tests/Makefile: tests/tests.pro + $(QMAKE) $(QMAKEFLAGS) -o $@ $< + +$(PACKAGE).tar.gz: | .git + GIT_DIR=$(SRCDIR).git $(GIT_ARCHIVE) --format=tar.gz -o "$(PACKAGE).tar.gz" HEAD +$(PACKAGE).zip: | .git + GIT_DIR=$(SRCDIR).git $(GIT_ARCHIVE) --format=zip -o "$(PACKAGE).zip" HEAD + +$(DESTDIR)$(libdir)/%: lib/% + $(INSTALL) -d $(@D) + $(INSTALL_DATA) $< $@ +$(DESTDIR)$(bindir)/%: bin/% + $(INSTALL) -d $(@D) + $(INSTALL_PROGRAM) $< $@ +$(DESTDIR)$(pkgconfigdir)/%: % + $(INSTALL) -d $(@D) + $(INSTALL_DATA) $< $@ +$(DESTDIR)$(includedir)/tinycbor/%: src/% + $(INSTALL) -d $(@D) + $(INSTALL_DATA) $< $@ + +install-strip: + $(MAKE) -f $(MAKEFILE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install + +install: $(INSTALL_TARGETS:%=$(DESTDIR)%) +ifeq ($(BUILD_SHARED),1) + ln -sf libtinycbor.so.$(VERSION) $(DESTDIR)$(libdir)/libtinycbor.so + ln -sf libtinycbor.so.$(VERSION) $(DESTDIR)$(libdir)/libtinycbor.so.$(SOVERSION) +endif + +uninstall: + $(RM) $(INSTALL_TARGETS:%=$(DESTDIR)%) + $(RM) $(DESTDIR)$(libdir)/libtinycbor.so + $(RM) $(DESTDIR)$(libdir)/libtinycbor.so.$(SOVERSION) + +mostlyclean: + $(RM) $(TINYCBOR_SOURCES:.c=.o) + $(RM) $(TINYCBOR_SOURCES:.c=.pic.o) + $(RM) $(CBORDUMP_SOURCES:.c=.o) + +clean: mostlyclean + $(RM) bin/cbordump + $(RM) bin/json2cbor + $(RM) lib/libtinycbor.a + $(RM) lib/libtinycbor-freestanding.a + $(RM) tinycbor.pc + $(RM) lib/libtinycbor.so* + test -e tests/Makefile && $(MAKE) -C tests clean || : + +distclean: clean + test -e tests/Makefile && $(MAKE) -C tests distclean || : + +docs: + cd $(SRCDIR)src && VERSION=$(VERSION) doxygen $(SRCDIR)/../Doxyfile + +dist: $(PACKAGE).tar.gz $(PACKAGE).zip +distcheck: .git + -$(RM) -r $${TMPDIR-/tmp}/tinycbor-distcheck + GIT_DIR=$(SRCDIR).git git archive --prefix=tinycbor-distcheck/ --format=tar HEAD | tar -xf - -C $${TMPDIR-/tmp} + cd $${TMPDIR-/tmp}/tinycbor-distcheck && $(MAKE) silentcheck + $(RM) -r $${TMPDIR-/tmp}/tinycbor-distcheck + +tag: distcheck + @cd $(SRCDIR). && perl scripts/maketag.pl + +.PHONY: all check silentcheck configure install uninstall +.PHONY: mostlyclean clean distclean +.PHONY: docs dist distcheck release +.SECONDARY: + +cflags := $(CPPFLAGS) -I$(SRCDIR)src +cflags += -std=gnu99 $(CFLAGS) \ + -Werror=incompatible-pointer-types \ + -Werror=implicit-function-declaration \ + -Werror=int-conversion +%.o: %.c + @test -d $(@D) || $(MKDIR) $(@D) + $(CC) $(cflags) $($(basename $(notdir $@))_CCFLAGS) -c -o $@ $< +%.pic.o: %.c + @test -d $(@D) || $(MKDIR) $(@D) + $(CC) $(cflags) -fPIC $($(basename $(notdir $@))_CCFLAGS) -c -o $@ $< + +-include src/*.d diff --git a/lib/cbor/tinycbor/README b/lib/cbor/tinycbor/README new file mode 100644 index 00000000..167efa06 --- /dev/null +++ b/lib/cbor/tinycbor/README @@ -0,0 +1,13 @@ +Concise Binary Object Representation (CBOR) Library +--------------------------------------------------- + +To build TinyCBOR: + + make + +If you want to change the compiler or pass extra compiler flags: + + make CC=clang CFLAGS="-m32 -Oz" LDFLAGS="-m32" + +Documentation: https://intel.github.io/tinycbor/current/ + diff --git a/lib/cbor/tinycbor/TODO b/lib/cbor/tinycbor/TODO new file mode 100644 index 00000000..e9103ee6 --- /dev/null +++ b/lib/cbor/tinycbor/TODO @@ -0,0 +1,25 @@ +==== To Do list for libcbor ==== +=== General === +* API review +* Benchmark +* Write examples +** Simple decoder +** Decoder to JSON +** Windowed encoding/decoding (limited memory) + +=== Encoder === +* Write API docs +* Add API for creating indeterminate-length arrays and maps +* Add API for creating indeterminate-length strings +* Add API for relaxing doubles to floats and to integers +* Add length-checking of the sub-containers (#ifndef CBOR_ENCODER_NO_USER_CHECK) +* Decide how to indicate number of bytes needed +** Suggestion: return negative number from the functions + +=== Decoder === +* Write functions not yet implemented +* Add API for stream-decoding strings +* Add API for checking known tags and simple types +* (unlikely) Add API for checking the pairing of a tag and the tagged type +* Write tests for error conditions +* Fuzzy-test the decoder diff --git a/lib/cbor/tinycbor/VERSION b/lib/cbor/tinycbor/VERSION new file mode 100644 index 00000000..a918a2aa --- /dev/null +++ b/lib/cbor/tinycbor/VERSION @@ -0,0 +1 @@ +0.6.0 diff --git a/lib/cbor/tinycbor/examples/examples.pro b/lib/cbor/tinycbor/examples/examples.pro new file mode 100644 index 00000000..22071ac3 --- /dev/null +++ b/lib/cbor/tinycbor/examples/examples.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = simplereader.pro diff --git a/lib/cbor/tinycbor/examples/simplereader.c b/lib/cbor/tinycbor/examples/simplereader.c new file mode 100644 index 00000000..0612ba44 --- /dev/null +++ b/lib/cbor/tinycbor/examples/simplereader.c @@ -0,0 +1,185 @@ +#include "../src/cbor.h" + +#include +#include +#include +#include +#include + +static uint8_t *readfile(const char *fname, size_t *size) +{ + struct stat st; + FILE *f = fopen(fname, "rb"); + if (!f) + return NULL; + if (fstat(fileno(f), &st) == -1) + return NULL; + uint8_t *buf = malloc(st.st_size); + if (buf == NULL) + return NULL; + *size = fread(buf, st.st_size, 1, f) == 1 ? st.st_size : 0; + fclose(f); + return buf; +} + +static void indent(int nestingLevel) +{ + while (nestingLevel--) + printf(" "); +} + +static void dumpbytes(const uint8_t *buf, size_t len) +{ + printf("\""); + while (len--) + printf("\\x%02X", *buf++); + printf("\""); +} + +static CborError dumprecursive(CborValue *it, int nestingLevel) +{ + while (!cbor_value_at_end(it)) { + CborError err; + CborType type = cbor_value_get_type(it); + + indent(nestingLevel); + switch (type) { + case CborArrayType: + case CborMapType: { + // recursive type + CborValue recursed; + assert(cbor_value_is_container(it)); + puts(type == CborArrayType ? "Array[" : "Map["); + err = cbor_value_enter_container(it, &recursed); + if (err) + return err; // parse error + err = dumprecursive(&recursed, nestingLevel + 1); + if (err) + return err; // parse error + err = cbor_value_leave_container(it, &recursed); + if (err) + return err; // parse error + indent(nestingLevel); + puts("]"); + continue; + } + + case CborIntegerType: { + int64_t val; + cbor_value_get_int64(it, &val); // can't fail + printf("%lld\n", (long long)val); + break; + } + + case CborByteStringType: { + uint8_t *buf; + size_t n; + err = cbor_value_dup_byte_string(it, &buf, &n, it); + if (err) + return err; // parse error + dumpbytes(buf, n); + puts(""); + free(buf); + continue; + } + + case CborTextStringType: { + char *buf; + size_t n; + err = cbor_value_dup_text_string(it, &buf, &n, it); + if (err) + return err; // parse error + printf("\"%s\"\n", buf); + free(buf); + continue; + } + + case CborTagType: { + CborTag tag; + cbor_value_get_tag(it, &tag); // can't fail + printf("Tag(%lld)\n", (long long)tag); + break; + } + + case CborSimpleType: { + uint8_t type; + cbor_value_get_simple_type(it, &type); // can't fail + printf("simple(%u)\n", type); + break; + } + + case CborNullType: + puts("null"); + break; + + case CborUndefinedType: + puts("undefined"); + break; + + case CborBooleanType: { + bool val; + cbor_value_get_boolean(it, &val); // can't fail + puts(val ? "true" : "false"); + break; + } + + case CborDoubleType: { + double val; + if (false) { + float f; + case CborFloatType: + cbor_value_get_float(it, &f); + val = f; + } else { + cbor_value_get_double(it, &val); + } + printf("%g\n", val); + break; + } + case CborHalfFloatType: { + uint16_t val; + cbor_value_get_half_float(it, &val); + printf("__f16(%04x)\n", val); + break; + } + + case CborInvalidType: + assert(false); // can't happen + break; + } + + err = cbor_value_advance_fixed(it); + if (err) + return err; + } + return CborNoError; +} + +int main(int argc, char **argv) +{ + if (argc != 2) { + puts("simplereader "); + return 1; + } + + size_t length; + uint8_t *buf = readfile(argv[1], &length); + if (!buf) { + perror("readfile"); + return 1; + } + + CborParser parser; + CborValue it; + CborError err = cbor_parser_init(buf, length, 0, &parser, &it); + if (!err) + err = dumprecursive(&it, 0); + free(buf); + + if (err) { + fprintf(stderr, "CBOR parsing failure at offset %ld: %s\n", + it.ptr - buf, cbor_error_string(err)); + return 1; + } + return 0; +} diff --git a/lib/cbor/tinycbor/examples/simplereader.pro b/lib/cbor/tinycbor/examples/simplereader.pro new file mode 100644 index 00000000..07fdc6ac --- /dev/null +++ b/lib/cbor/tinycbor/examples/simplereader.pro @@ -0,0 +1,3 @@ +CONFIG -= qt +SOURCES = simplereader.c +include(../src/src.pri) diff --git a/lib/cbor/tinycbor/scripts/maketag.pl b/lib/cbor/tinycbor/scripts/maketag.pl new file mode 100644 index 00000000..5b1a8b79 --- /dev/null +++ b/lib/cbor/tinycbor/scripts/maketag.pl @@ -0,0 +1,91 @@ +#!perl +use strict; +sub run(@) { + open PROC, "-|", @_ or die("Cannot run $_[0]: $!"); + my @out; + while () { + chomp; + push @out, $_; + } + close PROC; + return @out; +} + +my @tags = run("git", "tag"); +my @v = run("git", "show", "HEAD:VERSION"); +my $v = $v[0]; + +my $tagfile = ".git/TAG_EDITMSG"; +open TAGFILE, ">", $tagfile + or die("Cannot create file for editing tag message: $!"); +select TAGFILE; +print "TinyCBOR release $v\n"; +print "\n"; +print "# Write something nice about this release here\n"; + +# Do we have a commit template? +my @result = run("git", "config", "--get", "commit.template"); +if (scalar @result) { + open TEMPLATE, "<", $result[0]; + map { print $_; }