merge 'default' into this - somewhat older - branch to see whether it makes troubles somewhere...

JSON-172
Roker 2 years ago
commit 061e5e8d12

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{84d7820e-599c-4ac9-b93c-ecedb0f4d213}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Label="Shared" />
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<ItemGroup>
<ProjectReference Include="..\..\..\libpEpAdapter\libpEpAdapter\libpEpAdapter.vcxproj">
<Project>{ec44fec9-2f3a-4a0c-b60e-0f22aa43ef58}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\pEpEngine\build-windows\pEpEngine.vcxproj">
<Project>{146e69f8-e1da-456a-b048-6dd29d9acf6b}</Project>
</ProjectReference>
<ProjectReference Include="..\pEpJSONServerAdapter\pEpJSONServerAdapterLibrary.vcxproj">
<Project>{644d1ba4-084c-47b2-8a9e-00a8d9f9a35c}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\server\unittest_rpc.cc" />
</ItemGroup>
<ItemDefinitionGroup />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.3\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets" Condition="Exists('..\..\..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.3\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets')" />
</ImportGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)pEpJSONServerAdapter\build-windows\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<AdditionalOptions>-D__PRETTY_FUNCTION__=__FUNCSIG__ %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)pEpJSONServerAdapter\build-windows\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>X64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<AdditionalOptions>-D__PRETTY_FUNCTION__=__FUNCSIG__ %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)pEpJSONServerAdapter\build-windows\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<IntrinsicFunctions>false</IntrinsicFunctions>
<AdditionalOptions>-D__PRETTY_FUNCTION__=__FUNCSIG__ %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)pEpJSONServerAdapter\build-windows\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>X64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<AdditionalOptions>-D__PRETTY_FUNCTION__=__FUNCSIG__ %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
</Link>
</ItemDefinitionGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.3\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.3\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets'))" />
</Target>
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\..\packages\boost.1.72.0.0\build\boost.targets" Condition="Exists('..\..\..\packages\boost.1.72.0.0\build\boost.targets')" />
<Import Project="..\..\..\packages\boost_chrono-vc142.1.72.0.0\build\boost_chrono-vc142.targets" Condition="Exists('..\..\..\packages\boost_chrono-vc142.1.72.0.0\build\boost_chrono-vc142.targets')" />
<Import Project="..\..\..\packages\boost_date_time-vc142.1.72.0.0\build\boost_date_time-vc142.targets" Condition="Exists('..\..\..\packages\boost_date_time-vc142.1.72.0.0\build\boost_date_time-vc142.targets')" />
<Import Project="..\..\..\packages\boost_filesystem-vc142.1.72.0.0\build\boost_filesystem-vc142.targets" Condition="Exists('..\..\..\packages\boost_filesystem-vc142.1.72.0.0\build\boost_filesystem-vc142.targets')" />
<Import Project="..\..\..\packages\boost_program_options-vc142.1.72.0.0\build\boost_program_options-vc142.targets" Condition="Exists('..\..\..\packages\boost_program_options-vc142.1.72.0.0\build\boost_program_options-vc142.targets')" />
<Import Project="..\..\..\packages\boost_thread-vc142.1.72.0.0\build\boost_thread-vc142.targets" Condition="Exists('..\..\..\packages\boost_thread-vc142.1.72.0.0\build\boost_thread-vc142.targets')" />
<Import Project="..\..\..\packages\boost_regex-vc142.1.72.0.0\build\boost_regex-vc142.targets" Condition="Exists('..\..\..\packages\boost_regex-vc142.1.72.0.0\build\boost_regex-vc142.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\boost.1.72.0.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\boost.1.72.0.0\build\boost.targets'))" />
<Error Condition="!Exists('..\..\..\packages\boost_chrono-vc142.1.72.0.0\build\boost_chrono-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\boost_chrono-vc142.1.72.0.0\build\boost_chrono-vc142.targets'))" />
<Error Condition="!Exists('..\..\..\packages\boost_date_time-vc142.1.72.0.0\build\boost_date_time-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\boost_date_time-vc142.1.72.0.0\build\boost_date_time-vc142.targets'))" />
<Error Condition="!Exists('..\..\..\packages\boost_filesystem-vc142.1.72.0.0\build\boost_filesystem-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\boost_filesystem-vc142.1.72.0.0\build\boost_filesystem-vc142.targets'))" />
<Error Condition="!Exists('..\..\..\packages\boost_program_options-vc142.1.72.0.0\build\boost_program_options-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\boost_program_options-vc142.1.72.0.0\build\boost_program_options-vc142.targets'))" />
<Error Condition="!Exists('..\..\..\packages\boost_thread-vc142.1.72.0.0\build\boost_thread-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\boost_thread-vc142.1.72.0.0\build\boost_thread-vc142.targets'))" />
<Error Condition="!Exists('..\..\..\packages\boost_regex-vc142.1.72.0.0\build\boost_regex-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\boost_regex-vc142.1.72.0.0\build\boost_regex-vc142.targets'))" />
</Target>
</Project>

