Skip to content

Commit d046efd

Browse files
committed
Pull latest tinycbor changes from the PR#83
- Pull latest changes from intel/tinycbor#83
1 parent 6baf3fa commit d046efd

File tree

16 files changed

+556
-112
lines changed

16 files changed

+556
-112
lines changed

ext/tinycbor/.travis.yml

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,60 @@
11
language: cpp
2-
os:
3-
- linux
4-
- osx
5-
env:
6-
- CFLAGS="-O0 -g" QMAKEFLAGS="-config debug" PATH=/opt/qt59/bin:/usr/local/opt/qt5/bin:$PATH
7-
addons:
8-
apt:
9-
sources:
10-
- sourceline: 'ppa:beineri/opt-qt593-trusty'
11-
packages:
12-
- qt59base valgrind
2+
matrix:
3+
include:
4+
- os: linux
5+
addons:
6+
apt:
7+
sources:
8+
- ubuntu-toolchain-r-test
9+
- sourceline: 'ppa:beineri/opt-qt593-trusty'
10+
packages:
11+
- qt59base valgrind
12+
- g++-7
13+
env:
14+
- QMAKESPEC=linux-g++
15+
- EVAL="CC=gcc-7 && CXX=g++-7"
16+
- CFLAGS="-Os"
17+
- QMAKEFLAGS="-config release"
18+
- os: linux
19+
addons:
20+
apt:
21+
sources:
22+
- ubuntu-toolchain-r-test
23+
- llvm-toolchain-trusty-5.0
24+
- sourceline: 'ppa:beineri/opt-qt593-trusty'
25+
packages:
26+
- qt59base
27+
- clang-5.0
28+
env:
29+
- QMAKESPEC=linux-clang
30+
- EVAL="CC=clang-5.0 && CXX=clang++-5.0"
31+
- CFLAGS="-Oz"
32+
- QMAKEFLAGS="-config release"
33+
- os: osx
34+
env:
35+
- QMAKESPEC=macx-clang
36+
- CFLAGS="-Oz"
37+
- QMAKEFLAGS="-config debug"
38+
- PATH=/usr/local/opt/qt5/bin:$PATH
1339
install:
1440
- if [ "${TRAVIS_OS_NAME}" != "linux" ]; then
1541
brew update;
1642
brew install qt5;
1743
fi
1844
script:
45+
- PATH=`echo /opt/qt*/bin`:$PATH
46+
- eval "$EVAL"
1947
- make -s -f Makefile.configure configure | tee .config
48+
- make -k
49+
CFLAGS="$CFLAGS -march=native -g1 -Wall -Wextra -Werror"
50+
CPPFLAGS="-DNDEBUG"
51+
lib/libtinycbor.a
52+
- size lib/libtinycbor.a
53+
- make clean
54+
- make -k
55+
CFLAGS="$CFLAGS -O0 -g"
2056
- make
21-
CFLAGS="$CFLAGS"
22-
all tests/Makefile
57+
QMAKEFLAGS="$QMAKEFLAGS QMAKE_CXX=$CXX"
58+
tests/Makefile
2359
- cd tests && make check -k
2460
TESTRUNNER=`which valgrind 2>/dev/null`

ext/tinycbor/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ prefix = /usr/local
33
exec_prefix = $(prefix)
44
bindir = $(exec_prefix)/bin
55
libdir = $(exec_prefix)/lib
6-
includedir = $(prefix)/src
6+
includedir = $(prefix)/include
77
pkgconfigdir = $(libdir)/pkgconfig
88

99
CFLAGS = -Wall -Wextra
@@ -24,11 +24,11 @@ TINYCBOR_HEADERS = \
2424
src/cbor.h \
2525
src/cborjson.h \
2626
src/cbor_enocoder_writer.h \
27-
src/cbor_decoder_reader.h \
28-
src/cbor_defs.h
27+
src/cbor_decoder_reader.h
2928
TINYCBOR_SOURCES = \
3029
src/cborerrorstrings.c \
3130
src/cborencoder.c \
31+
src/cborencoder_close_container_checked.c \
3232
src/cborparser.c \
3333
src/cborparser_dup_string.c \
3434
src/cborpretty.c \
@@ -61,7 +61,7 @@ BINLIBRARY=lib/libtinycbor.a
6161
INSTALL_TARGETS += $(libdir)/libtinycbor.a
6262
endif
6363
INSTALL_TARGETS += $(pkgconfigdir)/tinycbor.pc
64-
INSTALL_TARGETS += $(TINYCBOR_HEADERS:./%=$(includedir)/%)
64+
INSTALL_TARGETS += $(TINYCBOR_HEADERS:src/%=$(includedir)/tinycbor/%)
6565

