libosip  4.1.0
osip2/internal.h
1 /*
2  The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
3  Copyright (C) 2001-2012 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 #define snprintf _snprintf
59 
60 /* use win32 crypto routines for random number generation */
61 /* only use for vs .net (compiler v. 1300) or greater */
62 #if _MSC_VER >= 1300
63 #define WIN32_USE_CRYPTO 1
64 #endif
65 
66 #endif
67 
68 #if defined (HAVE_STRING_H)
69 #include <string.h>
70 #elif defined (HAVE_STRINGS_H)
71 #include <strings.h>
72 #else
73 #include <string.h>
74 #endif
75 
76 #include <stdio.h>
77 #include <stdlib.h>
78 
79 #if defined (HAVE_SYS_TYPES_H)
80 #include <sys/types.h>
81 #endif
82 
83 #ifdef HAVE_TIME_H
84 #include <time.h>
85 #endif
86 
87 #if defined (HAVE_SYS_TIME_H)
88 #include <sys/time.h>
89 #endif
90 
91 #if defined(__arc__)
92 #include "includes_api.h"
93 #include "os_cfg_pub.h"
94 #include <posix_time_pub.h>
95 #endif
96 
97 #ifdef __PSOS__
98 #define VA_START(a, f) va_start(a, f)
99 #include "pna.h"
100 #include "stdlib.h"
101 #include "time.h"
102 #define timercmp(tvp, uvp, cmp) \
103 ((tvp)->tv_sec cmp (uvp)->tv_sec || \
104 (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__) && \
136  !defined(WIN32) && !defined(_WIN32_WCE) && !defined(HAVE_PTHREAD_WIN32) && \
137  !defined(HAVE_PTHREAD) && !defined(HAVE_PTHREAD_H) && !defined(HAVE_PTH_PTHREAD_H)
138 #error No thread implementation found!
139 #endif
140 
141 /* Pthreads support: */
142 /* - Unix: native Pthreads. */
143 /* - Win32: Pthreads for Win32 (http://sources.redhat.com/pthreads-win32). */
144 #if defined(HAVE_PTHREAD) || defined(HAVE_PTHREAD_H) || defined(HAVE_PTH_PTHREAD_H) || \
145  defined(HAVE_PTHREAD_WIN32)
146 #if defined(__arc__)
147 #include <ucos_ii_api.h>
148 #endif
149 
150 
151 #include <pthread.h>
152 typedef pthread_t osip_thread_t;
153 #endif
154 
155 #if (_MSC_VER >= 1700) && !defined(_USING_V110_SDK71_)
156 #include <winapifamily.h>
157 #endif
158 
159 /* Windows without Pthreads for Win32 */
160 #if (_MSC_VER >= 1700) && !defined(_USING_V110_SDK71_)
161 #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
162 #define HAVE_CPP11_THREAD
163 #elif defined(WINAPI_FAMILY) && WINAPI_FAMILY_ONE_PARTITION( WINAPI_FAMILY, WINAPI_PARTITION_APP )
164 #define HAVE_CPP11_THREAD
165 #endif
166 #endif
167 
168 #if defined(HAVE_CPP11_THREAD)
169 
170 typedef struct {
171  void *h;
172 } osip_thread_t;
173 
174 #elif (defined(WIN32) || defined(_WIN32_WCE)) && !defined(HAVE_PTHREAD_WIN32)
175 
176 /* Prevent the inclusion of winsock.h */
177 #define _WINSOCKAPI_
178 #include <windows.h>
179 #undef _WINSOCKAPI_
180 
181 typedef struct {
182  HANDLE h;
183  unsigned id;
184 } osip_thread_t;
185 #endif
186 
187 #ifdef __VXWORKS_OS__
188 #include <taskLib.h>
189 typedef struct {
190  int id;
191 } osip_thread_t;
192 #endif
193 
194 #ifdef __PSOS__
195 #include <psos.h>
196 typedef struct {
197  unsigned long tid;
198 } osip_thread_t;
199 #endif
200 
201 
202 /* Semaphore and Mutex abstraction layer definition */
203 
204 /* Is there any semaphore implementation available? */
205 #if !defined(HAVE_SEMAPHORE_H) && !defined(HAVE_SYS_SEM_H) && \
206  !defined(WIN32) && !defined(_WIN32_WCE) && !defined(HAVE_PTHREAD_WIN32) && \
207  !defined(__PSOS__) && !defined(__VXWORKS_OS__) && !defined(__arc__)
208 #error No semaphore implementation found
209 #endif
210 
211 /* Pthreads */
212 #if defined(HAVE_PTHREAD) || defined(HAVE_PTHREAD_H) || defined(HAVE_PTH_PTHREAD_H) || \
213  defined(HAVE_PTHREAD_WIN32)
214 typedef pthread_mutex_t osip_mutex_t;
215 #endif
216 
217 #ifdef __sun__
218 #include <semaphore.h>
219 #undef getdate
220 #include <synch.h>
221 #endif
222 
223 #if defined(__arc__)
224 
225 typedef struct {
226  int _sem_counter;
227  struct osip_mutex *_sem_mutex;
228 } sem_t;
229 
230 typedef sem_t osip_sem_t;
231 
232 #elif (defined(HAVE_SEMAPHORE_H) && !defined(__APPLE_CC__)) || defined(HAVE_PTHREAD_WIN32)
233 #include <semaphore.h>
234 #ifdef __sun__
235 #undef getdate
236 #include <synch.h>
237 #endif
238 
242 typedef sem_t osip_sem_t;
243 
244 #elif defined (__APPLE_CC__)
245 #include <mach/task.h>
246 #include <mach/semaphore.h>
247 #include <mach/mach_init.h>
248 typedef struct {
249  semaphore_t semid;
250 } osip_sem_t;
251 #elif defined(HAVE_SYS_SEM_H)
252 #include <sys/types.h>
253 #include <sys/ipc.h>
254 #include <sys/sem.h>
255 typedef struct {
256  int semid;
257 } osip_sem_t;
258 #endif
259 
260 /* Windows without Pthreads for Win32 */
261 #if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(HAVE_PTHREAD_WIN32)
262 /* Prevent the inclusion of winsock.h */
263 #define _WINSOCKAPI_
264 #include <windows.h>
265 #undef _WINSOCKAPI_
266 
267 #if (_WIN32_WINNT >= 0x0403) && (!defined(_WIN32_WCE))
268 
269 #define OSIP_CRITICALSECTION_SPIN 4000
270 typedef struct {
271  CRITICAL_SECTION h;
272 } osip_mutex_t;
273 #else
274 
275 typedef struct {
276  HANDLE h;
277 } osip_mutex_t;
278 #endif
279 
280 typedef struct {
281  HANDLE h;
282 } osip_sem_t;
283 #endif
284 
285 #ifdef __VXWORKS_OS__
286 #include <semaphore.h>
287 #include <semLib.h>
288 typedef struct semaphore osip_mutex_t;
289 typedef sem_t osip_sem_t;
290 #endif
291 
292 #ifdef __PSOS__
293 #include <Types.h>
294 #include <os.h>
295 typedef struct {
296  UInt32 id;
297 } osip_mutex_t;
298 typedef struct {
299  UInt32 id;
300 } osip_sem_t;
301 #endif
302 
303 
304 /* Condition variable abstraction layer definition */
305 
310 #if defined(HAVE_PTHREAD) || defined(HAVE_PTH_PTHREAD_H) || defined(HAVE_PTHREAD_WIN32)
311 typedef struct osip_cond {
312  pthread_cond_t cv;
313 } osip_cond_t;
314 #endif
315 
316 #if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(HAVE_PTHREAD_WIN32)
317 typedef struct osip_cond {
318  struct osip_mutex *mut;
319  struct osip_sem *sem;
320 } osip_cond_t;
321 #endif
322 
323 #if defined(__PSOS__) || defined(__VXWORKS_OS__)
324 typedef struct osip_cond {
325  struct osip_sem *sem;
326 } osip_cond_t;
327 #endif
328 
329 #endif
330 
331 #if defined(__rtems__)
332 typedef struct {
333  rtems_id tid;
334 } osip_thread_t;
335 
336 typedef struct {
337  rtems_id id;
338 } osip_sem_t;
339 
340 typedef struct {
341  rtems_id id;
342 } osip_mutex_t;
343 #endif
344 
345 
346 #endif /* #ifndef OSIP_MONOTHREAD */
347 
348 #endif /* #ifndef DOXYGEN */
349 
350 #endif /* #ifndef _INTERNAL_H_ */