/* Copyright (c) 2011-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "buffer.h"
#include "str.h"
#include "sha1.h"
#include "hash.h"
#include "hex-binary.h"
#include "hostpid.h"
#include "guid.h"
#include <unistd.h>
#include <time.h>
const char *guid_generate(void)
{
static unsigned int pid = 0;
/* we'll use the current time in nanoseconds as the initial 64bit
counter. */
i_fatal("clock_gettime() failed: %m");
} else {
}
return t_strdup_printf("%08x%08lx.%x.%s",
pid, my_hostname);
}
{
}
{
#if GUID_128_HOST_HASH_SIZE != 4
#endif
/* we'll use the current time in nanoseconds as the initial 64bit
counter. */
i_fatal("clock_gettime() failed: %m");
/* use ioloop's time since we have it. it doesn't provide any
more uniqueness, but it allows finding out more reliably
when a GUID was created. */
} else {
}
}
{
unsigned int i;
for (i = 0; i < GUID_128_SIZE; i++) {
if (guid[i] != 0)
return FALSE;
}
return TRUE;
}
{
}
{
}
{
}
{
}
{
}
{
switch(format) {
case FORMAT_COMPACT:
return guid_128_to_string(guid);
case FORMAT_RECORD:
return t_strdup_printf("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
guid[15]);
case FORMAT_MICROSOFT:
}
i_unreached();
}
{
int ret;
T_BEGIN {
for(i=0; i < len; i++) {
/* Microsoft format */
/* 8-4-4-4-12 */
if (((i==8+m) || (i==13+m) || (i==18+m) || (i==23+m)) &&
str[i] == '-') continue;
}
} T_END;
return ret;
}