UUID specifica

ENGINE-96
Volker Birk 7 years ago
parent 1857c94e88
commit 21be660041

@ -158,6 +158,7 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
int_result = sqlite3_exec(
_session->db,
"PRAGMA application_id = 0x23423423;\n"
"create table if not exists log (\n"
" timestamp integer default (datetime('now')) ,\n"
" title text not null,\n"
@ -260,6 +261,7 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
if (version < 2) {
int_result = sqlite3_exec(
_session->db,
"PRAGMA application_id = 0x23423423;\n"
"alter table pgp_keypair\n"
" add column flags integer default (0);",
NULL,

@ -5,6 +5,7 @@
#include <unistd.h>
#include <strings.h>
#include <sys/select.h>
#include <uuid/uuid.h>
#ifdef __cplusplus
extern "C" {
@ -45,6 +46,15 @@ size_t strlcpy(char* dst, const char* src, size_t size);
size_t strlcat(char* dst, const char* src, size_t size);
#endif
#ifndef _UUID_STRING_T
#define _UUID_STRING_T
typedef char uuid_string_t[37];
#endif
#ifdef UUID
// on *nix, uuid_t is an array and already implements pointer semantics
#define UUID uuid_t
#endif
#ifdef __cplusplus
}
#endif

@ -267,4 +267,36 @@ int mkstemp(char *templ)
return _open(pathname, _O_RDWR | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE);
}
void uuid_generate_random(uuid_t out)
{
RPC_STATUS rpc_status = UuidCreate(out);
assert(rpc_status == RPC_S_OK);
}
int uuid_parse(char *in, uuid_t uu)
{
unsigned char *_in = (unsigned char *) in;
RPC_STATUS rpc_status = UuidFromString(_in, &uu);
assert(rpc_status == RPC_S_OK);
if (rpc_status == RPC_S_INVALID_STRING_UUID)
return -1;
return 0;
}
void uuid_unparse_upper(uuid_t uu, uuid_string_t out)
{
unsigned char *_out = out;
RPC_CSTR str;
RPC_STATUS rpc_status = UuidToString(uu, &str);
assert(rpc_status == RPC_S_OK);
if (rpc_status == RPC_S_OK) {
memcpy(out, str, 36);
out[36] = 0;
RpcStringFree(str);
}
else { // if (rpc_status == RPC_S_OUT_OF_MEMORY)
memset(out, 0, 37);
}
}
} // "C"

@ -4,6 +4,7 @@
#pragma warning(disable : 4996)
#include <Rpc.h>
#include <string.h>
#include <io.h>
#include <basetsd.h>
@ -58,6 +59,15 @@ const char *gpg_conf(void);
long random(void);
// on Windoze, uuid_t needs pointer semantics
typedef UUID *uuid_t;
#define _UUID_STRING_T
typedef char uuid_string_t[37];
void uuid_generate_random(uuid_t out);
int uuid_parse(char *in, uuid_t uu);
void uuid_unparse_upper(uuid_t uu, uuid_string_t out);
#ifndef inline
#define inline __inline
#endif

Loading…
Cancel
Save