You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sa...@apache.org on 2006/01/27 13:54:48 UTC
svn commit: r372829 - in /webservices/axis2/trunk/c: configure.ac
include/axis2_uuid_gen.h modules/Makefile.am
modules/platforms/unix/Makefile.am
modules/platforms/unix/axis2_uuid_gen_unix.h
modules/platforms/unix/uuid_gen_unix.c modules/util/uuid_gen.c
Author: sahan
Date: Fri Jan 27 04:54:35 2006
New Revision: 372829
URL: http://svn.apache.org/viewcvs?rev=372829&view=rev
Log:
Moved platform dependant code in uuid_gen to platforms directory and added platform dependent code
Added:
webservices/axis2/trunk/c/modules/platforms/unix/Makefile.am
webservices/axis2/trunk/c/modules/platforms/unix/axis2_uuid_gen_unix.h
webservices/axis2/trunk/c/modules/platforms/unix/uuid_gen_unix.c
Modified:
webservices/axis2/trunk/c/configure.ac
webservices/axis2/trunk/c/include/axis2_uuid_gen.h
webservices/axis2/trunk/c/modules/Makefile.am
webservices/axis2/trunk/c/modules/util/uuid_gen.c
Modified: webservices/axis2/trunk/c/configure.ac
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/configure.ac?rev=372829&r1=372828&r2=372829&view=diff
==============================================================================
--- webservices/axis2/trunk/c/configure.ac (original)
+++ webservices/axis2/trunk/c/configure.ac Fri Jan 27 04:54:35 2006
@@ -109,6 +109,7 @@
modules/xml/soap/Makefile \
modules/xml/om/Makefile \
modules/util/Makefile \
+ modules/platforms/unix/Makefile \
modules/wsdl/Makefile \
test/Makefile \
test/server/Makefile \
Modified: webservices/axis2/trunk/c/include/axis2_uuid_gen.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_uuid_gen.h?rev=372829&r1=372828&r2=372829&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_uuid_gen.h (original)
+++ webservices/axis2/trunk/c/include/axis2_uuid_gen.h Fri Jan 27 04:54:35 2006
@@ -20,11 +20,8 @@
#include <axis2.h>
#include <axis2_defines.h>
#include <axis2_env.h>
-#include <axis2_network_handler.h>
#include <axis2_platform_auto_sense.h>
-#define UUIDS_PER_TICK 100
-#define UUID_TIMEOFFSET AXIS2_UNSIGNED_LONGLONGVALUE(0x01B21DD213814000)
#ifdef __cplusplus
extern "C"
@@ -37,33 +34,6 @@
* @ingroup axis2_util
* @{
*/
-
-struct axis2_uuid {
- AXIS2_LONGLONG time_stamp_ver;
- short int clock_variant;
- unsigned char mac_addr[6];
-};
-
-/* bits 0-59 time field
- * bits 60-63 version
- * bits 64-65 2 bit variant
- * bits 66-79 clock sequence
- * bits 80-107 node MAC address
- */
-struct axis2_uuid_st {
- unsigned char mac[6]; /* pre-determined MAC address */
- struct timeval time_last; /* last retrieved timestamp */
- unsigned long time_seq; /* last timestamp sequence counter */
- short int clock; /* clock tick - incremented random number */
-};
-
-typedef struct axis2_uuid axis2_uuid_t;
-/**
- * generate a uuid
- * @return generated uuid as a <code>axis2_uuid_t</code> struct
- */
-axis2_uuid_t* AXIS2_CALL
-axis2_uuid_gen_v1(axis2_env_t **env);
/**
* generate a uuid
Modified: webservices/axis2/trunk/c/modules/Makefile.am
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/Makefile.am?rev=372829&r1=372828&r2=372829&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/Makefile.am (original)
+++ webservices/axis2/trunk/c/modules/Makefile.am Fri Jan 27 04:54:35 2006
@@ -1 +1 @@
-SUBDIRS = util xml wsdl core
+SUBDIRS = util xml wsdl core platforms/unix
Added: webservices/axis2/trunk/c/modules/platforms/unix/Makefile.am
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/platforms/unix/Makefile.am?rev=372829&view=auto
==============================================================================
--- webservices/axis2/trunk/c/modules/platforms/unix/Makefile.am (added)
+++ webservices/axis2/trunk/c/modules/platforms/unix/Makefile.am Fri Jan 27 04:54:35 2006
@@ -0,0 +1,7 @@
+lib_LTLIBRARIES = libaxis2_unix.la
+AM_CPPFLAGS = $(CPPFLAGS)
+libaxis2_unix_la_SOURCES = uuid_gen_unix.c
+
+libaxis2_unix_la_LIBADD =
+INCLUDES = -I$(top_builddir)/include\
+ -I$(top_builddir)/modules/platforms
Added: webservices/axis2/trunk/c/modules/platforms/unix/axis2_uuid_gen_unix.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/platforms/unix/axis2_uuid_gen_unix.h?rev=372829&view=auto
==============================================================================
--- webservices/axis2/trunk/c/modules/platforms/unix/axis2_uuid_gen_unix.h (added)
+++ webservices/axis2/trunk/c/modules/platforms/unix/axis2_uuid_gen_unix.h Fri Jan 27 04:54:35 2006
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain count copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AXIS2_UUID_GEN_UNIX_H
+#define AXIS2_UUID_GEN_UNIX_H
+
+#include <axis2.h>
+#include <axis2_defines.h>
+
+
+#define UUIDS_PER_TICK 100
+#define UUID_TIMEOFFSET AXIS2_UNSIGNED_LONGLONGVALUE(0x01B21DD213814000)
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+/**
+ * @defgroup axis2_uuid_gen UUID Generator
+ * @ingroup axis2_util
+ * @{
+ */
+
+
+struct axis2_uuid {
+ unsigned int time_low;
+ unsigned short int time_mid;
+ unsigned short int time_high_version;
+ short int clock_variant;
+ unsigned char mac_addr[6];
+};
+
+/* bits 0-59 time field
+ * bits 60-63 version
+ * bits 64-65 2 bit variant
+ * bits 66-79 clock sequence
+ * bits 80-107 node MAC address
+ */
+struct axis2_uuid_st {
+ unsigned char mac[6]; /* pre-determined MAC address */
+ struct timeval time_last; /* last retrieved timestamp */
+ unsigned long time_seq; /* last timestamp sequence counter */
+ short int clock; /* clock tick - incremented random number */
+};
+typedef struct axis2_uuid axis2_uuid_t;
+
+/**
+ * Returns the mac address of the first ethernet intsrface
+ * @return MAC address as a <code>char[6]</code>
+ */
+char * AXIS2_CALL
+axis2_uuid_get_mac_addr();
+
+/**
+ * Generates a uuid in version1 format (node - timestamp based)
+ * @return generated uuid as a axis2_uuid_t
+ */
+axis2_uuid_t* AXIS2_CALL
+axis2_uuid_gen_v1();
+
+/**
+ * Generates a uuid
+ * @return generated uuid as a string
+ */
+axis2_char_t* AXIS2_CALL
+axis2_uuid_gen();
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AXIS2_UUID_GEN_UNIX_H */
Added: webservices/axis2/trunk/c/modules/platforms/unix/uuid_gen_unix.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/platforms/unix/uuid_gen_unix.c?rev=372829&view=auto
==============================================================================
--- webservices/axis2/trunk/c/modules/platforms/unix/uuid_gen_unix.c (added)
+++ webservices/axis2/trunk/c/modules/platforms/unix/uuid_gen_unix.c Fri Jan 27 04:54:35 2006
@@ -0,0 +1,203 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <sys/ioctl.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <linux/if.h>
+#include <sys/time.h>
+#include <axis2_uuid_gen_unix.h>
+
+
+/* We need these static variables to track throughout the program execution */
+static axis2_bool_t axis2_uuid_gen_is_first = AXIS2_TRUE;
+static struct axis2_uuid_st axis2_uuid_static;
+
+
+axis2_uuid_t* AXIS2_CALL
+axis2_uuid_gen_v1()
+{
+ struct timeval time_now;
+ struct timeval tv;
+ unsigned long long time_val;
+ unsigned long long time_val2;
+ unsigned short int clck = 0;
+ axis2_uuid_t *ret_uuid = NULL;
+ unsigned short int time_high_version = 0;
+
+ if(AXIS2_TRUE == axis2_uuid_gen_is_first)
+ {
+ char *mac_addr = axis2_uuid_get_mac_addr();
+ memcpy(axis2_uuid_static.mac, mac_addr, 6);
+ axis2_uuid_static.time_seq = 0;
+ axis2_uuid_static.clock = 0;
+ free(mac_addr);
+ axis2_uuid_gen_is_first = AXIS2_FALSE;
+ }
+ /*
+ * GENERATE TIME
+ */
+
+ /* determine current system time and sequence counter */
+ if(gettimeofday(&time_now, NULL) == -1)
+ return NULL;
+
+ /* check whether system time changed since last retrieve */
+ if(!(time_now.tv_sec == axis2_uuid_static.time_last.tv_sec
+ && time_now.tv_usec ==
+ axis2_uuid_static.time_last.tv_usec)) {
+ /* reset time sequence counter and continue */
+ axis2_uuid_static.time_seq = 0;
+ }
+
+ /* until we are out of UUIDs per tick, increment
+ the time/tick sequence counter and continue */
+ while(axis2_uuid_static.time_seq < UUIDS_PER_TICK)
+ {
+ axis2_uuid_static.time_seq++;
+ }
+ /* sleep for 1000ns (1us) */
+ tv.tv_sec = 0;
+ tv.tv_usec = 1;
+ select(0, NULL, NULL, NULL, &tv);
+
+ time_val = (unsigned long long)time_now.tv_sec * 10000000ull;
+ time_val += (unsigned long long)time_now.tv_usec * 10ull;
+
+ ret_uuid = malloc(sizeof(axis2_uuid_t));
+
+ time_val += UUID_TIMEOFFSET;
+ /* compensate for low resolution system clock by adding
+ the time/tick sequence counter */
+ if (axis2_uuid_static.time_seq > 0)
+ time_val += (unsigned long long)axis2_uuid_static.time_seq;
+
+ time_val2 = time_val;
+ ret_uuid->time_low = (unsigned long)time_val2;
+ time_val2 >>= 32;
+ ret_uuid->time_mid = (unsigned short int)time_val2;
+ time_val2 >>= 16;
+ time_high_version = (unsigned short int)time_val2;
+
+ /* store the 60 LSB of the time in the UUID and make version 1*/
+ time_high_version <<= 4;
+ time_high_version &= 0xFFF0;
+ time_high_version |= 0x0001;
+ ret_uuid->time_high_version = time_high_version;
+
+ /*
+ * GENERATE CLOCK
+ */
+
+ /* retrieve current clock sequence */
+ clck = axis2_uuid_static.clock;
+
+ /* generate new random clock sequence (initially or if the
+ time has stepped backwards) or else just increase it */
+ if (clck == 0 || (time_now.tv_sec < axis2_uuid_static.time_last.tv_sec ||
+ (time_now.tv_sec == axis2_uuid_static.time_last.tv_sec
+ && time_now.tv_usec <
+ axis2_uuid_static.time_last.tv_usec)))
+ {
+ srand(time_now.tv_usec);
+ clck = rand();
+ }
+ else
+ {
+ clck++;
+ }
+ clck %= (2<<14);
+
+ /* store back new clock sequence */
+ axis2_uuid_static.clock = clck;
+
+ clck &= 0x1FFF;
+ clck |= 0x2000;
+
+ /*
+ * FINISH
+ */
+ /* remember current system time for next iteration */
+ axis2_uuid_static.time_last.tv_sec = time_now.tv_sec;
+ axis2_uuid_static.time_last.tv_usec = time_now.tv_usec;
+
+ if(NULL == ret_uuid)
+ {
+ return NULL;
+ }
+ ret_uuid->clock_variant = clck;
+ memcpy(ret_uuid->mac_addr, axis2_uuid_static.mac, 6);
+ return ret_uuid;
+}
+
+
+axis2_char_t* AXIS2_CALL
+axis2_uuid_gen()
+{
+ axis2_uuid_t *uuid_struct = NULL;
+ axis2_char_t *uuid_str = NULL;
+ unsigned char mac[7];
+ char mac_hex[13];
+
+ uuid_struct = axis2_uuid_gen_v1();
+ if(NULL == uuid_struct)
+ {
+ return NULL;
+ }
+ uuid_str = malloc(sizeof(axis2_char_t)*40);
+ if(NULL == uuid_str)
+ {
+ return NULL;
+ }
+ memcpy(mac, uuid_struct->mac_addr, 6);
+ sprintf(mac_hex, "%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3]
+ , mac[4], mac[5]);
+ sprintf(uuid_str, "%08x-%04x-%04x-%04x-%s", uuid_struct->time_low,
+ uuid_struct->time_mid, uuid_struct->time_high_version,
+ uuid_struct->clock_variant, mac_hex);
+ return uuid_str;
+}
+
+char * AXIS2_CALL
+axis2_uuid_get_mac_addr()
+{
+ struct ifreq ifr;
+ struct sockaddr *sa;
+ int s = 0;
+ int i = 0;
+ char *buffer = NULL;
+
+
+ if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
+ return NULL;
+ sprintf(ifr.ifr_name, "eth0");
+ if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0)
+ {
+ close(s);
+ return NULL;
+ }
+ buffer = (char*)malloc(6*sizeof(char));
+
+ sa = (struct sockaddr *)&ifr.ifr_addr;
+ for (i = 0; i < 6; i++)
+ buffer[i] = (unsigned char)(sa->sa_data[i] & 0xff);
+ close(s);
+ return buffer;
+}
Modified: webservices/axis2/trunk/c/modules/util/uuid_gen.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/util/uuid_gen.c?rev=372829&r1=372828&r2=372829&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/util/uuid_gen.c (original)
+++ webservices/axis2/trunk/c/modules/util/uuid_gen.c Fri Jan 27 04:54:35 2006
@@ -21,144 +21,15 @@
static struct axis2_uuid_st axis2_uuid_static;
-axis2_uuid_t* AXIS2_CALL
-axis2_uuid_gen_v1(axis2_env_t **env)
+axis2_char_t * AXIS2_CALL
+axis2_uuid_gen(axis2_env **env)
{
- struct timeval time_now;
- struct timeval tv;
- AXIS2_LONGLONG time_val;
- short int clck = 0;
- axis2_uuid_t *ret_uuid = NULL;
-
- AXIS2_ENV_CHECK(env, NULL);
-
- if(AXIS2_TRUE == axis2_uuid_gen_is_first)
- {
- char *mac_addr = axis2_network_handler_get_mac_addr(env);
- memcpy(axis2_uuid_static.mac, mac_addr, 6);
- axis2_uuid_static.time_seq = 0;
- axis2_uuid_static.clock = 0;
- AXIS2_FREE((*env)->allocator, mac_addr);
- }
- /*
- * GENERATE TIME
- */
-
- /* determine current system time and sequence counter */
- if(gettimeofday(&time_now, NULL) == -1)
- return NULL;
-
- /* check whether system time changed since last retrieve */
- if(!(time_now.tv_sec == axis2_uuid_static.time_last.tv_sec
- && time_now.tv_usec ==
- axis2_uuid_static.time_last.tv_usec)) {
- /* reset time sequence counter and continue */
- axis2_uuid_static.time_seq = 0;
- }
-
- /* until we are out of UUIDs per tick, increment
- the time/tick sequence counter and continue */
- while(axis2_uuid_static.time_seq < UUIDS_PER_TICK)
- {
- axis2_uuid_static.time_seq++;
- }
- /* sleep for 1000ns (1us) */
- tv.tv_sec = 0;
- tv.tv_usec = 1;
- select(0, NULL, NULL, NULL, &tv);
-
- time_val = time_now.tv_sec * 1000000;
- time_val += time_now.tv_usec * 10;
-
- time_val += UUID_TIMEOFFSET;
-
- /* compensate for low resolution system clock by adding
- the time/tick sequence counter */
- if (axis2_uuid_static.time_seq > 0)
- time_val += (int)axis2_uuid_static.time_seq;
-
- /* store the 60 LSB of the time in the UUID and make version 1*/
- time_val &= AXIS2_UNSIGNED_LONGLONGVALUE(0xFFFFFFFFFFFFFFF0);
- time_val |= AXIS2_UNSIGNED_LONGLONGVALUE(0x0000000000000001);
- /*
- * GENERATE CLOCK
- */
-
- /* retrieve current clock sequence */
- clck = axis2_uuid_static.clock;
-
- /* generate new random clock sequence (initially or if the
- time has stepped backwards) or else just increase it */
- if (clck == 0 || (time_now.tv_sec < axis2_uuid_static.time_last.tv_sec ||
- (time_now.tv_sec == axis2_uuid_static.time_last.tv_sec
- && time_now.tv_usec <
- axis2_uuid_static.time_last.tv_usec)))
+ axis2_char_t *str = axis2_uuid_get();
+ if (str == NULL)
{
- srand(time_now.tv_usec);
- clck = rand();
- }
- else
- {
- clck++;
- }
- clck %= (2<<14);
-
- /* store back new clock sequence */
- axis2_uuid_static.clock = clck;
-
- clck &= 0x1FFF;
- clck |= 0x2000;
-
- /*
- * FINISH
- */
- /* remember current system time for next iteration */
- axis2_uuid_static.time_last.tv_sec = time_now.tv_sec;
- axis2_uuid_static.time_last.tv_usec = time_now.tv_usec;
-
- ret_uuid = AXIS2_MALLOC((*env)->allocator, sizeof(axis2_uuid_t));
- if(NULL == ret_uuid)
- {
- AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
- return NULL;
- }
- ret_uuid->time_stamp_ver = time_val;
- ret_uuid->clock_variant = clck;
- memcpy(ret_uuid->mac_addr, axis2_uuid_static.mac, 6);
- return ret_uuid;
-}
-
-
-axis2_char_t* AXIS2_CALL
-axis2_uuid_gen(axis2_env_t **env)
-{
- axis2_uuid_t *uuid_struct = NULL;
- axis2_char_t *uuid_str = NULL;
- unsigned char mac[7];
- axis2_char_t llvalue[30];
- char mac_hex[13];
- AXIS2_LONGLONG llno = 0;
- long lno = 0;
-
- AXIS2_ENV_CHECK(env, NULL);
-
- uuid_struct = axis2_uuid_gen_v1(env);
- if(NULL == uuid_struct)
- {
- return NULL;
- }
- uuid_str = AXIS2_MALLOC((*env)->allocator, sizeof(axis2_char_t)*35);
- if(NULL == uuid_str)
- {
- AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
- AXIS2_FREE((*env)->allocator, uuid_struct);
+ AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_UUID_GEN_FAILED,
+ AXIS2_FAILURE);
return NULL;
}
- memcpy(mac, uuid_struct->mac_addr, 6);
- sprintf(mac_hex, "%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3]
- , mac[4], mac[5]);
- sprintf(llvalue, "%llx", uuid_struct->time_stamp_ver);
-
- sprintf(uuid_str, "%s%04x%s", llvalue, uuid_struct->clock_variant, mac_hex);
- return uuid_str;
-}
+ return str;
+};