summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2002-07-17 04:11:33 +0000
committerwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2002-07-17 04:11:33 +0000
commit605b54192e0415842a035a92d184dc42b3b9f3b7 (patch)
tree25abd7ec9408454b845528ded5902165d9dbad20
parent9f711f6f3be61c88fe4e086bf0e38fe1ebe241d3 (diff)
downloadlibapr-605b54192e0415842a035a92d184dc42b3b9f3b7.tar.gz
Move UUID. Not the simplest thing in the world. Note that almost
all the remaining getuuid.c source should be made generic. I just grabbed what my compiler tripped over. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@63696 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--apr.dsp12
-rw-r--r--include/apr.h.in1
-rw-r--r--include/apr.hnw1
-rw-r--r--include/apr.hw1
-rw-r--r--include/apr_portable.h8
-rw-r--r--include/apr_uuid.h114
-rw-r--r--libapr.dsp12
-rw-r--r--misc/unix/Makefile.in3
-rw-r--r--misc/unix/getuuid.c240
-rw-r--r--misc/unix/uuid.c134
-rw-r--r--misc/win32/getuuid.c81
-rw-r--r--misc/win32/rand.c23
-rw-r--r--test/Makefile.in4
-rw-r--r--test/testuuid.c96
14 files changed, 34 insertions, 696 deletions
diff --git a/apr.dsp b/apr.dsp
index 72ce1805c..539fb6578 100644
--- a/apr.dsp
+++ b/apr.dsp
@@ -206,10 +206,6 @@ SOURCE=.\misc\unix\getopt.c
# End Source File
# Begin Source File
-SOURCE=.\misc\win32\getuuid.c
-# End Source File
-# Begin Source File
-
SOURCE=.\misc\win32\internal.c
# End Source File
# Begin Source File
@@ -234,10 +230,6 @@ SOURCE=.\misc\win32\utf8.c
# End Source File
# Begin Source File
-SOURCE=.\misc\unix\uuid.c
-# End Source File
-# Begin Source File
-
SOURCE=.\misc\unix\version.c
# End Source File
# End Group
@@ -601,10 +593,6 @@ SOURCE=.\include\apr_user.h
# End Source File
# Begin Source File
-SOURCE=.\include\apr_uuid.h
-# End Source File
-# Begin Source File
-
SOURCE=.\include\apr_want.h
# End Source File
# Begin Source File
diff --git a/include/apr.h.in b/include/apr.h.in
index 432f1cb7e..ea9caf161 100644
--- a/include/apr.h.in
+++ b/include/apr.h.in
@@ -146,6 +146,7 @@
#define APR_HAS_USER 1
#define APR_HAS_LARGE_FILES 0
#define APR_HAS_XTHREAD_FILES 0
+#define APR_HAS_OS_UUID 0
/* APR sets APR_FILES_AS_SOCKETS to 1 on systems where it is possible
* to poll on files/pipes. On such a system, the application can
diff --git a/include/apr.hnw b/include/apr.hnw
index 009b883c8..063c9f80d 100644
--- a/include/apr.hnw
+++ b/include/apr.hnw
@@ -209,6 +209,7 @@
#define APR_HAS_USER 1
#define APR_HAS_LARGE_FILES 0
#define APR_HAS_XTHREAD_FILES 0
+#define APR_HAS_OS_UUID 0
/* Not all platforms have a real INADDR_NONE. This macro replaces INADDR_NONE
* on all platforms.
diff --git a/include/apr.hw b/include/apr.hw
index 207441454..75a328973 100644
--- a/include/apr.hw
+++ b/include/apr.hw
@@ -297,6 +297,7 @@ extern "C" {
#define APR_HAS_LARGE_FILES 0
#define APR_HAS_XTHREAD_FILES 0
#endif
+#define APR_HAS_OS_UUID 1
/* Not all platforms have a real INADDR_NONE. This macro replaces INADDR_NONE
* on all platforms.
diff --git a/include/apr_portable.h b/include/apr_portable.h
index d4388d633..1b73c6caf 100644
--- a/include/apr_portable.h
+++ b/include/apr_portable.h
@@ -463,6 +463,14 @@ APR_DECLARE(apr_status_t) apr_os_dso_handle_put(apr_dso_handle_t **dso,
*/
APR_DECLARE(apr_status_t) apr_os_dso_handle_get(apr_os_dso_handle_t *dso,
apr_dso_handle_t *aprdso);
+
+#if APR_HAS_OS_UUID
+/**
+ * Private: apr-util's apr_uuid module when supported by the platform
+ */
+APR_DECLARE(apr_status_t) apr_os_uuid_get(unsigned char *uuid_data);
+#endif
+
/** @} */
#endif /* APR_HAS_DSO */
diff --git a/include/apr_uuid.h b/include/apr_uuid.h
deleted file mode 100644
index 48fe2c41f..000000000
--- a/include/apr_uuid.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-/**
- * @file apr_uuid.h
- * @brief APR UUID library
- */
-#ifndef APR_UUID_H
-#define APR_UUID_H
-
-#include "apr.h"
-#include "apr_errno.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-/**
- * @defgroup APR_UUID UUID Handling
- * @ingroup APR
- * @{
- */
-
-/**
- * we represent a UUID as a block of 16 bytes.
- */
-
-typedef struct {
- unsigned char data[16]; /**< the actual UUID */
-} apr_uuid_t;
-
-/** UUIDs are formatted as: 00112233-4455-6677-8899-AABBCCDDEEFF */
-#define APR_UUID_FORMATTED_LENGTH 36
-
-
-/**
- * Generate and return a (new) UUID
- * @param uuid The resulting UUID
- */
-APR_DECLARE(void) apr_uuid_get(apr_uuid_t *uuid);
-
-/**
- * Format a UUID into a string, following the standard format
- * @param buffer The buffer to place the formatted UUID string into. It must
- * be at least APR_UUID_FORMATTED_LENGTH + 1 bytes long to hold
- * the formatted UUID and a null terminator
- * @param uuid The UUID to format
- */
-APR_DECLARE(void) apr_uuid_format(char *buffer, const apr_uuid_t *uuid);
-
-/**
- * Parse a standard-format string into a UUID
- * @param uuid The resulting UUID
- * @param uuid_str The formatted UUID
- */
-APR_DECLARE(apr_status_t) apr_uuid_parse(apr_uuid_t *uuid, const char *uuid_str);
-
-/** @} */
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* APR_UUID_H */
diff --git a/libapr.dsp b/libapr.dsp
index d639848fc..fd48cb056 100644
--- a/libapr.dsp
+++ b/libapr.dsp
@@ -212,10 +212,6 @@ SOURCE=.\misc\unix\getopt.c
# End Source File
# Begin Source File
-SOURCE=.\misc\win32\getuuid.c
-# End Source File
-# Begin Source File
-
SOURCE=.\misc\win32\internal.c
# End Source File
# Begin Source File
@@ -240,10 +236,6 @@ SOURCE=.\misc\win32\utf8.c
# End Source File
# Begin Source File
-SOURCE=.\misc\unix\uuid.c
-# End Source File
-# Begin Source File
-
SOURCE=.\misc\unix\version.c
# End Source File
# End Group
@@ -607,10 +599,6 @@ SOURCE=.\include\apr_user.h
# End Source File
# Begin Source File
-SOURCE=.\include\apr_uuid.h
-# End Source File
-# Begin Source File
-
SOURCE=.\include\apr_want.h
# End Source File
# Begin Source File
diff --git a/misc/unix/Makefile.in b/misc/unix/Makefile.in
index 9d9a91f52..76366dbb8 100644
--- a/misc/unix/Makefile.in
+++ b/misc/unix/Makefile.in
@@ -2,8 +2,7 @@ srcdir = @srcdir@
VPATH = @srcdir@
TARGETS = \
- start.lo getopt.lo otherchild.lo errorcodes.lo rand.lo \
- uuid.lo getuuid.lo version.lo
+ start.lo getopt.lo otherchild.lo errorcodes.lo rand.lo version.lo
# bring in rules.mk for standard functionality
@INCLUDE_RULES@
diff --git a/misc/unix/getuuid.c b/misc/unix/getuuid.c
deleted file mode 100644
index 97c3a9d23..000000000
--- a/misc/unix/getuuid.c
+++ /dev/null
@@ -1,240 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-/*
- * This attempts to generate V1 UUIDs according to the Internet Draft
- * located at http://www.webdav.org/specs/draft-leach-uuids-guids-01.txt
- */
-
-#include <unistd.h> /* for getpid, gethostname */
-#include <stdlib.h> /* for rand, srand */
-
-#include "apr.h"
-#include "apr_private.h"
-#include "apr_uuid.h"
-#include "apr_md5.h"
-#include "apr_general.h"
-#if APR_HAVE_STRING_H
-#include <string.h>
-#endif
-#if APR_HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#if APR_HAVE_NETDB_H
-#include <netdb.h>
-#endif
-#if APR_HAVE_SYS_TIME_H
-#include <sys/time.h> /* for gettimeofday */
-#endif
-
-#define NODE_LENGTH 6
-
-static int uuid_state_seqnum;
-static unsigned char uuid_state_node[NODE_LENGTH] = { 0 };
-
-
-static void get_random_info(unsigned char node[NODE_LENGTH])
-{
-#if APR_HAS_RANDOM
-
- (void) apr_generate_random_bytes(node, NODE_LENGTH);
-
-#else
-
- unsigned char seed[MD5_DIGESTSIZE];
- apr_md5_ctx_t c;
-
- /* ### probably should revise some of this to be a bit more portable */
-
- /* Leach & Salz use Linux-specific struct sysinfo;
- * replace with pid/tid for portability (in the spirit of mod_unique_id) */
- struct {
- /* Add thread id here, if applicable, when we get to pthread or apr */
- pid_t pid;
-#ifdef NETWARE
- apr_uint64_t t;
-#else
- struct timeval t;
-#endif
- char hostname[257];
-
- } r;
-
- apr_md5_init(&c);
-#ifdef NETWARE
- r.pid = NXThreadGetId();
- NXGetTime(NX_SINCE_BOOT, NX_USECONDS, &(r.t));
-#else
- r.pid = getpid();
- gettimeofday(&r.t, (struct timezone *)0);
-#endif
- gethostname(r.hostname, 256);
- apr_md5_update(&c, (const unsigned char *)&r, sizeof(r));
- apr_md5_final(seed, &c);
-
- memcpy(node, seed, NODE_LENGTH); /* use a subset of the seed bytes */
-#endif
-}
-
-/* This implementation generates a random node ID instead of a
- system-dependent call to get IEEE node ID. This is also more secure:
- we aren't passing out our MAC address.
-*/
-static void get_pseudo_node_identifier(unsigned char *node)
-{
- get_random_info(node);
- node[0] |= 0x80; /* this designates a random node ID */
-}
-
-static void get_system_time(apr_uint64_t *uuid_time)
-{
-#ifdef NETWARE
- uint64_t sec;
-
- NXGetTime(NX_SINCE_1970, NX_SECONDS, &sec);
- *uuid_time = (sec * 10000000) + 0x01B21DD213814000LL;
-#else
- struct timeval tp;
-
- /* ### fix this call to be more portable? */
- gettimeofday(&tp, (struct timezone *)0);
-
- /* Offset between UUID formatted times and Unix formatted times.
- UUID UTC base time is October 15, 1582.
- Unix base time is January 1, 1970. */
- *uuid_time = (tp.tv_sec * 10000000) + (tp.tv_usec * 10) +
- 0x01B21DD213814000LL;
-#endif
-}
-
-/* true_random -- generate a crypto-quality random number. */
-static int true_random(void)
-{
- apr_uint64_t time_now;
-
-#if APR_HAS_RANDOM
- unsigned char buf[2];
-
- if (apr_generate_random_bytes(buf, 2) == APR_SUCCESS) {
- return (buf[0] << 8) | buf[1];
- }
-#endif
-
- /* crap. this isn't crypto quality, but it will be Good Enough */
-
- get_system_time(&time_now);
- srand((unsigned int)(((time_now >> 32) ^ time_now) & 0xffffffff));
-
- return rand() & 0x0FFFF;
-}
-
-static void init_state(void)
-{
- uuid_state_seqnum = true_random();
- get_pseudo_node_identifier(uuid_state_node);
-}
-
-static void get_current_time(apr_uint64_t *timestamp)
-{
- /* ### this needs to be made thread-safe! */
-
- apr_uint64_t time_now;
- static apr_uint64_t time_last = 0;
- static int fudge = 0;
-
- get_system_time(&time_now);
-
- /* if clock reading changed since last UUID generated... */
- if (time_last != time_now) {
- /* The clock reading has changed since the last UUID was generated.
- Reset the fudge factor. if we are generating them too fast, then
- the fudge may need to be reset to something greater than zero. */
- if (time_last + fudge > time_now)
- fudge = time_last + fudge - time_now + 1;
- else
- fudge = 0;
- time_last = time_now;
- }
- else {
- /* We generated two really fast. Bump the fudge factor. */
- ++fudge;
- }
-
- *timestamp = time_now + fudge;
-}
-
-APR_DECLARE(void) apr_uuid_get(apr_uuid_t *uuid)
-{
- apr_uint64_t timestamp;
- unsigned char *d = uuid->data;
-
- if (!uuid_state_node[0])
- init_state();
-
- get_current_time(&timestamp);
-
- d[0] = (unsigned char)timestamp;
- d[1] = (unsigned char)(timestamp >> 8);
- d[2] = (unsigned char)(timestamp >> 16);
- d[3] = (unsigned char)(timestamp >> 24);
- d[4] = (unsigned char)(timestamp >> 32);
- d[5] = (unsigned char)(timestamp >> 40);
- d[6] = (unsigned char)(timestamp >> 48);
- d[7] = (unsigned char)(((timestamp >> 56) & 0x0F) | 0x10);
-
- d[8] = (unsigned char)(((uuid_state_seqnum >> 8) & 0x3F) | 0x80);
- d[9] = (unsigned char)uuid_state_seqnum;
-
- memcpy(&d[10], uuid_state_node, NODE_LENGTH);
-}
diff --git a/misc/unix/uuid.c b/misc/unix/uuid.c
deleted file mode 100644
index 48ed48a8d..000000000
--- a/misc/unix/uuid.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-#include <stdio.h> /* for sprintf */
-
-#include "apr.h"
-#include "apr_uuid.h"
-#include "apr_errno.h"
-#include "apr_lib.h"
-
-
-APR_DECLARE(void) apr_uuid_format(char *buffer, const apr_uuid_t *uuid)
-{
- const unsigned char *d = uuid->data;
-
- sprintf(buffer,
- "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
- d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],
- d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
-}
-
-/* convert a pair of hex digits to an integer value [0,255] */
-static unsigned char parse_hexpair(const char *s)
-{
- int result;
- int temp;
-
- result = s[0] - '0';
- if (result > 48)
- result = (result - 39) << 4;
- else if (result > 16)
- result = (result - 7) << 4;
- else
- result = result << 4;
-
- temp = s[1] - '0';
- if (temp > 48)
- result |= temp - 39;
- else if (temp > 16)
- result |= temp - 7;
- else
- result |= temp;
-
- return (unsigned char)result;
-}
-
-APR_DECLARE(apr_status_t) apr_uuid_parse(apr_uuid_t *uuid,
- const char *uuid_str)
-{
- int i;
- unsigned char *d = uuid->data;
-
- for (i = 0; i < 36; ++i) {
- char c = uuid_str[i];
- if (!apr_isxdigit(c) &&
- !(c == '-' && (i == 8 || i == 13 || i == 18 || i == 23)))
- /* ### need a better value */
- return APR_BADARG;
- }
- if (uuid_str[36] != '\0') {
- /* ### need a better value */
- return APR_BADARG;
- }
-
- d[0] = parse_hexpair(&uuid_str[0]);
- d[1] = parse_hexpair(&uuid_str[2]);
- d[2] = parse_hexpair(&uuid_str[4]);
- d[3] = parse_hexpair(&uuid_str[6]);
-
- d[4] = parse_hexpair(&uuid_str[9]);
- d[5] = parse_hexpair(&uuid_str[11]);
-
- d[6] = parse_hexpair(&uuid_str[14]);
- d[7] = parse_hexpair(&uuid_str[16]);
-
- d[8] = parse_hexpair(&uuid_str[19]);
- d[9] = parse_hexpair(&uuid_str[21]);
-
- for (i = 6; i--;)
- d[10 + i] = parse_hexpair(&uuid_str[i*2+24]);
-
- return APR_SUCCESS;
-}
diff --git a/misc/win32/getuuid.c b/misc/win32/getuuid.c
deleted file mode 100644
index f04e128f7..000000000
--- a/misc/win32/getuuid.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-/*
- * This attempts to generate V1 UUIDs according to the Internet Draft
- * located at http://www.webdav.org/specs/draft-leach-uuids-guids-01.txt
- */
-
-#include <windows.h>
-#include <objbase.h>
-#include "apr.h"
-#include "apr_uuid.h"
-
-APR_DECLARE(void) apr_uuid_get(apr_uuid_t *uuid)
-{
- GUID guid;
-
- /* Note: this call doesn't actually require CoInitialize() first
- *
- * XXX: This is wrong (two ways) ... one we need to test the HRESULT
- * and if not S_OK (0) then we actually FAILED!
- *
- * Second, we should scramble the bytes or some such to eliminate the
- * possible misuse/abuse since uuid is based on the NIC address, and
- * is therefore not only a uniqifier, but an identity (which might not
- * be appropriate in all cases.
- */
- (void) CoCreateGuid(&guid);
- memcpy(uuid->data, &guid, sizeof(uuid->data));
-}
diff --git a/misc/win32/rand.c b/misc/win32/rand.c
index ca55caeba..0e3b47be6 100644
--- a/misc/win32/rand.c
+++ b/misc/win32/rand.c
@@ -52,10 +52,15 @@
* <http://www.apache.org/>.
*/
+#include <windows.h>
+#include <objbase.h>
+#include <wincrypt.h>
+#include "apr.h"
#include "apr_private.h"
#include "apr_general.h"
+#include "apr_portable.h"
#include "misc.h"
-#include <wincrypt.h>
+
APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf,
int length)
@@ -78,3 +83,19 @@ APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf,
CryptReleaseContext(hProv, 0);
return res;
}
+
+
+APR_DECLARE(apr_status_t) apr_os_uuid_get(unsigned char *uuid_data)
+{
+ /* Note: this call doesn't actually require CoInitialize() first
+ *
+ * XXX: we should scramble the bytes or some such to eliminate the
+ * possible misuse/abuse since uuid is based on the NIC address, and
+ * is therefore not only a uniqifier, but an identity (which might not
+ * be appropriate in all cases.
+ */
+ if (FAILED(CoCreateGuid((LPGUID)uuid_data))) {
+ return APR_EGENERAL;
+ }
+ return APR_SUCCESS;
+}
diff --git a/test/Makefile.in b/test/Makefile.in
index e373a3b3f..fc61f0d43 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -29,7 +29,6 @@ PROGRAMS = \
testshmconsumer@EXEEXT@ \
testpipe@EXEEXT@ \
testoc@EXEEXT@ \
- testuuid@EXEEXT@ \
testsockopt@EXEEXT@ \
testipsub@EXEEXT@ \
testpoll@EXEEXT@ \
@@ -143,9 +142,6 @@ testshmconsumer@EXEEXT@: testshmconsumer.lo $(LOCAL_LIBS)
testpipe@EXEEXT@: testpipe.lo $(LOCAL_LIBS)
$(LINK) testpipe.lo $(LOCAL_LIBS) $(ALL_LIBS)
-testuuid@EXEEXT@: testuuid.lo $(LOCAL_LIBS)
- $(LINK) testuuid.lo $(LOCAL_LIBS) $(ALL_LIBS)
-
testsockopt@EXEEXT@: testsockopt.lo $(LOCAL_LIBS)
$(LINK) testsockopt.lo $(LOCAL_LIBS) $(ALL_LIBS)
diff --git a/test/testuuid.c b/test/testuuid.c
deleted file mode 100644
index 8a691d812..000000000
--- a/test/testuuid.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "apr_general.h"
-#include "apr_uuid.h"
-
-
-int main(int argc, char **argv)
-{
- apr_uuid_t uuid;
- apr_uuid_t uuid2;
- char buf[APR_UUID_FORMATTED_LENGTH + 1];
- int retcode = 0;
-
- apr_initialize();
- atexit(apr_terminate);
-
- apr_uuid_get(&uuid);
- apr_uuid_format(buf, &uuid);
- printf("UUID: %s\n", buf);
-
- apr_uuid_parse(&uuid2, buf);
- if (memcmp(&uuid, &uuid2, sizeof(uuid)) == 0)
- printf("Parse appears to work.\n");
- else {
- printf("ERROR: parse produced a different UUID.\n");
- retcode = 1;
- }
-
- apr_uuid_format(buf, &uuid2);
- printf("parsed/reformatted UUID: %s\n", buf);
-
- /* generate two of them quickly */
- apr_uuid_get(&uuid);
- apr_uuid_get(&uuid2);
- apr_uuid_format(buf, &uuid);
- printf("UUID 1: %s\n", buf);
- apr_uuid_format(buf, &uuid2);
- printf("UUID 2: %s\n", buf);
-
- return retcode;
-}