@ -6,23 +6,32 @@ endif
# default config
# these are source builds
# set to 'etpan' or 'pEpMIME'
MIME_LIB?=etpan
PEP_WEBSERVER?=../../webserver
PEP_ADAPTER_LIBRARY=../../libpEpAdapter
PEP_ENGINE?=../../pEpEngine/src
LIBETPAN_FDIK?=../../libetpan/src/.libs
SEQUOIA_PGP?=../../sequoia/target/release
NETTLE?=../../nettle
BOOST_INCLUDE_PATH?=../../boost_1_72_0
BOOST_LIBRARY_PATH?=../../boost_1_72_0/stage/lib
ASN1_PATH?=$(PEP_ENGINE)/asn.1
PREFIX?=$(HOME)/local
# path to installed libraries
# where pEp stuff is installed into:
PEP_LIB_PATH?=$(PREFIX)/lib
PEP_INCLUDE?=$(PREFIX)/include
PREFIX?=$(HOME)
# where libs from the packages systems are installed into:
LIBRARY_PATH?=/usr/local/lib
# paths to the .a libraries. Can be overridden in local.conf
PEP_WEBSERVER?=$(PEP_LIB_PATH)
PEP_ADAPTER_LIBRARY=$(PEP_LIB_PATH)
PEP_ENGINE?=$(PEP_LIB_PATH)
LIBETPAN_FDIK?=$(PEP_LIB_PATH)
PEP_MIME_PATH?=$(PEP_LIB_PATH)
SEQUOIA_PGP?=$(PEP_LIB_PATH)
ASN1_PATH?=$(PEP_LIB_PATH)
NETTLE?=$(LIBRARY_PATH)
BOOST_INCLUDE_PATH?=/usr/local/include
BOOST_LIBRARY_PATH?=$(LIBRARY_PATH)
PEP_INCLUDE?=$(PREFIX)/include
LIBRARY_PATH?=$(PREFIX)/lib
@ -32,39 +41,78 @@ LIBZ_LIBRARY_PATH?=$(LIBRARY_PATH)
ICONV_LIBRARY_PATH?=$(LIBRARY_PATH)
LIBEVENT_LIBRARY_PATH=$(LIBRARY_PATH)
AR?=ar
AR?=/usr/bin/ar
CC?=cc
CXX?=c++
CFLAGS+=-std=c14
CXXFLAGS+=-I$(BOOST_INCLUDE_PATH) -I$(PEP_INCLUDE) -std=c++14
CFLAGS+=-std=c14 -fvisibility=hidden
CXXFLAGS+=-I$(BOOST_INCLUDE_PATH) -I$(PEP_INCLUDE) -std=c++14 -fvisibility=hidden -fsanitize=address
LDFLAGS+=-std=c++14
ifdef NDEBUG
CFLAGS+=-O3 -DNDEBUG -fvisibility=hidden -fno-stack-check
CXXFLAGS+=-O3 -DNDEBUG -fvisibility=hidden -fno-stack-check
CFLAGS+=-O3 -DNDEBUG
CXXFLAGS+=-O3 -DNDEBUG
else
CFLAGS+=-O0 -g -DDEBUG_ENABLED -fvisibility=hidden -fno-stack-check
CXXFLAGS+=-O0 -g -DDEBUG_ENABLED -fvisibility=hidden -fno-stack-check
CFLAGS+=-O0 -g -DDEBUG_ENABLED
CXXFLAGS+=-O0 -g -DDEBUG_ENABLED
endif
TARGET=pEp-mini-json-adapter
LIB_TARGET=libjson-adapter.a
ALL_SOURCE=$(filter-out unittest_%.cc,$(wildcard *.cc))
LIB_SOURCE=$(filter-out miniadapter-%.cc,$(ALL_SOURCE))
MA_SOURCE=$(wildcard miniadapter-*.cc)
ifeq ($(MIME_LIB),etpan)
LDLIBS+=-letpan
MIME_LIB_A=$(LIBETPAN_FDIK)/libetpan.a
OMIT_NFC_SOURCE=
else ifeq ($(MIME_LIB),pEpMIME)
LDLUBS+=-lpEpMIME
MIME_LIB_A=$(PEP_MIME_PATH)/libpEpMIME.a
# is already in libpEpMIME:
OMIT_NFC_SOURCE=nfc.cc nfc_sets.cc
else
$(error "You must set MIME_LIB to 'etpan' or 'pEpMIME'!" )
endif
ALL_SOURCE=$(filter-out parse_mail.cc unittest_%.cc, $(wildcard *.cc))
MA_SOURCE=$(wildcard mini-adapter-*.cc)
LIB_SOURCE=$(filter-out $(MA_SOURCE) $(OMIT_NFC_SOURCE), $(ALL_SOURCE))
DEPENDS=$(subst .cc,.d,$(ALL_SOURCE))
ALL_OBJECTS=$(subst .d,.o,$(DEPENDS))
LIB_OBJECTS=$(subst .cc,.o,$(LIB_SOURCE))
MA_OBJECTS=$(subst .cc,.o,$(MA_SOURCE))
SPIRIT_SOURCE=$(wildcard json_spirit/*.cpp)
SPIRIT_OBJECTS=$(subst .cpp,.o,$(SPIRIT_SOURCE))
TEST_SOURCE=$(wildcard test_*.cc)
TEST_SOURCE=$(wildcard unittest_*.cc)
TEST_OBJECTS=$(subst .cc,.o,$(TEST_SOURCE))
TESTS=$(subst .cc,,$(TEST_SOURCE))
all: $(TARGET)
ALL_STATIC_LIBS=$(PEP_ENGINE)/libpEpEngine.a \
$(PEP_ADAPTER_LIBRARY)/libpEpAdapter.a \
$(PEP_WEBSERVER)/libpEpwebserver.a \
$(BOOST_LIBRARY_PATH)/libboost_filesystem$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_program_options$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_system$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_thread$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_regex$(BOOST_MT).a \
$(SEQUOIA_PGP)/libsequoia_openpgp_ffi.a \
$(MIME_LIB_A) \
$(ASN1_PATH)/libasn1.a \
$(LIBZ_LIBRARY_PATH)/libz.a \
$(SQLITE3_LIBRARY_PATH)/libsqlite3.a \
$(NETTLE)/libhogweed.a \
$(NETTLE)/libnettle.a \
$(GMP_LIBRARY_PATH)/libgmp.a \
$(ICONV_LIBRARY_PATH)/libiconv.a
all: $(TARGET) unittests parse_mail
%.d: %.cc
@set -e; rm -f $@; \
@ -81,35 +129,20 @@ $(LIB_TARGET): $(LIB_OBJECTS)
$(AR) -cr $@ $^
$(TARGET): $(LIB_TARGET) $(MA_OBJECTS) $(SPIRIT_OBJECTS)
$(CXX) $(LDFLAGS) -liconv \
$(CXX) $(LDFLAGS) \
$(MA_OBJECTS) $(SPIRIT_OBJECTS) $(LIB_TARGET) \
-lobjc -framework Foundation -framework Security \
$(PEP_WEBSERVER)/libpEpwebserver.a \
$(BOOST_LIBRARY_PATH)/libboost_filesystem$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_program_options$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_system$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_thread$(BOOST_MT).a \
$(BOOST_LIBRARY_PATH)/libboost_regex$(BOOST_MT).a \
$(ICONV_LIBRARY_PATH)/libiconv.a \
$(LIBZ_LIBRARY_PATH)/libz.a \
$(SQLITE3_LIBRARY_PATH)/libsqlite3.a \
$(GMP_LIBRARY_PATH)/libgmp.a \
$(NETTLE)/libnettle.a $(NETTLE)/libhogweed.a \
$(SEQUOIA_PGP)/libsequoia_ffi.a \
$(SEQUOIA_PGP)/libsequoia_openpgp_ffi.a \
$(LIBETPAN_FDIK)/libetpan.a \
$(PEP_ENGINE)/libpEpEngine.a \
$(ASN1_PATH)/libasn1.a \
$(PEP_ADAPTER_LIBRARY)/libpEpAdapter.a \
$(MA_OBJECTS) $(SPIRIT_OBJECTS) $(LIB_TARGET) -o "$@"
$(ALL_STATIC_LIBS)
-o "$@"
%.o: %.cc
$(CXX) $(CXXFLAGS) -c -o $@ $^
test_%: test_%.o $(TARGET)
$(CXX) $(LDFLAGS) $(TARGET) -o $@ $<
unittests: $(TEST_OBJECTS)
$(CXX) $(CXXFLAGS) -o $@ $^ $(ALL_STATIC_LIBS)
test: $(TESTS)
for i in $(TESTS) ; do ./$$i ; done
parse_mail: parse_mail.o $(LIB_TARGET) $(SPIRIT_OBJECTS)
$(CXX) $(CXXFLAGS) -o $@ $^ $(ALL_STATIC_LIBS) $(LIB_TARGET) -liconv
.PHONY: clean uninstall install
@ -122,7 +155,7 @@ uninstall:
for i in *.hh; do rm -f $(PREFIX)/include/pEp/\$i ; done
clean:
rm -vf *.o *.d *.d.* $(TARGET) $(TESTS)
rm -vf *.o *.d *.d.* $(TARGET) $(TESTS) encode_decode
local.conf:
@echo "# the following are directories with the source build" >> local.conf

@ -0,0 +1,172 @@
# Copyright 2017 pEp Security SA
#
# This file is part of pEp JSON Server Adapter.
#
# pEp JSON Server Adapter is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License, version 3, as
# published by the Free Software Foundation.
#
# pEp JSON Server Adapter is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with pEp JSON Server Adapter. If not, see <http://www.gnu.org/licenses/>.
include Makefile.conf-old
ifneq ($(wildcard local.conf-old),)
$(info ================================================)
$(info Overrides in \`local.conf\` are used.)
$(info ================================================)
endif
ifdef BUILD_CONFIG
$(info ================================================)
$(info Overrides in \`$(BUILD_CONFIG)\` are used.)
$(info ================================================)
endif
# These source files shall _not_ be part of the libjson-adapter.a:
NO_SOURCE=$(wildcard mini-adapter-*.cc) servertest.cc $(wildcard unittest_*.cc) parse_mail.cc
ALL_SOURCE=$(filter-out $(NO_SOURCE),$(wildcard json_spirit/*.cpp))
ALL_SOURCE+= prefix-config.cc
ALL_SOURCE+= $(filter-out $(NO_SOURCE),$(wildcard *.cc))
DEPENDS0=$(subst .cpp,.d,$(ALL_SOURCE))
DEPENDS=$(subst .cc,.d,$(DEPENDS0))
ALL_OBJECTS0=$(subst .cpp,.o,$(ALL_SOURCE))
ALL_OBJECTS=$(subst .cc,.o,$(ALL_OBJECTS0))
ifeq ($(BUILD_FOR),Linux)
LIBPATH=LD_LIBRARY_PATH
else
LIBPATH=DYLD_LIBRARY_PATH
endif
ifeq ($(BUILD_FOR),Linux)
LD_EAGER_VAR=LD_BIND_NOW=placeholder
else
LD_EAGER_VAR=DYLD_BIND_AT_LAUNCH=placeholder
endif
# Create a list of the extra library paths for the loader.
# Note that += can not be used here, as it changes the amount of whitespace
EXTRA_LIB_PATHS=$(PREFIX)/lib:
ifdef BOOST_LIB
EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(BOOST_LIB)):
endif
ifdef ENGINE_LIB
EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ENGINE_LIB)):
endif
ifdef ETPAN_LIB
EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
endif
ifdef GPGME_LIB
EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)):
endif
ifdef UUID_LIB
EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(UUID_LIB)):
endif
# Remove trailing ':'
EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=)
CMD_PFX=$(LIBPATH)=$(EXTRA_LIB_PATHS)
ifdef DEBUG
CMD_PFX+= $(LD_EAGER_VAR)
endif
.PHONY: all lib
all: $(TARGET) $(TARGET_TEST) $(TARGET_GTEST) parse_mail
lib: libjson-adapter.a
$(TARGET): mini-adapter-main.o mini-adapter-impl.o libjson-adapter.a
$(CXX) $(CPPFLAGS) $^ $(LDFLAGS) $(LDLIBS) -o $@
$(TARGET)-static: mini-adapter-main.o mini-adapter-impl.o libjson-adapter.a
$(CXX) $(CPPFLAGS) $(LDFLAGS) $^ \
/Users/lars/local/lib/libpEpEngine.a \
/Users/lars/local/lib/libpEpAdapter.a \
/Users/lars/local/lib/libetpan.a \
/Users/lars/hg/pEpEngine/asn.1/libasn1.a \
/usr/local/Cellar/libiconv/1.16/lib/libiconv.a \
/usr/local/lib/libboost_system-mt.a \
/usr/local/lib/libboost_filesystem-mt.a \
/usr/local/lib/libboost_program_options-mt.a \
/usr/local/lib/libboost_thread-mt.a \
/usr/local/lib/libboost_regex-mt.a /Users/lars/local/lib/libpEpwebserver.a \
/usr/local/Cellar/sqlite/3.33.0/lib/libsqlite3.a \
/usr/local/Cellar/zlib/1.2.11/lib/libz.a \
/usr/local/Cellar/libiconv/1.16/lib/libiconv.a \
/Users/lars/local/lib/libsequoia_ffi.a \
-o $@
$(TARGET_TEST): servertest.o libjson-adapter.a
$(CXX) $(CPPFLAGS) $^ $(LDFLAGS) $(LDLIBS) -o $@
$(TARGET_GTEST): unittest_json.o unittest_nfc.o unittest_decompose.o unittest_rpc.o \
unittest_logger.o unittest_pEp.o unittest_string.o \
gtest-all.o gtest_main.o libjson-adapter.a
$(CXX) $(CPPFLAGS) $^ $(LDFLAGS) $(LDLIBS) -o $@
parse_mail: parse_mail.o libjson-adapter.a
$(CXX) $(CPPFLAGS) $^ $(LDFLAGS) $(LDLIBS) -o $@
libjson-adapter.a: $(ALL_OBJECTS)
$(AR) rcs $@ $^
gtest-all.o: $(GTEST_DIR)/src/gtest-all.cc
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -o $@ -c $<
gtest_main.o: $(GTEST_DIR)/src/gtest_main.cc
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -o $@ -c $<
%.o: %.cc %.hh
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $<
%.d: %.cpp
@set -e; rm -f $@; \
$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
%.d: %.cc
@set -e; rm -f $@; \
$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
# If only the goal 'clean' is given, do not generate and include the '%.d' files.
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPENDS)
endif
.PHONY: install
install: all
mkdir -v -p "$(PREFIX)/bin" "$(PREFIX)/lib"
mkdir -v -p "$(HTML_DIRECTORY)"
cp -v ../html/* "$(HTML_DIRECTORY)"
cp -v libjson-adapter.a "$(PREFIX)/lib"
cp -v "$(TARGET)" "$(TARGET_TEST)" "$(TARGET_GTEST)" "$(PREFIX)/bin"
.PHONY: clean
clean:
rm -vf "$(TARGET)" "$(TARGET_TEST)" "$(TARGET_GTEST)" parse_mail
rm -vf *.o json_spirit/*.o
rm -vf *.a json_spirit/*.a
rm -vf *.d json_spirit/*.d
.PHONY: run
run:
@echo "The adapter must be installed for $< to work"
$(CMD_PFX) "$(PREFIX)/bin/$(TARGET)"
.PHONY: test
test:
@echo "The adapter must be installed for $< to work"
$(CMD_PFX) "$(PREFIX)/bin/$(TARGET_TEST)"
$(CMD_PFX) "$(PREFIX)/bin/$(TARGET_GTEST)"

@ -0,0 +1,161 @@
# Copyright 2017 pEp Security SA
#
# This file is part of pEp JSON Server Adapter.
#
# pEp JSON Server Adapter is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License, version 3, as
# published by the Free Software Foundation.
#
# pEp JSON Server Adapter is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with pEp JSON Server Adapter. If not, see <http://www.gnu.org/licenses/>.
HERE:=$(dir $(lastword $(MAKEFILE_LIST)))
######### General #########
BUILD_ON:=$(shell uname)
# This variable specifies the platform that the engine should be cross-compiled for.
BUILD_FOR=$(BUILD_ON)
# Cross-compiling is currently not supported.
# Maybe you can hack something with `local.conf`.
ifneq ($(BUILD_ON),$(BUILD_FOR))
$(error "I don't know how to build for $(BUILD_FOR) on $(BUILD_ON).")
endif
# Installation path prefix for libraries and binaries, except for HTML files
PREFIX=/usr
# Installation path for HTML files
HTML_DIRECTORY=$(PREFIX)/share/pEp/json-adapter/html
# Filename of the pEp JSON Server Adapter binary
TARGET=pEp-mini-json-adapter
# Filename of the pEp JSON Server Adapter testing binary
TARGET_TEST=servertest
# Filename of the unittest binary
TARGET_GTEST=unittests
# If empty, create a release build.
# Otherwise, create a debug build.
# This variable is ineffective in your local.conf file.
DEBUG=placeholder
# If empty, suppress compiler warnings.
# Otherwise, print warnings.
# This variable is ineffective in your local.conf file.
WARN=placeholder
######### C++ #########
TARGET_ARCH=
ifeq ($(BUILD_FOR),Linux)
CXX=g++ -std=c++14 -pthread -fPIC
else ifeq ($(BUILD_FOR),Darwin)
# clang issues a warning when "-pthread" is used for linking. So, include it in CXXFLAGS, and not in CXX
# "c++" != "clang"
CXX=c++ -std=c++14 -fPIC
endif
HTML_DIR ?= "html"
CPPFLAGS=-isystem $(GTEST_DIR)/include -DHTML_DIR=$(HTML_DIR)
ifeq ($(BUILD_FOR),Linux)
CXXFLAGS=-fstack-protector-all # -fdiagnostics-color=always
ifdef WARN
CXXFLAGS+= -Wall
else
CXXFLAGS+= -w
endif
ifdef DEBUG
CXXFLAGS+= -O0 -g -ggdb -DDEBUG_ENABLED
else
CXXFLAGS+= -O3 -DNDEBUG
endif
CXXFLAGS+=-fvisibility=hidden
else ifeq ($(BUILD_FOR),Darwin)
CXXFLAGS=-pthread -fstack-protector-all # -fcolor-diagnostics
ifdef WARN
CXXFLAGS+= -Wall
else
CXXFLAGS+= -w
endif
ifdef DEBUG
CXXFLAGS+= -O0 -g -DDEBUG_ENABLED
else
CXXFLAGS+= -O3 -DNDEBUG
endif
CXXFLAGS+=-fvisibility=hidden
endif
CXXFLAGS+= -Ijson_spirit $(BOOST_INC) $(ENGINE_INC) $(ETPAN_INC) $(GPGME_INC) $(UUID_INC)
LDFLAGS+= $(BOOST_LIB) $(ENGINE_LIB) $(ETPAN_LIB) $(GPGME_LIB) $(UUID_LIB)
ifeq ($(BUILD_FOR),Linux)
LDLIBS+= -lpEpEngine -lpEpAdapter -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -lboost_regex
GTEST_DIR=/usr/src/googletest/googletest/
else ifeq ($(BUILD_FOR),Darwin)
LDLIBS+= -lpEpEngine -lpEpAdapter -lboost_system-mt -lboost_filesystem-mt -lboost_program_options-mt -lboost_thread-mt -lboost_regex-mt
endif
LDLIBS+=$(WEBSERVER_LIB)
ifeq ($(MIME_LIB),etpan)
LDLIBS+=-letpan
else ifeq ($(MIME_LIB),pEpMIME)
LDLIBS+=-lpEpMIME
else
$(error "You must set MIME_LIB to 'etpan' or 'pEpMIME'!" )
endif
######### Google Test #########
#GTEST_DIR=
######### boost #########
BOOST_INC=
BOOST_LIB=
######### Engine #########
ENGINE_INC=-I$(HOME)/code/engine/build/include
ENGINE_LIB=-L$(HOME)/code/engine/build/lib
######### Etpan #########
ETPAN_INC=-I$(HOME)/code/libetpan/build/include
ETPAN_LIB=-L$(HOME)/code/libetpan/build/lib
######### pEp::Webserver #########
WEBSERVER_LIB=$(HOME)/local/lib/libpEpwebserver.a
######### GPGME #########
GPGME_INC=
GPGME_LIB=
######### OSSP uuid #########
UUID_INC=
UUID_LIB=
######### Footer #########
-include $(HERE)/local.conf-old
ifdef BUILD_CONFIG
-include $(BUILD_CONFIG)
endif

@ -0,0 +1,29 @@
#ifndef JSON_ADAPTER_CONFIG
#define JSON_ADAPTER_CONFIG
#if (__cplusplus >= 201606) // std::string_view is C++17.
# include <string_view>
typedef std::string_view sv;
#else // in C++11 / C++14 use boost::string_view instead.
# include <boost/utility/string_view.hpp>
typedef boost::string_view sv;
// if sv==boost::string_view these operations are not provided, neither by boost nor by the stdlib. :-(
inline
std::string& operator+=(std::string& s, sv v)
{
s.append(v.data(), v.size());
return s;
}
inline
std::string operator+(std::string s, sv v)
{
return s += v;
}
#endif // C++17 switch
#endif // JSON_ADAPTER_CONFIG

@ -127,19 +127,6 @@ public:
else {
// std::cerr << "|$ Param #" << U << " is not for output.\n";
}
#ifdef _MSC_BUILD
if (ret.type() == js::array_type && !ret.get_array().empty()) {
try {
const js::Array ret_ = ret.get_array()[0].get_array();
return ret_;
}
catch (std::runtime_error&) {
return ret;
}
}
else
#endif
return ret;
}
};

@ -151,12 +151,12 @@ struct Out
typedef T* c_type; // the according type in C function parameter
enum { is_output = true, need_input = !(PF & ParamFlag::NoInput) }; // if need_input=false it would no longer consume an element in the input parameter array.
explicit Out() : value{}
{ }
explicit Out(const T& t) : value{t}
Out() = default;
// JSON-160: (t) is necessary on GCC and MSVC. {t} does not work here. Whyever...
explicit Out(const T& t) : value(t)
{ }
~Out();
Out(const Out<T,PF>& other) = delete;

@ -1,3 +1,6 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
// converts a C++ string into NFC form
#include "nfc.hh"
@ -86,7 +89,7 @@ namespace
};
std::string escape(const std::string& s)
std::string escape(sv s)
{
std::string ret; ret.reserve(s.size() + 16 );
for(char c : s)
@ -173,8 +176,6 @@ namespace
} // end of anonymous namespace
std::ostream& operator<<(std::ostream& o, IsNFC is_nfc)
{
switch(is_nfc)
@ -271,11 +272,8 @@ uint32_t parseUtf8(const char*& c, const char* end)
}
std::string toUtf8(const std::u32string& u32)
void toUtf8(const char32_t c, std::string& ret)
{
std::string ret;
for(char32_t c : u32)
{
if(c<=0x7F)
{
ret += char(c);
@ -297,12 +295,21 @@ std::string toUtf8(const std::u32string& u32)
}else{
throw too_big(0, c);
}
}
std::string toUtf8(const std::u32string& u32)
{
std::string ret;
for(char32_t c : u32)
{
toUtf8(c, ret);
}
return ret;
}
illegal_utf8::illegal_utf8( const std::string& s, unsigned position, const std::string& reason)
illegal_utf8::illegal_utf8( sv s, unsigned position, const std::string& reason)
: std::runtime_error( "Illegal UTF-8 string \"" + escape(s) + "\" at position " + std::to_string(position) + ": " + reason )
{}
@ -312,7 +319,7 @@ illegal_utf8::illegal_utf8( const std::string& msg )
{}
void assert_utf8(const std::string& s)
void assert_utf8(sv s)
{
const char* begin = s.data();
const char* const end = s.data() + s.size();
@ -332,12 +339,12 @@ void assert_utf8(const std::string& s)
// creates a NFD string from s
std::u32string fromUtf8_decompose(const std::string& s)
std::u32string fromUtf8_decompose(sv s)
{
std::u32string u32s;
u32s.reserve( static_cast<std::size_t>(s.size()*1.25) );
const char* begin = s.c_str();
const char* end = s.c_str() + s.size();
const char* begin = s.data();
const char* end = s.data() + s.size();
for(; begin<end; ++begin)
{
unsigned u = parseUtf8(begin, end);
@ -416,7 +423,7 @@ std::u32string createNFC(std::u32string nfd)
}
IsNFC isNFC_quick_check(const std::string& s)
IsNFC isNFC_quick_check(sv s)
{
const char* begin = s.data();
const char* const end = s.data() + s.size();
@ -445,7 +452,7 @@ IsNFC isNFC_quick_check(const std::string& s)
}
bool isNFC(const std::string& s)
bool isNFC(sv s)
{
switch( isNFC_quick_check(s) )
{
@ -460,12 +467,23 @@ bool isNFC(const std::string& s)
throw -1; // could never happen, but compiler is too dumb to see this.
}
bool isUtf8(const char* begin, const char* end)
try{
for(; begin<end; ++begin)
{
(void)parseUtf8(begin, end);
}
return true;
}catch(const illegal_utf8&)
{
return false;
}
// s is ''moved'' to the return value if possible so no copy is done here.
std::string toNFC(std::string s)
std::string toNFC(sv s)
{
if(isNFC_quick_check(s)==IsNFC::Yes)
return s;
return std::string{s};
return toUtf8( createNFC( fromUtf8_decompose(s) ));
}

@ -1,6 +1,10 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef JSON_ADAPTER_NFC_HH
#define JSON_ADAPTER_NFC_HH
#include "config.hh" // to switch between std::string_view or boost::string_view.hh
#include <string>
#include <stdexcept>
#include <iosfwd>
@ -18,7 +22,7 @@ std::ostream& operator<<(std::ostream& o, IsNFC is_nfc);
class illegal_utf8 : public std::runtime_error
{
public:
illegal_utf8(const std::string& s, unsigned position, const std::string& reason);
illegal_utf8(sv, unsigned position, const std::string& reason);
protected:
explicit illegal_utf8(const std::string& message);
};
@ -27,25 +31,30 @@ protected:
// scans the char sequences and parses UTF-8 sequences. Detect UTF-8 errors and throws exceptions.
uint32_t parseUtf8(const char*& c, const char* end);
// converts 'c' into a UTF-8 sequence and adds it to 'ret'
void toUtf8(const char32_t c, std::string& ret);
// throws illegal_utf8 exception if s is not valid UTF-8
void assert_utf8(const std::string& s);
void assert_utf8(sv s);
// creates an NFD u32string from UTF-8 input string s
std::u32string fromUtf8_decompose(const std::string& s);
std::u32string fromUtf8_decompose(sv s);
// convert NFD to NFC
std::u32string createNFC(std::u32string nfd_string);
// return No or Maybe, if at least one character with NFC_Quickcheck class is "No" or "Maybe"
// might throw illegal_utf8 exception
IsNFC isNFC_quick_check(const std::string& s);
IsNFC isNFC_quick_check(sv s);
// runs first quick check and a deep test if quick check returns "Maybe".
bool isNFC(const std::string& s);
bool isNFC(sv s);
// returns true if the sequence is valid UTF-8
bool isUtf8(const char* begin, const char* end);
// converts a C++ string (in UTF-8) into NFC form
// s is ''moved'' to the return value if possible so no copy is done here.
std::string toNFC(std::string s);
std::string toNFC(sv s);
#endif // JSON_ADAPTER_NFC_HH

@ -0,0 +1,216 @@
// a program that parses (decodeS) a mail from stdin and prints the 'struct message' as JSON to stdout.
#include <pEp/mime.h>
#include <pEp/status_to_string.hh>
#include <pEp/slurp.hh>
#include "pEp-types.hh"
#include <string>
#include <iostream>
namespace js = json_spirit;
std::string S(const char* s)
{
if(s)
{
return '\"' + std::string(s) + '\"';
}else{
return "(NULL)";
}
}
std::string SX(const char* s, std::size_t length)
{
std::string ss(s); ss.resize( std::min(ss.size(), length) );
std::string ret; ret.reserve(ss.size() + 4);
ret = "";
char buf[8];
for(char c: ss)
{
if(c>' ' && c<127 && c!='\\' && c!='\"')
{
ret += c;
}else{
snprintf(buf, 7, "\\x%02hhx", uint8_t(c) );
ret += buf;
}
}
ret += "";
return ret;
}
std::ostream& operator<<(std::ostream& o, const bloblist_t* att)
{
if(att == nullptr)
{
return o << "(NULL)";
}
o << bloblist_length(att) << " elements:\n";
while(att)
{
o << "\t\t size=" << att->size
<< ", mime_type=" << S(att->mime_type)
<< ", filename=" << S(att->filename)
<< ", dispo=" << att->disposition
<< ", data=" << SX(att->value, 32) << ".\n";
att = att->next;
}
return o;
}
std::ostream& operator<<(std::ostream& o, const tm* t)
{
if(t==nullptr)
return o << "(NULL)";
char buf[64];
strftime(buf, 63, "%F %T", t);
return o << buf;
}
std::ostream& operator<<(std::ostream& o, const pEp_identity* ident)
{
if(ident==nullptr)
return o << "(NULL)";
o << "address=" << S(ident->address) << ", fpt=" << S(ident->fpr) << ", uid=" << S(ident->user_id) << ", name=" << S(ident->username);
return o;
}
std::ostream& operator<<(std::ostream& o, const identity_list* ident)
{
if(ident==nullptr)
return o << "(NULL)";
o << identity_list_length(ident) << " elements:\n";
while(ident)
{
o << "\t\t" << ident->ident << "\n";
ident = ident->next;
}
return o;
}
std::ostream& operator<<(std::ostream& o, const stringlist_t* sl)
{
if(sl==nullptr)
return o << "(NULL)";
o << stringlist_length(sl) << " elements:";
while(sl)
{
o << " " << S(sl->value);;
sl = sl->next;
}
return o;
}
std::ostream& operator<<(std::ostream& o, const stringpair_list_t* spl)
{
if(spl==nullptr)
return o << "(NULL)";
o << stringpair_list_length(spl) << " elements:\n";
while(spl)
{
o << "\t\t" << S(spl->value->key) << " -> " << S(spl->value->value) << "\n";
spl = spl->next;
}
return o;
}
void dump_message(const message* msg)
{
if(msg==nullptr)
{
std::cout << "Message: NULL!\n";
return;
}
std::cerr << "Message:\n";
std::cerr << "\tdir : " << msg->dir << "\n";
std::cerr << "\tid : " << S(msg->id) << "\n";
std::cerr << "\tshortmsg : " << S(msg->shortmsg) << "\n";
std::cerr << "\tlongmsg : " << S(msg->longmsg) << "\n";
std::cerr << "\tlongmsg_f : " << S(msg->longmsg_formatted) << "\n";
std::cerr << "\tattachmen : " << msg->attachments << "\n";
std::cerr << "\tsent : " << msg->sent << "\n";
std::cerr << "\trecv : " << msg->recv << "\n";
std::cerr << "\tfrom : " << msg->from << "\n";
std::cerr << "\tto : " << msg->to << "\n";
std::cerr << "\trecv_by : " << msg->recv_by << "\n";
std::cerr << "\tcc : " << msg->cc << "\n";
std::cerr << "\tbcc : " << msg->bcc << "\n";
std::cerr << "\treply_to : " << msg->reply_to << "\n";
std::cerr << "\tin_reply_t: " << msg->in_reply_to << "\n";
// TODO: refering_msg_ref
std::cerr << "\treferences: " << msg->references << "\n";
// TODO: refered_by
std::cerr << "\tkeywords : " << msg->keywords << "\n";
std::cerr << "\tcomments : " << S(msg->comments) << "\n";
std::cerr << "\topt_fields: " << msg->opt_fields << "\n";
std::cerr << "\tenc_format: " << msg->enc_format << "\n";
std::cerr << std::endl;
}
std::string read_from_stdin()
{
std::string mime_text;
std::string line;
while(std::cin)
{
std::getline(std::cin, line);
mime_text += line;
mime_text += "\r\n";
}
return mime_text;
}
PEP_STATUS parse_mail(const std::string& mime_text)
{
bool has_pEp_msg = false;
message* msg = nullptr;
const PEP_STATUS status = mime_decode_message(mime_text.data(), mime_text.size(), &msg, &has_pEp_msg);
std::cerr << "\n RESULT \n";
std::cerr << "status: " << pEp::status_to_string(status) << '\n';
std::cerr << "has_pEp_msg: " << (has_pEp_msg?"true":"false") << '\n';
dump_message(msg);
std::cerr << "\n ALL DONE \n";
return status;
}
int main(int argc, char** argv)
{
if(argc==1 || argv[1]==std::string("-"))
{
const std::string mime_text = read_from_stdin();
return parse_mail(mime_text);
}
for(int a=1; a<argc; ++a)
{
std::cout << "=== File #" << a << ": \"" << argv[a] << "\" ===\n";
const std::string mime_text = pEp::slurp(argv[a]);
const PEP_STATUS status = parse_mail(mime_text);
if(status!=PEP_STATUS_OK)
{
return status;
}
}
return 0;
}

@ -124,6 +124,30 @@ TEST_P( ToJsonTest, Meh )
}
TEST( ToJsonTest, Arrays )
{
js::Array arr;
EXPECT_EQ( js::write(arr), "[]" );
js::Value varr{arr};
EXPECT_EQ( js::write(varr), "[]" );
// that does not work on gcc (Linux) & MSVC, for whatever reasons.
// js::Array aarr{arr};
// EXPECT_EQ( js::write(aarr), "[]" );
// but that works. Bizarre...
js::Array aarr(arr);
EXPECT_EQ( js::write(aarr), "[]" );
Out<js::Array> oarr{arr};
EXPECT_EQ( js::write(oarr.to_json()), "[]" );
arr.push_back(42);
arr.push_back("Meh");
EXPECT_EQ( js::write(arr), "[42,\"Meh\"]" );
}
TEST( ToJsonTest, IllegalUtf8 )
{
// examples from UTF-8 stress test:

@ -23,10 +23,39 @@ std::ostream& operator<<(std::ostream& os, const Value& value)
return os;
}
std::ostream& operator<<(std::ostream& os, const Object& obj)
{
js::write(obj, os, 0x1B, 0);
return os;
}
} // end of namespace json_spirit
namespace {
// HACK: Define a dummy type, so I can define an operator<< which is used by GTest,
// which refuses to pretty-print js::Object directly, for whatever reason. *sigh*
struct O
{
js::Object obj;
};
std::ostream& operator<<(std::ostream& os, const O& o)
{
js::write(o.obj, os, 0x1B, 0);
return os;
}
bool operator==(const O& o1, const O& o2)
{
return o1.obj == o2.obj;
}
/// END OF HACK
class DummyAdapter : public JsonAdapterBase
{
public:
@ -85,6 +114,17 @@ char* tohex(const char* input, size_t length)
}
js::Array gen_array(size_t num_elements)
{
js::Array a;
for(unsigned u=0; u<num_elements; ++u)
{
a.push_back( js::Value( static_cast<int>(u)) );
}
return a;
}
const FunctionMap test_functions = {
FP( "add_mul_simple", new Func<int, In<int>, In<int>, In<int>>( &add_mul_simple )),
FP( "add_mul_inout" , new Func<char*, In<int>, In<c_string>, InOutP<int>, Out<char*>>( &add_mul_inout )),
@ -92,6 +132,7 @@ const FunctionMap test_functions = {
FP( "tohex_1", new Func<char*, In<c_string>, In<size_t>>( &tohex )), // with explicit length parameter
FP( "tohex_2", new Func<char*, In<c_string>, InLength<>>( &tohex )), // with implicit length parameter, with dummy JSON parameter
FP( "tohex_3", new Func<char*, In<c_string>, InLength<ParamFlag::NoInput>>( &tohex )), // with implicit length parameter, without JSON parameter
FP( "gen_array", new Func<js::Array, In<size_t>>( &gen_array )),
// TODO: test FuncCache stuff, too. :-/
// FP( "cache_s1", new FuncCache<void, In_Pep_Session, In<c_string>> ( "cache_s1", &cache_s1 )),
@ -111,8 +152,6 @@ std::ostream& operator<<(std::ostream& o, const TestEntry& tt)
}
const std::vector<TestEntry> testValues =
{
{ "{\"jsonrpc\":\"2.0\", \"id\":21, \"method\":\"add_mul_simple\", \"params\":[10,11,12]}",
@ -150,6 +189,16 @@ const std::vector<TestEntry> testValues =
"{\"jsonrpc\":\"2.0\", \"id\":30, \"result\":{ \"outParams\":[], \"return\":\"00 f0 9f 99 87\"}}"
},
{ "{\"jsonrpc\":\"2.0\", \"id\":40, \"method\":\"gen_array\", \"params\":[0]}",
"{\"jsonrpc\":\"2.0\", \"id\":40, \"result\":{ \"outParams\":[], \"return\":[]}}"
},
{ "{\"jsonrpc\":\"2.0\", \"id\":40, \"method\":\"gen_array\", \"params\":[1]}",
"{\"jsonrpc\":\"2.0\", \"id\":40, \"result\":{ \"outParams\":[], \"return\":[0]}}"
},
{ "{\"jsonrpc\":\"2.0\", \"id\":40, \"method\":\"gen_array\", \"params\":[2]}",
"{\"jsonrpc\":\"2.0\", \"id\":40, \"result\":{ \"outParams\":[], \"return\":[0,1]}}"
},
};
} // end of anonymous namespace
@ -178,5 +227,5 @@ TEST_P( RpcTest, Meh )
js::Object result_obj = actual_result.get_obj();
js::Object::iterator q = std::find_if(result_obj.begin(), result_obj.end(), [](const js::Pair& v){ return js::Config::get_name(v) == "thread_id"; } );
result_obj.erase( q );
EXPECT_EQ( expected_result, result_obj );
EXPECT_EQ( O{expected_result.get_obj()}, O{result_obj} );
}

Loading…
Cancel
Save