diff options
author | nadiramra | 2010-05-30 20:43:13 +0000 |
---|---|---|
committer | nadiramra | 2010-05-30 20:43:13 +0000 |
commit | cddcc5e6b3d63e42ded5bca4a3e5e7972cb2e216 (patch) | |
tree | d619453afb5f99ca02634b8305a0787af69d4de8 /util | |
parent | 4952078f0c24283ce57a6d316ef9470caf5a8fb2 (diff) | |
download | axis2c-cddcc5e6b3d63e42ded5bca4a3e5e7972cb2e216.tar.gz axis2c-cddcc5e6b3d63e42ded5bca4a3e5e7972cb2e216.tar.bz2 |
AXIS2C-1478 Changes due to port to IBM i (aka OS/400).
git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@949568 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'util')
-rw-r--r-- | util/include/platforms/axutil_platform_auto_sense.h | 2 | ||||
-rw-r--r-- | util/include/platforms/os400/axutil_date_time_util_os400.h | 46 | ||||
-rw-r--r-- | util/include/platforms/os400/axutil_os400.h | 277 | ||||
-rw-r--r-- | util/include/platforms/os400/axutil_thread_os400.h | 59 | ||||
-rw-r--r-- | util/include/platforms/os400/axutil_uuid_gen_os400.h | 94 | ||||
-rw-r--r-- | util/src/platforms/os400/date_time_util_os400.c | 31 | ||||
-rw-r--r-- | util/src/platforms/os400/platformSpecificOS400.c | 482 | ||||
-rw-r--r-- | util/src/platforms/os400/thread_os400.c | 358 | ||||
-rw-r--r-- | util/src/platforms/os400/uuid_gen_os400.c | 244 |
9 files changed, 1592 insertions, 1 deletions
diff --git a/util/include/platforms/axutil_platform_auto_sense.h b/util/include/platforms/axutil_platform_auto_sense.h index feec323..2f36a53 100644 --- a/util/include/platforms/axutil_platform_auto_sense.h +++ b/util/include/platforms/axutil_platform_auto_sense.h @@ -44,7 +44,7 @@ extern "C" #include "windows/axutil_date_time_util_windows.h" #include "windows/axutil_thread_windows.h" #elif defined ( __OS400__ ) -#include <os400/axis2_os400.h> +#include "os400/axutil_os400.h" #elif defined ( AIX ) #include <aix/aix.h> #elif defined ( HPUX ) diff --git a/util/include/platforms/os400/axutil_date_time_util_os400.h b/util/include/platforms/os400/axutil_date_time_util_os400.h new file mode 100644 index 0000000..9979395 --- /dev/null +++ b/util/include/platforms/os400/axutil_date_time_util_os400.h @@ -0,0 +1,46 @@ + +/* + * 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 AXUTIL_DATE_TIME_UTIL_UNIX_H +#define AXUTIL_DATE_TIME_UTIL_UNIX_H + +#include <axutil_utils.h> +#include <axutil_utils_defines.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/timeb.h> +#include <time.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axis2_milliseconds + * @ingroup axis2_milliseconds + * @{ + */ + AXIS2_EXTERN int AXIS2_CALL + axis2_platform_get_milliseconds(void + ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/util/include/platforms/os400/axutil_os400.h b/util/include/platforms/os400/axutil_os400.h new file mode 100644 index 0000000..e9ca465 --- /dev/null +++ b/util/include/platforms/os400/axutil_os400.h @@ -0,0 +1,277 @@ +
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+#ifndef AXIS2_UNIX_H
+#define AXIS2_UNIX_H
+
+#include <axutil_config.h>
+
+/**
+ * @file axutil_unix.h
+ * @brief axis2 unix platform specific interface
+ */
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /** @defgroup axis2_unix Platform Specific
+ * @ingroup axis2_platforms_unix
+ * @{
+ */
+
+ /***************************************************************
+ * Default paths to shared library/DLLs and files
+ ***************************************************************
+ */
+
+#define AXIS2_PLATFORM_DEFAULT_DEPLOY_PATH ""
+
+#define AXIS2_PLATFORM_XMLPARSER_PATH "libaxis2_parser.so"
+#define AXIS2_PLATFORM_TRANSPORTHTTP_PATH "libhttp_transport.so"
+#define AXIS2_PLATFORM_CHANNEL_PATH "libhttp_channel.so"
+#define AXIS2_PLATFORM_SSLCHANNEL_PATH "Unknown"
+
+#define AXIS2_PLATFORM_LOG_PATH "/axis2/log/axutil_log"
+#define AXIS2_PLATFORM_CLIENTLOG_PATH "/axis2/log/axis2_client_log"
+#define AXIS2_PLATFORM_CONFIG_PATH "/etc/axiscpp.conf"
+#define AXIS2_PLATFORM_SECUREINFO ""
+
+ /**
+ * Resource that contains the configuration
+ */
+#define AXIS2_CONFIGURATION_RESOURCE "/axis2/axis2.xml"
+
+ /*****************************************************************
+ * Library loading and procedure resolution
+ ****************************************************************/
+
+#define AXIS2_DLHANDLER void*
+
+#define AXIS2_PLATFORM_LOADLIBINIT()
+#define AXIS2_PLATFORM_LOADLIB(_lib) os400_dlopen(_lib)
+
+#define AXIS2_PLATFORM_UNLOADLIB os400_dlclose
+#define AXIS2_PLATFORM_GETPROCADDR os400_dlsym
+#define AXIS2_PLATFORM_LOADLIBEXIT()
+#define AXIS2_PLATFORM_LOADLIB_ERROR os400_dlerror()
+
+extern void *os400_dlopen(const char *);
+extern void *os400_dlsym(void *, const char *);
+extern int os400_dlclose(void *);
+extern char *os400_dlerror();
+
+
+ /***************************************************************
+ * National Language Support
+ ****************************************************************/
+
+// STRTOASC is to translate single byte 'native' character representation to ASCII
+// ASCTOSTR is to translate single byte ascii representation to 'native' character (EBCDIC)
+// CANNOT be used with constants.
+extern char* strtoasc( char* );
+extern char* asctostr( char* );
+#define AXIS2_PLATFORM_STRTOASC( x ) strtoasc( (char*)(x) )
+#define AXIS2_PLATFORM_ASCTOSTR( x ) asctostr( (char*)(x) )
+
+// reference to ebcdic to ascii conversion table
+extern const char EBCDICtoASCII[256];
+
+// Turkish double quote in EBCDIC is not invariant (i.e. the hexadecimal
+// value for double quote is different in turkish locale than when running
+// in english locale). This, when using double quotes we must reference the
+// following, which will be set to proper value on EBCDIC-based systems.
+
+extern char AXIS2_PLATFORM_DOUBLE_QUOTE_S[];
+extern char AXIS2_PLATFORM_DOUBLE_QUOTE_C;
+
+extern char AXIS2_PLATFORM_XML_ENTITY_REFERENCE_CHARS_S[];
+
+ /***************************************************************
+ * Miscellaneous
+ ****************************************************************/
+#include <sys/time.h>
+
+#include <errno.h>
+#include <sys/param.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include "axutil_uuid_gen_os400.h" /* uuid_gen unix implementation */
+#include <netinet/tcp.h> /* TCP_NODELAY */
+#include <utime.h>
+
+#include "axutil_date_time_util_os400.h"
+
+ /* for file access handling */
+#include <unistd.h>
+
+ /* network handling */
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <sys/ioctl.h>
+
+#include <fcntl.h>
+
+ /* dir handling */
+#include <sys/types.h>
+#include <dirent.h>
+
+#define AXIS2_STRRCHR(x, y) (strrchr(x, y))
+
+#define AXIS2_PLATFORM_SLEEP(x) sleep(0);
+
+ /** sleep function abstraction */
+#define AXIS2_SLEEP sleep
+#define AXIS2_USLEEP usleep
+
+ /**
+ * Platform specific method to obtain current thread ID
+ */
+#include <pthread.h>
+#define AXIS2_PLATFORM_GET_THREAD_ID() os400_getThreadID()
+
+static long long os400_getThreadID()
+{
+ pthread_id_np_t tid = pthread_getthreadid_np();
+ return *((long long *)&tid);
+}
+
+ /**
+ * Platform specific method to obtain current time in milli seconds
+ */
+struct os400_timeb
+{
+ long time;
+ long millitm;
+};
+
+static int os400_ftime(struct os400_timeb * tp)
+{
+ struct timeval t;
+ gettimeofday(&t, NULL);
+ tp->time = t.tv_sec;
+ tp->millitm = t.tv_usec/1000;
+ return 0;
+}
+#define AXIS2_PLATFORM_GET_TIME_IN_MILLIS os400_ftime
+#define AXIS2_PLATFORM_TIMEB os400_timeb
+
+ /**
+ * type to be used for 64bit integers
+ */
+#define AXIS2_LONGLONG long long
+#define AXIS2_LONGLONGVALUE(value) value##LL
+#define AXIS2_UNSIGNED_LONGLONGVALUE(value) value##ULL
+
+ /**
+ * Format string to be used in printf for 64bit integers
+ */
+#define AXIS2_PRINTF_LONGLONG_FORMAT_SPECIFIER "%lld"
+#define AXIS2_PRINTF_LONGLONG_FORMAT_SPECIFIER_CHARS "lld"
+#define AXIS2_PRINTF_UNSIGNED_LONGLONG_FORMAT_SPECIFIER "%llu"
+#define AXIS2_PRINTF_UNSIGNED_LONGLONG_FORMAT_SPECIFIER_CHARS "llu"
+
+ /**
+ * Platform specific path separator char
+ */
+
+#define AXIS2_PATH_SEP_CHAR '/'
+#define AXIS2_PATH_SEP_STR "/"
+#define AXIS2_LIB_PREFIX "lib"
+#define AXIS2_LIB_SUFFIX ".so"
+
+ /**
+ * Platform specific time
+ */
+#define AXIS2_TIME_T time_t
+
+ /**
+ * Platform specific file handling
+ */
+#define AXIS2_FOPEN fopen
+#define AXIS2_FREAD fread
+#define AXIS2_FWRITE fwrite
+#define AXIS2_FCLOSE fclose
+#define AXIS2_FTELL ftell
+#define AXIS2_ACCESS(zpath,imode) access(zpath,imode)
+#define AXIS2_R_OK R_OK /* test for read permission */
+#define AXIS2_W_OK W_OK /* test for write permission */
+#define AXIS2_X_OK X_OK /* test for execute or search permission */
+#define AXIS2_F_OK F_OK /* test whether the directories leading to the file can be
+ searched and the file exists */
+
+ /**
+ * Platform specific environment variable access method
+ */
+#define AXIS2_GETENV(_env_var_name) getenv(_env_var_name)
+
+ /**
+ * unix specific directory handling functions
+ */
+#define AXIS2_SCANDIR os400_scandir
+#define AXIS2_ALPHASORT os400_alphasort
+#define AXIS2_OPENDIR opendir
+#define AXIS2_CLOSEDIR closedir
+#define AXIS2_READDIR readdir
+#define AXIS2_READDIR_R readdir_r
+#define AXIS2_REWINDDIR rewinddir
+#define AXIS2_MKDIR mkdir
+#define AXIS2_GETCWD getcwd
+#define AXIS2_CHDIR chdir
+
+ /**
+ * network specific functions and defs
+ */
+#define axis2_socket_t int
+#define AXIS2_INVALID_SOCKET -1
+#define AXIS2_INADDR_NONE (in_addr_t)-1
+#define axis2_unsigned_short_t uint16_t
+#define AXIS2_CLOSE_SOCKET(sock) close(sock)
+#define AXIS2_CLOSE_SOCKET_ON_EXIT(sock) fcntl(sock,F_SETFD, FD_CLOEXEC);
+#define axis2_socket_len_t socklen_t
+#define AXIS2_SHUT_WR SHUT_WR
+
+ /** getopt function */
+#define AXIS2_GETOPT getopt
+
+ /** minizip functions */
+#define axis2_fill_win32_filefunc(ffunc)
+#define AXIS2_UNZOPEN2(zipfilename,ffunc) unzOpen2(zipfilename,NULL); memset(&ffunc, 0, sizeof(ffunc));
+
+ /**
+ * handling variable number of arguments (for log.c)
+ */
+#define AXIS2_VSNPRINTF vsnprintf
+
+#define AXIS2_SNPRINTF snprintf
+
+#define axis2_gmtime_r gmtime_r
+
+ /** @} */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AXIS2_UNIX_H */
diff --git a/util/include/platforms/os400/axutil_thread_os400.h b/util/include/platforms/os400/axutil_thread_os400.h new file mode 100644 index 0000000..5ee5992 --- /dev/null +++ b/util/include/platforms/os400/axutil_thread_os400.h @@ -0,0 +1,59 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#ifndef AXUTIL_THREAD_UNIX_H +#define AXUTIL_THREAD_UNIX_H + +#include <axutil_thread.h> +#include <pthread.h> + +#define SHELL_PATH "/bin/sh" + +typedef pthread_t axis2_os_thread_t; /* Native thread */ + +struct axutil_thread_t +{ + pthread_t *td; + void *data; + axutil_thread_start_t func; + axis2_bool_t try_exit; +}; + +struct axutil_threadattr_t +{ + pthread_attr_t attr; +}; + +struct axutil_threadkey_t +{ + pthread_key_t key; +}; + +struct axutil_thread_once_t +{ + pthread_once_t once; +}; + +/*************************Thread locking functions*****************************/ +struct axutil_thread_mutex_t +{ + axutil_allocator_t *allocator; + pthread_mutex_t mutex; +}; + +#endif /* AXIS2_THREAD_UNIX_H */ diff --git a/util/include/platforms/os400/axutil_uuid_gen_os400.h b/util/include/platforms/os400/axutil_uuid_gen_os400.h new file mode 100644 index 0000000..d3b25ba --- /dev/null +++ b/util/include/platforms/os400/axutil_uuid_gen_os400.h @@ -0,0 +1,94 @@ + +/* + * 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 AXUTIL_UUID_GEN_UNIX_H +#define AXUTIL_UUID_GEN_UNIX_H + +#include <axutil_utils.h> +#include <axutil_utils_defines.h> + +#define UUIDS_PER_TICK 100 +#define UUID_TIMEOFFSET AXIS2_UNSIGNED_LONGLONGVALUE(0x01B21DD213814000) +#define AXIS2_LOCAL_MAC_ADDR "000000" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_uuid_gen UUID Generator + * @ingroup axis2_util + * @{ + */ + + struct axutil_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 axutil_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 axutil_uuid axutil_uuid_t; + + /** + * Returns the mac address of the first ethernet intsrface + * @return MAC address as a <code>char[6]</code> + */ + char *AXIS2_CALL + axutil_uuid_get_mac_addr(void + ); + + /** + * Generates a uuid in version1 format (node - timestamp based) + * @return generated uuid as a axutil_uuid_t + */ + axutil_uuid_t *AXIS2_CALL + axutil_uuid_gen_v1(void + ); + + /** + * Generates a uuid + * @return generated uuid as a string + */ + axis2_char_t *AXIS2_CALL + axutil_platform_uuid_gen( + char *s); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_UUID_GEN_UNIX_H */ diff --git a/util/src/platforms/os400/date_time_util_os400.c b/util/src/platforms/os400/date_time_util_os400.c new file mode 100644 index 0000000..c593246 --- /dev/null +++ b/util/src/platforms/os400/date_time_util_os400.c @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <platforms/os400/axutil_date_time_util_os400.h> + +AXIS2_EXTERN int AXIS2_CALL +axis2_platform_get_milliseconds() +{ + struct timeb t_current; + int milliseconds; + + ftime(&t_current); + milliseconds = t_current.millitm; + + return milliseconds; + +} diff --git a/util/src/platforms/os400/platformSpecificOS400.c b/util/src/platforms/os400/platformSpecificOS400.c new file mode 100644 index 0000000..be60e8c --- /dev/null +++ b/util/src/platforms/os400/platformSpecificOS400.c @@ -0,0 +1,482 @@ +/*
+ * Copyright 2004-2004 The Apache Software Foundation.
+// (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved
+ *
+ * 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 "platforms/axutil_platform_auto_sense.h"
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <qusec.h> // Qus_EC_t
+#include <mih/rslvsp.h> // rslvsp()
+#include <mih/micommon.h> // _AUTH_EXECUTE
+#include <qleawi.h> // QleActBndPgm(), QleGetExp()
+#include <qp0lstdi.h> // Qp0lCvtPathToQSYSObjName()
+#include <unistd.h> // readlink()
+#include <except.h>
+#include <errno.h>
+#include <qwcrtvca.h> // Retrieve job's ccsid API prototype
+
+
+
+/**********************************************************************/
+/* Function: */
+/* retrieveJobCcsid */
+/* Description: */
+/* Retrieves the ccsid of the current job. */
+/* If the current job's ccsid is 65535, the job's default ccsid is */
+/* returned. */
+/* If the ccsid cannot be retrieved (error occurs), -1 is returned. */
+/* Return: */
+/* int status of call. if 0, success; -1 failure. */
+/**********************************************************************/
+
+#define RTV_CCSID_ATTR_LEN 512
+
+static int retrieveJobCcsid(int *ccsid, char *langID)
+{
+ char receiverVariable[RTV_CCSID_ATTR_LEN];
+ char format[8] = {'R', 'T', 'V', 'C', '0', '1', '0', '0'};
+ int numberOfAttributes = 3;
+ int attributeKeys[3] = {QWCA_KEY_CCSID, QWCA_KEY_DEFAULTCCSID, QWCA_KEY_LANGID};
+ Qwc_RTVC_Attribute_Data_t *attribute;
+ int defaultCcsid;
+ char errorCode[8];
+ int i;
+ memset(errorCode, 0x00, sizeof(errorCode));
+
+#pragma exception_handler(RetrieveJobCcsidError,0,_C1_ALL,_C2_ALL,_CTLA_HANDLE)
+ QWCRTVCA(receiverVariable,RTV_CCSID_ATTR_LEN,format,numberOfAttributes,attributeKeys,&errorCode);
+#pragma disable_handler
+ if (((Qwc_RTVC0100_t *)receiverVariable)->Number_Fields_Rtnd != 3)
+ {
+ /* Unable to retrieve the ccsid information */
+ return -1;
+ }
+ /* Retrieved ccsid, default CCSID and language ID */
+ attribute = (Qwc_RTVC_Attribute_Data_t *)(receiverVariable + sizeof(int));
+ for (i=0; i < 3; i++)
+ {
+ if (attribute->Key_Field == QWCA_KEY_CCSID)
+ *ccsid = *(int *)((char *)attribute + sizeof(Qwc_RTVC_Attribute_Data_t));
+ else if (attribute->Key_Field == QWCA_KEY_DEFAULTCCSID)
+ defaultCcsid = *(int *)((char *)attribute + sizeof(Qwc_RTVC_Attribute_Data_t));
+ else
+ strncpy(langID, ((char *)attribute + sizeof(Qwc_RTVC_Attribute_Data_t)), 3);
+ attribute = (Qwc_RTVC_Attribute_Data_t *)((char *)attribute + attribute->Length_Field_Info_Rtnd);
+ }
+ if (*ccsid == 65535)
+ *ccsid = defaultCcsid;
+
+ return 0;
+
+ RetrieveJobCcsidError:
+ return -1;
+}
+
+
+typedef int HMODULE;
+
+static char *dlErrorMessage = NULL;
+
+/*
+ * ==========================================
+ * dlopen()
+ * Gain access to an executable object file.
+ * ==========================================
+ */
+void * os400_dlopen(const char *file)
+{
+ Qus_EC_t err = { sizeof(err), 0};
+ int rc;
+ char dllPath[4*1024+1];
+ char *fp;
+ char pathNameBuffer[8*1024];
+ Qlg_Path_Name_T *pathName;
+ Qp0l_QSYS_Info_t qsys_info;
+ char objectName[11];
+ char objectLibrary[11];
+ _SYSPTR sysP;
+ _OBJ_TYPE_T objectType;
+ HMODULE handle;
+ int actInfoLen;
+ Qle_ABP_Info_t activationInfo;
+ void *returnHandle;
+
+ dlErrorMessage = NULL;
+
+ // Assume symbolic link, if error, assume actual path
+
+ memset(dllPath, 0x00, 4*1024+1);
+ rc = readlink ( file , dllPath, 4*1024);
+ if (rc == -1)
+ strcpy(dllPath, file);
+
+ // Uppercase file
+ fp = dllPath;
+ while (*fp++) *fp = toupper(*fp);
+
+ // Parse the path to its QSYS.LIB file system name: library and service program.
+
+ pathName = (Qlg_Path_Name_T *)pathNameBuffer;
+
+ memset(pathNameBuffer, 0x00, sizeof (pathNameBuffer));
+ pathName->Path_Length = strlen(dllPath);
+ memcpy( &(((char *) pathName)[sizeof(Qlg_Path_Name_T)]), dllPath, pathName->Path_Length);
+ pathName->Path_Name_Delimiter[0] = '/';
+
+ Qp0lCvtPathToQSYSObjName(pathName,&qsys_info,"QSYS0100",sizeof(Qp0l_QSYS_Info_t), 0, &err);
+
+ if (err.Bytes_Available)
+ {
+ dlErrorMessage = "Path to shared library not valid.";
+ return NULL;
+ }
+
+ // blank pad object name and library in order to use on rslvsp().
+
+ sprintf(objectName, "%-10.10s", qsys_info.Obj_Name);
+ sprintf(objectLibrary,"%-10.10s", qsys_info.Lib_Name);
+
+#pragma exception_handler (LBL_RSLV_EH, 0,_C1_ALL,_C2_MH_ESCAPE |_C2_MH_FUNCTION_CHECK, _CTLA_HANDLE)
+
+ // Resolve pointer to DLL.
+ objectType = WLI_SRVPGM;
+ sysP = rslvsp(objectType,objectName, objectLibrary,_AUTH_EXECUTE);
+
+#pragma disable_handler
+
+ // We got a pointer to the DLL. Activate it (i.e. load it).
+ actInfoLen = sizeof(activationInfo);
+ QleActBndPgm (&sysP,&handle,&activationInfo,&actInfoLen,&err);
+ if (err.Bytes_Available)
+ {
+ dlErrorMessage = "Unable to activate shared library.";
+ return NULL;
+ }
+
+ // Return the dlopen object.
+ returnHandle = malloc(sizeof(HMODULE));
+ memcpy(returnHandle, &handle, sizeof(HMODULE));
+ return returnHandle;
+
+ LBL_RSLV_EH:
+ dlErrorMessage = "Unable to resolve to shared library.";
+ return NULL;
+}
+
+/*
+ * dlsym()
+ * Obtain the address to symbol from a dlopen() object.
+ */
+void * os400_dlsym(void *handle, const char * name)
+{
+ void *symbolAddress = NULL;
+ int exportType;
+
+ Qus_EC_t err = {sizeof(err),0 };
+ dlErrorMessage = NULL;
+
+#pragma exception_handler (LBL_RSLV_EH, 0,_C1_ALL,_C2_MH_ESCAPE |_C2_MH_FUNCTION_CHECK, _CTLA_HANDLE)
+
+ // Get the function pointer.
+ // Export type of 1 means that that the pointer is to a procedure.
+
+ QleGetExp ((int *)handle,0,0,(char *)name,&symbolAddress,&exportType,&err);
+ if (err.Bytes_Available)
+ {
+ dlErrorMessage = "Unable to resolve to procedure in shared library.";
+ return NULL;
+ }
+
+ return symbolAddress;
+
+#pragma disable_handler
+
+ LBL_RSLV_EH:
+ dlErrorMessage = "Unable to resolve to procedure in shared library.";
+ return NULL;
+}
+
+
+/*
+ * ==========================================
+ * dlclose()
+ * Close a dlopen() object.
+ * ==========================================
+ */
+int os400_dlclose(void *handle)
+{
+ dlErrorMessage = NULL;
+ *(int *)handle = -1;
+ free(handle);
+ return 0;
+}
+
+/*
+ * ==========================================
+ * dlclose()
+ * Close a dlopen() object.
+ * ==========================================
+ */
+char * os400_dlerror()
+{
+ char *retError = dlErrorMessage;
+ dlErrorMessage = NULL;
+ return retError;
+}
+
+/* ---------------------------------------------------------------------------------*/
+/* ---------------------------------------------------------------------------------*/
+/* Below are routines to handle conversion between ascii and ebcdic */
+/* */
+/* The tables below are used to translate single byte data, and should never */
+/* be used to translate data that is not single byte. */
+/* ---------------------------------------------------------------------------------*/
+/* ---------------------------------------------------------------------------------*/
+
+
+/* constToAsc conversion table generated by ebcdic 37 -> ascii 819 */
+const char EBCDICtoASCII[256] = {
+/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
+ 0, 1, 2, 3, 156, 9, 134, 127, 151, 141, 142, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 157, 133, 8, 135, 24, 25, 146, 143, 28, 29, 30, 31,
+ 128, 129, 130, 131, 132, 10, 23, 27, 136, 137, 138, 139, 140, 5, 6, 7,
+ 144, 145, 22, 147, 148, 149, 150, 4, 152, 153, 154, 155, 20, 21, 158, 26,
+ 32, 160, 226, 228, 224, 225, 227, 229, 231, 241, 162, 46, 60, 40, 43, 124,
+ 38, 233, 234, 235, 232, 237, 238, 239, 236, 223, 33, 36, 42, 41, 59, 172,
+ 45, 47, 194, 196, 192, 193, 195, 197, 199, 209, 166, 44, 37, 95, 62, 63,
+ 248, 201, 202, 203, 200, 205, 206, 207, 204, 96, 58, 35, 64, 39, 61, 34,
+ 216, 97, 98, 99, 100, 101, 102, 103, 104, 105, 171, 187, 240, 253, 254, 177,
+ 176, 106, 107, 108, 109, 110, 111, 112, 113, 114, 170, 186, 230, 184, 198, 164,
+ 181, 126, 115, 116, 117, 118, 119, 120, 121, 122, 161, 191, 208, 221, 222, 174,
+ 94, 163, 165, 183, 169, 167, 182, 188, 189, 190, 91, 93, 175, 168, 180, 215,
+ 123, 65, 66, 67, 68, 69, 70, 71, 72, 73, 173, 244, 246, 242, 243, 245,
+ 125, 74, 75, 76, 77, 78, 79, 80, 81, 82, 185, 251, 252, 249, 250, 255,
+ 92, 247, 83, 84, 85, 86, 87, 88, 89, 90, 178, 212, 214, 210, 211, 213,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 179, 219, 220, 217, 218, 159
+};
+
+/* ascToString conversion table generated by ascii 819 -> ebcdic 37 */
+const char ASCIItoEBCDIC[256] = {
+/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
+ 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 37, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 60, 61, 50, 38, 24, 25, 63, 39, 28, 29, 30, 31,
+ 64, 90, 127, 123, 91, 108, 80, 125, 77, 93, 92, 78, 107, 96, 75, 97,
+ 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 122, 94, 76, 126, 110, 111,
+ 124, 193, 194, 195, 196, 197, 198, 199, 200, 201, 209, 210, 211, 212, 213, 214,
+ 215, 216, 217, 226, 227, 228, 229, 230, 231, 232, 233, 186, 224, 187, 176, 109,
+ 121, 129, 130, 131, 132, 133, 134, 135, 136, 137, 145, 146, 147, 148, 149, 150,
+ 151, 152, 153, 162, 163, 164, 165, 166, 167, 168, 169, 192, 79, 208, 161, 7,
+ 32, 33, 34, 35, 36, 21, 6, 23, 40, 41, 42, 43, 44, 9, 10, 27,
+ 48, 49, 26, 51, 52, 53, 54, 8, 56, 57, 58, 59, 4, 20, 62, 255,
+ 65, 170, 74, 177, 159, 178, 106, 181, 189, 180, 154, 138, 95, 202, 175, 188,
+ 144, 143, 234, 250, 190, 160, 182, 179, 157, 218, 155, 139, 183, 184, 185, 171,
+ 100, 101, 98, 102, 99, 103, 158, 104, 116, 113, 114, 115, 120, 117, 118, 119,
+ 172, 105, 237, 238, 235, 239, 236, 191, 128, 253, 254, 251, 252, 173, 174, 89,
+ 68, 69, 66, 70, 67, 71, 156, 72, 84, 81, 82, 83, 88, 85, 86, 87,
+ 140, 73, 205, 206, 203, 207, 204, 225, 112, 221, 222, 219, 220, 141, 142, 223
+};
+
+
+/* converts an existing non constant character buffer from Ebcdic ( 37 ) */
+/* to Ascii ( 819 ). */
+char* strtoasc( char *string )
+{
+ char* pch = string;
+ if( string == NULL ) return NULL;
+
+ /* while not EOL... */
+ while( *pch != (char)0 )
+ {
+ *pch = EBCDICtoASCII[*pch];
+ pch++;
+ }
+ return string;
+}
+char* buftoasc( char *b, int len )
+{
+ char* pch = b;
+ if( b == NULL ) return NULL;
+
+ /* while not EOL... */
+ while( len > 0 )
+ {
+ *pch = EBCDICtoASCII[*pch];
+ pch++;len--;
+ }
+ return b;
+}
+
+/* converts an existing non-constant character buffer from ASCII ( 819 ) */
+/* to EBCDIC ( 37 ). */
+char* asctostr( char *string )
+{
+ char* pch = string;
+ if( string == NULL ) return NULL;
+
+ /* while not EOL... */
+ while( *pch != (char)0 )
+ {
+ *pch = ASCIItoEBCDIC[*pch];
+ pch++;
+ }
+ return string;
+}
+char* asctobuf( char *b, int len )
+{
+ char* pch = b;
+ if( b == NULL ) return NULL;
+
+ /* while not EOL... */
+ while( len > 0 )
+ {
+ *pch = ASCIItoEBCDIC[*pch];
+ pch++;len--;
+ }
+ return b;
+}
+
+
+char PLATFORM_DOUBLE_QUOTE_S[] = "\"";
+char PLATFORM_DOUBLE_QUOTE_C = '\"';
+char PLATFORM_XML_ENTITY_REFERENCE_CHARS_S[] = "<>&\"\'";
+
+static int initializePlatform(void)
+{
+ char *language= "En_US";
+ char langID[3] = {'E' , 'N' , 'U'};
+ int jobCCSID = 37;
+
+ int rc = retrieveJobCcsid(&jobCCSID, langID);
+ if (rc == 0)
+ {
+ // double quote character is not invariant when running
+ // turkish ccsid (1026). That is, the hexadecimal value
+ // of double quote is different than when running in
+ // any other language. So use correct double quote character.
+ if (jobCCSID == 1026)
+ {
+ strcpy(PLATFORM_DOUBLE_QUOTE_S, "\xFC");
+ PLATFORM_DOUBLE_QUOTE_C = '\xFC';
+ strcpy(PLATFORM_XML_ENTITY_REFERENCE_CHARS_S, "<>&\xFC\'");
+ }
+ }
+
+ return rc;
+}
+
+// TODO-AMRA static int platformRc = initializePlatform();
+
+
+int +os400_alphasort( + const struct dirent **__d1, + const struct dirent **__d2) +{ + return strcoll((*__d1)->d_name, (*__d2)->d_name); +} + +int +os400_scandir( + const char *_dirname, + struct dirent **__namelist[], + int (*selector) (const struct dirent * entry), + int (*compare) (const struct dirent ** __d1, + const struct dirent ** __d2)) +{ + DIR *dirp = NULL; + struct dirent **vector = NULL; + struct dirent *dp = NULL; + int vector_size = 0; + int nfiles = 0; + + if (__namelist == NULL) + { + return -1; + } + dirp = opendir(_dirname); + if (!dirp) + { + return -1; + } + dp = readdir(dirp); + while (dp) + { + int dsize = 0; + struct dirent *newdp = NULL; + + if (selector && (*selector) (dp) == 0) + { + dp = readdir(dirp); + continue; + } + + if (nfiles == vector_size) + { + struct dirent **newv; + if (vector_size == 0) + { + vector_size = 10; + } + else + { + vector_size *= 2; + } + + newv = + (struct dirent **) realloc(vector, + vector_size * + sizeof(struct dirent *)); + if (!newv) + { + return -1; + } + vector = newv; + } + + /*dsize = + (int) sizeof(struct dirent) + + (int) ((strlen(dp->d_name) + 1) * sizeof(char));*/ + dsize = (int) sizeof(struct dirent); + newdp = (struct dirent *) malloc(dsize); + + if (newdp == NULL) + { + while (nfiles-- > 0) + { + free(vector[nfiles]); + } + free(vector); + return -1; + } + + vector[nfiles++] = (struct dirent *) memcpy(newdp, dp, dsize); + dp = readdir(dirp); + } + + closedir(dirp); + + *__namelist = vector; + + if (compare) + { + // TODO-AMRA qsort(*__namelist, nfiles, sizeof(struct dirent *), compare); + } + + return nfiles; +} diff --git a/util/src/platforms/os400/thread_os400.c b/util/src/platforms/os400/thread_os400.c new file mode 100644 index 0000000..0269f9e --- /dev/null +++ b/util/src/platforms/os400/thread_os400.c @@ -0,0 +1,358 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 "axutil_thread_os400.h" + +AXIS2_EXTERN axutil_threadattr_t *AXIS2_CALL +axutil_threadattr_create( + axutil_allocator_t * allocator) +{ + int stat = 0; + axutil_threadattr_t *new = NULL; + + new = AXIS2_MALLOC(allocator, sizeof(axutil_threadattr_t)); + if (!new) + { + return NULL; + } + stat = pthread_attr_init(&(new->attr)); + + if (stat != 0) + { + AXIS2_FREE(allocator, new); + return NULL; + } + return new; +} + +/* Destroy the threadattr object */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +threadattr_cleanup( + void *data) +{ + axutil_threadattr_t *attr = data; + int rv; + + rv = pthread_attr_destroy(&(attr->attr)); + + if (0 != rv) + { + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +#define DETACH_ARG(v) ((v) ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE) + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_threadattr_detach_set( + axutil_threadattr_t * attr, + axis2_bool_t detached) +{ + if (0 == pthread_attr_setdetachstate(&(attr->attr), DETACH_ARG(detached))) + { + return AXIS2_SUCCESS; + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_threadattr_detach_get( + axutil_threadattr_t * attr) +{ + int state = 0; + pthread_attr_getdetachstate(&(attr->attr), &state); + if (state == 1) + { + return AXIS2_TRUE; + } + return AXIS2_FALSE; +} + +static void * +dummy_worker( + void *opaque) +{ + axutil_thread_t *thread = (axutil_thread_t *) opaque; + return thread->func(thread, thread->data); +} + +AXIS2_EXTERN axutil_thread_t *AXIS2_CALL +axutil_thread_create( + axutil_allocator_t * allocator, + axutil_threadattr_t * attr, + axutil_thread_start_t func, + void *data) +{ + axis2_status_t stat; + pthread_attr_t *temp = NULL; + axutil_thread_t *new = NULL; + + new = (axutil_thread_t *) AXIS2_MALLOC(allocator, sizeof(axutil_thread_t)); + + if (!new) + { + return NULL; + } + new->td = (pthread_t *) AXIS2_MALLOC(allocator, sizeof(pthread_t)); + if (!new->td) + { + return NULL; + } + + new->data = data; + new->func = func; + new->try_exit = AXIS2_FALSE; + + if (attr) + { + temp = &(attr->attr); + } + else + { + temp = NULL; + } + + if ((stat = pthread_create(new->td, temp, dummy_worker, new)) == 0) + { + return new; + } + return NULL; +} + +AXIS2_EXTERN axis2_os_thread_t AXIS2_CALL +axis2_os_thread_current( + void) +{ + return pthread_self(); +} + +AXIS2_EXTERN int AXIS2_CALL +axis2_os_thread_equal( + axis2_os_thread_t tid1, + axis2_os_thread_t tid2) +{ + return pthread_equal(tid1, tid2); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_exit( + axutil_thread_t * thd, + axutil_allocator_t * allocator) +{ + axis2_bool_t same_thread = AXIS2_TRUE; + if (thd) + { + while (!thd->try_exit) + { + sleep(1); + } + + if (thd->td) + { + same_thread = pthread_equal(pthread_self(), *thd->td); + if(!same_thread) + { + pthread_kill(*(thd->td), 0); + axutil_thread_join(thd); + } + AXIS2_FREE(allocator, thd->td); + } + AXIS2_FREE(allocator, thd); + } + if(same_thread) + { + pthread_exit(NULL); + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_join( + axutil_thread_t * thd) +{ + void *thread_stat; + if (0 == pthread_join(*(thd->td), (void *) (&thread_stat))) + { + return AXIS2_SUCCESS; + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_detach( + axutil_thread_t * thd) +{ + if (0 == pthread_detach(*(thd->td))) + { + thd->try_exit = AXIS2_TRUE; + return AXIS2_SUCCESS; + } + return AXIS2_FAILURE; +} + +void +axutil_thread_yield( + void) +{ + return; +} + +/** + * function is used to allocate a new key. This key now becomes valid for all threads in our process. + * When a key is created, the value it points to defaults to NULL. Later on each thread may change + * its copy of the value as it wishes. + */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_key_create( + axutil_threadkey_t * axis2_key) +{ + int rc = -1; + pthread_key_t key = axis2_key->key; + rc = pthread_key_create(&key, NULL); + if (0 == rc) + return AXIS2_SUCCESS; + else + return AXIS2_FAILURE; +} + +/** + * This function is used to get the value of a given key + * @return void*. A key's value is simply a void pointer (void*) + */ +AXIS2_EXTERN void *AXIS2_CALL +axutil_thread_getspecific( + axutil_threadkey_t * axis2_key) +{ + void *value = NULL; + pthread_key_t key = axis2_key->key; + value = pthread_getspecific(key); + return value; +} + +/** + * This function is used to get the value of a given key + * @param keys value. A key's value is simply a void pointer (void*), so we can + * store in it anything that we want + */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_setspecific( + axutil_threadkey_t * axis2_key, + void *value) +{ + int rc = -1; + pthread_key_t key = axis2_key->key; + rc = pthread_setspecific(key, value); + if (0 == rc) + return AXIS2_SUCCESS; + else + return AXIS2_FAILURE; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_thread_key_free( + axutil_threadkey_t * axis2_key) +{ + pthread_key_t key = axis2_key->key; + pthread_key_delete(key); +} + +AXIS2_EXTERN axis2_os_thread_t *AXIS2_CALL +axis2_os_thread_get( + axutil_thread_t * thd) +{ + if (!thd) + { + return NULL; + } + return thd->td; +} + +AXIS2_EXTERN axutil_thread_once_t *AXIS2_CALL +axutil_thread_once_init( + axutil_allocator_t * allocator) +{ + static const pthread_once_t once_init = PTHREAD_ONCE_INIT; + axutil_thread_once_t *control = AXIS2_MALLOC(allocator, sizeof(axutil_thread_once_t)); + if (!control) + { + return NULL; + } + (control)->once = once_init; + return control; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_once( + axutil_thread_once_t * control, + void + (*func)( + void)) +{ + return pthread_once(&(control->once), func); +} + +/*************************Thread locking functions*****************************/ +AXIS2_EXTERN axutil_thread_mutex_t *AXIS2_CALL +axutil_thread_mutex_create( + axutil_allocator_t * allocator, + unsigned int flags) +{ + axutil_thread_mutex_t *new_mutex = NULL; + + new_mutex = AXIS2_MALLOC(allocator, sizeof(axutil_thread_mutex_t)); + new_mutex->allocator = allocator; + + if (pthread_mutex_init(&(new_mutex->mutex), NULL) != 0) + { + AXIS2_FREE(allocator, new_mutex); + return NULL; + } + return new_mutex; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_mutex_lock( + axutil_thread_mutex_t * mutex) +{ + return pthread_mutex_lock(&(mutex->mutex)); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_mutex_unlock( + axutil_thread_mutex_t * mutex) +{ + if (pthread_mutex_unlock(&(mutex->mutex)) != 0) + { + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_mutex_destroy( + axutil_thread_mutex_t * mutex) +{ + if (0 != pthread_mutex_destroy(&(mutex->mutex))) + { + return AXIS2_FAILURE; + } + AXIS2_FREE(mutex->allocator, mutex); + return AXIS2_SUCCESS; +} diff --git a/util/src/platforms/os400/uuid_gen_os400.c b/util/src/platforms/os400/uuid_gen_os400.c new file mode 100644 index 0000000..6c40a82 --- /dev/null +++ b/util/src/platforms/os400/uuid_gen_os400.c @@ -0,0 +1,244 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <string.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 <sys/time.h> + +# include <net/if.h> + +#include "platforms/os400/axutil_uuid_gen_os400.h" +#include "platforms/axutil_platform_auto_sense.h" + +/* We need these static variables to track throughout the program execution */ +static axis2_bool_t axutil_uuid_gen_is_first = AXIS2_TRUE; +static struct axutil_uuid_st axutil_uuid_static; + +axutil_uuid_t *AXIS2_CALL +axutil_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; + axutil_uuid_t *ret_uuid = NULL; + unsigned short int time_high_version = 0; + + if (AXIS2_TRUE == axutil_uuid_gen_is_first) + { + char *mac_addr = axutil_uuid_get_mac_addr(); + memcpy(axutil_uuid_static.mac, mac_addr, 6); + axutil_uuid_static.time_seq = 0; + axutil_uuid_static.clock = 0; + free(mac_addr); + axutil_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 == axutil_uuid_static.time_last.tv_sec && time_now.tv_usec + == axutil_uuid_static.time_last.tv_usec)) + { + /* reset time sequence counter and continue */ + axutil_uuid_static.time_seq = 0; + } + + /* until we are out of UUIDs per tick, increment + the time/tick sequence counter and continue */ + while (axutil_uuid_static.time_seq < UUIDS_PER_TICK) + { + axutil_uuid_static.time_seq++; + } + /* sleep for 1000ns (1us) */ + tv.tv_sec = 0; + tv.tv_usec = 1; + /* + The following select causes severe performance problems. + Hence commenting out. I am not sure why this is required. - Samisa. + 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(axutil_uuid_t)); + + time_val += UUID_TIMEOFFSET; + /* compensate for low resolution system clock by adding + the time/tick sequence counter */ + if (axutil_uuid_static.time_seq > 0) + time_val += (unsigned long long) axutil_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 = axutil_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 < axutil_uuid_static.time_last.tv_sec || (time_now.tv_sec + == axutil_uuid_static.time_last.tv_sec && time_now.tv_usec + < axutil_uuid_static.time_last.tv_usec))) + { + srand(time_now.tv_usec); + clck = rand(); + } + else + { + clck++; + } + clck %= (2 << 14); + + /* store back new clock sequence */ + axutil_uuid_static.clock = clck; + + clck &= 0x1FFF; + clck |= 0x2000; + + /* + * FINISH + */ + /* remember current system time for next iteration */ + axutil_uuid_static.time_last.tv_sec = time_now.tv_sec; + axutil_uuid_static.time_last.tv_usec = time_now.tv_usec; + + if (!ret_uuid) + { + return NULL; + } + ret_uuid->clock_variant = clck; + memcpy(ret_uuid->mac_addr, axutil_uuid_static.mac, 6); + return ret_uuid; +} + +axis2_char_t *AXIS2_CALL +axutil_platform_uuid_gen( + char *s) +{ + axutil_uuid_t *uuid_struct = NULL; + axis2_char_t *uuid_str = NULL; + unsigned char mac[7]; + char mac_hex[13]; + + if (!s) + { + return NULL; + } + uuid_struct = axutil_uuid_gen_v1(); + if (!uuid_struct) + { + return NULL; + } + uuid_str = s; + if (!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); + free(uuid_struct); + uuid_struct = NULL; + return uuid_str; +} + +char *AXIS2_CALL +axutil_uuid_get_mac_addr( + ) +{ + struct ifreq ifr; + struct ifreq *IFR; + struct ifconf ifc; + struct sockaddr *sa; + int s = 0; + int i = 0; + char *buffer = NULL; + char buf[1024]; + int ok = AXIS2_FALSE; + + if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) + return NULL; + + ifc.ifc_len = sizeof(buf); + ifc.ifc_buf = buf; + ioctl(s, SIOCGIFCONF, &ifc); + IFR = ifc.ifc_req; + + for (i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; IFR++) + { + strcpy(ifr.ifr_name, IFR->ifr_name); + /*sprintf(ifr.ifr_name, "eth0"); */ + if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0) + { + if (!(ifr.ifr_flags & IFF_LOOPBACK)) + { + +// TODO-AMRA if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) + { + ok = AXIS2_TRUE; + break; + } + } + } + } + buffer = (char *) malloc(6 * sizeof(char)); + if (ok) + { + sa = (struct sockaddr *) &ifr.ifr_addr; + for (i = 0; i < 6; i++) + buffer[i] = (unsigned char) (sa->sa_data[i] & 0xff); + } + else + { + for (i = 0; i < 6; i++) + buffer[i] = (unsigned char) ((AXIS2_LOCAL_MAC_ADDR[i]) - '0'); + } + close(s); + return buffer; +} + |