libosip 3.6.0

internal.h

00001 /*
00002   The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
00003   Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Aymeric MOIZARD jack@atosc.org
00004   
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009   
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014   
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 #if defined(WIN32)
00021 #if !defined(_WIN32_WINNT) && defined(WINVER)
00022 #define _WIN32_WINNT WINVER
00023 #elif !defined(_WIN32_WINNT)
00024 #define _WIN32_WINNT 0x0403
00025 #endif
00026 #endif
00027 
00028 #include <osipparser2/osip_port.h>
00029 
00030 #ifndef _INTERNAL_H_
00031 #define _INTERNAL_H_
00032 
00033 #ifdef __BORLANDC__
00034 #define _timeb timeb
00035 #define _ftime ftime
00036 #endif
00037 
00038 #ifndef DOXYGEN
00039 
00040 #if !( defined(__rtems__) || defined(__PALMOS__) || defined(HAVE_STRUCT_TIMEVAL) )
00041 /* Struct timeval */
00042 struct timeval {
00043         long tv_sec;                            /* seconds */
00044         long tv_usec;                           /* and microseconds */
00045 };
00046 #endif
00047 
00053 typedef struct __payload __payload_t;
00054 
00055 struct __payload {
00056         char *payload;
00057         /*  char *port; this must be assigned by the application dynamicly */
00058         char *number_of_port;
00059         char *proto;
00060         char *c_nettype;
00061         char *c_addrtype;
00062         char *c_addr;
00063         char *c_addr_multicast_ttl;
00064         char *c_addr_multicast_int;
00065         /* rtpmap (rcvonly and other attributes are added dynamicly) */
00066         char *a_rtpmap;
00067 };
00068 
00069 
00074 int __payload_init(__payload_t ** payload);
00075 
00080 void __payload_free(__payload_t * payload);
00081 
00082 
00083 #ifdef OSIP_MT
00084 
00085 /* Thread abstraction layer definition */
00086 #if defined(__rtems__)
00087 #include <rtems.h>
00088 #else
00089 
00090 /* Is there any thread implementation available? */
00091 /* HAVE_PTHREAD_H is not used any more! I keep it for a while... */
00092 #if !defined(__VXWORKS_OS__) && !defined(__PSOS__) && \
00093         !defined(WIN32) && !defined(_WIN32_WCE) && !defined(HAVE_PTHREAD_WIN32) && \
00094     !defined(HAVE_PTHREAD) && !defined(HAVE_PTHREAD_H) && !defined(HAVE_PTH_PTHREAD_H)
00095 #error No thread implementation found!
00096 #endif
00097 
00098 /* Pthreads support: */
00099 /* - Unix: native Pthreads. */
00100 /* - Win32: Pthreads for Win32 (http://sources.redhat.com/pthreads-win32). */
00101 #if defined(HAVE_PTHREAD) || defined(HAVE_PTHREAD_H) || defined(HAVE_PTH_PTHREAD_H) || \
00102         defined(HAVE_PTHREAD_WIN32)
00103 #if defined(__arc__)
00104 #include <ucos_ii_api.h>
00105 #endif
00106 
00107 
00108 #include <pthread.h>
00109 typedef pthread_t osip_thread_t;
00110 #endif
00111 
00112 /* Windows without Pthreads for Win32 */
00113 #if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(HAVE_PTHREAD_WIN32)
00114 
00115 /* Prevent the inclusion of winsock.h */
00116 #define _WINSOCKAPI_
00117 #include <windows.h>
00118 #undef _WINSOCKAPI_
00119 
00120 typedef struct {
00121         HANDLE h;
00122         unsigned id;
00123 } osip_thread_t;
00124 #endif
00125 
00126 #ifdef __VXWORKS_OS__
00127 #include <taskLib.h>
00128 typedef struct {
00129         int id;
00130 } osip_thread_t;
00131 #endif
00132 
00133 #ifdef __PSOS__
00134 #include <psos.h>
00135 typedef struct {
00136         unsigned long tid;
00137 } osip_thread_t;
00138 #endif
00139 
00140 
00141 /* Semaphore and Mutex abstraction layer definition */
00142 
00143 /* Is there any semaphore implementation available? */
00144 #if !defined(HAVE_SEMAPHORE_H) && !defined(HAVE_SYS_SEM_H) && \
00145     !defined(WIN32) && !defined(_WIN32_WCE) && !defined(HAVE_PTHREAD_WIN32) && \
00146     !defined(__PSOS__) && !defined(__VXWORKS_OS__) && !defined(__arc__)
00147 #error No semaphore implementation found
00148 #endif
00149 
00150 /* Pthreads */
00151 #if defined(HAVE_PTHREAD) || defined(HAVE_PTHREAD_H) || defined(HAVE_PTH_PTHREAD_H) || \
00152         defined(HAVE_PTHREAD_WIN32)
00153 typedef pthread_mutex_t osip_mutex_t;
00154 #endif
00155 
00156 #ifdef __sun__
00157 #include <semaphore.h>
00158 #undef getdate
00159 #include <synch.h>
00160 #endif
00161 
00162 #if defined(__arc__)
00163 
00164 typedef struct {
00165         int _sem_counter;
00166         struct osip_mutex *_sem_mutex;
00167 } sem_t;
00168 
00169 typedef sem_t osip_sem_t;
00170 
00171 #elif (defined(HAVE_SEMAPHORE_H) && !defined(__APPLE_CC__)) || defined(HAVE_PTHREAD_WIN32)
00172 #include <semaphore.h>
00173 #ifdef __sun__
00174 #undef getdate
00175 #include <synch.h>
00176 #endif
00177 
00181 typedef sem_t osip_sem_t;
00182 
00183 #elif defined (__APPLE_CC__)
00184 #include <mach/task.h>
00185 #include <mach/semaphore.h>
00186 #include <mach/mach_init.h>
00187 typedef struct {
00188         semaphore_t semid;
00189 } osip_sem_t;
00190 #elif defined(HAVE_SYS_SEM_H)
00191 #include <sys/types.h>
00192 #include <sys/ipc.h>
00193 #include <sys/sem.h>
00194 typedef struct {
00195         int semid;
00196 } osip_sem_t;
00197 #endif
00198 
00199 /* Windows without Pthreads for Win32 */
00200 #if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(HAVE_PTHREAD_WIN32)
00201 /* Prevent the inclusion of winsock.h */
00202 #define _WINSOCKAPI_
00203 #include <windows.h>
00204 #undef _WINSOCKAPI_
00205 
00206 #if (_WIN32_WINNT >= 0x0403) && (!defined(_WIN32_WCE))
00207 
00208 #define OSIP_CRITICALSECTION_SPIN  4000
00209 typedef struct {
00210         CRITICAL_SECTION h;
00211 } osip_mutex_t;
00212 #else
00213 
00214 typedef struct {
00215         HANDLE h;
00216 } osip_mutex_t;
00217 #endif
00218 
00219 typedef struct {
00220         HANDLE h;
00221 } osip_sem_t;
00222 #endif
00223 
00224 #ifdef __VXWORKS_OS__
00225 #include <semaphore.h>
00226 #include <semLib.h>
00227 typedef struct semaphore osip_mutex_t;
00228 typedef sem_t osip_sem_t;
00229 #endif
00230 
00231 #ifdef __PSOS__
00232 #include <Types.h>
00233 #include <os.h>
00234 typedef struct {
00235         UInt32 id;
00236 } osip_mutex_t;
00237 typedef struct {
00238         UInt32 id;
00239 } osip_sem_t;
00240 #endif
00241 
00242 
00243 /* Condition variable abstraction layer definition */
00244 
00249 #if defined(HAVE_PTHREAD) || defined(HAVE_PTH_PTHREAD_H) || defined(HAVE_PTHREAD_WIN32)
00250 typedef struct osip_cond {
00251         pthread_cond_t cv;
00252 } osip_cond_t;
00253 #endif
00254 
00255 #if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(HAVE_PTHREAD_WIN32)
00256 typedef struct osip_cond {
00257         struct osip_mutex *mut;
00258         struct osip_sem *sem;
00259 } osip_cond_t;
00260 #endif
00261 
00262 #if defined(__PSOS__) || defined(__VXWORKS_OS__)
00263 typedef struct osip_cond {
00264         struct osip_sem *sem;
00265 } osip_cond_t;
00266 #endif
00267 
00268 #endif
00269 
00270 #if defined(__rtems__)
00271 typedef struct {
00272         rtems_id tid;
00273 } osip_thread_t;
00274 
00275 typedef struct {
00276         rtems_id id;
00277 } osip_sem_t;
00278 
00279 typedef struct {
00280         rtems_id id;
00281 } osip_mutex_t;
00282 #endif
00283 
00284 
00285 #endif                                                  /* #ifdef OSIP_MT */
00286 
00287 #endif                                                  /* #ifndef DOXYGEN */
00288 
00289 #endif                                                  /* #ifndef _INTERNAL_H_ */