OSSP CVS Repository

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

Check-in Number: 3703
Date: 2004-Jan-08 22:31:47 (local)
2004-Jan-08 21:31:47 (UTC)
User:rse
Branch:
Comment: introduce UUID versioning into API
Tickets:
Inspections:
Files:
ossp-pkg/uuid/uuid.c      1.2 -> 1.3     14 inserted, 1 deleted
ossp-pkg/uuid/uuid.h      1.2 -> 1.3     12 inserted, 1 deleted
ossp-pkg/uuid/uuid_cli.c      1.2 -> 1.3     38 inserted, 10 deleted
ossp-pkg/uuid/uuidtool.c      1.2 -> 1.3     38 inserted, 10 deleted

ossp-pkg/uuid/uuid.c 1.2 -> 1.3

--- uuid.c       2004/01/06 20:43:34     1.2
+++ uuid.c       2004/01/08 21:31:47     1.3
@@ -29,6 +29,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdarg.h>
 #include <string.h>
 #include <unistd.h>
 
@@ -127,11 +128,15 @@
     return UUID_RC_OK;
 }
 
-uuid_rc_t uuid_generate(uuid_t *uuid)
+uuid_rc_t uuid_generate(uuid_t *uuid, unsigned int mode, ...)
 {
+    va_list ap;
+
     if (uuid == NULL)
         return UUID_RC_ARG;
+    va_start(ap, mode);
     /* FIXME */
+    va_end(ap);
     return UUID_RC_OK;
 }
 
@@ -241,6 +246,14 @@
         return UUID_RC_ARG;
     /* FIXME */
     return UUID_RC_OK;
+}
+
+uuid_rc_t uuid_dump(uuid_t *uuid, char **str)
+{
+    if (uuid == NULL || str == NULL)
+        return UUID_RC_ARG;
+    /* FIXME */
+    return UUID_RC_OK;
 }
 
 char *uuid_error(uuid_rc_t rc)


ossp-pkg/uuid/uuid.h 1.2 -> 1.3

--- uuid.h       2004/01/06 20:29:51     1.2
+++ uuid.h       2004/01/08 21:31:47     1.3
@@ -79,6 +79,14 @@
     UUID_RC_SYS = 3
 } uuid_rc_t;
 
+/* generation mode flags */
+enum {
+    UUID_VERSION1      = (1 << 0),
+    UUID_VERSION3      = (1 << 1),
+    UUID_VERSION4      = (1 << 2),
+    UUID_MCASTRND      = (1 << 3)
+};
+
 /* abstract data type */
 struct uuid_st;
 typedef struct uuid_st uuid_t;
@@ -93,7 +101,7 @@
 extern uuid_rc_t  uuid_isnull   (uuid_t  *uuid,                int *result);
 
 /* UUID generation */
-extern uuid_rc_t  uuid_generate (uuid_t  *uuid);
+extern uuid_rc_t  uuid_generate (uuid_t  *uuid, unsigned int mode, ...);
 
 /* string representation handling */
 extern uuid_rc_t  uuid_parse    (uuid_t  *uuid, const char  *str);
@@ -103,6 +111,9 @@
 extern uuid_rc_t  uuid_read     (uuid_t  *uuid, const void  *buf);
 extern uuid_rc_t  uuid_write    (uuid_t  *uuid,       void **buf);
 
+/* UUID dumping */
+extern uuid_rc_t  uuid_dump     (uuid_t  *uuid, char **str);
+
 /* error handling */
 extern char      *uuid_error    (uuid_rc_t rc);
 


ossp-pkg/uuid/uuid_cli.c 1.2 -> 1.3

--- uuid_cli.c   2004/01/06 20:29:51     1.2
+++ uuid_cli.c   2004/01/08 21:31:47     1.3
@@ -52,9 +52,18 @@
 
 /* usage handler */
 static void
-usage(void)
+usage(const char *str, ...)
 {
+    va_list ap;
+
+    va_start(ap, str);
+    if (str != NULL) {
+        fprintf(stderr, "uuid:ERROR: ");
+        vfprintf(stderr, str, ap);
+        fprintf(stderr, "\n");
+    }
     fprintf(stderr, "usage: uuid [-1] [-n count] [-a] [-d] [-o filename] [UUID]\n");
+    va_end(ap);
     exit(1);
 }
 
@@ -73,6 +82,7 @@
     int decode;
     char *cp;
     void *vp;
+    unsigned int version;
 
     /* command line parsing */
     count = -1;     /* no count yet */
@@ -80,17 +90,18 @@
     iterate = 0;    /* not one at a time */
     ascii = 0;      /* default is binary output */
     decode = 0;     /* default is to encode */
-    while ((ch = getopt(argc, argv, "1n:ado:")) != -1) {
+    version = UUID_VERSION1;
+    while ((ch = getopt(argc, argv, "1n:ado:v:")) != -1) {
         switch (ch) {
             case '1':
                 iterate = 1;
                 break;
             case 'n':
                 if (count > 0)
-                    usage();
+                    usage("option 'n' specified multiple times");
                 count = strtol(optarg, &p, 10);
-                if (*p != 0 || count < 1)
-                    usage();
+                if (*p != '\0' || count < 1)
+                    usage("invalid argument to option 'n'");
                 break;
             case 'a':
                 ascii = 1;
@@ -104,8 +115,21 @@
                 if ((fp = fopen(optarg, "w")) == NULL)
                     error(1, "fopen: %s", strerror(errno));
                 break;
+            case 'v':
+                i = strtol(optarg, &p, 10);
+                if (*p != '\0')
+                    usage("invalid argument to option 'v'");
+                switch (i) {
+                    case 1: version = UUID_VERSION1; break;;
+                    case 3: version = UUID_VERSION3; break;;
+                    case 4: version = UUID_VERSION4; break;;
+                    default:
+                        usage("invalid version on option 'v'");
+                        break;
+                }
+                break;
             default:
-                usage();
+                usage("invalid option '%c'", ch);
         }
     }
     argv += optind;
@@ -116,13 +140,13 @@
     if (decode) {
         /* decoding */
         if (argc != 1)
-            usage();
+            usage("invalid number of arguments");
         /* FIXME */
     }
     else {
         /* encoding */
-        if (argc < 0 || argc > 1)
-            usage();
+        if (argc < 0 || ((version == UUID_VERSION3 && argc > 2) || argc > 1))
+            usage("invalid number of arguments");
         if ((rc = uuid_create(&uuid)) != UUID_RC_OK)
             error(1, "uuid_create: %s", uuid_error(rc));
         if (argc == 1) {
@@ -135,7 +159,11 @@
                 if ((rc = uuid_null(uuid)) != UUID_RC_OK)
                     error(1, "uuid_null: %s", uuid_error(rc));
             }
-            if ((rc = uuid_generate(uuid)) != UUID_RC_OK)
+            if (version == UUID_VERSION3)
+                rc = uuid_generate(uuid, version, argv[0]);
+            else
+                rc = uuid_generate(uuid, version);
+            if (rc != UUID_RC_OK)
                 error(1, "uuid_generate: %s", uuid_error(rc));
             if (ascii) {
                 cp = NULL;


CVSTrac 2.0.1