Return-Path: Delivered-To: apmail-apr-cvs-archive@apr.apache.org Received: (qmail 33331 invoked by uid 500); 17 Jul 2002 04:11:35 -0000 Mailing-List: contact cvs-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: dev@apr.apache.org Delivered-To: mailing list cvs@apr.apache.org Received: (qmail 33319 invoked by uid 500); 17 Jul 2002 04:11:35 -0000 Delivered-To: apmail-apr-util-cvs@apache.org Date: 17 Jul 2002 04:11:34 -0000 Message-ID: <20020717041134.45094.qmail@icarus.apache.org> From: wrowe@apache.org To: apr-util-cvs@apache.org Subject: cvs commit: apr-util/test testuuid.c Makefile.in X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N wrowe 2002/07/16 21:11:33 Modified: . apr.dsp libapr.dsp include apr.h.in apr.hnw apr.hw apr_portable.h misc/unix Makefile.in misc/win32 rand.c test Makefile.in . aprutil.dsp libaprutil.dsp crypto Makefile.in test Makefile.in Added: crypto getuuid.c uuid.c include apr_uuid.h test testuuid.c Removed: include apr_uuid.h misc/unix getuuid.c uuid.c misc/win32 getuuid.c test testuuid.c Log: 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. Revision Changes Path 1.110 +0 -12 apr/apr.dsp Index: apr.dsp =================================================================== RCS file: /home/cvs/apr/apr.dsp,v retrieving revision 1.109 retrieving revision 1.110 diff -u -r1.109 -r1.110 --- apr.dsp 17 Jul 2002 03:26:29 -0000 1.109 +++ apr.dsp 17 Jul 2002 04:11:32 -0000 1.110 @@ -206,10 +206,6 @@ # 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 @@ # 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 @@ -598,10 +590,6 @@ # Begin Source File SOURCE=.\include\apr_user.h -# End Source File -# Begin Source File - -SOURCE=.\include\apr_uuid.h # End Source File # Begin Source File 1.71 +0 -12 apr/libapr.dsp Index: libapr.dsp =================================================================== RCS file: /home/cvs/apr/libapr.dsp,v retrieving revision 1.70 retrieving revision 1.71 diff -u -r1.70 -r1.71 --- libapr.dsp 17 Jul 2002 03:26:29 -0000 1.70 +++ libapr.dsp 17 Jul 2002 04:11:32 -0000 1.71 @@ -212,10 +212,6 @@ # 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 @@ # 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 @@ -604,10 +596,6 @@ # Begin Source File SOURCE=.\include\apr_user.h -# End Source File -# Begin Source File - -SOURCE=.\include\apr_uuid.h # End Source File # Begin Source File 1.111 +1 -0 apr/include/apr.h.in Index: apr.h.in =================================================================== RCS file: /home/cvs/apr/include/apr.h.in,v retrieving revision 1.110 retrieving revision 1.111 diff -u -r1.110 -r1.111 --- apr.h.in 1 Jul 2002 14:04:58 -0000 1.110 +++ apr.h.in 17 Jul 2002 04:11:32 -0000 1.111 @@ -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 1.17 +1 -0 apr/include/apr.hnw Index: apr.hnw =================================================================== RCS file: /home/cvs/apr/include/apr.hnw,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- apr.hnw 7 Jun 2002 21:17:19 -0000 1.16 +++ apr.hnw 17 Jul 2002 04:11:32 -0000 1.17 @@ -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. 1.96 +1 -0 apr/include/apr.hw Index: apr.hw =================================================================== RCS file: /home/cvs/apr/include/apr.hw,v retrieving revision 1.95 retrieving revision 1.96 diff -u -r1.95 -r1.96 --- apr.hw 8 Jul 2002 17:30:56 -0000 1.95 +++ apr.hw 17 Jul 2002 04:11:32 -0000 1.96 @@ -297,6 +297,7 @@ #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. 1.80 +8 -0 apr/include/apr_portable.h Index: apr_portable.h =================================================================== RCS file: /home/cvs/apr/include/apr_portable.h,v retrieving revision 1.79 retrieving revision 1.80 diff -u -r1.79 -r1.80 --- apr_portable.h 8 May 2002 13:30:11 -0000 1.79 +++ apr_portable.h 17 Jul 2002 04:11:32 -0000 1.80 @@ -463,6 +463,14 @@ */ 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 */ 1.31 +1 -2 apr/misc/unix/Makefile.in Index: Makefile.in =================================================================== RCS file: /home/cvs/apr/misc/unix/Makefile.in,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- Makefile.in 22 Apr 2002 01:24:50 -0000 1.30 +++ Makefile.in 17 Jul 2002 04:11:33 -0000 1.31 @@ -2,8 +2,7 @@ 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@ 1.15 +22 -1 apr/misc/win32/rand.c Index: rand.c =================================================================== RCS file: /home/cvs/apr/misc/win32/rand.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- rand.c 29 May 2002 22:07:58 -0000 1.14 +++ rand.c 17 Jul 2002 04:11:33 -0000 1.15 @@ -52,10 +52,15 @@ * . */ +#include +#include +#include +#include "apr.h" #include "apr_private.h" #include "apr_general.h" +#include "apr_portable.h" #include "misc.h" -#include + APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf, int length) @@ -77,4 +82,20 @@ } 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; } 1.87 +0 -4 apr/test/Makefile.in Index: Makefile.in =================================================================== RCS file: /home/cvs/apr/test/Makefile.in,v retrieving revision 1.86 retrieving revision 1.87 diff -u -r1.86 -r1.87 --- Makefile.in 17 Jul 2002 02:56:37 -0000 1.86 +++ Makefile.in 17 Jul 2002 04:11:33 -0000 1.87 @@ -29,7 +29,6 @@ testshmconsumer@EXEEXT@ \ testpipe@EXEEXT@ \ testoc@EXEEXT@ \ - testuuid@EXEEXT@ \ testsockopt@EXEEXT@ \ testipsub@EXEEXT@ \ testpoll@EXEEXT@ \ @@ -142,9 +141,6 @@ 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) 1.43 +12 -0 apr-util/aprutil.dsp Index: aprutil.dsp =================================================================== RCS file: /home/cvs/apr-util/aprutil.dsp,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- aprutil.dsp 17 Jul 2002 02:53:25 -0000 1.42 +++ aprutil.dsp 17 Jul 2002 04:11:33 -0000 1.43 @@ -155,6 +155,14 @@ SOURCE=.\crypto\apr_sha1.c # End Source File +# Begin Source File + +SOURCE=.\crypto\getuuid.c +# End Source File +# Begin Source File + +SOURCE=.\crypto\uuid.c +# End Source File # End Group # Begin Group "dbm" @@ -496,6 +504,10 @@ # Begin Source File SOURCE=.\include\apr_uri.h +# End Source File +# Begin Source File + +SOURCE=.\include\apr_uuid.h # End Source File # Begin Source File 1.37 +12 -0 apr-util/libaprutil.dsp Index: libaprutil.dsp =================================================================== RCS file: /home/cvs/apr-util/libaprutil.dsp,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- libaprutil.dsp 17 Jul 2002 02:53:26 -0000 1.36 +++ libaprutil.dsp 17 Jul 2002 04:11:33 -0000 1.37 @@ -161,6 +161,14 @@ SOURCE=.\crypto\apr_sha1.c # End Source File +# Begin Source File + +SOURCE=.\crypto\getuuid.c +# End Source File +# Begin Source File + +SOURCE=.\crypto\uuid.c +# End Source File # End Group # Begin Group "dbm" @@ -502,6 +510,10 @@ # Begin Source File SOURCE=.\include\apr_uri.h +# End Source File +# Begin Source File + +SOURCE=.\include\apr_uuid.h # End Source File # Begin Source File 1.14 +1 -1 apr-util/crypto/Makefile.in Index: Makefile.in =================================================================== RCS file: /home/cvs/apr-util/crypto/Makefile.in,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- Makefile.in 17 Jul 2002 02:53:26 -0000 1.13 +++ Makefile.in 17 Jul 2002 04:11:33 -0000 1.14 @@ -2,7 +2,7 @@ INCLUDES = @APRUTIL_PRIV_INCLUDES@ @APR_INCLUDES@ @APRUTIL_INCLUDES@ -TARGETS = apr_sha1.lo apr_md4.lo apr_md5.lo +TARGETS = apr_sha1.lo apr_md4.lo apr_md5.lo uuid.lo getuuid.lo # bring in rules.mk for standard functionality @INCLUDE_RULES@ 1.1 apr-util/crypto/getuuid.c Index: getuuid.c =================================================================== /* ==================================================================== * 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 * . */ /* * This attempts to generate V1 UUIDs according to the Internet Draft * located at http://www.webdav.org/specs/draft-leach-uuids-guids-01.txt */ #if APR_HAVE_UNISTD_H #include /* for getpid, gethostname */ #endif #if APR_HAVE_STDLIB_H #include /* for rand, srand */ #endif #include "apr.h" #include "apr_uuid.h" #include "apr_md5.h" #include "apr_general.h" #include "apr_portable.h" #if APR_HAVE_STRING_H #include #endif #if APR_HAVE_STRINGS_H #include #endif #if APR_HAVE_NETDB_H #include #endif #if APR_HAVE_SYS_TIME_H #include /* 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) { /* ### fix this call to be more portable? */ *uuid_time = apr_time_now(); /* 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 = (*uuid_time * 10) + APR_TIME_C(0x01B21DD213814000); } /* 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_time_t time_now; static apr_interval_time_t time_last = 0; static apr_interval_time_t fudge = 0; time_now = apr_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; } APU_DECLARE(void) apr_uuid_get(apr_uuid_t *uuid) { apr_uint64_t timestamp; unsigned char *d = uuid->data; #if APR_HAS_OS_UUID if (apr_os_uuid_get(d) == APR_SUCCESS) { return; } #endif /* !APR_HAS_OS_UUID */ if (!uuid_state_node[0]) init_state(); get_current_time(×tamp); 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); } 1.1 apr-util/crypto/uuid.c Index: uuid.c =================================================================== /* ==================================================================== * 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 * . */ #include /* for sprintf */ #include "apr.h" #include "apr_uuid.h" #include "apr_errno.h" #include "apr_lib.h" APU_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; } APU_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; } 1.1 apr-util/include/apr_uuid.h Index: apr_uuid.h =================================================================== /* ==================================================================== * 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 * . */ /** * @file apr_uuid.h * @brief APR UUID library */ #ifndef APR_UUID_H #define APR_UUID_H #include "apu.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 */ APU_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 */ APU_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 */ APU_DECLARE(apr_status_t) apr_uuid_parse(apr_uuid_t *uuid, const char *uuid_str); /** @} */ #ifdef __cplusplus } #endif #endif /* APR_UUID_H */ 1.29 +7 -1 apr-util/test/Makefile.in Index: Makefile.in =================================================================== RCS file: /home/cvs/apr-util/test/Makefile.in,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- Makefile.in 17 Jul 2002 02:56:37 -0000 1.28 +++ Makefile.in 17 Jul 2002 04:11:33 -0000 1.29 @@ -2,7 +2,7 @@ INCLUDES = @APRUTIL_PRIV_INCLUDES@ @APR_INCLUDES@ @APRUTIL_INCLUDES@ -PROGRAMS = testdbm testdate testmd4 testmd5 testxml testrmm teststrmatch +PROGRAMS = testdbm testdate testmd4 testmd5 testxml testrmm teststrmatch testuuid TARGETS = $(PROGRAMS) # bring in rules.mk for standard functionality @@ -45,3 +45,9 @@ teststrmatch_LDADD = ../libaprutil.la teststrmatch: $(teststrmatch_OBJECTS) $(teststrmatch_LDADD) $(LINK) $(teststrmatch_OBJECTS) $(teststrmatch_LDADD) $(PROGRAM_DEPENDENCIES) + +testuuid_OBJECTS = testuuid.lo +testuuid_LDADD = ../libaprutil.la +testuuid: $(testuuid_OBJECTS) $(testuuid_LDADD) + $(LINK) $(testuuid_OBJECTS) $(testuuid_LDADD) $(PROGRAM_DEPENDENCIES) + 1.1 apr-util/test/testuuid.c Index: testuuid.c =================================================================== /* ==================================================================== * 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 * . */ #include #include #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; }