git: 1755b9daa693 - stable/14 - libcbor: vendor update to 0.11.0
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 01 Aug 2024 16:07:19 UTC
The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=1755b9daa6938fa549abbe7f99d53bf504ea48c7 commit 1755b9daa6938fa549abbe7f99d53bf504ea48c7 Author: Ed Maste <emaste@FreeBSD.org> AuthorDate: 2024-05-03 23:33:50 +0000 Commit: Ed Maste <emaste@FreeBSD.org> CommitDate: 2024-08-01 15:11:45 +0000 libcbor: vendor update to 0.11.0 Sponsored by: The FreeBSD Foundation (cherry picked from commit abd872540f24cfc7dbd1ea29b6918c7082a22108) --- contrib/libcbor/.circleci/config.yml | 30 ++-- contrib/libcbor/.cirrus.yml | 26 +++ contrib/libcbor/.readthedocs.yaml | 21 +++ contrib/libcbor/CHANGELOG.md | 15 +- contrib/libcbor/CMakeLists.txt | 18 +- contrib/libcbor/CONTRIBUTING.md | 2 +- contrib/libcbor/Doxyfile | 2 +- contrib/libcbor/README.md | 7 +- contrib/libcbor/appveyor.yml | 14 -- contrib/libcbor/doc/source/api/item_types.rst | 2 +- contrib/libcbor/doc/source/conf.py | 18 +- contrib/libcbor/doc/source/development.rst | 6 +- contrib/libcbor/doc/source/index.rst | 8 +- contrib/libcbor/doc/source/internal.rst | 4 +- contrib/libcbor/doc/source/requirements.txt | 52 +++--- ...fc_conformance.rst => standard_conformance.rst} | 6 +- contrib/libcbor/examples/CMakeLists.txt | 4 + .../bazel/third_party/libcbor/cbor/configuration.h | 4 +- contrib/libcbor/examples/cbor2cjson.c | 123 +++++++++++++ contrib/libcbor/examples/cjson2cbor.c | 4 +- contrib/libcbor/examples/data/all_types.cbor | Bin 0 -> 354 bytes contrib/libcbor/examples/readfile.c | 2 +- contrib/libcbor/oss-fuzz/build.sh | 2 +- contrib/libcbor/src/CMakeLists.txt | 21 ++- contrib/libcbor/src/cbor.c | 82 +++++---- contrib/libcbor/src/cbor/common.h | 2 +- .../libcbor/src/cbor/internal/builder_callbacks.c | 27 +-- contrib/libcbor/src/cbor/internal/loaders.c | 2 +- contrib/libcbor/src/cbor/internal/memory_utils.h | 2 +- contrib/libcbor/src/cbor/internal/unicode.c | 6 +- contrib/libcbor/src/cbor/internal/unicode.h | 6 +- contrib/libcbor/src/cbor/maps.c | 1 + contrib/libcbor/src/cbor/streaming.c | 43 ++--- contrib/libcbor/src/cbor/strings.c | 10 ++ contrib/libcbor/src/cbor/strings.h | 19 +- contrib/libcbor/src/libcborConfig.cmake.in | 8 + contrib/libcbor/test/callbacks_test.c | 25 +++ contrib/libcbor/test/cbor_serialize_test.c | 32 ++++ contrib/libcbor/test/cbor_stream_decode_test.c | 8 +- contrib/libcbor/test/float_ctrl_test.c | 6 +- contrib/libcbor/test/pretty_printer_test.c | 197 +++++++++++++++++++-- contrib/libcbor/test/string_test.c | 67 +++++++ contrib/libcbor/test/tag_test.c | 23 +++ contrib/libcbor/test/test_allocator.c | 2 +- 44 files changed, 746 insertions(+), 213 deletions(-) diff --git a/contrib/libcbor/.circleci/config.yml b/contrib/libcbor/.circleci/config.yml index 69371b67d624..4391ad8d1e9c 100644 --- a/contrib/libcbor/.circleci/config.yml +++ b/contrib/libcbor/.circleci/config.yml @@ -4,12 +4,14 @@ commands: linux-setup: steps: - run: sudo apt-get update - - run: sudo apt-get install -y cmake ${TOOLCHAIN_PACKAGES} - - run: sudo apt install libcmocka-dev + # NEEDRESTART_MODE prevents automatic restarts which seem to hang. + - run: sudo NEEDRESTART_MODE=l apt-get install -y cmake ${TOOLCHAIN_PACKAGES} + - run: sudo NEEDRESTART_MODE=l apt-get install -y libcmocka-dev libcjson-dev build: steps: - run: > cmake -DWITH_TESTS=ON \ + -DWITH_EXAMPLES=ON \ -DCMAKE_BUILD_TYPE=Debug \ -DSANITIZE=OFF \ -DCOVERAGE="${CMAKE_COVERAGE:='OFF'}" \ @@ -31,14 +33,14 @@ orbs: jobs: static-test: - machine: - image: ubuntu-2204:2022.10.2 + machine: &default-machine + image: ubuntu-2204:2023.07.2 environment: TOOLCHAIN_PACKAGES: g++ steps: - checkout - linux-setup - - run: sudo apt-get install -y clang-format doxygen cppcheck + - run: sudo NEEDRESTART_MODE=l apt-get install -y clang-format doxygen cppcheck - run: cppcheck --inline-suppr --error-exitcode=1 . - run: bash clang-format.sh --verbose - run: > @@ -60,14 +62,14 @@ jobs: build-and-test: machine: - image: ubuntu-2204:2022.10.2 + <<: *default-machine environment: TOOLCHAIN_PACKAGES: g++ CMAKE_COVERAGE: ON steps: - checkout - linux-setup - - run: sudo apt-get install -y valgrind + - run: sudo NEEDRESTART_MODE=l apt-get install -y valgrind - build - test - run: ctest -T Coverage @@ -81,7 +83,7 @@ jobs: build-and-test-clang: machine: - image: ubuntu-2204:2022.10.2 + <<: *default-machine environment: TOOLCHAIN_PACKAGES: clang CC: clang @@ -94,11 +96,11 @@ jobs: build-and-test-32b: machine: - image: ubuntu-2204:2022.10.2 + <<: *default-machine steps: - checkout - run: sudo apt-get update - - run: sudo apt-get install -y cmake gcc-multilib g++-multilib libc6-dev-i386 + - run: sudo NEEDRESTART_MODE=l apt-get install -y cmake gcc-multilib g++-multilib libc6-dev-i386 # Make cmocka from source w/ 32b setup - run: git clone https://git.cryptomilk.org/projects/cmocka.git ~/cmocka - run: > @@ -117,7 +119,7 @@ jobs: build-and-test-release-clang: machine: - image: ubuntu-2204:2022.10.2 + <<: *default-machine environment: TOOLCHAIN_PACKAGES: clang CC: clang @@ -130,7 +132,7 @@ jobs: llvm-coverage: machine: - image: ubuntu-2204:2022.10.2 + <<: *default-machine environment: TOOLCHAIN_PACKAGES: clang CC: clang @@ -145,7 +147,7 @@ jobs: build-and-test-arm: machine: - image: ubuntu-2204:2022.10.2 + <<: *default-machine environment: TOOLCHAIN_PACKAGES: g++ resource_class: arm.medium @@ -157,7 +159,7 @@ jobs: build-bazel: machine: - image: ubuntu-2204:2022.10.2 + image: ubuntu-2204:2023.07.2 environment: TOOLCHAIN_PACKAGES: g++ steps: diff --git a/contrib/libcbor/.cirrus.yml b/contrib/libcbor/.cirrus.yml new file mode 100644 index 000000000000..948ae23b4a98 --- /dev/null +++ b/contrib/libcbor/.cirrus.yml @@ -0,0 +1,26 @@ +freebsd_task: + install_script: + - ASSUME_ALWAYS_YES=yes pkg bootstrap -f && pkg install -y cmocka cmake ninja + build_script: + - mkdir build + - cd build + - cmake -GNinja -DWITH_TESTS=ON + -DCBOR_CUSTOM_ALLOC=ON + -DCMAKE_BUILD_TYPE=Debug + -DSANITIZE=OFF + .. + - ninja -j $(sysctl -n hw.ncpu) + test_script: + - cd build + - ctest -VV + matrix: + # From gcloud compute images list --project freebsd-org-cloud-dev --no-standard-images + - name: freebsd-13-2 + freebsd_instance: + image_family: freebsd-13-2 + - name: freebsd-14-0 + freebsd_instance: + image_family: freebsd-14-0 + - name: freebsd-15-0-snap + freebsd_instance: + image_family: freebsd-15-0-snap diff --git a/contrib/libcbor/.readthedocs.yaml b/contrib/libcbor/.readthedocs.yaml new file mode 100644 index 000000000000..f2514ffae113 --- /dev/null +++ b/contrib/libcbor/.readthedocs.yaml @@ -0,0 +1,21 @@ +# .readthedocs.yaml +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Set the version of Python and other tools you might need +build: + os: ubuntu-22.04 + tools: + python: "3.11" + +sphinx: + configuration: doc/source/conf.py + +# We recommend specifying your dependencies to enable reproducible builds: +# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html +python: + install: + - requirements: doc/source/requirements.txt diff --git a/contrib/libcbor/CHANGELOG.md b/contrib/libcbor/CHANGELOG.md index f2475f308c7a..3c331f9266ab 100644 --- a/contrib/libcbor/CHANGELOG.md +++ b/contrib/libcbor/CHANGELOG.md @@ -4,6 +4,19 @@ Template: Next --------------------- +0.11.0 (2024-02-04) +--------------------- +- [Updated documentation to refer to RFC 8949](https://github.com/PJK/libcbor/issues/269) +- Improvements to `cbor_describe` + - [Bytestring data will now be printed as well](https://github.com/PJK/libcbor/pull/281) by [akallabeth](https://github.com/akallabeth) + - [Formatting consistency and clarity improvements](https://github.com/PJK/libcbor/pull/285) +- [Fix `cbor_string_set_handle` not setting the codepoint count](https://github.com/PJK/libcbor/pull/286) +- BREAKING: [`cbor_load` will no longer fail on input strings that are well-formed but not valid UTF-8](https://github.com/PJK/libcbor/pull/286) + - If you were relying on the validation, please check the result using `cbor_string_codepoint_count` instead +- BREAKING: [All decoders like `cbor_load` and `cbor_stream_decode` will accept all well-formed tag values](https://github.com/PJK/libcbor/pull/308) (bug discovered by [dskern-github](https://github.com/dskern-github)) + - Previously, decoding of certain values would fail with `CBOR_ERR_MALFORMATED` or `CBOR_DECODER_ERROR` + - This also makes decoding symmetrical with serialization, which already accepts all values + 0.10.2 (2023-01-31) --------------------- - [Fixed minor test bug causing failures for x86 Linux](https://github.com/PJK/libcbor/pull/266) (discovered by [trofi](https://github.com/PJK/libcbor/issues/263)) @@ -117,7 +130,7 @@ Next Breaks build & header compatibility due to: - Improved build configuration and feature check macros -- Endianess configuration fixes (by Erwin Kroon and David Grigsby) +- Endianness configuration fixes (by Erwin Kroon and David Grigsby) - pkg-config compatibility (by Vincent Bernat) - enable use of versioned SONAME (by Vincent Bernat) - better fuzzer (wasn't random until now, ooops) diff --git a/contrib/libcbor/CMakeLists.txt b/contrib/libcbor/CMakeLists.txt index 5c0a7846cfa3..16b9f0875d33 100644 --- a/contrib/libcbor/CMakeLists.txt +++ b/contrib/libcbor/CMakeLists.txt @@ -1,14 +1,18 @@ cmake_minimum_required(VERSION 3.0) + project(libcbor) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/") include(CTest) +include(GNUInstallDirs) # Provides CMAKE_INSTALL_ variables SET(CBOR_VERSION_MAJOR "0") -SET(CBOR_VERSION_MINOR "10") -SET(CBOR_VERSION_PATCH "2") +SET(CBOR_VERSION_MINOR "11") +SET(CBOR_VERSION_PATCH "0") SET(CBOR_VERSION ${CBOR_VERSION_MAJOR}.${CBOR_VERSION_MINOR}.${CBOR_VERSION_PATCH}) -set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true) +option(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY "cmake --build --target install does not depend on cmake --build" true) +option(BUILD_SHARED_LIBS "Build as a shared library" false) + include(CheckIncludeFiles) include(TestBigEndian) @@ -19,10 +23,10 @@ endif() option(CBOR_CUSTOM_ALLOC "Custom, dynamically defined allocator support" OFF) if(CBOR_CUSTOM_ALLOC) - message(WARNING + message(WARNING "CBOR_CUSTOM_ALLOC has been deprecated. Custom allocators are now enabled by default." "The flag is a no-op and will be removed in the next version. " - "Please remove CBOR_CUSTOM_ALLOC from your build configuation.") + "Please remove CBOR_CUSTOM_ALLOC from your build configuration.") endif(CBOR_CUSTOM_ALLOC) option(CBOR_PRETTY_PRINTER "Include a pretty-printing routine" ON) @@ -138,12 +142,10 @@ if (COVERAGE) endif() endif (COVERAGE) - # We want to generate configuration.h from the template and make it so that it is accessible using the same # path during both library build and installed header use, without littering the source dir. -# Using cbor/configuration.h in the build dir works b/c headers will be installed to <prefix>/cbor configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/cbor/configuration.h.in ${PROJECT_BINARY_DIR}/cbor/configuration.h) -install(FILES ${PROJECT_BINARY_DIR}/cbor/configuration.h DESTINATION include/cbor) +install(FILES ${PROJECT_BINARY_DIR}/cbor/configuration.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cbor) # Make the header visible at compile time include_directories(${PROJECT_BINARY_DIR}) diff --git a/contrib/libcbor/CONTRIBUTING.md b/contrib/libcbor/CONTRIBUTING.md index cc834d21a46b..9bd42a06b6dc 100644 --- a/contrib/libcbor/CONTRIBUTING.md +++ b/contrib/libcbor/CONTRIBUTING.md @@ -2,7 +2,7 @@ libcbor is maintained by [@PJK](https://github.com/PJK) in his spare time on a best-effort basis. -Community contributions are welcome as long as they align with the [project priorities](https://github.com/PJK/libcbor#main-features) and [goals](https://libcbor.readthedocs.io/en/latest/development.html#goals) and follow the guidelines described belows. +Community contributions are welcome as long as they align with the [project priorities](https://github.com/PJK/libcbor#main-features) and [goals](https://libcbor.readthedocs.io/en/latest/development.html#goals) and follow the guidelines described below. ## Principles diff --git a/contrib/libcbor/Doxyfile b/contrib/libcbor/Doxyfile index 2571057646d7..67df45cfbb94 100644 --- a/contrib/libcbor/Doxyfile +++ b/contrib/libcbor/Doxyfile @@ -48,7 +48,7 @@ PROJECT_NAME = libcbor # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 0.10.2 +PROJECT_NUMBER = 0.11.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/contrib/libcbor/README.md b/contrib/libcbor/README.md index 6d34ba9d4dcb..ea54bed9437b 100644 --- a/contrib/libcbor/README.md +++ b/contrib/libcbor/README.md @@ -1,16 +1,15 @@ # [libcbor](https://github.com/PJK/libcbor) [![CircleCI](https://circleci.com/gh/PJK/libcbor/tree/master.svg?style=svg)](https://circleci.com/gh/PJK/libcbor/tree/master) -[![Build status](https://ci.appveyor.com/api/projects/status/8kkmvmefelsxp5u2?svg=true)](https://ci.appveyor.com/project/PJK/libcbor) [![Documentation Status](https://readthedocs.org/projects/libcbor/badge/?version=latest)](https://readthedocs.org/projects/libcbor/?badge=latest) [![latest packaged version(s)](https://repology.org/badge/latest-versions/libcbor.svg)](https://repology.org/project/libcbor/versions) [![codecov](https://codecov.io/gh/PJK/libcbor/branch/master/graph/badge.svg)](https://codecov.io/gh/PJK/libcbor) -**libcbor** is a C library for parsing and generating [CBOR](https://tools.ietf.org/html/rfc7049), the general-purpose schema-less binary data format. +**libcbor** is a C library for parsing and generating [CBOR](https://cbor.io/), the general-purpose schema-less binary data format. ## Main features - - Complete RFC conformance - - Robust C99 implementation + - Complete [IETF RFC 8949 (STD 94)](https://www.rfc-editor.org/info/std94) conformance + - Robust platform-independent C99 implementation - Layered architecture offers both control and convenience - Flexible memory management - No shared global state - threading friendly diff --git a/contrib/libcbor/appveyor.yml b/contrib/libcbor/appveyor.yml deleted file mode 100644 index 6a0cca219b92..000000000000 --- a/contrib/libcbor/appveyor.yml +++ /dev/null @@ -1,14 +0,0 @@ -image: Visual Studio 2022 -version: '{build}' -platform: x64 - -skip_branch_with_pr: true - -before_build: -- cmake -H. -Bbuild - -build_script: -- if "%APPVEYOR_REPO_TAG%"=="true" (set CONFIGURATION=RelWithDebInfo) else (set CONFIGURATION=Debug) -- cmake --build build --config "%CONFIGURATION%" - -# TODO enable CMocka tests, maybe package the binaries diff --git a/contrib/libcbor/doc/source/api/item_types.rst b/contrib/libcbor/doc/source/api/item_types.rst index 1452b3e5f90e..1051b97ded7b 100644 --- a/contrib/libcbor/doc/source/api/item_types.rst +++ b/contrib/libcbor/doc/source/api/item_types.rst @@ -1,7 +1,7 @@ Types of items =============================================== -Every :type:`cbor_item_t` has a :type:`cbor_type` associated with it - these constants correspond to the types specified by the `CBOR standard <http://tools.ietf.org/html/rfc7049>`_: +Every :type:`cbor_item_t` has a :type:`cbor_type` associated with it - these constants correspond to the types specified by the `CBOR standard <https://www.rfc-editor.org/info/std94>`_: .. doxygenenum:: cbor_type diff --git a/contrib/libcbor/doc/source/conf.py b/contrib/libcbor/doc/source/conf.py index 585efc8a436f..0eee7103bb5a 100644 --- a/contrib/libcbor/doc/source/conf.py +++ b/contrib/libcbor/doc/source/conf.py @@ -33,7 +33,8 @@ extensions = [ 'breathe', 'sphinx.ext.mathjax', 'sphinx.ext.autodoc', - 'sphinx.ext.ifconfig' + 'sphinx.ext.ifconfig', + 'sphinx_rtd_theme' ] import subprocess, os @@ -76,8 +77,8 @@ copyright = '2014 - 2020, Pavel Kalvoda' # built documents. # # The short X.Y version. -version = '0.10' -release = '0.10.2' +version = '0.11' +release = '0.11.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -127,7 +128,7 @@ pygments_style = 'sphinx' # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'default' +html_theme = 'sphinx_rtd_theme' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -285,12 +286,3 @@ texinfo_documents = [ # If true, do not generate a @detailmenu in the "Top" node's menu. #texinfo_no_detailmenu = False - - -if not on_rtd: # only import and set the theme if we're building docs locally - import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] - -# otherwise, readthedocs.org uses their theme by default, so no need to specify it - diff --git a/contrib/libcbor/doc/source/development.rst b/contrib/libcbor/doc/source/development.rst index 13e91ef25762..0b0ac21007ed 100644 --- a/contrib/libcbor/doc/source/development.rst +++ b/contrib/libcbor/doc/source/development.rst @@ -22,15 +22,15 @@ everywhere. Goals ~~~~~~~~~~~~~~~~~~~~~~ -RFC-conformance and full feature support -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Standard conformance and full feature support +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Anything the standard allows, libcbor can do. **Why?** Because conformance and interoperability is the point of defining standards. Clients expect the support to be feature-complete and there is no significant complexity reduction that can be achieved by slightly -cutting corners, which means that the incremental cost of full RFC support is +cutting corners, which means that the incremental cost of full [CBOR standard](https://www.rfc-editor.org/info/std94) support is comparatively small over "almost-conformance" seen in many alternatives. diff --git a/contrib/libcbor/doc/source/index.rst b/contrib/libcbor/doc/source/index.rst index 79293e798c3b..d3d62cf75c41 100644 --- a/contrib/libcbor/doc/source/index.rst +++ b/contrib/libcbor/doc/source/index.rst @@ -9,7 +9,7 @@ Overview Main features - - Complete RFC conformance [#]_ + - Complete `IETF RFC 8949 (STD 94) <https://www.rfc-editor.org/info/std94>`_ conformance [#]_ - Robust C99 implementation - Layered architecture offers both control and convenience - Flexible memory management @@ -19,7 +19,7 @@ Main features - Extensive documentation and test suite - No runtime dependencies, small footprint -.. [#] See :doc:`rfc_conformance` +.. [#] See :doc:`standard_conformance` .. [#] With the exception of custom memory allocators (see :doc:`api/item_reference_counting`) @@ -31,9 +31,9 @@ Contents using api tests - rfc_conformance + standard_conformance internal changelog development -.. _CBOR: http://tools.ietf.org/html/rfc7049 +.. _CBOR: https://www.rfc-editor.org/info/std94 diff --git a/contrib/libcbor/doc/source/internal.rst b/contrib/libcbor/doc/source/internal.rst index 2c62a82b2329..e30cb11dffa1 100644 --- a/contrib/libcbor/doc/source/internal.rst +++ b/contrib/libcbor/doc/source/internal.rst @@ -6,7 +6,7 @@ Internal workings of *libcbor* are mostly derived from the specification. The pu Terminology --------------- === ====================== ======================================================================================================================================== -MTB Major Type Byte http://tools.ietf.org/html/rfc7049#section-2.1 +MTB Major Type Byte https://www.rfc-editor.org/rfc/rfc8949.html#section-3.1 --- ---------------------- ---------------------------------------------------------------------------------------------------------------------------------------- DST Dynamically Sized Type Type whose storage requirements cannot be determined @@ -32,7 +32,7 @@ and also borrowing from General notes on the API design -------------------------------- -The API design has two main driving priciples: +The API design has two main driving principles: 1. Let the client manage the memory as much as possible 2. Behave exactly as specified by the standard diff --git a/contrib/libcbor/doc/source/requirements.txt b/contrib/libcbor/doc/source/requirements.txt index a82e34e58ad2..502d79cc62e6 100644 --- a/contrib/libcbor/doc/source/requirements.txt +++ b/contrib/libcbor/doc/source/requirements.txt @@ -1,31 +1,31 @@ -alabaster==0.7.12 -Babel==2.9.1 -breathe==4.33.1 -certifi==2022.12.7 -charset-normalizer==2.0.12 -colorama==0.4.4 -docutils==0.17.1 -idna==3.3 -imagesize==1.3.0 -importlib-metadata==4.11.3 -Jinja2==3.0.3 +alabaster==0.7.13 +Babel==2.13.1 +breathe==4.35.0 +certifi==2023.11.17 +charset-normalizer==3.3.2 +colorama==0.4.6 +docutils==0.18.1 +idna==3.4 +imagesize==1.4.1 +importlib-metadata==6.8.0 +Jinja2==3.1.2 livereload==2.6.3 -MarkupSafe==2.1.1 -packaging==21.3 -Pygments==2.11.2 -pyparsing==3.0.7 +MarkupSafe==2.1.3 +packaging==23.2 +Pygments==2.16.1 +pyparsing==3.1.1 pytz==2021.3 -requests==2.27.1 +requests==2.31.0 snowballstemmer==2.2.0 -Sphinx==4.4.0 +Sphinx==7.2.6 sphinx-autobuild==2021.3.14 -sphinx-rtd-theme==1.0.0 -sphinxcontrib-applehelp==1.0.2 -sphinxcontrib-devhelp==1.0.2 -sphinxcontrib-htmlhelp==2.0.0 +sphinx-rtd-theme==1.3.0 +sphinxcontrib-applehelp==1.0.7 +sphinxcontrib-devhelp==1.0.5 +sphinxcontrib-htmlhelp==2.0.4 sphinxcontrib-jsmath==1.0.1 -sphinxcontrib-qthelp==1.0.3 -sphinxcontrib-serializinghtml==1.1.5 -tornado==6.1 -urllib3==1.26.9 -zipp==3.7.0 +sphinxcontrib-qthelp==1.0.6 +sphinxcontrib-serializinghtml==1.1.9 +tornado==6.3.3 +urllib3==2.1.0 +zipp==3.17.0 diff --git a/contrib/libcbor/doc/source/rfc_conformance.rst b/contrib/libcbor/doc/source/standard_conformance.rst similarity index 73% rename from contrib/libcbor/doc/source/rfc_conformance.rst rename to contrib/libcbor/doc/source/standard_conformance.rst index 6848fbacd464..62965f0c4493 100644 --- a/contrib/libcbor/doc/source/rfc_conformance.rst +++ b/contrib/libcbor/doc/source/standard_conformance.rst @@ -1,13 +1,13 @@ -RFC conformance +IETF standard conformance ========================= -*libcbor* is, generally speaking, very faithful implementation of `RFC 7049 <https://tools.ietf.org/html/rfc7049>`_. There are, however, some limitations imposed by technical constraints. +*libcbor* is, generally speaking, a very faithful implementation of `IETF RFC 8949 (STD 94) <https://www.rfc-editor.org/info/std94>`_. There are, however, some limitations related to the numerical range and precision available in portable C99. Bytestring length ------------------- There is no explicit limitation of indefinite length byte strings. [#]_ *libcbor* will not handle byte strings with more chunks than the maximum value of :type:`size_t`. On any sane platform, such string would not fit in the memory anyway. It is, however, possible to process arbitrarily long strings and byte strings using the streaming decoder. -.. [#] https://tools.ietf.org/html/rfc7049#section-2.2.2 +.. [#] https://www.rfc-editor.org/rfc/rfc8949.html#section-3.2.3 "Half-precision" IEEE 754 floats --------------------------------- diff --git a/contrib/libcbor/examples/CMakeLists.txt b/contrib/libcbor/examples/CMakeLists.txt index eaf985ba32cd..b1f2ec290e7a 100644 --- a/contrib/libcbor/examples/CMakeLists.txt +++ b/contrib/libcbor/examples/CMakeLists.txt @@ -22,6 +22,10 @@ if(CJSON_FOUND) add_executable(cjson2cbor cjson2cbor.c) target_include_directories(cjson2cbor PUBLIC ${CJSON_INCLUDE_DIRS}) target_link_libraries(cjson2cbor cbor ${CJSON_LIBRARY}) + + add_executable(cbor2cjson cbor2cjson.c) + target_include_directories(cbor2cjson PUBLIC ${CJSON_INCLUDE_DIRS}) + target_link_libraries(cbor2cjson cbor ${CJSON_LIBRARY}) endif() file(COPY data DESTINATION .) diff --git a/contrib/libcbor/examples/bazel/third_party/libcbor/cbor/configuration.h b/contrib/libcbor/examples/bazel/third_party/libcbor/cbor/configuration.h index 3472cf49d8fe..ddf6b9dc5f2b 100644 --- a/contrib/libcbor/examples/bazel/third_party/libcbor/cbor/configuration.h +++ b/contrib/libcbor/examples/bazel/third_party/libcbor/cbor/configuration.h @@ -2,8 +2,8 @@ #define LIBCBOR_CONFIGURATION_H #define CBOR_MAJOR_VERSION 0 -#define CBOR_MINOR_VERSION 10 -#define CBOR_PATCH_VERSION 2 +#define CBOR_MINOR_VERSION 11 +#define CBOR_PATCH_VERSION 0 #define CBOR_BUFFER_GROWTH 2 #define CBOR_MAX_STACK_SIZE 2048 diff --git a/contrib/libcbor/examples/cbor2cjson.c b/contrib/libcbor/examples/cbor2cjson.c new file mode 100644 index 000000000000..99ddc9ee09e1 --- /dev/null +++ b/contrib/libcbor/examples/cbor2cjson.c @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com> + * + * libcbor is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ + +#include <cjson/cJSON.h> +#include <stdio.h> +#include <string.h> + +#include "cbor.h" + +void usage(void) { + printf("Usage: cbor2cjson [input file]\n"); + exit(1); +} + +cJSON* cbor_to_cjson(cbor_item_t* item) { + switch (cbor_typeof(item)) { + case CBOR_TYPE_UINT: + return cJSON_CreateNumber(cbor_get_int(item)); + case CBOR_TYPE_NEGINT: + return cJSON_CreateNumber(-1 - cbor_get_int(item)); + case CBOR_TYPE_BYTESTRING: + // cJSON only handles null-terminated string -- binary data would have to + // be escaped + return cJSON_CreateString("Unsupported CBOR item: Bytestring"); + case CBOR_TYPE_STRING: + if (cbor_string_is_definite(item)) { + // cJSON only handles null-terminated string + char* null_terminated_string = malloc(cbor_string_length(item) + 1); + memcpy(null_terminated_string, cbor_string_handle(item), + cbor_string_length(item)); + null_terminated_string[cbor_string_length(item)] = 0; + cJSON* result = cJSON_CreateString(null_terminated_string); + free(null_terminated_string); + return result; + } + return cJSON_CreateString("Unsupported CBOR item: Chunked string"); + case CBOR_TYPE_ARRAY: { + cJSON* result = cJSON_CreateArray(); + for (size_t i = 0; i < cbor_array_size(item); i++) { + cJSON_AddItemToArray(result, cbor_to_cjson(cbor_array_get(item, i))); + } + return result; + } + case CBOR_TYPE_MAP: { + cJSON* result = cJSON_CreateObject(); + for (size_t i = 0; i < cbor_map_size(item); i++) { + char* key = malloc(128); + snprintf(key, 128, "Surrogate key %zu", i); + // JSON only support string keys + if (cbor_isa_string(cbor_map_handle(item)[i].key) && + cbor_string_is_definite(cbor_map_handle(item)[i].key)) { + size_t key_length = cbor_string_length(cbor_map_handle(item)[i].key); + if (key_length > 127) key_length = 127; + // Null-terminated madness + memcpy(key, cbor_string_handle(cbor_map_handle(item)[i].key), + key_length); + key[key_length] = 0; + } + + cJSON_AddItemToObject(result, key, + cbor_to_cjson(cbor_map_handle(item)[i].value)); + free(key); + } + return result; + } + case CBOR_TYPE_TAG: + return cJSON_CreateString("Unsupported CBOR item: Tag"); + case CBOR_TYPE_FLOAT_CTRL: + if (cbor_float_ctrl_is_ctrl(item)) { + if (cbor_is_bool(item)) return cJSON_CreateBool(cbor_get_bool(item)); + if (cbor_is_null(item)) return cJSON_CreateNull(); + return cJSON_CreateString("Unsupported CBOR item: Control value"); + } + return cJSON_CreateNumber(cbor_float_get_float(item)); + } + + return cJSON_CreateNull(); +} + +/* + * Reads CBOR data from a file and outputs JSON using cJSON + * $ ./examples/cbor2cjson examples/data/nested_array.cbor + */ + +int main(int argc, char* argv[]) { + if (argc != 2) usage(); + FILE* f = fopen(argv[1], "rb"); + if (f == NULL) usage(); + fseek(f, 0, SEEK_END); + size_t length = (size_t)ftell(f); + fseek(f, 0, SEEK_SET); + unsigned char* buffer = malloc(length); + fread(buffer, length, 1, f); + + /* Assuming `buffer` contains `length` bytes of input data */ + struct cbor_load_result result; + cbor_item_t* item = cbor_load(buffer, length, &result); + free(buffer); + + if (result.error.code != CBOR_ERR_NONE) { + printf( + "There was an error while reading the input near byte %zu (read %zu " + "bytes in total): ", + result.error.position, result.read); + exit(1); + } + + cJSON* cjson_item = cbor_to_cjson(item); + char* json_string = cJSON_Print(cjson_item); + printf("%s\n", json_string); + free(json_string); + fflush(stdout); + + /* Deallocate the result */ + cbor_decref(&item); + cJSON_Delete(cjson_item); + + fclose(f); +} diff --git a/contrib/libcbor/examples/cjson2cbor.c b/contrib/libcbor/examples/cjson2cbor.c index eae78e1cf7a6..b67439902442 100644 --- a/contrib/libcbor/examples/cjson2cbor.c +++ b/contrib/libcbor/examples/cjson2cbor.c @@ -7,7 +7,7 @@ /** * This code demonstrates how cJSON (https://github.com/DaveGamble/cJSON) - * callbacks can be used in conjuction with the streaming parser to translate + * callbacks can be used in conjunction with the streaming parser to translate * JSON to CBOR. Please note that cbor_builder_* APIs are internal and thus * subject to change. * @@ -111,7 +111,7 @@ void cjson_cbor_stream_decode(cJSON *source, } void usage(void) { - printf("Usage: cjson [input JSON file]\n"); + printf("Usage: cjson2cbor [input JSON file]\n"); exit(1); } diff --git a/contrib/libcbor/examples/data/all_types.cbor b/contrib/libcbor/examples/data/all_types.cbor new file mode 100644 index 000000000000..00d66a0e667e Binary files /dev/null and b/contrib/libcbor/examples/data/all_types.cbor differ diff --git a/contrib/libcbor/examples/readfile.c b/contrib/libcbor/examples/readfile.c index 3f8db6152800..c6f4a3342d08 100644 --- a/contrib/libcbor/examples/readfile.c +++ b/contrib/libcbor/examples/readfile.c @@ -58,7 +58,7 @@ int main(int argc, char* argv[]) { case CBOR_ERR_SYNTAXERROR: { printf( "Syntactically malformed data -- see " - "http://tools.ietf.org/html/rfc7049\n"); + "https://www.rfc-editor.org/info/std94\n"); break; } case CBOR_ERR_NONE: { diff --git a/contrib/libcbor/oss-fuzz/build.sh b/contrib/libcbor/oss-fuzz/build.sh index 10853a398734..e7b1df3ada0a 100755 --- a/contrib/libcbor/oss-fuzz/build.sh +++ b/contrib/libcbor/oss-fuzz/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash -eu +#!/bin/bash -eux # Copyright 2019 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/contrib/libcbor/src/CMakeLists.txt b/contrib/libcbor/src/CMakeLists.txt index 72a0c901556d..e9312395db25 100644 --- a/contrib/libcbor/src/CMakeLists.txt +++ b/contrib/libcbor/src/CMakeLists.txt @@ -1,6 +1,5 @@ set(SOURCES cbor.c allocators.c cbor/streaming.c cbor/internal/encoders.c cbor/internal/builder_callbacks.c cbor/internal/loaders.c cbor/internal/memory_utils.c cbor/internal/stack.c cbor/internal/unicode.c cbor/encoding.c cbor/serialization.c cbor/arrays.c cbor/common.c cbor/floats_ctrls.c cbor/bytestrings.c cbor/callbacks.c cbor/strings.c cbor/maps.c cbor/tags.c cbor/ints.c) -include(GNUInstallDirs) include(JoinPaths) include(CheckFunctionExists) set(CMAKE_SKIP_BUILD_RPATH FALSE) @@ -49,3 +48,23 @@ install(FILES cbor.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libcbor.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + +include(CMakePackageConfigHelpers) +configure_package_config_file( + libcborConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/libcborConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libcbor + PATH_VARS CMAKE_INSTALL_INCLUDEDIR +) +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/libcborConfigVersion.cmake + VERSION ${CBOR_VERSION} + COMPATIBILITY SameMajorVersion +) +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/libcborConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/libcborConfigVersion.cmake + DESTINATION + ${CMAKE_INSTALL_LIBDIR}/cmake/libcbor + ) diff --git a/contrib/libcbor/src/cbor.c b/contrib/libcbor/src/cbor.c index 626ddddaecfc..a8b4bcd7a080 100644 --- a/contrib/libcbor/src/cbor.c +++ b/contrib/libcbor/src/cbor.c @@ -9,6 +9,7 @@ #include "cbor/internal/builder_callbacks.h" #include "cbor/internal/loaders.h" +#pragma clang diagnostic push cbor_item_t *cbor_load(cbor_data source, size_t source_size, struct cbor_load_result *result) { /* Context stack */ @@ -289,7 +290,6 @@ cbor_item_t *cbor_copy(cbor_item_t *item) { #include <inttypes.h> #include <locale.h> -#include <stdlib.h> #include <wchar.h> #define __STDC_FORMAT_MACROS @@ -301,89 +301,105 @@ static int _pow(int b, int ex) { return res; } +static void _cbor_type_marquee(FILE *out, char *label, int indent) { + fprintf(out, "%*.*s[%s] ", indent, indent, " ", label); +} + static void _cbor_nested_describe(cbor_item_t *item, FILE *out, int indent) { - setlocale(LC_ALL, ""); + const int indent_offset = 4; switch (cbor_typeof(item)) { case CBOR_TYPE_UINT: { - fprintf(out, "%*s[CBOR_TYPE_UINT] ", indent, " "); + _cbor_type_marquee(out, "CBOR_TYPE_UINT", indent); fprintf(out, "Width: %dB, ", _pow(2, cbor_int_get_width(item))); fprintf(out, "Value: %" PRIu64 "\n", cbor_get_int(item)); break; } case CBOR_TYPE_NEGINT: { - fprintf(out, "%*s[CBOR_TYPE_NEGINT] ", indent, " "); + _cbor_type_marquee(out, "CBOR_TYPE_NEGINT", indent); fprintf(out, "Width: %dB, ", _pow(2, cbor_int_get_width(item))); - fprintf(out, "Value: -%" PRIu64 " -1\n", cbor_get_int(item)); + fprintf(out, "Value: -%" PRIu64 " - 1\n", cbor_get_int(item)); break; } case CBOR_TYPE_BYTESTRING: { - fprintf(out, "%*s[CBOR_TYPE_BYTESTRING] ", indent, " "); + _cbor_type_marquee(out, "CBOR_TYPE_BYTESTRING", indent); if (cbor_bytestring_is_indefinite(item)) { - fprintf(out, "Indefinite, with %zu chunks:\n", + fprintf(out, "Indefinite, Chunks: %zu, Chunk data:\n", cbor_bytestring_chunk_count(item)); for (size_t i = 0; i < cbor_bytestring_chunk_count(item); i++) _cbor_nested_describe(cbor_bytestring_chunks_handle(item)[i], out, - indent + 4); + indent + indent_offset); } else { - fprintf(out, "Definite, length %zuB\n", cbor_bytestring_length(item)); + const unsigned char *data = cbor_bytestring_handle(item); + fprintf(out, "Definite, Length: %zuB, Data:\n", + cbor_bytestring_length(item)); + fprintf(out, "%*s", indent + indent_offset, " "); + for (size_t i = 0; i < cbor_bytestring_length(item); i++) + fprintf(out, "%02x", (int)(data[i] & 0xff)); + fprintf(out, "\n"); } break; } case CBOR_TYPE_STRING: { - fprintf(out, "%*s[CBOR_TYPE_STRING] ", indent, " "); + _cbor_type_marquee(out, "CBOR_TYPE_STRING", indent); if (cbor_string_is_indefinite(item)) { - fprintf(out, "Indefinite, with %zu chunks:\n", + fprintf(out, "Indefinite, Chunks: %zu, Chunk data:\n", cbor_string_chunk_count(item)); for (size_t i = 0; i < cbor_string_chunk_count(item); i++) _cbor_nested_describe(cbor_string_chunks_handle(item)[i], out, - indent + 4); + indent + indent_offset); } else { - fprintf(out, "Definite, length %zuB, %zu codepoints\n", + fprintf(out, "Definite, Length: %zuB, Codepoints: %zu, Data:\n", cbor_string_length(item), cbor_string_codepoint_count(item)); - /* Careful - this doesn't support multibyte characters! */ - /* Printing those is out of the scope of this demo :) */ - /* libICU is your friend */ - fprintf(out, "%*s", indent + 4, " "); - /* XXX: no null at the end -> confused vprintf */ - fwrite(cbor_string_handle(item), (int)cbor_string_length(item), 1, out); + fprintf(out, "%*s", indent + indent_offset, " "); + // Note: The string is not escaped, whitespace and control character + // will be printed in verbatim and take effect. + fwrite(cbor_string_handle(item), sizeof(unsigned char), + cbor_string_length(item), out); fprintf(out, "\n"); } break; } case CBOR_TYPE_ARRAY: { - fprintf(out, "%*s[CBOR_TYPE_ARRAY] ", indent, " "); + _cbor_type_marquee(out, "CBOR_TYPE_ARRAY", indent); if (cbor_array_is_definite(item)) { - fprintf(out, "Definite, size: %zu\n", cbor_array_size(item)); + fprintf(out, "Definite, Size: %zu, Contents:\n", cbor_array_size(item)); } else { - fprintf(out, "Indefinite, size: %zu\n", cbor_array_size(item)); + fprintf(out, "Indefinite, Size: %zu, Contents:\n", + cbor_array_size(item)); } for (size_t i = 0; i < cbor_array_size(item); i++) - _cbor_nested_describe(cbor_array_handle(item)[i], out, indent + 4); + _cbor_nested_describe(cbor_array_handle(item)[i], out, + indent + indent_offset); break; } case CBOR_TYPE_MAP: { - fprintf(out, "%*s[CBOR_TYPE_MAP] ", indent, " "); + _cbor_type_marquee(out, "CBOR_TYPE_MAP", indent); if (cbor_map_is_definite(item)) { - fprintf(out, "Definite, size: %zu\n", cbor_map_size(item)); + fprintf(out, "Definite, Size: %zu, Contents:\n", cbor_map_size(item)); } else { - fprintf(out, "Indefinite, size: %zu\n", cbor_map_size(item)); *** 885 LINES SKIPPED ***