OSSP CVS Repository

ossp - Check-in [4364]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 4364
Date: 2004-Jan-18 12:31:09 (local)
2004-Jan-18 11:31:09 (UTC)
User:rse
Branch:
Comment: Improvide decoding in uuid_dump() by at least hex-dumping the binary representation in case of v3, v4 and Nil UUIDs. Also, annotate with better hints.
Tickets:
Inspections:
Files:
ossp-pkg/uuid/ChangeLog      1.24 -> 1.25     5 inserted, 0 deleted
ossp-pkg/uuid/uuid.c      1.33 -> 1.34     72 inserted, 43 deleted

ossp-pkg/uuid/ChangeLog 1.24 -> 1.25

--- ChangeLog    2004/01/17 14:21:57     1.24
+++ ChangeLog    2004/01/18 11:31:09     1.25
@@ -13,6 +13,11 @@
 
   Changes between 0.9.3 and 0.9.4 (16-Jan-2004 to xx-Jan-2004)
 
+   o Improvide decoding in uuid_dump() by at least hex-dumping the
+     binary representation in case of v3, v4 and Nil UUIDs. Also,
+     annotate with better hints.
+     [Ralf S. Engelschall]
+
    o Recognize special "Nil UUID" on decoding in uuid_dump().
      [Ralf S. Engelschall]
 


ossp-pkg/uuid/uuid.c 1.33 -> 1.34

--- uuid.c       2004/01/17 14:21:57     1.33
+++ uuid.c       2004/01/18 11:31:10     1.34
@@ -85,7 +85,7 @@
     if ((*uuid = (uuid_t *)malloc(sizeof(uuid_t))) == NULL)
         return UUID_RC_MEM;
 
-    /* set UUID object initially to "nil UUID" */
+    /* set UUID object initially to "Nil UUID" */
     uuid_nil(*uuid);
 
     /* create PRNG and MD5 sub-objects */
@@ -125,20 +125,20 @@
     return UUID_RC_OK;
 }
 
-/* set UUID object to represents 'nil UUID' */
+/* set UUID object to represents "Nil UUID" */
 uuid_rc_t uuid_nil(uuid_t *uuid)
 {
     /* argument sanity check */
     if (uuid == NULL)
         return UUID_RC_ARG;
 
-    /* clear all octets to create "nil UUID" */
+    /* clear all octets to create "Nil UUID" */
     memset((void *)&(uuid->obj), '\0', sizeof(uuid->obj));
 
     return UUID_RC_OK;
 }
 
