From 4c8c2a65ead2089c30c431ef34c31d4e0c7b9cb3 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Mon, 20 Mar 2006 12:39:24 +0000 Subject: Ported pjlib to PowerPC/MacOS git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@338 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pj/guid_simple.c | 1 - pjlib/src/pj/os_core_unix.c | 11 +++--- pjlib/src/pj/os_time_ansi.c | 87 ------------------------------------------- pjlib/src/pj/os_time_bsd.c | 35 +++++++++++++++++ pjlib/src/pj/os_time_common.c | 75 +++++++++++++++++++++++++++++++++++++ pjlib/src/pj/os_time_unix.c | 39 +++++++++++++++++++ pjlib/src/pj/pool_caching.c | 2 +- pjlib/src/pj/sock_bsd.c | 40 ++++++++++++++++++-- pjlib/src/pj/sock_select.c | 4 ++ 9 files changed, 195 insertions(+), 99 deletions(-) delete mode 100644 pjlib/src/pj/os_time_ansi.c create mode 100644 pjlib/src/pj/os_time_bsd.c create mode 100644 pjlib/src/pj/os_time_common.c create mode 100644 pjlib/src/pj/os_time_unix.c (limited to 'pjlib/src') diff --git a/pjlib/src/pj/guid_simple.c b/pjlib/src/pj/guid_simple.c index 300abace..9e179925 100644 --- a/pjlib/src/pj/guid_simple.c +++ b/pjlib/src/pj/guid_simple.c @@ -20,7 +20,6 @@ #include #include #include -#include const unsigned PJ_GUID_STRING_LENGTH=20; diff --git a/pjlib/src/pj/os_core_unix.c b/pjlib/src/pj/os_core_unix.c index b9fd0be7..ad9f6143 100644 --- a/pjlib/src/pj/os_core_unix.c +++ b/pjlib/src/pj/os_core_unix.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -204,9 +203,9 @@ PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name, thread->thread = pthread_self(); if(cstr_thread_name && pj_strlen(&thread_name) < sizeof(thread->obj_name)-1) - pj_sprintf(thread->obj_name, cstr_thread_name, thread->thread); + pj_ansi_sprintf(thread->obj_name, cstr_thread_name, thread->thread); else - pj_sprintf(thread->obj_name, "thr%p", (void*)thread->thread); + pj_ansi_sprintf(thread->obj_name, "thr%p", (void*)thread->thread); rc = pj_thread_local_set(thread_tls_id, thread); if (rc != PJ_SUCCESS) @@ -314,7 +313,7 @@ PJ_DEF(pj_status_t) pj_thread_create( pj_pool_t *pool, thread_name = "thr%p"; if (strchr(thread_name, '%')) { - pj_snprintf(rec->obj_name, PJ_MAX_OBJ_NAME, thread_name, rec); + pj_ansi_snprintf(rec->obj_name, PJ_MAX_OBJ_NAME, thread_name, rec); } else { strncpy(rec->obj_name, thread_name, PJ_MAX_OBJ_NAME); rec->obj_name[PJ_MAX_OBJ_NAME-1] = '\0'; @@ -804,7 +803,7 @@ static pj_status_t init_mutex(pj_mutex_t *mutex, const char *name, int type) name = "mtx%p"; } if (strchr(name, '%')) { - pj_snprintf(mutex->obj_name, PJ_MAX_OBJ_NAME, name, mutex); + pj_ansi_snprintf(mutex->obj_name, PJ_MAX_OBJ_NAME, name, mutex); } else { strncpy(mutex->obj_name, name, PJ_MAX_OBJ_NAME); mutex->obj_name[PJ_MAX_OBJ_NAME-1] = '\0'; @@ -1125,7 +1124,7 @@ PJ_DEF(pj_status_t) pj_sem_create( pj_pool_t *pool, name = "sem%p"; } if (strchr(name, '%')) { - pj_snprintf(sem->obj_name, PJ_MAX_OBJ_NAME, name, sem); + pj_ansi_snprintf(sem->obj_name, PJ_MAX_OBJ_NAME, name, sem); } else { strncpy(sem->obj_name, name, PJ_MAX_OBJ_NAME); sem->obj_name[PJ_MAX_OBJ_NAME-1] = '\0'; diff --git a/pjlib/src/pj/os_time_ansi.c b/pjlib/src/pj/os_time_ansi.c deleted file mode 100644 index c0cb9f51..00000000 --- a/pjlib/src/pj/os_time_ansi.c +++ /dev/null @@ -1,87 +0,0 @@ -/* $Id$ */ -/* - * Copyright (C)2003-2006 Benny Prijono - * - * 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 -#include - -/////////////////////////////////////////////////////////////////////////////// - -PJ_DEF(pj_status_t) pj_gettimeofday(pj_time_val *tv) -{ - struct timeb tb; - - PJ_CHECK_STACK(); - - ftime(&tb); - tv->sec = tb.time; - tv->msec = tb.millitm; - return PJ_SUCCESS; -} - -PJ_DEF(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt) -{ - struct tm *local_time; - - PJ_CHECK_STACK(); - - local_time = localtime((time_t*)&tv->sec); - - pt->year = local_time->tm_year+1900; - pt->mon = local_time->tm_mon; - pt->day = local_time->tm_mday; - pt->hour = local_time->tm_hour; - pt->min = local_time->tm_min; - pt->sec = local_time->tm_sec; - pt->wday = local_time->tm_wday; - pt->msec = tv->msec; - - return PJ_SUCCESS; -} - -/** - * Encode parsed time to time value. - */ -PJ_DEF(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv) -{ - struct tm local_time; - - local_time.tm_year = pt->year-1900; - local_time.tm_mon = pt->mon; - local_time.tm_mday = pt->day; - local_time.tm_hour = pt->hour; - local_time.tm_min = pt->min; - local_time.tm_sec = pt->sec; - local_time.tm_isdst = 0; - - tv->sec = mktime(&local_time); - tv->msec = pt->msec; - - return PJ_SUCCESS; -} - -/** - * Convert local time to GMT. - */ -PJ_DEF(pj_status_t) pj_time_local_to_gmt(pj_time_val *tv); - -/** - * Convert GMT to local time. - */ -PJ_DEF(pj_status_t) pj_time_gmt_to_local(pj_time_val *tv); - - diff --git a/pjlib/src/pj/os_time_bsd.c b/pjlib/src/pj/os_time_bsd.c new file mode 100644 index 00000000..b9918f18 --- /dev/null +++ b/pjlib/src/pj/os_time_bsd.c @@ -0,0 +1,35 @@ +/* $Id$ */ +/* + * Copyright (C)2003-2006 Benny Prijono + * + * 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 +#include + +/////////////////////////////////////////////////////////////////////////////// + +PJ_DEF(pj_status_t) pj_gettimeofday(pj_time_val *tv) +{ + struct timeb tb; + + PJ_CHECK_STACK(); + + ftime(&tb); + tv->sec = tb.time; + tv->msec = tb.millitm; + return PJ_SUCCESS; +} + diff --git a/pjlib/src/pj/os_time_common.c b/pjlib/src/pj/os_time_common.c new file mode 100644 index 00000000..3d470a27 --- /dev/null +++ b/pjlib/src/pj/os_time_common.c @@ -0,0 +1,75 @@ +/* $Id$ */ +/* + * Copyright (C)2003-2006 Benny Prijono + * + * 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 +#include + +/////////////////////////////////////////////////////////////////////////////// + +PJ_DEF(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt) +{ + struct tm *local_time; + + PJ_CHECK_STACK(); + + local_time = localtime((time_t*)&tv->sec); + + pt->year = local_time->tm_year+1900; + pt->mon = local_time->tm_mon; + pt->day = local_time->tm_mday; + pt->hour = local_time->tm_hour; + pt->min = local_time->tm_min; + pt->sec = local_time->tm_sec; + pt->wday = local_time->tm_wday; + pt->msec = tv->msec; + + return PJ_SUCCESS; +} + +/** + * Encode parsed time to time value. + */ +PJ_DEF(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv) +{ + struct tm local_time; + + local_time.tm_year = pt->year-1900; + local_time.tm_mon = pt->mon; + local_time.tm_mday = pt->day; + local_time.tm_hour = pt->hour; + local_time.tm_min = pt->min; + local_time.tm_sec = pt->sec; + local_time.tm_isdst = 0; + + tv->sec = mktime(&local_time); + tv->msec = pt->msec; + + return PJ_SUCCESS; +} + +/** + * Convert local time to GMT. + */ +PJ_DEF(pj_status_t) pj_time_local_to_gmt(pj_time_val *tv); + +/** + * Convert GMT to local time. + */ +PJ_DEF(pj_status_t) pj_time_gmt_to_local(pj_time_val *tv); + + diff --git a/pjlib/src/pj/os_time_unix.c b/pjlib/src/pj/os_time_unix.c new file mode 100644 index 00000000..b5733b64 --- /dev/null +++ b/pjlib/src/pj/os_time_unix.c @@ -0,0 +1,39 @@ +/* $Id$ */ +/* + * Copyright (C)2003-2006 Benny Prijono + * + * 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 +#include + +#if defined(PJ_HAS_UNISTD_H) && PJ_HAS_UNISTD_H!=0 +# include +#endif + +/////////////////////////////////////////////////////////////////////////////// + +PJ_DEF(pj_status_t) pj_gettimeofday(pj_time_val *p_tv) +{ + struct timeval tv; + + PJ_CHECK_STACK(); + + gettimeofday(&tv, NULL); + p_tv->sec = tv.tv_sec; + p_tv->msec = tv.tv_usec / 1000; + return PJ_SUCCESS; +} + diff --git a/pjlib/src/pj/pool_caching.c b/pjlib/src/pj/pool_caching.c index 6114160e..324ad05d 100644 --- a/pjlib/src/pj/pool_caching.c +++ b/pjlib/src/pj/pool_caching.c @@ -57,7 +57,7 @@ PJ_DEF(void) pj_caching_pool_init( pj_caching_pool *cp, cp->factory.release_pool = &cpool_release_pool; cp->factory.dump_status = &cpool_dump_status; - cp->pool = pj_pool_create_int(&cp->factory, "cachingpool", 128, + cp->pool = pj_pool_create_int(&cp->factory, "cachingpool", 256, 0, NULL); i = pj_mutex_create_simple(cp->pool, "cachingpool", &cp->mutex); } diff --git a/pjlib/src/pj/sock_bsd.c b/pjlib/src/pj/sock_bsd.c index df59a742..09b362ad 100644 --- a/pjlib/src/pj/sock_bsd.c +++ b/pjlib/src/pj/sock_bsd.c @@ -82,6 +82,15 @@ const pj_uint16_t PJ_SO_RCVBUF = SO_RCVBUF; const pj_uint16_t PJ_SO_SNDBUF = SO_SNDBUF; +#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 +# define SET_LEN(addr,len) (((pj_sockaddr*)(addr))->sa_zero_len=(len)) +# define RESET_LEN(addr) (((pj_sockaddr*)(addr))->sa_zero_len=0) +#else +# define SET_LEN(addr,len) +# define RESET_LEN(addr) +#endif + + /* * Convert 16-bit value from network byte order to host byte order. */ @@ -190,6 +199,7 @@ PJ_DEF(pj_status_t) pj_sockaddr_in_set_str_addr( pj_sockaddr_in *addr, PJ_ASSERT_RETURN(!str_addr || str_addr->slen < PJ_MAX_HOSTNAME, (addr->sin_addr.s_addr=PJ_INADDR_NONE, PJ_EINVAL)); + RESET_LEN(addr); addr->sin_family = AF_INET; if (str_addr && str_addr->slen) { @@ -226,6 +236,7 @@ PJ_DEF(pj_status_t) pj_sockaddr_in_init( pj_sockaddr_in *addr, { PJ_ASSERT_RETURN(addr, (addr->sin_addr.s_addr=PJ_INADDR_NONE, PJ_EINVAL)); + RESET_LEN(addr); addr->sin_family = PJ_AF_INET; pj_sockaddr_in_set_port(addr, port); return pj_sockaddr_in_set_str_addr(addr, str_addr); @@ -346,6 +357,7 @@ PJ_DEF(pj_status_t) pj_sock_bind_in( pj_sock_t sock, PJ_CHECK_STACK(); + SET_LEN(&addr, sizeof(pj_sockaddr_in)); addr.sin_family = PJ_AF_INET; addr.sin_addr.s_addr = pj_htonl(addr32); addr.sin_port = pj_htons(port); @@ -385,8 +397,10 @@ PJ_DEF(pj_status_t) pj_sock_getpeername( pj_sock_t sock, PJ_CHECK_STACK(); if (getpeername(sock, (struct sockaddr*)addr, (socklen_t*)namelen) != 0) return PJ_RETURN_OS_ERROR(pj_get_native_netos_error()); - else + else { + RESET_LEN(addr); return PJ_SUCCESS; + } } /* @@ -399,8 +413,10 @@ PJ_DEF(pj_status_t) pj_sock_getsockname( pj_sock_t sock, PJ_CHECK_STACK(); if (getsockname(sock, (struct sockaddr*)addr, (socklen_t*)namelen) != 0) return PJ_RETURN_OS_ERROR(pj_get_native_netos_error()); - else + else { + RESET_LEN(addr); return PJ_SUCCESS; + } } /* @@ -483,8 +499,10 @@ PJ_DEF(pj_status_t) pj_sock_recvfrom(pj_sock_t sock, if (*len < 0) return PJ_RETURN_OS_ERROR(pj_get_native_netos_error()); - else + else { + RESET_LEN(from); return PJ_SUCCESS; + } } /* @@ -574,11 +592,25 @@ PJ_DEF(pj_status_t) pj_sock_accept( pj_sock_t serverfd, PJ_CHECK_STACK(); PJ_ASSERT_RETURN(newsock != NULL, PJ_EINVAL); +#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 + if (addr) { + SET_LEN(addr, *addrlen); + } +#endif + *newsock = accept(serverfd, (struct sockaddr*)addr, (socklen_t*)addrlen); if (*newsock==PJ_INVALID_SOCKET) return PJ_RETURN_OS_ERROR(pj_get_native_netos_error()); - else + else { + +#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 + if (addr) { + RESET_LEN(addr); + } +#endif + return PJ_SUCCESS; + } } #endif /* PJ_HAS_TCP */ diff --git a/pjlib/src/pj/sock_select.c b/pjlib/src/pj/sock_select.c index c2d0fcf8..59950e62 100644 --- a/pjlib/src/pj/sock_select.c +++ b/pjlib/src/pj/sock_select.c @@ -26,6 +26,10 @@ # include #endif +#if defined(PJ_HAS_SYS_TIME_H) && PJ_HAS_SYS_TIME_H!=0 +# include +#endif + #ifdef _MSC_VER # pragma warning(disable: 4018) // Signed/unsigned mismatch in FD_* # pragma warning(disable: 4389) // Signed/unsigned mismatch in FD_* -- cgit v1.2.3