Make the pEp Engine keysync branch compile on Windows again. keysync-windows
authorMarkus Schaber <markus@pep-security.net>
Fri, 30 Sep 2016 21:16:56 +0200
branchkeysync-windows
changeset 1226a4e082c43cdd
parent 1225 01568160d98c
child 1227 633e90f0e2f2
Make the pEp Engine keysync branch compile on Windows again.

Warning: The changes are not yet tested. Especially the ones in platform_unix.*.
pEpEngine.vcxproj
pEpEngine.vcxproj.filters
src/platform_unix.c
src/platform_unix.h
src/platform_windows.cpp
src/platform_windows.h
src/sync_impl.c
     1.1 --- a/pEpEngine.vcxproj	Fri Sep 30 21:15:32 2016 +0200
     1.2 +++ b/pEpEngine.vcxproj	Fri Sep 30 21:16:56 2016 +0200
     1.3 @@ -65,7 +65,7 @@
     1.4      <Link>
     1.5        <SubSystem>Windows</SubSystem>
     1.6        <GenerateDebugInformation>true</GenerateDebugInformation>
     1.7 -      <AdditionalDependencies>$(TargetDir)\pEpEngineASN1.lib;%(AdditionalDependencies)</AdditionalDependencies>
     1.8 +      <AdditionalDependencies>$(TargetDir)\pEpEngineASN1.lib;Rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
     1.9      </Link>
    1.10      <PreBuildEvent>
    1.11        <Command>
    1.12 @@ -84,13 +84,15 @@
    1.13        <TreatWarningAsError>false</TreatWarningAsError>
    1.14        <AdditionalIncludeDirectories>C:\Users\vb\share\asn1c;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    1.15        <CompileAs>Default</CompileAs>
    1.16 +      <MultiProcessorCompilation>true</MultiProcessorCompilation>
    1.17 +      <ControlFlowGuard>Guard</ControlFlowGuard>
    1.18      </ClCompile>
    1.19      <Link>
    1.20        <SubSystem>Windows</SubSystem>
    1.21        <GenerateDebugInformation>true</GenerateDebugInformation>
    1.22        <EnableCOMDATFolding>true</EnableCOMDATFolding>
    1.23        <OptimizeReferences>true</OptimizeReferences>
    1.24 -      <AdditionalDependencies>$(TargetDir)\pEpEngineASN1.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.25 +      <AdditionalDependencies>$(TargetDir)\pEpEngineASN1.lib;Rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.26      </Link>
    1.27      <PreBuildEvent>
    1.28        <Command>
    1.29 @@ -98,6 +100,7 @@
    1.30      </PreBuildEvent>
    1.31    </ItemDefinitionGroup>
    1.32    <ItemGroup>
    1.33 +    <ClCompile Include="src\asn1_helper.c" />
    1.34      <ClCompile Include="src\baseprotocol.c" />
    1.35      <ClCompile Include="src\blacklist.c" />
    1.36      <ClCompile Include="src\bloblist.c" />
    1.37 @@ -121,12 +124,14 @@
    1.38      <ClCompile Include="src\sync_actions.c" />
    1.39      <ClCompile Include="src\sync_driver.c" />
    1.40      <ClCompile Include="src\sync_fsm.c" />
    1.41 +    <ClCompile Include="src\sync_impl.c" />
    1.42      <ClCompile Include="src\sync_send_actions.c" />
    1.43      <ClCompile Include="src\timestamp.c" />
    1.44      <ClCompile Include="src\transport.c" />
    1.45      <ClCompile Include="src\trans_auto.c" />
    1.46    </ItemGroup>
    1.47    <ItemGroup>
    1.48 +    <ClInclude Include="src\asn1_helper.h" />
    1.49      <ClInclude Include="src\baseprotocol.h" />
    1.50      <ClInclude Include="src\blacklist.h" />
    1.51      <ClInclude Include="src\bloblist.h" />
    1.52 @@ -153,6 +158,7 @@
    1.53      <ClInclude Include="src\stringpair.h" />
    1.54      <ClInclude Include="src\sync.h" />
    1.55      <ClInclude Include="src\sync_fsm.h" />
    1.56 +    <ClInclude Include="src\sync_impl.h" />
    1.57      <ClInclude Include="src\timestamp.h" />
    1.58      <ClInclude Include="src\transport.h" />
    1.59      <ClInclude Include="src\trans_auto.h" />
     2.1 --- a/pEpEngine.vcxproj.filters	Fri Sep 30 21:15:32 2016 +0200
     2.2 +++ b/pEpEngine.vcxproj.filters	Fri Sep 30 21:16:56 2016 +0200
     2.3 @@ -96,6 +96,12 @@
     2.4      <ClCompile Include="src\openpgp_compat.c">
     2.5        <Filter>Quelldateien</Filter>
     2.6      </ClCompile>
     2.7 +    <ClCompile Include="src\asn1_helper.c">
     2.8 +      <Filter>Quelldateien</Filter>
     2.9 +    </ClCompile>
    2.10 +    <ClCompile Include="src\sync_impl.c">
    2.11 +      <Filter>Quelldateien</Filter>
    2.12 +    </ClCompile>
    2.13    </ItemGroup>
    2.14    <ItemGroup>
    2.15      <ClInclude Include="src\keymanagement.h">
    2.16 @@ -188,6 +194,12 @@
    2.17      <ClInclude Include="src\openpgp_compat.h">
    2.18        <Filter>Headerdateien</Filter>
    2.19      </ClInclude>
    2.20 +    <ClInclude Include="src\asn1_helper.h">
    2.21 +      <Filter>Headerdateien</Filter>
    2.22 +    </ClInclude>
    2.23 +    <ClInclude Include="src\sync_impl.h">
    2.24 +      <Filter>Headerdateien</Filter>
    2.25 +    </ClInclude>
    2.26    </ItemGroup>
    2.27    <ItemGroup>
    2.28      <Text Include="LICENSE.txt" />
     3.1 --- a/src/platform_unix.c	Fri Sep 30 21:15:32 2016 +0200
     3.2 +++ b/src/platform_unix.c	Fri Sep 30 21:16:56 2016 +0200
     3.3 @@ -98,7 +98,8 @@
     3.4      return buffer;
     3.5  }
     3.6  
     3.7 -void uuid_generate_random(uuid__t out)
     3.8 +// TODO: Check and possibly fix this function if necessary
     3.9 +void uuid_generate_random(pEpUUID out)
    3.10  {
    3.11      uuid_t *uuid;
    3.12      uuid_rc_t rc_create;
    3.13 @@ -107,7 +108,7 @@
    3.14          uuid_make(uuid, UUID_MAKE_V1) != UUID_RC_OK ||
    3.15          uuid_export(uuid, UUID_FMT_BIN, out, NULL) != UUID_RC_OK)
    3.16      {
    3.17 -        memset(out, 0, sizeof(uuid__t));
    3.18 +        memset(out, 0, sizeof(pEpUUID));
    3.19      }
    3.20  
    3.21      if (rc_create == UUID_RC_OK)
    3.22 @@ -116,7 +117,8 @@
    3.23      }
    3.24  }
    3.25  
    3.26 -void uuid_unparse_upper(uuid__t uu, uuid_string_t out)
    3.27 +// TODO: Check and possibly fix this function if necessary
    3.28 +void uuid_unparse_upper(pEpUUID uu, uuid_string_t out)
    3.29  {
    3.30      uuid_t *uuid;
    3.31      uuid_rc_t rc_create;
     4.1 --- a/src/platform_unix.h	Fri Sep 30 21:15:32 2016 +0200
     4.2 +++ b/src/platform_unix.h	Fri Sep 30 21:16:56 2016 +0200
     4.3 @@ -71,9 +71,11 @@
     4.4  #define UUID uuid_t
     4.5  
     4.6  #ifdef ANDROID
     4.7 -typedef char uuid__t[16];
     4.8 -void uuid_generate_random(uuid__t out);
     4.9 -void uuid_unparse_upper(uuid__t uu, uuid_string_t out);
    4.10 +typedef char pEpUUID[16];
    4.11 +void uuid_generate_random(pEpUUID out);
    4.12 +void uuid_unparse_upper(pEpUUID uu, uuid_string_t out);
    4.13 +#else
    4.14 +typedef uuid_t pEpUUID;
    4.15  #endif
    4.16  
    4.17  #ifdef __cplusplus
     5.1 --- a/src/platform_windows.cpp	Fri Sep 30 21:15:32 2016 +0200
     5.2 +++ b/src/platform_windows.cpp	Fri Sep 30 21:16:56 2016 +0200
     5.3 @@ -267,32 +267,32 @@
     5.4      return _open(pathname, _O_RDWR | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE);
     5.5  }
     5.6  
     5.7 -void uuid_generate_random(uuid_t out)
     5.8 +void uuid_generate_random(pEpUUID out)
     5.9  {
    5.10      RPC_STATUS rpc_status = UuidCreate(out);
    5.11      assert(rpc_status == RPC_S_OK);
    5.12  }
    5.13  
    5.14 -int uuid_parse(char *in, uuid_t uu)
    5.15 +int uuid_parse(char *in, pEpUUID uu)
    5.16  {
    5.17      unsigned char *_in = (unsigned char *) in;
    5.18 -    RPC_STATUS rpc_status = UuidFromString(_in, &uu);
    5.19 +    RPC_STATUS rpc_status = UuidFromStringA(_in, uu);
    5.20      assert(rpc_status == RPC_S_OK);
    5.21      if (rpc_status == RPC_S_INVALID_STRING_UUID)
    5.22          return -1;
    5.23      return 0;
    5.24  }
    5.25  
    5.26 -void uuid_unparse_upper(uuid_t uu, uuid_string_t out)
    5.27 +void uuid_unparse_upper(pEpUUID uu, uuid_string_t out)
    5.28  {
    5.29 -    unsigned char *_out = out;
    5.30 +    unsigned char *_out = (unsigned char*)out;
    5.31      RPC_CSTR str;
    5.32 -    RPC_STATUS rpc_status = UuidToString(uu, &str);
    5.33 +    RPC_STATUS rpc_status = UuidToStringA(uu, &str);
    5.34      assert(rpc_status == RPC_S_OK);
    5.35      if (rpc_status == RPC_S_OK) {
    5.36          memcpy(out, str, 36);
    5.37          out[36] = 0;
    5.38 -        RpcStringFree(str);
    5.39 +        RpcStringFreeA(&str);
    5.40      }
    5.41      else { // if (rpc_status == RPC_S_OUT_OF_MEMORY)
    5.42          memset(out, 0, 37);
     6.1 --- a/src/platform_windows.h	Fri Sep 30 21:15:32 2016 +0200
     6.2 +++ b/src/platform_windows.h	Fri Sep 30 21:16:56 2016 +0200
     6.3 @@ -4,6 +4,14 @@
     6.4  
     6.5  #pragma warning(disable : 4996)
     6.6  
     6.7 +// We need to make sure winsock2 is included before windows.h, or we will get redefinitions of symbols
     6.8 +// as windows.h includes winsock1.h, so we will have duplicate symbols if windows.h is included first.
     6.9 +// It seems some of our code includes sync.h before including winsock.h, leading to the failure.
    6.10 +// Including winsock2.h here fixes the problem for now...
    6.11 +#ifdef WIN32 
    6.12 +#include <winsock2.h>
    6.13 +#endif // WIN32 
    6.14 +
    6.15  #include <Rpc.h>
    6.16  #include <string.h>
    6.17  #include <io.h>
    6.18 @@ -62,13 +70,13 @@
    6.19  long random(void);
    6.20  
    6.21  // on Windoze, uuid_t needs pointer semantics
    6.22 -typedef UUID *uuid_t;
    6.23 +typedef UUID pEpUUID[1];
    6.24  #define _UUID_STRING_T
    6.25  typedef char uuid_string_t[37];
    6.26  
    6.27 -void uuid_generate_random(uuid_t out);
    6.28 -int uuid_parse(char *in, uuid_t uu);
    6.29 -void uuid_unparse_upper(uuid_t uu, uuid_string_t out);
    6.30 +void uuid_generate_random(pEpUUID out);
    6.31 +int uuid_parse(char *in, pEpUUID uu);
    6.32 +void uuid_unparse_upper(pEpUUID uu, uuid_string_t out);
    6.33  
    6.34  #ifndef inline
    6.35  #define inline __inline
     7.1 --- a/src/sync_impl.c	Fri Sep 30 21:15:32 2016 +0200
     7.2 +++ b/src/sync_impl.c	Fri Sep 30 21:16:56 2016 +0200
     7.3 @@ -104,7 +104,9 @@
     7.4      return status;
     7.5  }
     7.6  
     7.7 -DYNAMIC_API void free_sync_msg(sync_msg_t *sync_msg)
     7.8 +// TODO: DYNAMIC_API was here, but broke the windows build. 
     7.9 +// We need to check whether it belongs here or it's a bug.
    7.10 +/* DYNAMIC_API */ void free_sync_msg(sync_msg_t *sync_msg)
    7.11  {
    7.12      assert(sync_msg);
    7.13      if (!(sync_msg))