OSSP CVS Repository

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

Check-in Number: 5139
Date: 2005-Aug-31 16:28:28 (local)
2005-Aug-31 14:28:28 (UTC)
User:rse
Branch:
Comment: Cleanup the internals of the uuid_create() function and add a new corresponding uuid_clone() API function.
Tickets:
Inspections:
Files:
ossp-pkg/uuid/ChangeLog      1.82 -> 1.83     4 inserted, 0 deleted
ossp-pkg/uuid/uuid.c      1.52 -> 1.53     49 inserted, 14 deleted
ossp-pkg/uuid/uuid.h.in      1.7 -> 1.8     1 inserted, 0 deleted

ossp-pkg/uuid/ChangeLog 1.82 -> 1.83

--- ChangeLog    2005/08/31 12:59:58     1.82
+++ ChangeLog    2005/08/31 14:28:28     1.83
@@ -13,6 +13,10 @@
 
   Changes between 1.2.1 and 1.3.0 (30-Aug-2005 to xx-XXX-2005)
 
+   o Cleanup the internals of the uuid_create() function and
+     add a new corresponding uuid_clone() API function.
+     [Ralf S. Engelschall]
+
    o Cleanup some Makefile parts.
      [Ralf S. Engelschall]
 


ossp-pkg/uuid/uuid.c 1.52 -> 1.53

--- uuid.c       2005/08/30 20:34:35     1.52
+++ uuid.c       2005/08/31 14:28:28     1.53
@@ -92,35 +92,40 @@
 /* create UUID object */
 uuid_rc_t uuid_create(uuid_t **uuid)
 {
+    uuid_t *obj;
+
     /* argument sanity check */
     if (uuid == NULL)
         return UUID_RC_ARG;
 
     /* allocate UUID object */
-    if ((*uuid = (uuid_t *)malloc(sizeof(uuid_t))) == NULL)
+    if ((obj = (uuid_t *)malloc(sizeof(uuid_t))) == NULL)
         return UUID_RC_MEM;
 
-    /* set UUID object initially to "Nil UUID" */
-    uuid_load(*uuid, "nil");
-
-    /* create PRNG and MD5 sub-objects */
-    if (prng_create(&(*uuid)->prng) != PRNG_RC_OK)
+    /* create PRNG, MD5 and SHA1 sub-objects */
+    if (prng_create(&obj->prng) != PRNG_RC_OK)
         return UUID_RC_INT;
-    if (md5_create(&(*uuid)->md5) != MD5_RC_OK)
+    if (md5_create(&obj->md5) != MD5_RC_OK)
         return UUID_RC_INT;
-    if (sha1_create(&(*uuid)->sha1) != SHA1_RC_OK)
+    if (sha1_create(&obj->sha1) != SHA1_RC_OK)
         return UUID_RC_INT;
 
+    /* set UUID object initially to "Nil UUID" */
+    uuid_load(obj, "nil");
+
     /* resolve MAC address for insertion into node field of UUIDs */
-    if (!mac_address((unsigned char *)((*uuid)->mac), sizeof((*uuid)->mac))) {
-        memset((*uuid)->mac, '\0', sizeof((*uuid)->mac));
-        (*uuid)->mac[0] = BM_OCTET(1,0,0,0,0,0,0,0);
+    if (!mac_address((unsigned char *)(obj->mac), sizeof(obj->mac))) {
+        memset(obj->mac, '\0', sizeof(obj->mac));
+        obj->mac[0] = BM_OCTET(1,0,0,0,0,0,0,0);
     }
 
     /* initialize time attributes */
-    (*uuid)->time_last.tv_sec  = 0;
-    (*uuid)->time_last.tv_usec = 0;
-    (*uuid)->time_seq = 0;
+    obj->time_last.tv_sec  = 0;
+    obj->time_last.tv_usec = 0;
+    obj->time_seq = 0;
+
+    /* store result object */
+    *uuid = obj;
 
     return UUID_RC_OK;
 }
@@ -142,6 +147,36 @@
 
     return UUID_RC_OK;
 }
+
+/* clone UUID object */
+uuid_rc_t uuid_clone(uuid_t *uuid, uuid_t **clone)
+{
+    uuid_t *obj;
+
+    /* argument sanity check */
+    if (uuid == NULL || uuid_clone == NULL)
+        return UUID_RC_ARG;
+
+    /* allocate UUID object */
+    if ((obj = (uuid_t *)malloc(sizeof(uuid_t))) == NULL)
+        return UUID_RC_MEM;
+
+    /* clone entire internal state */
+    memcpy(obj, uuid, sizeof(uuid));
+
+    /* re-initialize with new PRNG, MD5 and SHA1 sub-objects */
+    if (prng_create(&obj->prng) != PRNG_RC_OK)
+        return UUID_RC_INT;
+    if (md5_create(&obj->md5) != MD5_RC_OK)
+        return UUID_RC_INT;
+    if (sha1_create(&obj->sha1) != SHA1_RC_OK)
+        return UUID_RC_INT;
+
+    /* store result object */
+    *clone = obj;
+
+    return UUID_RC_OK;
+}
 
 /* check whether UUID object represents "Nil UUID" */
 uuid_rc_t uuid_isnil(const uuid_t *uuid, int *result)


ossp-pkg/uuid/uuid.h.in 1.7 -> 1.8

--- uuid.h.in    2005/03/29 19:01:41     1.7
+++ uuid.h.in    2005/08/31 14:28:28     1.8
@@ -84,6 +84,7 @@
 /* UUID object handling */
 extern uuid_rc_t     uuid_create   (uuid_t **_uuid);
 extern uuid_rc_t     uuid_destroy  (uuid_t  *_uuid);
+extern uuid_rc_t     uuid_clone    (uuid_t  *_uuid, uuid_t **_uuid_clone);
 
 /* UUID generation */
 extern uuid_rc_t     uuid_load     (uuid_t  *_uuid, const char *_name);

CVSTrac 2.0.1