1 /* 2 The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 Copyright (C) 2001-2020 Aymeric MOIZARD amoizard@antisip.com 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 */ 19 20 #ifndef _INTERNAL_H_ 21 #define _INTERNAL_H_ 22 23 #if defined(HAVE_CONFIG_H) 24 #include <osip-config.h> 25 #endif 26 27 #if defined(__PALMOS__) && (__PALMOS__ >= 0x06000000) 28 #define HAVE_CTYPE_H 1 29 #define HAVE_STRING_H 1 30 #define HAVE_SYS_TYPES_H 1 31 #define HAVE_TIME_H 1 32 #define HAVE_STDARG_H 1 33 34 #elif defined(__VXWORKS_OS__) || defined(__rtems__) 35 #define HAVE_STRING_H 1 36 #define HAVE_TIME_H 1 37 #define HAVE_SYS_TIME_H 1 38 #define HAVE_SYS_TYPES_H 1 39 #define HAVE_STDARG_H 1 40 41 #elif defined _WIN32_WCE 42 43 #define HAVE_CTYPE_H 1 44 #define HAVE_STRING_H 1 45 #define HAVE_TIME_H 1 46 #define HAVE_STDARG_H 1 47 48 #define snprintf _snprintf 49 50 #elif defined(WIN32) 51 52 #define HAVE_CTYPE_H 1 53 #define HAVE_STRING_H 1 54 #define HAVE_SYS_TYPES_H 1 55 #define HAVE_TIME_H 1 56 #define HAVE_STDARG_H 1 57 58 #if (_MSC_VER < 1900) 59 #define snprintf _snprintf 60 #endif 61 62 /* use win32 crypto routines for random number generation */ 63 /* only use for vs .net (compiler v. 1300) or greater */ 64 #if _MSC_VER >= 1300 65 #define WIN32_USE_CRYPTO 1 66 #endif 67 68 #endif 69 70 #if defined(HAVE_STRING_H) 71 #include <string.h> 72 #elif defined(HAVE_STRINGS_H) 73 #include <strings.h> 74 #else 75 #include <string.h> 76 #endif 77 78 #include <stdio.h> 79 #include <stdlib.h> 80 81 #if defined(HAVE_SYS_TYPES_H) 82 #include <sys/types.h> 83 #endif 84 85 #ifdef HAVE_TIME_H 86 #include <time.h> 87 #endif 88 89 #if defined(HAVE_SYS_TIME_H) 90 #include <sys/time.h> 91 #endif 92 93 #if defined(__arc__) 94 #include "includes_api.h" 95 #include "os_cfg_pub.h" 96 #include <posix_time_pub.h> 97 #endif 98 99 #ifdef __PSOS__ 100 #define VA_START(a, f) va_start(a, f) 101 #include "pna.h" 102 #include "stdlib.h" 103 #include "time.h" 104 #define timercmp(tvp, uvp, cmp) ((tvp)->tv_sec cmp(uvp)->tv_sec || (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp(uvp)->tv_usec) 105 #define snprintf osip_snprintf 106 #ifndef INT_MAX 107 #define INT_MAX 0x7FFFFFFF 108 #endif 109 #endif 110 111 #ifdef __BORLANDC__ 112 #define _timeb timeb 113 #define _ftime ftime 114 #endif 115 116 #ifndef DOXYGEN 117 118 #if !(defined(__rtems__) || defined(__PALMOS__) || defined(HAVE_STRUCT_TIMEVAL)) 119 /* Struct timeval */ 120 struct timeval { 121 long tv_sec; /* seconds */ 122 long tv_usec; /* and microseconds */ 123 }; 124 #endif 125 126 #ifndef OSIP_MONOTHREAD 127 128 /* Thread abstraction layer definition */ 129 #if defined(__rtems__) 130 #include <rtems.h> 131 #else 132 133 /* Is there any thread implementation available? */ 134 /* HAVE_PTHREAD_H is not used any more! I keep it for a while... */ 135 #if !defined(__VXWORKS_OS__) && !defined(__PSOS__) && !defined(WIN32) && !defined(_WIN32_WCE) && !defined(HAVE_PTHREAD_WIN32) && !defined(HAVE_PTHREAD) && !defined(HAVE_PTHREAD_H) && !defined(HAVE_PTH_PTHREAD_H) 136 #error No thread implementation found! 137 #endif 138 139 /* Pthreads support: */ 140 /* - Unix: native Pthreads. */ 141 /* - Win32: Pthreads for Win32 (http://sources.redhat.com/pthreads-win32). */ 142 #if defined(HAVE_PTHREAD) || defined(HAVE_PTHREAD_H) || defined(HAVE_PTH_PTHREAD_H) || defined(HAVE_PTHREAD_WIN32) 143 #if defined(__arc__) 144 #include <ucos_ii_api.h> 145 #endif 146 147 #include <pthread.h> 148 typedef pthread_t osip_thread_t; 149 #endif 150 151 #if (_MSC_VER >= 1700) && !defined(_USING_V110_SDK71_) 152 #include <winapifamily.h> 153 #endif 154 155 /* Windows without Pthreads for Win32 */ 156 #if (_MSC_VER >= 1700) && !defined(_USING_V110_SDK71_) 157 #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) 158 #define HAVE_CPP11_THREAD 159 #elif defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PC_APP) 160 #define HAVE_CPP11_THREAD 161 #endif 162 #endif 163 164 #if defined(HAVE_CPP11_THREAD) 165 166 typedef struct { 167 void *h; 168 } osip_thread_t; 169 170 #elif (defined(WIN32) || defined(_WIN32_WCE)) && !defined(HAVE_PTHREAD_WIN32) 171 172 /* Prevent the inclusion of winsock.h */ 173 #define _WINSOCKAPI_ 174 #include <windows.h> 175 #undef _WINSOCKAPI_ 176 177 typedef struct { 178 HANDLE h; 179 unsigned id; 180 } osip_thread_t; 181 #endif 182 183 #ifdef __VXWORKS_OS__ 184 #include <taskLib.h> 185 typedef struct { 186 int id; 187 } osip_thread_t; 188 #endif 189 190 #ifdef __PSOS__ 191 #include <psos.h> 192 typedef struct { 193 unsigned long tid; 194 } osip_thread_t; 195 #endif 196 197 /* Semaphore and Mutex abstraction layer definition */ 198 199 /* Is there any semaphore implementation available? */ 200 #if !defined(HAVE_SEMAPHORE_H) && !defined(HAVE_SYS_SEM_H) && !defined(WIN32) && !defined(_WIN32_WCE) && !defined(HAVE_PTHREAD_WIN32) && !defined(__PSOS__) && !defined(__VXWORKS_OS__) && !defined(__arc__) 201 #error No semaphore implementation found 202 #endif 203 204 /* Pthreads */ 205 #if defined(HAVE_PTHREAD) || defined(HAVE_PTHREAD_H) || defined(HAVE_PTH_PTHREAD_H) || defined(HAVE_PTHREAD_WIN32) 206 typedef pthread_mutex_t osip_mutex_t; 207 #endif 208 209 #ifdef __sun__ 210 #include <semaphore.h> 211 #undef getdate 212 #include <synch.h> 213 #endif 214 215 #if defined(__arc__) 216 217 typedef struct { 218 int _sem_counter; 219 struct osip_mutex *_sem_mutex; 220 } sem_t; 221 222 typedef sem_t osip_sem_t; 223 224 #elif (defined(HAVE_SEMAPHORE_H) && !defined(__APPLE_CC__)) || defined(HAVE_PTHREAD_WIN32) 225 #include <semaphore.h> 226 #ifdef __sun__ 227 #undef getdate 228 #include <synch.h> 229 #endif 230 /** 231 * Structure for referencing a semaphore element. 232 * @var osip_sem_t 233 */ 234 typedef sem_t osip_sem_t; 235 236 #elif defined(__APPLE_CC__) 237 #include <mach/task.h> 238 #include <mach/semaphore.h> 239 #include <mach/mach_init.h> 240 typedef struct { 241 semaphore_t semid; 242 } osip_sem_t; 243 #elif defined(HAVE_SYS_SEM_H) 244 #include <sys/types.h> 245 #include <sys/ipc.h> 246 #include <sys/sem.h> 247 typedef struct { 248 int semid; 249 } osip_sem_t; 250 #endif 251 252 /* Windows without Pthreads for Win32 */ 253 #if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(HAVE_PTHREAD_WIN32) 254 /* Prevent the inclusion of winsock.h */ 255 #define _WINSOCKAPI_ 256 #include <windows.h> 257 #undef _WINSOCKAPI_ 258 259 #if (_WIN32_WINNT >= 0x0403) && (!defined(_WIN32_WCE)) 260 261 #define OSIP_CRITICALSECTION_SPIN 4000 262 typedef struct { 263 CRITICAL_SECTION h; 264 } osip_mutex_t; 265 #else 266 267 typedef struct { 268 HANDLE h; 269 } osip_mutex_t; 270 #endif 271 272 typedef struct { 273 HANDLE h; 274 } osip_sem_t; 275 #endif 276 277 #ifdef __VXWORKS_OS__ 278 #include <semaphore.h> 279 #include <semLib.h> 280 typedef struct semaphore osip_mutex_t; 281 typedef sem_t osip_sem_t; 282 #endif 283 284 #ifdef __PSOS__ 285 #include <Types.h> 286 #include <os.h> 287 typedef struct { 288 UInt32 id; 289 } osip_mutex_t; 290 typedef struct { 291 UInt32 id; 292 } osip_sem_t; 293 #endif 294 295 /* Condition variable abstraction layer definition */ 296 297 /** 298 * Structure for referencing a condition variable element. 299 * @var osip_cond_t 300 */ 301 #if defined(HAVE_PTHREAD) || defined(HAVE_PTH_PTHREAD_H) || defined(HAVE_PTHREAD_WIN32) 302 typedef struct osip_cond { 303 pthread_cond_t cv; 304 } osip_cond_t; 305 #endif 306 307 #if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(HAVE_PTHREAD_WIN32) 308 typedef struct osip_cond { 309 struct osip_mutex *mut; 310 struct osip_sem *sem; 311 } osip_cond_t; 312 #endif 313 314 #if defined(__PSOS__) || defined(__VXWORKS_OS__) 315 typedef struct osip_cond { 316 struct osip_sem *sem; 317 } osip_cond_t; 318 #endif 319 320 #endif 321 322 #if defined(__rtems__) 323 typedef struct { 324 rtems_id tid; 325 } osip_thread_t; 326 327 typedef struct { 328 rtems_id id; 329 } osip_sem_t; 330 331 typedef struct { 332 rtems_id id; 333 } osip_mutex_t; 334 #endif 335 336 #endif /* #ifndef OSIP_MONOTHREAD */ 337 338 #endif /* #ifndef DOXYGEN */ 339 340 #endif /* #ifndef _INTERNAL_H_ */ 341