Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
libucl: update to latest version
Baptiste Daroussin committed 5 years ago
commit 5bc18e392885716a48ef16ca70162d04d4a426b1
parent 6c2b807
25 files changed +761 -118
added external/libucl/CMakeLists.txt
@@ -0,0 +1,314 @@
+
PROJECT(libucl C)
+
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0 FATAL_ERROR)
+

+
SET(LIBUCL_VERSION_MAJOR 0)
+
SET(LIBUCL_VERSION_MINOR 5)
+
SET(LIBUCL_VERSION_PATCH 0)
+

+
SET(LIBUCL_VERSION
+
        "${LIBUCL_VERSION_MAJOR}.${LIBUCL_VERSION_MINOR}.${LIBUCL_VERSION_PATCH}")
+

+
INCLUDE(CheckCCompilerFlag)
+
INCLUDE(CheckCSourceCompiles)
+
INCLUDE(FindOpenSSL)
+
INCLUDE(GNUInstallDirs)
+

+
OPTION(ENABLE_URL_INCLUDE  "Enable urls in ucl includes (requires libcurl or libfetch) [default: OFF]" OFF)
+
OPTION(ENABLE_URL_SIGN  "Enable signatures check in ucl includes (requires openssl) [default: OFF]" OFF)
+
OPTION(BUILD_SHARED_LIBS "Build Shared Libraries [default: OFF]" OFF)
+
OPTION(ENABLE_LUA "Enable lua support [default: OFF]" OFF)
+
OPTION(ENABLE_LUAJIT "Enable luajit support [default: OFF]" OFF)
+
OPTION(ENABLE_UTILS "Enable building utility binaries [default: OFF]" OFF)
+

+
# Find lua installation
+
MACRO(FindLua)
+
	# Find lua libraries
+
	UNSET(LUA_INCLUDE_DIR CACHE)
+
	UNSET(LUA_LIBRARY CACHE)
+
	CMAKE_PARSE_ARGUMENTS(LUA "" "VERSION_MAJOR;VERSION_MINOR;ROOT" "" ${ARGN})
+

+
	IF(NOT LUA_VERSION_MAJOR OR NOT LUA_VERSION_MINOR)
+
		MESSAGE(FATAL_ERROR "Invalid FindLua invocation: ${ARGN}")
+
	ENDIF()
+

+
	IF(ENABLE_LUAJIT MATCHES "ON")
