libosip  4.0.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 /* Windows without Pthreads for Win32 */
156 #if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(HAVE_PTHREAD_WIN32)
157 
158 /* Prevent the inclusion of winsock.h */
159 #define _WINSOCKAPI_
160 #include <windows.h>
161 #undef _WINSOCKAPI_
162 
163 typedef struct {
164  HANDLE h;
165  unsigned id;
166 } osip_thread_t;
167 #endif
168 
169 #ifdef __VXWORKS_OS__
170 #include <taskLib.h>
171 typedef struct {
172  int id;
173 } osip_thread_t;
174 #endif
175 
176 #ifdef __PSOS__
177 #include <psos.h>
178 typedef struct {
179  unsigned long tid;
180 } osip_thread_t;
181 #endif
182 
183 
184 /* Semaphore and Mutex abstraction layer definition */
185 
186 /* Is there any semaphore implementation available? */
187 #if !defined(HAVE_SEMAPHORE_H) && !defined(HAVE_SYS_SEM_H) && \
188  !defined(WIN32) && !defined(_WIN32_WCE) && !defined(HAVE_PTHREAD_WIN32) && \
189  !defined(__PSOS__) && !defined(__VXWORKS_OS__) && !defined(__arc__)
190 #error No semaphore implementation found
191 #endif
192 
193 /* Pthreads */
194 #if defined(HAVE_PTHREAD) || defined(HAVE_PTHREAD_H) || defined(HAVE_PTH_PTHREAD_H) || \
195  defined(HAVE_PTHREAD_WIN32)
196 typedef pthread_mutex_t osip_mutex_t;
197 #endif
198 
199 #ifdef __sun__
200 #include <semaphore.h>
201 #undef getdate
202 #include <synch.h>
203 #endif
204 
205 #if defined(__arc__)
206 
207 typedef struct {
208  int _sem_counter;
209  struct osip_mutex *_sem_mutex;
210 } sem_t;
211 
212 typedef sem_t osip_sem_t;
213 
214 #elif (defined(HAVE_SEMAPHORE_H) && !defined(__APPLE_CC__)) || defined(HAVE_PTHREAD_WIN32)
215 #include <semaphore.h>
216 #ifdef __sun__
217 #undef getdate
218 #include <synch.h>
219 #endif
220 
224 typedef sem_t osip_sem_t;
225 
226 #elif defined (__APPLE_CC__)
227 #include <mach/task.h>
228 #include <mach/semaphore.h>
229 #include <mach/mach_init.h>
230 typedef struct {
231  semaphore_t semid;
232 } osip_sem_t;
233 #elif defined(HAVE_SYS_SEM_H)
234 #include <sys/types.h>
235 #include <sys/ipc.h>
236 #include <sys/sem.h>
237 typedef struct {
238  int semid;
239 } osip_sem_t;
240 #endif
241 
242 /* Windows without Pthreads for Win32 */
243 #if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(HAVE_PTHREAD_WIN32)
244 /* Prevent the inclusion of winsock.h */
245 #define _WINSOCKAPI_
246 #include <windows.h>
247 #undef _WINSOCKAPI_
248 
249 #if (_WIN32_WINNT >= 0x0403) && (!defined(_WIN32_WCE))
250 
251 #define OSIP_CRITICALSECTION_SPIN 4000
252 typedef struct {
253  CRITICAL_SECTION h;
254 } osip_mutex_t;
255 #else
256 
257 typedef struct {
258  HANDLE h;
259 } osip_mutex_t;
260 #endif
261 
262 typedef struct {
263  HANDLE h;
264 } osip_sem_t;
265 #endif
266 
267 #ifdef __VXWORKS_OS__
268 #include <semaphore.h>
269 #include <semLib.h>
270 typedef struct semaphore osip_mutex_t;
271 typedef sem_t osip_sem_t;
272 #endif
273 
274 #ifdef __PSOS__
275 #include <Types.h>
276 #include <os.h>
277 typedef struct {
278  UInt32 id;
279 } osip_mutex_t;
280 typedef struct {
281  UInt32 id;
282 } osip_sem_t;
283 #endif
284 
285 
286 /* Condition variable abstraction layer definition */
287 
292 #if defined(HAVE_PTHREAD) || defined(HAVE_PTH_PTHREAD_H) || defined(HAVE_PTHREAD_WIN32)
293 typedef struct osip_cond {
294  pthread_cond_t cv;
295 } osip_cond_t;
296 #endif
297 
298 #if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(HAVE_PTHREAD_WIN32)
299 typedef struct osip_cond {
300  struct osip_mutex *mut;
301  struct osip_sem *sem;
302 } osip_cond_t;
303 #endif
304 
305 #if defined(__PSOS__) || defined(__VXWORKS_OS__)
306 typedef struct osip_cond {
307  struct osip_sem *sem;
308 } osip_cond_t;
309 #endif
310 
311 #endif
312 
313 #if defined(__rtems__)
314 typedef struct {
315  rtems_id tid;
316 } osip_thread_t;
317 
318 typedef struct {
319  rtems_id id;
320 } osip_sem_t;
321 
322 typedef struct {
323  rtems_id id;
324 } osip_mutex_t;
325 #endif
326 
327 
328 #endif /* #ifndef OSIP_MONOTHREAD */
329 
330 #endif /* #ifndef DOXYGEN */
331 
332 #endif /* #ifndef _INTERNAL_H_ */