OSSP CVS Repository

ossp - Difference in ossp-pkg/uuid/uuid.c versions 1.10 and 1.11
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/uuid/uuid.c 1.10 -> 1.11

--- uuid.c       2004/01/10 10:49:00     1.10
+++ uuid.c       2004/01/10 11:07:26     1.11
@@ -320,49 +320,64 @@
     return UUID_RC_OK;
 }
 
-uuid_rc_t uuid_parse(uuid_t *uuid, const char *str)
+/* check for correct UUID string representation syntax */
+static int uuid_isstr(const char *str)
 {
-    uuid_uint16_t tmp16;
-    const char *cp;
-    char hexbuf[3];
     int i;
-
-    /* sanity check argument(s) */
-    if (uuid == NULL || str == NULL)
-        return UUID_RC_ARG;
+    const char *cp;
 
     /*
-     * pass 1: check UUID string representation syntax
      * example reference:
      *   f81d4fae-7dec-11d0-a765-00a0c91e6bf6
      *   012345678901234567890123456789012345
      *   0         1         2         3
      */
+    if (str == NULL)
+        return FALSE;
     if (strlen(str) != UUID_LEN_STR)
-        return UUID_RC_ARG;
+        return FALSE;
     for (i = 0, cp = str; i <= UUID_LEN_STR; i++, cp++) {
         if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) {
             if (*cp == '-')
                 continue;
             else
-                return -1;
+                return FALSE;
         }
         if (i == UUID_LEN_STR)
             if (*cp == '\0')
                 continue;
         if (!isxdigit(*cp))
-            return UUID_RC_ARG;
+            return FALSE;
     }
+    return TRUE;
+}
 
-    /*
-     * pass 2: parse hex values of string representation syntax
-     */
+uuid_rc_t uuid_parse(uuid_t *uuid, const char *str)
+{
+    uuid_uint16_t tmp16;
+    const char *cp;
+    char hexbuf[3];
+    int i;
+
+    /* sanity check argument(s) */
+    if (uuid == NULL || str == NULL)
+        return UUID_RC_ARG;
+
+    /* check for correct UUID string representation syntax */
+    if (!uuid_isstr(str))
+        return UUID_RC_ARG;
+
+    /* parse hex values of "time" parts */
     uuid->time_low            = (uuid_uint32_t)strtoul(str,    NULL, 16);
     uuid->time_mid            = (uuid_uint16_t)strtoul(str+9,  NULL, 16);
     uuid->time_hi_and_version = (uuid_uint16_t)strtoul(str+14, NULL, 16);
+
+    /* parse hex values of "clock" parts */
     tmp16 = (uuid_uint16_t)strtoul(str+19, NULL, 16);
     uuid->clock_seq_low             = (uuid_uint8_t)(tmp16 & 0xff); tmp16 >>= 8;
     uuid->clock_seq_hi_and_reserved = (uuid_uint8_t)(tmp16 & 0xff);
+
+    /* parse hex values of "node" part */
     cp = str+24;
     hexbuf[2] = '\0';
     for (i = 0; i < sizeof(uuid->node); i++) {
@@ -513,6 +528,8 @@
     char *str;
     char *ns_name;
     void *ns_uuid;
+    uuid_t *uuid_tmp;
+    uuid_rc_t rc;
     md5_t *md5;
     int i;
 
@@ -527,16 +544,29 @@
         return UUID_RC_MEM;
 
     /* load the namespace UUID into MD5 context */
-    ns_uuid = 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;
-             break;
-         }
+    if (uuid_isstr(ns_name)) {
+        /* custom namespace via UUID string representation */
+        if ((rc = uuid_create(&uuid_tmp)) != UUID_RC_OK)
+            return rc;
+        if ((rc = uuid_parse(uuid_tmp, ns_name)) != 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);
+    }
+    else {
+        /* standard namespace via UUID namespace id */
+        ns_uuid = 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;
+                 break;
+             }
+        }
+        if (ns_uuid == NULL)
+            return UUID_RC_ARG;
+        md5_update(md5, ns_uuid, UUID_LEN_BIN);
     }
-    if (ns_uuid == NULL)
-        return UUID_RC_ARG;
-    md5_update(md5, ns_uuid, UUID_LEN_BIN);
 
     /* load the argument name string into MD5 context */
     md5_update(md5, str, strlen(str));

CVSTrac 2.0.1