Datum uuid_generate_v1mc(PG_FUNCTION_ARGS) { #ifdef HAVE_UUID_OSSP char *buf = NULL; #elif defined(HAVE_UUID_E2FS) char strbuf[40]; char *buf; uuid_t uu; uuid_generate_random(uu); /* set IEEE802 multicast and local-admin bits */ ((dce_uuid_t *) &uu)->node[0] |= 0x03; uuid_unparse(uu, strbuf); buf = strbuf + 24; #else /* BSD */ char buf[16]; /* set IEEE802 multicast and local-admin bits */ snprintf(buf, sizeof(buf), "-%04x%08lx", (unsigned) ((arc4random() & 0xffff) | 0x0300), (unsigned long) arc4random()); #endif return uuid_generate_internal(UUID_MAKE_V1 | UUID_MAKE_MC, NULL, buf, 13); }
Datum uuid_ns_x500(PG_FUNCTION_ARGS) { #ifdef HAVE_UUID_OSSP return special_uuid_value("ns:X500"); #else return uuid_generate_internal(0, NULL, "6ba7b814-9dad-11d1-80b4-00c04fd430c8", 36); #endif }
Datum uuid_nil(PG_FUNCTION_ARGS) { #ifdef HAVE_UUID_OSSP return special_uuid_value("nil"); #else return uuid_generate_internal(0, NULL, "00000000-0000-0000-0000-000000000000", 36); #endif }
Datum uuid_generate_v5(PG_FUNCTION_ARGS) { pg_uuid_t *ns = PG_GETARG_UUID_P(0); text *name = PG_GETARG_TEXT_P(1); #ifdef HAVE_UUID_OSSP return uuid_generate_v35_internal(UUID_MAKE_V5, ns, name); #else return uuid_generate_internal(UUID_MAKE_V5, (unsigned char *) ns, VARDATA(name), VARSIZE(name) - VARHDRSZ); #endif }
static Datum uuid_generate_v35_internal(int mode, pg_uuid_t *ns, text *name) { uuid_t *ns_uuid = get_cached_uuid_t(1); string_to_uuid(DatumGetCString(DirectFunctionCall1(uuid_out, UUIDPGetDatum(ns))), ns_uuid); return uuid_generate_internal(mode, ns_uuid, text_to_cstring(name), 0); }
static Datum uuid_generate_v35_internal(int mode, pg_uuid_t *ns, text *name) { uuid_t *ns_uuid; Datum result; uuid_rc_t rc; rc = uuid_create(&ns_uuid); if (rc != UUID_RC_OK) pguuid_complain(rc); string_to_uuid(DatumGetCString(DirectFunctionCall1(uuid_out, UUIDPGetDatum(ns))), ns_uuid); result = uuid_generate_internal(mode, ns_uuid, text_to_cstring(name)); rc = uuid_destroy(ns_uuid); if (rc != UUID_RC_OK) pguuid_complain(rc); return result; }
Datum uuid_generate_v4(PG_FUNCTION_ARGS) { return uuid_generate_internal(UUID_MAKE_V4, NULL, NULL); }
Datum uuid_generate_v1mc(PG_FUNCTION_ARGS) { return uuid_generate_internal(UUID_MAKE_V1 | UUID_MAKE_MC, NULL, NULL); }