UUID specifica keysync
authorVolker Birk <vb@pep.foundation>
Sun, 31 Jul 2016 09:01:39 +0200
branchkeysync
changeset 9482c689b7707a9
parent 947 c311bd72af1d
child 949 779219e99833
UUID specifica
src/pEpEngine.c
src/platform_unix.h
src/platform_windows.cpp
src/platform_windows.h
     1.1 --- a/src/pEpEngine.c	Sun Jul 31 00:24:15 2016 +0200
     1.2 +++ b/src/pEpEngine.c	Sun Jul 31 09:01:39 2016 +0200
     1.3 @@ -158,6 +158,7 @@
     1.4  
     1.5          int_result = sqlite3_exec(
     1.6              _session->db,
     1.7 +                "PRAGMA application_id = 0x23423423;\n"
     1.8                  "create table if not exists log (\n"
     1.9                  "   timestamp integer default (datetime('now')) ,\n"
    1.10                  "   title text not null,\n"
    1.11 @@ -260,6 +261,7 @@
    1.12          if (version < 2) {
    1.13              int_result = sqlite3_exec(
    1.14                  _session->db,
    1.15 +                "PRAGMA application_id = 0x23423423;\n"
    1.16                  "alter table pgp_keypair\n"
    1.17                  "   add column flags integer default (0);",
    1.18                  NULL,
     2.1 --- a/src/platform_unix.h	Sun Jul 31 00:24:15 2016 +0200
     2.2 +++ b/src/platform_unix.h	Sun Jul 31 09:01:39 2016 +0200
     2.3 @@ -5,6 +5,7 @@
     2.4  #include <unistd.h>
     2.5  #include <strings.h>
     2.6  #include <sys/select.h>
     2.7 +#include <uuid/uuid.h>
     2.8  
     2.9  #ifdef __cplusplus
    2.10  extern "C" {
    2.11 @@ -45,6 +46,15 @@
    2.12  size_t strlcat(char* dst, const	char* src, size_t size);
    2.13  #endif
    2.14  
    2.15 +#ifndef _UUID_STRING_T
    2.16 +#define _UUID_STRING_T
    2.17 +typedef char uuid_string_t[37];
    2.18 +#endif
    2.19 +#ifdef UUID
    2.20 +// on *nix, uuid_t is an array and already implements pointer semantics
    2.21 +#define UUID uuid_t
    2.22 +#endif
    2.23 +
    2.24  #ifdef __cplusplus
    2.25  }
    2.26  #endif
     3.1 --- a/src/platform_windows.cpp	Sun Jul 31 00:24:15 2016 +0200
     3.2 +++ b/src/platform_windows.cpp	Sun Jul 31 09:01:39 2016 +0200
     3.3 @@ -267,4 +267,36 @@
     3.4      return _open(pathname, _O_RDWR | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE);
     3.5  }
     3.6  
     3.7 +void uuid_generate_random(uuid_t out)
     3.8 +{
     3.9 +    RPC_STATUS rpc_status = UuidCreate(out);
    3.10 +    assert(rpc_status == RPC_S_OK);
    3.11 +}
    3.12 +
    3.13 +int uuid_parse(char *in, uuid_t uu)
    3.14 +{
    3.15 +    unsigned char *_in = (unsigned char *) in;
    3.16 +    RPC_STATUS rpc_status = UuidFromString(_in, &uu);
    3.17 +    assert(rpc_status == RPC_S_OK);
    3.18 +    if (rpc_status == RPC_S_INVALID_STRING_UUID)
    3.19 +        return -1;
    3.20 +    return 0;
    3.21 +}
    3.22 +
    3.23 +void uuid_unparse_upper(uuid_t uu, uuid_string_t out)
    3.24 +{
    3.25 +    unsigned char *_out = out;
    3.26 +    RPC_CSTR str;
    3.27 +    RPC_STATUS rpc_status = UuidToString(uu, &str);
    3.28 +    assert(rpc_status == RPC_S_OK);
    3.29 +    if (rpc_status == RPC_S_OK) {
    3.30 +        memcpy(out, str, 36);
    3.31 +        out[36] = 0;
    3.32 +        RpcStringFree(str);
    3.33 +    }
    3.34 +    else { // if (rpc_status == RPC_S_OUT_OF_MEMORY)
    3.35 +        memset(out, 0, 37);
    3.36 +    }
    3.37 +}
    3.38 +
    3.39  } // "C"
     4.1 --- a/src/platform_windows.h	Sun Jul 31 00:24:15 2016 +0200
     4.2 +++ b/src/platform_windows.h	Sun Jul 31 09:01:39 2016 +0200
     4.3 @@ -4,6 +4,7 @@
     4.4  
     4.5  #pragma warning(disable : 4996)
     4.6  
     4.7 +#include <Rpc.h>
     4.8  #include <string.h>
     4.9  #include <io.h>
    4.10  #include <basetsd.h>
    4.11 @@ -58,6 +59,15 @@
    4.12  
    4.13  long random(void);
    4.14  
    4.15 +// on Windoze, uuid_t needs pointer semantics
    4.16 +typedef UUID *uuid_t;
    4.17 +#define _UUID_STRING_T
    4.18 +typedef char uuid_string_t[37];
    4.19 +
    4.20 +void uuid_generate_random(uuid_t out);
    4.21 +int uuid_parse(char *in, uuid_t uu);
    4.22 +void uuid_unparse_upper(uuid_t uu, uuid_string_t out);
    4.23 +
    4.24  #ifndef inline
    4.25  #define inline __inline
    4.26  #endif