merge in euid generation from master
[citadel.git] / libcitadel / lib / tools.c
index 4a8eb6baaf108b426f256b5c6194599f2dce4754..0c012e7955e184d128b589ad547b1bf645ebb767 100644 (file)
@@ -858,12 +858,20 @@ char *strcpy(char *dest, const char *src) {
  * Generate a new, globally unique UID parameter for a calendar etc. object
  */
 void generate_uuid(char *buf) {
-       static int seq = 0;
+       static int seq = (-1);
 
-       sprintf(buf, "%lx-%lx-%x",
-               time(NULL),
+       if (seq == (-1)) {
+               seq = (int)rand();
+       }
+       ++seq;
+       seq = (seq % 0x0FFF) ;
+
+       sprintf(buf, "%08lx-%04lx-4%03x-a%03x-%012lx",
+               (long)time(NULL),
                (long)getpid(),
-               (seq++)
+               seq,
+               seq,
+               (long)rand()
        );
 }