Skip to content

Commit

Permalink
Pull latest tinycbor changes from the PR#83
Browse files Browse the repository at this point in the history
- Pull latest changes from intel/tinycbor#83
  • Loading branch information
vrahane committed Jan 30, 2018
1 parent 6baf3fa commit d046efd
Show file tree
Hide file tree
Showing 16 changed files with 556 additions and 112 deletions.
62 changes: 49 additions & 13 deletions ext/tinycbor/.travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,60 @@
language: cpp
os:
- linux
- osx
env:
- CFLAGS="-O0 -g" QMAKEFLAGS="-config debug" PATH=/opt/qt59/bin:/usr/local/opt/qt5/bin:$PATH
addons:
apt:
sources:
- sourceline: 'ppa:beineri/opt-qt593-trusty'
packages:
- qt59base valgrind
matrix:
include:
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- sourceline: 'ppa:beineri/opt-qt593-trusty'
packages:
- qt59base valgrind
- g++-7
env:
- QMAKESPEC=linux-g++
- EVAL="CC=gcc-7 && CXX=g++-7"
- CFLAGS="-Os"
- QMAKEFLAGS="-config release"
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-5.0
- sourceline: 'ppa:beineri/opt-qt593-trusty'
packages:
- qt59base
- clang-5.0
env:
- QMAKESPEC=linux-clang
- EVAL="CC=clang-5.0 && CXX=clang++-5.0"
- CFLAGS="-Oz"
- QMAKEFLAGS="-config release"
- os: osx
env:
- QMAKESPEC=macx-clang
- CFLAGS="-Oz"
- QMAKEFLAGS="-config debug"
- 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"
lib/libtinycbor.a
- size lib/libtinycbor.a
- make clean
- make -k
CFLAGS="$CFLAGS -O0 -g"
- make
CFLAGS="$CFLAGS"
all tests/Makefile
QMAKEFLAGS="$QMAKEFLAGS QMAKE_CXX=$CXX"
tests/Makefile
- cd tests && make check -k
TESTRUNNER=`which valgrind 2>/dev/null`
12 changes: 6 additions & 6 deletions ext/tinycbor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ prefix = /usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
libdir = $(exec_prefix)/lib
includedir = $(prefix)/src
includedir = $(prefix)/include
pkgconfigdir = $(libdir)/pkgconfig

CFLAGS = -Wall -Wextra
Expand All @@ -24,11 +24,11 @@ TINYCBOR_HEADERS = \
src/cbor.h \
src/cborjson.h \
src/cbor_enocoder_writer.h \
src/cbor_decoder_reader.h \
src/cbor_defs.h
src/cbor_decoder_reader.h
TINYCBOR_SOURCES = \
src/cborerrorstrings.c \
src/cborencoder.c \
src/cborencoder_close_container_checked.c \
src/cborparser.c \
src/cborparser_dup_string.c \
src/cborpretty.c \
Expand Down Expand Up @@ -61,7 +61,7 @@ BINLIBRARY=lib/libtinycbor.a
INSTALL_TARGETS += $(libdir)/libtinycbor.a
endif
INSTALL_TARGETS += $(pkgconfigdir)/tinycbor.pc
INSTALL_TARGETS += $(TINYCBOR_HEADERS:./%=$(includedir)/%)
INSTALL_TARGETS += $(TINYCBOR_HEADERS:src/%=$(includedir)/tinycbor/%)

# setup VPATH
MAKEFILE := $(lastword $(MAKEFILE_LIST))
Expand Down Expand Up @@ -176,7 +176,7 @@ $(DESTDIR)$(bindir)/%: bin/%
$(DESTDIR)$(pkgconfigdir)/%: %
$(INSTALL) -d $(@D)
$(INSTALL_DATA) $< $@
$(DESTDIR)$(includedir)/%: src/%
$(DESTDIR)$(includedir)/tinycbor/%: src/%
$(INSTALL) -d $(@D)
$(INSTALL_DATA) $< $@

Expand Down Expand Up @@ -221,7 +221,7 @@ tag: distcheck
.PHONY: docs dist distcheck release
.SECONDARY:

cflags := $(CPPFLAGS) -I$(SRCDIR)/src
cflags := $(CPPFLAGS) -I$(SRCDIR)src
cflags += -DTINYCBOR_VERSION_SUFFIX=\"$(DIRTYSRC)\"
cflags += -std=c99 $(CFLAGS)
%.o: %.c
Expand Down
227 changes: 224 additions & 3 deletions ext/tinycbor/src/cbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

#include "cbor_buf_writer.h"
#include "cbor_buf_reader.h"
#include "cbor_defs.h"
#include "tinycbor-version.h"