+
		MESSAGE(STATUS "Check for luajit ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
+
		FIND_PATH(LUA_INCLUDE_DIR luajit.h
+
				HINTS
+
				"${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}"
+
				$ENV{LUA_DIR}
+
				PATH_SUFFIXES "include/luajit-2.0"
+
				"include/luajit${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
+
				"include/luajit${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+
				"include/luajit-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+
				"include/luajit"
+
				"include/lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
+
				"include/lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+
				"include/lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+
				include/lua include
+
				PATHS ${RSPAMD_DEFAULT_INCLUDE_PATHS}
+
		)
+
		FIND_LIBRARY(LUA_LIBRARY
+
				NAMES luajit
+
				"luajit-2.0"
+
				"luajit2.0"
+
				"luajit${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
+
				"luajit${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+
				"luajit-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+
				HINTS
+
				"${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}"
+
				$ENV{LUA_DIR}
+
				PATH_SUFFIXES lib64 lib
+
				PATHS ${RSPAMD_DEFAULT_LIBRARY_PATHS}
+
				DOC "Lua library"
+
		)
+

+
		IF(NOT LUA_LIBRARY OR NOT LUA_INCLUDE_DIR)
+
			MESSAGE(STATUS "Fallback from luajit to plain lua")
+
			SET(ENABLE_LUAJIT "OFF")
+
			MESSAGE(STATUS "Check for lua ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
+
			FIND_PATH(LUA_INCLUDE_DIR lua.h
+
					HINTS
+
					"${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}"
+
					$ENV{LUA_DIR}
+
					PATH_SUFFIXES "include/lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
+
					"include/lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+
					"include/lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+
					include/lua include
+
					PATHS ${RSPAMD_DEFAULT_INCLUDE_PATHS}
+
			)
+
			FIND_LIBRARY(LUA_LIBRARY
+
					NAMES lua
+
					"lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
+
					"lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+
					"lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+
					HINTS
+
					"${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}"
+
					$ENV{LUA_DIR}
+
					PATH_SUFFIXES lib64 lib
+
					PATHS ${RSPAMD_DEFAULT_LIBRARY_PATHS}
+
					DOC "Lua library"
+
			)
+
		ENDIF()
+
	ELSE(ENABLE_LUAJIT MATCHES "ON")
+
		MESSAGE(STATUS "Check for lua ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
+
		FIND_PATH(LUA_INCLUDE_DIR lua.h
+
				HINTS
+
				"${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}"
+
				$ENV{LUA_DIR}
+
				PATH_SUFFIXES "include/lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
+
				"include/lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+
				"include/lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+
				include/lua include
+
				PATHS ${RSPAMD_DEFAULT_INCLUDE_PATHS}
+
		)
+
		FIND_LIBRARY(LUA_LIBRARY
+
				NAMES lua
+
				"lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
+
				"lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+
				"lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+
				HINTS
+
				"${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}"
+
				$ENV{LUA_DIR}
+
				PATH_SUFFIXES lib64 lib
+
				PATHS ${RSPAMD_DEFAULT_LIBRARY_PATHS}
+
				DOC "Lua library"
+
		)
+
	ENDIF(ENABLE_LUAJIT MATCHES "ON")
+

+
	IF(LUA_LIBRARY AND LUA_INCLUDE_DIR)
+
		SET(LUA_FOUND 1)
+
		IF(NOT LUA_VERSION_MAJOR OR NOT LUA_VERSION_MINOR)
+
			SET(LUA_VERSION_MAJOR ${LUA_VERSION_MAJOR})
+
			SET(LUA_VERSION_MINOR ${LUA_VERSION_MINOR})
+
		ENDIF(NOT LUA_VERSION_MAJOR OR NOT LUA_VERSION_MINOR)
+
		IF(ENABLE_LUAJIT MATCHES "ON")
+
			MESSAGE(STATUS "Found luajit ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
+
		ELSE(ENABLE_LUAJIT MATCHES "ON")
+
			MESSAGE(STATUS "Found lua ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
+
		ENDIF(ENABLE_LUAJIT MATCHES "ON")
+
	ENDIF(LUA_LIBRARY AND LUA_INCLUDE_DIR)
+
ENDMACRO()
+

+
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+
	LIST(APPEND CMAKE_REQUIRED_LIBRARIES rt)
+
ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+

+
IF(ENABLE_URL_INCLUDE MATCHES "ON")
+
    FIND_LIBRARY(LIBFETCH_LIBRARY NAMES fetch PATHS	PATH_SUFFIXES lib64 lib
+
                      PATHS
+
                          ~/Library/Frameworks
+
                          /Library/Frameworks
+
                          /usr/local
+
                          /usr
+
                          /sw
+
                          /opt/local
+
                          /opt/csw
+
                          /opt
+
                     DOC "Path where the libfetch library can be found")
+
    IF(LIBFETCH_LIBRARY)
+
    	FIND_FILE(HAVE_FETCH_H NAMES fetch.h PATHS /usr/include
+
    											   /opt/include
+
    											   /usr/local/include
+
    				DOC "Path to libfetch header")
+
    ELSE(LIBFETCH_LIBRARY)
+
    	# Try to find libcurl
+
        FIND_PACKAGE(CURL)
+
    	IF(NOT CURL_FOUND)
+
    		MESSAGE(WARNING "Neither libcurl nor libfetch were found, no support of URL includes in configuration")
+
    	ENDIF(NOT CURL_FOUND)
+
    ENDIF(LIBFETCH_LIBRARY)
+
ENDIF(ENABLE_URL_INCLUDE MATCHES "ON")
+

+
set(SYNC_BUILTINS_TEST_SOURCE [====[
+
int main()
+
{
+
    unsigned long val;
+

+
    __sync_bool_compare_and_swap(&val, 0, 1);
+
    __sync_add_and_fetch(&val, 1);
+
    __sync_fetch_and_add(&val, 0);
+
    __sync_sub_and_fetch(&val, 1);
+

+
    return 0;
+
}
+
]====])
+

+
CHECK_C_SOURCE_COMPILES("${SYNC_BUILTINS_TEST_SOURCE}" HAVE_ATOMIC_BUILTINS)
+
IF(NOT HAVE_ATOMIC_BUILTINS)
+
    MESSAGE(WARNING "Libucl references could be thread-unsafe because atomic builtins are missing")
+
ENDIF(NOT HAVE_ATOMIC_BUILTINS)
+

+
SET(CMAKE_C_WARN_FLAGS "")
+
CHECK_C_COMPILER_FLAG(-W SUPPORT_W)
+
CHECK_C_COMPILER_FLAG(-Wno-pointer-sign SUPPORT_WPOINTER_SIGN)
+
CHECK_C_COMPILER_FLAG(-Wno-unused-parameter SUPPORT_WUNUSED_PARAMETER)
+
IF(SUPPORT_W)
+
    SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -W")
+
ENDIF(SUPPORT_W)
+
IF(SUPPORT_WPOINTER_SIGN)
+
	SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-pointer-sign")
+
ENDIF(SUPPORT_WPOINTER_SIGN)
+
IF(SUPPORT_WUNUSED_PARAMETER)
+
	SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-unused-parameter")
+
ENDIF(SUPPORT_WUNUSED_PARAMETER)
+

+
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_WARN_FLAGS}" )
+

+
IF(ENABLE_URL_SIGN MATCHES "ON")
+
	IF(OPENSSL_FOUND)
+
		SET(HAVE_OPENSSL 1)
+
		INCLUDE_DIRECTORIES("${OPENSSL_INCLUDE_DIR}")
+
	ENDIF(OPENSSL_FOUND)
+
ENDIF(ENABLE_URL_SIGN MATCHES "ON")
+

+
SET(UCL_COMPILE_DEFS)
+
IF(HAVE_FETCH_H)
+
    LIST(APPEND UCL_COMPILE_DEFS -DHAVE_FETCH_H=1)
+
ENDIF(HAVE_FETCH_H)
+
IF(CURL_FOUND)
+
    LIST(APPEND UCL_COMPILE_DEFS -DCURL_FOUND=1)
+
ENDIF(CURL_FOUND)
+
IF(HAVE_OPENSSL)
+
    LIST(APPEND UCL_COMPILE_DEFS -DHAVE_OPENSSL=1)
+
ENDIF(HAVE_OPENSSL)
+
IF(HAVE_ATOMIC_BUILTINS)
+
    LIST(APPEND UCL_COMPILE_DEFS -DHAVE_ATOMIC_BUILTINS=1)
+
ENDIF(HAVE_ATOMIC_BUILTINS)
+

+
SET(UCLSRC src/ucl_util.c
+
		src/ucl_parser.c
+
		src/ucl_emitter.c
+
		src/ucl_emitter_streamline.c
+
		src/ucl_emitter_utils.c
+
		src/ucl_hash.c
+
		src/ucl_schema.c
+
		src/ucl_msgpack.c
+
		src/ucl_sexp.c)
+

+
SET(UCLHDR include/ucl.h
+
		include/ucl++.h)
+

+
SET (LIB_TYPE STATIC)
+
IF (BUILD_SHARED_LIBS)
+
  SET (LIB_TYPE SHARED)
+
ENDIF (BUILD_SHARED_LIBS)
+
ADD_LIBRARY(ucl ${LIB_TYPE} ${UCLSRC})
+
ADD_LIBRARY(ucl::ucl ALIAS ucl)
+
SET_TARGET_PROPERTIES(ucl PROPERTIES VERSION ${LIBUCL_VERSION} SOVERSION ${LIBUCL_VERSION_MAJOR})
+
TARGET_INCLUDE_DIRECTORIES(ucl
+
	PUBLIC
+
	  include
+
	PRIVATE
+
	  src
+
	  uthash
+
	  klib)
+
TARGET_COMPILE_DEFINITIONS(ucl
+
    PRIVATE
+
    ${UCL_COMPILE_DEFS}
+
)
+

+
IF(ENABLE_LUA MATCHES "ON")
+
	IF(ENABLE_LUAJIT MATCHES "ON")
+
		FindLua(VERSION_MAJOR "5" VERSION_MINOR "1" ROOT "${LUA_ROOT}")
+
		IF(NOT LUA_FOUND)
+
			MESSAGE(FATAL_ERROR "Lua not found, lua support is required")
+
		ELSE(NOT LUA_FOUND)
+
			INCLUDE_DIRECTORIES("${LUA_INCLUDE_DIR}")
+
		ENDIF(NOT LUA_FOUND)
+
	ELSE(ENABLE_LUAJIT MATCHES "ON")
+
		FindLua(VERSION_MAJOR "5" VERSION_MINOR "2" ROOT "${LUA_ROOT}")
+
		IF(NOT LUA_FOUND)
+
			FindLua(VERSION_MAJOR "5" VERSION_MINOR "1" ROOT "${LUA_ROOT}")
+
		ENDIF(NOT LUA_FOUND)
+
		IF(NOT LUA_FOUND)
+
			MESSAGE(FATAL_ERROR "Lua not found, lua support is required")
+
		ELSE(NOT LUA_FOUND)
+
			INCLUDE_DIRECTORIES("${LUA_INCLUDE_DIR}")
+
		ENDIF(NOT LUA_FOUND)
+
	ENDIF(ENABLE_LUAJIT MATCHES "ON")
+
	SET(UCL_LUA_SRC lua/lua_ucl.c)
+
	ADD_LIBRARY(lua-ucl ${LIB_TYPE} ${UCL_LUA_SRC})
+
	ADD_LIBRARY(ucl::lua ALIAS lua-ucl)
+
	IF(ENABLE_LUAJIT MATCHES "ON")
+
		TARGET_LINK_LIBRARIES(lua-ucl "${LUAJIT_LIBRARY}")
+
	ELSE(ENABLE_LUAJIT MATCHES "ON")
+
		TARGET_LINK_LIBRARIES(lua-ucl "${LUA_LIBRARY}")
+
	ENDIF(ENABLE_LUAJIT MATCHES "ON")
+
	TARGET_LINK_LIBRARIES(lua-ucl ucl)
+
	TARGET_INCLUDE_DIRECTORIES(lua-ucl PUBLIC include PRIVATE src uthash)
+
	SET_TARGET_PROPERTIES(lua-ucl PROPERTIES
+
		VERSION ${LIBUCL_VERSION}
+
		SOVERSION ${LIBUCL_VERSION_MAJOR}
+
		PUBLIC_HEADER include/lua_ucl.h)
+
	INSTALL(TARGETS lua-ucl DESTINATION ${CMAKE_INSTALL_LIBDIR}
+
			PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+
ENDIF()
+

+
IF(HAVE_FETCH_H)
+
    TARGET_LINK_LIBRARIES(ucl fetch)
+
ELSE(HAVE_FETCH_H)
+
    IF(CURL_FOUND)
+
        TARGET_LINK_LIBRARIES(ucl ${CURL_LIBRARIES})
+
    ENDIF(CURL_FOUND)
+
ENDIF(HAVE_FETCH_H)
+
IF(ENABLE_URL_SIGN MATCHES "ON")
+
	IF(OPENSSL_FOUND)
+
		TARGET_LINK_LIBRARIES(ucl ${OPENSSL_LIBRARIES})
+
	ENDIF(OPENSSL_FOUND)
+
ENDIF(ENABLE_URL_SIGN MATCHES "ON")
+

+
IF(UNIX)
+
    TARGET_LINK_LIBRARIES(ucl -lm)
+
ENDIF(UNIX)
+

+
SET_TARGET_PROPERTIES(ucl PROPERTIES
+
	PUBLIC_HEADER "${UCLHDR}")
+

+
INSTALL(TARGETS ucl DESTINATION ${CMAKE_INSTALL_LIBDIR}
+
		PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+

+
IF(ENABLE_UTILS MATCHES "ON")
+
    ADD_SUBDIRECTORY(utils)
+
ENDIF()
+

added external/libucl/Makefile.am
@@ -0,0 +1,81 @@
+
ACLOCAL_AMFLAGS = -I m4
+
EXTRA_DIST = uthash klib README.md
+

+
pkgconfigdir = $(libdir)/pkgconfig
+
pkgconfig_DATA = libucl.pc
+

+
if LUA_SUB
+
  LUA_SUBDIR = lua
+
endif
+

+
COVERAGE_INFO_FILE = $(top_builddir)/coverage.info
+
COVERAGE_REPORT_DIR = $(top_builddir)/coverage
+

+
.PHONY = coverage-requirement-check clean-coverage-report
+

+
coverage-requirement-check:
+
	@if test ! -e $(GCOV); then \
+
		echo "Cannot find $(GCOV). Please install gcov."; \
+
		exit 1; \
+
	fi
+

+
coverage: coverage-requirement-check clean-coverage coverage-build coverage-check coverage-report
+
	@echo "Please execute 'make clean' before 'make' or 'make check' to remove instrumented object files(compiled with -O0 etc.). Note that 'make clean' also remove coverage data."
+

+
coverage-build: coverage-requirement-check
+
	@if test `find $(top_builddir) -name "*.gcno" | wc -l` -eq 0; then \
+
		echo "Start to remove old non-instrumented object files..."; \
+
		$(MAKE) $(AM_MAKEFLAGS) clean; \
+
		echo "Successfully removed old non-instrumented object files."; \
+
	fi
+
	@echo "Start to build libraries with coverage options..."
+
	$(MAKE) $(AM_MAKEFLAGS) \
+
		CFLAGS="$(CFLAGS) $(COVERAGE_CFLAGS) $(COVERAGE_OPTFLAGS)" \
+
		CXXFLAGS="$(CXXFLAGS) $(COVERAGE_CXXFLAGS) $(COVERAGE_OPTFLAGS)" \
+
		LDFLAGS="$(LDFLAGS) $(COVERAGE_LDFLAGS)" \
+
		LIBS="$(LIBS) $(COVERAGE_LIBS)"
+
	@echo "Successfully built libraries with coverage options."
+

+
coverage-check: coverage-requirement-check
+
	@echo "Start to run tests with instrumented libraries..."
+
	$(MAKE) $(AM_MAKEFLAGS) check \
+
		CFLAGS="$(CFLAGS) $(COVERAGE_CFLAGS) $(COVERAGE_OPTFLAGS)" \
+
		CXXFLAGS="$(CXXFLAGS) $(COVERAGE_CXXFLAGS) $(COVERAGE_OPTFLAGS)" \
+
		LDFLAGS="$(LDFLAGS) $(COVERAGE_LDFLAGS)" \
+
		LIBS="$(LIBS) $(COVERAGE_LIBS)"
+
	@echo "Successfully run tests with instrumented libraries."
+

+
coverage-lcov: coverage-check coverage-requirement-check
+
	$(LCOV) --capture \
+
		--directory "$(top_builddir)/" \
+
		--output-file $(COVERAGE_INFO_FILE) \
+
		--gcov-tool $(GCOV) \
+
		--compat-libtool --checksum
+
	$(LCOV) --extract $(COVERAGE_INFO_FILE) `pwd`/src/ucl_\* \
+
		--output-file $(COVERAGE_INFO_FILE)
+

+
coverage-report: coverage-lcov
+
	@echo "Start to create coverage reports..."
+
	$(GENHTML) --prefix "$(top_srcdir)" \
+
		--output-directory $(COVERAGE_REPORT_DIR) \
+
		--title $(PACKAGE_NAME) \
+
		--legend --show-details \
+
		$(GENHTML_OPTIONS) \
+
		$(COVERAGE_INFO_FILE)
+
	@echo "Successfully created coverage reports into $(COVERAGE_REPORT_DIR) directory."
+

+
clean-coverage-report:
+
	-rm -rf $(COVERAGE_INFO_FILE)
+
	-rm -rf $(COVERAGE_REPORT_DIR)
+

+
clean-coverage: clean-coverage-report
+
	-$(LCOV) --gcov-tool $(GCOV) --zerocounters --directory $(top_builddir)
+
	@if xargs --version 2>/dev/null; then \
+
		find $(top_builddir) -name "*.gcno" | xargs --no-run-if-empty rm; \
+
	else \
+
		find $(top_builddir) -name "*.gcno" | xargs rm; \
+
	fi
+

+
clean-local: clean-coverage
+

+
SUBDIRS = src tests utils doc $(LUA_SUBDIR)
modified external/libucl/README.md
@@ -66,19 +66,25 @@ section {
```json
{
    "param": "value",
-
    "param1": "value1",
-
    "flag": true,
-
    "subsection": {
-
        "host": [
-
        {
-
            "host": "hostname",
-
            "port": 900
-
        },
-
        {
-
            "host": "hostname",
-
            "port": 901
+
    "section": {
+
        "param": "value",
+
        "param1": "value1",
+
        "flag": true,
+
        "number": 10000,
+
        "time": "0.2s",
+
        "string": "something",
+
        "subsection": {
+
            "host": [
+
                {
+
                    "host": "hostname",
+
                    "port": 900
+
                },
+
                {
+
                    "host": "hostname",
+
                    "port": 901
+
                }
+
            ]
        }
-
        ]
    }
}
```
@@ -289,7 +295,22 @@ as following:

By default, the priority of top-level object is set to zero (lowest priority). Currently,
you can define up to 16 priorities (from 0 to 15). Includes with bigger priorities will
-
rewrite keys from the objects with lower priorities as specified by the policy.
+
rewrite keys from the objects with lower priorities as specified by the policy. The priority
+
of the top-level or any other object can be changed with the `.priority` macro, which has no
+
options and takes the new priority:
+

+
```
+
# Default priority: 0.
+
foo = 6
+
.priority 5
+
# The following will have priority 5.
+
bar = 6
+
baz = 7
+
# The following will be included with a priority of 3, 5, and 6 respectively.
+
.include(priority=3) "path.conf"
+
.include(priority=5) "equivalent-path.conf"
+
.include(priority=6) "highpriority-path.conf"
+
```

### Variables support

@@ -348,7 +369,7 @@ bla'; # Read as valuebla

## Emitter

-
Each UCL object can be serialized to one of the three supported formats:
+
Each UCL object can be serialized to one of the four supported formats:

* `JSON` - canonic json notation (with spaces indented structure);
* `Compacted JSON` - compact json notation (without spaces or newlines);
modified external/libucl/configure.ac
@@ -73,11 +73,11 @@ AC_ARG_ENABLE([utils],
AM_CONDITIONAL([UTILS], [test x$utils = xtrue])

AS_IF([test "x$enable_signatures" = "xyes"], [
-
	AC_SEARCH_LIBS([EVP_MD_CTX_create], [crypto], [
+
	AC_SEARCH_LIBS([CRYPTO_new_ex_data], [crypto], [
		AC_DEFINE(HAVE_OPENSSL, 1, [Define to 1 if you have the 'crypto' library (-lcrypto).])
		LIBCRYPTO_LIB="-lcrypto"
		LIBS_EXTRA="${LIBS_EXTRA} -lcrypto"
-
		], [AC_MSG_ERROR([unable to find the EVP_MD_CTX_create() function])])
+
		], [AC_MSG_ERROR([unable to find the CRYPTO_new_ex_data() function])])
])
AC_SUBST(LIBCRYPTO_LIB)
AC_PATH_PROG(PANDOC, pandoc, [/non/existent])
added external/libucl/doc/Makefile.am
@@ -0,0 +1,9 @@
+
EXTRA_DIST = api.md
+

+
dist_man_MANS = libucl.3
+

+
gen-man: @PANDOC@
+
	tail -n +$$(grep -n '# Synopsis' api.md | cut -d':' -f1) api.md | \
+
	cat pandoc.template - | sed -e 's/^# \(.*\)/# \U\1/' \
+
	-e "s/%%date%%/$$(LANG=C date +'%d %B, %Y')/" | \
+
	@PANDOC@ -s -f markdown -t man -o libucl.3
modified external/libucl/doc/api.md
@@ -243,7 +243,7 @@ return ret;

# Emitting functions

-
Libucl can transform UCL objects to a number of tectual formats:
+
Libucl can transform UCL objects to a number of textual formats:

- configuration (`UCL_EMIT_CONFIG`) - nginx like human readable configuration file where implicit arrays are transformed to the duplicate keys
- compact json: `UCL_EMIT_JSON_COMPACT` - single line valid json without spaces
modified external/libucl/include/lua_ucl.h
@@ -70,8 +70,16 @@ UCL_EXTERN ucl_object_t* ucl_object_lua_import_escape (lua_State *L, int idx);
 */
UCL_EXTERN int ucl_object_push_lua (lua_State *L,
		const ucl_object_t *obj, bool allow_array);
+
/**
+
 * Push an object to lua replacing all ucl.null with `false`
+
 * @param L lua state
+
 * @param obj object to push
+
 * @param allow_array traverse over implicit arrays
+
 */
+
UCL_EXTERN int ucl_object_push_lua_filter_nil (lua_State *L,
+
											   const ucl_object_t *obj,
+
											   bool allow_array);

-
UCL_EXTERN struct ucl_lua_funcdata* ucl_object_toclosure (
-
		const ucl_object_t *obj);
+
UCL_EXTERN struct ucl_lua_funcdata* ucl_object_toclosure (const ucl_object_t *obj);

#endif /* LUA_UCL_H_ */
modified external/libucl/include/ucl.h
@@ -1647,4 +1647,7 @@ UCL_EXTERN bool ucl_object_validate_root_ext (const ucl_object_t *schema,
#define ucl_obj_ref ucl_object_ref
#define ucl_obj_free ucl_object_free

+
#define UCL_PRIORITY_MIN 0
+
#define UCL_PRIORITY_MAX 15
+

#endif /* UCL_H_ */
added external/libucl/lua/Makefile.am
@@ -0,0 +1,26 @@
+
ucl_common_cflags=	-I$(top_srcdir)/src \
+
			-I$(top_srcdir)/include \
+
			-I$(top_srcdir)/uthash \
+
			-Wall -W -Wno-unused-parameter -Wno-pointer-sign
+
luaexec_LTLIBRARIES=	ucl.la
+
ucl_la_SOURCES=	lua_ucl.c
+
ucl_la_CFLAGS=	$(ucl_common_cflags) \
+
					@LUA_INCLUDE@
+
ucl_la_LDFLAGS = -module -export-dynamic -avoid-version
+
ucl_la_LIBADD=	$(top_srcdir)/src/libucl.la \
+
					@LIBFETCH_LIBS@ \
+
					@LIBCRYPTO_LIB@ \
+
					@LIBREGEX_LIB@ \
+
					@CURL_LIBS@ \
+
					@LUA_LIB@
+

+
include_HEADERS=	$(top_srcdir)/include/lua_ucl.h
+

+
ROCKSPEC = $(PACKAGE)-$(VERSION)-1.rockspec
+
EXTRA_DIST = $(PACKAGE).rockspec.in \
+
			test.lua
+
DISTCLEANFILES = $(PACKAGE).rockspec
+

+
$(ROCKSPEC): $(PACKAGE).rockspec dist
+
	sed -e 's/@MD5@/'`$(MD5SUM) $(distdir).tar.gz | \
+
	cut -d " " -f 1`'/g' < $(PACKAGE).rockspec > $@

\ No newline at end of file
modified external/libucl/lua/lua_ucl.c
@@ -74,13 +74,21 @@ func = "huh";
#define UCL_ARRAY_TYPE_META "ucl.type.array"
#define UCL_IMPL_ARRAY_TYPE_META "ucl.type.impl_array"

-
static int ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj);
-
static int ucl_object_lua_push_scalar (lua_State *L, const ucl_object_t *obj, bool allow_array);
+
static int ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj, int flags);
+
static int ucl_object_lua_push_scalar (lua_State *L, const ucl_object_t *obj, int flags);
+
static int ucl_object_push_lua_common (lua_State *L, const ucl_object_t *obj, int flags);
static ucl_object_t* ucl_object_lua_fromtable (lua_State *L, int idx, ucl_string_flags_t flags);
static ucl_object_t* ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_flags_t flags);

static void *ucl_null;

+

+
enum lua_ucl_push_flags {
+
	LUA_UCL_DEFAULT_FLAGS = 0,
+
	LUA_UCL_ALLOW_ARRAY = (1u << 0u),
+
	LUA_UCL_CONVERT_NIL = (1u << 1u),
+
};
+

/**
 * Push a single element of an object to lua
 * @param L
@@ -89,10 +97,10 @@ static void *ucl_null;
 */
static void
ucl_object_lua_push_element (lua_State *L, const char *key,
-
		const ucl_object_t *obj)
+
		const ucl_object_t *obj, int flags)
{
	lua_pushstring (L, key);
-
	ucl_object_push_lua (L, obj, true);
+
	ucl_object_push_lua_common (L, obj, flags|LUA_UCL_ALLOW_ARRAY);
	lua_settable (L, -3);
}

@@ -140,21 +148,21 @@ lua_ucl_userdata_emitter (void *ud)
 */
static int
ucl_object_lua_push_object (lua_State *L, const ucl_object_t *obj,
-
		bool allow_array)
+
		int flags)
{
	const ucl_object_t *cur;
	ucl_object_iter_t it = NULL;

-
	if (allow_array && obj->next != NULL) {
+
	if ((flags & LUA_UCL_ALLOW_ARRAY) && obj->next != NULL) {
		/* Actually we need to push this as an array */
-
		return ucl_object_lua_push_array (L, obj);
+
		return ucl_object_lua_push_array (L, obj, flags);
	}

	lua_createtable (L, 0, obj->len);
	it = NULL;

	while ((cur = ucl_object_iterate (obj, &it, true)) != NULL) {
-
		ucl_object_lua_push_element (L, ucl_object_key (cur), cur);
+
		ucl_object_lua_push_element (L, ucl_object_key (cur), cur, flags);
	}

	luaL_getmetatable (L, UCL_OBJECT_TYPE_META);
@@ -170,7 +178,7 @@ ucl_object_lua_push_object (lua_State *L, const ucl_object_t *obj,
 * @return
 */
static int
-
ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj)
+
ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj, int flags)
{
	const ucl_object_t *cur;
	ucl_object_iter_t it;
@@ -182,7 +190,7 @@ ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj)
		lua_createtable (L, nelt, 0);

		while ((cur = ucl_object_iterate_safe (it, true))) {
-
			ucl_object_push_lua (L, cur, false);
+
			ucl_object_push_lua (L, cur, (flags & ~LUA_UCL_ALLOW_ARRAY));
			lua_rawseti (L, -2, i);
			i ++;
		}
@@ -201,7 +209,7 @@ ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj)
		lua_createtable (L, nelt, 0);

		LL_FOREACH (obj, cur) {
-
			ucl_object_push_lua (L, cur, false);
+
			ucl_object_push_lua (L, cur, (flags & ~LUA_UCL_ALLOW_ARRAY));
			lua_rawseti (L, -2, i);
			i ++;
		}
@@ -218,13 +226,13 @@ ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj)
 */
static int
ucl_object_lua_push_scalar (lua_State *L, const ucl_object_t *obj,
-
		bool allow_array)
+
		int flags)
{
	struct ucl_lua_funcdata *fd;

-
	if (allow_array && obj->next != NULL) {
+
	if ((flags & LUA_UCL_ALLOW_ARRAY) && obj->next != NULL) {
		/* Actually we need to push this as an array */
-
		return ucl_object_lua_push_array (L, obj);
+
		return ucl_object_lua_push_array (L, obj, flags);
	}

	switch (obj->type) {
@@ -246,7 +254,12 @@ ucl_object_lua_push_scalar (lua_State *L, const ucl_object_t *obj,
		lua_pushnumber (L, ucl_obj_todouble (obj));
		break;
	case UCL_NULL:
-
		lua_getfield (L, LUA_REGISTRYINDEX, "ucl.null");
+
		if (flags & LUA_UCL_CONVERT_NIL) {
+
			lua_pushboolean (L, false);
+
		}
+
		else {
+
			lua_getfield (L, LUA_REGISTRYINDEX, "ucl.null");
+
		}
		break;
	case UCL_USERDATA:
		fd = (struct ucl_lua_funcdata *)obj->value.ud;
@@ -260,6 +273,19 @@ ucl_object_lua_push_scalar (lua_State *L, const ucl_object_t *obj,
	return 1;
}

+
static int
+
ucl_object_push_lua_common (lua_State *L, const ucl_object_t *obj, int flags)
+
{
+
	switch (obj->type) {
+
	case UCL_OBJECT:
+
		return ucl_object_lua_push_object (L, obj, flags);
+
	case UCL_ARRAY:
+
		return ucl_object_lua_push_array (L, obj, flags);
+
	default:
+
		return ucl_object_lua_push_scalar (L, obj, flags);
+
	}
+
}
+

/***
 * @function ucl_object_push_lua(L, obj, allow_array)
 * This is a `C` function to push `UCL` object as lua variable. This function
@@ -278,14 +304,16 @@ ucl_object_lua_push_scalar (lua_State *L, const ucl_object_t *obj,
int
ucl_object_push_lua (lua_State *L, const ucl_object_t *obj, bool allow_array)
{
-
	switch (obj->type) {
-
	case UCL_OBJECT:
-
		return ucl_object_lua_push_object (L, obj, allow_array);
-
	case UCL_ARRAY:
-
		return ucl_object_lua_push_array (L, obj);
-
	default:
-
		return ucl_object_lua_push_scalar (L, obj, allow_array);
-
	}
+
	return ucl_object_push_lua_common (L, obj,
+
			allow_array ? LUA_UCL_ALLOW_ARRAY : LUA_UCL_DEFAULT_FLAGS);
+
}
+

+
int
+
ucl_object_push_lua_filter_nil (lua_State *L, const ucl_object_t *obj, bool allow_array)
+
{
+
	return ucl_object_push_lua_common (L, obj,
+
			allow_array ? (LUA_UCL_ALLOW_ARRAY|LUA_UCL_CONVERT_NIL) :
+
			(LUA_UCL_DEFAULT_FLAGS|LUA_UCL_CONVERT_NIL));
}

/**
@@ -597,6 +625,7 @@ lua_ucl_parser_init (lua_State *L)
	parser = ucl_parser_new (flags);
	if (parser == NULL) {
		lua_pushnil (L);
+
		return 1;
	}

	pparser = lua_newuserdata (L, sizeof (parser));
added external/libucl/src/Makefile.am
@@ -0,0 +1,30 @@
+
libucl_common_cflags=	-I$(top_srcdir)/src \
+
			-I$(top_srcdir)/include \
+
			-I$(top_srcdir)/uthash \
+
			-I$(top_srcdir)/klib \
+
			-Wall -W -Wno-unused-parameter -Wno-pointer-sign
+
lib_LTLIBRARIES=	libucl.la
+
libucl_la_SOURCES=	ucl_emitter.c \
+
					ucl_emitter_streamline.c \
+
					ucl_emitter_utils.c \
+
					ucl_hash.c \
+
					ucl_parser.c \
+
					ucl_schema.c \
+
					ucl_util.c \
+
					ucl_msgpack.c \
+
					ucl_sexp.c
+
libucl_la_CFLAGS=	$(libucl_common_cflags) \
+
					@CURL_CFLAGS@
+
libucl_la_LDFLAGS = -version-info @SO_VERSION@
+
libucl_la_LIBADD=	@LIBFETCH_LIBS@ \
+
					@LIBCRYPTO_LIB@ \
+
					@LIBREGEX_LIB@ \
+
					@CURL_LIBS@
+

+
include_HEADERS=	$(top_srcdir)/include/ucl.h \
+
					$(top_srcdir)/include/ucl++.h
+
noinst_HEADERS=	ucl_internal.h \
+
				mum.h \
+
				ucl_hash.h \
+
				ucl_chartable.h \
+
				tree.h
modified external/libucl/src/ucl_chartable.h
@@ -49,7 +49,7 @@ UCL_CHARACTER_VALUE_END /* # */, UCL_CHARACTER_VALUE_STR /* $ */,
UCL_CHARACTER_VALUE_STR /* % */, UCL_CHARACTER_VALUE_STR /* & */,
UCL_CHARACTER_VALUE_STR /* ' */, UCL_CHARACTER_VALUE_STR /* ( */,
UCL_CHARACTER_VALUE_STR /* ) */, UCL_CHARACTER_VALUE_STR /* * */,
-
UCL_CHARACTER_VALUE_STR|UCL_CHARACTER_VALUE_DIGIT /* + */,
+
UCL_CHARACTER_VALUE_STR|UCL_CHARACTER_VALUE_DIGIT|UCL_CHARACTER_UCL_UNSAFE /* + */,
UCL_CHARACTER_VALUE_END /* , */,
UCL_CHARACTER_KEY|UCL_CHARACTER_VALUE_STR|UCL_CHARACTER_VALUE_DIGIT_START|UCL_CHARACTER_VALUE_DIGIT /* - */,
UCL_CHARACTER_KEY|UCL_CHARACTER_VALUE_STR|UCL_CHARACTER_VALUE_DIGIT /* . */,
modified external/libucl/src/ucl_hash.c
@@ -544,7 +544,7 @@ e0:
	return false;
}

-
int
+
static int
ucl_lc_cmp (const char *s, const char *d, size_t l)
{
	unsigned int fp, i;
@@ -634,4 +634,4 @@ ucl_hash_sort (ucl_hash_t *hashlin, enum ucl_object_keys_sort_flags fl)
			}
		}
	}
-
}

\ No newline at end of file
+
}
modified external/libucl/src/ucl_hash.h
@@ -103,7 +103,7 @@ bool ucl_hash_iter_has_next (ucl_hash_t *hashlin, ucl_hash_iter_t iter);
 * @param hashlin
 */
bool ucl_hash_reserve (ucl_hash_t *hashlin, size_t sz);
-
void ucl_hash_sort (ucl_hash_t *hashlin, enum ucl_object_keys_sort_flags fl);

+
void ucl_hash_sort (ucl_hash_t *hashlin, enum ucl_object_keys_sort_flags fl);

#endif
modified external/libucl/src/ucl_internal.h
@@ -98,6 +98,7 @@
#if defined(_MSC_VER)
/* Windows hacks */
#include <BaseTsd.h>
+
#include <inttypes.h>
typedef SSIZE_T ssize_t;
#define strdup _strdup
#define snprintf _snprintf
modified external/libucl/src/ucl_msgpack.c
@@ -1019,6 +1019,8 @@ ucl_msgpack_consume (struct ucl_parser *parser)
			}
			else {
				/* Length is not embedded */
+
				remain --;
+

				if (remain < obj_parser->len) {
					ucl_create_err (&parser->err, "not enough data remain to "
							"read object's length: %u remain, %u needed",
@@ -1028,7 +1030,6 @@ ucl_msgpack_consume (struct ucl_parser *parser)
				}

				p ++;
-
				remain --;

				switch (obj_parser->len) {
				case 1:
@@ -1044,8 +1045,10 @@ ucl_msgpack_consume (struct ucl_parser *parser)
					len = FROM_BE64 (*(uint64_t *)p);
					break;
				default:
-
					assert (0);
-
					break;
+
					ucl_create_err (&parser->err, "invalid length of the length field: %u",
+
							(unsigned)obj_parser->len);
+

+
					return false;
				}

				p += obj_parser->len;
@@ -1131,7 +1134,9 @@ ucl_msgpack_consume (struct ucl_parser *parser)
			 */
			container = parser->stack;

-
			if (container == NULL) {
+
			if (parser->stack == NULL) {
+
				ucl_create_err (&parser->err,
+
						"read assoc value when no container represented");
				return false;
			}

@@ -1191,6 +1196,8 @@ ucl_msgpack_consume (struct ucl_parser *parser)
			container = parser->stack;

			if (container == NULL) {
+
				ucl_create_err (&parser->err,
+
						"read assoc value when no container represented");
				return false;
			}

@@ -1202,6 +1209,7 @@ ucl_msgpack_consume (struct ucl_parser *parser)

			if (!ucl_msgpack_insert_object (parser, key, keylen,
					parser->cur_obj)) {
+

				return false;
			}

@@ -1237,7 +1245,9 @@ ucl_msgpack_consume (struct ucl_parser *parser)
	case start_assoc:
		/* Empty container at the end */
		if (len != 0) {
-
			ucl_create_err (&parser->err, "invalid non-empty container at the end");
+
			ucl_create_err (&parser->err,
+
					"invalid non-empty container at the end; len=%zu",
+
					(uintmax_t)len);

			return false;
		}
@@ -1245,6 +1255,12 @@ ucl_msgpack_consume (struct ucl_parser *parser)
		parser->cur_obj = ucl_object_new_full (
				state == start_array ? UCL_ARRAY : UCL_OBJECT,
				parser->chunks->priority);
+

+
		if (parser->stack == NULL) {
+
			ucl_create_err (&parser->err,
+
					"read assoc value when no container represented");
+
			return false;
+
		}
		/* Insert to the previous level container */
		if (!ucl_msgpack_insert_object (parser,
				key, keylen, parser->cur_obj)) {
@@ -1271,7 +1287,9 @@ ucl_msgpack_consume (struct ucl_parser *parser)

		container = parser->stack;

-
		if (container == NULL) {
+
		if (parser->stack == NULL) {
+
			ucl_create_err (&parser->err,
+
					"read assoc value when no container represented");
			return false;
		}

@@ -1301,7 +1319,12 @@ ucl_msgpack_consume (struct ucl_parser *parser)

	/* Rewind to the top level container */
	ucl_msgpack_get_next_container (parser);
-
	assert (parser->stack == NULL);
+

+
	if (parser->stack != NULL) {
+
		ucl_create_err (&parser->err, "incomplete container");
+

+
		return false;
+
	}

	return true;
}
modified external/libucl/src/ucl_parser.c
@@ -345,6 +345,7 @@ ucl_check_variable_safe (struct ucl_parser *parser, const char *ptr, size_t rema
		/* Call generic handler */
		if (parser->var_handler (ptr, remain, &dst, &dstlen, &need_free,
				parser->var_data)) {
+
			*out_len = dstlen;
			*found = true;
			if (need_free) {
				free (dst);
@@ -461,12 +462,15 @@ ucl_expand_single_variable (struct ucl_parser *parser, const char *ptr,
	}
	if (!found) {
		if (strict && parser->var_handler != NULL) {
-
			if (parser->var_handler (ptr, remain, &dst, &dstlen, &need_free,
+
			if (parser->var_handler (p, remain, &dst, &dstlen, &need_free,
							parser->var_data)) {
				memcpy (d, dst, dstlen);
-
				ret += dstlen;
-
				d += remain;
+
				ret += remain;
+
				d += dstlen;
				found = true;
+
				if (need_free) {
+
					free (dst);
+
				}
			}
		}

modified external/libucl/src/ucl_util.c
@@ -866,6 +866,8 @@ ucl_fetch_url (const unsigned char *url, unsigned char **buf, size_t *buflen,
	*buf = cbdata.buf;
	*buflen = cbdata.buflen;

+
	curl_easy_cleanup (curl);
+

	return true;
#else
	ucl_create_err (err, "URL support is disabled");
@@ -1574,6 +1576,11 @@ ucl_include_common (const unsigned char *data, size_t len,
			else if (param->type == UCL_INT) {
				if (strncmp (param->key, "priority", param->keylen) == 0) {
					params.priority = ucl_object_toint (param);
+
					if (params.priority > UCL_PRIORITY_MAX) {
+
						ucl_create_err (&parser->err, "Invalid priority value in macro: %d",
+
							params.priority);
+
						return false;
+
					}
				}
			}
		}
@@ -1712,8 +1719,9 @@ ucl_priority_handler (const unsigned char *data, size_t len,
	if (len > 0) {
		value = malloc(len + 1);
		ucl_strlcpy(value, (const char *)data, len + 1);
-
		priority = strtol(value, &leftover, 10);
-
		if (*leftover != '\0') {
+
		errno = 0;
+
		priority = strtoul(value, &leftover, 10);
+
		if (errno != 0 || *leftover != '\0' || priority > UCL_PRIORITY_MAX) {
			ucl_create_err (&parser->err, "Invalid priority value in macro: %s",
				value);
			free(value);
@@ -3658,6 +3666,13 @@ ucl_object_compare (const ucl_object_t *o1, const ucl_object_t *o2)
	ucl_object_iter_t iter = NULL;
	int ret = 0;

+
    // Must check for NULL or code will segfault
+
    if ((o1 == NULL) || (o2 == NULL))
+
    {
+
        // The only way this could be true is of both are NULL
+
        return (o1 == NULL) && (o2 == NULL);
+
    }
+
    
	if (o1->type != o2->type) {
		return (o1->type) - (o2->type);
	}
@@ -3929,4 +3944,4 @@ const char *
ucl_parser_get_cur_file (struct ucl_parser *parser)
{
	return parser->cur_file;
-
}

\ No newline at end of file
+
}
added external/libucl/tests/Makefile.am
@@ -0,0 +1,45 @@
+
EXTRA_DIST = $(TESTS) basic schema generate.res \
+
	streamline.res rcl_test.json.xz
+

+
TESTS = basic.test \
+
		generate.test \
+
		schema.test \
+
		msgpack.test \
+
		speed.test \
+
		msgpack.test
+
TESTS_ENVIRONMENT = $(SH) \
+
			TEST_DIR=$(top_srcdir)/tests \
+
			TEST_OUT_DIR=$(top_builddir)/tests \
+
			TEST_BINARY_DIR=$(top_builddir)/tests
+

+
common_test_cflags = -I$(top_srcdir)/include \
+
					-I$(top_srcdir)/src \
+
					-I$(top_srcdir)/uthash
+
common_test_ldadd = $(top_builddir)/src/libucl.la
+

+
test_basic_SOURCES = test_basic.c
+
test_basic_LDADD = $(common_test_ldadd)
+
test_basic_CFLAGS = $(common_test_cflags)
+

+
test_speed_SOURCES = test_speed.c
+
test_speed_LDADD = $(common_test_ldadd)
+
test_speed_CFLAGS = $(common_test_cflags)
+

+
test_generate_SOURCES = test_generate.c
+
test_generate_LDADD = $(common_test_ldadd)
+
test_generate_CFLAGS = $(common_test_cflags)
+

+
test_schema_SOURCES = test_schema.c
+
test_schema_LDADD = $(common_test_ldadd)
+
test_schema_CFLAGS = $(common_test_cflags)
+

+
test_streamline_SOURCES = test_streamline.c
+
test_streamline_LDADD = $(common_test_ldadd)
+
test_streamline_CFLAGS = $(common_test_cflags)
+

+
test_msgpack_SOURCES = test_msgpack.c
+
test_msgpack_LDADD = $(common_test_ldadd)
+
test_msgpack_CFLAGS = $(common_test_cflags)
+

+
check_PROGRAMS = test_basic test_speed test_generate test_schema test_streamline \
+
	test_msgpack

\ No newline at end of file
modified external/libucl/tests/test_basic.c
@@ -40,10 +40,10 @@ main (int argc, char **argv)
	const char *fname_in = NULL, *fname_out = NULL;
	int ret = 0, opt, json = 0, compact = 0, yaml = 0,
			save_comments = 0, skip_macro = 0,
-
			flags, fd_out, fd_in, use_fd = 0;
+
			flags, fd_out, fd_in, use_fd = 0, msgpack_input = 0;
	struct ucl_emitter_functions *func;

-
	while ((opt = getopt(argc, argv, "fjcyCM")) != -1) {
+
	while ((opt = getopt(argc, argv, "fjcyCMm")) != -1) {
		switch (opt) {
		case 'j':
			json = 1;
@@ -60,6 +60,9 @@ main (int argc, char **argv)
		case 'M':
			skip_macro = true;
			break;
+
		case 'm':
+
			msgpack_input = 1;
+
			break;
		case 'f':
			use_fd = true;
			break;
@@ -145,7 +148,9 @@ main (int argc, char **argv)
			exit (EXIT_FAILURE);
		}

-
		ucl_parser_add_chunk (parser, (const unsigned char *)inbuf, r);
+
		ucl_parser_add_chunk_full (parser, (const unsigned char *)inbuf, r,
+
				0, UCL_DUPLICATE_APPEND,
+
				msgpack_input ? UCL_PARSE_MSGPACK : UCL_PARSE_UCL);
		fclose (in);
	}
	else {
modified external/libucl/tests/test_generate.c
@@ -273,7 +273,7 @@ main (int argc, char **argv)
	assert (ucl_object_type (it_obj) == UCL_BOOLEAN);
	ucl_object_iterate_free (it);

-
	fn = ucl_object_emit_memory_funcs (&emitted);
+
	fn = ucl_object_emit_memory_funcs ((void **)&emitted);
	assert (ucl_object_emit_full (obj, UCL_EMIT_CONFIG, fn, comments));
	fprintf (out, "%s\n", emitted);
	ucl_object_emit_funcs_free (fn);
@@ -302,7 +302,7 @@ main (int argc, char **argv)
	assert (ucl_parser_get_error_code (parser) == 0);
	obj = ucl_parser_get_object (parser);
	ucl_parser_free (parser);
-
	ucl_object_free (obj);
+
	ucl_object_unref (obj);

	if (emitted != NULL) {
		free (emitted);
modified external/libucl/tests/test_msgpack.c
@@ -456,6 +456,7 @@ ucl_test_large_string (void)
	res = ucl_object_fromstring_common (str, cur_len % 100000,
				UCL_STRING_RAW);
	res->flags |= UCL_OBJECT_BINARY;
+
	free (str);

	return res;
}
added external/libucl/utils/Makefile.am
@@ -0,0 +1,23 @@
+
common_utils_cflags = -I$(top_srcdir)/include \
+
					-I$(top_srcdir)/src \
+
					-I$(top_srcdir)/uthash
+
common_utils_ldadd = $(top_builddir)/src/libucl.la
+

+
ucl_chargen_SOURCES = chargen.c
+
ucl_chargen_LDADD = $(common_utils_ldadd)
+
ucl_chargen_CFLAGS = $(common_utils_cflags)
+

+
ucl_objdump_SOURCES = objdump.c
+
ucl_objdump_LDADD = $(common_utils_ldadd)
+
ucl_objdump_CFLAGS = $(common_utils_cflags)
+

+
ucl_tool_SOURCES = ucl-tool.c
+
ucl_tool_LDADD = $(common_utils_ldadd)
+
ucl_tool_CFLAGS = $(common_utils_cflags)
+

+
if UTILS
+
UTL = ucl_chargen ucl_objdump ucl_tool
+
else
+
UTL =
+
endif
+
bin_PROGRAMS = $(UTL)

\ No newline at end of file
modified external/libucl/utils/objdump.c
@@ -22,8 +22,11 @@
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

-
#include <stdio.h>
-
#include <errno.h>
+
#if defined(_MSC_VER)
+
    #include <BaseTsd.h>
+

+
    typedef SSIZE_T ssize_t;
+
#endif

#include "ucl.h"

@@ -101,8 +104,8 @@ main(int argc, char **argv)
	const char *fn = NULL;
	unsigned char *inbuf;
	struct ucl_parser *parser;
-
	int k, ret = 0, r = 0;
-
	ssize_t bufsize;
+
	int k, ret = 0;
+
	ssize_t bufsize, r = 0;
	ucl_object_t *obj = NULL;
	const ucl_object_t *par;
	FILE *in;
@@ -114,7 +117,7 @@ main(int argc, char **argv)
	if (fn != NULL) {
		in = fopen (fn, "r");
		if (in == NULL) {
-
			exit (-errno);
+
			exit (EXIT_FAILURE);
		}
	}
	else {
modified external/libucl/utils/ucl-tool.c
@@ -20,21 +20,8 @@
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

-
#include <stdio.h>
-
#include <getopt.h>
-
#include <stdlib.h>
-

#include "ucl.h"

-
static struct option opts[] = {
-
    {"help", no_argument, NULL, 'h'},
-
    {"in", required_argument, NULL, 'i' },
-
    {"out", required_argument, NULL, 'o' },
-
    {"schema", required_argument, NULL, 's'},
-
    {"format", required_argument, NULL, 'f'},
-
    {0, 0, 0, 0}
-
};
-

void usage(const char *name, FILE *out) {
  fprintf(out, "Usage: %s [--help] [-i|--in file] [-o|--out file]\n", name);
  fprintf(out, "    [-s|--schema file] [-f|--format format]\n\n");
@@ -49,64 +36,75 @@ void usage(const char *name, FILE *out) {
}

int main(int argc, char **argv) {
+
  int i;
  char ch;
  FILE *in = stdin, *out = stdout;
-
  const char *schema = NULL;
+
  const char *schema = NULL, *parm, *val;
  unsigned char *buf = NULL;
  size_t size = 0, r = 0;
  struct ucl_parser *parser = NULL;
  ucl_object_t *obj = NULL;
  ucl_emitter_t emitter = UCL_EMIT_CONFIG;

-
  while((ch = getopt_long(argc, argv, "hi:o:s:f:", opts, NULL)) != -1) {
-
    switch (ch) {
-
    case 'i':
-
      in = fopen(optarg, "r");
+
  for (i = 1; i < argc; ++i) {
+
    parm = argv[i];
+
    val = ((i + 1) < argc) ? argv[++i] : NULL;
+

+
    if ((strcmp(parm, "--help") == 0) || (strcmp(parm, "-h") == 0)) {
+
      usage(argv[0], stdout);
+
      exit(0);
+

+
    } else if ((strcmp(parm, "--in") == 0) || (strcmp(parm, "-i") == 0)) {
+
      if (!val)
+
        goto err_val;
+

+
      in = fopen(val, "r");
      if (in == NULL) {
        perror("fopen on input file");
        exit(EXIT_FAILURE);
      }
-
      break;
-
    case 'o':
-
      out = fopen(optarg, "w");
+
    } else if ((strcmp(parm, "--out") == 0) || (strcmp(parm, "-o") == 0)) {
+
      if (!val)
+
        goto err_val;
+

+
      out = fopen(val, "w");
      if (out == NULL) {
        perror("fopen on output file");
        exit(EXIT_FAILURE);
      }
-
      break;
-
    case 's':
-
      schema = optarg;
-
      break;
-
    case 'f':
-
      if (strcmp(optarg, "ucl") == 0) {
-
        emitter = UCL_EMIT_CONFIG;
-
      } else if (strcmp(optarg, "json") == 0) {
-
        emitter = UCL_EMIT_JSON;
-
      } else if (strcmp(optarg, "yaml") == 0) {
-
        emitter = UCL_EMIT_YAML;
-
      } else if (strcmp(optarg, "compact_json") == 0) {
-
        emitter = UCL_EMIT_JSON_COMPACT;
-
      } else if (strcmp(optarg, "msgpack") == 0) {
-
        emitter = UCL_EMIT_MSGPACK;
-
      } else {
-
        fprintf(stderr, "Unknown output format: %s\n", optarg);
-
        exit(EXIT_FAILURE);
-
      }
-
      break;
-
    case 'h':
-
      usage(argv[0], stdout);
-
      exit(0);
-
    default:
+
    } else if ((strcmp(parm, "--schema") == 0) || (strcmp(parm, "-s") == 0)) {
+
      if (!val)
+
        goto err_val;
+
      schema = val;
+

+
    } else if ((strcmp(parm, "--format") == 0) || (strcmp(parm, "-f") == 0)) {
+
        if (!val)
+
          goto err_val;
+

+
        if (strcmp(val, "ucl") == 0) {
+
          emitter = UCL_EMIT_CONFIG;
+
        } else if (strcmp(val, "json") == 0) {
+
          emitter = UCL_EMIT_JSON;
+
        } else if (strcmp(val, "yaml") == 0) {
+
          emitter = UCL_EMIT_YAML;
+
        } else if (strcmp(val, "compact_json") == 0) {
+
          emitter = UCL_EMIT_JSON_COMPACT;
+
        } else if (strcmp(val, "msgpack") == 0) {
+
          emitter = UCL_EMIT_MSGPACK;
+
        } else {
+
          fprintf(stderr, "Unknown output format: %s\n", val);
+
          exit(EXIT_FAILURE);
+
        }
+
    } else {
      usage(argv[0], stderr);
      exit(EXIT_FAILURE);
-
      break;
    }
  }

  parser = ucl_parser_new(0);
  buf = malloc(BUFSIZ);
  size = BUFSIZ;
-
  while(!feof(in) && !ferror(in)) {
+
  while (!feof(in) && !ferror(in)) {
    if (r == size) {
      buf = realloc(buf, size*2);
      size *= 2;
@@ -155,8 +153,7 @@ int main(int argc, char **argv) {

  if (emitter != UCL_EMIT_MSGPACK) {
    fprintf(out, "%s\n", ucl_object_emit(obj, emitter));
-
  }
-
  else {
+
  } else {
    size_t len;
    unsigned char *res;

@@ -165,4 +162,9 @@ int main(int argc, char **argv) {
  }

  return 0;
+

+
err_val:
+
    fprintf(stderr, "Parameter %s is missing mandatory value\n", parm);
+
    usage(argv[0], stderr);
+
    exit(EXIT_FAILURE);
}