summaryrefslogtreecommitdiff
path: root/pjlib
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2011-02-28 07:44:19 +0000
committerBenny Prijono <bennylp@teluu.com>2011-02-28 07:44:19 +0000
commitd62ff46dee0080e4470c03496614245f23c68a2d (patch)
tree2a6f0fbd7ce92cb34f7ec671f6beff15c0b872e9 /pjlib
parenta8f0337ed01c61809d5ff4b0ae026cbae142b697 (diff)
Initial implementation for re #1202 (PJILB System Information API) for Linux/Unix
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3423 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib')
-rw-r--r--pjlib/build/Makefile2
-rw-r--r--pjlib/include/pj/compat/os_auto.h.in2
-rw-r--r--pjlib/include/pj/config.h24
-rw-r--r--pjlib/include/pj/os.h94
-rw-r--r--pjlib/src/pj/config.c9
-rw-r--r--pjlib/src/pj/os_info.c242
6 files changed, 371 insertions, 2 deletions
diff --git a/pjlib/build/Makefile b/pjlib/build/Makefile
index 76fece33..6e95003e 100644
--- a/pjlib/build/Makefile
+++ b/pjlib/build/Makefile
@@ -24,7 +24,7 @@ export PJLIB_SRCDIR = ../src/pj
export PJLIB_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \
activesock.o array.o config.o ctype.o errno.o except.o fifobuf.o \
guid.o hash.o ip_helper_generic.o list.o lock.o log.o os_time_common.o \
- pool.o pool_buf.o pool_caching.o pool_dbg.o rand.o \
+ os_info.o pool.o pool_buf.o pool_caching.o pool_dbg.o rand.o \
rbtree.o sock_common.o sock_qos_common.o sock_qos_bsd.o \
ssl_sock_common.o ssl_sock_ossl.o ssl_sock_dump.o \
string.o timer.o types.o
diff --git a/pjlib/include/pj/compat/os_auto.h.in b/pjlib/include/pj/compat/os_auto.h.in
index 5c5f74bf..97501a55 100644
--- a/pjlib/include/pj/compat/os_auto.h.in
+++ b/pjlib/include/pj/compat/os_auto.h.in
@@ -48,6 +48,7 @@
#undef PJ_HAS_CTYPE_H
#undef PJ_HAS_ERRNO_H
#undef PJ_HAS_FCNTL_H
+#undef PJ_HAS_LIMITS_H
#undef PJ_HAS_LINUX_SOCKET_H
#undef PJ_HAS_MALLOC_H
#undef PJ_HAS_NETDB_H
@@ -73,6 +74,7 @@
#undef PJ_HAS_SYS_TYPES_H
#undef PJ_HAS_SYS_FILIO_H
#undef PJ_HAS_SYS_SOCKIO_H
+#undef PJ_HAS_SYS_UTSNAME_H
#undef PJ_HAS_TIME_H
#undef PJ_HAS_UNISTD_H
diff --git a/pjlib/include/pj/config.h b/pjlib/include/pj/config.h
index bf05cbae..f75a7f34 100644
--- a/pjlib/include/pj/config.h
+++ b/pjlib/include/pj/config.h
@@ -1119,6 +1119,30 @@
PJ_BEGIN_DECL
+/** PJLIB version major number. */
+#define PJ_VERSION_NUM_MAJOR 1
+
+/** PJLIB version minor number. */
+#define PJ_VERSION_NUM_MINOR 8
+
+/** PJLIB version revision number. */
+#define PJ_VERSION_NUM_REV 10
+
+/**
+ * Extra suffix for the version (e.g. "-trunk"), or empty for
+ * web release version.
+ */
+#define PJ_VERSION_NUM_EXTRA "-trunk"
+
+/**
+ * PJLIB version number consists of three bytes with the following format:
+ * 0xMMIIRR00, where MM: major number, II: minor number, RR: revision
+ * number, 00: always zero for now.
+ */
+#define PJ_VERSION_NUM ((PJ_VERSION_NUM_MAJOR << 24) | \
+ (PJ_VERSION_NUM_MINOR << 16) | \
+ (PJ_VERSION_NUM_REV << 8))
+
/**
* PJLIB version string constant. @see pj_get_version()
*/
diff --git a/pjlib/include/pj/os.h b/pjlib/include/pj/os.h
index e1d3c485..8d50476a 100644
--- a/pjlib/include/pj/os.h
+++ b/pjlib/include/pj/os.h
@@ -35,6 +35,100 @@ PJ_BEGIN_DECL
/* **************************************************************************/
/**
+ * @defgroup PJ_SYS_INFO System Information
+ * @ingroup PJ_OS
+ * @{
+ */
+
+/**
+ * These enumeration contains constants to indicate support of miscellaneous
+ * system features. These will go in "flags" field of #pj_sys_info structure.
+ */
+typedef enum pj_sys_info_flag
+{
+ /**
+ * Support for Apple iOS background feature.
+ */
+ PJ_SYS_HAS_IOS_BG = 1
+
+} pj_sys_info_flag;
+
+
+/**
+ * This structure contains information about the system. Use #pj_get_sys_info()
+ * to obtain the system information.
+ */
+typedef struct pj_sys_info
+{
+ /**
+ * Null terminated string containing processor information (e.g. "i386",
+ * "x86_64"). It may contain empty string if the value cannot be obtained.
+ */
+ pj_str_t machine;
+
+ /**
+ * Null terminated string identifying the system operation (e.g. "Linux",
+ * "win32", "wince"). It may contain empty string if the value cannot be
+ * obtained.
+ */
+ pj_str_t os_name;
+
+ /**
+ * A number containing the operating system version number. By convention,
+ * this field is divided into four bytes, where the highest order byte
+ * contains the most major version of the OS, the next less significant
+ * byte contains the less major version, and so on. How the OS version
+ * number is mapped into these four bytes would be specific for each OS.
+ * For example, Linux-2.6.32-28 would yield "os_ver" value of 0x0206201c,
+ * while for Windows 7 it will be 0x06010000 (because dwMajorVersion is
+ * 6 and dwMinorVersion is 1 for Windows 7).
+ *
+ * This field may contain zero if the OS version cannot be obtained.
+ */
+ pj_uint32_t os_ver;
+
+ /**
+ * Null terminated string identifying the SDK name that is used to build
+ * the library (e.g. "glibc", "uclibc", "msvc", "wince"). It may contain
+ * empty string if the value cannot eb obtained.
+ */
+ pj_str_t sdk_name;
+
+ /**
+ * A number containing the SDK version, using the numbering convention as
+ * the "os_ver" field. The value will be zero if the version cannot be
+ * obtained.
+ */
+ pj_uint32_t sdk_ver;
+
+ /**
+ * A longer null terminated string identifying the underlying system with
+ * as much information as possible.
+ */
+ pj_str_t info;
+
+ /**
+ * Other flags containing system specific information. The value is
+ * bitmask of #pj_sys_info_flag constants.
+ */
+ pj_uint32_t flags;
+
+} pj_sys_info;
+
+
+/**
+ * Obtain the system information.
+ *
+ * @return System information structure.
+ */
+PJ_DECL(const pj_sys_info*) pj_get_sys_info(void);
+
+/*
+ * @}
+ */
+
+/* **************************************************************************/
+/**
* @defgroup PJ_THREAD Threads
* @ingroup PJ_OS
* @{
diff --git a/pjlib/src/pj/config.c b/pjlib/src/pj/config.c
index e03395e9..8be85cdb 100644
--- a/pjlib/src/pj/config.c
+++ b/pjlib/src/pj/config.c
@@ -22,7 +22,14 @@
#include <pj/ioqueue.h>
static const char *id = "config.c";
-PJ_DEF_DATA(const char*) PJ_VERSION = "1.8.10-trunk";
+
+#define PJ_MAKE_VERSION1(a,b,c,d) #a "." #b "." #c d
+#define PJ_MAKE_VERSION2(a,b,c,d) PJ_MAKE_VERSION1(a,b,c,d)
+
+PJ_DEF_DATA(const char*) PJ_VERSION = PJ_MAKE_VERSION2(PJ_VERSION_NUM_MAJOR,
+ PJ_VERSION_NUM_MINOR,
+ PJ_VERSION_NUM_REV,
+ PJ_VERSION_NUM_EXTRA);
/*
* Get PJLIB version string.
diff --git a/pjlib/src/pj/os_info.c b/pjlib/src/pj/os_info.c
new file mode 100644
index 00000000..6259aafa
--- /dev/null
+++ b/pjlib/src/pj/os_info.c
@@ -0,0 +1,242 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <pj/os.h>
+#include <pj/ctype.h>
+#include <pj/errno.h>
+#include <pj/string.h>
+
+/*
+ * FYI these links contain useful infos about predefined macros across
+ * platforms:
+ * - http://predef.sourceforge.net/preos.html
+ */
+
+#if defined(PJ_HAS_SYS_UTSNAME_H) && PJ_HAS_SYS_UTSNAME_H != 0
+/* For uname() */
+# include <sys/utsname.h>
+# include <stdlib.h>
+# define PJ_HAS_UNAME 1
+#endif
+
+#if defined(PJ_HAS_LIMITS_H) && PJ_HAS_LIMITS_H != 0
+/* Include <limits.h> to get <features.h> to get various glibc macros.
+ * See http://predef.sourceforge.net/prelib.html
+ */
+# include <limits.h>
+#endif
+
+#if defined(_MSC_VER)
+/* For all Windows including mobile */
+# include <windows.h>
+#endif
+
+
+#ifndef PJ_SYS_INFO_BUFFER_SIZE
+# define PJ_SYS_INFO_BUFFER_SIZE 64
+#endif
+
+static char *ver_info(pj_uint32_t ver, char *buf)
+{
+ int len;
+
+ if (ver == 0) {
+ *buf = '\0';
+ return buf;
+ }
+
+ sprintf(buf, "-%u.%u",
+ (ver & 0xFF000000) >> 24,
+ (ver & 0x00FF0000) >> 16);
+ len = strlen(buf);
+
+ if (ver & 0xFFFF) {
+ sprintf(buf+len, ".%u", (ver & 0xFF00) >> 8);
+ len = strlen(buf);
+
+ if (ver & 0x00FF) {
+ sprintf(buf+len, ".%u", (ver & 0xFF));
+ }
+ }
+
+ return buf;
+}
+
+PJ_DEF(const pj_sys_info*) pj_get_sys_info(void)
+{
+ static char si_buffer[PJ_SYS_INFO_BUFFER_SIZE];
+ static pj_sys_info si;
+ static pj_bool_t si_initialized;
+ unsigned left = PJ_SYS_INFO_BUFFER_SIZE, len;
+
+ if (si_initialized)
+ return &si;
+
+#define ALLOC_CP_STR(str,field) \
+ do { \
+ len = pj_ansi_strlen(str); \
+ if (len && left >= len+1) { \
+ si.field.ptr = si_buffer + PJ_SYS_INFO_BUFFER_SIZE - left; \
+ si.field.slen = len; \
+ pj_memcpy(si.field.ptr, str, len+1); \
+ left -= (len+1); \
+ } \
+ } while (0)
+
+ /*
+ * Machine and OS info.
+ */
+#if defined(PJ_HAS_UNAME) && PJ_HAS_UNAME
+ {
+ struct utsname u;
+ char *tok;
+ int i, maxtok;
+
+ if (uname(&u) != 0)
+ goto get_sdk_info;
+ ALLOC_CP_STR(u.machine, machine);
+ ALLOC_CP_STR(u.sysname, os_name);
+
+ maxtok = 4;
+ for (tok = strtok(u.release, ".-"), i=0;
+ tok && i<maxtok;
+ ++i, tok=strtok(NULL, ".-"))
+ {
+ int n;
+
+ if (!pj_isdigit(*tok))
+ break;
+
+ n = atoi(tok);
+ si.os_ver |= (n << ((3-i)*8));
+ }
+ }
+#elif defined(_MSC_VER)
+ {
+ OSVERSIONINFO ovi;
+
+ ovi.dwOSVersionInfoSize = sizeof(ovi);
+
+ if (GetVersionInfoEx(&ovi) == FALSE)
+ goto get_sdk_info;
+
+ si.os_ver = (ovi.dwMajorVersion << 24) |
+ (ovi.dwMinorVersion << 16);
+ #if defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE
+ si.os_name = pj_str("wince");
+ #else
+ si.os_name = pj_str("win32");
+ #endif
+ }
+
+ {
+ SYSTEM_INFO wsi;
+
+ GetSystemInfo(&wsi);
+ switch (wsi.wProcessorArchitecture) {
+ #if defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE
+ case PROCESSOR_ARCHITECTURE_ARM:
+ si.machine = pj_str("arm");
+ break;
+ case PROCESSOR_ARCHITECTURE_SHX:
+ si.machine = pj_str("shx");
+ break;
+ #else
+ case PROCESSOR_ARCHITECTURE_AMD64:
+ si.machine = pj_str("x86_64");
+ break;
+ case PROCESSOR_ARCHITECTURE_IA64:
+ si.machine = pj_str("ia64");
+ break;
+ case PROCESSOR_ARCHITECTURE_INTEL:
+ si.machine = pj_str("i386");
+ break;
+ #endif /* PJ_WIN32_WINCE */
+ }
+ }
+#endif
+
+ /*
+ * SDK info.
+ */
+get_sdk_info:
+
+#if defined(__GLIBC__)
+ si.sdk_ver = (__GLIBC__ << 24) |
+ (__GLIBC_MINOR__ << 16);
+ si.sdk_name = pj_str("glibc");
+#elif defined(__GNU_LIBRARY__)
+ si.sdk_ver = (__GNU_LIBRARY__ << 24) |
+ (__GNU_LIBRARY_MINOR__ << 16);
+ si.sdk_name = pj_str("libc");
+#elif defined(__UCLIBC__)
+ si.sdk_ver = (__UCLIBC_MAJOR__ << 24) |
+ (__UCLIBC_MINOR__ << 16);
+ si.sdk_name = pj_str("uclibc");
+#elif defined(_WIN32_WCE) && _WIN32_WCE
+ /* Old window mobile declares _WIN32_WCE as decimal (e.g. 300, 420, etc.),
+ * but then it was changed to use hex, e.g. 0x420, etc. See
+ * http://social.msdn.microsoft.com/forums/en-US/vssmartdevicesnative/thread/8a97c59f-5a1c-4bc6-99e6-427f065ff439/
+ */
+ #if _WIN32_WCE <= 500
+ si.sdk_ver = ( (_WIN32_WCE / 100) << 24) |
+ ( ((_WIN32_WCE % 100) / 10) << 16) |
+ ( (_WIN32_WCE % 10) << 8);
+ #else
+ si.sdk_ver = ( ((_WIN32_WCE & 0xFF00) >> 8) << 24) |
+ ( ((_WIN32_WCE & 0x00F0) >> 4) << 16) |
+ ( ((_WIN32_WCE & 0x000F) >> 0) << 8);
+ #endif
+ si.sdk_name = pj_str("cesdk");
+#elif defined(_MSC_VER)
+ /* No SDK info is easily obtainable for Visual C, so lets just use
+ * _MSC_VER. The _MSC_VER macro reports the major and minor versions
+ * of the compiler. For example, 1310 for Microsoft Visual C++ .NET 2003.
+ * 1310 represents version 13 and a 1.0 point release.
+ * The Visual C++ 2005 compiler version is 1400.
+ */
+ si.sdk_ver = ((_MSC_VER / 100) << 24) |
+ (((_MSC_VER % 100) / 10) << 16) |
+ ((_MSC_VER % 10) << 8);
+ si.sdk_name = pj_str("msvc");
+#endif
+
+ /*
+ * Build the info string.
+ */
+ {
+ char tmp[PJ_SYS_INFO_BUFFER_SIZE];
+ char os_ver[20], sdk_ver[20];
+ int len;
+
+ len = pj_ansi_snprintf(tmp, sizeof(tmp),
+ "%s%s/%s/%s%s",
+ si.os_name.ptr,
+ ver_info(si.os_ver, os_ver),
+ si.machine.ptr,
+ si.sdk_name.ptr,
+ ver_info(si.sdk_ver, sdk_ver));
+ if (len > 0 && len < sizeof(tmp)) {
+ ALLOC_CP_STR(tmp, info);
+ }
+ }
+
+ si_initialized = PJ_TRUE;
+ return &si;
+}