From 2068f13bc42cf3a47374aa2765f82724a5782028 Mon Sep 17 00:00:00 2001 From: Liong Sauw Ming Date: Mon, 24 Oct 2011 09:28:13 +0000 Subject: Re #1395: Backport of PJSIP 1.x branch into PJSIP 2.0 trunk * Backport of r3557:r3832 TODO: ticket #1268 (Option for automatic/manual sending of RTCP SDES/BYE for the stream) for video stream. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3841 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/include/pj/compat/os_auto.h.in | 2 + pjlib/include/pj/compat/os_symbian.h | 5 +++ pjlib/include/pj/compat/os_win32_wince.h | 6 +++ pjlib/include/pj/config.h | 23 +++++----- pjlib/include/pj/hash.h | 4 +- pjlib/include/pj/sock.h | 9 +++- pjlib/src/pj/ioqueue_symbian.cpp | 3 +- pjlib/src/pj/sock_common.c | 7 +++- pjlib/src/pj/ssl_sock_ossl.c | 4 ++ pjlib/src/pjlib-test/os.c | 72 ++++++++++++++++++++++++++++++++ pjlib/src/pjlib-test/sock.c | 2 +- 11 files changed, 119 insertions(+), 18 deletions(-) (limited to 'pjlib') diff --git a/pjlib/include/pj/compat/os_auto.h.in b/pjlib/include/pj/compat/os_auto.h.in index 1dc88028..77980d36 100644 --- a/pjlib/include/pj/compat/os_auto.h.in +++ b/pjlib/include/pj/compat/os_auto.h.in @@ -177,6 +177,8 @@ # include "Availability.h" /* Use CFHost API for pj_getaddrinfo() (see ticket #1246) */ # define PJ_GETADDRINFO_USE_CFHOST 1 + /* Disable local host resolution in pj_gethostip() (see ticket #1342) */ +# define PJ_GETHOSTIP_DISABLE_LOCAL_RESOLUTION 1 # ifdef __IPHONE_4_0 /* Is multitasking support available? (see ticket #1107) */ # define PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT 1 diff --git a/pjlib/include/pj/compat/os_symbian.h b/pjlib/include/pj/compat/os_symbian.h index 62bd3e9f..9f953648 100644 --- a/pjlib/include/pj/compat/os_symbian.h +++ b/pjlib/include/pj/compat/os_symbian.h @@ -108,6 +108,11 @@ # define NULL 0 #endif +/* Endianness */ +#ifndef PJ_IS_LITTLE_ENDIAN +# define PJ_IS_LITTLE_ENDIAN 1 +# define PJ_IS_BIG_ENDIAN 0 +#endif /* Doesn't seem to allow more than this */ #define PJ_IOQUEUE_MAX_HANDLES 8 diff --git a/pjlib/include/pj/compat/os_win32_wince.h b/pjlib/include/pj/compat/os_win32_wince.h index 043bb632..9ae05313 100644 --- a/pjlib/include/pj/compat/os_win32_wince.h +++ b/pjlib/include/pj/compat/os_win32_wince.h @@ -98,6 +98,12 @@ */ #define PJ_SELECT_NEEDS_NFDS 0 +/* Endianness */ +#ifndef PJ_IS_LITTLE_ENDIAN +# define PJ_IS_LITTLE_ENDIAN 1 +# define PJ_IS_BIG_ENDIAN 0 +#endif + /* Default threading is enabled, unless it's overridden. */ #ifndef PJ_HAS_THREADS # define PJ_HAS_THREADS (1) diff --git a/pjlib/include/pj/config.h b/pjlib/include/pj/config.h index c96d0ce8..dd3533e8 100644 --- a/pjlib/include/pj/config.h +++ b/pjlib/include/pj/config.h @@ -170,7 +170,7 @@ #elif defined(PJ_M_IA64) || defined(__ia64__) || defined(_IA64) || \ defined(__IA64__) || defined( _M_IA64) /* - * Intel IA64 processor, little endian + * Intel IA64 processor, default to little endian */ # undef PJ_M_IA64 # define PJ_M_IA64 1 @@ -208,15 +208,14 @@ #elif defined(PJ_M_MIPS) || defined(__mips__) || defined(__mips) || \ defined(__MIPS__) || defined(MIPS) || defined(_MIPS_) /* - * MIPS, default to little endian + * MIPS, bi-endian, so raise error if endianness is not configured */ # undef PJ_M_MIPS # define PJ_M_MIPS 1 # define PJ_M_NAME "mips" # define PJ_HAS_PENTIUM 0 -# if !defined(PJ_IS_LITTLE_ENDIAN) && !defined(PJ_IS_BIG_ENDIAN) -# define PJ_IS_LITTLE_ENDIAN 1 -# define PJ_IS_BIG_ENDIAN 0 +# if !PJ_IS_LITTLE_ENDIAN && !PJ_IS_BIG_ENDIAN +# error Endianness must be declared for this processor # endif @@ -234,29 +233,29 @@ #elif defined (PJ_M_ARMV4) || defined(ARM) || defined(_ARM_) || \ defined(ARMV4) || defined(__arm__) /* - * ARM, default to little endian + * ARM, bi-endian, so raise error if endianness is not configured */ # undef PJ_M_ARMV4 # define PJ_M_ARMV4 1 # define PJ_M_NAME "armv4" # define PJ_HAS_PENTIUM 0 -# if !defined(PJ_IS_LITTLE_ENDIAN) && !defined(PJ_IS_BIG_ENDIAN) -# define PJ_IS_LITTLE_ENDIAN 1 -# define PJ_IS_BIG_ENDIAN 0 +# if !PJ_IS_LITTLE_ENDIAN && !PJ_IS_BIG_ENDIAN +# error Endianness must be declared for this processor # endif #elif defined (PJ_M_POWERPC) || defined(__powerpc) || defined(__powerpc__) || \ defined(__POWERPC__) || defined(__ppc__) || defined(_M_PPC) || \ defined(_ARCH_PPC) /* - * PowerPC, big endian + * PowerPC, bi-endian, so raise error if endianness is not configured */ # undef PJ_M_POWERPC # define PJ_M_POWERPC 1 # define PJ_M_NAME "powerpc" # define PJ_HAS_PENTIUM 0 -# define PJ_IS_LITTLE_ENDIAN 0 -# define PJ_IS_BIG_ENDIAN 1 +# if !PJ_IS_LITTLE_ENDIAN && !PJ_IS_BIG_ENDIAN +# error Endianness must be declared for this processor +# endif #elif defined (PJ_M_NIOS2) || defined(__nios2) || defined(__nios2__) || \ defined(__NIOS2__) || defined(__M_NIOS2) || defined(_ARCH_NIOS2) diff --git a/pjlib/include/pj/hash.h b/pjlib/include/pj/hash.h index e7cf9d33..7b9f6df3 100644 --- a/pjlib/include/pj/hash.h +++ b/pjlib/include/pj/hash.h @@ -125,8 +125,8 @@ PJ_DECL(void *) pj_hash_get( pj_hash_table_t *ht, * @param pool the pool to allocate the new entry if a new entry has to be * created. * @param ht the hash table. - * @param key the key, which MUST point to buffer that remains valid - * for the duration of the entry. + * @param key the key. If pool is not specified, the key MUST point to + * buffer that remains valid for the duration of the entry. * @param keylen the length of the key, or PJ_HASH_KEY_STRING to use the * string length of the key. * @param hval if the value is not zero, then the hash table will use diff --git a/pjlib/include/pj/sock.h b/pjlib/include/pj/sock.h index 88152c05..83d35db9 100644 --- a/pjlib/include/pj/sock.h +++ b/pjlib/include/pj/sock.h @@ -493,6 +493,13 @@ typedef struct pj_in_addr */ #define PJ_INET6_ADDRSTRLEN 46 +/** + * The size of sin_zero field in pj_sockaddr_in structure. Most OSes + * use 8, but others such as the BSD TCP/IP stack in eCos uses 24. + */ +#ifndef PJ_SOCKADDR_IN_SIN_ZERO_LEN +# define PJ_SOCKADDR_IN_SIN_ZERO_LEN 8 +#endif /** * This structure describes Internet socket address. @@ -512,7 +519,7 @@ struct pj_sockaddr_in #endif pj_uint16_t sin_port; /**< Transport layer port number. */ pj_in_addr sin_addr; /**< IP address. */ - char sin_zero[8]; /**< Padding. */ + char sin_zero[PJ_SOCKADDR_IN_SIN_ZERO_LEN]; /**< Padding.*/ }; diff --git a/pjlib/src/pj/ioqueue_symbian.cpp b/pjlib/src/pj/ioqueue_symbian.cpp index 2cd9ac96..f945b2b9 100644 --- a/pjlib/src/pj/ioqueue_symbian.cpp +++ b/pjlib/src/pj/ioqueue_symbian.cpp @@ -340,6 +340,7 @@ CPjSocket *CIoqueueCallback::HandleAcceptCompletion() // void CIoqueueCallback::RunL() { + pj_ioqueue_t *ioq = ioqueue_; Type cur_type = type_; type_ = TYPE_NONE; @@ -399,7 +400,7 @@ void CIoqueueCallback::RunL() } } - ioqueue_->eventCount++; + ioq->eventCount++; } // diff --git a/pjlib/src/pj/sock_common.c b/pjlib/src/pj/sock_common.c index 170fe5c7..948d47da 100644 --- a/pjlib/src/pj/sock_common.c +++ b/pjlib/src/pj/sock_common.c @@ -784,6 +784,8 @@ PJ_DEF(pj_status_t) pj_gethostip(int af, pj_sockaddr *addr) addr->addr.sa_family = (pj_uint16_t)af; PJ_SOCKADDR_RESET_LEN(addr); +#if !defined(PJ_GETHOSTIP_DISABLE_LOCAL_RESOLUTION) || \ + PJ_GETHOSTIP_DISABLE_LOCAL_RESOLUTION == 0 /* Get hostname's IP address */ count = 1; status = pj_getaddrinfo(af, pj_gethostname(), &count, &ai); @@ -797,7 +799,10 @@ PJ_DEF(pj_status_t) pj_gethostip(int af, pj_sockaddr *addr) TRACE_((THIS_FILE, "hostname IP is %s", pj_sockaddr_print(&ai.ai_addr, strip, sizeof(strip), 0))); } - +#else + PJ_UNUSED_ARG(ai); + PJ_UNUSED_ARG(count); +#endif /* Get default interface (interface for default route) */ if (cand_cnt < PJ_ARRAY_SIZE(cand_addr)) { diff --git a/pjlib/src/pj/ssl_sock_ossl.c b/pjlib/src/pj/ssl_sock_ossl.c index 56a6023b..6ce44ad1 100644 --- a/pjlib/src/pj/ssl_sock_ossl.c +++ b/pjlib/src/pj/ssl_sock_ossl.c @@ -310,8 +310,10 @@ static pj_status_t init_openssl(void) meth = (SSL_METHOD*)TLSv1_server_method(); if (!meth) meth = (SSL_METHOD*)SSLv3_server_method(); +#ifndef OPENSSL_NO_SSL2 if (!meth) meth = (SSL_METHOD*)SSLv2_server_method(); +#endif pj_assert(meth); ctx=SSL_CTX_new(meth); @@ -488,9 +490,11 @@ static pj_status_t create_ssl(pj_ssl_sock_t *ssock) case PJ_SSL_SOCK_PROTO_TLS1: ssl_method = (SSL_METHOD*)TLSv1_method(); break; +#ifndef OPENSSL_NO_SSL2 case PJ_SSL_SOCK_PROTO_SSL2: ssl_method = (SSL_METHOD*)SSLv2_method(); break; +#endif case PJ_SSL_SOCK_PROTO_SSL3: ssl_method = (SSL_METHOD*)SSLv3_method(); break; diff --git a/pjlib/src/pjlib-test/os.c b/pjlib/src/pjlib-test/os.c index ad630245..d5b1879c 100644 --- a/pjlib/src/pjlib-test/os.c +++ b/pjlib/src/pjlib-test/os.c @@ -22,11 +22,81 @@ #include #if INCLUDE_OS_TEST +static int endianness_test32(void) +{ + union t + { + pj_uint32_t u32; + pj_uint16_t u16[2]; + pj_uint8_t u8[4]; + } t; + + PJ_LOG(3,("", " Testing endianness..")); + + t.u32 = 0x11223344; + +#if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN + PJ_LOG(3,("", " Library is set to little endian")); + +# if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN +# error Error: Both PJ_IS_LITTLE_ENDIAN and PJ_IS_BIG_ENDIAN are set! +# endif + + if ((t.u16[0] & 0xFFFF) != 0x3344 || + (t.u16[1] & 0xFFFF) != 0x1122) + { + PJ_LOG(3,("", " Error: wrong 16bit values 0x%x and 0x%x", + (t.u16[0] & 0xFFFF), (t.u16[1] & 0xFFFF))); + return 10; + } + + if ((t.u8[0] & 0xFF) != 0x44 || + (t.u8[1] & 0xFF) != 0x33 || + (t.u8[2] & 0xFF) != 0x22 || + (t.u8[3] & 0xFF) != 0x11) + { + PJ_LOG(3,("", " Error: wrong 8bit values")); + return 12; + } + +#elif defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN + PJ_LOG(3,("", " Library is set to big endian")); + + if ((t.u16[0] & 0xFFFF) != 0x1122 || + (t.u16[1] & 0xFFFF) != 0x3344) + { + PJ_LOG(3,("", " Error: wrong 16bit values 0x%x and 0x%x", + (t.u16[0] & 0xFFFF), (t.u16[1] & 0xFFFF))); + return 20; + } + + if ((t.u8[0] & 0xFF) != 0x11 || + (t.u8[1] & 0xFF) != 0x22 || + (t.u8[2] & 0xFF) != 0x33 || + (t.u8[3] & 0xFF) != 0x44) + { + PJ_LOG(3,("", " Error: wrong 8bit values")); + return 22; + } + +# if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN +# error Error: Both PJ_IS_LITTLE_ENDIAN and PJ_IS_BIG_ENDIAN are set! +# endif + + +#else +# error Error: Endianness is not set properly! +#endif + + return 0; +} + int os_test(void) { const pj_sys_info *si; int rc = 0; + PJ_LOG(3,("", " Sys info:")); si = pj_get_sys_info(); PJ_LOG(3,("", " machine: %s", si->machine.ptr)); PJ_LOG(3,("", " os_name: %s", si->os_name.ptr)); @@ -35,6 +105,8 @@ int os_test(void) PJ_LOG(3,("", " sdk_ver: 0x%x", si->sdk_ver)); PJ_LOG(3,("", " info: %s", si->info.ptr)); + rc = endianness_test32(); + return rc; } diff --git a/pjlib/src/pjlib-test/sock.c b/pjlib/src/pjlib-test/sock.c index ebb58379..35669dc0 100644 --- a/pjlib/src/pjlib-test/sock.c +++ b/pjlib/src/pjlib-test/sock.c @@ -510,7 +510,7 @@ static int send_recv_test(int sock_type, } if (srclen != addrlen) return -151; - if (pj_memcmp(&addr, srcaddr, srclen) != 0) { + if (pj_sockaddr_cmp(&addr, srcaddr) != 0) { char srcaddr_str[32], addr_str[32]; strcpy(srcaddr_str, pj_inet_ntoa(srcaddr->sin_addr)); strcpy(addr_str, pj_inet_ntoa(addr.sin_addr)); -- cgit v1.2.3