Archived
Merge remote-tracking branch 'origin/main' into HEAD
This commit is contained in:
+9
-1
@@ -1,3 +1,11 @@
|
||||
env:
|
||||
- BUILD_DOCS=false
|
||||
jobs:
|
||||
include:
|
||||
- # only build docs on main
|
||||
if: branch = main
|
||||
env: BUILD_DOCS=true
|
||||
|
||||
language: cpp
|
||||
matrix:
|
||||
include:
|
||||
@@ -81,4 +89,4 @@ script:
|
||||
(cd tests && make TESTARGS=-silent check -k
|
||||
TESTRUNNER=`which valgrind 2>/dev/null`)
|
||||
- make -s clean
|
||||
- ./scripts/update-docs.sh
|
||||
- ! [ $BUILD_DOCS ] || ./scripts/update-docs.sh
|
||||
|
||||
@@ -15,6 +15,8 @@ static uint8_t *readfile(const char *fname, size_t *size)
|
||||
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;
|
||||
@@ -23,13 +25,15 @@ static uint8_t *readfile(const char *fname, size_t *size)
|
||||
static void indent(int nestingLevel)
|
||||
{
|
||||
while (nestingLevel--)
|
||||
puts(" ");
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
static void dumpbytes(const uint8_t *buf, size_t len)
|
||||
{
|
||||
printf("\"");
|
||||
while (len--)
|
||||
printf("%02X ", *buf++);
|
||||
printf("\\x%02X", *buf++);
|
||||
printf("\"");
|
||||
}
|
||||
|
||||
static CborError dumprecursive(CborValue *it, int nestingLevel)
|
||||
@@ -85,7 +89,7 @@ static CborError dumprecursive(CborValue *it, int nestingLevel)
|
||||
err = cbor_value_dup_text_string(it, &buf, &n, it);
|
||||
if (err)
|
||||
return err; // parse error
|
||||
puts(buf);
|
||||
printf("\"%s\"\n", buf);
|
||||
free(buf);
|
||||
continue;
|
||||
}
|
||||
@@ -153,9 +157,9 @@ static CborError dumprecursive(CborValue *it, int nestingLevel)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc == 1) {
|
||||
if (argc != 2) {
|
||||
puts("simplereader <filename>");
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t length;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh -ex
|
||||
tuple="$TRAVIS_BRANCH${TRAVIS_TAG:+tag:$TRAVIS_TAG},$TRAVIS_PULL_REQUEST"
|
||||
case "$tuple" in
|
||||
dev,false|master,false|tag:*)
|
||||
dev,false|main,false|tag:*)
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
|
||||
+4
-4
@@ -244,10 +244,10 @@ CBOR_INLINE_API CborError cbor_encode_float(CborEncoder *encoder, float value)
|
||||
CBOR_INLINE_API CborError cbor_encode_double(CborEncoder *encoder, double value)
|
||||
{ return cbor_encode_floating_point(encoder, CborDoubleType, &value); }
|
||||
|
||||
CBOR_API CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEncoder, size_t length);
|
||||
CBOR_API CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder, size_t length);
|
||||
CBOR_API CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder);
|
||||
CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *encoder, const CborEncoder *containerEncoder);
|
||||
CBOR_API CborError cbor_encoder_create_array(CborEncoder *parentEncoder, CborEncoder *arrayEncoder, size_t length);
|
||||
CBOR_API CborError cbor_encoder_create_map(CborEncoder *parentEncoder, CborEncoder *mapEncoder, size_t length);
|
||||
CBOR_API CborError cbor_encoder_close_container(CborEncoder *parentEncoder, const CborEncoder *containerEncoder);
|
||||
CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *parentEncoder, const CborEncoder *containerEncoder);
|
||||
|
||||
CBOR_INLINE_API uint8_t *_cbor_encoder_get_buffer_pointer(const CborEncoder *encoder)
|
||||
{
|
||||
|
||||
+13
-13
@@ -482,7 +482,7 @@ static CborError create_container(CborEncoder *encoder, CborEncoder *container,
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a CBOR array in the CBOR stream provided by \a encoder and
|
||||
* Creates a CBOR array in the CBOR stream provided by \a parentEncoder and
|
||||
* initializes \a arrayEncoder so that items can be added to the array using
|
||||
* the CborEncoder functions. The array must be terminated by calling either
|
||||
* cbor_encoder_close_container() or cbor_encoder_close_container_checked()
|
||||
@@ -491,17 +491,17 @@ static CborError create_container(CborEncoder *encoder, CborEncoder *container,
|
||||
* The number of items inserted into the array must be exactly \a length items,
|
||||
* otherwise the stream is invalid. If the number of items is not known when
|
||||
* creating the array, the constant \ref CborIndefiniteLength may be passed as
|
||||
* length instead.
|
||||
* length instead, and an indefinite length array is created.
|
||||
*
|
||||
* \sa cbor_encoder_create_map
|
||||
*/
|
||||
CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEncoder, size_t length)
|
||||
CborError cbor_encoder_create_array(CborEncoder *parentEncoder, CborEncoder *arrayEncoder, size_t length)
|
||||
{
|
||||
return create_container(encoder, arrayEncoder, length, ArrayType << MajorTypeShift);
|
||||
return create_container(parentEncoder, arrayEncoder, length, ArrayType << MajorTypeShift);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a CBOR map in the CBOR stream provided by \a encoder and
|
||||
* Creates a CBOR map in the CBOR stream provided by \a parentEncoder and
|
||||
* initializes \a mapEncoder so that items can be added to the map using
|
||||
* the CborEncoder functions. The map must be terminated by calling either
|
||||
* cbor_encoder_close_container() or cbor_encoder_close_container_checked()
|
||||
@@ -510,7 +510,7 @@ CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEnco
|
||||
* The number of pair of items inserted into the map must be exactly \a length
|
||||
* items, otherwise the stream is invalid. If the number is not known
|
||||
* when creating the map, the constant \ref CborIndefiniteLength may be passed as
|
||||
* length instead.
|
||||
* length instead, and an indefinite length map is created.
|
||||
*
|
||||
* \b{Implementation limitation:} TinyCBOR cannot encode more than SIZE_MAX/2
|
||||
* key-value pairs in the stream. If the length \a length is larger than this
|
||||
@@ -519,11 +519,11 @@ CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEnco
|
||||
*
|
||||
* \sa cbor_encoder_create_array
|
||||
*/
|
||||
CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder, size_t length)
|
||||
CborError cbor_encoder_create_map(CborEncoder *parentEncoder, CborEncoder *mapEncoder, size_t length)
|
||||
{
|
||||
if (length != CborIndefiniteLength && length > SIZE_MAX / 2)
|
||||
return CborErrorDataTooLarge;
|
||||
return create_container(encoder, mapEncoder, length, MapType << MajorTypeShift);
|
||||
return create_container(parentEncoder, mapEncoder, length, MapType << MajorTypeShift);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -538,19 +538,19 @@ CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder,
|
||||
*
|
||||
* \sa cbor_encoder_create_array(), cbor_encoder_create_map()
|
||||
*/
|
||||
CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder)
|
||||
CborError cbor_encoder_close_container(CborEncoder *parentEncoder, const CborEncoder *containerEncoder)
|
||||
{
|
||||
// synchronise buffer state with that of the container
|
||||
encoder->end = containerEncoder->end;
|
||||
encoder->data = containerEncoder->data;
|
||||
parentEncoder->end = containerEncoder->end;
|
||||
parentEncoder->data = containerEncoder->data;
|
||||
|
||||
if (containerEncoder->flags & CborIteratorFlag_UnknownLength)
|
||||
return append_byte_to_buffer(encoder, BreakByte);
|
||||
return append_byte_to_buffer(parentEncoder, BreakByte);
|
||||
|
||||
if (containerEncoder->remaining != 1)
|
||||
return containerEncoder->remaining == 0 ? CborErrorTooManyItems : CborErrorTooFewItems;
|
||||
|
||||
if (!encoder->end)
|
||||
if (!parentEncoder->end)
|
||||
return CborErrorOutOfMemory; /* keep the state */
|
||||
|
||||
return CborNoError;
|
||||
|
||||
+10
-1
@@ -179,6 +179,10 @@ static CborError dump_bytestring_base16(char **result, CborValue *it)
|
||||
|
||||
/* a Base16 (hex) output is twice as big as our buffer */
|
||||
buffer = (uint8_t *)malloc(n * 2 + 1);
|
||||
if (buffer == NULL)
|
||||
/* out of memory */
|
||||
return CborErrorOutOfMemory;
|
||||
|
||||
*result = (char *)buffer;
|
||||
|
||||
/* let cbor_value_copy_byte_string know we have an extra byte for the terminating NUL */
|
||||
@@ -204,7 +208,12 @@ static CborError generic_dump_base64(char **result, CborValue *it, const char al
|
||||
|
||||
/* a Base64 output (untruncated) has 4 bytes for every 3 in the input */
|
||||
size_t len = (n + 5) / 3 * 4;
|
||||
out = buffer = (uint8_t *)malloc(len + 1);
|
||||
buffer = (uint8_t *)malloc(len + 1);
|
||||
if (buffer == NULL)
|
||||
/* out of memory */
|
||||
return CborErrorOutOfMemory;
|
||||
|
||||
out = buffer;
|
||||
*result = (char *)buffer;
|
||||
|
||||
/* we read our byte string at the tail end of the buffer
|
||||
|
||||
+11
-1
@@ -1,14 +1,24 @@
|
||||
SOURCES += \
|
||||
$$PWD/cborencoder.c \
|
||||
$$PWD/cborencoder_close_container_checked.c \
|
||||
$$PWD/cborencoder_float.c \
|
||||
$$PWD/cborerrorstrings.c \
|
||||
$$PWD/cborparser.c \
|
||||
$$PWD/cborparser_dup_string.c \
|
||||
$$PWD/cborparser_float.c \
|
||||
$$PWD/cborpretty.c \
|
||||
$$PWD/cborpretty_stdio.c \
|
||||
$$PWD/cbortojson.c \
|
||||
$$PWD/cborvalidation.c \
|
||||
|
||||
HEADERS += $$PWD/cbor.h $$PWD/tinycbor-version.h
|
||||
HEADERS += \
|
||||
$$PWD/cbor.h \
|
||||
$$PWD/cborinternal_p.h \
|
||||
$$PWD/cborjson.h \
|
||||
$$PWD/compilersupport_p.h \
|
||||
$$PWD/tinycbor-version.h \
|
||||
$$PWD/utf8_p.h \
|
||||
|
||||
|
||||
QMAKE_CFLAGS *= $$QMAKE_CFLAGS_SPLIT_SECTIONS
|
||||
QMAKE_LFLAGS *= $$QMAKE_LFLAGS_GCSECTIONS
|
||||
|
||||
Reference in New Issue
Block a user