Changeset: b2c9f7c667cd for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b2c9f7c667cd
Modified Files:
common/utils/Makefile.ag
common/utils/muuid.c
common/utils/muuid.h
tools/merovingian/client/Makefile.ag
tools/merovingian/daemon/Makefile.ag
tools/merovingian/utils/properties.c
tools/merovingian/utils/utils.c
tools/merovingian/utils/utils.h
Branch: default
Log Message:
generateUUID: move from merovingian/utils to common/utils
Prepare for usage outside of merovingian of UUIDs.
diffs (222 lines):
diff --git a/common/utils/Makefile.ag b/common/utils/Makefile.ag
--- a/common/utils/Makefile.ag
+++ b/common/utils/Makefile.ag
@@ -23,10 +23,15 @@ INCLUDES = $(openssl_CFLAGS)
lib_mutils = {
NOINST
- SOURCES = mutils.c mutils.h
+ SOURCES = mutils.h mutils.c
}
lib_mcrypt = {
NOINST
SOURCES = mcrypt.h mcrypt.c
}
+
+lib_muuid = {
+ NOINST
+ SOURCES = muuid.h muuid.c
+}
diff --git a/common/utils/muuid.c b/common/utils/muuid.c
new file mode 100644
--- /dev/null
+++ b/common/utils/muuid.c
@@ -0,0 +1,68 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2011 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+/* NOTE: for this file to work correctly, the random number generator
+ * must have been seeded (srand) with something like the current time */
+
+#include "monetdb_config.h"
+#include "muuid.h"
+#include <stdlib.h> /* rand */
+#include <string.h> /* strdup */
+#ifdef HAVE_UUID_UUID_H
+# include <uuid/uuid.h>
+#endif
+
+/**
+ * Shallow wrapper around uuid, that comes up with some random pseudo
+ * uuid if uuid is not available
+ */
+char *
+generateUUID(void)
+{
+#ifdef HAVE_UUID_UUID_H
+# ifdef UUID_PRINTABLE_STRING_LENGTH
+ /* Solaris */
+ char out[UUID_PRINTABLE_STRING_LENGTH];
+# else
+ char out[37];
+# endif
+ uuid_t uuid;
+ uuid_generate(uuid);
+ uuid_unparse(uuid, out);
+#else
+ /* try to do some pseudo interesting stuff, and stash it in the
+ * format of an UUID to at least return some uniform answer */
+ char out[37];
+ char *p = out;
+
+ /* generate something like this:
+ * cefa7a9c-1dd2-11b2-8350-880020adbeef ("%08x-%04x-%04x-%04x-%012x") */
+ p += snprintf(p, 5, "%04x", rand() % 65536);
+ p += snprintf(p, 6, "%04x-", rand() % 65536);
+ p += snprintf(p, 6, "%04x-", rand() % 65536);
+ p += snprintf(p, 6, "%04x-", rand() % 65536);
+ p += snprintf(p, 6, "%04x-", rand() % 65536);
+ p += snprintf(p, 5, "%04x", rand() % 65536);
+ p += snprintf(p, 5, "%04x", rand() % 65536);
+ p += snprintf(p, 5, "%04x", rand() % 65536);
+#endif
+ return(strdup(out));
+}
+
+/* vim:set ts=4 sw=4 noexpandtab: */
diff --git a/common/utils/muuid.h b/common/utils/muuid.h
new file mode 100644
--- /dev/null
+++ b/common/utils/muuid.h
@@ -0,0 +1,27 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2011 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+#ifndef _SEEN_MUUID_H
+#define _SEEN_MUUID_H 1
+
+char *generateUUID(void);
+
+#endif
+
+/* vim:set ts=4 sw=4 noexpandtab: */
diff --git a/tools/merovingian/client/Makefile.ag
b/tools/merovingian/client/Makefile.ag
--- a/tools/merovingian/client/Makefile.ag
+++ b/tools/merovingian/client/Makefile.ag
@@ -33,6 +33,7 @@ bin_monetdb = {
../../../common/stream/libstream \
../../../common/utils/libmutils \
../../../common/utils/libmcrypt \
+ ../../../common/utils/libmuuid \
$(UUID_LIBS) \
$(openssl_LIBS) \
$(curl_LIBS) \
diff --git a/tools/merovingian/daemon/Makefile.ag
b/tools/merovingian/daemon/Makefile.ag
--- a/tools/merovingian/daemon/Makefile.ag
+++ b/tools/merovingian/daemon/Makefile.ag
@@ -55,6 +55,7 @@ bin_monetdbd = {
../../../clients/mapilib/libmapi \
../../../common/utils/libmutils \
../../../common/utils/libmcrypt \
+ ../../../common/utils/libmuuid \
$(UUID_LIBS) \
$(curl_LIBS) \
$(SOCKET_LIBS) \
diff --git a/tools/merovingian/utils/properties.c
b/tools/merovingian/utils/properties.c
--- a/tools/merovingian/utils/properties.c
+++ b/tools/merovingian/utils/properties.c
@@ -26,6 +26,7 @@
#include "monetdb_config.h"
#include "properties.h"
#include "utils.h"
+#include "muuid.h"
#include <stdio.h> /* fprintf, fgets */
#include <string.h> /* memcpy */
diff --git a/tools/merovingian/utils/utils.c b/tools/merovingian/utils/utils.c
--- a/tools/merovingian/utils/utils.c
+++ b/tools/merovingian/utils/utils.c
@@ -35,9 +35,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#ifdef HAVE_UUID_UUID_H
-# include <uuid/uuid.h>
-#endif
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
@@ -361,39 +358,6 @@ generatePassphraseFile(char *path)
return(NULL);
}
-char *
-generateUUID(void)
-{
-#ifdef HAVE_UUID_UUID_H
-# ifdef UUID_PRINTABLE_STRING_LENGTH
- /* Solaris */
- char out[UUID_PRINTABLE_STRING_LENGTH];
-# else
- char out[37];
-# endif
- uuid_t uuid;
- uuid_generate(uuid);
- uuid_unparse(uuid, out);
-#else
- /* try to do some pseudo interesting stuff, and stash it in the
- * format of an UUID to at least return some uniform answer */
- char out[37];
- char *p = out;
-
- /* generate something like this:
- * cefa7a9c-1dd2-11b2-8350-880020adbeef ("%08x-%04x-%04x-%04x-%012x") */
- p += snprintf(p, 5, "%04x", rand() % 65536);
- p += snprintf(p, 6, "%04x-", rand() % 65536);
- p += snprintf(p, 6, "%04x-", rand() % 65536);
- p += snprintf(p, 6, "%04x-", rand() % 65536);
- p += snprintf(p, 6, "%04x-", rand() % 65536);
- p += snprintf(p, 5, "%04x", rand() % 65536);
- p += snprintf(p, 5, "%04x", rand() % 65536);
- p += snprintf(p, 5, "%04x", rand() % 65536);
-#endif
- return(strdup(out));
-}
-
void
sleep_ms(size_t ms)
{
diff --git a/tools/merovingian/utils/utils.h b/tools/merovingian/utils/utils.h
--- a/tools/merovingian/utils/utils.h
+++ b/tools/merovingian/utils/utils.h
@@ -49,7 +49,6 @@ void secondsToString(char *buf, time_t t
void abbreviateString(char *ret, const char *in, size_t width);
void generateSalt(char *buf, unsigned int len);
char *generatePassphraseFile(char *path);
-char *generateUUID(void);
void sleep_ms(size_t ms);
#endif
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list