Commit 29c2532c authored by Tomas Gavenciak's avatar Tomas Gavenciak
Browse files

Add 'tinycbor/' from commit '4197849c2c5d4cb5dfa146380d8b436f47b51bf6'

git-subtree-dir: tinycbor
git-subtree-mainline: 353d1d53
git-subtree-split: 4197849c2c5d4cb5dfa146380d8b436f47b51bf6
parents 353d1d53 3cdb9c89
version: 0.5-build-{build}
pull_requests:
do_not_increment_build_number: true
image:
- Visual Studio 2015
- Visual Studio 2013
- Visual Studio 2017
install:
- cmd: >-
set tests=1
if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2013" (call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64) & (set tests=0)
if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" (call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64) & (set QTDIR=C:\Qt\5.9\msvc2015_64)
if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" (call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64) & (set QTDIR=C:\Qt\5.9\msvc2017_64)
set path=%PATH%;%QTDIR%\bin
build_script:
- cmd: >-
nmake -f Makefile.nmake -nologo CFLAGS="-W3 -Os -MDd"
cd tests
if /i "%tests%"=="1" qmake CONFIG-=release CONFIG+=debug
if /i "%tests%"=="1" nmake -nologo -s
test_script:
- cmd: >-
if /i "%tests%"=="1" nmake -s -nologo check
if /i "%tests%"=="0" echo Tests skipped.
artifacts:
- path: lib\tinycbor.lib
deploy: off
.tag export-subst
.gitignore export-ignore
.gitattributes export-ignore
.appveyor.yml text
# 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
$Format:%H$
language: cpp
matrix:
include:
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- sourceline: 'ppa:beineri/opt-qt593-trusty'
packages:
- qt59base valgrind
- g++-7
- doxygen
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
- sourceline: 'ppa:beineri/opt-qt593-trusty'
packages:
- qt59base
env:
- QMAKESPEC=linux-clang
- EVAL="CC=clang-5.0 && CXX=clang++"
- PATH=$PATH:/usr/local/clang/bin
- CFLAGS="-Oz"
- QMAKEFLAGS="-config release"
- MAKEFLAGS=-s
- TESTARGS=-silent
- 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"
lib/libtinycbor.a
- size lib/libtinycbor.a | tee sizes
- make -s clean
- make -k
CFLAGS="$CFLAGS -O0 -g"
- make
QMAKEFLAGS="$QMAKEFLAGS QMAKE_CXX=$CXX"
tests/Makefile
- (cd tests && make check -k
TESTRUNNER=`which valgrind 2>/dev/null`)
- make -s clean
- ./scripts/update-docs.sh
This diff is collapsed.
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.
# 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))
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
TINYCBOR_FREESTANDING_SOURCES = \
src/cborerrorstrings.c \
src/cborencoder.c \
src/cborencoder_close_container_checked.c \
src/cborparser.c \
src/cborpretty.c \
#
TINYCBOR_SOURCES = \
$(TINYCBOR_FREESTANDING_SOURCES) \
src/cborparser_dup_string.c \
src/cborpretty_stdio.c \
src/cbortojson.c \
src/cborvalidation.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
INSTALL_TARGETS += $(libdir)/libtinycbor.so.$(SOVERSION)
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
# 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
$(warning warning: funopen and fopencookie unavailable, open_memstream can not be implemented and conversion to JSON will not work properly!)
else
TINYCBOR_SOURCES += src/open_memstream.c
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) \
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) $^
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) -lm
bin/json2cbor: $(JSON2CBOR_SOURCES:.c=.o) $(BINLIBRARY)
@$(MKDIR) -p bin
$(CC) -o $@ $(LDFLAGS) $^ $(LDFLAGS_CJSON) $(LDLIBS) -lm
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)%)
uninstall:
$(RM) $(INSTALL_TARGETS:%=$(DESTDIR)%)
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=c99 $(CFLAGS)
%.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
ALLTESTS = open_memstream funopen fopencookie gc_sections \
system-cjson cjson
MAKEFILE := $(lastword $(MAKEFILE_LIST))
OUT :=
PROGRAM-open_memstream = extern int open_memstream(); int main() { return open_memstream(); }
PROGRAM-funopen = extern int funopen(); int main() { return funopen(); }
PROGRAM-fopencookie = extern int fopencookie(); int main() { return fopencookie(); }
PROGRAM-gc_sections = int main() {}
CCFLAGS-gc_sections = -Wl,--gc-sections
PROGRAM-cjson = \#include <stdlib.h>\n
PROGRAM-cjson += \#include <cjson/cJSON.h>\n
PROGRAM-cjson += int main() { return cJSON_False; }
CCFLAGS-cjson = -I$(dir $(MAKEFILE))src/cjson
PROGRAM-system-cjson = $(PROGRAM-cjson)
CCFLAGS-system-cjson = -lcjson
sink:
@echo >&2 Please run from the top-level Makefile.
configure: $(foreach it,$(ALLTESTS),check-$(it))
check-%:
@echo $(subst check-,,$@)-tested := 1 $(OUT)
$(if $(V),,@)if printf "$($(subst check-,PROGRAM-,$@))" | \
$(CC) -xc $($(subst check-,CCFLAGS-,$@)) -o /dev/null - $(if $(V),,>/dev/null 2>&1); \
then \
echo $(subst check-,,$@)-pass := 1 $(OUT); \
fi
CFLAGS = -W3
TINYCBOR_HEADERS = src\cbor.h src\cborjson.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 \
src\cborpretty_stdio.c \
src\cborvalidation.c
TINYCBOR_OBJS = \
src\cborerrorstrings.obj \
src\cborencoder.obj \
src\cborencoder_close_container_checked.obj \
src\cborparser.obj \
src\cborparser_dup_string.obj \
src\cborpretty.obj \
src\cborpretty_stdio.obj \
src\cborvalidation.obj
all: lib\tinycbor.lib
check: tests\Makefile lib\tinycbor.lib
cd tests & $(MAKE) check
silentcheck:
cd tests & set TESTARGS=-silent & $(MAKE) -s check
tests\Makefile: tests\tests.pro
qmake -o $@ $**
lib\tinycbor.lib: $(TINYCBOR_OBJS)
-if not exist lib\NUL md lib
lib -nologo /out:$@ $**
mostlyclean:
-del $(TINYCBOR_OBJS)
clean: mostlyclean
-del lib\tinycbor.lib
if exist tests\Makefile (cd tests & $(MAKE) clean)
distclean: clean
if exist tests\Makefile (cd tests & $(MAKE) distclean)
tag:
@perl maketag.pl
{src\}.c{src\}.obj:
$(CC) -nologo $(CFLAGS) -Isrc -c -Fo$@ $<
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/
==== 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
TEMPLATE = subdirs
SUBDIRS = simplereader.pro
#include "../src/cbor.h"
#include <sys/stat.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
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);
*size = fread(buf, st.st_size, 1, f);
fclose(f);
return buf;
}
static void indent(int nestingLevel)
{
while (nestingLevel--)
puts(" ");
}
static void dumpbytes(const uint8_t *buf, size_t len)
{
while (len--)
printf("%02X ", *buf++);
}
static bool 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);