6666
# setup VPATH
6767
MAKEFILE := $(lastword $(MAKEFILE_LIST))
@@ -176,7 +176,7 @@ $(DESTDIR)$(bindir)/%: bin/%
176176
$(DESTDIR)$(pkgconfigdir)/%: %
177177
$(INSTALL) -d $(@D)
178178
$(INSTALL_DATA) $< $@
179-
$(DESTDIR)$(includedir)/%: src/%
179+
$(DESTDIR)$(includedir)/tinycbor/%: src/%
180180
$(INSTALL) -d $(@D)
181181
$(INSTALL_DATA) $< $@
182182

@@ -221,7 +221,7 @@ tag: distcheck
221221
.PHONY: docs dist distcheck release
222222
.SECONDARY:
223223

224-
cflags := $(CPPFLAGS) -I$(SRCDIR)/src
224+
cflags := $(CPPFLAGS) -I$(SRCDIR)src
225225
cflags += -DTINYCBOR_VERSION_SUFFIX=\"$(DIRTYSRC)\"
226226
cflags += -std=c99 $(CFLAGS)
227227
%.o: %.c

ext/tinycbor/src/cbor.h

Lines changed: 224 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
#include "cbor_buf_writer.h"
3838
#include "cbor_buf_reader.h"
39-
#include "cbor_defs.h"
4039
#include "tinycbor-version.h"
4140

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

