261 #ifdef HAVE_UUID_E2FS
264 uuid_generate_time(uu);
265 uuid_unparse(uu, strbuf);
272 if (ptr &&
len <= 36)
273 strcpy(strbuf + (36 -
len), ptr);
276 uint32_t status = uuid_s_ok;
279 uuid_create(&uu, &status);
281 if (status == uuid_s_ok)
283 uuid_to_string(&uu, &
str, &status);
284 if (status == uuid_s_ok)
293 if (strbuf[14] !=
'1')
295 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
297 errmsg(
"uuid_create() produced a version %c UUID instead of the expected version 1",
305 if (ptr &&
len <= 36)
306 strcpy(strbuf + (36 -
len), ptr);
311 if (status != uuid_s_ok)
313 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
314 errmsg(
"uuid library failure: %d",
325 uint32_t status = uuid_s_ok;
334 elog(
ERROR,
"could not initialize %s context: %s",
"MD5",
338 elog(
ERROR,
"could not update %s context: %s",
"MD5",
343 elog(
ERROR,
"could not finalize %s context: %s",
"MD5",
353 elog(
ERROR,
"could not initialize %s context: %s",
"SHA1",
357 elog(
ERROR,
"could not update %s context: %s",
"SHA1",
360 elog(
ERROR,
"could not finalize %s context: %s",
"SHA1",
364 memcpy(&uu, sha1result,
sizeof(uu));
371 #ifdef HAVE_UUID_E2FS
374 uuid_unparse((
unsigned char *) &uu, strbuf);
376 uuid_to_string(&uu, &
str, &status);
378 if (status == uuid_s_ok)
383 if (status != uuid_s_ok)
385 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
386 errmsg(
"uuid library failure: %d",
395 #ifdef HAVE_UUID_E2FS
398 uuid_generate_random(uu);
399 uuid_unparse(uu, strbuf);
402 "%08lx-%04x-%04x-%04x-%04x%08lx",
403 (
unsigned long) arc4random(),
404 (
unsigned) (arc4random() & 0xffff),
405 (
unsigned) ((arc4random() & 0xfff) | 0x4000),
406 (
unsigned) ((arc4random() & 0x3fff) | 0x8000),
407 (
unsigned) (arc4random() & 0xffff),
408 (
unsigned long) arc4random());
int pg_cryptohash_update(pg_cryptohash_ctx *ctx, const uint8 *data, size_t len)
int pg_cryptohash_init(pg_cryptohash_ctx *ctx)
void pg_cryptohash_free(pg_cryptohash_ctx *ctx)
pg_cryptohash_ctx * pg_cryptohash_create(pg_cryptohash_type type)
int pg_cryptohash_final(pg_cryptohash_ctx *ctx, uint8 *dest, size_t len)
const char * pg_cryptohash_error(pg_cryptohash_ctx *ctx)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define DirectFunctionCall1(func, arg1)
size_t strlcpy(char *dst, const char *src, size_t siz)
static Datum CStringGetDatum(const char *X)
#define SHA1_DIGEST_LENGTH
#define UUID_V3_OR_V5(uu, v)
#define UUID_TO_LOCAL(uu)
#define UUID_TO_NETWORK(uu)
Datum uuid_in(PG_FUNCTION_ARGS)