#define TINYCBOR_VERSION ((TINYCBOR_VERSION_MAJOR << 16) | (TINYCBOR_VERSION_MINOR << 8) | TINYCBOR_VERSION_PATCH)
Expand All @@ -47,6 +46,161 @@ extern "C" {
#include <stdbool.h>
#endif

#ifndef SIZE_MAX
/* Some systems fail to define SIZE_MAX in <stdint.h>, even though C99 requires it...
* Conversion from signed to unsigned is defined in 6.3.1.3 (Signed and unsigned integers) p2,
* which says: "the value is converted by repeatedly adding or subtracting one more than the
* maximum value that can be represented in the new type until the value is in the range of the
* new type."
* So -1 gets converted to size_t by adding SIZE_MAX + 1, which results in SIZE_MAX.
*/
# define SIZE_MAX ((size_t)-1)
#endif

#ifndef CBOR_API
# define CBOR_API
#endif
#ifndef CBOR_PRIVATE_API
# define CBOR_PRIVATE_API
#endif
#ifndef CBOR_INLINE_API
# if defined(__cplusplus)
# define CBOR_INLINE inline
# define CBOR_INLINE_API inline
# else
# define CBOR_INLINE_API static CBOR_INLINE
# if defined(_MSC_VER)
# define CBOR_INLINE __inline
# elif defined(__GNUC__)
# define CBOR_INLINE __inline__
# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
# define CBOR_INLINE inline
# else
# define CBOR_INLINE
# endif
# endif
#endif

typedef enum CborType {
CborIntegerType = 0x00,
CborByteStringType = 0x40,
CborTextStringType = 0x60,
CborArrayType = 0x80,
CborMapType = 0xa0,
CborTagType = 0xc0,
CborSimpleType = 0xe0,
CborBooleanType = 0xf5,
CborNullType = 0xf6,
CborUndefinedType = 0xf7,
CborHalfFloatType = 0xf9,
CborFloatType = 0xfa,
CborDoubleType = 0xfb,

CborInvalidType = 0xff /* equivalent to the break byte, so it will never be used */
} CborType;

typedef uint64_t CborTag;
typedef enum CborKnownTags {
CborDateTimeStringTag = 0,
CborUnixTime_tTag = 1,
CborPositiveBignumTag = 2,
CborNegativeBignumTag = 3,
CborDecimalTag = 4,
CborBigfloatTag = 5,
CborCOSE_Encrypt0Tag = 16,
CborCOSE_Mac0Tag = 17,
CborCOSE_Sign1Tag = 18,
CborExpectedBase64urlTag = 21,
CborExpectedBase64Tag = 22,
CborExpectedBase16Tag = 23,
CborEncodedCborTag = 24,
CborUrlTag = 32,
CborBase64urlTag = 33,
CborBase64Tag = 34,
CborRegularExpressionTag = 35,
CborMimeMessageTag = 36,
CborCOSE_EncryptTag = 96,
CborCOSE_MacTag = 97,
CborCOSE_SignTag = 98,
CborSignatureTag = 55799
} CborKnownTags;

/* #define the constants so we can check with #ifdef */
#define CborDateTimeStringTag CborDateTimeStringTag
#define CborUnixTime_tTag CborUnixTime_tTag
#define CborPositiveBignumTag CborPositiveBignumTag
#define CborNegativeBignumTag CborNegativeBignumTag
#define CborDecimalTag CborDecimalTag
#define CborBigfloatTag CborBigfloatTag
#define CborCOSE_Encrypt0Tag CborCOSE_Encrypt0Tag
#define CborCOSE_Mac0Tag CborCOSE_Mac0Tag
#define CborCOSE_Sign1Tag CborCOSE_Sign1Tag
#define CborExpectedBase64urlTag CborExpectedBase64urlTag
#define CborExpectedBase64Tag CborExpectedBase64Tag
#define CborExpectedBase16Tag CborExpectedBase16Tag
#define CborEncodedCborTag CborEncodedCborTag
#define CborUrlTag CborUrlTag
#define CborBase64urlTag CborBase64urlTag
#define CborBase64Tag CborBase64Tag
#define CborRegularExpressionTag CborRegularExpressionTag
#define CborMimeMessageTag CborMimeMessageTag
#define CborCOSE_EncryptTag CborCOSE_EncryptTag
#define CborCOSE_MacTag CborCOSE_MacTag
#define CborCOSE_SignTag CborCOSE_SignTag
#define CborSignatureTag CborSignatureTag

/* Error API */

typedef enum CborError {
CborNoError = 0,

/* errors in all modes */
CborUnknownError,
CborErrorUnknownLength, /* request for length in array, map, or string with indeterminate length */
CborErrorAdvancePastEOF,
CborErrorIO,

/* parser errors streaming errors */
CborErrorGarbageAtEnd = 256,
CborErrorUnexpectedEOF,
CborErrorUnexpectedBreak,
CborErrorUnknownType, /* can only heppen in major type 7 */
CborErrorIllegalType, /* type not allowed here */
CborErrorIllegalNumber,
CborErrorIllegalSimpleType, /* types of value less than 32 encoded in two bytes */

/* parser errors in strict mode parsing only */
CborErrorUnknownSimpleType = 512,
CborErrorUnknownTag,
CborErrorInappropriateTagForType,
CborErrorDuplicateObjectKeys,
CborErrorInvalidUtf8TextString,
CborErrorExcludedType,
CborErrorExcludedValue,
CborErrorImproperValue,
CborErrorOverlongEncoding,
CborErrorMapKeyNotString,
CborErrorMapNotSorted,
CborErrorMapKeysNotUnique,

/* encoder errors */
CborErrorTooManyItems = 768,
CborErrorTooFewItems,

/* internal implementation errors */
CborErrorDataTooLarge = 1024,
CborErrorNestingTooDeep,
CborErrorUnsupportedType,

/* errors in converting to JSON */
CborErrorJsonObjectKeyIsAggregate = 1280,
CborErrorJsonObjectKeyNotString,
CborErrorJsonNotImplemented,

CborErrorOutOfMemory = (int) (~0U / 2 + 1),
CborErrorInternalError = (int) (~0U / 2) /* INT_MAX on two's complement machines */
} CborError;

CBOR_API const char *cbor_error_string(CborError error);

/* Encoder API */
Expand All @@ -57,13 +211,14 @@ struct CborEncoder
#ifndef NO_DFLT_WRITER
struct cbor_buf_writer wr;
#endif
size_t added;
size_t container_size;
size_t remaining;
int flags;
};

