diff options
Diffstat (limited to 'databases/postgresql92-server/files/patch-contrib-uuid')
-rw-r--r-- | databases/postgresql92-server/files/patch-contrib-uuid | 201 |
1 files changed, 95 insertions, 106 deletions
diff --git a/databases/postgresql92-server/files/patch-contrib-uuid b/databases/postgresql92-server/files/patch-contrib-uuid index c7b003bb39a5..8f8748ea8dcc 100644 --- a/databases/postgresql92-server/files/patch-contrib-uuid +++ b/databases/postgresql92-server/files/patch-contrib-uuid @@ -1,5 +1,15 @@ ---- contrib/uuid-ossp/Makefile.orig 2014-03-17 20:36:46.000000000 +0100 -+++ contrib/uuid-ossp/Makefile 2014-03-19 21:19:28.000000000 +0100 +--- contrib/Makefile.orig 2014-07-21 20:12:31.000000000 +0100 ++++ contrib/Makefile 2014-07-30 18:15:30.332934684 +0100 +@@ -50,6 +50,7 @@ + test_parser \ + tsearch2 \ + unaccent \ ++ uuid-ossp \ + vacuumlo + + ifeq ($(with_openssl),yes) +--- contrib/uuid-ossp/Makefile.orig 2014-07-21 20:12:31.000000000 +0100 ++++ contrib/uuid-ossp/Makefile 2014-07-30 18:15:36.370934674 +0100 @@ -1,12 +1,14 @@ # contrib/uuid-ossp/Makefile +# modified using http://pgfoundry.org/projects/uuid-freebsd/ @@ -17,23 +27,8 @@ ifdef USE_PGXS PG_CONFIG = pg_config ---- contrib/uuid-ossp/uuid-ossp--1.0.sql.orig 2014-03-17 20:36:46.000000000 +0100 -+++ contrib/uuid-ossp/uuid-ossp--1.0.sql 2014-03-19 21:19:28.000000000 +0100 -@@ -1,5 +1,12 @@ - /* contrib/uuid-ossp/uuid-ossp--1.0.sql */ - -+-- this module is modified by girgen@ for FreeBSD using -+-- http://pgfoundry.org/projects/uuid-freebsd/ -+-- based on the work of Andrew Gierth. -+-- The name is still uuid-ossp to maintain verbatim compatibility -+-- with the original ossp based module, although the built-in libc -+-- routines are actually used instead, not ossp. -+ - -- complain if script is sourced in psql, rather than via CREATE EXTENSION - \echo Use '''CREATE EXTENSION "uuid-ossp"''' to load this file. \quit - ---- contrib/uuid-ossp/uuid-ossp.c.orig 2014-03-17 20:36:46.000000000 +0100 -+++ contrib/uuid-ossp/uuid-ossp.c 2014-03-19 21:20:56.000000000 +0100 +--- contrib/uuid-ossp/uuid-ossp.c.orig 2014-07-21 20:12:31.000000000 +0100 ++++ contrib/uuid-ossp/uuid-ossp.c 2014-07-30 18:15:44.843935308 +0100 @@ -6,6 +6,10 @@ * * contrib/uuid-ossp/uuid-ossp.c @@ -80,7 +75,7 @@ PG_MODULE_MAGIC; -@@ -64,163 +55,175 @@ +@@ -64,177 +55,175 @@ PG_FUNCTION_INFO_V1(uuid_generate_v4); PG_FUNCTION_INFO_V1(uuid_generate_v5); @@ -103,41 +98,45 @@ + * that pg's internal storage of uuids is the simple byte-oriented + * binary format. */ --static char * --uuid_to_string(const uuid_t *uuid) --{ -- char *buf = palloc(UUID_LEN_STR + 1); -- void *ptr = buf; -- size_t len = UUID_LEN_STR + 1; -- uuid_rc_t rc; -- -- rc = uuid_export(uuid, UUID_FMT_STR, &ptr, &len); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); -- -- return buf; --} -- -- --static void --string_to_uuid(const char *str, uuid_t *uuid) +-/* +- * We create a uuid_t object just once per session and re-use it for all +- * operations in this module. OSSP UUID caches the system MAC address and +- * other state in this object. Reusing the object has a number of benefits: +- * saving the cycles needed to fetch the system MAC address over and over, +- * reducing the amount of entropy we draw from /dev/urandom, and providing a +- * positive guarantee that successive generated V1-style UUIDs don't collide. +- * (On a machine fast enough to generate multiple UUIDs per microsecond, +- * or whatever the system's wall-clock resolution is, we'd otherwise risk +- * collisions whenever random initialization of the uuid_t's clock sequence +- * value chanced to produce duplicates.) +- * +- * However: when we're doing V3 or V5 UUID creation, uuid_make needs two +- * uuid_t objects, one holding the namespace UUID and one for the result. +- * It's unspecified whether it's safe to use the same uuid_t for both cases, +- * so let's cache a second uuid_t for use as the namespace holder object. +- */ +-static uuid_t * +-get_cached_uuid_t(int which) +static Datum +internal_uuid_create(int v, unsigned char *ns, char *ptr, int len) { -- uuid_rc_t rc; -- -- rc = uuid_import(uuid, UUID_FMT_STR, str, UUID_LEN_STR + 1); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); --} +- static uuid_t *cached_uuid[2] = {NULL, NULL}; + char strbuf[40]; +- if (cached_uuid[which] == NULL) + switch (v) -+ { + { +- uuid_rc_t rc; + case 0: /* constant-value uuids: nil, or namespace uuids */ + strlcpy(strbuf, ptr, 37); + break; -+ + +- rc = uuid_create(&cached_uuid[which]); +- if (rc != UUID_RC_OK) +- { +- cached_uuid[which] = NULL; +- pguuid_complain(rc); +- } + case 4: default: /* random uuid */ + { + sprintf(strbuf, "%08lx-%04x-%04x-%04x-%04x%08lx", @@ -148,23 +147,37 @@ + (unsigned) (arc4random() & 0xffff), + (unsigned long) arc4random()); + break; -+ } + } +- return cached_uuid[which]; +-} + + case 1: /* time/node-based uuids */ + { + uuid_t uu; + uint32_t status = uuid_s_ok; + char *str = NULL; -+ + +-static char * +-uuid_to_string(const uuid_t *uuid) +-{ +- char *buf = palloc(UUID_LEN_STR + 1); +- void *ptr = buf; +- size_t len = UUID_LEN_STR + 1; +- uuid_rc_t rc; + uuid_create(&uu, &status); -+ + +- rc = uuid_export(uuid, UUID_FMT_STR, &ptr, &len); +- if (rc != UUID_RC_OK) +- pguuid_complain(rc); + if (status == uuid_s_ok) + { + uuid_to_string(&uu, &str, &status); + if (status == uuid_s_ok) + { + strlcpy(strbuf, str, 37); -+ + +- return buf; +-} + /* PTR, if set, replaces the trailing characters of the uuid; + * this is to support v1mc, where a random multicast MAC is + * used instead of the physical one @@ -177,23 +190,6 @@ + free(str); + } --static Datum --special_uuid_value(const char *name) --{ -- uuid_t *uuid; -- char *str; -- uuid_rc_t rc; -- -- rc = uuid_create(&uuid); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); -- rc = uuid_load(uuid, name); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); -- str = uuid_to_string(uuid); -- rc = uuid_destroy(uuid); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); + if (status != uuid_s_ok) + { + ereport(ERROR, @@ -203,7 +199,11 @@ + + break; + } -+ + +-static void +-string_to_uuid(const char *str, uuid_t *uuid) +-{ +- uuid_rc_t rc; + case 3: /* namespace-based MD5 uuids */ + { + /* we could use pg's md5(), but we're already pulling in libmd */ @@ -223,7 +223,11 @@ + buf[4], buf[5], ((buf[6] & 0xf) | 0x30), buf[7], + ((buf[8] & 0x3F) | 0x80), buf[9], buf[10], buf[11], + buf[12], buf[13], buf[14], buf[15]); -+ + +- rc = uuid_import(uuid, UUID_FMT_STR, str, UUID_LEN_STR + 1); +- if (rc != UUID_RC_OK) +- pguuid_complain(rc); +-} + break; + } + @@ -231,7 +235,7 @@ + { + SHA_CTX ctx; + unsigned char buf[20]; -+ + + SHA1_Init(&ctx); + SHA1_Update(&ctx, ns, 16); + SHA1_Update(&ctx, (unsigned char *)ptr, len); @@ -245,7 +249,18 @@ + buf[4], buf[5], ((buf[6] & 0xf) | 0x30), buf[7], + ((buf[8] & 0x3F) | 0x80), buf[9], buf[10], buf[11], + buf[12], buf[13], buf[14], buf[15]); -+ + +-static Datum +-special_uuid_value(const char *name) +-{ +- uuid_t *uuid = get_cached_uuid_t(0); +- char *str; +- uuid_rc_t rc; +- +- rc = uuid_load(uuid, name); +- if (rc != UUID_RC_OK) +- pguuid_complain(rc); +- str = uuid_to_string(uuid); + break; + } + } @@ -297,20 +312,14 @@ -static Datum -uuid_generate_internal(int mode, const uuid_t *ns, const char *name) -{ -- uuid_t *uuid; +- uuid_t *uuid = get_cached_uuid_t(0); - char *str; - uuid_rc_t rc; - -- rc = uuid_create(&uuid); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); - rc = uuid_make(uuid, mode, ns, name); - if (rc != UUID_RC_OK) - pguuid_complain(rc); - str = uuid_to_string(uuid); -- rc = uuid_destroy(uuid); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); - - return DirectFunctionCall1(uuid_in, CStringGetDatum(str)); + return internal_uuid_create(0, NULL, "6ba7b814-9dad-11d1-80b4-00c04fd430c8", 36); @@ -335,26 +344,16 @@ -static Datum -uuid_generate_v35_internal(int mode, pg_uuid_t *ns, text *name) -{ -- uuid_t *ns_uuid; -- Datum result; -- uuid_rc_t rc; +- uuid_t *ns_uuid = get_cached_uuid_t(1); - -- rc = uuid_create(&ns_uuid); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); -- string_to_uuid(DatumGetCString(DirectFunctionCall1(uuid_out, UUIDPGetDatum(ns))), +- 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); + char buf[20]; -- return result; +- return uuid_generate_internal(mode, +- ns_uuid, +- text_to_cstring(name)); + sprintf(buf, "-%04x-%04x%08lx", + (unsigned)((arc4random() & 0x3FFF) | 0x8000), + /* set IEEE802 multicast and local-admin bits */ @@ -365,7 +364,7 @@ } -@@ -230,14 +233,15 @@ +@@ -244,14 +233,15 @@ pg_uuid_t *ns = PG_GETARG_UUID_P(0); text *name = PG_GETARG_TEXT_P(1); @@ -383,7 +382,7 @@ } -@@ -247,5 +251,6 @@ +@@ -261,5 +251,6 @@ pg_uuid_t *ns = PG_GETARG_UUID_P(0); text *name = PG_GETARG_TEXT_P(1); @@ -391,13 +390,3 @@ + return internal_uuid_create(5, (unsigned char *)ns, + VARDATA(name), VARSIZE(name) - VARHDRSZ); } ---- contrib/Makefile.orig 2014-03-21 09:01:58.000000000 +0100 -+++ contrib/Makefile 2014-03-21 09:02:16.000000000 +0100 -@@ -50,6 +50,7 @@ - test_parser \ - tsearch2 \ - unaccent \ -+ uuid-ossp \ - vacuumlo - - ifeq ($(with_openssl),yes) |