and added files
[bcm963xx.git] / userapps / opensource / libosip2 / include / osipparser2 / osip_port.h
1 /*
2   The oSIP library implements the Session Initiation Protocol (SIP -rfc2543-)
3   Copyright (C) 2001  Aymeric MOIZARD jack@atosc.org
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
21 #ifndef _OSIP_PORT_H_
22 #define _OSIP_PORT_H_
23
24 /* Include necessary headers for osip */
25
26 #include <stdio.h>
27 #ifdef WIN32
28
29 #define STDC_HEADERS 1
30 #define HAVE_CTYPE_H 1
31 #define HAVE_STRING_H 1
32 #define HAVE_SYS_TYPES_H 1
33 #define HAVE_TIME_H 1
34 #define HAVE_STDARG_H 1
35
36 /* use win32 crypto routines for random number generation */
37 /* only use for vs .net (compiler v. 1300) or greater */
38 #if _MSC_VER >= 1300
39 #define WIN32_USE_CRYPTO 1
40 #endif
41
42 #elif defined _WIN32_WCE
43
44 #define STDC_HEADERS 1
45 #define HAVE_CTYPE_H 1
46 #define HAVE_STRING_H 1
47 #define HAVE_TIME_H 1
48 #define HAVE_STDARG_H 1
49
50 #define strnicmp        _strnicmp
51 #define stricmp         _stricmp
52 #define EBUSY           16
53
54 #endif
55
56 #ifdef __VXWORKS_OS__
57
58 #include <string.h>
59 #include <time.h>
60 #include <stdarg.h>
61 #define VA_START(a, f)  va_start(a, f)
62
63 #else /* end of __VXWORKS_OS__ */
64
65 #if defined (HAVE_CONFIG_H)
66 #include <config.h>
67 #  if defined (HAVE_STRING_H)
68 #    include <string.h>
69 #  else
70 #    include <strings.h>
71 #  endif /* HAVE_STRING_H */
72 #else
73 #  include <string.h>
74 #endif /* !HAVE_CONFIG_H */
75
76 #if defined (HAVE_SYS_TYPES_H)
77 #  include <sys/types.h>
78 #endif
79
80 #if STDC_HEADERS
81 #    include <stdlib.h>
82 #endif /* !STDC_HEADERS */
83
84 #if defined(HAVE_STDARG_H) || defined(WIN32)
85 #  include <stdarg.h>
86 #  define VA_START(a, f)  va_start(a, f)
87 #else
88 #  if defined(HAVE_VARARGS_H)
89 #    include <varargs.h>
90 #    define VA_START(a, f) va_start(a)
91 #  else
92 #    include <stdarg.h>
93 #    define VA_START(a, f)  va_start(a, f)
94 #  endif
95 #endif
96
97 #ifdef HAVE_TIME_H
98 #  include <time.h>
99 #endif
100
101 #if defined (HAVE_SYS_TIME_H)
102 #  include <sys/time.h>
103 #endif
104
105 #endif /* end of !__VXWORKS_OS__ */
106
107 #ifdef _WIN32_WCE
108 #define VA_START(a, f)  va_start(a, f)
109 #endif
110
111 #ifdef WIN32
112 #define VA_START(a, f)  va_start(a, f)
113 #endif
114
115 #ifdef __PSOS__
116 #define VA_START(a, f)  va_start(a, f)
117 #endif
118
119 #if __STDC__
120 #  ifndef NOPROTOS
121 #    define PARAMS(args)   args
122 #  endif
123 #endif
124
125 #ifndef PARAMS
126 #  define PARAMS(args)     ()
127 #endif
128
129 #include <osipparser2/osip_const.h>
130
131 #include <osipparser2/osip_list.h>
132
133 #define SIP_SYNTAX_ERROR    (-1)
134 #define SIP_NETWORK_ERROR   (-2)
135 #define SIP_ECONNREFUSED    (-3)
136 #define SIP_RESSOURCE_ERROR (-4)
137 #define SIP_GLOBAL_ERROR    (-5)
138
139 #ifdef __cplusplus
140 extern "C"
141 {
142 #endif
143
144 /**************************/
145 /* MALLOC redirections    */
146 /**************************/
147
148 #ifndef WIN32
149
150 #ifndef osip_malloc
151 #define osip_malloc(S) malloc(S)
152 #endif
153 #ifndef osip_free
154 #define osip_free(P) { if (P!=NULL) free(P); }
155 #endif
156
157 #else
158 void *osip_malloc(size_t size);
159 void osip_free(void *);
160 #endif
161
162 #ifdef WIN32
163 #define alloca _alloca
164 #endif
165
166 /**************************/
167 /* RANDOM number support  */
168 /**************************/
169
170   unsigned int osip_build_random_number (void);
171
172 /**************************/
173 /* TIMER support          */
174 /**************************/
175
176 #define SP   " \0"
177
178   void osip_usleep (int useconds);
179
180 /**************************/
181 /* STRING support         */
182 /**************************/
183
184   int osip_atoi (const char *number);
185   char *osip_strncpy (char *dest, const char *src, size_t length);
186   char *osip_strdup (const char *ch);
187   char *osip_strdup_without_quote (const char *ch);
188   int osip_tolower (char *word);
189   int osip_clrspace (char *word);
190   char *__osip_sdp_append_string (char *string, size_t size,
191                                   char *cur, char *string_osip_to_append);
192   int __osip_set_next_token (char **dest, char *buf, int end_separator,
193                              char **next);
194   /* find the next unescaped quote and return its index. */
195   char *__osip_quote_find (const char *qstring);
196   char *osip_enquote (const char *s);
197   void osip_dequote (char *s);
198
199   int osip_strcasecmp (const char *s1, const char *s2);
200   int osip_strncasecmp (const char *s1, const char *s2, size_t len);
201
202 /**************************/
203 /* LOG&DEBUG support      */
204 /**************************/
205
206 #define LOG_TRUE  1
207 #define LOG_FALSE 0
208 /* levels */
209   typedef enum _trace_level
210   {
211     TRACE_LEVEL0 = 0,
212 #define OSIP_FATAL    0
213     TRACE_LEVEL1 = 1,
214 #define OSIP_BUG      1
215     TRACE_LEVEL2 = 2,
216 #define OSIP_ERROR    2
217     TRACE_LEVEL3 = 3,
218 #define OSIP_WARNING  3
219     TRACE_LEVEL4 = 4,
220 #define OSIP_INFO1    4
221     TRACE_LEVEL5 = 5,
222 #define OSIP_INFO2    5
223     TRACE_LEVEL6 = 6,
224 #define OSIP_INFO3    6
225     TRACE_LEVEL7 = 7,
226 #define OSIP_INFO4    7
227     END_TRACE_LEVEL = 8
228   }
229   osip_trace_level_t;
230
231 /* these are defined in all cases, but are empty when oSIP is compiled
232    without trace */
233   void osip_trace_initialize_syslog (osip_trace_level_t level, char *ident);
234   void osip_trace_initialize (osip_trace_level_t level, FILE * file);
235   void osip_trace_enable_level (osip_trace_level_t level);
236   void osip_trace_disable_level (osip_trace_level_t level);
237   int osip_is_trace_level_activate (osip_trace_level_t level);
238
239 #ifndef ENABLE_TRACE
240
241 #define TRACE_INITIALIZE(level, file)  do { } while (0)
242 #define TRACE_ENABLE_LEVEL(level)      do { } while (0)
243 #define TRACE_DISABLE_LEVEL(level)     do { } while (0)
244 #define IS_TRACE_LEVEL_ACTIVATE(level) (-1)
245
246 #else
247
248 #define TRACE_INITIALIZE(level, file)  osip_trace_initialize(level, file)
249 #define TRACE_ENABLE_LEVEL(level)      osip_trace_enable_level ( level )
250 #define TRACE_DISABLE_LEVEL(level)     osip_trace_disable_level ( level )
251 #define IS_TRACE_LEVEL_ACTIVATE(level) osip_is_trace_level_activate( level )
252
253 #endif
254
255 /* log facility. */
256 /* if f is NULL, current default log file is used. */
257 /* INPUT: level | level of the trace               */
258 /* INPUT: f | use f instead of default log file    */
259 /* INPUT: chfr | format string for next args       */
260   int osip_trace (char *fi, int li, osip_trace_level_t level, FILE * f,
261                   char *chfr, ...);
262
263 #ifdef ENABLE_TRACE
264 #define OSIP_TRACE(P) P
265 #else
266 #define OSIP_TRACE(P) do {} while (0)
267 #endif
268
269 #ifdef __cplusplus
270 }
271 #endif
272
273 #endif                          /* _PORT_H_ */