typedef struct CborEncoder CborEncoder;

static const size_t CborIndefiniteLength = SIZE_MAX;

#ifndef NO_DFLT_WRITER
CBOR_API void cbor_encoder_init(CborEncoder *encoder, uint8_t *buffer, size_t size, int flags);
#endif
Expand Down Expand Up @@ -100,6 +255,16 @@ CBOR_API CborError cbor_encoder_close_container(CborEncoder *encoder, const Cbor
CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *encoder, const CborEncoder *containerEncoder);

/* Parser API */

enum CborParserIteratorFlags
{
CborIteratorFlag_IntegerValueTooLarge = 0x01,
CborIteratorFlag_NegativeInteger = 0x02,
CborIteratorFlag_IteratingStringChunks = 0x02,
CborIteratorFlag_UnknownLength = 0x04,
CborIteratorFlag_ContainerIsMap = 0x20
};

struct CborParser
{
#ifndef NO_DFLT_READER
Expand Down Expand Up @@ -362,10 +527,65 @@ CBOR_INLINE_API CborError cbor_value_get_double(const CborValue *value, double *
}

/* Validation API */

enum CborValidationFlags {
/* Bit mapping:
* bits 0-7 (8 bits): canonical format
* bits 8-11 (4 bits): canonical format & strict mode
* bits 12-20 (8 bits): strict mode
* bits 21-31 (10 bits): other
*/

CborValidateShortestIntegrals = 0x0001,
CborValidateShortestFloatingPoint = 0x0002,
CborValidateShortestNumbers = CborValidateShortestIntegrals | CborValidateShortestFloatingPoint,
CborValidateNoIndeterminateLength = 0x0100,
CborValidateMapIsSorted = 0x0200 | CborValidateNoIndeterminateLength,

CborValidateCanonicalFormat = 0x0fff,

CborValidateMapKeysAreUnique = 0x1000 | CborValidateMapIsSorted,
CborValidateTagUse = 0x2000,
CborValidateUtf8 = 0x4000,

CborValidateStrictMode = 0xfff00,

CborValidateMapKeysAreString = 0x100000,
CborValidateNoUndefined = 0x200000,
CborValidateNoTags = 0x400000,
CborValidateFiniteFloatingPoint = 0x800000,
/* unused = 0x1000000, */
/* unused = 0x2000000, */

CborValidateNoUnknownSimpleTypesSA = 0x4000000,
CborValidateNoUnknownSimpleTypes = 0x8000000 | CborValidateNoUnknownSimpleTypesSA,
CborValidateNoUnknownTagsSA = 0x10000000,
CborValidateNoUnknownTagsSR = 0x20000000 | CborValidateNoUnknownTagsSA,
CborValidateNoUnknownTags = 0x40000000 | CborValidateNoUnknownTagsSR,

CborValidateCompleteData = (int)0x80000000,

CborValidateStrictest = (int)~0U,
CborValidateBasic = 0
};

CBOR_API CborError cbor_value_validate(const CborValue *it, int flags);

/* Human-readable (dump) API */

enum CborPrettyFlags {
CborPrettyNumericEncodingIndicators = 0x01,
CborPrettyTextualEncodingIndicators = 0,

CborPrettyIndicateIndetermineLength = 0x02,
CborPrettyIndicateOverlongNumbers = 0x04,

CborPrettyShowStringFragments = 0x100,
CborPrettyMergeStringFragments = 0,

CborPrettyDefaultFlags = CborPrettyIndicateIndetermineLength
};

typedef CborError (*CborStreamFunction)(void *token, const char *fmt, ...)
#ifdef __GNUC__
__attribute__((__format__(printf, 2, 3)))
Expand All @@ -390,3 +610,4 @@ CBOR_INLINE_API CborError cbor_value_to_pretty(FILE *out, const CborValue *value
#endif

#endif /* CBOR_H */

Loading

0 comments on commit d046efd

Please sign in to comment.