49+
#ifndef SIZE_MAX
50+
/* Some systems fail to define SIZE_MAX in <stdint.h>, even though C99 requires it...
51+
* Conversion from signed to unsigned is defined in 6.3.1.3 (Signed and unsigned integers) p2,
52+
* which says: "the value is converted by repeatedly adding or subtracting one more than the
53+
* maximum value that can be represented in the new type until the value is in the range of the
54+
* new type."
55+
* So -1 gets converted to size_t by adding SIZE_MAX + 1, which results in SIZE_MAX.
56+
*/
57+
# define SIZE_MAX ((size_t)-1)
58+
#endif
59+
60+
#ifndef CBOR_API
61+
# define CBOR_API
62+
#endif
63+
#ifndef CBOR_PRIVATE_API
64+
# define CBOR_PRIVATE_API
65+
#endif
66+
#ifndef CBOR_INLINE_API
67+
# if defined(__cplusplus)
68+
# define CBOR_INLINE inline
69+
# define CBOR_INLINE_API inline
70+
# else
71+
# define CBOR_INLINE_API static CBOR_INLINE
72+
# if defined(_MSC_VER)
73+
# define CBOR_INLINE __inline
74+
# elif defined(__GNUC__)
75+
# define CBOR_INLINE __inline__
76+
# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
77+
# define CBOR_INLINE inline
78+
# else
79+
# define CBOR_INLINE
80+
# endif
81+
# endif
82+
#endif
83+
84+
typedef enum CborType {
85+
CborIntegerType = 0x00,
86+
CborByteStringType = 0x40,
87+
CborTextStringType = 0x60,
88+
CborArrayType = 0x80,
89+
CborMapType = 0xa0,
90+
CborTagType = 0xc0,
91+
CborSimpleType = 0xe0,
92+
CborBooleanType = 0xf5,
93+
CborNullType = 0xf6,
94+
CborUndefinedType = 0xf7,
95+
CborHalfFloatType = 0xf9,
96+
CborFloatType = 0xfa,
97+
CborDoubleType = 0xfb,
98+
99+
CborInvalidType = 0xff /* equivalent to the break byte, so it will never be used */
100+
} CborType;
101+
102+
typedef uint64_t CborTag;
103+
typedef enum CborKnownTags {
104+
CborDateTimeStringTag = 0,
105+
CborUnixTime_tTag = 1,
106+
CborPositiveBignumTag = 2,
107+
CborNegativeBignumTag = 3,
108+
CborDecimalTag = 4,
109+
CborBigfloatTag = 5,
110+
CborCOSE_Encrypt0Tag = 16,
111+
CborCOSE_Mac0Tag = 17,
112+
CborCOSE_Sign1Tag = 18,
113+
CborExpectedBase64urlTag = 21,
114+
CborExpectedBase64Tag = 22,
115+
CborExpectedBase16Tag = 23,
116+
CborEncodedCborTag = 24,
117+
CborUrlTag = 32,
118+
CborBase64urlTag = 33,
119+
CborBase64Tag = 34,
120+
CborRegularExpressionTag = 35,
121+
CborMimeMessageTag = 36,
122+
CborCOSE_EncryptTag = 96,
123+
CborCOSE_MacTag = 97,
124+
CborCOSE_SignTag = 98,
125+
CborSignatureTag = 55799
126+
} CborKnownTags;
127+
128+
/* #define the constants so we can check with #ifdef */
129+
#define CborDateTimeStringTag CborDateTimeStringTag
130+
#define CborUnixTime_tTag CborUnixTime_tTag
131+
#define CborPositiveBignumTag CborPositiveBignumTag
132+
#define CborNegativeBignumTag CborNegativeBignumTag
133+
#define CborDecimalTag CborDecimalTag
134+
#define CborBigfloatTag CborBigfloatTag
135+
#define CborCOSE_Encrypt0Tag CborCOSE_Encrypt0Tag
136+
#define CborCOSE_Mac0Tag CborCOSE_Mac0Tag
137+
#define CborCOSE_Sign1Tag CborCOSE_Sign1Tag
138+
#define CborExpectedBase64urlTag CborExpectedBase64urlTag
139+
#define CborExpectedBase64Tag CborExpectedBase64Tag
140+
#define CborExpectedBase16Tag CborExpectedBase16Tag
141+
#define CborEncodedCborTag CborEncodedCborTag
142+
#define CborUrlTag CborUrlTag
143+
#define CborBase64urlTag CborBase64urlTag
144+
#define CborBase64Tag CborBase64Tag
145+
#define CborRegularExpressionTag CborRegularExpressionTag
146+
#define CborMimeMessageTag CborMimeMessageTag
147+
#define CborCOSE_EncryptTag CborCOSE_EncryptTag
148+
#define CborCOSE_MacTag CborCOSE_MacTag
149+
#define CborCOSE_SignTag CborCOSE_SignTag
150+
#define CborSignatureTag CborSignatureTag
151+
152+
/* Error API */
153+
154+
typedef enum CborError {
155+
CborNoError = 0,
156+
157+
/* errors in all modes */
158+
CborUnknownError,
159+
CborErrorUnknownLength, /* request for length in array, map, or string with indeterminate length */
160+
CborErrorAdvancePastEOF,
161+
CborErrorIO,
162+
163+
/* parser errors streaming errors */
164+
CborErrorGarbageAtEnd = 256,
165+
CborErrorUnexpectedEOF,
166+
CborErrorUnexpectedBreak,
167+
CborErrorUnknownType, /* can only heppen in major type 7 */
168+
CborErrorIllegalType, /* type not allowed here */
169+
CborErrorIllegalNumber,
170+
CborErrorIllegalSimpleType, /* types of value less than 32 encoded in two bytes */
171+
172+
/* parser errors in strict mode parsing only */
173+
CborErrorUnknownSimpleType = 512,
174+
CborErrorUnknownTag,
175+
CborErrorInappropriateTagForType,
176+
CborErrorDuplicateObjectKeys,
177+
CborErrorInvalidUtf8TextString,
178+
CborErrorExcludedType,
179+
CborErrorExcludedValue,
180+
CborErrorImproperValue,
181+
CborErrorOverlongEncoding,
182+
CborErrorMapKeyNotString,
183+
CborErrorMapNotSorted,
184+
CborErrorMapKeysNotUnique,
185+
186+
/* encoder errors */
187+
CborErrorTooManyItems = 768,
188+
CborErrorTooFewItems,
189+
190+
/* internal implementation errors */
191+
CborErrorDataTooLarge = 1024,
192+
CborErrorNestingTooDeep,
193+
CborErrorUnsupportedType,
194+
195+
/* errors in converting to JSON */
196+
CborErrorJsonObjectKeyIsAggregate = 1280,
197+
CborErrorJsonObjectKeyNotString,
198+
CborErrorJsonNotImplemented,
199+
200+
CborErrorOutOfMemory = (int) (~0U / 2 + 1),
201+
CborErrorInternalError = (int) (~0U / 2) /* INT_MAX on two's complement machines */
202+
} CborError;
203+
50204
CBOR_API const char *cbor_error_string(CborError error);
51205

52206
/* Encoder API */
@@ -57,13 +211,14 @@ struct CborEncoder
57211
#ifndef NO_DFLT_WRITER
58212
struct cbor_buf_writer wr;
59213
#endif
60-
size_t added;
61-
size_t container_size;
214+
size_t remaining;
62215
int flags;
63216
};
64217