-/* check whether UUID object represents 'nil UUID' */
+/* check whether UUID object represents "Nil UUID" */
 uuid_rc_t uuid_isnil(uuid_t *uuid, int *result)
 {
     const unsigned char *ucp;
@@ -148,7 +148,7 @@
     if (uuid == NULL || result == NULL)
         return UUID_RC_ARG;
 
-    /* a "nil UUID" is defined as all octets zero, so check for this case */
+    /* a "Nil UUID" is defined as all octets zero, so check for this case */
     *result = UUID_TRUE;
     for (i = 0, ucp = (unsigned char *)&(uuid->obj); i < UUID_LEN_BIN; i++) {
         if (*ucp++ != '\0') {
@@ -768,6 +768,7 @@
 {
     const char *version;
     const char *variant;
+    uuid_rc_t rc;
     uuid_uint8_t tmp8;
     uuid_uint16_t tmp16;
     uuid_uint32_t tmp32;
@@ -780,8 +781,11 @@
     int t_usec;
     time_t t_sec;
     char buf[19+1]; /* YYYY-MM-DD HH:MM:SS */
+    char *content;
     struct tm *tm;
-    int r;
+    int isnil;
+    uuid_uint8_t tmp[UUID_LEN_BIN];
+    void *tmp_ptr;
 
     /* sanity check argument(s) */
     if (uuid == NULL || str == NULL)
@@ -795,50 +799,52 @@
     uuid_format(uuid, &s);
     str_rsprintf(str, "UUID:    %s\n", s);
 
-    /* short-circuit special case of 'nil UUID' */
-    if (uuid_isnil(uuid, &r), r) {
-        str_rsprintf(str, "variant: [none]\n"
-                          "version: [none]\n"
-                          "content: Nil UUID\n");
-        return UUID_RC_OK;
-    }
+    /* check for special case of "Nil UUID" */
+    if ((rc = uuid_isnil(uuid, &isnil)) != UUID_RC_OK)
+        return rc;
 
     /* decode UUID variant */
-    variant = "unknown";
     tmp8 = uuid->obj.clock_seq_hi_and_reserved;
-    for (i = 7; i >= 0; i--) {
-        if ((tmp8 & BM_BIT(i,1)) == 0) {
-            tmp8 &= ~BM_MASK(i,0);
-            break;
+    if (isnil)
+        variant = "n.a.";
+    else {
+        variant = "unknown";
+        for (i = 7; i >= 0; i--) {
+            if ((tmp8 & BM_BIT(i,1)) == 0) {
+                tmp8 &= ~BM_MASK(i,0);
+                break;
+            }
         }
-    }
-    for (i = 0; i < sizeof(uuid_dectab_variant)/sizeof(uuid_dectab_variant[0]); i++) {
-        if (uuid_dectab_variant[i].num == tmp8) {
-            variant = uuid_dectab_variant[i].desc;
-            break;
+        for (i = 0; i < sizeof(uuid_dectab_variant)/sizeof(uuid_dectab_variant[0]); i++) {
+            if (uuid_dectab_variant[i].num == tmp8) {
+                variant = uuid_dectab_variant[i].desc;
+                break;
+            }
         }
     }
     str_rsprintf(str, "variant: %s\n", variant);
 
     /* decode UUID version */
-    version = "unknown";
     tmp16 = (BM_SHR(uuid->obj.time_hi_and_version, 12) & BM_MASK(3,0));
-    for (i = 0; i < sizeof(uuid_dectab_version)/sizeof(uuid_dectab_version[0]); i++) {
-        if (uuid_dectab_version[i].num == (int)tmp16) {
-            version = uuid_dectab_version[i].desc;
-            break;
+    if (isnil)
+        version = "n.a.";
+    else {
+        version = "unknown";
+        for (i = 0; i < sizeof(uuid_dectab_version)/sizeof(uuid_dectab_version[0]); i++) {
+            if (uuid_dectab_version[i].num == (int)tmp16) {
+                version = uuid_dectab_version[i].desc;
+                break;
+            }
         }
     }
     str_rsprintf(str, "version: %d (%s)\n", (int)tmp16, version);
 
-    /* we currently support DCE 1.1 variants of version 1/3/4 only */
-    if (!(   tmp8 == BM_OCTET(1,0,0,0,0,0,0,0)
-          && (tmp16 == 1 || tmp16 == 3 || tmp16 == 4)))
-        return UUID_RC_OK;
-
-    /* decode more */
-    if (tmp16 == 1) {
-        /* decode version 1 */
+    /*
+     * decode UUID content
+     */
+
+    if (tmp8 == BM_OCTET(1,0,0,0,0,0,0,0) && tmp16 == 1) {
+        /* decode DCE 1.1 version 1 UUID */
 
         /* decode system time */
         t = ui64_rol(ui64_n2i((unsigned long)(uuid->obj.time_hi_and_version & BM_MASK(11,0))), 48, NULL),
@@ -869,13 +875,36 @@
             (uuid->obj.node[0] & IEEE_MAC_LOBIT_DEC ? "local" : "global"),
             (uuid->obj.node[0] & IEEE_MAC_MCBIT_DEC ? "multicast" : "unicast"));
     }
-    else if (tmp16 == 3) {
-        /* decode version 3 */
-        str_rsprintf(str, "content: [not decipherable]\n");
-    }
-    else if (tmp16 == 4) {
-        /* decode version 4 */
-        str_rsprintf(str, "content: [no semantics]\n");
+    else {
+        /* decode anything else as hexadecimal byte-string only */
+
+        /* determine annotational hint */
+        content = "not decipherable, because unknown UUID version";
+        if (isnil)
+            content = "special case of DCE 1.1 Nil UUID";
+        else if (tmp16 == 3)
+            content = "not decipherable, because message digest only";
+        else if (tmp16 == 4)
+            content = "no semantics, because random data only";
+
+        /* pack UUID into binary representation */
+        tmp_ptr = tmp;
+        if ((rc = uuid_pack(uuid, &tmp_ptr)) != UUID_RC_OK)
+            return rc;
+
+        /* mask out version and variant parts */
+        tmp[6] &= BM_MASK(3,0);
+        tmp[8] &= BM_MASK(5,0);
+
+        /* dump as colon-seperated hexadecimal byte-string */
+        str_rsprintf(str,
+            "content: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n"
+            "         (%s)\n",
+            (unsigned int)tmp[0],  (unsigned int)tmp[1],  (unsigned int)tmp[2],  (unsigned int)tmp[3],
+            (unsigned int)tmp[4],  (unsigned int)tmp[5],  (unsigned int)tmp[6],  (unsigned int)tmp[7],
+            (unsigned int)tmp[8],  (unsigned int)tmp[9],  (unsigned int)tmp[10], (unsigned int)tmp[11],
+            (unsigned int)tmp[12], (unsigned int)tmp[13], (unsigned int)tmp[14], (unsigned int)tmp[15],
+            content);
     }
 
     return UUID_RC_OK;

CVSTrac 2.0.1