IOSAD-15 more renames
authorDirk Zimmermann <dirk@pep-project.org>
Wed, 17 May 2017 09:27:57 +0200
changeset 1871f630a05e444
parent 186 db7d4cea0274
child 188 22b004dbda22
IOSAD-15 more renames
pEpObjCAdapter.xcodeproj/project.pbxproj
pEpObjCAdapter/NSArray+Extension.h
pEpObjCAdapter/NSArray+Extension.m
pEpObjCAdapter/PEPCSVScanner.h
pEpObjCAdapter/PEPCSVScanner.m
pEpObjCAdapter/PEPLanguage.h
pEpObjCAdapter/PEPLanguage.m
pEpObjCAdapter/PEPMessage.h
pEpObjCAdapter/PEPMessage.m
pEpObjCAdapter/PEPObjCAdapter+Internal.h
pEpObjCAdapter/PEPObjCAdapter.h
pEpObjCAdapter/PEPObjCAdapter.m
pEpObjCAdapter/PEPQueue.h
pEpObjCAdapter/PEPQueue.m
pEpObjCAdapter/PEPSession+Internal.h
pEpObjCAdapter/PEPSession.h
pEpObjCAdapter/PEPSession.m
pEpiOSAdapter/NSArray+Extension.h
pEpiOSAdapter/NSArray+Extension.m
pEpiOSAdapter/PEPCSVScanner.h
pEpiOSAdapter/PEPCSVScanner.m
pEpiOSAdapter/PEPLanguage.h
pEpiOSAdapter/PEPLanguage.m
pEpiOSAdapter/PEPMessage.h
pEpiOSAdapter/PEPMessage.m
pEpiOSAdapter/PEPObjCAdapter+Internal.h
pEpiOSAdapter/PEPObjCAdapter.h
pEpiOSAdapter/PEPObjCAdapter.m
pEpiOSAdapter/PEPQueue.h
pEpiOSAdapter/PEPQueue.m
pEpiOSAdapter/PEPSession+Internal.h
pEpiOSAdapter/PEPSession.h
pEpiOSAdapter/PEPSession.m
     1.1 --- a/pEpObjCAdapter.xcodeproj/project.pbxproj	Wed May 17 08:16:57 2017 +0200
     1.2 +++ b/pEpObjCAdapter.xcodeproj/project.pbxproj	Wed May 17 09:27:57 2017 +0200
     1.3 @@ -7,15 +7,13 @@
     1.4  	objects = {
     1.5  
     1.6  /* Begin PBXBuildFile section */
     1.7 -		350F0ED31B4D642200D9964F /* PEPSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 350F0ED21B4D642200D9964F /* PEPSession.m */; };
     1.8 -		350F0ED91B4E997300D9964F /* PEPMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 350F0ED81B4E997300D9964F /* PEPMessage.m */; };
     1.9 -		352988AE1AEF964100FA7E2E /* PEPObjCAdapter.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 352988AD1AEF964100FA7E2E /* PEPObjCAdapter.h */; };
    1.10 -		352988B01AEF964100FA7E2E /* PEPObjCAdapter.m in Sources */ = {isa = PBXBuildFile; fileRef = 352988AF1AEF964100FA7E2E /* PEPObjCAdapter.m */; };
    1.11 -		35EA58151B565643000B4CC5 /* PEPQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 35EA58141B565643000B4CC5 /* PEPQueue.m */; };
    1.12 -		43293F011EBA067600EEE010 /* PEPLanguage.m in Sources */ = {isa = PBXBuildFile; fileRef = 43293F001EBA067600EEE010 /* PEPLanguage.m */; };
    1.13 -		43293F021EBA0FDC00EEE010 /* PEPLanguage.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 43293EFF1EBA067600EEE010 /* PEPLanguage.h */; };
    1.14 -		43293F051EBA246700EEE010 /* PEPCSVScanner.m in Sources */ = {isa = PBXBuildFile; fileRef = 43293F041EBA246700EEE010 /* PEPCSVScanner.m */; };
    1.15 -		43293F081EBA364700EEE010 /* NSArray+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 43293F071EBA364700EEE010 /* NSArray+Extension.m */; };
    1.16 +		43209B3D1ECC2DA7007E7E2E /* NSArray+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 43209B271ECC2ACD007E7E2E /* NSArray+Extension.m */; };
    1.17 +		43209B3E1ECC2DAB007E7E2E /* PEPCSVScanner.m in Sources */ = {isa = PBXBuildFile; fileRef = 43209B291ECC2ACD007E7E2E /* PEPCSVScanner.m */; };
    1.18 +		43209B3F1ECC2DB0007E7E2E /* PEPLanguage.m in Sources */ = {isa = PBXBuildFile; fileRef = 43209B2B1ECC2ACD007E7E2E /* PEPLanguage.m */; };
    1.19 +		43209B401ECC2DB4007E7E2E /* PEPMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 43209B2D1ECC2ACD007E7E2E /* PEPMessage.m */; };
    1.20 +		43209B411ECC2DB8007E7E2E /* PEPObjCAdapter.m in Sources */ = {isa = PBXBuildFile; fileRef = 43209B301ECC2ACD007E7E2E /* PEPObjCAdapter.m */; };
    1.21 +		43209B421ECC2DBC007E7E2E /* PEPQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 43209B321ECC2ACD007E7E2E /* PEPQueue.m */; };
    1.22 +		43209B431ECC2DC0007E7E2E /* PEPSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 43209B351ECC2ACD007E7E2E /* PEPSession.m */; };
    1.23  		432EF60C1C58B77900B6782A /* 0xB623F674.asc in Resources */ = {isa = PBXBuildFile; fileRef = 432EF6091C58B77900B6782A /* 0xB623F674.asc */; };
    1.24  		432EF60E1C58B77900B6782A /* msg_to_B623F674.asc in Resources */ = {isa = PBXBuildFile; fileRef = 432EF60B1C58B77900B6782A /* msg_to_B623F674.asc */; };
    1.25  		432FA2D21C884C5F00DDF874 /* partner1_F2D281C2789DD7F6_pub.asc in Resources */ = {isa = PBXBuildFile; fileRef = 432FA2CF1C884C5F00DDF874 /* partner1_F2D281C2789DD7F6_pub.asc */; };
    1.26 @@ -30,8 +28,6 @@
    1.27  		43E02A211C71F65B008F05E9 /* A3FC7F0A.asc in Resources */ = {isa = PBXBuildFile; fileRef = 43E02A1D1C71F65B008F05E9 /* A3FC7F0A.asc */; };
    1.28  		43E02A221C71F65B008F05E9 /* account_A3FC7F0A.ser in Resources */ = {isa = PBXBuildFile; fileRef = 43E02A1E1C71F65B008F05E9 /* account_A3FC7F0A.ser */; };
    1.29  		43E02A231C71F65B008F05E9 /* msg_to_A3FC7F0A_from_mutt.ser in Resources */ = {isa = PBXBuildFile; fileRef = 43E02A1F1C71F65B008F05E9 /* msg_to_A3FC7F0A_from_mutt.ser */; };
    1.30 -		640037F91BE1A7DE00F0014E /* PEPSession.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 350F0ED11B4D642200D9964F /* PEPSession.h */; };
    1.31 -		640037FA1BE1A7EF00F0014E /* PEPQueue.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 35EA58131B565643000B4CC5 /* PEPQueue.h */; };
    1.32  		6400FB911B8CA543005221E3 /* libpEpEngine.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 64289E561B8B70E800FC617B /* libpEpEngine.a */; };
    1.33  		640F79231C9B517C00DBEC4E /* 5CB2C182_sec.asc in Resources */ = {isa = PBXBuildFile; fileRef = 640F79211C9B517C00DBEC4E /* 5CB2C182_sec.asc */; };
    1.34  		640F79241C9B517C00DBEC4E /* 5CB2C182.asc in Resources */ = {isa = PBXBuildFile; fileRef = 640F79221C9B517C00DBEC4E /* 5CB2C182.asc */; };
    1.35 @@ -47,7 +43,6 @@
    1.36  		64415E4B1BEA523300F6CBB2 /* 70DCF575_sec.asc in Resources */ = {isa = PBXBuildFile; fileRef = 64415E451BEA523300F6CBB2 /* 70DCF575_sec.asc */; };
    1.37  		64415E4C1BEA523300F6CBB2 /* 0xC9C2EE39.asc in Resources */ = {isa = PBXBuildFile; fileRef = 64415E461BEA523300F6CBB2 /* 0xC9C2EE39.asc */; };
    1.38  		64415E4D1BEA523300F6CBB2 /* C9C2EE39_sec.asc in Resources */ = {isa = PBXBuildFile; fileRef = 64415E471BEA523300F6CBB2 /* C9C2EE39_sec.asc */; };
    1.39 -		64415E4E1BEB8ECD00F6CBB2 /* PEPMessage.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 350F0ED71B4E997300D9964F /* PEPMessage.h */; };
    1.40  /* End PBXBuildFile section */
    1.41  
    1.42  /* Begin PBXContainerItemProxy section */
    1.43 @@ -102,34 +97,31 @@
    1.44  			dstPath = "include/$(PRODUCT_NAME)";
    1.45  			dstSubfolderSpec = 16;
    1.46  			files = (
    1.47 -				43293F021EBA0FDC00EEE010 /* PEPLanguage.h in CopyFiles */,
    1.48 -				640037FA1BE1A7EF00F0014E /* PEPQueue.h in CopyFiles */,
    1.49 -				640037F91BE1A7DE00F0014E /* PEPSession.h in CopyFiles */,
    1.50 -				352988AE1AEF964100FA7E2E /* PEPObjCAdapter.h in CopyFiles */,
    1.51 -				64415E4E1BEB8ECD00F6CBB2 /* PEPMessage.h in CopyFiles */,
    1.52  			);
    1.53  			runOnlyForDeploymentPostprocessing = 0;
    1.54  		};
    1.55  /* End PBXCopyFilesBuildPhase section */
    1.56  
    1.57  /* Begin PBXFileReference section */
    1.58 -		350F0ED11B4D642200D9964F /* PEPSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPSession.h; sourceTree = "<group>"; };
    1.59 -		350F0ED21B4D642200D9964F /* PEPSession.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPSession.m; sourceTree = "<group>"; };
    1.60 -		350F0ED71B4E997300D9964F /* PEPMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPMessage.h; sourceTree = "<group>"; };
    1.61 -		350F0ED81B4E997300D9964F /* PEPMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPMessage.m; sourceTree = "<group>"; };
    1.62  		352988AA1AEF964100FA7E2E /* libpEpObjCAdapter.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libpEpObjCAdapter.a; sourceTree = BUILT_PRODUCTS_DIR; };
    1.63 -		352988AD1AEF964100FA7E2E /* PEPObjCAdapter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPObjCAdapter.h; sourceTree = "<group>"; };
    1.64 -		352988AF1AEF964100FA7E2E /* PEPObjCAdapter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPObjCAdapter.m; sourceTree = "<group>"; };
    1.65 -		35EA58131B565643000B4CC5 /* PEPQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPQueue.h; sourceTree = "<group>"; };
    1.66 -		35EA58141B565643000B4CC5 /* PEPQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPQueue.m; sourceTree = "<group>"; };
    1.67  		35FB0ABB1B57F97E00377032 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
    1.68  		35FB0ABD1B57F99D00377032 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
    1.69 -		43293EFF1EBA067600EEE010 /* PEPLanguage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPLanguage.h; sourceTree = "<group>"; };
    1.70 -		43293F001EBA067600EEE010 /* PEPLanguage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPLanguage.m; sourceTree = "<group>"; };
    1.71 -		43293F031EBA246700EEE010 /* PEPCSVScanner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPCSVScanner.h; sourceTree = "<group>"; };
    1.72 -		43293F041EBA246700EEE010 /* PEPCSVScanner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPCSVScanner.m; sourceTree = "<group>"; };
    1.73 -		43293F061EBA364700EEE010 /* NSArray+Extension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+Extension.h"; sourceTree = "<group>"; };
    1.74 -		43293F071EBA364700EEE010 /* NSArray+Extension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+Extension.m"; sourceTree = "<group>"; };
    1.75 +		43209B261ECC2ACD007E7E2E /* NSArray+Extension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+Extension.h"; sourceTree = "<group>"; };
    1.76 +		43209B271ECC2ACD007E7E2E /* NSArray+Extension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+Extension.m"; sourceTree = "<group>"; };
    1.77 +		43209B281ECC2ACD007E7E2E /* PEPCSVScanner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPCSVScanner.h; sourceTree = "<group>"; };
    1.78 +		43209B291ECC2ACD007E7E2E /* PEPCSVScanner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPCSVScanner.m; sourceTree = "<group>"; };
    1.79 +		43209B2A1ECC2ACD007E7E2E /* PEPLanguage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPLanguage.h; sourceTree = "<group>"; };
    1.80 +		43209B2B1ECC2ACD007E7E2E /* PEPLanguage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPLanguage.m; sourceTree = "<group>"; };
    1.81 +		43209B2C1ECC2ACD007E7E2E /* PEPMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPMessage.h; sourceTree = "<group>"; };
    1.82 +		43209B2D1ECC2ACD007E7E2E /* PEPMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPMessage.m; sourceTree = "<group>"; };
    1.83 +		43209B2E1ECC2ACD007E7E2E /* PEPObjCAdapter+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PEPObjCAdapter+Internal.h"; sourceTree = "<group>"; };
    1.84 +		43209B2F1ECC2ACD007E7E2E /* PEPObjCAdapter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPObjCAdapter.h; sourceTree = "<group>"; };
    1.85 +		43209B301ECC2ACD007E7E2E /* PEPObjCAdapter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPObjCAdapter.m; sourceTree = "<group>"; };
    1.86 +		43209B311ECC2ACD007E7E2E /* PEPQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPQueue.h; sourceTree = "<group>"; };
    1.87 +		43209B321ECC2ACD007E7E2E /* PEPQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPQueue.m; sourceTree = "<group>"; };
    1.88 +		43209B331ECC2ACD007E7E2E /* PEPSession+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PEPSession+Internal.h"; sourceTree = "<group>"; };
    1.89 +		43209B341ECC2ACD007E7E2E /* PEPSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPSession.h; sourceTree = "<group>"; };
    1.90 +		43209B351ECC2ACD007E7E2E /* PEPSession.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PEPSession.m; sourceTree = "<group>"; };
    1.91  		432EF6091C58B77900B6782A /* 0xB623F674.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = 0xB623F674.asc; sourceTree = "<group>"; };
    1.92  		432EF60A1C58B77900B6782A /* B623F674_sec.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = B623F674_sec.asc; sourceTree = "<group>"; };
    1.93  		432EF60B1C58B77900B6782A /* msg_to_B623F674.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = msg_to_B623F674.asc; sourceTree = "<group>"; };
    1.94 @@ -148,7 +140,6 @@
    1.95  		43E02A1F1C71F65B008F05E9 /* msg_to_A3FC7F0A_from_mutt.ser */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; path = msg_to_A3FC7F0A_from_mutt.ser; sourceTree = "<group>"; };
    1.96  		640F79211C9B517C00DBEC4E /* 5CB2C182_sec.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = 5CB2C182_sec.asc; sourceTree = "<group>"; };
    1.97  		640F79221C9B517C00DBEC4E /* 5CB2C182.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = 5CB2C182.asc; sourceTree = "<group>"; };
    1.98 -		642FB6551ECB4B89008D3DF3 /* PEPSession+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PEPSession+Internal.h"; sourceTree = "<group>"; };
    1.99  		64415E171BE94FCB00F6CBB2 /* iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = iOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
   1.100  		64415E191BE94FCB00F6CBB2 /* iOSTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = iOSTests.m; sourceTree = "<group>"; };
   1.101  		64415E1B1BE94FCB00F6CBB2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
   1.102 @@ -159,7 +150,6 @@
   1.103  		64415E451BEA523300F6CBB2 /* 70DCF575_sec.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = 70DCF575_sec.asc; path = ../../pEpEngine/test/70DCF575_sec.asc; sourceTree = "<group>"; };
   1.104  		64415E461BEA523300F6CBB2 /* 0xC9C2EE39.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = 0xC9C2EE39.asc; path = ../../pEpEngine/test/0xC9C2EE39.asc; sourceTree = "<group>"; };
   1.105  		64415E471BEA523300F6CBB2 /* C9C2EE39_sec.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = C9C2EE39_sec.asc; path = ../../pEpEngine/test/C9C2EE39_sec.asc; sourceTree = "<group>"; };
   1.106 -		64415E5A1BF3840500F6CBB2 /* PEPObjCAdapter+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PEPObjCAdapter+Internal.h"; sourceTree = "<group>"; };
   1.107  		64DA243B1B833248000BEE80 /* pEpEngine.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = pEpEngine.xcodeproj; path = "../pEpEngine/build-mac/pEpEngine.xcodeproj"; sourceTree = "<group>"; };
   1.108  /* End PBXFileReference section */
   1.109  
   1.110 @@ -193,7 +183,7 @@
   1.111  				64DA243B1B833248000BEE80 /* pEpEngine.xcodeproj */,
   1.112  				35FB0ABD1B57F99D00377032 /* Security.framework */,
   1.113  				35FB0ABB1B57F97E00377032 /* CFNetwork.framework */,
   1.114 -				352988AC1AEF964100FA7E2E /* pEpiOSAdapter */,
   1.115 +				43209B251ECC2ACD007E7E2E /* pEpObjCAdapter */,
   1.116  				64415E181BE94FCB00F6CBB2 /* iOSTests */,
   1.117  				352988AB1AEF964100FA7E2E /* Products */,
   1.118  			);
   1.119 @@ -208,27 +198,27 @@
   1.120  			name = Products;
   1.121  			sourceTree = "<group>";
   1.122  		};
   1.123 -		352988AC1AEF964100FA7E2E /* pEpiOSAdapter */ = {
   1.124 +		43209B251ECC2ACD007E7E2E /* pEpObjCAdapter */ = {
   1.125  			isa = PBXGroup;
   1.126  			children = (
   1.127 -				352988AD1AEF964100FA7E2E /* PEPObjCAdapter.h */,
   1.128 -				64415E5A1BF3840500F6CBB2 /* PEPObjCAdapter+Internal.h */,
   1.129 -				352988AF1AEF964100FA7E2E /* PEPObjCAdapter.m */,
   1.130 -				350F0ED11B4D642200D9964F /* PEPSession.h */,
   1.131 -				642FB6551ECB4B89008D3DF3 /* PEPSession+Internal.h */,
   1.132 -				350F0ED21B4D642200D9964F /* PEPSession.m */,
   1.133 -				350F0ED71B4E997300D9964F /* PEPMessage.h */,
   1.134 -				350F0ED81B4E997300D9964F /* PEPMessage.m */,
   1.135 -				35EA58131B565643000B4CC5 /* PEPQueue.h */,
   1.136 -				35EA58141B565643000B4CC5 /* PEPQueue.m */,
   1.137 -				43293EFF1EBA067600EEE010 /* PEPLanguage.h */,
   1.138 -				43293F001EBA067600EEE010 /* PEPLanguage.m */,
   1.139 -				43293F031EBA246700EEE010 /* PEPCSVScanner.h */,
   1.140 -				43293F041EBA246700EEE010 /* PEPCSVScanner.m */,
   1.141 -				43293F061EBA364700EEE010 /* NSArray+Extension.h */,
   1.142 -				43293F071EBA364700EEE010 /* NSArray+Extension.m */,
   1.143 +				43209B261ECC2ACD007E7E2E /* NSArray+Extension.h */,
   1.144 +				43209B271ECC2ACD007E7E2E /* NSArray+Extension.m */,
   1.145 +				43209B281ECC2ACD007E7E2E /* PEPCSVScanner.h */,
   1.146 +				43209B291ECC2ACD007E7E2E /* PEPCSVScanner.m */,
   1.147 +				43209B2A1ECC2ACD007E7E2E /* PEPLanguage.h */,
   1.148 +				43209B2B1ECC2ACD007E7E2E /* PEPLanguage.m */,
   1.149 +				43209B2C1ECC2ACD007E7E2E /* PEPMessage.h */,
   1.150 +				43209B2D1ECC2ACD007E7E2E /* PEPMessage.m */,
   1.151 +				43209B2E1ECC2ACD007E7E2E /* PEPObjCAdapter+Internal.h */,
   1.152 +				43209B2F1ECC2ACD007E7E2E /* PEPObjCAdapter.h */,
   1.153 +				43209B301ECC2ACD007E7E2E /* PEPObjCAdapter.m */,
   1.154 +				43209B311ECC2ACD007E7E2E /* PEPQueue.h */,
   1.155 +				43209B321ECC2ACD007E7E2E /* PEPQueue.m */,
   1.156 +				43209B331ECC2ACD007E7E2E /* PEPSession+Internal.h */,
   1.157 +				43209B341ECC2ACD007E7E2E /* PEPSession.h */,
   1.158 +				43209B351ECC2ACD007E7E2E /* PEPSession.m */,
   1.159  			);
   1.160 -			path = pEpiOSAdapter;
   1.161 +			path = pEpObjCAdapter;
   1.162  			sourceTree = "<group>";
   1.163  		};
   1.164  		64289E521B8B70E800FC617B /* Products */ = {
   1.165 @@ -410,13 +400,13 @@
   1.166  			isa = PBXSourcesBuildPhase;
   1.167  			buildActionMask = 2147483647;
   1.168  			files = (
   1.169 -				35EA58151B565643000B4CC5 /* PEPQueue.m in Sources */,
   1.170 -				43293F051EBA246700EEE010 /* PEPCSVScanner.m in Sources */,
   1.171 -				350F0ED31B4D642200D9964F /* PEPSession.m in Sources */,
   1.172 -				350F0ED91B4E997300D9964F /* PEPMessage.m in Sources */,
   1.173 -				352988B01AEF964100FA7E2E /* PEPObjCAdapter.m in Sources */,
   1.174 -				43293F011EBA067600EEE010 /* PEPLanguage.m in Sources */,
   1.175 -				43293F081EBA364700EEE010 /* NSArray+Extension.m in Sources */,
   1.176 +				43209B411ECC2DB8007E7E2E /* PEPObjCAdapter.m in Sources */,
   1.177 +				43209B431ECC2DC0007E7E2E /* PEPSession.m in Sources */,
   1.178 +				43209B3F1ECC2DB0007E7E2E /* PEPLanguage.m in Sources */,
   1.179 +				43209B401ECC2DB4007E7E2E /* PEPMessage.m in Sources */,
   1.180 +				43209B3D1ECC2DA7007E7E2E /* NSArray+Extension.m in Sources */,
   1.181 +				43209B3E1ECC2DAB007E7E2E /* PEPCSVScanner.m in Sources */,
   1.182 +				43209B421ECC2DBC007E7E2E /* PEPQueue.m in Sources */,
   1.183  			);
   1.184  			runOnlyForDeploymentPostprocessing = 0;
   1.185  		};
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/pEpObjCAdapter/NSArray+Extension.h	Wed May 17 09:27:57 2017 +0200
     2.3 @@ -0,0 +1,25 @@
     2.4 +//
     2.5 +//  NSArray+Extension.h
     2.6 +//  pEpiOSAdapter
     2.7 +//
     2.8 +//  Created by Dirk Zimmermann on 03.05.17.
     2.9 +//  Copyright © 2017 p≡p. All rights reserved.
    2.10 +//
    2.11 +
    2.12 +#import <Foundation/Foundation.h>
    2.13 +
    2.14 +@interface ArrayTake : NSObject
    2.15 +
    2.16 +@property (nonatomic, readonly) NSArray * _Nonnull elements;
    2.17 +@property (nonatomic, readonly) NSArray * _Nonnull rest;
    2.18 +
    2.19 +@end
    2.20 +
    2.21 +@interface NSArray (Extension)
    2.22 +
    2.23 +/**
    2.24 + @Return The next count elements or nil, if less than that amount available.
    2.25 + */
    2.26 +- (ArrayTake * _Nullable)takeOrNil:(NSInteger)count;
    2.27 +
    2.28 +@end
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/pEpObjCAdapter/NSArray+Extension.m	Wed May 17 09:27:57 2017 +0200
     3.3 @@ -0,0 +1,38 @@
     3.4 +//
     3.5 +//  NSArray+Extension.m
     3.6 +//  pEpiOSAdapter
     3.7 +//
     3.8 +//  Created by Dirk Zimmermann on 03.05.17.
     3.9 +//  Copyright © 2017 p≡p. All rights reserved.
    3.10 +//
    3.11 +
    3.12 +#import "NSArray+Extension.h"
    3.13 +
    3.14 +@implementation ArrayTake
    3.15 +
    3.16 +- (instancetype)initWithElements:(NSArray * _Nonnull)elements rest:(NSArray * _Nonnull)rest
    3.17 +{
    3.18 +    if (self = [super init]) {
    3.19 +        _elements = elements;
    3.20 +        _rest = rest;
    3.21 +    }
    3.22 +    return self;
    3.23 +}
    3.24 +
    3.25 +@end
    3.26 +
    3.27 +@implementation NSArray (Extension)
    3.28 +
    3.29 +- (ArrayTake * _Nullable)takeOrNil:(NSInteger)count
    3.30 +{
    3.31 +    if (self.count >= count) {
    3.32 +        NSInteger restCount = self.count - count;
    3.33 +        NSArray *elements = [self subarrayWithRange:NSMakeRange(0, count)];
    3.34 +        NSArray *rest = [self subarrayWithRange:NSMakeRange(count, restCount)];
    3.35 +        ArrayTake *taken = [[ArrayTake alloc] initWithElements:elements rest:rest];
    3.36 +        return taken;
    3.37 +    }
    3.38 +    return nil;
    3.39 +}
    3.40 +
    3.41 +@end
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/pEpObjCAdapter/PEPCSVScanner.h	Wed May 17 09:27:57 2017 +0200
     4.3 @@ -0,0 +1,18 @@
     4.4 +//
     4.5 +//  PEPCSVScanner.h
     4.6 +//  pEpiOSAdapter
     4.7 +//
     4.8 +//  Created by Dirk Zimmermann on 03.05.17.
     4.9 +//  Copyright © 2017 p≡p. All rights reserved.
    4.10 +//
    4.11 +
    4.12 +#import <Foundation/Foundation.h>
    4.13 +
    4.14 +@interface PEPCSVScanner : NSObject
    4.15 +
    4.16 +@property (nonatomic, readonly, nonnull) NSString *string;
    4.17 +
    4.18 +- (instancetype _Nonnull )initWithString:(NSString * _Nonnull)string;
    4.19 +- (NSString * _Nullable)nextString;
    4.20 +
    4.21 +@end
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/pEpObjCAdapter/PEPCSVScanner.m	Wed May 17 09:27:57 2017 +0200
     5.3 @@ -0,0 +1,82 @@
     5.4 +//
     5.5 +//  PEPCSVScanner.m
     5.6 +//  pEpiOSAdapter
     5.7 +//
     5.8 +//  Created by Dirk Zimmermann on 03.05.17.
     5.9 +//  Copyright © 2017 p≡p. All rights reserved.
    5.10 +//
    5.11 +
    5.12 +#import "PEPCSVScanner.h"
    5.13 +
    5.14 +static unichar s_quoteChar = '"';
    5.15 +
    5.16 +@interface PEPCSVScanner ()
    5.17 +
    5.18 +@property (nonatomic) NSInteger position;
    5.19 +@property (nonatomic) NSInteger len;
    5.20 +
    5.21 +@end;
    5.22 +
    5.23 +@implementation PEPCSVScanner
    5.24 +
    5.25 +- (instancetype _Nonnull )initWithString:(NSString * _Nonnull)string
    5.26 +{
    5.27 +    if (self = [super init]) {
    5.28 +        _string = string;
    5.29 +        _len = [string length];
    5.30 +    }
    5.31 +    return self;
    5.32 +}
    5.33 +
    5.34 +- (NSString * _Nullable)nextString
    5.35 +{
    5.36 +    NSInteger startPos = NSNotFound;
    5.37 +    for (NSInteger thePos = self.position; thePos < self.len; thePos++) {
    5.38 +        if ([self startingQuoteAt:thePos]) {
    5.39 +            startPos = thePos + 1;
    5.40 +            for (NSInteger endPos = startPos; endPos < self.len; endPos++) {
    5.41 +                if ([self endingQuoteAt:endPos]) {
    5.42 +                    self.position = endPos + 1;
    5.43 +                    return [self.string substringWithRange:NSMakeRange(startPos, endPos - startPos)];
    5.44 +                }
    5.45 +            }
    5.46 +        }
    5.47 +    }
    5.48 +    return nil;
    5.49 +}
    5.50 +
    5.51 +/**
    5.52 + @return YES if the given position points to a starting quote.
    5.53 + */
    5.54 +- (BOOL)startingQuoteAt:(NSInteger)pos
    5.55 +{
    5.56 +    // The last char can never be a starting quote
    5.57 +    if (pos >= self.len - 1) {
    5.58 +        return NO;
    5.59 +    }
    5.60 +    unichar ch1 = [self.string characterAtIndex:pos];
    5.61 +    unichar ch2 = [self.string characterAtIndex:pos + 1];
    5.62 +    if (ch1 == s_quoteChar && ch2 != s_quoteChar) {
    5.63 +        return YES;
    5.64 +    }
    5.65 +    return NO;
    5.66 +}
    5.67 +
    5.68 +/**
    5.69 + @return YES if the given position points to an ending quote.
    5.70 + */
    5.71 +- (BOOL)endingQuoteAt:(NSInteger)pos
    5.72 +{
    5.73 +    NSString *context = [self.string substringFromIndex:pos];
    5.74 +    unichar ch1 = [self.string characterAtIndex:pos];
    5.75 +    if (ch1 == s_quoteChar) {
    5.76 +        if (pos == self.len - 1) {
    5.77 +            return YES;
    5.78 +        }
    5.79 +        unichar ch2 = [self.string characterAtIndex:pos + 1];
    5.80 +        return ch2 != s_quoteChar;
    5.81 +    }
    5.82 +    return NO;
    5.83 +}
    5.84 +
    5.85 +@end
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/pEpObjCAdapter/PEPLanguage.h	Wed May 17 09:27:57 2017 +0200
     6.3 @@ -0,0 +1,33 @@
     6.4 +//
     6.5 +//  PEPLanguage.h
     6.6 +//  pEpiOSAdapter
     6.7 +//
     6.8 +//  Created by Dirk Zimmermann on 03.05.17.
     6.9 +//  Copyright © 2017 p≡p. All rights reserved.
    6.10 +//
    6.11 +
    6.12 +#import <Foundation/Foundation.h>
    6.13 +
    6.14 +@interface PEPLanguage : NSObject
    6.15 +
    6.16 +- (instancetype _Nonnull)initWithCode:(NSString * _Nonnull)code
    6.17 +                                 name:(NSString * _Nonnull)name
    6.18 +                                 sentence:(NSString * _Nonnull)sentence;
    6.19 +
    6.20 +/**
    6.21 + ISO 639-1 language code
    6.22 + */
    6.23 +@property (nonatomic, nonnull) NSString *code;
    6.24 +
    6.25 +/**
    6.26 + Name of the language. Should not be translated.
    6.27 + */
    6.28 +@property (nonatomic, nonnull) NSString *name;
    6.29 +
    6.30 +/**
    6.31 + Sentence of the form "I want to display the trustwords in <lang>".
    6.32 + Should not be translated.
    6.33 + */
    6.34 +@property (nonatomic, nonnull) NSString *sentence;
    6.35 +
    6.36 +@end
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/pEpObjCAdapter/PEPLanguage.m	Wed May 17 09:27:57 2017 +0200
     7.3 @@ -0,0 +1,35 @@
     7.4 +//
     7.5 +//  PEPLanguage.m
     7.6 +//  pEpiOSAdapter
     7.7 +//
     7.8 +//  Created by Dirk Zimmermann on 03.05.17.
     7.9 +//  Copyright © 2017 p≡p. All rights reserved.
    7.10 +//
    7.11 +
    7.12 +#import "PEPLanguage.h"
    7.13 +
    7.14 +@implementation PEPLanguage
    7.15 +
    7.16 +- (instancetype _Nonnull)initWithCode:(NSString * _Nonnull)code
    7.17 +                                 name:(NSString * _Nonnull)name
    7.18 +                                 sentence:(NSString * _Nonnull)sentence
    7.19 +{
    7.20 +    if (self = [[PEPLanguage alloc] init]) {
    7.21 +        _code = code;
    7.22 +        _name = name;
    7.23 +        _sentence = sentence;
    7.24 +    }
    7.25 +    return self;
    7.26 +}
    7.27 +
    7.28 +- (NSString *)debugDescription
    7.29 +{
    7.30 +    return [NSString stringWithFormat:@"<%@: %p> %@", [self class], self, self.description];
    7.31 +}
    7.32 +
    7.33 +- (NSString *)description
    7.34 +{
    7.35 +    return [NSString stringWithFormat:@"%@ %@", self.code, self.name];
    7.36 +}
    7.37 +
    7.38 +@end
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/pEpObjCAdapter/PEPMessage.h	Wed May 17 09:27:57 2017 +0200
     8.3 @@ -0,0 +1,114 @@
     8.4 +//
     8.5 +//  MCOAbstractMessage+PEPMessage.h
     8.6 +//  pEpiOSAdapter
     8.7 +//
     8.8 +//  Created by Volker Birk on 09.07.15.
     8.9 +//  Copyright (c) 2015 p≡p. All rights reserved.
    8.10 +//
    8.11 +
    8.12 +#import <Foundation/Foundation.h>
    8.13 +
    8.14 +#include "message_api.h"
    8.15 +
    8.16 +NSArray * _Nonnull PEP_arrayFromStringlist(stringlist_t * _Nonnull sl);
    8.17 +stringlist_t * _Nullable PEP_arrayToStringlist(NSArray * _Nullable array);
    8.18 +
    8.19 +pEp_identity * _Nullable PEP_identityDictToStruct(NSDictionary * _Nullable dict);
    8.20 +NSDictionary * _Nonnull PEP_identityDictFromStruct(pEp_identity * _Nullable ident);
    8.21 +
    8.22 +message * _Nullable PEP_messageDictToStruct(NSDictionary * _Nullable dict);
    8.23 +NSDictionary * _Nonnull PEP_messageDictFromStruct(message * _Nullable msg);
    8.24 +
    8.25 +#pragma mark -- Constants
    8.26 +
    8.27 +/** The name of the user */
    8.28 +extern NSString *const _Nonnull kPepUsername;
    8.29 +
    8.30 +/** Email address of the contact */
    8.31 +extern NSString *const _Nonnull kPepAddress;
    8.32 +
    8.33 +/**
    8.34 + A user ID, used by pEp to map multiple identities to a single user.
    8.35 + This should be a stable ID (e.g. derived from the address book if possible).
    8.36 + pEp identities set up with mySelf() get a special user ID.
    8.37 + */
    8.38 +extern NSString *const _Nonnull kPepUserID;
    8.39 +
    8.40 +/** The fingerprint for the key for this contact. */
    8.41 +extern NSString *const _Nonnull kPepFingerprint;
    8.42 +
    8.43 +/** NSNumber denoting a boolean, true if that identity was setup with mySelf() */
    8.44 +extern NSString *const _Nonnull kPepIsMe;
    8.45 +
    8.46 +/** In an email, the identity this email is from */
    8.47 +extern NSString *const _Nonnull kPepFrom;
    8.48 +
    8.49 +/** In an email, the `NSArray` of to recipients */
    8.50 +extern NSString *const _Nonnull kPepTo;
    8.51 +
    8.52 +/** In an email, the `NSArray` of CC recipients */
    8.53 +extern NSString *const _Nonnull kPepCC;
    8.54 +
    8.55 +/** In an email, the `NSArray` of BCC recipients */
    8.56 +extern NSString *const _Nonnull kPepBCC;
    8.57 +
    8.58 +/** The subject of an email */
    8.59 +extern NSString *const _Nonnull kPepShortMessage;
    8.60 +
    8.61 +/** The text message of an email */
    8.62 +extern NSString *const _Nonnull kPepLongMessage;
    8.63 +
    8.64 +/** HTML message part, if any */
    8.65 +extern NSString *const _Nonnull kPepLongMessageFormatted;
    8.66 +
    8.67 +/** NSNumber denoting a boolean. True if that message is supposed to be sent. */
    8.68 +extern NSString *const _Nonnull kPepOutgoing;
    8.69 +
    8.70 +/** Sent date of the message (NSDate) */
    8.71 +extern NSString *const _Nonnull kPepSent;
    8.72 +
    8.73 +/** Received date of the message (NSDate) */
    8.74 +extern NSString *const _Nonnull kPepReceived;
    8.75 +
    8.76 +/** The message ID */
    8.77 +extern NSString *const _Nonnull kPepID;
    8.78 +
    8.79 +extern NSString *const _Nonnull kPepReceivedBy;
    8.80 +extern NSString *const _Nonnull kPepReplyTo;
    8.81 +extern NSString *const _Nonnull kPepInReplyTo;
    8.82 +extern NSString *const _Nonnull kPepReferences;
    8.83 +extern NSString *const _Nonnull kPepKeywords;
    8.84 +extern NSString *const _Nonnull kPepOptFields;
    8.85 +
    8.86 +/** NSArray of attachment dicts */
    8.87 +extern NSString *const _Nonnull kPepAttachments;
    8.88 +
    8.89 +/** The binary NSData representing the content of an attachment */
    8.90 +extern NSString *const _Nonnull kPepMimeData;
    8.91 +
    8.92 +/** The NSString filename of an attachment, if any */
    8.93 +extern NSString *const _Nonnull kPepMimeFilename;
    8.94 +
    8.95 +/** The mime type of an attachment */
    8.96 +extern NSString *const _Nonnull kPepMimeType;
    8.97 +
    8.98 +/** The content ID of an attachment */
    8.99 +extern NSString *const _Nonnull kPepContentID;
   8.100 +
   8.101 +/** The pEp internal communication type */
   8.102 +extern NSString *const _Nonnull kPepCommType;
   8.103 +
   8.104 +/** The raw message created by pEp (NSData) */
   8.105 +extern NSString *const _Nonnull kPepRawMessage;
   8.106 +
   8.107 +/** NSError parameters will use this domain */
   8.108 +extern NSString *const _Nonnull PEPSessionErrorDomain;
   8.109 +
   8.110 +/** Optional field "X-pEp-Version" */
   8.111 +extern NSString *const _Nonnull kXpEpVersion;
   8.112 +
   8.113 +/** Optional field "X-EncStatus" */
   8.114 +extern NSString *const _Nonnull kXEncStatus;
   8.115 +
   8.116 +/** Optional field "X-KeyList" */
   8.117 +extern NSString *const _Nonnull kXKeylist;
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/pEpObjCAdapter/PEPMessage.m	Wed May 17 09:27:57 2017 +0200
     9.3 @@ -0,0 +1,434 @@
     9.4 +//
     9.5 +//  PEPMessage.m
     9.6 +//  pEpiOSAdapter
     9.7 +//
     9.8 +//  Created by Volker Birk on 09.07.15.
     9.9 +//  Copyright (c) 2015 p≡p. All rights reserved.
    9.10 +//
    9.11 +
    9.12 +#import "PEPMessage.h"
    9.13 +
    9.14 +#pragma mark -- Constants
    9.15 +
    9.16 +NSString *const kPepUsername = @"username";
    9.17 +
    9.18 +NSString *const kPepAddress = @"address";
    9.19 +
    9.20 +NSString *const kPepUserID = @"user_id";
    9.21 +
    9.22 +NSString *const kPepFingerprint = @"fpr";
    9.23 +
    9.24 +NSString *const kPepIsMe = @"me";
    9.25 +
    9.26 +NSString *const kPepFrom = @"from";
    9.27 +
    9.28 +NSString *const kPepTo = @"to";
    9.29 +
    9.30 +NSString *const kPepCC = @"cc";
    9.31 +
    9.32 +NSString *const kPepBCC = @"bcc";
    9.33 +
    9.34 +NSString *const kPepShortMessage = @"shortmsg";
    9.35 +
    9.36 +NSString *const kPepLongMessage = @"longmsg";
    9.37 +
    9.38 +NSString *const kPepLongMessageFormatted = @"longmsg_formatted";
    9.39 +
    9.40 +NSString *const kPepOutgoing = @"outgoing";
    9.41 +
    9.42 +NSString *const kPepSent = @"sent";
    9.43 +
    9.44 +NSString *const kPepReceived = @"recv";
    9.45 +
    9.46 +NSString *const kPepID = @"id";
    9.47 +
    9.48 +NSString *const kPepReceivedBy = @"recv_by";
    9.49 +NSString *const kPepReplyTo = @"reply_to";
    9.50 +NSString *const kPepInReplyTo = @"in_reply_to";
    9.51 +NSString *const kPepReferences = @"references";
    9.52 +NSString *const kPepKeywords = @"keywords";
    9.53 +NSString *const kPepOptFields = @"opt_fields";
    9.54 +
    9.55 +NSString *const kPepAttachments = @"attachments";
    9.56 +
    9.57 +NSString *const kPepMimeData = @"data";
    9.58 +
    9.59 +NSString *const kPepMimeFilename = @"filename";
    9.60 +
    9.61 +NSString *const kPepMimeType = @"mimeType";
    9.62 +
    9.63 +NSString *const kPepContentID = @"contentID";
    9.64 +
    9.65 +NSString *const kPepCommType = @"comm_type";
    9.66 +
    9.67 +NSString *const kPepRawMessage = @"raw_message";
    9.68 +
    9.69 +NSString *const kXpEpVersion = @"X-pEp-Version";
    9.70 +
    9.71 +NSString *const kXEncStatus = @"X-EncStatus";
    9.72 +
    9.73 +NSString *const kXKeylist = @"X-KeyList";
    9.74 +
    9.75 +NSArray *PEP_arrayFromStringlist(stringlist_t *sl)
    9.76 +{
    9.77 +    NSMutableArray *array = [NSMutableArray array];
    9.78 +    
    9.79 +    for (stringlist_t *_sl = sl; _sl && _sl->value; _sl = _sl->next) {
    9.80 +        [array addObject:[NSString stringWithUTF8String:_sl->value]];
    9.81 +    }
    9.82 +    
    9.83 +    return array;
    9.84 +}
    9.85 +
    9.86 +stringlist_t *PEP_arrayToStringlist(NSArray *array)
    9.87 +{
    9.88 +    stringlist_t *sl = new_stringlist(NULL);
    9.89 +    if (!sl)
    9.90 +        return NULL;
    9.91 +    
    9.92 +    stringlist_t *_sl = sl;
    9.93 +    for (NSString *str in array) {
    9.94 +        _sl = stringlist_add(_sl, [[str precomposedStringWithCanonicalMapping] UTF8String]);
    9.95 +    }
    9.96 +    
    9.97 +    return sl;
    9.98 +}
    9.99 +
   9.100 +NSArray *PEP_arrayFromStringPairlist(stringpair_list_t *sl)
   9.101 +{
   9.102 +    NSMutableArray *array = [NSMutableArray array];
   9.103 +
   9.104 +    for (stringpair_list_t *_sl = sl; _sl && _sl->value; _sl = _sl->next) {
   9.105 +        [array addObject:[[NSMutableArray alloc ]initWithObjects:
   9.106 +                [NSString stringWithUTF8String:_sl->value->key],
   9.107 +                [NSString stringWithUTF8String:_sl->value->value],
   9.108 +                nil]];
   9.109 +    }
   9.110 +
   9.111 +    return array;
   9.112 +}
   9.113 +
   9.114 +stringpair_list_t *PEP_arrayToStringPairlist(NSArray *array)
   9.115 +{
   9.116 +    stringpair_list_t *sl = new_stringpair_list(NULL);
   9.117 +    if (!sl)
   9.118 +        return NULL;
   9.119 +    
   9.120 +    stringpair_list_t *_sl = sl;
   9.121 +    for (NSArray *pair in array) {
   9.122 +        stringpair_t *_sp = new_stringpair(
   9.123 +               [[pair[0] precomposedStringWithCanonicalMapping] UTF8String],
   9.124 +               [[pair[1] precomposedStringWithCanonicalMapping] UTF8String]);
   9.125 +        _sl = stringpair_list_add(_sl, _sp);
   9.126 +    }
   9.127 +    
   9.128 +    return sl;
   9.129 +}
   9.130 +
   9.131 +
   9.132 +NSArray *PEP_arrayFromBloblist(bloblist_t *bl)
   9.133 +{
   9.134 +    NSMutableArray *array = [NSMutableArray array];
   9.135 +    
   9.136 +    for (bloblist_t *_bl = bl; _bl && _bl->value; _bl = _bl->next) {
   9.137 +        NSMutableDictionary* blob = [NSMutableDictionary new];
   9.138 +        [blob setObject: [NSData dataWithBytes:_bl->value
   9.139 +                                 length:_bl->size]
   9.140 +              forKey:@"data"];
   9.141 +        
   9.142 +        if(_bl->filename && _bl->filename[0])
   9.143 +            [blob setObject:[NSString stringWithUTF8String:_bl->filename]
   9.144 +                 forKey:@"filename"];
   9.145 +        
   9.146 +        if(_bl->mime_type && _bl->mime_type[0])
   9.147 +            [blob setObject: [NSString stringWithUTF8String:_bl->mime_type]
   9.148 +                 forKey:@"mimeType"];
   9.149 +        
   9.150 +        [array addObject:blob];
   9.151 +    }
   9.152 +    return array;
   9.153 +}
   9.154 +
   9.155 +bloblist_t *PEP_arrayToBloblist(NSArray *array)
   9.156 +{
   9.157 +    if (array.count == 0) {
   9.158 +        return nil;
   9.159 +    }
   9.160 +
   9.161 +    bloblist_t *_bl = new_bloblist(NULL, 0, NULL, NULL);
   9.162 +    bloblist_t *bl =_bl;
   9.163 +    for (NSMutableDictionary *blob in array) {
   9.164 +        NSData *data = blob[@"data"];
   9.165 +        size_t size = [data length];
   9.166 +        
   9.167 +        char *buf = malloc(size);
   9.168 +        assert(buf);
   9.169 +        memcpy(buf, [data bytes], size);
   9.170 +        
   9.171 +        bl = bloblist_add(bl, buf, size,
   9.172 +                          [blob[@"mimeType"] UTF8String],
   9.173 +                          [[blob[@"filename"] precomposedStringWithCanonicalMapping] UTF8String]);
   9.174 +    }
   9.175 +    return _bl;
   9.176 +}
   9.177 +
   9.178 +NSDictionary *PEP_identityDictFromStruct(pEp_identity *ident)
   9.179 +{
   9.180 +    NSMutableDictionary *dict = [NSMutableDictionary new];
   9.181 +
   9.182 +    if (ident) {
   9.183 +        if (ident->address && ident->address[0])
   9.184 +            [dict setObject:[NSString stringWithUTF8String:ident->address] forKey:@"address"];
   9.185 +        
   9.186 +        if (ident->fpr && ident->fpr[0])
   9.187 +            [dict setObject:[NSString stringWithUTF8String:ident->fpr] forKey:@"fpr"];
   9.188 +        
   9.189 +        if (ident->user_id && ident->user_id[0])
   9.190 +            [dict setObject:[NSString stringWithUTF8String:ident->user_id] forKey:@"user_id"];
   9.191 +        
   9.192 +        if (ident->username && ident->username[0])
   9.193 +            [dict setObject:[NSString stringWithUTF8String:ident->username] forKey:@"username"];
   9.194 +        
   9.195 +        if (ident->lang[0])
   9.196 +            [dict setObject:[NSString stringWithUTF8String:ident->lang] forKey:@"lang"];
   9.197 +        
   9.198 +        [dict setObject:[NSNumber numberWithInt: ident->comm_type] forKey:@"comm_type"];
   9.199 +        
   9.200 +        if (ident->me)
   9.201 +            [dict setObject:@YES forKey:@"me"];
   9.202 +        else
   9.203 +            [dict setObject:@NO forKey:@"me"];
   9.204 +    }
   9.205 +    return dict;
   9.206 +}
   9.207 +
   9.208 +pEp_identity *PEP_identityDictToStruct(NSDictionary *dict)
   9.209 +{
   9.210 +    pEp_identity *ident = new_identity(NULL, NULL, NULL, NULL);
   9.211 +    
   9.212 +    if (dict && ident) {
   9.213 +        if ([dict objectForKey:@"address"])
   9.214 +            ident->address = strdup(
   9.215 +                                    [[[dict objectForKey:@"address"] precomposedStringWithCanonicalMapping] UTF8String]
   9.216 +                                    );
   9.217 +        
   9.218 +        if ([dict objectForKey:@"fpr"]){
   9.219 +            ident->fpr = strdup(
   9.220 +                                [[[dict objectForKey:@"fpr"] precomposedStringWithCanonicalMapping] UTF8String]
   9.221 +                                );
   9.222 +        }
   9.223 +        
   9.224 +        if ([dict objectForKey:@"user_id"]){
   9.225 +            ident->user_id = strdup(
   9.226 +                                    [[[dict objectForKey:@"user_id"] precomposedStringWithCanonicalMapping] UTF8String]
   9.227 +                                    );
   9.228 +        }
   9.229 +        
   9.230 +        if ([dict objectForKey:@"username"])
   9.231 +            ident->username = strdup(
   9.232 +                                     [[[dict objectForKey:@"username"] precomposedStringWithCanonicalMapping] UTF8String]
   9.233 +                                     );
   9.234 +        
   9.235 +        if ([dict objectForKey:@"lang"])
   9.236 +            strncpy(ident->fpr, [[[dict objectForKey:@"lang"] precomposedStringWithCanonicalMapping] UTF8String], 2);
   9.237 +        
   9.238 +        if ([[dict objectForKey:@"me"] isEqual: @YES])
   9.239 +            ident->me = true;
   9.240 +        
   9.241 +        if ([dict objectForKey:@"comm_type"])
   9.242 +            ident->comm_type = [[dict objectForKey:@"comm_type"] intValue];
   9.243 +    }
   9.244 +    
   9.245 +    return ident;
   9.246 +}
   9.247 +
   9.248 +NSArray *PEP_arrayFromIdentityList(identity_list *il)
   9.249 +{
   9.250 +    NSMutableArray *array = [NSMutableArray array];
   9.251 +    
   9.252 +    for (identity_list *_il = il; _il && _il->ident; _il = _il->next) {
   9.253 +        [array addObject:PEP_identityDictFromStruct(il->ident)];
   9.254 +    }
   9.255 +    
   9.256 +    return array;
   9.257 +}
   9.258 +
   9.259 +identity_list *PEP_arrayToIdentityList(NSArray *array)
   9.260 +{
   9.261 +    identity_list *il = new_identity_list(NULL);
   9.262 +    if (!il)
   9.263 +        return NULL;
   9.264 +    
   9.265 +    identity_list *_il = il;
   9.266 +    for (NSDictionary *dict in array) {
   9.267 +        _il = identity_list_add(_il, PEP_identityDictToStruct(dict));
   9.268 +    }
   9.269 +    
   9.270 +    return il;
   9.271 +}
   9.272 +
   9.273 +identity_list *PEP_identityArrayToList(NSArray *array)
   9.274 +{
   9.275 +    identity_list *il = new_identity_list(NULL);
   9.276 +    if (!il)
   9.277 +        return NULL;
   9.278 +    
   9.279 +    identity_list *_il = il;
   9.280 +    for (NSMutableDictionary *address in array) {
   9.281 +        _il = identity_list_add(_il, PEP_identityDictToStruct(address));
   9.282 +    }
   9.283 +    
   9.284 +    return il;
   9.285 +}
   9.286 +
   9.287 +NSArray *PEP_identityArrayFromList(identity_list *il)
   9.288 +{
   9.289 +    NSMutableArray *array = [NSMutableArray array];
   9.290 +    
   9.291 +    for (identity_list *_il = il; _il && _il->ident; _il = _il->next) {
   9.292 +        NSDictionary *address = PEP_identityDictFromStruct(_il->ident);
   9.293 +        [array addObject:address];
   9.294 +    }
   9.295 +    
   9.296 +    return array;
   9.297 +}
   9.298 +
   9.299 +NSDictionary *PEP_messageDictFromStruct(message *msg)
   9.300 +{
   9.301 +    NSMutableDictionary *dict = [NSMutableDictionary new];
   9.302 +    if (msg && dict) {
   9.303 +
   9.304 +        [dict setObject:(msg->dir==PEP_dir_outgoing)?@YES:@NO forKey:@"outgoing"];
   9.305 +
   9.306 +        if (msg->id)
   9.307 +            [dict setObject:[NSString stringWithUTF8String:msg->id] forKey:@"id"];
   9.308 +        
   9.309 +        if (msg->shortmsg)
   9.310 +            [dict setObject:[NSString stringWithUTF8String:msg->shortmsg] forKey:@"shortmsg"];
   9.311 +
   9.312 +        if (msg->sent)
   9.313 +            [dict setObject:[NSDate dateWithTimeIntervalSince1970:timegm(msg->sent)] forKey:@"sent"];
   9.314 +        
   9.315 +        if (msg->recv)
   9.316 +            [dict setObject:[NSDate dateWithTimeIntervalSince1970:mktime(msg->recv)] forKey:@"recv"];
   9.317 +        
   9.318 +        if (msg->from)
   9.319 +            [dict setObject:PEP_identityDictFromStruct(msg->from) forKey:@"from"];
   9.320 +        
   9.321 +        if (msg->to && msg->to->ident)
   9.322 +            [dict setObject:PEP_identityArrayFromList(msg->to) forKey:@"to"];
   9.323 +        
   9.324 +        if (msg->recv_by)
   9.325 +            [dict setObject:PEP_identityDictFromStruct(msg->recv_by) forKey:@"recv_by"];
   9.326 +        
   9.327 +        if (msg->cc && msg->cc->ident)
   9.328 +            [dict setObject:PEP_identityArrayFromList(msg->cc) forKey:@"cc"];
   9.329 +        
   9.330 +        if (msg->bcc && msg->bcc->ident)
   9.331 +            [dict setObject:PEP_identityArrayFromList(msg->bcc) forKey:@"bcc"];
   9.332 +        
   9.333 +        if (msg->reply_to && msg->reply_to->ident)
   9.334 +            [dict setObject:PEP_identityArrayFromList(msg->reply_to) forKey:@"reply_to"];
   9.335 +        
   9.336 +        if (msg->in_reply_to)
   9.337 +            [dict setObject:PEP_arrayFromStringlist(msg->in_reply_to) forKey:@"in_reply_to"];
   9.338 +
   9.339 +        if (msg->references && msg->references->value)
   9.340 +            [dict setObject:PEP_arrayFromStringlist(msg->references) forKey:kPepReferences];
   9.341 +
   9.342 +        if (msg->keywords && msg->keywords->value)
   9.343 +            [dict setObject:PEP_arrayFromStringlist(msg->keywords) forKey:@"keywords"];
   9.344 +
   9.345 +        if (msg->opt_fields)
   9.346 +            [dict setObject:PEP_arrayFromStringPairlist(msg->opt_fields) forKey:@"opt_fields"];
   9.347 +        
   9.348 +        if (msg->longmsg_formatted)
   9.349 +            [dict setObject:[NSString stringWithUTF8String:msg->longmsg_formatted]
   9.350 +                     forKey:@"longmsg_formatted"];
   9.351 +
   9.352 +        if (msg->longmsg)
   9.353 +            [dict setObject:[NSString stringWithUTF8String:msg->longmsg] forKey:@"longmsg"];
   9.354 +        
   9.355 +        if (msg->attachments && msg->attachments->value)
   9.356 +            [dict setObject: PEP_arrayFromBloblist(msg->attachments) forKey:@"attachments"];
   9.357 +
   9.358 +        if (msg->rawmsg_size > 0 && *msg->rawmsg_ref) {
   9.359 +            NSData *data = [NSData dataWithBytes:msg->rawmsg_ref length:msg->rawmsg_size];
   9.360 +            dict[kPepRawMessage] = data;
   9.361 +        }
   9.362 +
   9.363 +        return dict;
   9.364 +    }
   9.365 +    return nil;
   9.366 +}
   9.367 +
   9.368 +message *PEP_messageDictToStruct(NSDictionary *dict)
   9.369 +{
   9.370 +    // Direction default to incoming
   9.371 +    PEP_msg_direction dir = PEP_dir_incoming;
   9.372 +    
   9.373 +    if ([dict objectForKey:@"outgoing"])
   9.374 +        dir = [[dict objectForKey:@"outgoing"] boolValue] ? PEP_dir_outgoing : PEP_dir_incoming;
   9.375 +    
   9.376 +    message *msg = new_message(dir);
   9.377 +    
   9.378 +    if(!msg)
   9.379 +        return NULL;
   9.380 +    
   9.381 +    if ([dict objectForKey:@"id"])
   9.382 +        msg->id = strdup([[[dict objectForKey:@"id"] precomposedStringWithCanonicalMapping]
   9.383 +                          UTF8String]);
   9.384 +    
   9.385 +    if ([dict objectForKey:@"shortmsg"])
   9.386 +        msg->shortmsg = strdup([[[dict objectForKey:@"shortmsg"]
   9.387 +                                 precomposedStringWithCanonicalMapping] UTF8String]);
   9.388 +
   9.389 +    if ([dict objectForKey:@"sent"])
   9.390 +        msg->sent = new_timestamp([[dict objectForKey:@"sent"] timeIntervalSince1970]);
   9.391 +    
   9.392 +    if ([dict objectForKey:@"recv"])
   9.393 +        msg->recv = new_timestamp([[dict objectForKey:@"recv"] timeIntervalSince1970]);
   9.394 +    
   9.395 +    if ([dict objectForKey:@"from"])
   9.396 +        msg->from = PEP_identityDictToStruct([dict objectForKey:@"from"]);
   9.397 +
   9.398 +    if ([dict objectForKey:@"to"])
   9.399 +        msg->to = PEP_identityArrayToList([dict objectForKey:@"to"]);
   9.400 +
   9.401 +    if ([dict objectForKey:@"recv_by"])
   9.402 +        msg->recv_by = PEP_identityDictToStruct([dict objectForKey:@"recv_by"]);
   9.403 +
   9.404 +    if ([dict objectForKey:@"cc"])
   9.405 +        msg->cc = PEP_identityArrayToList([dict objectForKey:@"cc"]);
   9.406 +
   9.407 +    if ([dict objectForKey:@"bcc"])
   9.408 +        msg->bcc = PEP_identityArrayToList([dict objectForKey:@"bcc"]);
   9.409 +    
   9.410 +    if ([dict objectForKey:@"reply_to"])
   9.411 +        msg->reply_to = PEP_identityArrayToList([dict objectForKey:@"reply_to"]);
   9.412 +    
   9.413 +    if ([dict objectForKey:@"in_reply_to"])
   9.414 +        msg->in_reply_to = PEP_arrayToStringlist([dict objectForKey:@"in_reply_to"]);
   9.415 +    
   9.416 +    if ([dict objectForKey:@"references"])
   9.417 +        msg->references = PEP_arrayToStringlist([dict objectForKey:@"references"]);
   9.418 +    
   9.419 +    if ([dict objectForKey:kPepKeywords])
   9.420 +        msg->keywords = PEP_arrayToStringlist([dict objectForKey:kPepKeywords]);
   9.421 +
   9.422 +    if ([dict objectForKey:@"opt_fields"])
   9.423 +        msg->opt_fields = PEP_arrayToStringPairlist([dict objectForKey:@"opt_fields"]);
   9.424 +    
   9.425 +    if ([dict objectForKey:@"longmsg"])
   9.426 +        msg->longmsg = strdup([[[dict objectForKey:@"longmsg"]
   9.427 +             precomposedStringWithCanonicalMapping] UTF8String]);
   9.428 +    
   9.429 +    if ([dict objectForKey:@"longmsg_formatted"])
   9.430 +        msg->longmsg_formatted = strdup([[[dict objectForKey:@"longmsg_formatted"]
   9.431 +             precomposedStringWithCanonicalMapping] UTF8String]);
   9.432 +
   9.433 +    if ([dict objectForKey:@"attachments"])
   9.434 +        msg->attachments = PEP_arrayToBloblist([dict objectForKey:@"attachments"]);
   9.435 +
   9.436 +    return msg;
   9.437 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/pEpObjCAdapter/PEPObjCAdapter+Internal.h	Wed May 17 09:27:57 2017 +0200
    10.3 @@ -0,0 +1,33 @@
    10.4 +//
    10.5 +//  PEPIOSAdapter+Internal.h
    10.6 +//  pEpiOSAdapter
    10.7 +//
    10.8 +//  Created by Edouard Tisserant on 11/11/15.
    10.9 +//  Copyright © 2015 p≡p. All rights reserved.
   10.10 +//
   10.11 +
   10.12 +#ifndef PEPIOSAdapter_Internal_h
   10.13 +#define PEPIOSAdapter_Internal_h
   10.14 +
   10.15 +#import "sync.h"
   10.16 +
   10.17 +#import "PEPQueue.h"
   10.18 +#import "PEPSession.h"
   10.19 +#import "PEPSession+Internal.h"
   10.20 +
   10.21 +@interface PEPObjCAdapter ()
   10.22 +
   10.23 +// this messages are for internal use only; do not call
   10.24 +
   10.25 ++ (void)registerExamineFunction:(PEP_SESSION)session;
   10.26 ++ (PEPQueue*)getLookupQueue;
   10.27 +
   10.28 ++ (PEPQueue*)getSyncQueue;
   10.29 ++ (id <PEPSyncDelegate>)getSyncDelegate;
   10.30 ++ (void)bindSession:(PEPSession*)session;
   10.31 ++ (void)unbindSession:(PEPSession*)session;
   10.32 +
   10.33 +
   10.34 +@end
   10.35 +
   10.36 +#endif /* PEPIOSAdapter_Internal_h */
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/pEpObjCAdapter/PEPObjCAdapter.h	Wed May 17 09:27:57 2017 +0200
    11.3 @@ -0,0 +1,61 @@
    11.4 +//
    11.5 +//  pEpiOSAdapter.h
    11.6 +//  pEpiOSAdapter
    11.7 +//
    11.8 +//  Created by Volker Birk on 28.04.15.
    11.9 +//  Copyright (c) 2015 p≡p. All rights reserved.
   11.10 +//
   11.11 +
   11.12 +#import <Foundation/Foundation.h>
   11.13 +
   11.14 +#include "message_api.h"
   11.15 +#include "sync_app.h"
   11.16 +
   11.17 +@protocol PEPKeyManagementDelegate <NSObject>
   11.18 +
   11.19 +- (void)identityUpdated:(id)identity;
   11.20 +
   11.21 +@end
   11.22 +
   11.23 +@protocol PEPSyncDelegate <NSObject>
   11.24 +
   11.25 +- (PEP_STATUS)notifyHandshakeWithSignal:(sync_handshake_signal)signal me:(id)me partner:(id)partner;
   11.26 +
   11.27 +- (PEP_STATUS)sendMessage:(id)msg;
   11.28 +
   11.29 +@end
   11.30 +
   11.31 +@interface PEPObjCAdapter : NSObject
   11.32 +
   11.33 +/**
   11.34 + The HOME URL, where all pEp related files will be stored.
   11.35 + */
   11.36 ++ (NSURL *)homeURL;
   11.37 +
   11.38 +/**
   11.39 + Start keyserver lookup.
   11.40 + - Note: There is only one keyserver lookup thread
   11.41 + */
   11.42 ++ (void)startKeyserverLookup;
   11.43 +
   11.44 +/**
   11.45 + Stop keyserver lookup.
   11.46 + */
   11.47 ++ (void)stopKeyserverLookup;
   11.48 +
   11.49 ++ (void)setupTrustWordsDB;
   11.50 ++ (void)setupTrustWordsDB:(NSBundle *)rootBundle;
   11.51 +
   11.52 +/**
   11.53 + Start Sync.
   11.54 + - Note: There is only one Sync session and thread
   11.55 + */
   11.56 ++ (void)startSync:(id <PEPSyncDelegate>)delegate;
   11.57 +
   11.58 +/**
   11.59 + Stop Sync.
   11.60 + */
   11.61 ++ (void)stopSync;
   11.62 +
   11.63 +
   11.64 +@end
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/pEpObjCAdapter/PEPObjCAdapter.m	Wed May 17 09:27:57 2017 +0200
    12.3 @@ -0,0 +1,420 @@
    12.4 +//
    12.5 +//  pEpiOSAdapter.m
    12.6 +//  pEpiOSAdapter
    12.7 +//
    12.8 +//  Created by Volker Birk on 28.04.15.
    12.9 +//  Copyright (c) 2015 p≡p. All rights reserved.
   12.10 +//
   12.11 +
   12.12 +@import Foundation;
   12.13 +
   12.14 +#import "PEPObjCAdapter.h"
   12.15 +#import "PEPObjCAdapter+Internal.h"
   12.16 +#import "PEPMessage.h"
   12.17 +#include "keymanagement.h"
   12.18 +
   12.19 +///////////////////////////////////////////////////////////////////////////////
   12.20 +//  Keyserver and Identity lookup - C part
   12.21 +
   12.22 +
   12.23 +int examine_identity(pEp_identity *ident, void *management)
   12.24 +{
   12.25 +    //PEPQueue *q = (__bridge PEPQueue *)management;
   12.26 +    PEPQueue *q = [PEPObjCAdapter getLookupQueue];
   12.27 +    
   12.28 +    NSDictionary *identity = PEP_identityDictFromStruct(ident);
   12.29 +    
   12.30 +    [q enqueue:identity];
   12.31 +    return 0;
   12.32 +}
   12.33 +
   12.34 +static pEp_identity *retrieve_next_identity(void *management)
   12.35 +{
   12.36 +    //PEPQueue *q = (__bridge PEPQueue *)management;
   12.37 +    PEPQueue *q = [PEPObjCAdapter getLookupQueue];
   12.38 +    
   12.39 +    // Dequeue is a blocking operation
   12.40 +    // that returns nil when queue is killed
   12.41 +    NSDictionary *ident = [q dequeue];
   12.42 +    
   12.43 +    if (ident)
   12.44 +        return PEP_identityDictToStruct(ident);
   12.45 +    else
   12.46 +        return NULL;
   12.47 +}
   12.48 +
   12.49 +///////////////////////////////////////////////////////////////////////////////
   12.50 +// Sync - C part
   12.51 +
   12.52 +// Called by sync thread only
   12.53 +PEP_STATUS notify_handshake(void *unused_object, pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal)
   12.54 +{
   12.55 +    id <PEPSyncDelegate> syncDelegate = [PEPObjCAdapter getSyncDelegate];
   12.56 +    if ( syncDelegate )
   12.57 +        return [syncDelegate
   12.58 +                notifyHandshakeWithSignal:signal
   12.59 +                me:PEP_identityDictFromStruct(me)
   12.60 +                partner:PEP_identityDictFromStruct(partner)];
   12.61 +    else
   12.62 +        return PEP_SYNC_NO_NOTIFY_CALLBACK;
   12.63 +}
   12.64 +
   12.65 +// Called by sync thread only
   12.66 +PEP_STATUS message_to_send(void *unused_object, message *msg)
   12.67 +{
   12.68 +    id <PEPSyncDelegate> syncDelegate = [PEPObjCAdapter getSyncDelegate];
   12.69 +    if ( syncDelegate )
   12.70 +        return [syncDelegate sendMessage:PEP_messageDictFromStruct(msg)];
   12.71 +    else
   12.72 +        return PEP_SEND_FUNCTION_NOT_REGISTERED;
   12.73 +}
   12.74 +
   12.75 +// called indirectly by decrypt message - any thread/session
   12.76 +int inject_sync_msg(void *msg, void *unused_management)
   12.77 +{
   12.78 +    PEPQueue *q = [PEPObjCAdapter getSyncQueue];
   12.79 +    
   12.80 +    [q enqueue:[NSValue valueWithPointer:msg]];
   12.81 +    
   12.82 +    return 0;
   12.83 +}
   12.84 +
   12.85 +// Called by sync thread only
   12.86 +void *retrieve_next_sync_msg(void *unused_mamagement, time_t *timeout)
   12.87 +{
   12.88 +    PEPQueue *q = [PEPObjCAdapter getSyncQueue];
   12.89 +    
   12.90 +    return (void*)[[q dequeue] pointerValue];
   12.91 +}
   12.92 +
   12.93 +
   12.94 +///////////////////////////////////////////////////////////////////////////////
   12.95 +// DB and paths
   12.96 +
   12.97 +const char* _Nullable SystemDB = NULL;
   12.98 +NSURL *s_homeURL;
   12.99 +
  12.100 +@implementation PEPObjCAdapter
  12.101 +
  12.102 ++ (void)initialize
  12.103 +{
  12.104 +    s_homeURL = [self createApplicationDirectory];
  12.105 +}
  12.106 +
  12.107 ++ (NSURL *)homeURL
  12.108 +{
  12.109 +    return s_homeURL;
  12.110 +}
  12.111 +
  12.112 ++ (NSURL *)createApplicationDirectory
  12.113 +{
  12.114 +    NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
  12.115 +    if (!bundleID) {
  12.116 +        // This can happen in unit tests
  12.117 +        bundleID = @"test";
  12.118 +    }
  12.119 +    NSFileManager *fm = [NSFileManager defaultManager];
  12.120 +    NSURL *dirPath = nil;
  12.121 +
  12.122 +    // Find the application support directory in the home directory.
  12.123 +    NSArray *appSupportDir = [fm URLsForDirectory:NSApplicationSupportDirectory
  12.124 +                                        inDomains:NSUserDomainMask];
  12.125 +    if ([appSupportDir count] > 0)
  12.126 +    {
  12.127 +        // Append the bundle ID to the URL for the
  12.128 +        // Application Support directory.
  12.129 +        // Mainly needed for OS X, but doesn't do any harm on iOS
  12.130 +        dirPath = [[appSupportDir objectAtIndex:0] URLByAppendingPathComponent:bundleID];
  12.131 +
  12.132 +        // If the directory does not exist, this method creates it.
  12.133 +        // This method is only available in OS X v10.7 and iOS 5.0 or later.
  12.134 +        NSError *theError = nil;
  12.135 +        if (![fm createDirectoryAtURL:dirPath withIntermediateDirectories:YES
  12.136 +                           attributes:nil error:&theError])
  12.137 +        {
  12.138 +            // Handle the error.
  12.139 +            return nil;
  12.140 +        }
  12.141 +    }
  12.142 +
  12.143 +    return dirPath;
  12.144 +}
  12.145 +
  12.146 ++ (NSURL *)createAndSetHomeDirectory
  12.147 +{
  12.148 +    // create and set home directory
  12.149 +    setenv("HOME", [[s_homeURL path] cStringUsingEncoding:NSUTF8StringEncoding], 1);
  12.150 +
  12.151 +    // create and set temp directory
  12.152 +    NSURL *tmpDirUrl = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
  12.153 +    setenv("TEMP", [[tmpDirUrl path] cStringUsingEncoding:NSUTF8StringEncoding], 1);
  12.154 +
  12.155 +    return s_homeURL;
  12.156 +}
  12.157 +
  12.158 ++ (NSString *) getBundlePathFor: (NSString *) filename
  12.159 +{
  12.160 +    return nil;
  12.161 +}
  12.162 +
  12.163 ++ (NSString *) copyAssetIntoDocumentsDirectory:(NSBundle *)rootBundle
  12.164 +                                                          :(NSString *)bundleName
  12.165 +                                                          :(NSString *)fileName{
  12.166 +
  12.167 +    NSURL *homeUrl = [PEPObjCAdapter createAndSetHomeDirectory];
  12.168 +    NSString *documentsDirectory = [homeUrl path];
  12.169 +    
  12.170 +    if(!(documentsDirectory && bundleName && fileName))
  12.171 +        return nil;
  12.172 +    
  12.173 +    // Check if the database file exists in the documents directory.
  12.174 +    NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:fileName];
  12.175 +    if (![[NSFileManager defaultManager] fileExistsAtPath:destinationPath]) {
  12.176 +        // The file does not exist in the documents directory, so copy it from bundle now.
  12.177 +        NSBundle *bundleObj = [NSBundle bundleWithPath:
  12.178 +                               [[rootBundle resourcePath]
  12.179 +                                stringByAppendingPathComponent: bundleName]];
  12.180 +        
  12.181 +        if (!bundleObj)
  12.182 +            return nil;
  12.183 +        
  12.184 +        NSString *sourcePath =[[bundleObj resourcePath] stringByAppendingPathComponent: fileName];
  12.185 +        
  12.186 +        NSError *error;
  12.187 +        [[NSFileManager defaultManager]
  12.188 +         copyItemAtPath:sourcePath toPath:destinationPath error:&error];
  12.189 +        
  12.190 +        // Check if any error occurred during copying and display it.
  12.191 +        if (error != nil) {
  12.192 +            NSLog(@"%@", [error localizedDescription]);
  12.193 +            return nil;
  12.194 +        }
  12.195 +    }
  12.196 +    NSLog(@"Asset %@ copied into %@", fileName, destinationPath);
  12.197 +    return destinationPath;
  12.198 +}
  12.199 +
  12.200 ++ (void)setupTrustWordsDB:(NSBundle *)rootBundle{
  12.201 +    NSString *systemDBPath = [PEPObjCAdapter copyAssetIntoDocumentsDirectory:rootBundle
  12.202 +                                                                           :@"pEpTrustWords.bundle"
  12.203 +                                                                           :@"system.db"];
  12.204 +    if (SystemDB) {
  12.205 +        free((void *) SystemDB);
  12.206 +    }
  12.207 +    SystemDB = strdup(systemDBPath.UTF8String);
  12.208 +}
  12.209 +
  12.210 ++ (void)setupTrustWordsDB
  12.211 +{
  12.212 +    [PEPObjCAdapter setupTrustWordsDB:[NSBundle mainBundle]];
  12.213 +}
  12.214 +
  12.215 +static NSMutableArray* boundSessions = nil;
  12.216 +
  12.217 ++ (NSMutableArray*)boundSessions
  12.218 +{
  12.219 +    static dispatch_once_t once;
  12.220 +    dispatch_once(&once, ^{
  12.221 +        boundSessions =  [[NSMutableArray alloc] init];
  12.222 +    });
  12.223 +    return boundSessions;
  12.224 +}
  12.225 +
  12.226 +///////////////////////////////////////////////////////////////////////////////
  12.227 +//  Keyserver and Identity lookup - ObjC part
  12.228 +
  12.229 +static PEPQueue *lookupQueue = nil;
  12.230 +static NSThread *lookupThread = nil;
  12.231 +static NSConditionLock *lookupThreadJoinCond = nil;
  12.232 +
  12.233 ++ (void)lookupThreadRoutine:(id)object
  12.234 +{
  12.235 +    [lookupThreadJoinCond lock];
  12.236 +
  12.237 +    // FIXME: do_KeyManagement asserts if management is null.
  12.238 +    do_keymanagement(retrieve_next_identity, "NOTNULL" /* (__bridge void *)queue */);
  12.239 +    
  12.240 +    // Set and signal join()
  12.241 +    [lookupThreadJoinCond unlockWithCondition:YES];
  12.242 +}
  12.243 +
  12.244 ++ (void)startKeyserverLookup
  12.245 +{
  12.246 +    if (!lookupQueue)
  12.247 +    {
  12.248 +        lookupQueue = [[PEPQueue alloc]init];
  12.249 +        
  12.250 +        // There is no join() call on NSThreads.
  12.251 +        lookupThreadJoinCond = [[NSConditionLock alloc] initWithCondition:NO];
  12.252 +        
  12.253 +        lookupThread = [[NSThread alloc] initWithTarget:self selector:@selector(lookupThreadRoutine:) object:nil];
  12.254 +        [lookupThread start];
  12.255 +    }
  12.256 +}
  12.257 +
  12.258 ++ (void)stopKeyserverLookup
  12.259 +{
  12.260 +    
  12.261 +    if (lookupQueue)
  12.262 +    {
  12.263 +        // Flush queue and kick the consumer
  12.264 +        [lookupQueue kill];
  12.265 +        
  12.266 +        // Thread then bailout. Wait for that.
  12.267 +        [lookupThreadJoinCond lockWhenCondition:YES];
  12.268 +        [lookupThreadJoinCond unlock];
  12.269 +        
  12.270 +        lookupThread = nil;
  12.271 +        lookupQueue = nil;
  12.272 +        lookupThreadJoinCond = nil;
  12.273 +    }
  12.274 +}
  12.275 +
  12.276 ++ (void)registerExamineFunction:(PEP_SESSION)session
  12.277 +{
  12.278 +    register_examine_function(session, examine_identity, NULL /* (__bridge void *)queue */);
  12.279 +}
  12.280 +
  12.281 ++ (PEPQueue*)getLookupQueue
  12.282 +{
  12.283 +    return lookupQueue;
  12.284 +}
  12.285 +
  12.286 +///////////////////////////////////////////////////////////////////////////////
  12.287 +// Sync - ObjC part
  12.288 +
  12.289 +static PEPQueue *syncQueue = nil;
  12.290 +static NSThread *syncThread = nil;
  12.291 +static NSConditionLock *syncThreadJoinCond = nil;
  12.292 +static PEP_SESSION sync_session = NULL;
  12.293 +static id <PEPSyncDelegate> syncDelegate = nil;
  12.294 +
  12.295 +
  12.296 ++ (void)syncThreadRoutine:(id)object
  12.297 +{
  12.298 +    [syncThreadJoinCond lock];
  12.299 +    
  12.300 +    PEP_STATUS status = init(&sync_session);
  12.301 +    if (status != PEP_STATUS_OK) {
  12.302 +        return;
  12.303 +    }
  12.304 +    
  12.305 +    register_sync_callbacks(sync_session,
  12.306 +                             /* "management" : queuing (unused) */
  12.307 +                            "NOTNULL",
  12.308 +                            message_to_send,
  12.309 +                            notify_handshake,
  12.310 +                            inject_sync_msg,
  12.311 +                            retrieve_next_sync_msg);
  12.312 +
  12.313 +    status = do_sync_protocol(sync_session,
  12.314 +                              /* "object" : notifying, sending (unused) */
  12.315 +                              "NOTNULL");
  12.316 +    
  12.317 +    // TODO : detach all attached sessions
  12.318 +    
  12.319 +    release(sync_session);
  12.320 +    
  12.321 +    [syncThreadJoinCond unlockWithCondition:YES];
  12.322 +}
  12.323 +
  12.324 ++ (void)attachSyncSession:(PEP_SESSION)session
  12.325 +{
  12.326 +    if(sync_session)
  12.327 +        attach_sync_session(session, sync_session);
  12.328 +}
  12.329 +
  12.330 ++ (void)detachSyncSession:(PEP_SESSION)session
  12.331 +{
  12.332 +    detach_sync_session(session);
  12.333 +}
  12.334 +
  12.335 ++ (void)startSync:(id <PEPSyncDelegate>)delegate;
  12.336 +{
  12.337 +    syncDelegate = delegate;
  12.338 +    
  12.339 +    if (!syncQueue)
  12.340 +    {
  12.341 +        syncQueue = [[PEPQueue alloc]init];
  12.342 +        
  12.343 +        syncThreadJoinCond = [[NSConditionLock alloc] initWithCondition:NO];
  12.344 +        
  12.345 +        syncThread = [[NSThread alloc]
  12.346 +                      initWithTarget:self
  12.347 +                      selector:@selector(syncThreadRoutine:)
  12.348 +                      object:nil];
  12.349 +
  12.350 +        [syncThread start];
  12.351 +    }
  12.352 +
  12.353 +    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
  12.354 +    PEPSession* session;
  12.355 +    @synchronized (sessionList) {
  12.356 +        for (session in sessionList) {
  12.357 +            [PEPObjCAdapter attachSyncSession:[session session]];
  12.358 +        }
  12.359 +    }
  12.360 +}
  12.361 +
  12.362 ++ (void)stopSync
  12.363 +{
  12.364 +    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
  12.365 +    PEPSession* session;
  12.366 +    @synchronized (sessionList) {
  12.367 +        for (session in sessionList) {
  12.368 +            [PEPObjCAdapter detachSyncSession:[session session]];
  12.369 +        }
  12.370 +    }
  12.371 +    
  12.372 +    syncDelegate = nil;
  12.373 +    
  12.374 +    if (syncQueue)
  12.375 +    {
  12.376 +        // FIXME : memory leak ! unallocate sync message waiting in the queue
  12.377 +        
  12.378 +        [syncQueue kill];
  12.379 +        
  12.380 +        [syncThreadJoinCond lockWhenCondition:YES];
  12.381 +        [syncThreadJoinCond unlock];
  12.382 +        
  12.383 +        syncThread = nil;
  12.384 +        syncQueue = nil;
  12.385 +        syncThreadJoinCond = nil;
  12.386 +    }
  12.387 +}
  12.388 +
  12.389 ++ (PEPQueue*)getSyncQueue
  12.390 +{
  12.391 +    return syncQueue;
  12.392 +}
  12.393 +
  12.394 ++ (id <PEPSyncDelegate>)getSyncDelegate
  12.395 +{
  12.396 +    return syncDelegate;
  12.397 +}
  12.398 +
  12.399 ++ (void)bindSession:(PEPSession*)session
  12.400 +{
  12.401 +    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
  12.402 +    @synchronized (sessionList) {
  12.403 +        [sessionList addObject:session];
  12.404 +    }
  12.405 +
  12.406 +    [PEPObjCAdapter registerExamineFunction:[session session]];
  12.407 +    [PEPObjCAdapter attachSyncSession:[session session]];
  12.408 +}
  12.409 +
  12.410 ++ (void)unbindSession:(PEPSession*)session
  12.411 +{
  12.412 +    [PEPObjCAdapter detachSyncSession:[session session]];
  12.413 +    
  12.414 +    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
  12.415 +    @synchronized (sessionList) {
  12.416 +        [sessionList removeObject:session];
  12.417 +    }
  12.418 +
  12.419 +}
  12.420 +
  12.421 +
  12.422 +
  12.423 +@end
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/pEpObjCAdapter/PEPQueue.h	Wed May 17 09:27:57 2017 +0200
    13.3 @@ -0,0 +1,21 @@
    13.4 +//
    13.5 +//  PEPQueue.h
    13.6 +//  pEpiOSAdapter
    13.7 +//
    13.8 +//  Created by Volker Birk on 15.07.15.
    13.9 +//  Copyright (c) 2015 p≡p. All rights reserved.
   13.10 +//
   13.11 +
   13.12 +#import <Foundation/Foundation.h>
   13.13 +
   13.14 +@interface PEPQueue : NSObject
   13.15 +
   13.16 +- (void)enqueue:(id)object;
   13.17 +
   13.18 +- (id)dequeue;
   13.19 +
   13.20 +- (void)kill;
   13.21 +
   13.22 +- (NSUInteger)count;
   13.23 +
   13.24 +@end
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/pEpObjCAdapter/PEPQueue.m	Wed May 17 09:27:57 2017 +0200
    14.3 @@ -0,0 +1,97 @@
    14.4 +//
    14.5 +//  PEPQueue.m
    14.6 +//  pEpiOSAdapter
    14.7 +//
    14.8 +//  Created by Volker Birk on 15.07.15.
    14.9 +//  Copyright (c) 2015 p≡p. All rights reserved.
   14.10 +//
   14.11 +
   14.12 +#import "PEPQueue.h"
   14.13 +
   14.14 +
   14.15 +@interface PEPQueue ()
   14.16 +
   14.17 +@property (nonatomic, strong) NSMutableArray *queue;
   14.18 +@property (nonatomic, strong) NSCondition *cond;
   14.19 +
   14.20 +@end
   14.21 +
   14.22 +@implementation PEPQueue
   14.23 +
   14.24 +- (id)init
   14.25 +{
   14.26 +    self = [super init];
   14.27 +    
   14.28 +    if (self)
   14.29 +    {
   14.30 +        self.queue = [[NSMutableArray alloc] init];
   14.31 +        self.cond = [[NSCondition alloc] init];
   14.32 +    }
   14.33 +    
   14.34 +    return self;
   14.35 +}
   14.36 +
   14.37 +- (void)enqueue:(id)object
   14.38 +{
   14.39 +
   14.40 +    @synchronized(self) {
   14.41 +        if (_queue)
   14.42 +            [_queue insertObject:object atIndex:0];
   14.43 +    }
   14.44 +    
   14.45 +    [_cond signal];
   14.46 +    
   14.47 +}
   14.48 +
   14.49 +- (BOOL)condwait
   14.50 +{
   14.51 +    BOOL res;
   14.52 +    @synchronized(self) {
   14.53 +        res = _queue && _queue.count == 0;
   14.54 +    }
   14.55 +    return res;
   14.56 +}
   14.57 +
   14.58 +- (id)dequeue
   14.59 +{
   14.60 +    id tmp = nil;
   14.61 +    
   14.62 +    [_cond lock];
   14.63 +    
   14.64 +    while ([self condwait])
   14.65 +    {
   14.66 +        [_cond wait];
   14.67 +    }
   14.68 +    
   14.69 +    @synchronized(self) {
   14.70 +        if (_queue)
   14.71 +        {
   14.72 +            tmp = [_queue lastObject];
   14.73 +            
   14.74 +            [_queue removeLastObject];
   14.75 +        }
   14.76 +    }
   14.77 +    [_cond unlock];
   14.78 +    
   14.79 +    return tmp;
   14.80 +}
   14.81 +
   14.82 +- (void)kill
   14.83 +{
   14.84 +    _queue = nil;
   14.85 +    
   14.86 +    [_cond signal];
   14.87 +}
   14.88 +
   14.89 +- (NSUInteger)count
   14.90 +{
   14.91 +    return [_queue count];
   14.92 +}
   14.93 +
   14.94 +- (void)dealloc
   14.95 +{
   14.96 +    self.queue = nil;
   14.97 +    self.cond = nil;
   14.98 +}
   14.99 +
  14.100 +@end
  14.101 \ No newline at end of file
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/pEpObjCAdapter/PEPSession+Internal.h	Wed May 17 09:27:57 2017 +0200
    15.3 @@ -0,0 +1,18 @@
    15.4 +//
    15.5 +//  PEPSession+Internal.h
    15.6 +//  pEpiOSAdapter
    15.7 +//
    15.8 +//  Created by Edouard Tisserant on 16.05.17.
    15.9 +//  Copyright © 2017 p≡p. All rights reserved.
   15.10 +//
   15.11 +
   15.12 +#ifndef PEPSession_internal_h
   15.13 +#define PEPSession_internal_h
   15.14 +
   15.15 +@interface PEPSession ()
   15.16 +
   15.17 +@property (nonatomic) PEP_SESSION session;
   15.18 +
   15.19 +@end
   15.20 +
   15.21 +#endif /* PEPSession_internal_h */
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/pEpObjCAdapter/PEPSession.h	Wed May 17 09:27:57 2017 +0200
    16.3 @@ -0,0 +1,137 @@
    16.4 +//
    16.5 +//  PEPSession.h
    16.6 +//  pEpiOSAdapter
    16.7 +//
    16.8 +//  Created by Volker Birk on 08.07.15.
    16.9 +//  Copyright (c) 2015 p≡p. All rights reserved.
   16.10 +//
   16.11 +
   16.12 +#import <Foundation/Foundation.h>
   16.13 +
   16.14 +#import "PEPObjCAdapter.h"
   16.15 +#import "PEPMessage.h"
   16.16 +
   16.17 +@class PEPSession;
   16.18 +@class PEPLanguage;
   16.19 +
   16.20 +/** Callback type for doing something with a session */
   16.21 +typedef void (^PEPSessionBlock)(PEPSession * _Nonnull session);
   16.22 +
   16.23 +@interface PEPSession : NSObject
   16.24 +
   16.25 +#pragma mark -- Public API
   16.26 +
   16.27 ++ (nonnull PEPSession *)session;
   16.28 +
   16.29 +/**
   16.30 + Execute a block concurrently on a session.
   16.31 + The session is created solely for execution of the block.
   16.32 + */
   16.33 ++ (void)dispatchAsyncOnSession:(nonnull PEPSessionBlock)block;
   16.34 +
   16.35 +/**
   16.36 + Execute a block on a session and wait for it.
   16.37 + The session is created solely for execution of the block.
   16.38 + */
   16.39 ++ (void)dispatchSyncOnSession:(nonnull PEPSessionBlock)block;
   16.40 +
   16.41 +/** Decrypt a message */
   16.42 +- (PEP_rating)decryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
   16.43 +                            dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst
   16.44 +                            keys:(NSArray<NSString *> * _Nullable * _Nullable)keys;
   16.45 +
   16.46 +/** Encrypt a message */
   16.47 +- (PEP_STATUS)encryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
   16.48 +                           extra:(nullable NSArray<NSString *> *)keys
   16.49 +                            dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst;
   16.50 +
   16.51 +/** Encrypt a message for the given identity, which is usually a mySelf identity */
   16.52 +- (PEP_STATUS)encryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
   16.53 +                        identity:(nonnull NSDictionary<NSString *, id> *)identity
   16.54 +                            dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst;
   16.55 +
   16.56 +/** Determine the status color of a message to be sent */
   16.57 +- (PEP_rating)outgoingMessageColor:(nonnull NSDictionary<NSString *, id> *)msg;
   16.58 +
   16.59 +/** Determine the rating of an identity */
   16.60 +- (PEP_rating)identityRating:(nonnull NSDictionary<NSString *, id> *)identity;
   16.61 +
   16.62 +/** Get trustwords for a fingerprint */
   16.63 +- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
   16.64 +                      shortened:(BOOL)shortened;
   16.65 +
   16.66 +/**
   16.67 + Supply an account used by our user himself. The identity is supplemented with the missing parts
   16.68 +
   16.69 + An identity is a `NSDictionary` mapping a field name as `NSString` to different values.
   16.70 + An identity can have the following fields (all other keys are ignored).
   16.71 + It is not necessary to supply all fields; missing fields are supplemented by p≡p engine.
   16.72 + 
   16.73 + @"username": real name or nick name (if pseudonymous) of identity
   16.74 + @"address": URI or SMTP address
   16.75 + @"user_id": persistent unique ID for identity
   16.76 + @"lang": preferred languageID for communication with this ID (default: @"en")
   16.77 + @"fpr": fingerprint of key to use for communication with this ID
   16.78 + @"comm_type": communication type code (usually not needed)
   16.79 + @"me": YES if this is an identity of our user, NO if it is one of a communication partner (default: NO)
   16.80 + 
   16.81 + As an example:
   16.82 + 
   16.83 + User has a mailbox. The mail address is "Dipul Khatri <dipul@inboxcube.com>". Then this would be:
   16.84 + 
   16.85 + NSDictionary *ident = [NSDictionary dictionaryWithObjectsAndKeys:
   16.86 + @"Dipul Khatri", @"username", @"dipul@inboxcube.com", @"address", 
   16.87 + @"23", @"user_id", nil];
   16.88 + 
   16.89 +*/
   16.90 +- (void)mySelf:(nonnull NSMutableDictionary<NSString *, id> *)identity;
   16.91 +
   16.92 +/**
   16.93 + Supplement missing information for an arbitrary identity (used for communication partners).
   16.94 + See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
   16.95 + */
   16.96 +- (void)updateIdentity:(nonnull NSMutableDictionary<NSString *, id> *)identity;
   16.97 +
   16.98 +/**
   16.99 + Mark a key as trusted with a person.
  16.100 + See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
  16.101 + */
  16.102 +- (void)trustPersonalKey:(nonnull NSMutableDictionary<NSString *, id> *)identity;
  16.103 +
  16.104 +/**
  16.105 + if a key is not trusted by the user tell this using this message
  16.106 + See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
  16.107 + */
  16.108 +- (void)keyMistrusted:(nonnull NSMutableDictionary<NSString *, id> *)identity;
  16.109 +
  16.110 +/**
  16.111 + Use this to undo keyCompromized or trustPersonalKey
  16.112 + See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
  16.113 +*/
  16.114 +- (void)keyResetTrust:(nonnull NSMutableDictionary<NSString *, id> *)identity;
  16.115 +
  16.116 +#pragma mark -- Internal API (testing etc.)
  16.117 +
  16.118 +/** For testing purpose, manual key import */
  16.119 +- (void)importKey:(nonnull NSString *)keydata;
  16.120 +
  16.121 +- (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
  16.122 +     description:(nullable NSString *)description comment:(nullable NSString *)comment;
  16.123 +
  16.124 +/**
  16.125 + Retrieves the log from the engine.
  16.126 + */
  16.127 +- (nonnull NSString *)getLog;
  16.128 +
  16.129 +/** Determine trustwords for two identities */
  16.130 +- (nullable NSString *)getTrustwordsIdentity1:(nonnull NSDictionary<NSString *, id> *)identity1
  16.131 +                                    identity2:(nonnull NSDictionary<NSString *, id> *)identity2
  16.132 +                                     language:(nullable NSString *)language
  16.133 +                                         full:(BOOL)full;
  16.134 +
  16.135 +/**
  16.136 + @returns The list of supported languages for trustwords.
  16.137 + */
  16.138 +- (NSArray<PEPLanguage *> * _Nonnull)languageList;
  16.139 +
  16.140 +@end
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/pEpObjCAdapter/PEPSession.m	Wed May 17 09:27:57 2017 +0200
    17.3 @@ -0,0 +1,417 @@
    17.4 +//
    17.5 +//  PEPSession.m
    17.6 +//  pEpiOSAdapter
    17.7 +//
    17.8 +//  Created by Volker Birk on 08.07.15.
    17.9 +//  Copyright (c) 2015 p≡p. All rights reserved.
   17.10 +//
   17.11 +
   17.12 +#import "PEPSession.h"
   17.13 +#import "PEPSession+Internal.h"
   17.14 +#import "PEPObjCAdapter.h"
   17.15 +#import "PEPObjCAdapter+Internal.h"
   17.16 +#import "PEPMessage.h"
   17.17 +#import "PEPLanguage.h"
   17.18 +#import "PEPCSVScanner.h"
   17.19 +#import "NSArray+Extension.h"
   17.20 +
   17.21 +@implementation PEPSession
   17.22 +
   17.23 +// serialize all session access
   17.24 ++ (dispatch_queue_t)sharedSessionQueue
   17.25 +{
   17.26 +    static dispatch_once_t once;
   17.27 +    static dispatch_queue_t sharedSessionQueue;
   17.28 +    dispatch_once(&once, ^{
   17.29 +        sharedSessionQueue = dispatch_queue_create("pEp session queue", DISPATCH_QUEUE_CONCURRENT);
   17.30 +    });
   17.31 +    return sharedSessionQueue;
   17.32 +}
   17.33 +
   17.34 ++ (PEPSession *)session
   17.35 +{
   17.36 +    PEPSession *_session = [[PEPSession alloc] init];
   17.37 +    return _session;
   17.38 +}
   17.39 +
   17.40 ++ (void)dispatchAsyncOnSession:(PEPSessionBlock)block
   17.41 +{
   17.42 +    dispatch_async([self sharedSessionQueue], ^{
   17.43 +        PEPSession *pepSession = [[PEPSession alloc] init];
   17.44 +        block(pepSession);
   17.45 +    });
   17.46 +}
   17.47 +
   17.48 ++ (void)dispatchSyncOnSession:(PEPSessionBlock)block
   17.49 +{
   17.50 +    PEPSession *pepSession = [[PEPSession alloc] init];
   17.51 +    block(pepSession);
   17.52 +}
   17.53 +
   17.54 ++ (void)setupTrustWordsDB
   17.55 +{
   17.56 +    static dispatch_once_t once;
   17.57 +    dispatch_once(&once, ^{
   17.58 +        [PEPObjCAdapter setupTrustWordsDB:[NSBundle bundleForClass:[self class]]];
   17.59 +    });
   17.60 +}
   17.61 +
   17.62 +- (id)init
   17.63 +{
   17.64 +    [PEPSession setupTrustWordsDB];
   17.65 +
   17.66 +    PEP_STATUS status = init(&_session);
   17.67 +
   17.68 +    if (status != PEP_STATUS_OK) {
   17.69 +        return nil;
   17.70 +    }
   17.71 +
   17.72 +    [PEPObjCAdapter bindSession:self];
   17.73 +    
   17.74 +    return self;
   17.75 +}
   17.76 +
   17.77 +- (void)dealloc
   17.78 +{
   17.79 +    [PEPObjCAdapter unbindSession:self];
   17.80 +    
   17.81 +    release(_session);
   17.82 +}
   17.83 +
   17.84 +- (PEP_rating)decryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
   17.85 +                            dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst
   17.86 +                            keys:(NSArray<NSString *> * _Nullable * _Nullable)keys
   17.87 +{
   17.88 +    message * _src = PEP_messageDictToStruct(src);
   17.89 +    message * _dst = NULL;
   17.90 +    stringlist_t * _keys = NULL;
   17.91 +    PEP_rating color = PEP_rating_undefined;
   17.92 +    PEP_decrypt_flags_t flags = 0;
   17.93 +
   17.94 +    @synchronized (self) {
   17.95 +        decrypt_message(_session, _src, &_dst, &_keys, &color, &flags);
   17.96 +    }
   17.97 +
   17.98 +    NSDictionary * dst_;
   17.99 +
  17.100 +    if (_dst) {
  17.101 +        dst_ = PEP_messageDictFromStruct(_dst);
  17.102 +    }
  17.103 +    else {
  17.104 +        dst_ = PEP_messageDictFromStruct(_src);
  17.105 +    }
  17.106 +
  17.107 +    NSArray * keys_ = nil;
  17.108 +    if (_keys)
  17.109 +        keys_ = PEP_arrayFromStringlist(_keys);
  17.110 +
  17.111 +    free_message(_src);
  17.112 +    free_message(_dst);
  17.113 +    free_stringlist(_keys);
  17.114 +
  17.115 +    if (dst) {
  17.116 +        *dst = dst_;
  17.117 +    }
  17.118 +    if (keys) {
  17.119 +        *keys = keys_;
  17.120 +    }
  17.121 +    return color;
  17.122 +}
  17.123 +
  17.124 +- (void)removeEmptyArrayKey:(NSString *)key inDict:(NSMutableDictionary<NSString *, id> *)dict
  17.125 +{
  17.126 +    if ([[dict objectForKey:key] count] == 0) {
  17.127 +        [dict removeObjectForKey:key];
  17.128 +    }
  17.129 +}
  17.130 +
  17.131 +- (NSDictionary *)removeEmptyRecipients:(NSDictionary<NSString *, id> *)src
  17.132 +{
  17.133 +    NSMutableDictionary *dest = src.mutableCopy;
  17.134 +
  17.135 +    [self removeEmptyArrayKey:kPepTo inDict:dest];
  17.136 +    [self removeEmptyArrayKey:kPepCC inDict:dest];
  17.137 +    [self removeEmptyArrayKey:kPepBCC inDict:dest];
  17.138 +
  17.139 +    return [NSDictionary dictionaryWithDictionary:dest];
  17.140 +}
  17.141 +
  17.142 +- (PEP_STATUS)encryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
  17.143 +                           extra:(nullable NSArray *)keys
  17.144 +                            dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst
  17.145 +{
  17.146 +    PEP_STATUS status;
  17.147 +    PEP_encrypt_flags_t flags = 0;
  17.148 +
  17.149 +    message * _src = PEP_messageDictToStruct([self removeEmptyRecipients:src]);
  17.150 +    message * _dst = NULL;
  17.151 +    stringlist_t * _keys = PEP_arrayToStringlist(keys);
  17.152 +
  17.153 +    @synchronized (self) {
  17.154 +        status = encrypt_message(_session, _src, _keys, &_dst, PEP_enc_PGP_MIME, flags);
  17.155 +    }
  17.156 +
  17.157 +    NSDictionary * dst_;
  17.158 +
  17.159 +    if (_dst) {
  17.160 +        dst_ = PEP_messageDictFromStruct(_dst);
  17.161 +    }
  17.162 +    else {
  17.163 +        dst_ = PEP_messageDictFromStruct(_src);
  17.164 +    }
  17.165 +    if (dst) {
  17.166 +        *dst = dst_;
  17.167 +    }
  17.168 +
  17.169 +    free_message(_src);
  17.170 +    free_message(_dst);
  17.171 +    free_stringlist(_keys);
  17.172 +    
  17.173 +    return status;
  17.174 +}
  17.175 +
  17.176 +- (PEP_STATUS)encryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
  17.177 +                        identity:(nonnull NSDictionary<NSString *, id> *)identity
  17.178 +                            dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst
  17.179 +{
  17.180 +    PEP_STATUS status;
  17.181 +    PEP_encrypt_flags_t flags = 0;
  17.182 +
  17.183 +    message * _src = PEP_messageDictToStruct([self removeEmptyRecipients:src]);
  17.184 +    pEp_identity *ident = PEP_identityDictToStruct(identity);
  17.185 +    message * _dst = NULL;
  17.186 +
  17.187 +    @synchronized (self) {
  17.188 +        status = encrypt_message_for_self(_session, ident, _src, &_dst, PEP_enc_PGP_MIME, flags);
  17.189 +    }
  17.190 +
  17.191 +    NSDictionary * dst_;
  17.192 +
  17.193 +    if (_dst) {
  17.194 +        dst_ = PEP_messageDictFromStruct(_dst);
  17.195 +    }
  17.196 +    else {
  17.197 +        dst_ = PEP_messageDictFromStruct(_src);
  17.198 +    }
  17.199 +
  17.200 +    if (dst) {
  17.201 +        *dst = dst_;
  17.202 +    }
  17.203 +
  17.204 +    free_message(_src);
  17.205 +    free_message(_dst);
  17.206 +    free_identity(ident);
  17.207 +
  17.208 +    return status;
  17.209 +}
  17.210 +
  17.211 +- (PEP_rating)outgoingMessageColor:(NSDictionary<NSString *, id> *)msg
  17.212 +{
  17.213 +    message * _msg = PEP_messageDictToStruct(msg);
  17.214 +    PEP_rating color = PEP_rating_undefined;
  17.215 +
  17.216 +    @synchronized (self) {
  17.217 +        outgoing_message_rating(_session, _msg, &color);
  17.218 +    }
  17.219 +
  17.220 +    free_message(_msg);
  17.221 +    
  17.222 +    return color;
  17.223 +}
  17.224 +
  17.225 +- (PEP_rating)identityRating:(nonnull NSDictionary<NSString *, id> *)identity
  17.226 +{
  17.227 +    pEp_identity *ident = PEP_identityDictToStruct(identity);
  17.228 +    PEP_rating color = PEP_rating_undefined;
  17.229 +    
  17.230 +    @synchronized (self) {
  17.231 +        identity_rating(_session, ident, &color);
  17.232 +    }
  17.233 +    
  17.234 +    free_identity(ident);
  17.235 +    
  17.236 +    return color;
  17.237 +}
  17.238 +
  17.239 +DYNAMIC_API PEP_STATUS identity_rating(
  17.240 +                                      PEP_SESSION session,
  17.241 +                                      pEp_identity *ident,
  17.242 +                                      PEP_rating *color
  17.243 +                                      );
  17.244 +
  17.245 +
  17.246 +- (NSArray *)trustwords:(NSString *)fpr forLanguage:(NSString *)languageID shortened:(BOOL)shortened
  17.247 +{
  17.248 +    NSMutableArray *array = [NSMutableArray array];
  17.249 +
  17.250 +    for (int i = 0; i < [fpr length]; i += 4) {
  17.251 +        if (shortened && i >= 20)
  17.252 +            break;
  17.253 +        
  17.254 +        NSString *str = [fpr substringWithRange:NSMakeRange(i, 4)];
  17.255 +
  17.256 +        unsigned int value;
  17.257 +        [[NSScanner scannerWithString:str] scanHexInt:&value];
  17.258 +        
  17.259 +        char *word;
  17.260 +        size_t size;
  17.261 +
  17.262 +        @synchronized (self) {
  17.263 +            trustword(_session, value, [languageID UTF8String], &word, &size);
  17.264 +        }
  17.265 +
  17.266 +        [array addObject:[NSString stringWithUTF8String:word]];
  17.267 +        free(word);
  17.268 +    }
  17.269 +    
  17.270 +    return array;
  17.271 +}
  17.272 +
  17.273 +- (void)mySelf:(NSMutableDictionary<NSString *, id> *)identity
  17.274 +{
  17.275 +    [identity removeObjectForKey:kPepUserID];
  17.276 +
  17.277 +    pEp_identity *ident = PEP_identityDictToStruct(identity);
  17.278 +
  17.279 +    @synchronized(self) {
  17.280 +        myself(_session, ident);
  17.281 +    }
  17.282 +
  17.283 +    [identity setValuesForKeysWithDictionary:PEP_identityDictFromStruct(ident)];
  17.284 +    free_identity(ident);
  17.285 +}
  17.286 +
  17.287 +- (void)updateIdentity:(NSMutableDictionary<NSString *, id> *)identity
  17.288 +{
  17.289 +    pEp_identity *ident = PEP_identityDictToStruct(identity);
  17.290 +
  17.291 +    @synchronized(self) {
  17.292 +        update_identity(_session, ident);
  17.293 +    }
  17.294 +
  17.295 +    [identity setValuesForKeysWithDictionary:PEP_identityDictFromStruct(ident)];
  17.296 +    free_identity(ident);
  17.297 +}
  17.298 +
  17.299 +- (void)trustPersonalKey:(NSMutableDictionary<NSString *, id> *)identity
  17.300 +{
  17.301 +    pEp_identity *ident = PEP_identityDictToStruct(identity);
  17.302 +    
  17.303 +    @synchronized(self) {
  17.304 +        trust_personal_key(_session, ident);
  17.305 +    }
  17.306 +    
  17.307 +    [identity setValuesForKeysWithDictionary:PEP_identityDictFromStruct(ident)];
  17.308 +    free_identity(ident);
  17.309 +}
  17.310 +
  17.311 +- (void)keyResetTrust:(NSMutableDictionary<NSString *, id> *)identity
  17.312 +{
  17.313 +    pEp_identity *ident = PEP_identityDictToStruct(identity);
  17.314 +    
  17.315 +    @synchronized(self) {
  17.316 +        key_reset_trust(_session, ident);
  17.317 +    }
  17.318 +    
  17.319 +    [identity setValuesForKeysWithDictionary:PEP_identityDictFromStruct(ident)];
  17.320 +    free_identity(ident);
  17.321 +}
  17.322 +
  17.323 +- (void)keyMistrusted:(NSMutableDictionary<NSString *, id> *)identity
  17.324 +{
  17.325 +    pEp_identity *ident = PEP_identityDictToStruct(identity);
  17.326 +    
  17.327 +    @synchronized(self) {
  17.328 +        key_mistrusted(_session, ident);
  17.329 +    }
  17.330 +    
  17.331 +    [identity setValuesForKeysWithDictionary:PEP_identityDictFromStruct(ident)];
  17.332 +    free_identity(ident);
  17.333 +}
  17.334 +
  17.335 +- (void)importKey:(NSString *)keydata
  17.336 +{
  17.337 +    @synchronized(self) {
  17.338 +        import_key(_session, [keydata UTF8String], [keydata length], NULL);
  17.339 +    }
  17.340 +
  17.341 +}
  17.342 +
  17.343 +- (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
  17.344 +     description:(nullable NSString *)description comment:(nullable NSString *)comment
  17.345 +{
  17.346 +    log_event(self.session, [[title precomposedStringWithCanonicalMapping] UTF8String],
  17.347 +              [[entity precomposedStringWithCanonicalMapping] UTF8String],
  17.348 +              [[description precomposedStringWithCanonicalMapping] UTF8String],
  17.349 +              [[comment precomposedStringWithCanonicalMapping] UTF8String]);
  17.350 +}
  17.351 +
  17.352 +- (nonnull NSString *)getLog
  17.353 +{
  17.354 +    char *data;
  17.355 +    get_crashdump_log(self.session, 0, &data);
  17.356 +    NSString *logString = [NSString stringWithUTF8String:data];
  17.357 +    return logString;
  17.358 +}
  17.359 +
  17.360 +- (nullable NSString *)getTrustwordsIdentity1:(nonnull NSDictionary<NSString *, id> *)identity1
  17.361 +                                    identity2:(nonnull NSDictionary<NSString *, id> *)identity2
  17.362 +                                     language:(nullable NSString *)language
  17.363 +                                         full:(BOOL)full
  17.364 +{
  17.365 +    NSString *result = nil;
  17.366 +    char *trustwords = nil;
  17.367 +    size_t sizeWritten = 0;
  17.368 +
  17.369 +    pEp_identity *ident1 = PEP_identityDictToStruct(identity1);
  17.370 +    pEp_identity *ident2 = PEP_identityDictToStruct(identity2);
  17.371 +    PEP_STATUS status =  get_trustwords(_session, ident1, ident2,
  17.372 +                                        [[language precomposedStringWithCanonicalMapping]
  17.373 +                                         UTF8String],
  17.374 +                                        &trustwords, &sizeWritten, full);
  17.375 +    if (status == PEP_STATUS_OK) {
  17.376 +        result = [NSString stringWithCString:trustwords
  17.377 +                                    encoding:NSUTF8StringEncoding];
  17.378 +    }
  17.379 +    if (trustwords) {
  17.380 +        free(trustwords);
  17.381 +    }
  17.382 +    return result;
  17.383 +}
  17.384 +
  17.385 +- (NSArray<PEPLanguage *> * _Nonnull)languageList
  17.386 +{
  17.387 +    char *chLangs;
  17.388 +    get_languagelist(self.session, &chLangs);
  17.389 +    NSString *parserInput = [NSString stringWithUTF8String:chLangs];
  17.390 +
  17.391 +    NSMutableArray<NSString *> *tokens = [NSMutableArray array];
  17.392 +    PEPCSVScanner *scanner = [[PEPCSVScanner alloc] initWithString:parserInput];
  17.393 +    while (YES) {
  17.394 +        NSString *token = [scanner nextString];
  17.395 +        if (!token) {
  17.396 +            break;
  17.397 +        }
  17.398 +        [tokens addObject:token];
  17.399 +    }
  17.400 +
  17.401 +    NSArray *theTokens = [NSArray arrayWithArray:tokens];
  17.402 +    NSMutableArray<PEPLanguage *> *langs = [NSMutableArray new];
  17.403 +    while (YES) {
  17.404 +        ArrayTake *take = [theTokens takeOrNil:3];
  17.405 +        if (!take) {
  17.406 +            break;
  17.407 +        }
  17.408 +        NSArray *elements = take.elements;
  17.409 +        PEPLanguage *lang = [[PEPLanguage alloc]
  17.410 +                             initWithCode:[elements objectAtIndex:0]
  17.411 +                             name:[elements objectAtIndex:1]
  17.412 +                             sentence:[elements objectAtIndex:2]];
  17.413 +        [langs addObject:lang];
  17.414 +        theTokens = take.rest;
  17.415 +    }
  17.416 +
  17.417 +    return [NSArray arrayWithArray:langs];
  17.418 +}
  17.419 +
  17.420 +@end
    18.1 --- a/pEpiOSAdapter/NSArray+Extension.h	Wed May 17 08:16:57 2017 +0200
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,25 +0,0 @@
    18.4 -//
    18.5 -//  NSArray+Extension.h
    18.6 -//  pEpiOSAdapter
    18.7 -//
    18.8 -//  Created by Dirk Zimmermann on 03.05.17.
    18.9 -//  Copyright © 2017 p≡p. All rights reserved.
   18.10 -//
   18.11 -
   18.12 -#import <Foundation/Foundation.h>
   18.13 -
   18.14 -@interface ArrayTake : NSObject
   18.15 -
   18.16 -@property (nonatomic, readonly) NSArray * _Nonnull elements;
   18.17 -@property (nonatomic, readonly) NSArray * _Nonnull rest;
   18.18 -
   18.19 -@end
   18.20 -
   18.21 -@interface NSArray (Extension)
   18.22 -
   18.23 -/**
   18.24 - @Return The next count elements or nil, if less than that amount available.
   18.25 - */
   18.26 -- (ArrayTake * _Nullable)takeOrNil:(NSInteger)count;
   18.27 -
   18.28 -@end
    19.1 --- a/pEpiOSAdapter/NSArray+Extension.m	Wed May 17 08:16:57 2017 +0200
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,38 +0,0 @@
    19.4 -//
    19.5 -//  NSArray+Extension.m
    19.6 -//  pEpiOSAdapter
    19.7 -//
    19.8 -//  Created by Dirk Zimmermann on 03.05.17.
    19.9 -//  Copyright © 2017 p≡p. All rights reserved.
   19.10 -//
   19.11 -
   19.12 -#import "NSArray+Extension.h"
   19.13 -
   19.14 -@implementation ArrayTake
   19.15 -
   19.16 -- (instancetype)initWithElements:(NSArray * _Nonnull)elements rest:(NSArray * _Nonnull)rest
   19.17 -{
   19.18 -    if (self = [super init]) {
   19.19 -        _elements = elements;
   19.20 -        _rest = rest;
   19.21 -    }
   19.22 -    return self;
   19.23 -}
   19.24 -
   19.25 -@end
   19.26 -
   19.27 -@implementation NSArray (Extension)
   19.28 -
   19.29 -- (ArrayTake * _Nullable)takeOrNil:(NSInteger)count
   19.30 -{
   19.31 -    if (self.count >= count) {
   19.32 -        NSInteger restCount = self.count - count;
   19.33 -        NSArray *elements = [self subarrayWithRange:NSMakeRange(0, count)];
   19.34 -        NSArray *rest = [self subarrayWithRange:NSMakeRange(count, restCount)];
   19.35 -        ArrayTake *taken = [[ArrayTake alloc] initWithElements:elements rest:rest];
   19.36 -        return taken;
   19.37 -    }
   19.38 -    return nil;
   19.39 -}
   19.40 -
   19.41 -@end
    20.1 --- a/pEpiOSAdapter/PEPCSVScanner.h	Wed May 17 08:16:57 2017 +0200
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,18 +0,0 @@
    20.4 -//
    20.5 -//  PEPCSVScanner.h
    20.6 -//  pEpiOSAdapter
    20.7 -//
    20.8 -//  Created by Dirk Zimmermann on 03.05.17.
    20.9 -//  Copyright © 2017 p≡p. All rights reserved.
   20.10 -//
   20.11 -
   20.12 -#import <Foundation/Foundation.h>
   20.13 -
   20.14 -@interface PEPCSVScanner : NSObject
   20.15 -
   20.16 -@property (nonatomic, readonly, nonnull) NSString *string;
   20.17 -
   20.18 -- (instancetype _Nonnull )initWithString:(NSString * _Nonnull)string;
   20.19 -- (NSString * _Nullable)nextString;
   20.20 -
   20.21 -@end
    21.1 --- a/pEpiOSAdapter/PEPCSVScanner.m	Wed May 17 08:16:57 2017 +0200
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,82 +0,0 @@
    21.4 -//
    21.5 -//  PEPCSVScanner.m
    21.6 -//  pEpiOSAdapter
    21.7 -//
    21.8 -//  Created by Dirk Zimmermann on 03.05.17.
    21.9 -//  Copyright © 2017 p≡p. All rights reserved.
   21.10 -//
   21.11 -
   21.12 -#import "PEPCSVScanner.h"
   21.13 -
   21.14 -static unichar s_quoteChar = '"';
   21.15 -
   21.16 -@interface PEPCSVScanner ()
   21.17 -
   21.18 -@property (nonatomic) NSInteger position;
   21.19 -@property (nonatomic) NSInteger len;
   21.20 -
   21.21 -@end;
   21.22 -
   21.23 -@implementation PEPCSVScanner
   21.24 -
   21.25 -- (instancetype _Nonnull )initWithString:(NSString * _Nonnull)string
   21.26 -{
   21.27 -    if (self = [super init]) {
   21.28 -        _string = string;
   21.29 -        _len = [string length];
   21.30 -    }
   21.31 -    return self;
   21.32 -}
   21.33 -
   21.34 -- (NSString * _Nullable)nextString
   21.35 -{
   21.36 -    NSInteger startPos = NSNotFound;
   21.37 -    for (NSInteger thePos = self.position; thePos < self.len; thePos++) {
   21.38 -        if ([self startingQuoteAt:thePos]) {
   21.39 -            startPos = thePos + 1;
   21.40 -            for (NSInteger endPos = startPos; endPos < self.len; endPos++) {
   21.41 -                if ([self endingQuoteAt:endPos]) {
   21.42 -                    self.position = endPos + 1;
   21.43 -                    return [self.string substringWithRange:NSMakeRange(startPos, endPos - startPos)];
   21.44 -                }
   21.45 -            }
   21.46 -        }
   21.47 -    }
   21.48 -    return nil;
   21.49 -}
   21.50 -
   21.51 -/**
   21.52 - @return YES if the given position points to a starting quote.
   21.53 - */
   21.54 -- (BOOL)startingQuoteAt:(NSInteger)pos
   21.55 -{
   21.56 -    // The last char can never be a starting quote
   21.57 -    if (pos >= self.len - 1) {
   21.58 -        return NO;
   21.59 -    }
   21.60 -    unichar ch1 = [self.string characterAtIndex:pos];
   21.61 -    unichar ch2 = [self.string characterAtIndex:pos + 1];
   21.62 -    if (ch1 == s_quoteChar && ch2 != s_quoteChar) {
   21.63 -        return YES;
   21.64 -    }
   21.65 -    return NO;
   21.66 -}
   21.67 -
   21.68 -/**
   21.69 - @return YES if the given position points to an ending quote.
   21.70 - */
   21.71 -- (BOOL)endingQuoteAt:(NSInteger)pos
   21.72 -{
   21.73 -    NSString *context = [self.string substringFromIndex:pos];
   21.74 -    unichar ch1 = [self.string characterAtIndex:pos];
   21.75 -    if (ch1 == s_quoteChar) {
   21.76 -        if (pos == self.len - 1) {
   21.77 -            return YES;
   21.78 -        }
   21.79 -        unichar ch2 = [self.string characterAtIndex:pos + 1];
   21.80 -        return ch2 != s_quoteChar;
   21.81 -    }
   21.82 -    return NO;
   21.83 -}
   21.84 -
   21.85 -@end
    22.1 --- a/pEpiOSAdapter/PEPLanguage.h	Wed May 17 08:16:57 2017 +0200
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,33 +0,0 @@
    22.4 -//
    22.5 -//  PEPLanguage.h
    22.6 -//  pEpiOSAdapter
    22.7 -//
    22.8 -//  Created by Dirk Zimmermann on 03.05.17.
    22.9 -//  Copyright © 2017 p≡p. All rights reserved.
   22.10 -//
   22.11 -
   22.12 -#import <Foundation/Foundation.h>
   22.13 -
   22.14 -@interface PEPLanguage : NSObject
   22.15 -
   22.16 -- (instancetype _Nonnull)initWithCode:(NSString * _Nonnull)code
   22.17 -                                 name:(NSString * _Nonnull)name
   22.18 -                                 sentence:(NSString * _Nonnull)sentence;
   22.19 -
   22.20 -/**
   22.21 - ISO 639-1 language code
   22.22 - */
   22.23 -@property (nonatomic, nonnull) NSString *code;
   22.24 -
   22.25 -/**
   22.26 - Name of the language. Should not be translated.
   22.27 - */
   22.28 -@property (nonatomic, nonnull) NSString *name;
   22.29 -
   22.30 -/**
   22.31 - Sentence of the form "I want to display the trustwords in <lang>".
   22.32 - Should not be translated.
   22.33 - */
   22.34 -@property (nonatomic, nonnull) NSString *sentence;
   22.35 -
   22.36 -@end
    23.1 --- a/pEpiOSAdapter/PEPLanguage.m	Wed May 17 08:16:57 2017 +0200
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,35 +0,0 @@
    23.4 -//
    23.5 -//  PEPLanguage.m
    23.6 -//  pEpiOSAdapter
    23.7 -//
    23.8 -//  Created by Dirk Zimmermann on 03.05.17.
    23.9 -//  Copyright © 2017 p≡p. All rights reserved.
   23.10 -//
   23.11 -
   23.12 -#import "PEPLanguage.h"
   23.13 -
   23.14 -@implementation PEPLanguage
   23.15 -
   23.16 -- (instancetype _Nonnull)initWithCode:(NSString * _Nonnull)code
   23.17 -                                 name:(NSString * _Nonnull)name
   23.18 -                                 sentence:(NSString * _Nonnull)sentence
   23.19 -{
   23.20 -    if (self = [[PEPLanguage alloc] init]) {
   23.21 -        _code = code;
   23.22 -        _name = name;
   23.23 -        _sentence = sentence;
   23.24 -    }
   23.25 -    return self;
   23.26 -}
   23.27 -
   23.28 -- (NSString *)debugDescription
   23.29 -{
   23.30 -    return [NSString stringWithFormat:@"<%@: %p> %@", [self class], self, self.description];
   23.31 -}
   23.32 -
   23.33 -- (NSString *)description
   23.34 -{
   23.35 -    return [NSString stringWithFormat:@"%@ %@", self.code, self.name];
   23.36 -}
   23.37 -
   23.38 -@end
    24.1 --- a/pEpiOSAdapter/PEPMessage.h	Wed May 17 08:16:57 2017 +0200
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,114 +0,0 @@
    24.4 -//
    24.5 -//  MCOAbstractMessage+PEPMessage.h
    24.6 -//  pEpiOSAdapter
    24.7 -//
    24.8 -//  Created by Volker Birk on 09.07.15.
    24.9 -//  Copyright (c) 2015 p≡p. All rights reserved.
   24.10 -//
   24.11 -
   24.12 -#import <Foundation/Foundation.h>
   24.13 -
   24.14 -#include "message_api.h"
   24.15 -
   24.16 -NSArray * _Nonnull PEP_arrayFromStringlist(stringlist_t * _Nonnull sl);
   24.17 -stringlist_t * _Nullable PEP_arrayToStringlist(NSArray * _Nullable array);
   24.18 -
   24.19 -pEp_identity * _Nullable PEP_identityDictToStruct(NSDictionary * _Nullable dict);
   24.20 -NSDictionary * _Nonnull PEP_identityDictFromStruct(pEp_identity * _Nullable ident);
   24.21 -
   24.22 -message * _Nullable PEP_messageDictToStruct(NSDictionary * _Nullable dict);
   24.23 -NSDictionary * _Nonnull PEP_messageDictFromStruct(message * _Nullable msg);
   24.24 -
   24.25 -#pragma mark -- Constants
   24.26 -
   24.27 -/** The name of the user */
   24.28 -extern NSString *const _Nonnull kPepUsername;
   24.29 -
   24.30 -/** Email address of the contact */
   24.31 -extern NSString *const _Nonnull kPepAddress;
   24.32 -
   24.33 -/**
   24.34 - A user ID, used by pEp to map multiple identities to a single user.
   24.35 - This should be a stable ID (e.g. derived from the address book if possible).
   24.36 - pEp identities set up with mySelf() get a special user ID.
   24.37 - */
   24.38 -extern NSString *const _Nonnull kPepUserID;
   24.39 -
   24.40 -/** The fingerprint for the key for this contact. */
   24.41 -extern NSString *const _Nonnull kPepFingerprint;
   24.42 -
   24.43 -/** NSNumber denoting a boolean, true if that identity was setup with mySelf() */
   24.44 -extern NSString *const _Nonnull kPepIsMe;
   24.45 -
   24.46 -/** In an email, the identity this email is from */
   24.47 -extern NSString *const _Nonnull kPepFrom;
   24.48 -
   24.49 -/** In an email, the `NSArray` of to recipients */
   24.50 -extern NSString *const _Nonnull kPepTo;
   24.51 -
   24.52 -/** In an email, the `NSArray` of CC recipients */
   24.53 -extern NSString *const _Nonnull kPepCC;
   24.54 -
   24.55 -/** In an email, the `NSArray` of BCC recipients */
   24.56 -extern NSString *const _Nonnull kPepBCC;
   24.57 -
   24.58 -/** The subject of an email */
   24.59 -extern NSString *const _Nonnull kPepShortMessage;
   24.60 -
   24.61 -/** The text message of an email */
   24.62 -extern NSString *const _Nonnull kPepLongMessage;
   24.63 -
   24.64 -/** HTML message part, if any */
   24.65 -extern NSString *const _Nonnull kPepLongMessageFormatted;
   24.66 -
   24.67 -/** NSNumber denoting a boolean. True if that message is supposed to be sent. */
   24.68 -extern NSString *const _Nonnull kPepOutgoing;
   24.69 -
   24.70 -/** Sent date of the message (NSDate) */
   24.71 -extern NSString *const _Nonnull kPepSent;
   24.72 -
   24.73 -/** Received date of the message (NSDate) */
   24.74 -extern NSString *const _Nonnull kPepReceived;
   24.75 -
   24.76 -/** The message ID */
   24.77 -extern NSString *const _Nonnull kPepID;
   24.78 -
   24.79 -extern NSString *const _Nonnull kPepReceivedBy;
   24.80 -extern NSString *const _Nonnull kPepReplyTo;
   24.81 -extern NSString *const _Nonnull kPepInReplyTo;
   24.82 -extern NSString *const _Nonnull kPepReferences;
   24.83 -extern NSString *const _Nonnull kPepKeywords;
   24.84 -extern NSString *const _Nonnull kPepOptFields;
   24.85 -
   24.86 -/** NSArray of attachment dicts */
   24.87 -extern NSString *const _Nonnull kPepAttachments;
   24.88 -
   24.89 -/** The binary NSData representing the content of an attachment */
   24.90 -extern NSString *const _Nonnull kPepMimeData;
   24.91 -
   24.92 -/** The NSString filename of an attachment, if any */
   24.93 -extern NSString *const _Nonnull kPepMimeFilename;
   24.94 -
   24.95 -/** The mime type of an attachment */
   24.96 -extern NSString *const _Nonnull kPepMimeType;
   24.97 -
   24.98 -/** The content ID of an attachment */
   24.99 -extern NSString *const _Nonnull kPepContentID;
  24.100 -
  24.101 -/** The pEp internal communication type */
  24.102 -extern NSString *const _Nonnull kPepCommType;
  24.103 -
  24.104 -/** The raw message created by pEp (NSData) */
  24.105 -extern NSString *const _Nonnull kPepRawMessage;
  24.106 -
  24.107 -/** NSError parameters will use this domain */
  24.108 -extern NSString *const _Nonnull PEPSessionErrorDomain;
  24.109 -
  24.110 -/** Optional field "X-pEp-Version" */
  24.111 -extern NSString *const _Nonnull kXpEpVersion;
  24.112 -
  24.113 -/** Optional field "X-EncStatus" */
  24.114 -extern NSString *const _Nonnull kXEncStatus;
  24.115 -
  24.116 -/** Optional field "X-KeyList" */
  24.117 -extern NSString *const _Nonnull kXKeylist;
    25.1 --- a/pEpiOSAdapter/PEPMessage.m	Wed May 17 08:16:57 2017 +0200
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,434 +0,0 @@
    25.4 -//
    25.5 -//  PEPMessage.m
    25.6 -//  pEpiOSAdapter
    25.7 -//
    25.8 -//  Created by Volker Birk on 09.07.15.
    25.9 -//  Copyright (c) 2015 p≡p. All rights reserved.
   25.10 -//
   25.11 -
   25.12 -#import "PEPMessage.h"
   25.13 -
   25.14 -#pragma mark -- Constants
   25.15 -
   25.16 -NSString *const kPepUsername = @"username";
   25.17 -
   25.18 -NSString *const kPepAddress = @"address";
   25.19 -
   25.20 -NSString *const kPepUserID = @"user_id";
   25.21 -
   25.22 -NSString *const kPepFingerprint = @"fpr";
   25.23 -
   25.24 -NSString *const kPepIsMe = @"me";
   25.25 -
   25.26 -NSString *const kPepFrom = @"from";
   25.27 -
   25.28 -NSString *const kPepTo = @"to";
   25.29 -
   25.30 -NSString *const kPepCC = @"cc";
   25.31 -
   25.32 -NSString *const kPepBCC = @"bcc";
   25.33 -
   25.34 -NSString *const kPepShortMessage = @"shortmsg";
   25.35 -
   25.36 -NSString *const kPepLongMessage = @"longmsg";
   25.37 -
   25.38 -NSString *const kPepLongMessageFormatted = @"longmsg_formatted";
   25.39 -
   25.40 -NSString *const kPepOutgoing = @"outgoing";
   25.41 -
   25.42 -NSString *const kPepSent = @"sent";
   25.43 -
   25.44 -NSString *const kPepReceived = @"recv";
   25.45 -
   25.46 -NSString *const kPepID = @"id";
   25.47 -
   25.48 -NSString *const kPepReceivedBy = @"recv_by";
   25.49 -NSString *const kPepReplyTo = @"reply_to";
   25.50 -NSString *const kPepInReplyTo = @"in_reply_to";
   25.51 -NSString *const kPepReferences = @"references";
   25.52 -NSString *const kPepKeywords = @"keywords";
   25.53 -NSString *const kPepOptFields = @"opt_fields";
   25.54 -
   25.55 -NSString *const kPepAttachments = @"attachments";
   25.56 -
   25.57 -NSString *const kPepMimeData = @"data";
   25.58 -
   25.59 -NSString *const kPepMimeFilename = @"filename";
   25.60 -
   25.61 -NSString *const kPepMimeType = @"mimeType";
   25.62 -
   25.63 -NSString *const kPepContentID = @"contentID";
   25.64 -
   25.65 -NSString *const kPepCommType = @"comm_type";
   25.66 -
   25.67 -NSString *const kPepRawMessage = @"raw_message";
   25.68 -
   25.69 -NSString *const kXpEpVersion = @"X-pEp-Version";
   25.70 -
   25.71 -NSString *const kXEncStatus = @"X-EncStatus";
   25.72 -
   25.73 -NSString *const kXKeylist = @"X-KeyList";
   25.74 -
   25.75 -NSArray *PEP_arrayFromStringlist(stringlist_t *sl)
   25.76 -{
   25.77 -    NSMutableArray *array = [NSMutableArray array];
   25.78 -    
   25.79 -    for (stringlist_t *_sl = sl; _sl && _sl->value; _sl = _sl->next) {
   25.80 -        [array addObject:[NSString stringWithUTF8String:_sl->value]];
   25.81 -    }
   25.82 -    
   25.83 -    return array;
   25.84 -}
   25.85 -
   25.86 -stringlist_t *PEP_arrayToStringlist(NSArray *array)
   25.87 -{
   25.88 -    stringlist_t *sl = new_stringlist(NULL);
   25.89 -    if (!sl)
   25.90 -        return NULL;
   25.91 -    
   25.92 -    stringlist_t *_sl = sl;
   25.93 -    for (NSString *str in array) {
   25.94 -        _sl = stringlist_add(_sl, [[str precomposedStringWithCanonicalMapping] UTF8String]);
   25.95 -    }
   25.96 -    
   25.97 -    return sl;
   25.98 -}
   25.99 -
  25.100 -NSArray *PEP_arrayFromStringPairlist(stringpair_list_t *sl)
  25.101 -{
  25.102 -    NSMutableArray *array = [NSMutableArray array];
  25.103 -
  25.104 -    for (stringpair_list_t *_sl = sl; _sl && _sl->value; _sl = _sl->next) {
  25.105 -        [array addObject:[[NSMutableArray alloc ]initWithObjects:
  25.106 -                [NSString stringWithUTF8String:_sl->value->key],
  25.107 -                [NSString stringWithUTF8String:_sl->value->value],
  25.108 -                nil]];
  25.109 -    }
  25.110 -
  25.111 -    return array;
  25.112 -}
  25.113 -
  25.114 -stringpair_list_t *PEP_arrayToStringPairlist(NSArray *array)
  25.115 -{
  25.116 -    stringpair_list_t *sl = new_stringpair_list(NULL);
  25.117 -    if (!sl)
  25.118 -        return NULL;
  25.119 -    
  25.120 -    stringpair_list_t *_sl = sl;
  25.121 -    for (NSArray *pair in array) {
  25.122 -        stringpair_t *_sp = new_stringpair(
  25.123 -               [[pair[0] precomposedStringWithCanonicalMapping] UTF8String],
  25.124 -               [[pair[1] precomposedStringWithCanonicalMapping] UTF8String]);
  25.125 -        _sl = stringpair_list_add(_sl, _sp);
  25.126 -    }
  25.127 -    
  25.128 -    return sl;
  25.129 -}
  25.130 -
  25.131 -
  25.132 -NSArray *PEP_arrayFromBloblist(bloblist_t *bl)
  25.133 -{
  25.134 -    NSMutableArray *array = [NSMutableArray array];
  25.135 -    
  25.136 -    for (bloblist_t *_bl = bl; _bl && _bl->value; _bl = _bl->next) {
  25.137 -        NSMutableDictionary* blob = [NSMutableDictionary new];
  25.138 -        [blob setObject: [NSData dataWithBytes:_bl->value
  25.139 -                                 length:_bl->size]
  25.140 -              forKey:@"data"];
  25.141 -        
  25.142 -        if(_bl->filename && _bl->filename[0])
  25.143 -            [blob setObject:[NSString stringWithUTF8String:_bl->filename]
  25.144 -                 forKey:@"filename"];
  25.145 -        
  25.146 -        if(_bl->mime_type && _bl->mime_type[0])
  25.147 -            [blob setObject: [NSString stringWithUTF8String:_bl->mime_type]
  25.148 -                 forKey:@"mimeType"];
  25.149 -        
  25.150 -        [array addObject:blob];
  25.151 -    }
  25.152 -    return array;
  25.153 -}
  25.154 -
  25.155 -bloblist_t *PEP_arrayToBloblist(NSArray *array)
  25.156 -{
  25.157 -    if (array.count == 0) {
  25.158 -        return nil;
  25.159 -    }
  25.160 -
  25.161 -    bloblist_t *_bl = new_bloblist(NULL, 0, NULL, NULL);
  25.162 -    bloblist_t *bl =_bl;
  25.163 -    for (NSMutableDictionary *blob in array) {
  25.164 -        NSData *data = blob[@"data"];
  25.165 -        size_t size = [data length];
  25.166 -        
  25.167 -        char *buf = malloc(size);
  25.168 -        assert(buf);
  25.169 -        memcpy(buf, [data bytes], size);
  25.170 -        
  25.171 -        bl = bloblist_add(bl, buf, size,
  25.172 -                          [blob[@"mimeType"] UTF8String],
  25.173 -                          [[blob[@"filename"] precomposedStringWithCanonicalMapping] UTF8String]);
  25.174 -    }
  25.175 -    return _bl;
  25.176 -}
  25.177 -
  25.178 -NSDictionary *PEP_identityDictFromStruct(pEp_identity *ident)
  25.179 -{
  25.180 -    NSMutableDictionary *dict = [NSMutableDictionary new];
  25.181 -
  25.182 -    if (ident) {
  25.183 -        if (ident->address && ident->address[0])
  25.184 -            [dict setObject:[NSString stringWithUTF8String:ident->address] forKey:@"address"];
  25.185 -        
  25.186 -        if (ident->fpr && ident->fpr[0])
  25.187 -            [dict setObject:[NSString stringWithUTF8String:ident->fpr] forKey:@"fpr"];
  25.188 -        
  25.189 -        if (ident->user_id && ident->user_id[0])
  25.190 -            [dict setObject:[NSString stringWithUTF8String:ident->user_id] forKey:@"user_id"];
  25.191 -        
  25.192 -        if (ident->username && ident->username[0])
  25.193 -            [dict setObject:[NSString stringWithUTF8String:ident->username] forKey:@"username"];
  25.194 -        
  25.195 -        if (ident->lang[0])
  25.196 -            [dict setObject:[NSString stringWithUTF8String:ident->lang] forKey:@"lang"];
  25.197 -        
  25.198 -        [dict setObject:[NSNumber numberWithInt: ident->comm_type] forKey:@"comm_type"];
  25.199 -        
  25.200 -        if (ident->me)
  25.201 -            [dict setObject:@YES forKey:@"me"];
  25.202 -        else
  25.203 -            [dict setObject:@NO forKey:@"me"];
  25.204 -    }
  25.205 -    return dict;
  25.206 -}
  25.207 -
  25.208 -pEp_identity *PEP_identityDictToStruct(NSDictionary *dict)
  25.209 -{
  25.210 -    pEp_identity *ident = new_identity(NULL, NULL, NULL, NULL);
  25.211 -    
  25.212 -    if (dict && ident) {
  25.213 -        if ([dict objectForKey:@"address"])
  25.214 -            ident->address = strdup(
  25.215 -                                    [[[dict objectForKey:@"address"] precomposedStringWithCanonicalMapping] UTF8String]
  25.216 -                                    );
  25.217 -        
  25.218 -        if ([dict objectForKey:@"fpr"]){
  25.219 -            ident->fpr = strdup(
  25.220 -                                [[[dict objectForKey:@"fpr"] precomposedStringWithCanonicalMapping] UTF8String]
  25.221 -                                );
  25.222 -        }
  25.223 -        
  25.224 -        if ([dict objectForKey:@"user_id"]){
  25.225 -            ident->user_id = strdup(
  25.226 -                                    [[[dict objectForKey:@"user_id"] precomposedStringWithCanonicalMapping] UTF8String]
  25.227 -                                    );
  25.228 -        }
  25.229 -        
  25.230 -        if ([dict objectForKey:@"username"])
  25.231 -            ident->username = strdup(
  25.232 -                                     [[[dict objectForKey:@"username"] precomposedStringWithCanonicalMapping] UTF8String]
  25.233 -                                     );
  25.234 -        
  25.235 -        if ([dict objectForKey:@"lang"])
  25.236 -            strncpy(ident->fpr, [[[dict objectForKey:@"lang"] precomposedStringWithCanonicalMapping] UTF8String], 2);
  25.237 -        
  25.238 -        if ([[dict objectForKey:@"me"] isEqual: @YES])
  25.239 -            ident->me = true;
  25.240 -        
  25.241 -        if ([dict objectForKey:@"comm_type"])
  25.242 -            ident->comm_type = [[dict objectForKey:@"comm_type"] intValue];
  25.243 -    }
  25.244 -    
  25.245 -    return ident;
  25.246 -}
  25.247 -
  25.248 -NSArray *PEP_arrayFromIdentityList(identity_list *il)
  25.249 -{
  25.250 -    NSMutableArray *array = [NSMutableArray array];
  25.251 -    
  25.252 -    for (identity_list *_il = il; _il && _il->ident; _il = _il->next) {
  25.253 -        [array addObject:PEP_identityDictFromStruct(il->ident)];
  25.254 -    }
  25.255 -    
  25.256 -    return array;
  25.257 -}
  25.258 -
  25.259 -identity_list *PEP_arrayToIdentityList(NSArray *array)
  25.260 -{
  25.261 -    identity_list *il = new_identity_list(NULL);
  25.262 -    if (!il)
  25.263 -        return NULL;
  25.264 -    
  25.265 -    identity_list *_il = il;
  25.266 -    for (NSDictionary *dict in array) {
  25.267 -        _il = identity_list_add(_il, PEP_identityDictToStruct(dict));
  25.268 -    }
  25.269 -    
  25.270 -    return il;
  25.271 -}
  25.272 -
  25.273 -identity_list *PEP_identityArrayToList(NSArray *array)
  25.274 -{
  25.275 -    identity_list *il = new_identity_list(NULL);
  25.276 -    if (!il)
  25.277 -        return NULL;
  25.278 -    
  25.279 -    identity_list *_il = il;
  25.280 -    for (NSMutableDictionary *address in array) {
  25.281 -        _il = identity_list_add(_il, PEP_identityDictToStruct(address));
  25.282 -    }
  25.283 -    
  25.284 -    return il;
  25.285 -}
  25.286 -
  25.287 -NSArray *PEP_identityArrayFromList(identity_list *il)
  25.288 -{
  25.289 -    NSMutableArray *array = [NSMutableArray array];
  25.290 -    
  25.291 -    for (identity_list *_il = il; _il && _il->ident; _il = _il->next) {
  25.292 -        NSDictionary *address = PEP_identityDictFromStruct(_il->ident);
  25.293 -        [array addObject:address];
  25.294 -    }
  25.295 -    
  25.296 -    return array;
  25.297 -}
  25.298 -
  25.299 -NSDictionary *PEP_messageDictFromStruct(message *msg)
  25.300 -{
  25.301 -    NSMutableDictionary *dict = [NSMutableDictionary new];
  25.302 -    if (msg && dict) {
  25.303 -
  25.304 -        [dict setObject:(msg->dir==PEP_dir_outgoing)?@YES:@NO forKey:@"outgoing"];
  25.305 -
  25.306 -        if (msg->id)
  25.307 -            [dict setObject:[NSString stringWithUTF8String:msg->id] forKey:@"id"];
  25.308 -        
  25.309 -        if (msg->shortmsg)
  25.310 -            [dict setObject:[NSString stringWithUTF8String:msg->shortmsg] forKey:@"shortmsg"];
  25.311 -
  25.312 -        if (msg->sent)
  25.313 -            [dict setObject:[NSDate dateWithTimeIntervalSince1970:timegm(msg->sent)] forKey:@"sent"];
  25.314 -        
  25.315 -        if (msg->recv)
  25.316 -            [dict setObject:[NSDate dateWithTimeIntervalSince1970:mktime(msg->recv)] forKey:@"recv"];
  25.317 -        
  25.318 -        if (msg->from)
  25.319 -            [dict setObject:PEP_identityDictFromStruct(msg->from) forKey:@"from"];
  25.320 -        
  25.321 -        if (msg->to && msg->to->ident)
  25.322 -            [dict setObject:PEP_identityArrayFromList(msg->to) forKey:@"to"];
  25.323 -        
  25.324 -        if (msg->recv_by)
  25.325 -            [dict setObject:PEP_identityDictFromStruct(msg->recv_by) forKey:@"recv_by"];
  25.326 -        
  25.327 -        if (msg->cc && msg->cc->ident)
  25.328 -            [dict setObject:PEP_identityArrayFromList(msg->cc) forKey:@"cc"];
  25.329 -        
  25.330 -        if (msg->bcc && msg->bcc->ident)
  25.331 -            [dict setObject:PEP_identityArrayFromList(msg->bcc) forKey:@"bcc"];
  25.332 -        
  25.333 -        if (msg->reply_to && msg->reply_to->ident)
  25.334 -            [dict setObject:PEP_identityArrayFromList(msg->reply_to) forKey:@"reply_to"];
  25.335 -        
  25.336 -        if (msg->in_reply_to)
  25.337 -            [dict setObject:PEP_arrayFromStringlist(msg->in_reply_to) forKey:@"in_reply_to"];
  25.338 -
  25.339 -        if (msg->references && msg->references->value)
  25.340 -            [dict setObject:PEP_arrayFromStringlist(msg->references) forKey:kPepReferences];
  25.341 -
  25.342 -        if (msg->keywords && msg->keywords->value)
  25.343 -            [dict setObject:PEP_arrayFromStringlist(msg->keywords) forKey:@"keywords"];
  25.344 -
  25.345 -        if (msg->opt_fields)
  25.346 -            [dict setObject:PEP_arrayFromStringPairlist(msg->opt_fields) forKey:@"opt_fields"];
  25.347 -        
  25.348 -        if (msg->longmsg_formatted)
  25.349 -            [dict setObject:[NSString stringWithUTF8String:msg->longmsg_formatted]
  25.350 -                     forKey:@"longmsg_formatted"];
  25.351 -
  25.352 -        if (msg->longmsg)
  25.353 -            [dict setObject:[NSString stringWithUTF8String:msg->longmsg] forKey:@"longmsg"];
  25.354 -        
  25.355 -        if (msg->attachments && msg->attachments->value)
  25.356 -            [dict setObject: PEP_arrayFromBloblist(msg->attachments) forKey:@"attachments"];
  25.357 -
  25.358 -        if (msg->rawmsg_size > 0 && *msg->rawmsg_ref) {
  25.359 -            NSData *data = [NSData dataWithBytes:msg->rawmsg_ref length:msg->rawmsg_size];
  25.360 -            dict[kPepRawMessage] = data;
  25.361 -        }
  25.362 -
  25.363 -        return dict;
  25.364 -    }
  25.365 -    return nil;
  25.366 -}
  25.367 -
  25.368 -message *PEP_messageDictToStruct(NSDictionary *dict)
  25.369 -{
  25.370 -    // Direction default to incoming
  25.371 -    PEP_msg_direction dir = PEP_dir_incoming;
  25.372 -    
  25.373 -    if ([dict objectForKey:@"outgoing"])
  25.374 -        dir = [[dict objectForKey:@"outgoing"] boolValue] ? PEP_dir_outgoing : PEP_dir_incoming;
  25.375 -    
  25.376 -    message *msg = new_message(dir);
  25.377 -    
  25.378 -    if(!msg)
  25.379 -        return NULL;
  25.380 -    
  25.381 -    if ([dict objectForKey:@"id"])
  25.382 -        msg->id = strdup([[[dict objectForKey:@"id"] precomposedStringWithCanonicalMapping]
  25.383 -                          UTF8String]);
  25.384 -    
  25.385 -    if ([dict objectForKey:@"shortmsg"])
  25.386 -        msg->shortmsg = strdup([[[dict objectForKey:@"shortmsg"]
  25.387 -                                 precomposedStringWithCanonicalMapping] UTF8String]);
  25.388 -
  25.389 -    if ([dict objectForKey:@"sent"])
  25.390 -        msg->sent = new_timestamp([[dict objectForKey:@"sent"] timeIntervalSince1970]);
  25.391 -    
  25.392 -    if ([dict objectForKey:@"recv"])
  25.393 -        msg->recv = new_timestamp([[dict objectForKey:@"recv"] timeIntervalSince1970]);
  25.394 -    
  25.395 -    if ([dict objectForKey:@"from"])
  25.396 -        msg->from = PEP_identityDictToStruct([dict objectForKey:@"from"]);
  25.397 -
  25.398 -    if ([dict objectForKey:@"to"])
  25.399 -        msg->to = PEP_identityArrayToList([dict objectForKey:@"to"]);
  25.400 -
  25.401 -    if ([dict objectForKey:@"recv_by"])
  25.402 -        msg->recv_by = PEP_identityDictToStruct([dict objectForKey:@"recv_by"]);
  25.403 -
  25.404 -    if ([dict objectForKey:@"cc"])
  25.405 -        msg->cc = PEP_identityArrayToList([dict objectForKey:@"cc"]);
  25.406 -
  25.407 -    if ([dict objectForKey:@"bcc"])
  25.408 -        msg->bcc = PEP_identityArrayToList([dict objectForKey:@"bcc"]);
  25.409 -    
  25.410 -    if ([dict objectForKey:@"reply_to"])
  25.411 -        msg->reply_to = PEP_identityArrayToList([dict objectForKey:@"reply_to"]);
  25.412 -    
  25.413 -    if ([dict objectForKey:@"in_reply_to"])
  25.414 -        msg->in_reply_to = PEP_arrayToStringlist([dict objectForKey:@"in_reply_to"]);
  25.415 -    
  25.416 -    if ([dict objectForKey:@"references"])
  25.417 -        msg->references = PEP_arrayToStringlist([dict objectForKey:@"references"]);
  25.418 -    
  25.419 -    if ([dict objectForKey:kPepKeywords])
  25.420 -        msg->keywords = PEP_arrayToStringlist([dict objectForKey:kPepKeywords]);
  25.421 -
  25.422 -    if ([dict objectForKey:@"opt_fields"])
  25.423 -        msg->opt_fields = PEP_arrayToStringPairlist([dict objectForKey:@"opt_fields"]);
  25.424 -    
  25.425 -    if ([dict objectForKey:@"longmsg"])
  25.426 -        msg->longmsg = strdup([[[dict objectForKey:@"longmsg"]
  25.427 -             precomposedStringWithCanonicalMapping] UTF8String]);
  25.428 -    
  25.429 -    if ([dict objectForKey:@"longmsg_formatted"])
  25.430 -        msg->longmsg_formatted = strdup([[[dict objectForKey:@"longmsg_formatted"]
  25.431 -             precomposedStringWithCanonicalMapping] UTF8String]);
  25.432 -
  25.433 -    if ([dict objectForKey:@"attachments"])
  25.434 -        msg->attachments = PEP_arrayToBloblist([dict objectForKey:@"attachments"]);
  25.435 -
  25.436 -    return msg;
  25.437 -}
    26.1 --- a/pEpiOSAdapter/PEPObjCAdapter+Internal.h	Wed May 17 08:16:57 2017 +0200
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,33 +0,0 @@
    26.4 -//
    26.5 -//  PEPIOSAdapter+Internal.h
    26.6 -//  pEpiOSAdapter
    26.7 -//
    26.8 -//  Created by Edouard Tisserant on 11/11/15.
    26.9 -//  Copyright © 2015 p≡p. All rights reserved.
   26.10 -//
   26.11 -
   26.12 -#ifndef PEPIOSAdapter_Internal_h
   26.13 -#define PEPIOSAdapter_Internal_h
   26.14 -
   26.15 -#import "sync.h"
   26.16 -
   26.17 -#import "PEPQueue.h"
   26.18 -#import "PEPSession.h"
   26.19 -#import "PEPSession+Internal.h"
   26.20 -
   26.21 -@interface PEPObjCAdapter ()
   26.22 -
   26.23 -// this messages are for internal use only; do not call
   26.24 -
   26.25 -+ (void)registerExamineFunction:(PEP_SESSION)session;
   26.26 -+ (PEPQueue*)getLookupQueue;
   26.27 -
   26.28 -+ (PEPQueue*)getSyncQueue;
   26.29 -+ (id <PEPSyncDelegate>)getSyncDelegate;
   26.30 -+ (void)bindSession:(PEPSession*)session;
   26.31 -+ (void)unbindSession:(PEPSession*)session;
   26.32 -
   26.33 -
   26.34 -@end
   26.35 -
   26.36 -#endif /* PEPIOSAdapter_Internal_h */
    27.1 --- a/pEpiOSAdapter/PEPObjCAdapter.h	Wed May 17 08:16:57 2017 +0200
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,61 +0,0 @@
    27.4 -//
    27.5 -//  pEpiOSAdapter.h
    27.6 -//  pEpiOSAdapter
    27.7 -//
    27.8 -//  Created by Volker Birk on 28.04.15.
    27.9 -//  Copyright (c) 2015 p≡p. All rights reserved.
   27.10 -//
   27.11 -
   27.12 -#import <Foundation/Foundation.h>
   27.13 -
   27.14 -#include "message_api.h"
   27.15 -#include "sync_app.h"
   27.16 -
   27.17 -@protocol PEPKeyManagementDelegate <NSObject>
   27.18 -
   27.19 -- (void)identityUpdated:(id)identity;
   27.20 -
   27.21 -@end
   27.22 -
   27.23 -@protocol PEPSyncDelegate <NSObject>
   27.24 -
   27.25 -- (PEP_STATUS)notifyHandshakeWithSignal:(sync_handshake_signal)signal me:(id)me partner:(id)partner;
   27.26 -
   27.27 -- (PEP_STATUS)sendMessage:(id)msg;
   27.28 -
   27.29 -@end
   27.30 -
   27.31 -@interface PEPObjCAdapter : NSObject
   27.32 -
   27.33 -/**
   27.34 - The HOME URL, where all pEp related files will be stored.
   27.35 - */
   27.36 -+ (NSURL *)homeURL;
   27.37 -
   27.38 -/**
   27.39 - Start keyserver lookup.
   27.40 - - Note: There is only one keyserver lookup thread
   27.41 - */
   27.42 -+ (void)startKeyserverLookup;
   27.43 -
   27.44 -/**
   27.45 - Stop keyserver lookup.
   27.46 - */
   27.47 -+ (void)stopKeyserverLookup;
   27.48 -
   27.49 -+ (void)setupTrustWordsDB;
   27.50 -+ (void)setupTrustWordsDB:(NSBundle *)rootBundle;
   27.51 -
   27.52 -/**
   27.53 - Start Sync.
   27.54 - - Note: There is only one Sync session and thread
   27.55 - */
   27.56 -+ (void)startSync:(id <PEPSyncDelegate>)delegate;
   27.57 -
   27.58 -/**
   27.59 - Stop Sync.
   27.60 - */
   27.61 -+ (void)stopSync;
   27.62 -
   27.63 -
   27.64 -@end
    28.1 --- a/pEpiOSAdapter/PEPObjCAdapter.m	Wed May 17 08:16:57 2017 +0200
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,420 +0,0 @@
    28.4 -//
    28.5 -//  pEpiOSAdapter.m
    28.6 -//  pEpiOSAdapter
    28.7 -//
    28.8 -//  Created by Volker Birk on 28.04.15.
    28.9 -//  Copyright (c) 2015 p≡p. All rights reserved.
   28.10 -//
   28.11 -
   28.12 -@import Foundation;
   28.13 -
   28.14 -#import "PEPObjCAdapter.h"
   28.15 -#import "PEPObjCAdapter+Internal.h"
   28.16 -#import "PEPMessage.h"
   28.17 -#include "keymanagement.h"
   28.18 -
   28.19 -///////////////////////////////////////////////////////////////////////////////
   28.20 -//  Keyserver and Identity lookup - C part
   28.21 -
   28.22 -
   28.23 -int examine_identity(pEp_identity *ident, void *management)
   28.24 -{
   28.25 -    //PEPQueue *q = (__bridge PEPQueue *)management;
   28.26 -    PEPQueue *q = [PEPObjCAdapter getLookupQueue];
   28.27 -    
   28.28 -    NSDictionary *identity = PEP_identityDictFromStruct(ident);
   28.29 -    
   28.30 -    [q enqueue:identity];
   28.31 -    return 0;
   28.32 -}
   28.33 -
   28.34 -static pEp_identity *retrieve_next_identity(void *management)
   28.35 -{
   28.36 -    //PEPQueue *q = (__bridge PEPQueue *)management;
   28.37 -    PEPQueue *q = [PEPObjCAdapter getLookupQueue];
   28.38 -    
   28.39 -    // Dequeue is a blocking operation
   28.40 -    // that returns nil when queue is killed
   28.41 -    NSDictionary *ident = [q dequeue];
   28.42 -    
   28.43 -    if (ident)
   28.44 -        return PEP_identityDictToStruct(ident);
   28.45 -    else
   28.46 -        return NULL;
   28.47 -}
   28.48 -
   28.49 -///////////////////////////////////////////////////////////////////////////////
   28.50 -// Sync - C part
   28.51 -
   28.52 -// Called by sync thread only
   28.53 -PEP_STATUS notify_handshake(void *unused_object, pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal)
   28.54 -{
   28.55 -    id <PEPSyncDelegate> syncDelegate = [PEPObjCAdapter getSyncDelegate];
   28.56 -    if ( syncDelegate )
   28.57 -        return [syncDelegate
   28.58 -                notifyHandshakeWithSignal:signal
   28.59 -                me:PEP_identityDictFromStruct(me)
   28.60 -                partner:PEP_identityDictFromStruct(partner)];
   28.61 -    else
   28.62 -        return PEP_SYNC_NO_NOTIFY_CALLBACK;
   28.63 -}
   28.64 -
   28.65 -// Called by sync thread only
   28.66 -PEP_STATUS message_to_send(void *unused_object, message *msg)
   28.67 -{
   28.68 -    id <PEPSyncDelegate> syncDelegate = [PEPObjCAdapter getSyncDelegate];
   28.69 -    if ( syncDelegate )
   28.70 -        return [syncDelegate sendMessage:PEP_messageDictFromStruct(msg)];
   28.71 -    else
   28.72 -        return PEP_SEND_FUNCTION_NOT_REGISTERED;
   28.73 -}
   28.74 -
   28.75 -// called indirectly by decrypt message - any thread/session
   28.76 -int inject_sync_msg(void *msg, void *unused_management)
   28.77 -{
   28.78 -    PEPQueue *q = [PEPObjCAdapter getSyncQueue];
   28.79 -    
   28.80 -    [q enqueue:[NSValue valueWithPointer:msg]];
   28.81 -    
   28.82 -    return 0;
   28.83 -}
   28.84 -
   28.85 -// Called by sync thread only
   28.86 -void *retrieve_next_sync_msg(void *unused_mamagement, time_t *timeout)
   28.87 -{
   28.88 -    PEPQueue *q = [PEPObjCAdapter getSyncQueue];
   28.89 -    
   28.90 -    return (void*)[[q dequeue] pointerValue];
   28.91 -}
   28.92 -
   28.93 -
   28.94 -///////////////////////////////////////////////////////////////////////////////
   28.95 -// DB and paths
   28.96 -
   28.97 -const char* _Nullable SystemDB = NULL;
   28.98 -NSURL *s_homeURL;
   28.99 -
  28.100 -@implementation PEPObjCAdapter
  28.101 -
  28.102 -+ (void)initialize
  28.103 -{
  28.104 -    s_homeURL = [self createApplicationDirectory];
  28.105 -}
  28.106 -
  28.107 -+ (NSURL *)homeURL
  28.108 -{
  28.109 -    return s_homeURL;
  28.110 -}
  28.111 -
  28.112 -+ (NSURL *)createApplicationDirectory
  28.113 -{
  28.114 -    NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
  28.115 -    if (!bundleID) {
  28.116 -        // This can happen in unit tests
  28.117 -        bundleID = @"test";
  28.118 -    }
  28.119 -    NSFileManager *fm = [NSFileManager defaultManager];
  28.120 -    NSURL *dirPath = nil;
  28.121 -
  28.122 -    // Find the application support directory in the home directory.
  28.123 -    NSArray *appSupportDir = [fm URLsForDirectory:NSApplicationSupportDirectory
  28.124 -                                        inDomains:NSUserDomainMask];
  28.125 -    if ([appSupportDir count] > 0)
  28.126 -    {
  28.127 -        // Append the bundle ID to the URL for the
  28.128 -        // Application Support directory.
  28.129 -        // Mainly needed for OS X, but doesn't do any harm on iOS
  28.130 -        dirPath = [[appSupportDir objectAtIndex:0] URLByAppendingPathComponent:bundleID];
  28.131 -
  28.132 -        // If the directory does not exist, this method creates it.
  28.133 -        // This method is only available in OS X v10.7 and iOS 5.0 or later.
  28.134 -        NSError *theError = nil;
  28.135 -        if (![fm createDirectoryAtURL:dirPath withIntermediateDirectories:YES
  28.136 -                           attributes:nil error:&theError])
  28.137 -        {
  28.138 -            // Handle the error.
  28.139 -            return nil;
  28.140 -        }
  28.141 -    }
  28.142 -
  28.143 -    return dirPath;
  28.144 -}
  28.145 -
  28.146 -+ (NSURL *)createAndSetHomeDirectory
  28.147 -{
  28.148 -    // create and set home directory
  28.149 -    setenv("HOME", [[s_homeURL path] cStringUsingEncoding:NSUTF8StringEncoding], 1);
  28.150 -
  28.151 -    // create and set temp directory
  28.152 -    NSURL *tmpDirUrl = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
  28.153 -    setenv("TEMP", [[tmpDirUrl path] cStringUsingEncoding:NSUTF8StringEncoding], 1);
  28.154 -
  28.155 -    return s_homeURL;
  28.156 -}
  28.157 -
  28.158 -+ (NSString *) getBundlePathFor: (NSString *) filename
  28.159 -{
  28.160 -    return nil;
  28.161 -}
  28.162 -
  28.163 -+ (NSString *) copyAssetIntoDocumentsDirectory:(NSBundle *)rootBundle
  28.164 -                                                          :(NSString *)bundleName
  28.165 -                                                          :(NSString *)fileName{
  28.166 -
  28.167 -    NSURL *homeUrl = [PEPObjCAdapter createAndSetHomeDirectory];
  28.168 -    NSString *documentsDirectory = [homeUrl path];
  28.169 -    
  28.170 -    if(!(documentsDirectory && bundleName && fileName))
  28.171 -        return nil;
  28.172 -    
  28.173 -    // Check if the database file exists in the documents directory.
  28.174 -    NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:fileName];
  28.175 -    if (![[NSFileManager defaultManager] fileExistsAtPath:destinationPath]) {
  28.176 -        // The file does not exist in the documents directory, so copy it from bundle now.
  28.177 -        NSBundle *bundleObj = [NSBundle bundleWithPath:
  28.178 -                               [[rootBundle resourcePath]
  28.179 -                                stringByAppendingPathComponent: bundleName]];
  28.180 -        
  28.181 -        if (!bundleObj)
  28.182 -            return nil;
  28.183 -        
  28.184 -        NSString *sourcePath =[[bundleObj resourcePath] stringByAppendingPathComponent: fileName];
  28.185 -        
  28.186 -        NSError *error;
  28.187 -        [[NSFileManager defaultManager]
  28.188 -         copyItemAtPath:sourcePath toPath:destinationPath error:&error];
  28.189 -        
  28.190 -        // Check if any error occurred during copying and display it.
  28.191 -        if (error != nil) {
  28.192 -            NSLog(@"%@", [error localizedDescription]);
  28.193 -            return nil;
  28.194 -        }
  28.195 -    }
  28.196 -    NSLog(@"Asset %@ copied into %@", fileName, destinationPath);
  28.197 -    return destinationPath;
  28.198 -}
  28.199 -
  28.200 -+ (void)setupTrustWordsDB:(NSBundle *)rootBundle{
  28.201 -    NSString *systemDBPath = [PEPObjCAdapter copyAssetIntoDocumentsDirectory:rootBundle
  28.202 -                                                                           :@"pEpTrustWords.bundle"
  28.203 -                                                                           :@"system.db"];
  28.204 -    if (SystemDB) {
  28.205 -        free((void *) SystemDB);
  28.206 -    }
  28.207 -    SystemDB = strdup(systemDBPath.UTF8String);
  28.208 -}
  28.209 -
  28.210 -+ (void)setupTrustWordsDB
  28.211 -{
  28.212 -    [PEPObjCAdapter setupTrustWordsDB:[NSBundle mainBundle]];
  28.213 -}
  28.214 -
  28.215 -static NSMutableArray* boundSessions = nil;
  28.216 -
  28.217 -+ (NSMutableArray*)boundSessions
  28.218 -{
  28.219 -    static dispatch_once_t once;
  28.220 -    dispatch_once(&once, ^{
  28.221 -        boundSessions =  [[NSMutableArray alloc] init];
  28.222 -    });
  28.223 -    return boundSessions;
  28.224 -}
  28.225 -
  28.226 -///////////////////////////////////////////////////////////////////////////////
  28.227 -//  Keyserver and Identity lookup - ObjC part
  28.228 -
  28.229 -static PEPQueue *lookupQueue = nil;
  28.230 -static NSThread *lookupThread = nil;
  28.231 -static NSConditionLock *lookupThreadJoinCond = nil;
  28.232 -
  28.233 -+ (void)lookupThreadRoutine:(id)object
  28.234 -{
  28.235 -    [lookupThreadJoinCond lock];
  28.236 -
  28.237 -    // FIXME: do_KeyManagement asserts if management is null.
  28.238 -    do_keymanagement(retrieve_next_identity, "NOTNULL" /* (__bridge void *)queue */);
  28.239 -    
  28.240 -    // Set and signal join()
  28.241 -    [lookupThreadJoinCond unlockWithCondition:YES];
  28.242 -}
  28.243 -
  28.244 -+ (void)startKeyserverLookup
  28.245 -{
  28.246 -    if (!lookupQueue)
  28.247 -    {
  28.248 -        lookupQueue = [[PEPQueue alloc]init];
  28.249 -        
  28.250 -        // There is no join() call on NSThreads.
  28.251 -        lookupThreadJoinCond = [[NSConditionLock alloc] initWithCondition:NO];
  28.252 -        
  28.253 -        lookupThread = [[NSThread alloc] initWithTarget:self selector:@selector(lookupThreadRoutine:) object:nil];
  28.254 -        [lookupThread start];
  28.255 -    }
  28.256 -}
  28.257 -
  28.258 -+ (void)stopKeyserverLookup
  28.259 -{
  28.260 -    
  28.261 -    if (lookupQueue)
  28.262 -    {
  28.263 -        // Flush queue and kick the consumer
  28.264 -        [lookupQueue kill];
  28.265 -        
  28.266 -        // Thread then bailout. Wait for that.
  28.267 -        [lookupThreadJoinCond lockWhenCondition:YES];
  28.268 -        [lookupThreadJoinCond unlock];
  28.269 -        
  28.270 -        lookupThread = nil;
  28.271 -        lookupQueue = nil;
  28.272 -        lookupThreadJoinCond = nil;
  28.273 -    }
  28.274 -}
  28.275 -
  28.276 -+ (void)registerExamineFunction:(PEP_SESSION)session
  28.277 -{
  28.278 -    register_examine_function(session, examine_identity, NULL /* (__bridge void *)queue */);
  28.279 -}
  28.280 -
  28.281 -+ (PEPQueue*)getLookupQueue
  28.282 -{
  28.283 -    return lookupQueue;
  28.284 -}
  28.285 -
  28.286 -///////////////////////////////////////////////////////////////////////////////
  28.287 -// Sync - ObjC part
  28.288 -
  28.289 -static PEPQueue *syncQueue = nil;
  28.290 -static NSThread *syncThread = nil;
  28.291 -static NSConditionLock *syncThreadJoinCond = nil;
  28.292 -static PEP_SESSION sync_session = NULL;
  28.293 -static id <PEPSyncDelegate> syncDelegate = nil;
  28.294 -
  28.295 -
  28.296 -+ (void)syncThreadRoutine:(id)object
  28.297 -{
  28.298 -    [syncThreadJoinCond lock];
  28.299 -    
  28.300 -    PEP_STATUS status = init(&sync_session);
  28.301 -    if (status != PEP_STATUS_OK) {
  28.302 -        return;
  28.303 -    }
  28.304 -    
  28.305 -    register_sync_callbacks(sync_session,
  28.306 -                             /* "management" : queuing (unused) */
  28.307 -                            "NOTNULL",
  28.308 -                            message_to_send,
  28.309 -                            notify_handshake,
  28.310 -                            inject_sync_msg,
  28.311 -                            retrieve_next_sync_msg);
  28.312 -
  28.313 -    status = do_sync_protocol(sync_session,
  28.314 -                              /* "object" : notifying, sending (unused) */
  28.315 -                              "NOTNULL");
  28.316 -    
  28.317 -    // TODO : detach all attached sessions
  28.318 -    
  28.319 -    release(sync_session);
  28.320 -    
  28.321 -    [syncThreadJoinCond unlockWithCondition:YES];
  28.322 -}
  28.323 -
  28.324 -+ (void)attachSyncSession:(PEP_SESSION)session
  28.325 -{
  28.326 -    if(sync_session)
  28.327 -        attach_sync_session(session, sync_session);
  28.328 -}
  28.329 -
  28.330 -+ (void)detachSyncSession:(PEP_SESSION)session
  28.331 -{
  28.332 -    detach_sync_session(session);
  28.333 -}
  28.334 -
  28.335 -+ (void)startSync:(id <PEPSyncDelegate>)delegate;
  28.336 -{
  28.337 -    syncDelegate = delegate;
  28.338 -    
  28.339 -    if (!syncQueue)
  28.340 -    {
  28.341 -        syncQueue = [[PEPQueue alloc]init];
  28.342 -        
  28.343 -        syncThreadJoinCond = [[NSConditionLock alloc] initWithCondition:NO];
  28.344 -        
  28.345 -        syncThread = [[NSThread alloc]
  28.346 -                      initWithTarget:self
  28.347 -                      selector:@selector(syncThreadRoutine:)
  28.348 -                      object:nil];
  28.349 -
  28.350 -        [syncThread start];
  28.351 -    }
  28.352 -
  28.353 -    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
  28.354 -    PEPSession* session;
  28.355 -    @synchronized (sessionList) {
  28.356 -        for (session in sessionList) {
  28.357 -            [PEPObjCAdapter attachSyncSession:[session session]];
  28.358 -        }
  28.359 -    }
  28.360 -}
  28.361 -
  28.362 -+ (void)stopSync
  28.363 -{
  28.364 -    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
  28.365 -    PEPSession* session;
  28.366 -    @synchronized (sessionList) {
  28.367 -        for (session in sessionList) {
  28.368 -            [PEPObjCAdapter detachSyncSession:[session session]];
  28.369 -        }
  28.370 -    }
  28.371 -    
  28.372 -    syncDelegate = nil;
  28.373 -    
  28.374 -    if (syncQueue)
  28.375 -    {
  28.376 -        // FIXME : memory leak ! unallocate sync message waiting in the queue
  28.377 -        
  28.378 -        [syncQueue kill];
  28.379 -        
  28.380 -        [syncThreadJoinCond lockWhenCondition:YES];
  28.381 -        [syncThreadJoinCond unlock];
  28.382 -        
  28.383 -        syncThread = nil;
  28.384 -        syncQueue = nil;
  28.385 -        syncThreadJoinCond = nil;
  28.386 -    }
  28.387 -}
  28.388 -
  28.389 -+ (PEPQueue*)getSyncQueue
  28.390 -{
  28.391 -    return syncQueue;
  28.392 -}
  28.393 -
  28.394 -+ (id <PEPSyncDelegate>)getSyncDelegate
  28.395 -{
  28.396 -    return syncDelegate;
  28.397 -}
  28.398 -
  28.399 -+ (void)bindSession:(PEPSession*)session
  28.400 -{
  28.401 -    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
  28.402 -    @synchronized (sessionList) {
  28.403 -        [sessionList addObject:session];
  28.404 -    }
  28.405 -
  28.406 -    [PEPObjCAdapter registerExamineFunction:[session session]];
  28.407 -    [PEPObjCAdapter attachSyncSession:[session session]];
  28.408 -}
  28.409 -
  28.410 -+ (void)unbindSession:(PEPSession*)session
  28.411 -{
  28.412 -    [PEPObjCAdapter detachSyncSession:[session session]];
  28.413 -    
  28.414 -    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
  28.415 -    @synchronized (sessionList) {
  28.416 -        [sessionList removeObject:session];
  28.417 -    }
  28.418 -
  28.419 -}
  28.420 -
  28.421 -
  28.422 -
  28.423 -@end
    29.1 --- a/pEpiOSAdapter/PEPQueue.h	Wed May 17 08:16:57 2017 +0200
    29.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.3 @@ -1,21 +0,0 @@
    29.4 -//
    29.5 -//  PEPQueue.h
    29.6 -//  pEpiOSAdapter
    29.7 -//
    29.8 -//  Created by Volker Birk on 15.07.15.
    29.9 -//  Copyright (c) 2015 p≡p. All rights reserved.
   29.10 -//
   29.11 -
   29.12 -#import <Foundation/Foundation.h>
   29.13 -
   29.14 -@interface PEPQueue : NSObject
   29.15 -
   29.16 -- (void)enqueue:(id)object;
   29.17 -
   29.18 -- (id)dequeue;
   29.19 -
   29.20 -- (void)kill;
   29.21 -
   29.22 -- (NSUInteger)count;
   29.23 -
   29.24 -@end
    30.1 --- a/pEpiOSAdapter/PEPQueue.m	Wed May 17 08:16:57 2017 +0200
    30.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.3 @@ -1,97 +0,0 @@
    30.4 -//
    30.5 -//  PEPQueue.m
    30.6 -//  pEpiOSAdapter
    30.7 -//
    30.8 -//  Created by Volker Birk on 15.07.15.
    30.9 -//  Copyright (c) 2015 p≡p. All rights reserved.
   30.10 -//
   30.11 -
   30.12 -#import "PEPQueue.h"
   30.13 -
   30.14 -
   30.15 -@interface PEPQueue ()
   30.16 -
   30.17 -@property (nonatomic, strong) NSMutableArray *queue;
   30.18 -@property (nonatomic, strong) NSCondition *cond;
   30.19 -
   30.20 -@end
   30.21 -
   30.22 -@implementation PEPQueue
   30.23 -
   30.24 -- (id)init
   30.25 -{
   30.26 -    self = [super init];
   30.27 -    
   30.28 -    if (self)
   30.29 -    {
   30.30 -        self.queue = [[NSMutableArray alloc] init];
   30.31 -        self.cond = [[NSCondition alloc] init];
   30.32 -    }
   30.33 -    
   30.34 -    return self;
   30.35 -}
   30.36 -
   30.37 -- (void)enqueue:(id)object
   30.38 -{
   30.39 -
   30.40 -    @synchronized(self) {
   30.41 -        if (_queue)
   30.42 -            [_queue insertObject:object atIndex:0];
   30.43 -    }
   30.44 -    
   30.45 -    [_cond signal];
   30.46 -    
   30.47 -}
   30.48 -
   30.49 -- (BOOL)condwait
   30.50 -{
   30.51 -    BOOL res;
   30.52 -    @synchronized(self) {
   30.53 -        res = _queue && _queue.count == 0;
   30.54 -    }
   30.55 -    return res;
   30.56 -}
   30.57 -
   30.58 -- (id)dequeue
   30.59 -{
   30.60 -    id tmp = nil;
   30.61 -    
   30.62 -    [_cond lock];
   30.63 -    
   30.64 -    while ([self condwait])
   30.65 -    {
   30.66 -        [_cond wait];
   30.67 -    }
   30.68 -    
   30.69 -    @synchronized(self) {
   30.70 -        if (_queue)
   30.71 -        {
   30.72 -            tmp = [_queue lastObject];
   30.73 -            
   30.74 -            [_queue removeLastObject];
   30.75 -        }
   30.76 -    }
   30.77 -    [_cond unlock];
   30.78 -    
   30.79 -    return tmp;
   30.80 -}
   30.81 -
   30.82 -- (void)kill
   30.83 -{
   30.84 -    _queue = nil;
   30.85 -    
   30.86 -    [_cond signal];
   30.87 -}
   30.88 -
   30.89 -- (NSUInteger)count
   30.90 -{
   30.91 -    return [_queue count];
   30.92 -}
   30.93 -
   30.94 -- (void)dealloc
   30.95 -{
   30.96 -    self.queue = nil;
   30.97 -    self.cond = nil;
   30.98 -}
   30.99 -
  30.100 -@end
  30.101 \ No newline at end of file
    31.1 --- a/pEpiOSAdapter/PEPSession+Internal.h	Wed May 17 08:16:57 2017 +0200
    31.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.3 @@ -1,18 +0,0 @@
    31.4 -//
    31.5 -//  PEPSession+Internal.h
    31.6 -//  pEpiOSAdapter
    31.7 -//
    31.8 -//  Created by Edouard Tisserant on 16.05.17.
    31.9 -//  Copyright © 2017 p≡p. All rights reserved.
   31.10 -//
   31.11 -
   31.12 -#ifndef PEPSession_internal_h
   31.13 -#define PEPSession_internal_h
   31.14 -
   31.15 -@interface PEPSession ()
   31.16 -
   31.17 -@property (nonatomic) PEP_SESSION session;
   31.18 -
   31.19 -@end
   31.20 -
   31.21 -#endif /* PEPSession_internal_h */
    32.1 --- a/pEpiOSAdapter/PEPSession.h	Wed May 17 08:16:57 2017 +0200
    32.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.3 @@ -1,137 +0,0 @@
    32.4 -//
    32.5 -//  PEPSession.h
    32.6 -//  pEpiOSAdapter
    32.7 -//
    32.8 -//  Created by Volker Birk on 08.07.15.
    32.9 -//  Copyright (c) 2015 p≡p. All rights reserved.
   32.10 -//
   32.11 -
   32.12 -#import <Foundation/Foundation.h>
   32.13 -
   32.14 -#import "PEPObjCAdapter.h"
   32.15 -#import "PEPMessage.h"
   32.16 -
   32.17 -@class PEPSession;
   32.18 -@class PEPLanguage;
   32.19 -
   32.20 -/** Callback type for doing something with a session */
   32.21 -typedef void (^PEPSessionBlock)(PEPSession * _Nonnull session);
   32.22 -
   32.23 -@interface PEPSession : NSObject
   32.24 -
   32.25 -#pragma mark -- Public API
   32.26 -
   32.27 -+ (nonnull PEPSession *)session;
   32.28 -
   32.29 -/**
   32.30 - Execute a block concurrently on a session.
   32.31 - The session is created solely for execution of the block.
   32.32 - */
   32.33 -+ (void)dispatchAsyncOnSession:(nonnull PEPSessionBlock)block;
   32.34 -
   32.35 -/**
   32.36 - Execute a block on a session and wait for it.
   32.37 - The session is created solely for execution of the block.
   32.38 - */
   32.39 -+ (void)dispatchSyncOnSession:(nonnull PEPSessionBlock)block;
   32.40 -
   32.41 -/** Decrypt a message */
   32.42 -- (PEP_rating)decryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
   32.43 -                            dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst
   32.44 -                            keys:(NSArray<NSString *> * _Nullable * _Nullable)keys;
   32.45 -
   32.46 -/** Encrypt a message */
   32.47 -- (PEP_STATUS)encryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
   32.48 -                           extra:(nullable NSArray<NSString *> *)keys
   32.49 -                            dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst;
   32.50 -
   32.51 -/** Encrypt a message for the given identity, which is usually a mySelf identity */
   32.52 -- (PEP_STATUS)encryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
   32.53 -                        identity:(nonnull NSDictionary<NSString *, id> *)identity
   32.54 -                            dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst;
   32.55 -
   32.56 -/** Determine the status color of a message to be sent */
   32.57 -- (PEP_rating)outgoingMessageColor:(nonnull NSDictionary<NSString *, id> *)msg;
   32.58 -
   32.59 -/** Determine the rating of an identity */
   32.60 -- (PEP_rating)identityRating:(nonnull NSDictionary<NSString *, id> *)identity;
   32.61 -
   32.62 -/** Get trustwords for a fingerprint */
   32.63 -- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
   32.64 -                      shortened:(BOOL)shortened;
   32.65 -
   32.66 -/**
   32.67 - Supply an account used by our user himself. The identity is supplemented with the missing parts
   32.68 -
   32.69 - An identity is a `NSDictionary` mapping a field name as `NSString` to different values.
   32.70 - An identity can have the following fields (all other keys are ignored).
   32.71 - It is not necessary to supply all fields; missing fields are supplemented by p≡p engine.
   32.72 - 
   32.73 - @"username": real name or nick name (if pseudonymous) of identity
   32.74 - @"address": URI or SMTP address
   32.75 - @"user_id": persistent unique ID for identity
   32.76 - @"lang": preferred languageID for communication with this ID (default: @"en")
   32.77 - @"fpr": fingerprint of key to use for communication with this ID
   32.78 - @"comm_type": communication type code (usually not needed)
   32.79 - @"me": YES if this is an identity of our user, NO if it is one of a communication partner (default: NO)
   32.80 - 
   32.81 - As an example:
   32.82 - 
   32.83 - User has a mailbox. The mail address is "Dipul Khatri <dipul@inboxcube.com>". Then this would be:
   32.84 - 
   32.85 - NSDictionary *ident = [NSDictionary dictionaryWithObjectsAndKeys:
   32.86 - @"Dipul Khatri", @"username", @"dipul@inboxcube.com", @"address", 
   32.87 - @"23", @"user_id", nil];
   32.88 - 
   32.89 -*/
   32.90 -- (void)mySelf:(nonnull NSMutableDictionary<NSString *, id> *)identity;
   32.91 -
   32.92 -/**
   32.93 - Supplement missing information for an arbitrary identity (used for communication partners).
   32.94 - See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
   32.95 - */
   32.96 -- (void)updateIdentity:(nonnull NSMutableDictionary<NSString *, id> *)identity;
   32.97 -
   32.98 -/**
   32.99 - Mark a key as trusted with a person.
  32.100 - See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
  32.101 - */
  32.102 -- (void)trustPersonalKey:(nonnull NSMutableDictionary<NSString *, id> *)identity;
  32.103 -
  32.104 -/**
  32.105 - if a key is not trusted by the user tell this using this message
  32.106 - See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
  32.107 - */
  32.108 -- (void)keyMistrusted:(nonnull NSMutableDictionary<NSString *, id> *)identity;
  32.109 -
  32.110 -/**
  32.111 - Use this to undo keyCompromized or trustPersonalKey
  32.112 - See `mySelf:(NSMutableDictionary *)identity` for an explanation of identities.
  32.113 -*/
  32.114 -- (void)keyResetTrust:(nonnull NSMutableDictionary<NSString *, id> *)identity;
  32.115 -
  32.116 -#pragma mark -- Internal API (testing etc.)
  32.117 -
  32.118 -/** For testing purpose, manual key import */
  32.119 -- (void)importKey:(nonnull NSString *)keydata;
  32.120 -
  32.121 -- (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
  32.122 -     description:(nullable NSString *)description comment:(nullable NSString *)comment;
  32.123 -
  32.124 -/**
  32.125 - Retrieves the log from the engine.
  32.126 - */
  32.127 -- (nonnull NSString *)getLog;
  32.128 -
  32.129 -/** Determine trustwords for two identities */
  32.130 -- (nullable NSString *)getTrustwordsIdentity1:(nonnull NSDictionary<NSString *, id> *)identity1
  32.131 -                                    identity2:(nonnull NSDictionary<NSString *, id> *)identity2
  32.132 -                                     language:(nullable NSString *)language
  32.133 -                                         full:(BOOL)full;
  32.134 -
  32.135 -/**
  32.136 - @returns The list of supported languages for trustwords.
  32.137 - */
  32.138 -- (NSArray<PEPLanguage *> * _Nonnull)languageList;
  32.139 -
  32.140 -@end
    33.1 --- a/pEpiOSAdapter/PEPSession.m	Wed May 17 08:16:57 2017 +0200
    33.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.3 @@ -1,417 +0,0 @@
    33.4 -//
    33.5 -//  PEPSession.m
    33.6 -//  pEpiOSAdapter
    33.7 -//
    33.8 -//  Created by Volker Birk on 08.07.15.
    33.9 -//  Copyright (c) 2015 p≡p. All rights reserved.
   33.10 -//
   33.11 -
   33.12 -#import "PEPSession.h"
   33.13 -#import "PEPSession+Internal.h"
   33.14 -#import "PEPObjCAdapter.h"
   33.15 -#import "PEPObjCAdapter+Internal.h"
   33.16 -#import "PEPMessage.h"
   33.17 -#import "PEPLanguage.h"
   33.18 -#import "PEPCSVScanner.h"
   33.19 -#import "NSArray+Extension.h"
   33.20 -
   33.21 -@implementation PEPSession
   33.22 -
   33.23 -// serialize all session access
   33.24 -+ (dispatch_queue_t)sharedSessionQueue
   33.25 -{
   33.26 -    static dispatch_once_t once;
   33.27 -    static dispatch_queue_t sharedSessionQueue;
   33.28 -    dispatch_once(&once, ^{
   33.29 -        sharedSessionQueue = dispatch_queue_create("pEp session queue", DISPATCH_QUEUE_CONCURRENT);
   33.30 -    });
   33.31 -    return sharedSessionQueue;
   33.32 -}
   33.33 -
   33.34 -+ (PEPSession *)session
   33.35 -{
   33.36 -    PEPSession *_session = [[PEPSession alloc] init];
   33.37 -    return _session;
   33.38 -}
   33.39 -
   33.40 -+ (void)dispatchAsyncOnSession:(PEPSessionBlock)block
   33.41 -{
   33.42 -    dispatch_async([self sharedSessionQueue], ^{
   33.43 -        PEPSession *pepSession = [[PEPSession alloc] init];
   33.44 -        block(pepSession);
   33.45 -    });
   33.46 -}
   33.47 -
   33.48 -+ (void)dispatchSyncOnSession:(PEPSessionBlock)block
   33.49 -{
   33.50 -    PEPSession *pepSession = [[PEPSession alloc] init];
   33.51 -    block(pepSession);
   33.52 -}
   33.53 -
   33.54 -+ (void)setupTrustWordsDB
   33.55 -{
   33.56 -    static dispatch_once_t once;
   33.57 -    dispatch_once(&once, ^{
   33.58 -        [PEPObjCAdapter setupTrustWordsDB:[NSBundle bundleForClass:[self class]]];
   33.59 -    });
   33.60 -}
   33.61 -
   33.62 -- (id)init
   33.63 -{
   33.64 -    [PEPSession setupTrustWordsDB];
   33.65 -
   33.66 -    PEP_STATUS status = init(&_session);
   33.67 -
   33.68 -    if (status != PEP_STATUS_OK) {
   33.69 -        return nil;
   33.70 -    }
   33.71 -
   33.72 -    [PEPObjCAdapter bindSession:self];
   33.73 -    
   33.74 -    return self;
   33.75 -}
   33.76 -
   33.77 -- (void)dealloc
   33.78 -{
   33.79 -    [PEPObjCAdapter unbindSession:self];
   33.80 -    
   33.81 -    release(_session);
   33.82 -}
   33.83 -
   33.84 -- (PEP_rating)decryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
   33.85 -                            dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst
   33.86 -                            keys:(NSArray<NSString *> * _Nullable * _Nullable)keys
   33.87 -{
   33.88 -    message * _src = PEP_messageDictToStruct(src);
   33.89 -    message * _dst = NULL;
   33.90 -    stringlist_t * _keys = NULL;
   33.91 -    PEP_rating color = PEP_rating_undefined;
   33.92 -    PEP_decrypt_flags_t flags = 0;
   33.93 -
   33.94 -    @synchronized (self) {
   33.95 -        decrypt_message(_session, _src, &_dst, &_keys, &color, &flags);
   33.96 -    }
   33.97 -
   33.98 -    NSDictionary * dst_;
   33.99 -
  33.100 -    if (_dst) {
  33.101 -        dst_ = PEP_messageDictFromStruct(_dst);
  33.102 -    }
  33.103 -    else {
  33.104 -        dst_ = PEP_messageDictFromStruct(_src);
  33.105 -    }
  33.106 -
  33.107 -    NSArray * keys_ = nil;
  33.108 -    if (_keys)
  33.109 -        keys_ = PEP_arrayFromStringlist(_keys);
  33.110 -
  33.111 -    free_message(_src);
  33.112 -    free_message(_dst);
  33.113 -    free_stringlist(_keys);
  33.114 -
  33.115 -    if (dst) {
  33.116 -        *dst = dst_;
  33.117 -    }
  33.118 -    if (keys) {
  33.119 -        *keys = keys_;
  33.120 -    }
  33.121 -    return color;
  33.122 -}
  33.123 -
  33.124 -- (void)removeEmptyArrayKey:(NSString *)key inDict:(NSMutableDictionary<NSString *, id> *)dict
  33.125 -{
  33.126 -    if ([[dict objectForKey:key] count] == 0) {
  33.127 -        [dict removeObjectForKey:key];
  33.128 -    }
  33.129 -}
  33.130 -
  33.131 -- (NSDictionary *)removeEmptyRecipients:(NSDictionary<NSString *, id> *)src
  33.132 -{
  33.133 -    NSMutableDictionary *dest = src.mutableCopy;
  33.134 -
  33.135 -    [self removeEmptyArrayKey:kPepTo inDict:dest];
  33.136 -    [self removeEmptyArrayKey:kPepCC inDict:dest];
  33.137 -    [self removeEmptyArrayKey:kPepBCC inDict:dest];
  33.138 -
  33.139 -    return [NSDictionary dictionaryWithDictionary:dest];
  33.140 -}
  33.141 -
  33.142 -- (PEP_STATUS)encryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
  33.143 -                           extra:(nullable NSArray *)keys
  33.144 -                            dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst
  33.145 -{
  33.146 -    PEP_STATUS status;
  33.147 -    PEP_encrypt_flags_t flags = 0;
  33.148 -
  33.149 -    message * _src = PEP_messageDictToStruct([self removeEmptyRecipients:src]);
  33.150 -    message * _dst = NULL;
  33.151 -    stringlist_t * _keys = PEP_arrayToStringlist(keys);
  33.152 -
  33.153 -    @synchronized (self) {
  33.154 -        status = encrypt_message(_session, _src, _keys, &_dst, PEP_enc_PGP_MIME, flags);
  33.155 -    }
  33.156 -
  33.157 -    NSDictionary * dst_;
  33.158 -
  33.159 -    if (_dst) {
  33.160 -        dst_ = PEP_messageDictFromStruct(_dst);
  33.161 -    }
  33.162 -    else {
  33.163 -        dst_ = PEP_messageDictFromStruct(_src);
  33.164 -    }
  33.165 -    if (dst) {
  33.166 -        *dst = dst_;
  33.167 -    }
  33.168 -
  33.169 -    free_message(_src);
  33.170 -    free_message(_dst);
  33.171 -    free_stringlist(_keys);
  33.172 -    
  33.173 -    return status;
  33.174 -}
  33.175 -
  33.176 -- (PEP_STATUS)encryptMessageDict:(nonnull NSDictionary<NSString *, id> *)src
  33.177 -                        identity:(nonnull NSDictionary<NSString *, id> *)identity
  33.178 -                            dest:(NSDictionary<NSString *, id> * _Nullable * _Nullable)dst
  33.179 -{
  33.180 -    PEP_STATUS status;
  33.181 -    PEP_encrypt_flags_t flags = 0;
  33.182 -
  33.183 -    message * _src = PEP_messageDictToStruct([self removeEmptyRecipients:src]);
  33.184 -    pEp_identity *ident = PEP_identityDictToStruct(identity);
  33.185 -    message * _dst = NULL;
  33.186 -
  33.187 -    @synchronized (self) {
  33.188 -        status = encrypt_message_for_self(_session, ident, _src, &_dst, PEP_enc_PGP_MIME, flags);
  33.189 -    }
  33.190 -
  33.191 -    NSDictionary * dst_;
  33.192 -
  33.193 -    if (_dst) {
  33.194 -        dst_ = PEP_messageDictFromStruct(_dst);
  33.195 -    }
  33.196 -    else {
  33.197 -        dst_ = PEP_messageDictFromStruct(_src);
  33.198 -    }
  33.199 -
  33.200 -    if (dst) {
  33.201 -        *dst = dst_;
  33.202 -    }
  33.203 -
  33.204 -    free_message(_src);
  33.205 -    free_message(_dst);
  33.206 -    free_identity(ident);
  33.207 -
  33.208 -    return status;
  33.209 -}
  33.210 -
  33.211 -- (PEP_rating)outgoingMessageColor:(NSDictionary<NSString *, id> *)msg
  33.212 -{
  33.213 -    message * _msg = PEP_messageDictToStruct(msg);
  33.214 -    PEP_rating color = PEP_rating_undefined;
  33.215 -
  33.216 -    @synchronized (self) {
  33.217 -        outgoing_message_rating(_session, _msg, &color);
  33.218 -    }
  33.219 -
  33.220 -    free_message(_msg);
  33.221 -    
  33.222 -    return color;
  33.223 -}
  33.224 -
  33.225 -- (PEP_rating)identityRating:(nonnull NSDictionary<NSString *, id> *)identity
  33.226 -{
  33.227 -    pEp_identity *ident = PEP_identityDictToStruct(identity);
  33.228 -    PEP_rating color = PEP_rating_undefined;
  33.229 -    
  33.230 -    @synchronized (self) {
  33.231 -        identity_rating(_session, ident, &color);
  33.232 -    }
  33.233 -    
  33.234 -    free_identity(ident);
  33.235 -    
  33.236 -    return color;
  33.237 -}
  33.238 -
  33.239 -DYNAMIC_API PEP_STATUS identity_rating(
  33.240 -                                      PEP_SESSION session,
  33.241 -                                      pEp_identity *ident,
  33.242 -                                      PEP_rating *color
  33.243 -                                      );
  33.244 -
  33.245 -
  33.246 -- (NSArray *)trustwords:(NSString *)fpr forLanguage:(NSString *)languageID shortened:(BOOL)shortened
  33.247 -{
  33.248 -    NSMutableArray *array = [NSMutableArray array];
  33.249 -
  33.250 -    for (int i = 0; i < [fpr length]; i += 4) {
  33.251 -        if (shortened && i >= 20)
  33.252 -            break;
  33.253 -        
  33.254 -        NSString *str = [fpr substringWithRange:NSMakeRange(i, 4)];
  33.255 -
  33.256 -        unsigned int value;
  33.257 -        [[NSScanner scannerWithString:str] scanHexInt:&value];
  33.258 -        
  33.259 -        char *word;
  33.260 -        size_t size;
  33.261 -
  33.262 -        @synchronized (self) {
  33.263 -            trustword(_session, value, [languageID UTF8String], &word, &size);
  33.264 -        }
  33.265 -
  33.266 -        [array addObject:[NSString stringWithUTF8String:word]];
  33.267 -        free(word);
  33.268 -    }
  33.269 -    
  33.270 -    return array;
  33.271 -}
  33.272 -
  33.273 -- (void)mySelf:(NSMutableDictionary<NSString *, id> *)identity
  33.274 -{
  33.275 -    [identity removeObjectForKey:kPepUserID];
  33.276 -
  33.277 -    pEp_identity *ident = PEP_identityDictToStruct(identity);
  33.278 -
  33.279 -    @synchronized(self) {
  33.280 -        myself(_session, ident);
  33.281 -    }
  33.282 -
  33.283 -    [identity setValuesForKeysWithDictionary:PEP_identityDictFromStruct(ident)];
  33.284 -    free_identity(ident);
  33.285 -}
  33.286 -
  33.287 -- (void)updateIdentity:(NSMutableDictionary<NSString *, id> *)identity
  33.288 -{
  33.289 -    pEp_identity *ident = PEP_identityDictToStruct(identity);
  33.290 -
  33.291 -    @synchronized(self) {
  33.292 -        update_identity(_session, ident);
  33.293 -    }
  33.294 -
  33.295 -    [identity setValuesForKeysWithDictionary:PEP_identityDictFromStruct(ident)];
  33.296 -    free_identity(ident);
  33.297 -}
  33.298 -
  33.299 -- (void)trustPersonalKey:(NSMutableDictionary<NSString *, id> *)identity
  33.300 -{
  33.301 -    pEp_identity *ident = PEP_identityDictToStruct(identity);
  33.302 -    
  33.303 -    @synchronized(self) {
  33.304 -        trust_personal_key(_session, ident);
  33.305 -    }
  33.306 -    
  33.307 -    [identity setValuesForKeysWithDictionary:PEP_identityDictFromStruct(ident)];
  33.308 -    free_identity(ident);
  33.309 -}
  33.310 -
  33.311 -- (void)keyResetTrust:(NSMutableDictionary<NSString *, id> *)identity
  33.312 -{
  33.313 -    pEp_identity *ident = PEP_identityDictToStruct(identity);
  33.314 -    
  33.315 -    @synchronized(self) {
  33.316 -        key_reset_trust(_session, ident);
  33.317 -    }
  33.318 -    
  33.319 -    [identity setValuesForKeysWithDictionary:PEP_identityDictFromStruct(ident)];
  33.320 -    free_identity(ident);
  33.321 -}
  33.322 -
  33.323 -- (void)keyMistrusted:(NSMutableDictionary<NSString *, id> *)identity
  33.324 -{
  33.325 -    pEp_identity *ident = PEP_identityDictToStruct(identity);
  33.326 -    
  33.327 -    @synchronized(self) {
  33.328 -        key_mistrusted(_session, ident);
  33.329 -    }
  33.330 -    
  33.331 -    [identity setValuesForKeysWithDictionary:PEP_identityDictFromStruct(ident)];
  33.332 -    free_identity(ident);
  33.333 -}
  33.334 -
  33.335 -- (void)importKey:(NSString *)keydata
  33.336 -{
  33.337 -    @synchronized(self) {
  33.338 -        import_key(_session, [keydata UTF8String], [keydata length], NULL);
  33.339 -    }
  33.340 -
  33.341 -}
  33.342 -
  33.343 -- (void)logTitle:(nonnull NSString *)title entity:(nonnull NSString *)entity
  33.344 -     description:(nullable NSString *)description comment:(nullable NSString *)comment
  33.345 -{
  33.346 -    log_event(self.session, [[title precomposedStringWithCanonicalMapping] UTF8String],
  33.347 -              [[entity precomposedStringWithCanonicalMapping] UTF8String],
  33.348 -              [[description precomposedStringWithCanonicalMapping] UTF8String],
  33.349 -              [[comment precomposedStringWithCanonicalMapping] UTF8String]);
  33.350 -}
  33.351 -
  33.352 -- (nonnull NSString *)getLog
  33.353 -{
  33.354 -    char *data;
  33.355 -    get_crashdump_log(self.session, 0, &data);
  33.356 -    NSString *logString = [NSString stringWithUTF8String:data];
  33.357 -    return logString;
  33.358 -}
  33.359 -
  33.360 -- (nullable NSString *)getTrustwordsIdentity1:(nonnull NSDictionary<NSString *, id> *)identity1
  33.361 -                                    identity2:(nonnull NSDictionary<NSString *, id> *)identity2
  33.362 -                                     language:(nullable NSString *)language
  33.363 -                                         full:(BOOL)full
  33.364 -{
  33.365 -    NSString *result = nil;
  33.366 -    char *trustwords = nil;
  33.367 -    size_t sizeWritten = 0;
  33.368 -
  33.369 -    pEp_identity *ident1 = PEP_identityDictToStruct(identity1);
  33.370 -    pEp_identity *ident2 = PEP_identityDictToStruct(identity2);
  33.371 -    PEP_STATUS status =  get_trustwords(_session, ident1, ident2,
  33.372 -                                        [[language precomposedStringWithCanonicalMapping]
  33.373 -                                         UTF8String],
  33.374 -                                        &trustwords, &sizeWritten, full);
  33.375 -    if (status == PEP_STATUS_OK) {
  33.376 -        result = [NSString stringWithCString:trustwords
  33.377 -                                    encoding:NSUTF8StringEncoding];
  33.378 -    }
  33.379 -    if (trustwords) {
  33.380 -        free(trustwords);
  33.381 -    }
  33.382 -    return result;
  33.383 -}
  33.384 -
  33.385 -- (NSArray<PEPLanguage *> * _Nonnull)languageList
  33.386 -{
  33.387 -    char *chLangs;
  33.388 -    get_languagelist(self.session, &chLangs);
  33.389 -    NSString *parserInput = [NSString stringWithUTF8String:chLangs];
  33.390 -
  33.391 -    NSMutableArray<NSString *> *tokens = [NSMutableArray array];
  33.392 -    PEPCSVScanner *scanner = [[PEPCSVScanner alloc] initWithString:parserInput];
  33.393 -    while (YES) {
  33.394 -        NSString *token = [scanner nextString];
  33.395 -        if (!token) {
  33.396 -            break;
  33.397 -        }
  33.398 -        [tokens addObject:token];
  33.399 -    }
  33.400 -
  33.401 -    NSArray *theTokens = [NSArray arrayWithArray:tokens];
  33.402 -    NSMutableArray<PEPLanguage *> *langs = [NSMutableArray new];
  33.403 -    while (YES) {
  33.404 -        ArrayTake *take = [theTokens takeOrNil:3];
  33.405 -        if (!take) {
  33.406 -            break;
  33.407 -        }
  33.408 -        NSArray *elements = take.elements;
  33.409 -        PEPLanguage *lang = [[PEPLanguage alloc]
  33.410 -                             initWithCode:[elements objectAtIndex:0]
  33.411 -                             name:[elements objectAtIndex:1]
  33.412 -                             sentence:[elements objectAtIndex:2]];
  33.413 -        [langs addObject:lang];
  33.414 -        theTokens = take.rest;
  33.415 -    }
  33.416 -
  33.417 -    return [NSArray arrayWithArray:langs];
  33.418 -}
  33.419 -
  33.420 -@end