65218
typedef struct CborEncoder CborEncoder;
66219

220+
static const size_t CborIndefiniteLength = SIZE_MAX;
221+
67222
#ifndef NO_DFLT_WRITER
68223
CBOR_API void cbor_encoder_init(CborEncoder *encoder, uint8_t *buffer, size_t size, int flags);
69224
#endif
@@ -100,6 +255,16 @@ CBOR_API CborError cbor_encoder_close_container(CborEncoder *encoder, const Cbor
100255
CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *encoder, const CborEncoder *containerEncoder);
101256

102257
/* Parser API */
258+
259+
enum CborParserIteratorFlags
260+
{
261+
CborIteratorFlag_IntegerValueTooLarge = 0x01,
262+
CborIteratorFlag_NegativeInteger = 0x02,
263+
CborIteratorFlag_IteratingStringChunks = 0x02,
264+
CborIteratorFlag_UnknownLength = 0x04,
265+
CborIteratorFlag_ContainerIsMap = 0x20
266+
};
267+
103268
struct CborParser
104269
{
105270
#ifndef NO_DFLT_READER
@@ -362,10 +527,65 @@ CBOR_INLINE_API CborError cbor_value_get_double(const CborValue *value, double *
362527
}
363528

364529
/* Validation API */
530+
531+
enum CborValidationFlags {
532+
/* Bit mapping:
533+
* bits 0-7 (8 bits): canonical format
534+
* bits 8-11 (4 bits): canonical format & strict mode
535+
* bits 12-20 (8 bits): strict mode
536+
* bits 21-31 (10 bits): other
537+
*/
538+
539+
CborValidateShortestIntegrals = 0x0001,
540+
CborValidateShortestFloatingPoint = 0x0002,
541+
CborValidateShortestNumbers = CborValidateShortestIntegrals | CborValidateShortestFloatingPoint,
542+
CborValidateNoIndeterminateLength = 0x0100,
543+
CborValidateMapIsSorted = 0x0200 | CborValidateNoIndeterminateLength,
544+
545+
CborValidateCanonicalFormat = 0x0fff,
546+
547+
CborValidateMapKeysAreUnique = 0x1000 | CborValidateMapIsSorted,
548+
CborValidateTagUse = 0x2000,
549+
CborValidateUtf8 = 0x4000,
550+
551+
CborValidateStrictMode = 0xfff00,
552+
553+
CborValidateMapKeysAreString = 0x100000,
554+
CborValidateNoUndefined = 0x200000,
555+
CborValidateNoTags = 0x400000,
556+
CborValidateFiniteFloatingPoint = 0x800000,
557+
/* unused = 0x1000000, */
558+
/* unused = 0x2000000, */
559+
560+
CborValidateNoUnknownSimpleTypesSA = 0x4000000,
561+
CborValidateNoUnknownSimpleTypes = 0x8000000 | CborValidateNoUnknownSimpleTypesSA,
562+
CborValidateNoUnknownTagsSA = 0x10000000,
563+
CborValidateNoUnknownTagsSR = 0x20000000 | CborValidateNoUnknownTagsSA,
564+
CborValidateNoUnknownTags = 0x40000000 | CborValidateNoUnknownTagsSR,
565+
566+
CborValidateCompleteData = (int)0x80000000,
567+
568+
CborValidateStrictest = (int)~0U,
569+
CborValidateBasic = 0
570+
};
571+
365572
CBOR_API CborError cbor_value_validate(const CborValue *it, int flags);
366573

367574
/* Human-readable (dump) API */
368575

576+
enum CborPrettyFlags {
577+
CborPrettyNumericEncodingIndicators = 0x01,
578+
CborPrettyTextualEncodingIndicators = 0,
579+
580+
CborPrettyIndicateIndetermineLength = 0x02,
581+
CborPrettyIndicateOverlongNumbers = 0x04,
582+
583+
CborPrettyShowStringFragments = 0x100,
584+
CborPrettyMergeStringFragments = 0,
585+
586+
CborPrettyDefaultFlags = CborPrettyIndicateIndetermineLength
587+
};
588+
369589
typedef CborError (*CborStreamFunction)(void *token, const char *fmt, ...)
370590
#ifdef __GNUC__
371591
__attribute__((__format__(printf, 2, 3)))
@@ -390,3 +610,4 @@ CBOR_INLINE_API CborError cbor_value_to_pretty(FILE *out, const CborValue *value
390610
#endif
391611

392612
#endif /* CBOR_H */
613+

0 commit comments

Comments
 (0)