Rolled back to revision 1982. Sorry all, checked in wrong branch to default
authorKrista Bennett <krista@pep-project.org>
Tue, 22 Aug 2017 15:34:17 +0200
changeset 1988ea7bceda4dc8
parent 1983 6e5243097e3b
child 1989 d3e5bc4a9854
Rolled back to revision 1982. Sorry all, checked in wrong branch to default
.hgignore
Makefile
Makefile.conf
README.txt
asn.1/Makefile
build-config/Darwin.conf
build-config/Linux.conf
build-config/common.conf
db/Makefile
src/Makefile
src/message_api.c
sync/Makefile
test/Makefile
     1.1 --- a/.hgignore	Tue Aug 22 09:08:15 2017 +0200
     1.2 +++ b/.hgignore	Tue Aug 22 15:34:17 2017 +0200
     1.3 @@ -3,6 +3,7 @@
     1.4  ^asn\.1/Makefile\.am\.sample$
     1.5  ^asn\.1/libasn1\.a$
     1.6  .*xcuserdata/
     1.7 +^build/
     1.8  
     1.9  syntax: glob
    1.10  *.orig
     2.1 --- a/Makefile	Tue Aug 22 09:08:15 2017 +0200
     2.2 +++ b/Makefile	Tue Aug 22 15:34:17 2017 +0200
     2.3 @@ -1,27 +1,33 @@
     2.4 -# this file is under GNU General Public License v3.0
     2.5 +# Copyright 2017, pEp Foundation
     2.6 +# This file is part of pEpEngine
     2.7 +# This file may be used under the terms of the GNU General Public License version 3
     2.8  # see LICENSE.txt
     2.9  
    2.10 +HERE_REL := $(notdir $(CURDIR))
    2.11 +
    2.12  include Makefile.conf
    2.13  
    2.14 -# add it to the environment of all executed programs:
    2.15 -export YML_PATH
    2.16 +# YML_PATH is needed in the environment of every call to a program of the YML2 distribution
    2.17 +export YML_PATH=$(YML2_PATH)
    2.18  
    2.19 -
    2.20 +.PHONY: all
    2.21  all:
    2.22  	$(MAKE) -C asn.1 generate
    2.23  	$(MAKE) -C asn.1
    2.24  	$(MAKE) -C sync
    2.25  	$(MAKE) -C src all
    2.26  
    2.27 -.PHONY: clean build_test test package install uninstall db
    2.28 -
    2.29 +.PHONY: install
    2.30  install: all
    2.31  	$(MAKE) -C src install
    2.32  	$(MAKE) -C asn.1 install
    2.33  
    2.34 +.PHONY: uninstall
    2.35  uninstall:
    2.36  	$(MAKE) -C src uninstall
    2.37 +	$(MAKE) -C asn.1 uninstall
    2.38  
    2.39 +.PHONY: clean
    2.40  clean:
    2.41  	$(MAKE) -C src clean
    2.42  	$(MAKE) -C test clean
    2.43 @@ -29,26 +35,19 @@
    2.44  	$(MAKE) -C sync clean
    2.45  	$(MAKE) -C asn.1 clean
    2.46  
    2.47 +.PHONY: test
    2.48  test: all
    2.49  	$(MAKE) -C test test
    2.50  	$(MAKE) -C test unit_tests
    2.51  
    2.52 +.PHONY: unit_tests
    2.53  unit_tests: all
    2.54  	$(MAKE) -C test unit_tests
    2.55  
    2.56 +.PHONY: package
    2.57  package: clean
    2.58 -	cd .. ; COPYFILE_DISABLE=true tar cjf pEpEngine.tar.bz2 pEpEngine
    2.59 +	cd .. ; COPYFILE_DISABLE=true tar cjf pEpEngine.tar.bz2 "$(HERE_REL)"
    2.60  
    2.61 +.PHONY: db
    2.62  db:
    2.63  	$(MAKE) -C db db
    2.64 -
    2.65 -windist:
    2.66 -ifneq ($(BUILD_FOR),Windoze)
    2.67 -	@echo use BUILD_FOR=Windoze \(did you forget -e ?\)
    2.68 -else
    2.69 -	make clean
    2.70 -	$(MAKE) all
    2.71 -	$(MAKE) -C test all
    2.72 -	zip -j pEpEngine-dist.zip src/pEpEngine.h src/keymanagement.h src/pEpEngine.dll src/pEpEngine.def test/pEpEngineTest.exe test/*.asc test/*.key db/*.db test/*.txt test/*.asc src/*.sql
    2.73 -endif
    2.74 -
     3.1 --- a/Makefile.conf	Tue Aug 22 09:08:15 2017 +0200
     3.2 +++ b/Makefile.conf	Tue Aug 22 15:34:17 2017 +0200
     3.3 @@ -1,30 +1,21 @@
     3.4 -# this file is in the Public Domain
     3.5 +# Copyright 2017, pEp Foundation
     3.6 +# This file is part of pEpEngine
     3.7 +# This file may be used under the terms of the GNU General Public License version 3
     3.8 +# see LICENSE.txt
     3.9  
    3.10 -BUILD_ON=$(shell uname)
    3.11 -BUILD_FOR=$(BUILD_ON)
    3.12 -OPTIMIZE=-g -Wall -O0 -fPIC -DDEBUG_ERRORSTACK
    3.13 -#OPTIMIZE=-O3 -Wall -DNDEBUG -std=c99
    3.14 -LD=$(CC)
    3.15 -#CC=gcc-mp-4.9 -std=c99 -fstrict-aliasing -Wstrict-aliasing=3
    3.16 -#LD=gcc-mp-4.9
    3.17 -SYSTEM_DB=/usr/local/share/pEp/system.db
    3.18 -PREFIX=$(HOME)
    3.19 -YML2PROC=$(HOME)/yml2/yml2proc
    3.20 -YML_OPTS=--encoding=utf8
    3.21 -YML_PATH=$(HOME)/yml2
    3.22 -ASN1C=asn1c
    3.23 -ASN1C_INCLUDE=/opt/local/share/asn1c
    3.24 -#ETPAN_IN=$(HOME)
    3.25 -#LIBGPGME=/opt/local/lib/libgpgme.11.dylib
    3.26 +# This file assembles all the make variables that a maintainer or dev may want to taylor to his or her needs on a given platform.
    3.27  
    3.28 -# C makros (not environment variables) to overwrite:
    3.29 -#
    3.30 -# DEFAULT_KEYSERVER - string with default keyserver
    3.31 -# CRASHDUMP_DEFAULT_LINES - number of log lines to deliver for crashdumps
    3.32 +# To use custom build configuration variables, put them in a new file with the path `build-config/<name>.conf`. Execute `export PLATFORM_OVERRIDE=<name>` before running make. If this environment variable is not set, make will load a default configuration for your platform.
    3.33  
    3.34 -#EXTRAMACROS=-DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23
    3.35 +BUILD_CONFIG:=$(dir $(lastword $(MAKEFILE_LIST)))build-config
    3.36  
    3.37 -# second instance for testing
    3.38 -
    3.39 -#EXTRAMACROS=-DLOCAL_DB_FILENAME=\".pEp_management2.db\"
    3.40 -#TARGET=libpEpEngine2.dylib 
    3.41 +include $(BUILD_CONFIG)/common.conf
    3.42 +# cross-compiling is currently not supported, but maybe you can hack something with `PLATFORM_OVERRIDE`
    3.43 +ifeq ($(BUILD_ON),$(BUILD_FOR))
    3.44 +    include $(BUILD_CONFIG)/$(BUILD_ON).conf
    3.45 +else
    3.46 +    $(error I don't know how to build for $(BUILD_FOR) on $(BUILD_ON))
    3.47 +endif
    3.48 +ifdef PLATFORM_OVERRIDE
    3.49 +    include $(BUILD_CONFIG)/$(PLATFORM_OVERRIDE).conf
    3.50 +endif
     4.1 --- a/README.txt	Tue Aug 22 09:08:15 2017 +0200
     4.2 +++ b/README.txt	Tue Aug 22 15:34:17 2017 +0200
     4.3 @@ -60,8 +60,7 @@
     4.4  
     4.5  * NetPGP/p≡p, see https://cacert.pep.foundation/dev/repos/netpgp-et/
     4.6  
     4.7 -* Asn1c, download from https://lionet.info/soft/asn1c-0.9.27.tar.gz
     4.8 -       (Debian's version 0.9.24 does not work)
     4.9 +* Asn1c, download from https://lionet.info/soft/asn1c-0.9.27.tar.gz . Debian 8's v0.9.24 does not work. Debian 9's v0.9.27 generates non-POSIX code, that will cause issues when the engine is compiled with '-std=c99'. Thus, use v0.9.28 for best results.
    4.10  
    4.11  * yml2, which needs lxml (where to get?)
    4.12  
     5.1 --- a/asn.1/Makefile	Tue Aug 22 09:08:15 2017 +0200
     5.2 +++ b/asn.1/Makefile	Tue Aug 22 15:34:17 2017 +0200
     5.3 @@ -1,37 +1,35 @@
     5.4 -# This file is under GNU General Public License 3.0
     5.5 +# Copyright 2017, pEp Foundation
     5.6 +# This file is part of pEpEngine
     5.7 +# This file may be used under the terms of the GNU General Public License version 3
     5.8  # see LICENSE.txt
     5.9  
    5.10  include ../Makefile.conf
    5.11  
    5.12 -ifeq ($(BUILD_ON),Linux)
    5.13 -ifeq ($(BUILD_FOR),Linux)
    5.14 -
    5.15 -CC=gcc
    5.16 -CFLAGS?=-fPIC
    5.17 -else
    5.18 -$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
    5.19 -endif
    5.20 -endif
    5.21 -
    5.22 -ALL_SOURCE=$(subst $(NO_SOURCE),,$(wildcard *.c))
    5.23 +ALL_SOURCE=$(wildcard *.c)
    5.24  ALL_OBJECTS=$(subst .c,.o,$(ALL_SOURCE))
    5.25  
    5.26  libasn1.a: $(ALL_OBJECTS)
    5.27 -	ar -rc $@ $(ALL_OBJECTS)
    5.28 +	ar -rc $@ $^
    5.29  
    5.30 +# "converter-sample.c" is the example file containing a "main()" function generated by ans1c.
    5.31 +.PHONY: generate
    5.32  generate: Sync-Protocols.c
    5.33  	rm -f converter-sample.c
    5.34  
    5.35  %.o: %.c %.h
    5.36 -	$(CC) $(CFLAGS) $(OPTIMIZE) -I. -I$(ASN1C_INCLUDE) -c $< -o $@
    5.37 +	$(CC) $(CFLAGS) $(CFLAGS_GENERATED) -I. $(ASN1C_INC) -c $< -o $@
    5.38  
    5.39 -Sync-Protocols.c: protocols.asn1 devicegroup.asn1 pEp.asn1
    5.40 -	$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=PEP.Message pEp.asn1 devicegroup.asn1 $<
    5.41 +Sync-Protocols.c: pEp.asn1 devicegroup.asn1 protocols.asn1
    5.42 +	$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=PEP.Message $^
    5.43  
    5.44  .PHONY: clean
    5.45 -
    5.46  clean:
    5.47  	rm -f *.a *.o *.c *.h *.sample
    5.48  
    5.49 +.PHONY: install
    5.50  install: libasn1.a
    5.51  	cp $< $(PREFIX)/lib/
    5.52 +
    5.53 +.PHONY: uninstall
    5.54 +uninstall:
    5.55 +	rm -f $(PREFIX)/lib/libasn1.a
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/build-config/Darwin.conf	Tue Aug 22 15:34:17 2017 +0200
     6.3 @@ -0,0 +1,55 @@
     6.4 +# Copyright 2017, pEp Foundation
     6.5 +# This file is part of pEpEngine
     6.6 +# This file may be used under the terms of the GNU General Public License version 3
     6.7 +# see LICENSE.txt
     6.8 +
     6.9 +######### General #########
    6.10 +TARGET=libpEpEngine.dylib
    6.11 +
    6.12 +######### C #########
    6.13 +# clang issues a warning when "-pthread" is used for linking. So, include it in CFLAGS, and not in CC
    6.14 +CC=clang -std=c99
    6.15 +CFLAGS=-pthread -fPIC -fstrict-aliasing -fcolor-diagnostics
    6.16 +ifdef WARN
    6.17 +    CFLAGS+= -Wall -pedantic
    6.18 +else
    6.19 +    CFLAGS+= -w
    6.20 +endif
    6.21 +ifdef DEBUG
    6.22 +    CFLAGS+= -O0 -g -DDEBUG_ERRORSTACK
    6.23 +else
    6.24 +    CFLAGS+= -O3 -DNDEBUG
    6.25 +endif
    6.26 +CFLAGS_GENERATED=
    6.27 +
    6.28 +######### C++ #########
    6.29 +# clang issues a warning when "-pthread" is used for linking. So, include it in CXXFLAGS, and not in CXX
    6.30 +CXX=clang -std=c++11
    6.31 +CXXFLAGS=-pthread -fcolor-diagnostics -I../src -I../asn.1 $(ETPAN_INC)
    6.32 +ifdef WARN
    6.33 +    CXXFLAGS+=
    6.34 +else
    6.35 +    CXXFLAGS+= -w
    6.36 +endif
    6.37 +ifdef DEBUG
    6.38 +    CXXFLAGS+= -O0 -g
    6.39 +else
    6.40 +    CXXFLAGS+= -O3 -DNDEBUG
    6.41 +endif
    6.42 +
    6.43 +######### C and C++ #########
    6.44 +
    6.45 +######### YML2 #########
    6.46 +
    6.47 +######### asn1c #########
    6.48 +
    6.49 +######### libetpan #########
    6.50 +
    6.51 +######### OpenPGP #########
    6.52 +LIBGPGME=libgpgme.dylib
    6.53 +GPGME_LIB=-L/opt/local/lib
    6.54 +GPGME_INC=-I/opt/local/include
    6.55 +
    6.56 +######### Engine internals #########
    6.57 +
    6.58 +######### Misc #########
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/build-config/Linux.conf	Tue Aug 22 15:34:17 2017 +0200
     7.3 @@ -0,0 +1,54 @@
     7.4 +# Copyright 2017, pEp Foundation
     7.5 +# This file is part of pEpEngine
     7.6 +# This file may be used under the terms of the GNU General Public License version 3
     7.7 +# see LICENSE.txt
     7.8 +
     7.9 +######### General #########
    7.10 +TARGET=libpEpEngine.so
    7.11 +
    7.12 +######### C #########
    7.13 +CC=gcc -std=c99 -pthread
    7.14 +CFLAGS=-fPIC -fstrict-aliasing -fdiagnostics-color=always
    7.15 +ifdef WARN
    7.16 +    CFLAGS+= -Wall -pedantic -Wstrict-aliasing=3
    7.17 +else
    7.18 +    CFLAGS+= -w
    7.19 +endif
    7.20 +ifdef DEBUG
    7.21 +    CFLAGS+= -Og -ggdb -DDEBUG_ERRORSTACK
    7.22 +else
    7.23 +    CFLAGS+= -O3 -DNDEBUG
    7.24 +endif
    7.25 +# '-Wno-cpp' is required to suppress the warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" otherwise printed during the compilation of every asn1c-generated C file.
    7.26 +CFLAGS_GENERATED=-Wno-cpp
    7.27 +
    7.28 +######### C++ #########
    7.29 +CXX=g++ -std=gnu++11 -pthread
    7.30 +CXXFLAGS=-fdiagnostics-color=always -I../src -I../asn.1 $(ETPAN_INC)
    7.31 +ifdef WARN
    7.32 +    CXXFLAGS+=
    7.33 +else
    7.34 +    CXXFLAGS+= -w
    7.35 +endif
    7.36 +ifdef DEBUG
    7.37 +    CXXFLAGS+= -Og -ggdb
    7.38 +else
    7.39 +    CXXFLAGS+= -O3 -DNDEBUG
    7.40 +endif
    7.41 +
    7.42 +######### C and C++ #########
    7.43 +
    7.44 +######### YML2 #########
    7.45 +
    7.46 +######### asn1c #########
    7.47 +
    7.48 +######### libetpan #########
    7.49 +
    7.50 +######### OpenPGP #########
    7.51 +LIBGPGME=libgpgme.so.11
    7.52 +GPGME_LIB=
    7.53 +GPGME_INC=
    7.54 +
    7.55 +######### Engine internals #########
    7.56 +
    7.57 +######### Misc #########
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/build-config/common.conf	Tue Aug 22 15:34:17 2017 +0200
     8.3 @@ -0,0 +1,88 @@
     8.4 +# Copyright 2017, pEp Foundation
     8.5 +# This file is part of pEpEngine
     8.6 +# This file may be used under the terms of the GNU General Public License version 3
     8.7 +# see LICENSE.txt
     8.8 +
     8.9 +# General remark: to use (only) system libraries, set all the *_INC and *_LIB variables to the empty string.
    8.10 +
    8.11 +######### General #########
    8.12 +BUILD_ON:=$(shell uname)
    8.13 +BUILD_FOR=$(BUILD_ON)
    8.14 +# Installation path prefix for libraries and binaries, except for system.db
    8.15 +PREFIX=$(HOME)
    8.16 +# Installation path for system.db
    8.17 +SYSTEM_DB=/usr/local/share/pEp/system.db
    8.18 +# Filename of the pEpEngine library
    8.19 +#TARGET This option is platform-specific
    8.20 +# If not empty, create a debug build
    8.21 +DEBUG=placeholder
    8.22 +# If not empty, print compiler warnings
    8.23 +WARN=placeholder
    8.24 +
    8.25 +######### C #########
    8.26 +#CC This option is platform-specific
    8.27 +CPPFLAGS=
    8.28 +#CFLAGS This option is platform-specific
    8.29 +# Additional CFLAGS used for compiling ASN1C-generated code
    8.30 +#CFLAGS_GENERATED This option is platform-specific
    8.31 +
    8.32 +######### C++ #########
    8.33 +#CXX This option is platform-specific
    8.34 +#CXXFLAGS This option is platform-specific
    8.35 +
    8.36 +######### C and C++ #########
    8.37 +TARGET_ARCH=
    8.38 +# The following two variables will be appended to. You can thus not set them to a fixed value here.
    8.39 +LDFLAGS=
    8.40 +LDLIBS=
    8.41 +
    8.42 +######### YML2 #########
    8.43 +YML2_PATH=$(HOME)/yml2
    8.44 +YML2_PROC=$(YML2_PATH)/yml2proc
    8.45 +YML2_OPTS=--encoding=utf8
    8.46 +
    8.47 +######### asn1c #########
    8.48 +# asn1c binary
    8.49 +ASN1C=asn1c
    8.50 +# asn1c include search flag
    8.51 +ASN1C_INC=
    8.52 +#ASN1C_INC= -I$(HOME)/include
    8.53 +
    8.54 +######### libetpan #########
    8.55 +# libetpan library search flag
    8.56 +ETPAN_LIB=-L$(PREFIX)/lib
    8.57 +# libetpan include search flag
    8.58 +ETPAN_INC=-I$(PREFIX)/include
    8.59 +
    8.60 +######### OpenPGP #########
    8.61 +# Path of GPG binary
    8.62 +GPG_CMD=gpg
    8.63 +ifneq ($(shell which gpg2),)
    8.64 +    GPG_CMD = gpg2
    8.65 +endif
    8.66 +# Selects OpenPGP implementation. must be either `GPG` or `NETPGP`
    8.67 +OPENPGP=GPG
    8.68 +# Path of libGPGME binary
    8.69 +#LIBGPGME This option is platform-specific
    8.70 +# libGPGME library search flag
    8.71 +#GPGME_LIB= This option is platform-specific
    8.72 +# libGPGME include search flag
    8.73 +#GPGME_INC= This option is platform-specific
    8.74 +# NETPGP library search flag
    8.75 +NETPGP_LIB=
    8.76 +#NETPGP_LIB=-L$(PREFIX)/lib
    8.77 +# libGPGME include search flag
    8.78 +NETPGP_INC=
    8.79 +#NETPGP_INC=-I$(PREFIX)/include
    8.80 +
    8.81 +######### Engine internals #########
    8.82 +# C macros (not environment variables) that can be overridden:
    8.83 +# DEFAULT_KEYSERVER - string with default keyserver
    8.84 +# CRASHDUMP_DEFAULT_LINES - number of log lines to deliver for crashdumps
    8.85 +# Example:
    8.86 +#    EXTRA_MACROS=-DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23
    8.87 +EXTRA_MACROS=
    8.88 +
    8.89 +######### Misc #########
    8.90 +# FIXME Maybe include these variables here. Check how they are used throughout the project before setting them here
    8.91 +#LLDB_BIN
     9.1 --- a/db/Makefile	Tue Aug 22 09:08:15 2017 +0200
     9.2 +++ b/db/Makefile	Tue Aug 22 15:34:17 2017 +0200
     9.3 @@ -1,22 +1,26 @@
     9.4 -# This file is under GNU General Public License 3.0
     9.5 +# Copyright 2017, pEp Foundation
     9.6 +# This file is part of pEpEngine
     9.7 +# This file may be used under the terms of the GNU General Public License version 3
     9.8  # see LICENSE.txt
     9.9  
    9.10  include ../Makefile.conf
    9.11  
    9.12 +.PHONY: db
    9.13  db: system.db
    9.14  
    9.15 -dicos=$(wildcard *.csv)
    9.16 +DICOS = $(wildcard *.csv)
    9.17  
    9.18 -system.db: create_system_db.sql $(dicos)
    9.19 +# The 'mv' keeps a backup db around
    9.20 +system.db: create_system_db.sql $(DICOS)
    9.21  	-mv -f $@ $@~ 
    9.22  	sqlite3 -batch $@ < $<
    9.23 -	for c in $(dicos); do echo $$c ; echo .import "$$c" wordlist | sqlite3 -batch -csv $@ ; done
    9.24 +	for c in $(DICOS) ; do echo "$$c" ; echo .import "$$c" wordlist | sqlite3 -batch -csv $@ ; done
    9.25  
    9.26 -.PHONY: clean install
    9.27 -
    9.28 +.PHONY: install
    9.29  install: system.db
    9.30  	mkdir -p `dirname $(SYSTEM_DB)`
    9.31  	cp system.db $(SYSTEM_DB)
    9.32  
    9.33 +.PHONY: clean
    9.34  clean:
    9.35 -	rm -f system.db
    9.36 +	rm -f system.db system.db~
    10.1 --- a/src/Makefile	Tue Aug 22 09:08:15 2017 +0200
    10.2 +++ b/src/Makefile	Tue Aug 22 15:34:17 2017 +0200
    10.3 @@ -1,70 +1,55 @@
    10.4 +# Copyright 2017, pEp Foundation
    10.5 +# This file is part of pEpEngine
    10.6 +# This file may be used under the terms of the GNU General Public License version 3
    10.7 +# see LICENSE.txt
    10.8 +
    10.9  include ../Makefile.conf
   10.10  
   10.11 -ETPAN_IN?=$(HOME)
   10.12 +CFLAGS+= $(ETPAN_INC) -I../asn.1 -DSYSTEM_DB=\"$(SYSTEM_DB)\" $(EXTRA_MACROS)
   10.13 +LDFLAGS+= $(ETPAN_LIB) -L../asn.1 -shared
   10.14 +LDLIBS+= -lc -lasn1 -letpan 
   10.15  
   10.16  ifeq ($(BUILD_ON),Darwin)
   10.17 -ifeq ($(BUILD_FOR),Darwin)
   10.18 -
   10.19 -TARGET?=libpEpEngine.dylib
   10.20 -MACOSX_VERSION_MIN=10.6
   10.21 -LIBGPGME?=libgpgme.dylib
   10.22 -CC?=clang -std=c99 -pthread
   10.23 -LD?=clang
   10.24 -CFLAGS?= -I$(ETPAN_IN)/include -I/opt/local/include $(OPTIMIZE) -pedantic \
   10.25 -	-DSYSTEM_DB=\"$(SYSTEM_DB)\" -I../asn.1 $(EXTRAMACROS)
   10.26 -LDFLAGS?= -lc -shared -arch x86_64 \
   10.27 -	-L$(ETPAN_IN)/lib -L/usr/lib -L/opt/local/lib -letpan -lsqlite3 -L../asn.1 -lasn1 -lz -liconv
   10.28 -
   10.29 +    ifeq ($(BUILD_FOR),Darwin)
   10.30 +        CFLAGS+= -DSQLITE_THREADSAFE=1
   10.31 +        #LDFLAGS+= -L/opt/local/lib
   10.32 +        LDLIBS+= -lsqlite3 -lz -liconv
   10.33 +    else
   10.34 +        $(error I don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
   10.35 +    endif
   10.36 +else ifeq ($(BUILD_ON),Linux)
   10.37 +    ifeq ($(BUILD_FOR),Linux)
   10.38 +        CFLAGS+= -DSQLITE_THREADSAFE=1 -D_GNU_SOURCE
   10.39 +        LDLIBS+= -ldl -luuid
   10.40 +    else
   10.41 +        $(error I don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
   10.42 +    endif
   10.43  else
   10.44 -$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
   10.45 +    $(error I don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
   10.46  endif
   10.47  
   10.48 -else ifeq ($(BUILD_ON),Linux)
   10.49 -ifeq ($(BUILD_FOR),Linux)
   10.50 -
   10.51 -TARGET=libpEpEngine.so
   10.52 -LIBGPGME?=libgpgme.so.11
   10.53 -CC=gcc -std=c99
   10.54 -CFLAGS?= -I$(ETPAN_IN)/include $(OPTIMIZE) -fPIC -pedantic -DSYSTEM_DB=\"$(SYSTEM_DB)\" \
   10.55 -	-DSQLITE_THREADSAFE=1 -D_GNU_SOURCE -I../asn.1 $(EXTRAMACROS)
   10.56 -LDFLAGS?= -L$(ETPAN_IN)/lib -shared -lc -ldl -letpan -lpthread -L../asn.1 -lasn1 -luuid
   10.57 -
   10.58 +ifeq ($(OPENPGP),GPG)
   10.59 +    NO_SOURCE=pgp_netpgp.c
   10.60 +    CFLAGS+= -DUSE_GPG $(GPGME_INC) -DLIBGPGME=\"$(LIBGPGME)\"
   10.61 +    LDFLAGS+= $(GPGME_LIB)
   10.62 +    # No extra LDLIBS are needed here, because GPGME is dynamically loaded
   10.63 +else ifeq ($(OPENPGP),NETPGP)
   10.64 +    NO_SOURCE=pgp_gpg.c
   10.65 +    CFLAGS+= -DUSE_NETPGP $(NETGPG_INC)
   10.66 +    LDFLAGS+= $(NETGPG_LIB)
   10.67 +    LDLIBS+= -lnetpgp -lcurl
   10.68  else
   10.69 -$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
   10.70 -endif
   10.71 -
   10.72 -else
   10.73 -$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
   10.74 -endif
   10.75 -
   10.76 -DEBUG?=NO
   10.77 -ifeq ("$(DEBUG)","NO")
   10.78 -    CFLAGS+= -DNDEBUG
   10.79 -endif
   10.80 -
   10.81 -OPENPGP?=GPG
   10.82 -ifeq ("$(OPENPGP)","GPG")
   10.83 -    NO_SOURCE=pgp_netpgp.c
   10.84 -    GPGME_IN?=$(HOME)
   10.85 -    CFLAGS+= -DUSE_GPG -I$(GPGME_IN)/include -DLIBGPGME=\"$(LIBGPGME)\"
   10.86 -    #LDFLAGS+= -L$(GPGME_IN)/lib -lgpgme
   10.87 -else ifeq ("$(OPENPGP)","NETPGP")
   10.88 -    NO_SOURCE=pgp_gpg.c
   10.89 -    NETPGP_IN?=$(HOME)
   10.90 -    CFLAGS+= -DUSE_NETPGP -I$(NETPGP_IN)/include
   10.91 -    LDFLAGS+= -L$(NETPGP_IN)/lib -lnetpgp -lcurl
   10.92 -else
   10.93 -	$(error Unknown OpenPGP library : $(OPENPGP))
   10.94 +    $(error Unknown OpenPGP library: $(OPENPGP))
   10.95  endif
   10.96  
   10.97  ALL_SOURCE=$(subst $(NO_SOURCE),,$(wildcard *.c))
   10.98 -
   10.99  DEPENDS=$(subst .c,.d,$(ALL_SOURCE))
  10.100  ALL_OBJECTS=$(subst .c,.o,$(ALL_SOURCE))
  10.101  
  10.102 +.PHONY: all
  10.103  all: $(TARGET)
  10.104  
  10.105 -include Makefile.protocols
  10.106 +-include Makefile.protocols
  10.107  
  10.108  %.d: %.c
  10.109  	@set -e; rm -f $@; \
  10.110 @@ -72,29 +57,32 @@
  10.111  	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
  10.112  	rm -f $@.$$$$
  10.113  
  10.114 --include $(DEPENDS)
  10.115 -
  10.116 -#platform_windows.o: platform_windows.cpp
  10.117 -#	$(CXX) $(CXX_FLAGS) -o $@ -c $<
  10.118 +# If only the goal 'clean' is given, do not generate and include the '%.d' files.
  10.119 +ifneq ($(MAKECMDGOALS),clean)
  10.120 +    -include $(DEPENDS)
  10.121 +endif
  10.122  
  10.123  $(TARGET): libpEpEngine.a
  10.124 -	$(LD) $(ALL_OBJECTS) $(LDFLAGS) -o $@
  10.125 +	$(CC) $(ALL_OBJECTS) $(LDFLAGS) $(LDLIBS) -o $@
  10.126  
  10.127 +.PHONY: objects
  10.128  objects: $(ALL_OBJECTS)
  10.129  
  10.130  libpEpEngine.a: $(ALL_OBJECTS)
  10.131 -	ar -r $@ $(ALL_OBJECTS)
  10.132 +	ar -rc $@ $^
  10.133  
  10.134  .PHONY: clean
  10.135 -
  10.136  clean:
  10.137  	rm -f *.d *.o *.a $(TARGET) *.dll *.so *.zip *.d.* *.def *~
  10.138  
  10.139 +.PHONY: install
  10.140  install: $(TARGET)
  10.141 +	mkdir -p "$(PREFIX)/lib/"
  10.142  	cp $< $(PREFIX)/lib/
  10.143  	mkdir -p $(PREFIX)/include/pEp
  10.144  	cp pEpEngine.h keymanagement.h message_api.h dynamic_api.h stringlist.h timestamp.h identity_list.h bloblist.h stringpair.h message.h mime.h cryptotech.h sync.h sync_fsm.h sync_app.h blacklist.h openpgp_compat.h $(PREFIX)/include/pEp/
  10.145  
  10.146 +.PHONY: uninstall
  10.147  uninstall:
  10.148  	rm -f $(PREFIX)/lib/$(TARGET)
  10.149 -
  10.150 +	rm -rf $(PREFIX)/include/pEp
    11.1 --- a/src/message_api.c	Tue Aug 22 09:08:15 2017 +0200
    11.2 +++ b/src/message_api.c	Tue Aug 22 15:34:17 2017 +0200
    11.3 @@ -211,32 +211,6 @@
    11.4      return -1;
    11.5  }
    11.6  
    11.7 -static void remove_msg_version_field(message* msg) {
    11.8 -    assert(msg);
    11.9 -
   11.10 -    stringpair_list_t* msg_opt_flds_curr = msg->opt_fields;
   11.11 -    stringpair_list_t** msg_opt_flds_prev_p = NULL;
   11.12 -    
   11.13 -    while (msg_opt_flds_curr) {
   11.14 -        char* fld_key = msg_opt_flds_curr->value->key;
   11.15 -        if (fld_key) {
   11.16 -            if (strcmp(fld_key, "X-pEp-Message-Version") == 0) {
   11.17 -                if (!msg_opt_flds_prev_p) {
   11.18 -                    msg->opt_fields = msg_opt_flds_curr->next;
   11.19 -                }
   11.20 -                else {
   11.21 -                    (*msg_opt_flds_prev_p)->next = msg_opt_flds_curr->next;
   11.22 -                }
   11.23 -                msg_opt_flds_curr->next = NULL;
   11.24 -                free_stringpair_list(msg_opt_flds_curr);
   11.25 -                break;
   11.26 -            }
   11.27 -            *msg_opt_flds_prev_p = msg_opt_flds_curr;
   11.28 -            msg_opt_flds_curr = msg_opt_flds_curr->next;
   11.29 -        }
   11.30 -    }
   11.31 -}
   11.32 -
   11.33  static PEP_STATUS copy_fields(message *dst, const message *src)
   11.34  {
   11.35      assert(dst);
   11.36 @@ -353,100 +327,6 @@
   11.37      return PEP_STATUS_OK;
   11.38  }
   11.39  
   11.40 -
   11.41 -static message* extract_minimal_envelope(const message* src, 
   11.42 -                                         PEP_msg_direction direct) {
   11.43 -    
   11.44 -    message* envelope = new_message(direct);
   11.45 -    if (!envelope)
   11.46 -        return NULL;
   11.47 -        
   11.48 -    envelope->shortmsg = strdup("pEp");
   11.49 -    if (!envelope->shortmsg)
   11.50 -        return NULL;
   11.51 -
   11.52 -    if (src->from) {
   11.53 -        envelope->from = identity_dup(src->from);
   11.54 -        if (!envelope->from)
   11.55 -            return NULL;
   11.56 -    }
   11.57 -
   11.58 -    if (src->to) {
   11.59 -        envelope->to = identity_list_dup(src->to);
   11.60 -        if (!envelope->to)
   11.61 -            return NULL;
   11.62 -    }
   11.63 -
   11.64 -    if (src->cc) {
   11.65 -        envelope->cc = identity_list_dup(src->cc);
   11.66 -        if (!envelope->cc)
   11.67 -            return NULL;
   11.68 -    }
   11.69 -
   11.70 -    if (src->bcc) {
   11.71 -        envelope->bcc = identity_list_dup(src->bcc);
   11.72 -        if (!envelope->bcc)
   11.73 -            return NULL;
   11.74 -    }
   11.75 -
   11.76 -    /* DO WE WANT TO EXPOSE THIS??? */
   11.77 -    if (src->reply_to) {
   11.78 -        envelope->reply_to = identity_list_dup(src->reply_to);
   11.79 -        if (!envelope->reply_to)
   11.80 -            return NULL;
   11.81 -    }
   11.82 -
   11.83 -    envelope->enc_format = src->enc_format;        
   11.84 -    
   11.85 -    return envelope;
   11.86 -}
   11.87 -
   11.88 -static void add_message_version(
   11.89 -    message* msg,
   11.90 -    int major_version,
   11.91 -    int minor_version
   11.92 -)
   11.93 -{
   11.94 -    assert(msg);
   11.95 -    
   11.96 -    char buf[8]; // xxx.xxx\0
   11.97 -    if (major_version < 1000 && minor_version < 1000) {
   11.98 -        int chars_set = sprintf(buf, "%d.%d", major_version, minor_version);
   11.99 -        if (chars_set >= 3)
  11.100 -            add_opt_field(msg, "X-pEp-Message-Version", buf);
  11.101 -    }
  11.102 -}
  11.103 -
  11.104 -static message* wrap_message_as_attachment(message* envelope, 
  11.105 -    const message* attachment) {
  11.106 -    
  11.107 -    message* _envelope = NULL;
  11.108 -    
  11.109 -    if (!envelope) {
  11.110 -        _envelope = extract_minimal_envelope(attachment, PEP_dir_outgoing);
  11.111 -        envelope = _envelope;
  11.112 -    }
  11.113 -    
  11.114 -    char* message_text = NULL;
  11.115 -    /* Turn message into a MIME-blob */
  11.116 -    PEP_STATUS status = mime_encode_message(attachment, false, &message_text);
  11.117 -    
  11.118 -    if (status != PEP_STATUS_OK) {
  11.119 -        free(_envelope);
  11.120 -        return NULL;
  11.121 -    }
  11.122 -    
  11.123 -    size_t message_len = strlen(message_text);
  11.124 -    
  11.125 -    bloblist_t* message_blob = new_bloblist(message_text, message_len,
  11.126 -                                            "message/rfc822", NULL);
  11.127 -    
  11.128 -    envelope->attachments = message_blob;
  11.129 -    add_message_version(envelope, 2, 0);
  11.130 -    
  11.131 -    return envelope;
  11.132 -}
  11.133 -
  11.134  static message * clone_to_empty_message(const message * src)
  11.135  {
  11.136      PEP_STATUS status;
  11.137 @@ -483,6 +363,7 @@
  11.138      )
  11.139  {
  11.140      PEP_STATUS status = PEP_STATUS_OK;
  11.141 +    bool free_ptext = false;
  11.142      char *ptext = NULL;
  11.143      char *ctext = NULL;
  11.144      char *mimetext = NULL;
  11.145 @@ -490,12 +371,20 @@
  11.146      assert(dst->longmsg == NULL);
  11.147      dst->enc_format = PEP_enc_PGP_MIME;
  11.148  
  11.149 -    if (src->shortmsg) {
  11.150 -        dst->shortmsg = strdup(src->shortmsg);
  11.151 -        assert(dst->shortmsg);
  11.152 -        if (dst->shortmsg == NULL)
  11.153 -            goto enomem;
  11.154 -        ptext = src->longmsg;
  11.155 +    if (src->shortmsg && strcmp(src->shortmsg, "pEp") != 0) {
  11.156 +        if (session->unencrypted_subject) {
  11.157 +            dst->shortmsg = strdup(src->shortmsg);
  11.158 +            assert(dst->shortmsg);
  11.159 +            if (dst->shortmsg == NULL)
  11.160 +                goto enomem;
  11.161 +            ptext = src->longmsg;
  11.162 +        }
  11.163 +        else {
  11.164 +            ptext = combine_short_and_long(src->shortmsg, src->longmsg);
  11.165 +            if (ptext == NULL)
  11.166 +                goto enomem;
  11.167 +            free_ptext = true;
  11.168 +        }
  11.169      }
  11.170      else if (src->longmsg) {
  11.171          ptext = src->longmsg;
  11.172 @@ -517,6 +406,10 @@
  11.173      if (status != PEP_STATUS_OK)
  11.174          goto pep_error;
  11.175  
  11.176 +    if (free_ptext){
  11.177 +        free(ptext);
  11.178 +        free_ptext=0;
  11.179 +    }
  11.180      free(_src);
  11.181      assert(mimetext);
  11.182      if (mimetext == NULL)
  11.183 @@ -1227,9 +1120,7 @@
  11.184      PEP_STATUS status = PEP_STATUS_OK;
  11.185      message * msg = NULL;
  11.186      stringlist_t * keys = NULL;
  11.187 -    message* _src = NULL;
  11.188 -    message* inner_message = NULL;
  11.189 -    
  11.190 +
  11.191      assert(session);
  11.192      assert(src);
  11.193      assert(dst);
  11.194 @@ -1241,14 +1132,6 @@
  11.195      if (src->dir == PEP_dir_incoming)
  11.196          return ADD_TO_LOG(PEP_ILLEGAL_VALUE);
  11.197  
  11.198 -    bool no_wrap_message = (flags & PEP_encrypt_flag_dont_raise_headers);
  11.199 -    
  11.200 -    if (!no_wrap_message) {
  11.201 -        PEP_STATUS wrap_status = encrypt_message(session, src, extra, &inner_message,
  11.202 -                                                 enc_format, 
  11.203 -                                                 (flags ^ PEP_encrypt_flag_dont_raise_headers));
  11.204 -    }
  11.205 -    
  11.206      determine_encryption_format(src);
  11.207      if (src->enc_format != PEP_enc_none)
  11.208          return ADD_TO_LOG(PEP_ILLEGAL_VALUE);
  11.209 @@ -1364,29 +1247,21 @@
  11.210          return ADD_TO_LOG(PEP_UNENCRYPTED);
  11.211      }
  11.212      else {
  11.213 -        if (no_wrap_message) {
  11.214 -            msg = clone_to_empty_message(src);
  11.215 -            _src = src;
  11.216 -        }
  11.217 -        else if (inner_message) {
  11.218 -            _src = wrap_message_as_attachment(NULL, inner_message);
  11.219 -            msg = clone_to_empty_message(_src);
  11.220 -        }
  11.221 +        msg = clone_to_empty_message(src);
  11.222          if (msg == NULL)
  11.223              goto enomem;
  11.224  
  11.225          if (!(flags & PEP_encrypt_flag_force_no_attached_key))
  11.226 -            attach_own_key(session, _src);
  11.227 +            attach_own_key(session, src);
  11.228  
  11.229          switch (enc_format) {
  11.230          case PEP_enc_PGP_MIME:
  11.231          case PEP_enc_PEP: // BUG: should be implemented extra
  11.232 -            status = encrypt_PGP_MIME(session, _src, keys, msg, flags);
  11.233 +            status = encrypt_PGP_MIME(session, src, keys, msg, flags);
  11.234              break;
  11.235  
  11.236 -        // This actually doesn't really make sense for message 2.0... See function comment below
  11.237          case PEP_enc_pieces:
  11.238 -            status = encrypt_PGP_in_pieces(session, _src, keys, msg, flags);
  11.239 +            status = encrypt_PGP_in_pieces(session, src, keys, msg, flags);
  11.240              break;
  11.241  
  11.242          /* case PEP_enc_PEP:
  11.243 @@ -1417,8 +1292,8 @@
  11.244  
  11.245      if (msg) {
  11.246          decorate_message(msg, PEP_rating_undefined, NULL);
  11.247 -        if (_src->id) {
  11.248 -            msg->id = strdup(_src->id);
  11.249 +        if (src->id) {
  11.250 +            msg->id = strdup(src->id);
  11.251              assert(msg->id);
  11.252              if (msg->id == NULL)
  11.253                  goto enomem;
  11.254 @@ -1426,7 +1301,6 @@
  11.255      }
  11.256  
  11.257      *dst = msg;
  11.258 -//    free_message(wrapped_msg);
  11.259      return ADD_TO_LOG(status);
  11.260  
  11.261  enomem:
  11.262 @@ -1435,8 +1309,7 @@
  11.263  pep_error:
  11.264      free_stringlist(keys);
  11.265      free_message(msg);
  11.266 -    if (!no_wrap_message)
  11.267 -        free_message(_src);
  11.268 +
  11.269      return ADD_TO_LOG(status);
  11.270  }
  11.271  
  11.272 @@ -1559,60 +1432,8 @@
  11.273      return false;
  11.274  }
  11.275  
  11.276 -static const char* pEpmessage_version_str(const message *msg)
  11.277 -{
  11.278 -    char* retval = NULL;
  11.279 -    for (stringpair_list_t *i = msg->opt_fields; i && i->value ; i=i->next) {
  11.280 -        if (strcasecmp(i->value->key, "X-pEp-Message-Version") == 0) {
  11.281 -            retval = i->value->value;
  11.282 -            break;
  11.283 -        }
  11.284 -    }
  11.285 -    return retval;
  11.286 -}
  11.287 -
  11.288 -static int pEpmessage_major_version(const message *msg) {
  11.289 -    const char* version_string = pEpmessage_version_str(msg);
  11.290 -    if (!version_string)
  11.291 -        return -1;
  11.292 -    
  11.293 -    int ver_strlen = strlen(version_string);
  11.294 -    if (ver_strlen < 3)
  11.295 -        return -1;
  11.296 -        
  11.297 -    const short MAX_MAJ_VERSION_DIGITS = 4; // I certainly hope...    
  11.298 -    char version_buf[MAX_MAJ_VERSION_DIGITS + 1];
  11.299 -
  11.300 -    int i = 0;    
  11.301 -    
  11.302 -    for ( ; i < MAX_MAJ_VERSION_DIGITS && i < ver_strlen; i++ ) {
  11.303 -        if (version_string[i] == '.') {
  11.304 -            version_buf[i] = '\0';
  11.305 -            break;
  11.306 -        }
  11.307 -        version_buf[i] = version_string[i];
  11.308 -    }
  11.309 -    
  11.310 -    if (version_string[i] != '.')
  11.311 -        return -1;
  11.312 -    
  11.313 -    // ok, this is some chars + \0, but not necessarily numeric.
  11.314 -    int retval = atoi(version_buf);
  11.315 -    if (retval == 0 && version_buf[0] != 0)
  11.316 -        return -1;
  11.317 -    
  11.318 -    return retval;
  11.319 -}
  11.320 -
  11.321 -static bool verify_explicit_message_version(const char* desired_version, 
  11.322 -    const message* msg) {
  11.323 -    if (!desired_version || !msg)
  11.324 -        return false;
  11.325 -    const char* msg_version_str = pEpmessage_version_str(msg);
  11.326 -    return (msg_version_str && (strcmp(desired_version, msg_version_str) == 0));
  11.327 -}
  11.328 -
  11.329  // update comm_type to pEp_ct_pEp if needed
  11.330 +
  11.331  static PEP_STATUS _update_identity_for_incoming_message(
  11.332          PEP_SESSION session,
  11.333          const message *src
  11.334 @@ -1840,29 +1661,6 @@
  11.335      return status;
  11.336  }
  11.337  
  11.338 -static void pull_up_longmsg_attachment(message* msg) {
  11.339 -    bloblist_t* matt = msg->attachments;
  11.340 -    if (matt) {
  11.341 -        const char* inner_mime_type = matt->mime_type;
  11.342 -        if (strcasecmp(inner_mime_type, "text/plain") == 0) {
  11.343 -            free(msg->longmsg); /* in case of "" */
  11.344 -            msg->longmsg = strndup(matt->value, matt->size);
  11.345 -            
  11.346 -            bloblist_t* next_node = matt->next;
  11.347 -            if (next_node) {
  11.348 -                inner_mime_type = next_node->mime_type;
  11.349 -                if (strcasecmp(inner_mime_type, "text/html") == 0) {
  11.350 -                    free(msg->longmsg_formatted);
  11.351 -                    msg->longmsg_formatted = strndup(next_node->value, next_node->size);
  11.352 -                }
  11.353 -            }
  11.354 -        }
  11.355 -        else if (strcasecmp(inner_mime_type, "text/html") == 0) {
  11.356 -            free(msg->longmsg_formatted);
  11.357 -            msg->longmsg_formatted = strndup(matt->value, matt->size);
  11.358 -        }
  11.359 -    }
  11.360 -}
  11.361  
  11.362  DYNAMIC_API PEP_STATUS _decrypt_message(
  11.363          PEP_SESSION session,
  11.364 @@ -1883,11 +1681,6 @@
  11.365      size_t psize;
  11.366      stringlist_t *_keylist = NULL;
  11.367  
  11.368 -    // this will only ever be non-null if the message passed in is an
  11.369 -    // outer message wrapping an inner one.
  11.370 -    message* inner_message = NULL;
  11.371 -    int inner_major_version = -1;
  11.372 -    
  11.373      assert(session);
  11.374      assert(src);
  11.375      assert(dst);
  11.376 @@ -1947,6 +1740,7 @@
  11.377              
  11.378              char* slong = src->longmsg;
  11.379              char* sform = src->longmsg_formatted;
  11.380 +            bloblist_t* satt = src->attachments;
  11.381              
  11.382              if ((!slong || slong[0] == '\0')
  11.383                   && (!sform || sform[0] == '\0')) {
  11.384 @@ -2019,55 +1813,32 @@
  11.385                  if (status != PEP_STATUS_OK)
  11.386                      goto pep_error;
  11.387                  
  11.388 -                int msg_major_version = pEpmessage_major_version(src);
  11.389 -
  11.390 -                /* Check for message version greater than 1 - if it is, it
  11.391 -                   means that this is an outer message containing an inner
  11.392 -                   message. The inner message has unencrypted headers, and
  11.393 -                   if ITS version == 1 (or is not present), it is the
  11.394 -                   innermost message.
  11.395 -                   
  11.396 -                   If version > 1, the outer message is just one layer of
  11.397 -                   a multilayer message, and we only strip one layer
  11.398 -                   and return the next one.
  11.399 -                   
  11.400 -                   If version == 1 (or none indicated), there are two possibilities:
  11.401 -                   either the inner message is a forwarded message, or it is the real message
  11.402 -                   which needs to be pulled up for evaluation.
  11.403 -                   
  11.404 -                   This should, in fact, not be difficult to determine, as a legitimately
  11.405 -                   wrapped inner message will have a version 2 outer message, whereas
  11.406 -                   an attachment will have a version 1 (or unspecified) outer message.
  11.407 -                   
  11.408 -                 */
  11.409 -                if (msg_major_version > 1) {
  11.410 -                    
  11.411 -                    /* This is an outer message - get the inner message */
  11.412 -                    status = mime_decode_message(msg->attachments->value, 
  11.413 -                                                 msg->attachments->size,
  11.414 -                                                 &inner_message);
  11.415 -                    if (status != PEP_STATUS_OK)
  11.416 -                        goto pep_error;
  11.417 -            
  11.418 -                    // FIXME: Deal with keys... we care about the outer and inner layers
  11.419 -                    // but how?
  11.420 -                    
  11.421 -                    inner_major_version = pEpmessage_major_version(inner_message);
  11.422 -            
  11.423 -                    if (inner_major_version < 2) {
  11.424 -                        // raise message, combine address lists, etc
  11.425 -                    }
  11.426 -                    else {
  11.427 -                        // raise message, check against outer address lists
  11.428 -                    }
  11.429 -                }
  11.430 -                                    
  11.431                  char* mlong = msg->longmsg;
  11.432                  char* mform = msg->longmsg_formatted;
  11.433 +                bloblist_t* matt = msg->attachments;
  11.434                  
  11.435 -                if ((!mlong || mlong[0] == '\0') && (!mform || mform[0] == '\0')) {             
  11.436 -                    pull_up_longmsg_attachment(msg);
  11.437 -                    
  11.438 +                if ((!mlong || mlong[0] == '\0')
  11.439 +                     && (!mform || mform[0] == '\0')) {
  11.440 +                    if (matt) {
  11.441 +                        const char* inner_mime_type = matt->mime_type;
  11.442 +                        if (strcasecmp(inner_mime_type, "text/plain") == 0) {
  11.443 +                            free(mlong); /* in case of "" */
  11.444 +                            msg->longmsg = strndup(matt->value, matt->size);
  11.445 +                            
  11.446 +                            bloblist_t* next_node = matt->next;
  11.447 +                            if (next_node) {
  11.448 +                                inner_mime_type = next_node->mime_type;
  11.449 +                                if (strcasecmp(inner_mime_type, "text/html") == 0) {
  11.450 +                                    free(mform);
  11.451 +                                    msg->longmsg_formatted = strndup(next_node->value, next_node->size);
  11.452 +                                }
  11.453 +                            }
  11.454 +                        }
  11.455 +                        else if (strcasecmp(inner_mime_type, "text/html") == 0) {
  11.456 +                            free(mform);
  11.457 +                            msg->longmsg_formatted = strndup(matt->value, matt->size);
  11.458 +                        }
  11.459 +                    }
  11.460                      if (msg->shortmsg) {
  11.461                          free(src->shortmsg);
  11.462                          src->shortmsg = strdup(msg->shortmsg);
  11.463 @@ -2097,8 +1868,6 @@
  11.464                          }
  11.465                      }
  11.466                  }
  11.467 -                
  11.468 -                /* Ok, so either way, detached sig or not, we should have decrypted and verified our PGP MIME encoded message if it was possible. */
  11.469                  break;
  11.470  
  11.471              case PEP_enc_pieces:
  11.472 @@ -2195,57 +1964,48 @@
  11.473              case PEP_enc_PGP_MIME:
  11.474              case PEP_enc_pieces:
  11.475              case PEP_enc_PGP_MIME_Outlook1:
  11.476 -            
  11.477 -                if (inner_message) {
  11.478 -                    /* we don't need to lift the subject etc, since the inner message has the real one */
  11.479 -                    if (inner_major_version < 2) {
  11.480 -                        // We need to verify that recips/sender are the same or combined or some such
  11.481 +                status = copy_fields(msg, src);
  11.482 +                if (status != PEP_STATUS_OK)
  11.483 +                {
  11.484 +                    GOTO(pep_error);
  11.485 +                }
  11.486 +
  11.487 +                if (src->shortmsg == NULL || strcmp(src->shortmsg, "pEp") == 0)
  11.488 +                {
  11.489 +                    char * shortmsg;
  11.490 +                    char * longmsg;
  11.491 +
  11.492 +                    int r = separate_short_and_long(msg->longmsg, &shortmsg,
  11.493 +                            &longmsg);
  11.494 +                    
  11.495 +                    if (r == -1)
  11.496 +                        goto enomem;
  11.497 +
  11.498 +                    if (shortmsg == NULL) {
  11.499 +                        if (src->shortmsg == NULL)
  11.500 +                            shortmsg = strdup("");
  11.501 +                        else {
  11.502 +                            // FIXME: is msg->shortmsg always a copy of
  11.503 +                            // src->shortmsg already?
  11.504 +                            // if so, we need to change the logic so
  11.505 +                            // that in this case, we don't free msg->shortmsg
  11.506 +                            // and do this strdup, etc.
  11.507 +                            shortmsg = strdup(src->shortmsg);
  11.508 +                        }
  11.509                      }
  11.510 +
  11.511 +
  11.512 +                    free(msg->shortmsg);
  11.513 +                    free(msg->longmsg);
  11.514 +
  11.515 +                    msg->shortmsg = shortmsg;
  11.516 +                    msg->longmsg = longmsg;
  11.517                  }
  11.518                  else {
  11.519 -                    status = copy_fields(msg, src);
  11.520 -                    if (status != PEP_STATUS_OK)
  11.521 -                    {
  11.522 -                        GOTO(pep_error);
  11.523 -                    }
  11.524 -
  11.525 -                    if (src->shortmsg == NULL || strcmp(src->shortmsg, "pEp") == 0)
  11.526 -                    {
  11.527 -                        char * shortmsg;
  11.528 -                        char * longmsg;
  11.529 -
  11.530 -                        int r = separate_short_and_long(msg->longmsg, &shortmsg,
  11.531 -                                &longmsg);
  11.532 -                        
  11.533 -                        if (r == -1)
  11.534 -                            goto enomem;
  11.535 -
  11.536 -                        if (shortmsg == NULL) {
  11.537 -                            if (src->shortmsg == NULL)
  11.538 -                                shortmsg = strdup("");
  11.539 -                            else {
  11.540 -                                // FIXME: is msg->shortmsg always a copy of
  11.541 -                                // src->shortmsg already?
  11.542 -                                // if so, we need to change the logic so
  11.543 -                                // that in this case, we don't free msg->shortmsg
  11.544 -                                // and do this strdup, etc.
  11.545 -                                shortmsg = strdup(src->shortmsg);
  11.546 -                            }
  11.547 -                        }
  11.548 -
  11.549 -
  11.550 -                        free(msg->shortmsg);
  11.551 -                        free(msg->longmsg);
  11.552 -
  11.553 -                        msg->shortmsg = shortmsg;
  11.554 -                        msg->longmsg = longmsg;
  11.555 -                    }
  11.556 -                    else {
  11.557 -                        msg->shortmsg = strdup(src->shortmsg);
  11.558 -                        assert(msg->shortmsg);
  11.559 -                        if (msg->shortmsg == NULL)
  11.560 -                            goto enomem;
  11.561 -                    }
  11.562 +                    msg->shortmsg = strdup(src->shortmsg);
  11.563 +                    assert(msg->shortmsg);
  11.564 +                    if (msg->shortmsg == NULL)
  11.565 +                        goto enomem;
  11.566                  }
  11.567                  break;
  11.568              default:
  11.569 @@ -2269,7 +2029,7 @@
  11.570              free_identity_list(_private_il);
  11.571          }
  11.572  
  11.573 -        if (decrypt_status == PEP_DECRYPTED){
  11.574 +        if(decrypt_status == PEP_DECRYPTED){
  11.575  
  11.576              // TODO optimize if import_attached_keys didn't import any key
  11.577  
    12.1 --- a/sync/Makefile	Tue Aug 22 09:08:15 2017 +0200
    12.2 +++ b/sync/Makefile	Tue Aug 22 15:34:17 2017 +0200
    12.3 @@ -1,35 +1,38 @@
    12.4 -
    12.5 -# This file is under GNU General Public License 3.0
    12.6 +# Copyright 2017, pEp Foundation
    12.7 +# This file is part of pEpEngine
    12.8 +# This file may be used under the terms of the GNU General Public License version 3
    12.9  # see LICENSE.txt
   12.10  
   12.11  include ../Makefile.conf
   12.12  
   12.13 +.PHONY: all
   12.14  all: .codegen
   12.15  
   12.16 +# Currently not in use, kept for historic reasons
   12.17  skeleton: .actions
   12.18  
   12.19  .codegen: .statemachines .actions
   12.20  	cp -f generated/*.* ../src
   12.21 -	touch .codegen
   12.22 +	touch $@
   12.23  
   12.24  .actions: devicegroup.fsm gen_actions.ysl2 fsm.yml2 functions.ysl2
   12.25 -	$(YML2PROC) $(YML_OPTS) -y gen_actions.ysl2 $< -o $@
   12.26 +	$(YML2_PROC) $(YML2_OPTS) -y gen_actions.ysl2 $< -o $@
   12.27  
   12.28  .statemachines: devicegroup.fsm gen_statemachine.ysl2 fsm.yml2 functions.ysl2
   12.29 -	$(YML2PROC) $(YML_OPTS) -y gen_statemachine.ysl2 $< -o $@
   12.30 +	$(YML2_PROC) $(YML2_OPTS) -y gen_statemachine.ysl2 $< -o $@
   12.31  
   12.32  .PHONY: clean
   12.33 -
   12.34  clean:
   12.35 -	rm -f *.xml *.xsl \
   12.36 -    $(pathsub generated/%, ../src/% $(wildcard generated/*.*)) \
   12.37 -    ../generated/* ../skeletons/* .statemachines .actions *.dot *.svg
   12.38 +	rm -f *.xml *.xsl *.dot *.svg \
   12.39 +	$(patsubst generated/%,../src/%,$(wildcard generated/*.*)) \
   12.40 +	../generated/* ../skeletons/* .statemachines .actions .codegen \
   12.41 +	generated/Makefile.protocols
   12.42  
   12.43  %.xml: %.fsm
   12.44 -	yml2c $< -o $@
   12.45 +	$(YML2_PATH)/yml2c $< -o $@
   12.46  
   12.47 -%.dot: devicegroup.fsm gen_dot.ysl2
   12.48 -	$(YML2PROC) $(YML_OPTS) -y gen_dot.ysl2 $<
   12.49 +%.dot: gen_dot.ysl2 devicegroup.fsm
   12.50 +	$(YML2_PROC) $(YML2_OPTS) -y $^
   12.51  
   12.52  %.svg: %.dot
   12.53  	dot -Tsvg -o $@ $<
    13.1 --- a/test/Makefile	Tue Aug 22 09:08:15 2017 +0200
    13.2 +++ b/test/Makefile	Tue Aug 22 15:34:17 2017 +0200
    13.3 @@ -1,59 +1,65 @@
    13.4 -
    13.5 -# This file is under GNU General Public License 3.0
    13.6 +# Copyright 2017, pEp Foundation
    13.7 +# This file is part of pEpEngine
    13.8 +# This file may be used under the terms of the GNU General Public License version 3
    13.9  # see LICENSE.txt
   13.10  
   13.11 -HERE := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
   13.12 +HERE:=$(CURDIR)
   13.13  
   13.14  include ../Makefile.conf
   13.15  
   13.16 -CC?=g++ -std=gnu++11 -pthread
   13.17 -CXX?=g++ -std=gnu++11 -pthread
   13.18 -LD?=$(CXX)
   13.19 -LDFLAGS?=-L$(HOME)/lib
   13.20 -LDLIBS?=-letpan -lpEpEngine -lstdc++ -L../asn.1 -lasn1
   13.21 +TARGET=pEpEngineTest
   13.22 +
   13.23 +unexport GNUPGHOME
   13.24 +TEST_HOME=$(HERE)/test_home
   13.25 +TEST_GNUPGHOME=$(TEST_HOME)/.gnupg
   13.26 +
   13.27 +LDFLAGS+= $(ETPAN_LIB) -L../asn.1 -L../src
   13.28 +LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1
   13.29 +
   13.30  ifeq ($(BUILD_FOR),Linux)
   13.31 -	LDLIBS+= -luuid
   13.32 -endif
   13.33 -CXXFLAGS?=-std=c++11 -g -O0 -I../src -I../asn.1
   13.34 -# CXXFLAGS=-O3 -DNDEBUG
   13.35 -
   13.36 -ifeq ("$(OPENPGP)","NETPGP")
   13.37 -	LDLIBS+= -lnetpgp
   13.38 +    LDLIBS+= -luuid
   13.39  endif
   13.40  
   13.41 -TARGET=pEpEngineTest
   13.42 +ifeq ($(OPENPGP),NETPGP)
   13.43 +    LDLIBS+= -lnetpgp
   13.44 +endif
   13.45 +
   13.46 +ifeq ($(shell uname),Darwin)
   13.47 +    LIBPATH=DYLD_LIBRARY_PATH
   13.48 +    LLDB_BIN=/Applications/Xcode.app/Contents/Developer/usr/bin/lldb
   13.49 +else
   13.50 +    LIBPATH=LD_LIBRARY_PATH
   13.51 +    LLDB_BIN=lldb
   13.52 +endif
   13.53 +
   13.54 +# Create a list of the extra library paths for the loader. I do not assume that the engine (and its dependencies) are installed for testing.
   13.55 +# Note that += can not be used here, as it changes the amount of whitespace
   13.56 +EXTRA_LIB_PATHS=../src:
   13.57 +ifdef ETPAN_LIB
   13.58 +    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
   13.59 +endif
   13.60 +ifdef GPGME_LIB
   13.61 +    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)):
   13.62 +endif
   13.63 +ifdef NETPGP_LIB
   13.64 +    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(NETPGP_LIB)):
   13.65 +endif
   13.66 +# Remove trailing ':'
   13.67 +EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=)
   13.68 +
   13.69 +TEST_CMD_PFX=$(LIBPATH)=$(EXTRA_LIB_PATHS) HOME=$(TEST_HOME)
   13.70  
   13.71  UNIT_TESTS_SOURCE=$(wildcard *_test.cc)
   13.72  UNIT_TESTS=$(subst .cc,,$(UNIT_TESTS_SOURCE))
   13.73  UNIT_TESTS_RUN=$(subst .cc,_run,$(UNIT_TESTS_SOURCE))
   13.74  
   13.75 +.PHONY: all
   13.76  all: $(TARGET) $(UNIT_TESTS)
   13.77  
   13.78 -.PHONY: clean
   13.79 -
   13.80  # don't delete .o files!
   13.81  .PRECIOUS: %.o
   13.82  
   13.83 -unexport GNUPGHOME;
   13.84 -TEST_HOME=$(HERE)/test_home
   13.85 -TEST_GNUPGHOME=$(TEST_HOME)/.gnupg
   13.86 -
   13.87 -ifeq ($(shell which gpg2), )
   13.88 -    GPG_CMD = gpg
   13.89 -else
   13.90 -    GPG_CMD = gpg2
   13.91 -endif
   13.92 -
   13.93 -ifeq ($(shell uname), Darwin)
   13.94 -    LIBPATH = DYLD_LIBRARY_PATH
   13.95 -    LLDB_BIN = /Applications/Xcode.app/Contents/Developer/usr/bin/lldb
   13.96 -else
   13.97 -    LIBPATH = LD_LIBRARY_PATH
   13.98 -    LLDB_BIN = lldb
   13.99 -endif
  13.100 -
  13.101 -TEST_CMD_PFX = $(LIBPATH)=$(HOME)/lib:../src HOME=$(TEST_HOME)
  13.102 -
  13.103 +.PHONY: test_home_
  13.104  test_home_: 
  13.105  	-gpgconf --kill gpg-agent
  13.106  	-HOME=$(TEST_HOME) gpgconf --kill gpg-agent
  13.107 @@ -62,15 +68,17 @@
  13.108  	mkdir -p $(TEST_GNUPGHOME)/private-keys-v1.d
  13.109  	$(GPG_CMD) --import --batch --homedir $(TEST_GNUPGHOME) 0x*.asc *_sec.asc
  13.110  
  13.111 +.PHONY: clean
  13.112  clean:
  13.113  	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf msg4.asc
  13.114  	rm -Rf *.dSYM $(TEST_HOME) pubring.gpg secring.gpg random_seed *.conf trustdb.gpg
  13.115  
  13.116 -test: pEpEngineTest test_home_
  13.117 -	$(TEST_CMD_PFX) ./pEpEngineTest
  13.118 +.PHONY: test
  13.119 +test: $(TARGET) test_home_
  13.120 +	$(TEST_CMD_PFX) ./$<
  13.121  
  13.122  %_test : %_test.o test_util.o
  13.123 -	 $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
  13.124 +	 $(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
  13.125  
  13.126  %_run : % test_home_
  13.127  	$(TEST_CMD_PFX) ./$<
  13.128 @@ -84,7 +92,10 @@
  13.129  %_gdb : % test_home_
  13.130  	$(TEST_CMD_PFX) gdb ./$<
  13.131  
  13.132 +.PHONY: unit_tests
  13.133  unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
  13.134  
  13.135 +# Installs the engine, not the test binaries
  13.136 +.PHONY: install
  13.137  install:
  13.138 -	make -C .. install
  13.139 +	$(MAKE) -C .. install