--- uuid.c 2004/01/10 11:07:26 1.11
+++ uuid.c 2004/01/10 11:14:18 1.12
@@ -116,6 +116,7 @@
uuid_uint8_t node[6];
};
+/* create UUID object */
uuid_rc_t uuid_create(uuid_t **uuid)
{
/* argument sanity check */
@@ -132,6 +133,7 @@
return UUID_RC_OK;
}
+/* destroy UUID object */
uuid_rc_t uuid_destroy(uuid_t *uuid)
{
/* argument sanity check */
@@ -144,6 +146,7 @@
return UUID_RC_OK;
}
+/* set UUID object to represents 'nil UUID' */
uuid_rc_t uuid_nil(uuid_t *uuid)
{
/* argument sanity check */
@@ -156,6 +159,7 @@
return UUID_RC_OK;
}
+/* compare UUID objects */
uuid_rc_t uuid_compare(uuid_t *a, uuid_t *b, int *result)
{
int r;
@@ -206,6 +210,7 @@
return UUID_RC_OK;
}
+/* check whether UUID object represents 'nil UUID' */
uuid_rc_t uuid_isnil(uuid_t *uuid, int *result)
{
const unsigned char *ucp;
@@ -227,6 +232,7 @@
return UUID_RC_OK;
}
+/* unpack UUID binary presentation into UUID object (allows in-place operation!) */
uuid_rc_t uuid_unpack(uuid_t *uuid, const void *buf)
{
const uuid_uint8_t *in;
@@ -271,6 +277,7 @@
return UUID_RC_OK;
}
+/* pack UUID object into binary representation (allows in-place operation!) */
uuid_rc_t uuid_pack(uuid_t *uuid, void **buf)
{
uuid_uint8_t *out;
@@ -320,18 +327,16 @@
return UUID_RC_OK;
}
-/* check for correct UUID string representation syntax */
+/* INTERNAL: check for valid UUID string representation syntax */
static int uuid_isstr(const char *str)
{
int i;
const char *cp;
- /*
- * example reference:
- * f81d4fae-7dec-11d0-a765-00a0c91e6bf6
- * 012345678901234567890123456789012345
- * 0 1 2 3
- */
+ /* example reference:
+ f81d4fae-7dec-11d0-a765-00a0c91e6bf6
+ 012345678901234567890123456789012345
+ 0 1 2 3 */
if (str == NULL)
return FALSE;
if (strlen(str) != UUID_LEN_STR)
@@ -352,6 +357,7 @@
return TRUE;
}
+/* parse string representation into UUID object */
uuid_rc_t uuid_parse(uuid_t *uuid, const char *str)
{
uuid_uint16_t tmp16;
@@ -389,6 +395,7 @@
return UUID_RC_OK;
}
+/* format UUID object into string representation */
uuid_rc_t uuid_format(uuid_t *uuid, char **str)
{
/* sanity check argument(s) */
@@ -418,7 +425,7 @@
return UUID_RC_OK;
}
-/* pseudo-random number generator (PRNG) */
+/* INTERNAL: pseudo-random number generator (PRNG) */
static void uuid_prng_getdata(uuid_uint8_t *data_ptr, size_t data_len)
{
static int initialized = FALSE;
@@ -480,7 +487,7 @@
return;
}
-/* brand UUID with version and variant */
+/* INTERNAL: brand UUID with version and variant */
static void uuid_brand(uuid_t *uuid, int version)
{
/* set version (as given) */
@@ -493,7 +500,7 @@
return;
}
-/* generate UUID version 1: time, clock and node based */
+/* INTERNAL: generate UUID version 1: time, clock and node based */
static uuid_rc_t uuid_generate_v1(uuid_t *uuid, unsigned int mode, va_list ap)
{
/* brand with version and variant */
@@ -504,11 +511,9 @@
return UUID_RC_OK;
}
-/*
- * UUID Namespace Ids as pre-defined by draft-leach-uuids-guids-01.txt
- * (defined here as network byte ordered octet stream for direct MD5 feeding)
- */
-struct {
+/* INTERNAL: UUID Namespace Ids as pre-defined by draft-leach-uuids-guids-01.txt
+ (defined here as network byte ordered octet stream for direct MD5 feeding) */
+static struct {
char *name;
uuid_uint8_t uuid[UUID_LEN_BIN];
} uuid_ns_table[] = {
@@ -522,19 +527,19 @@
{ 0x6b,0xa7,0xb8,0x14,0x9d,0xad,0x11,0xd1,0x80,0xb4,0x00,0xc0,0x4f,0xd4,0x30,0xc8 } }
};
-/* generate UUID version 3: name based */
+/* INTERNAL: generate UUID version 3: name based */
static uuid_rc_t uuid_generate_v3(uuid_t *uuid, unsigned int mode, va_list ap)
{
char *str;
- char *ns_name;
- void *ns_uuid;
- uuid_t *uuid_tmp;
+ char *ns;
+ void *uuid_octets;
+ uuid_t *uuid_object;
uuid_rc_t rc;
md5_t *md5;
int i;
/* determine namespace UUID name and argument name string */
- if ((ns_name = (char *)va_arg(ap, char *)) == NULL)
+ if ((ns = (char *)va_arg(ap, char *)) == NULL)
return UUID_RC_ARG;
if ((str = (char *)va_arg(ap, char *)) == NULL)
return UUID_RC_ARG;
@@ -544,28 +549,28 @@
return UUID_RC_MEM;
/* load the namespace UUID into MD5 context */
- if (uuid_isstr(ns_name)) {
+ if (uuid_isstr(ns)) {
/* custom namespace via UUID string representation */
- if ((rc = uuid_create(&uuid_tmp)) != UUID_RC_OK)
+ if ((rc = uuid_create(&uuid_object)) != UUID_RC_OK)
return rc;
- if ((rc = uuid_parse(uuid_tmp, ns_name)) != UUID_RC_OK)
+ if ((rc = uuid_parse(uuid_object, ns)) != UUID_RC_OK)
return rc;
- uuid_pack(uuid_tmp, (void **)&uuid_tmp);
- md5_update(md5, (void *)uuid_tmp, UUID_LEN_BIN);
- uuid_destroy(uuid_tmp);
+ uuid_pack(uuid_object, (void **)&uuid_object);
+ md5_update(md5, (void *)uuid_object, UUID_LEN_BIN);
+ uuid_destroy(uuid_object);
}
else {
/* standard namespace via UUID namespace id */
- ns_uuid = NULL;
+ uuid_octets = NULL;
for (i = 0; i < sizeof(uuid_ns_table)/sizeof(uuid_ns_table[0]); i++) {
- if (strcmp(uuid_ns_table[i].name, ns_name) == 0) {
- ns_uuid = uuid_ns_table[i].uuid;
+ if (strcmp(uuid_ns_table[i].name, ns) == 0) {
+ uuid_octets = uuid_ns_table[i].uuid;
break;
}
}
- if (ns_uuid == NULL)
+ if (uuid_octets == NULL)
return UUID_RC_ARG;
- md5_update(md5, ns_uuid, UUID_LEN_BIN);
+ md5_update(md5, uuid_octets, UUID_LEN_BIN);
}
/* load the argument name string into MD5 context */
@@ -590,7 +595,7 @@
return UUID_RC_OK;
}
-/* generate UUID version 4: random number based */
+/* INTERNAL: generate UUID version 4: random number based */
static uuid_rc_t uuid_generate_v4(uuid_t *uuid, unsigned int mode, va_list ap)
{
/* fill UUID with random data */
@@ -602,6 +607,7 @@
return UUID_RC_OK;
}
+/* generate UUID */
uuid_rc_t uuid_generate(uuid_t *uuid, unsigned int mode, ...)
{
va_list ap;
@@ -626,6 +632,7 @@
return rc;
}
+/* dump UUID object as descriptive text */
uuid_rc_t uuid_dump(uuid_t *uuid, char **str)
{
/* sanity check argument(s) */
@@ -635,6 +642,7 @@
return UUID_RC_OK;
}
+/* translate UUID API error code into corresponding error string */
char *uuid_error(uuid_rc_t rc)
{
char *str;
|