internal.h 7.5 KB

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