httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/apr/test testuuid.c .cvsignore Makefile.in
Date Fri, 06 Oct 2000 12:19:45 GMT
gstein      00/10/06 05:19:44

  Modified:    src/lib/apr/misc/unix Makefile.in
               src/lib/apr/test .cvsignore Makefile.in
  Added:       src/lib/apr/include apr_uuid.h
               src/lib/apr/misc/unix getuuid.c uuid.c
               src/lib/apr/misc/win32 getuuid.c
               src/lib/apr/test testuuid.c
  Log:
  add UUID generation/formatting/parsing to APR
  
  Revision  Changes    Path
  1.1                  apache-2.0/src/lib/apr/include/apr_uuid.h
  
  Index: apr_uuid.h
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 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/>.
   */
  
  #ifndef APR_UUID_H
  #define APR_UUID_H
  
  #include "apr.h"
  #include "apr_errno.h"
  
  /**
   * @package APR UUID Handling
   */
  
  /* we represent a UUID as a block of 16 bytes. */
  typedef struct {
      unsigned char data[16];
  } 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
   * @deffunc int apr_get_uuid(apr_uuid_t *uuid)
   */ 
  void apr_get_uuid(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 + 1bytes long to hold
   *               the formatted UUID and a null terminator
   * @param uuid The UUID to format
   * @deffunc int apr_format_uuid(apr_pool_t *p, const apr_uuid_t *uuid)
   */ 
  void apr_format_uuid(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
   * @deffunc int apr_parse_uuid(apr_uuid_t *uuid, const char *uuid_str)
   */ 
  apr_status_t apr_parse_uuid(apr_uuid_t *uuid, const char *uuid_str);
  
  #endif /* APR_UUID_H */
  
  
  
  1.22      +2 -1      apache-2.0/src/lib/apr/misc/unix/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/unix/Makefile.in,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- Makefile.in	2000/07/23 17:24:50	1.21
  +++ Makefile.in	2000/10/06 12:19:38	1.22
  @@ -17,7 +17,8 @@
   
   #LIB=libmisc.a
   
  -OBJS=start.o getopt.o otherchild.o errorcodes.o rand.o canonerr.o
  +OBJS=start.o getopt.o otherchild.o errorcodes.o rand.o canonerr.o \
  +	uuid.c getuuid.c
   
   .c.o:
   	$(CC) $(CFLAGS) -c $(INCLUDES) $<
  
  
  
  1.1                  apache-2.0/src/lib/apr/misc/unix/getuuid.c
  
  Index: getuuid.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 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_uuid.h"
  #include "apr_md5.h"
  #include "apr_general.h"
  
  #define NODE_LENGTH 6
  
  static int uuid_state_seqnum;
  static 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;
          struct timeval t;
          char hostname[257];
  
      } r;
  
      apr_MD5Init(&c);
      r.pid = getpid();
      gettimeofday(&r.t, (struct timezone *)0);
      gethostname(r.hostname, 256);
      apr_MD5Update(&c, (const unsigned char *)&r, sizeof(r));
      apr_MD5Final(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(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)
  {
      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;
  }
  
  /* 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)
  {
      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;
  }
  
  void apr_get_uuid(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);
  }
  
  
  
  1.1                  apache-2.0/src/lib/apr/misc/unix/uuid.c
  
  Index: uuid.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 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"
  
  
  void apr_format_uuid(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_status_t apr_parse_uuid(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                  apache-2.0/src/lib/apr/misc/win32/getuuid.c
  
  Index: getuuid.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 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 <objbase.h>
  
  #include "apr.h"
  #include "apr_uuid.h"
  
  void apr_get_uuid(apr_uuid_t *uuid)
  {
      GUID guid;
  
      /* Note: this call doesn't actually require CoInitialize() first */
      (void) CoCreateGuid(&guid);
      memcpy(uuid->data, &guid, sizeof(uuid->data));
  }
  
  
  
  1.7       +1 -0      apache-2.0/src/lib/apr/test/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/test/.cvsignore,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- .cvsignore	2000/06/26 20:40:42	1.6
  +++ .cvsignore	2000/10/06 12:19:42	1.7
  @@ -19,3 +19,4 @@
   testfile
   occhild
   testsf
  +testuuid
  
  
  
  1.25      +5 -0      apache-2.0/src/lib/apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/test/Makefile.in,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- Makefile.in	2000/06/26 20:14:34	1.24
  +++ Makefile.in	2000/10/06 12:19:42	1.25
  @@ -27,6 +27,7 @@
   	testpipe@EXEEXT@ \
   	testdso@EXEEXT@ \
   	testoc@EXEEXT@ \
  +	testuuid@EXEEXT@ \
   	occhild@EXEEXT@ \
   	mod_test.so
   
  @@ -42,6 +43,7 @@
   	testmmap.o \
   	testdso.o \
   	testoc.o \
  +	testuuid.o \
   	occhild.o \
   	mod_test.o
   
  @@ -99,6 +101,9 @@
   
   testpipe@EXEEXT@: testpipe.o
   	$(CC) $(CFLAGS) -o testpipe@EXEEXT@ testpipe.o $(LDFLAGS)
  +
  +testuuid@EXEEXT@: testuuid.o
  +	$(CC) $(CFLAGS) -o testuuid@EXEEXT@ testuuid.o $(LDFLAGS)
   
   clean:
   	$(RM) -f *.o *.a *.so $(TARGETS)
  
  
  
  1.1                  apache-2.0/src/lib/apr/test/testuuid.c
  
  Index: testuuid.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 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 "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_get_uuid(&uuid);
      apr_format_uuid(buf, &uuid);
      printf("UUID: %s\n", buf);
  
      apr_parse_uuid(&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_format_uuid(buf, &uuid2);
      printf("parsed/reformatted UUID: %s\n", buf);
  
      /* generate two of them quickly */
      apr_get_uuid(&uuid);
      apr_get_uuid(&uuid2);
      apr_format_uuid(buf, &uuid);
      printf("UUID 1: %s\n", buf);
      apr_format_uuid(buf, &uuid2);
      printf("UUID 2: %s\n", buf);
  
      return retcode;
  }
  
  
  

Mime
View raw message