Commit eab3ef8f authored by Karl-Hermann Wieners's avatar Karl-Hermann Wieners
Browse files

Moved creation of UUIDs to library utilities so they may be used by applications.

parent 1c4e468e
......@@ -211,6 +211,7 @@ src/cgribexlib.c -text
src/cksum.c -text
src/cksum.h -text
src/config.h.in -text
src/create_uuid.h -text
src/datetime.h -text
src/dmemory.c -text
src/dmemory.h -text
......@@ -342,8 +343,6 @@ tests/cksum_read.c -text
tests/cksum_verify.c -text
tests/cksum_write.c -text
tests/cksum_write_chunk.c -text
tests/create_uuid.c -text
tests/create_uuid.h -text
tests/deco2d_model.c -text
tests/ensure_array_size.c -text
tests/ensure_array_size.h -text
......
......@@ -39,6 +39,7 @@ libcdi_la_SOURCES = \
cksum.h \
cdi_cksum.c \
cdi_cksum.h \
create_uuid.h \
dtypes.h \
error.c \
error.h \
......
......@@ -468,6 +468,7 @@ libcdi_la_SOURCES = \
cksum.h \
cdi_cksum.c \
cdi_cksum.h \
create_uuid.h \
dtypes.h \
error.c \
error.h \
......
......@@ -2,6 +2,9 @@
# include "config.h"
#endif
#define _XOPEN_SOURCE 600
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <float.h>
......@@ -91,6 +94,84 @@ int str2uuid(const char *uuidstr, unsigned char *uuid)
return iret;
}
#ifdef HAVE_DECL_UUID_GENERATE
#include <sys/time.h>
#include <uuid/uuid.h>
void
create_uuid(unsigned char *uuid)
{
static int uuid_seeded = 0;
static char uuid_rand_state[31 * sizeof (long)];
char *caller_rand_state;
if (uuid_seeded)
caller_rand_state = setstate(uuid_rand_state);
else
{
struct timeval tv;
int status = gettimeofday(&tv, NULL);
if (status != 0)
{
perror("uuid random seed generation failed!");
exit(1);
}
unsigned seed = (unsigned)(tv.tv_sec ^ tv.tv_usec);
caller_rand_state = initstate(seed, uuid_rand_state,
sizeof (uuid_rand_state));
uuid_seeded = 1;
}
uuid_generate(uuid);
setstate(caller_rand_state);
}
#elif defined (HAVE_DECL_UUID_CREATE)
typedef uint8_t u_int8_t;
typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t;
#include <uuid.h>
void
create_uuid(unsigned char *uuid)
{
unsigned32 status;
uuid_create((uuid_t *)uuid, &status);
if (status == -1)
{
perror("uuid generation failed!");
exit(1);
}
}
#else
#include <sys/time.h>
void
create_uuid(unsigned char *uuid)
{
static int uuid_seeded = 0;
static char uuid_rand_state[31 * sizeof (long)];
char *caller_rand_state;
if (uuid_seeded)
caller_rand_state = setstate(uuid_rand_state);
else
{
struct timeval tv;
int status = gettimeofday(&tv, NULL);
if (status != 0)
{
perror("failed seed generation!");
exit(1);
}
unsigned seed = tv.tv_sec ^ tv.tv_usec;
caller_rand_state = initstate(seed, uuid_rand_state,
sizeof (uuid_rand_state));
uuid_seeded = 1;
}
for (size_t i = 0; i < CDI_UUID_SIZE; ++i)
uuid[i] = (unsigned char)random();
/* encode variant into msb of octet 8 */
uuid[8] = (unsigned char)((uuid[8] & 0x3f) | (1 << 7));
/* encode version 4 ((pseudo-)random uuid) into msb of octet 7 */
uuid[7] = (unsigned char)((uuid[7] & 0x0f) | (4 << 4));
setstate(caller_rand_state);
}
#endif
/*
* Local Variables:
* c-file-style: "Java"
......
......@@ -26,16 +26,12 @@ cksum_read_SOURCES = cksum_read.c \
stream_cksum.c stream_cksum.h \
ensure_array_size.h ensure_array_size.c
pio_write_SOURCES = pio_write.c pio_write.h simple_model.c \
simple_model_helper.h simple_model_helper.c \
create_uuid.h create_uuid.c
simple_model_helper.h simple_model_helper.c
pio_write_deco2d_SOURCES = pio_write.c pio_write.h deco2d_model.c \
simple_model_helper.h simple_model_helper.c \
create_uuid.h create_uuid.c
test_resource_copy_SOURCES = test_resource_copy.c \
create_uuid.h create_uuid.c
simple_model_helper.h simple_model_helper.c
test_resource_copy_SOURCES = test_resource_copy.c
test_resource_copy_LDADD = $(UUID_C_LIB) ../src/libcdiresunpack.la $(LDADD)
test_resource_copy_mpi_SOURCES = test_resource_copy.c \
create_uuid.h create_uuid.c
test_resource_copy_mpi_SOURCES = test_resource_copy.c
test_cdf_write_SOURCES = test_cdf_write.c
test_cdf_read_SOURCES = test_cdf_read.c
......
......@@ -159,7 +159,7 @@ cksum_write_chunk_OBJECTS = $(am_cksum_write_chunk_OBJECTS)
cksum_write_chunk_LDADD = $(LDADD)
cksum_write_chunk_DEPENDENCIES = ../src/libcdi.la
am_pio_write_OBJECTS = pio_write.$(OBJEXT) simple_model.$(OBJEXT) \
simple_model_helper.$(OBJEXT) create_uuid.$(OBJEXT)
simple_model_helper.$(OBJEXT)
pio_write_OBJECTS = $(am_pio_write_OBJECTS)
am__DEPENDENCIES_1 = ../src/libcdi.la
am__DEPENDENCIES_2 =
......@@ -168,8 +168,7 @@ am__DEPENDENCIES_2 =
@USE_MPI_TRUE@pio_write_DEPENDENCIES = ../src/libcdipio.la \
@USE_MPI_TRUE@ $(am__DEPENDENCIES_2)
am_pio_write_deco2d_OBJECTS = pio_write.$(OBJEXT) \
deco2d_model.$(OBJEXT) simple_model_helper.$(OBJEXT) \
create_uuid.$(OBJEXT)
deco2d_model.$(OBJEXT) simple_model_helper.$(OBJEXT)
pio_write_deco2d_OBJECTS = $(am_pio_write_deco2d_OBJECTS)
@USE_MPI_FALSE@pio_write_deco2d_DEPENDENCIES = $(am__DEPENDENCIES_1) \
@USE_MPI_FALSE@ $(am__DEPENDENCIES_2)
......@@ -187,14 +186,12 @@ am_test_grib_OBJECTS = test_grib.$(OBJEXT)
test_grib_OBJECTS = $(am_test_grib_OBJECTS)
test_grib_LDADD = $(LDADD)
test_grib_DEPENDENCIES = ../src/libcdi.la
am_test_resource_copy_OBJECTS = test_resource_copy.$(OBJEXT) \
create_uuid.$(OBJEXT)
am_test_resource_copy_OBJECTS = test_resource_copy.$(OBJEXT)
test_resource_copy_OBJECTS = $(am_test_resource_copy_OBJECTS)
test_resource_copy_DEPENDENCIES = $(am__DEPENDENCIES_2) \
../src/libcdiresunpack.la $(am__DEPENDENCIES_1)
am_test_resource_copy_mpi_OBJECTS = \
test_resource_copy_mpi-test_resource_copy.$(OBJEXT) \
test_resource_copy_mpi-create_uuid.$(OBJEXT)
test_resource_copy_mpi-test_resource_copy.$(OBJEXT)
test_resource_copy_mpi_OBJECTS = $(am_test_resource_copy_mpi_OBJECTS)
@USE_MPI_FALSE@test_resource_copy_mpi_DEPENDENCIES = \
@USE_MPI_FALSE@ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
......@@ -496,20 +493,14 @@ cksum_read_SOURCES = cksum_read.c \
ensure_array_size.h ensure_array_size.c
pio_write_SOURCES = pio_write.c pio_write.h simple_model.c \
simple_model_helper.h simple_model_helper.c \
create_uuid.h create_uuid.c
simple_model_helper.h simple_model_helper.c
pio_write_deco2d_SOURCES = pio_write.c pio_write.h deco2d_model.c \
simple_model_helper.h simple_model_helper.c \
create_uuid.h create_uuid.c
test_resource_copy_SOURCES = test_resource_copy.c \
create_uuid.h create_uuid.c
simple_model_helper.h simple_model_helper.c
test_resource_copy_SOURCES = test_resource_copy.c
test_resource_copy_LDADD = $(UUID_C_LIB) ../src/libcdiresunpack.la $(LDADD)
test_resource_copy_mpi_SOURCES = test_resource_copy.c \
create_uuid.h create_uuid.c
test_resource_copy_mpi_SOURCES = test_resource_copy.c
test_cdf_write_SOURCES = test_cdf_write.c
test_cdf_read_SOURCES = test_cdf_read.c
AM_CFLAGS = $(PPM_CORE_CFLAGS) $(YAXT_CFLAGS)
......@@ -662,7 +653,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_verify.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_write.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_write_chunk.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/create_uuid.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/deco2d_model.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ensure_array_size.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio_write.Po@am__quote@
......@@ -673,7 +663,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_cdf_write.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_grib.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_resource_copy.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_resource_copy_mpi-create_uuid.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_resource_copy_mpi-test_resource_copy.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/var_cksum.Po@am__quote@
......@@ -712,20 +701,6 @@ test_resource_copy_mpi-test_resource_copy.obj: test_resource_copy.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_resource_copy_mpi_CFLAGS) $(CFLAGS) -c -o test_resource_copy_mpi-test_resource_copy.obj `if test -f 'test_resource_copy.c'; then $(CYGPATH_W) 'test_resource_copy.c'; else $(CYGPATH_W) '$(srcdir)/test_resource_copy.c'; fi`
test_resource_copy_mpi-create_uuid.o: create_uuid.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_resource_copy_mpi_CFLAGS) $(CFLAGS) -MT test_resource_copy_mpi-create_uuid.o -MD -MP -MF $(DEPDIR)/test_resource_copy_mpi-create_uuid.Tpo -c -o test_resource_copy_mpi-create_uuid.o `test -f 'create_uuid.c' || echo '$(srcdir)/'`create_uuid.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_resource_copy_mpi-create_uuid.Tpo $(DEPDIR)/test_resource_copy_mpi-create_uuid.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='create_uuid.c' object='test_resource_copy_mpi-create_uuid.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_resource_copy_mpi_CFLAGS) $(CFLAGS) -c -o test_resource_copy_mpi-create_uuid.o `test -f 'create_uuid.c' || echo '$(srcdir)/'`create_uuid.c
test_resource_copy_mpi-create_uuid.obj: create_uuid.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_resource_copy_mpi_CFLAGS) $(CFLAGS) -MT test_resource_copy_mpi-create_uuid.obj -MD -MP -MF $(DEPDIR)/test_resource_copy_mpi-create_uuid.Tpo -c -o test_resource_copy_mpi-create_uuid.obj `if test -f 'create_uuid.c'; then $(CYGPATH_W) 'create_uuid.c'; else $(CYGPATH_W) '$(srcdir)/create_uuid.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_resource_copy_mpi-create_uuid.Tpo $(DEPDIR)/test_resource_copy_mpi-create_uuid.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='create_uuid.c' object='test_resource_copy_mpi-create_uuid.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_resource_copy_mpi_CFLAGS) $(CFLAGS) -c -o test_resource_copy_mpi-create_uuid.obj `if test -f 'create_uuid.c'; then $(CYGPATH_W) 'create_uuid.c'; else $(CYGPATH_W) '$(srcdir)/create_uuid.c'; fi`
mostlyclean-libtool:
-rm -f *.lo
......
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#define _XOPEN_SOURCE 600
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "create_uuid.h"
#ifdef HAVE_DECL_UUID_GENERATE
#include <sys/time.h>
#include <uuid/uuid.h>
void
create_uuid(unsigned char *uuid)
{
static int uuid_seeded = 0;
static char uuid_rand_state[31 * sizeof (long)];
char *caller_rand_state;
if (uuid_seeded)
caller_rand_state = setstate(uuid_rand_state);
else
{
struct timeval tv;
int status = gettimeofday(&tv, NULL);
if (status != 0)
{
perror("uuid random seed generation failed!");
exit(1);
}
unsigned seed = (unsigned)(tv.tv_sec ^ tv.tv_usec);
caller_rand_state = initstate(seed, uuid_rand_state,
sizeof (uuid_rand_state));
uuid_seeded = 1;
}
uuid_generate(uuid);
setstate(caller_rand_state);
}
#elif defined (HAVE_DECL_UUID_CREATE)
typedef uint8_t u_int8_t;
typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t;
#include <uuid.h>
void
create_uuid(unsigned char *uuid)
{
unsigned32 status;
uuid_create((uuid_t *)uuid, &status);
if (status == -1)
{
perror("uuid generation failed!");
exit(1);
}
}
#else
#include <sys/time.h>
void
create_uuid(unsigned char *uuid)
{
static int uuid_seeded = 0;
static char uuid_rand_state[31 * sizeof (long)];
char *caller_rand_state;
if (uuid_seeded)
caller_rand_state = setstate(uuid_rand_state);
else
{
struct timeval tv;
int status = gettimeofday(&tv, NULL);
if (status != 0)
{
perror("failed seed generation!");
exit(1);
}
unsigned seed = tv.tv_sec ^ tv.tv_usec;
caller_rand_state = initstate(seed, uuid_rand_state,
sizeof (uuid_rand_state));
uuid_seeded = 1;
}
for (size_t i = 0; i < CDI_UUID_SIZE; ++i)
uuid[i] = (unsigned char)random();
/* encode variant into msb of octet 8 */
uuid[8] = (unsigned char)((uuid[8] & 0x3f) | (1 << 7));
/* encode version 4 ((pseudo-)random uuid) into msb of octet 7 */
uuid[7] = (unsigned char)((uuid[7] & 0x0f) | (4 << 4));
setstate(caller_rand_state);
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment