SIP Witch 1.9.15
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
osip_port.h
Go to the documentation of this file.
1 /*
2  The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
3  Copyright (C) 2001-2015 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 
21 #ifndef _OSIP_PORT_H_
22 #define _OSIP_PORT_H_
23 
24 #include <stdio.h>
25 
26 /* on android, va_list is only defined if stdarg.h is included before */
27 /* on other platform, it doesn't harm to have it */
28 #if defined(HAVE_STDARG_H)
29 #include <stdarg.h>
30 #else
31 #if defined(HAVE_VARARGS_H)
32 #include <varargs.h>
33 #else
34 #include <stdarg.h>
35 #endif
36 #endif
37 
38 #if defined(__VXWORKS_OS__)
39 /* VxWorks lacks support for snprintf */
40 int osip_vsnprintf (char *buf, int max, const char *fmt, va_list ap);
41 int osip_snprintf (char *buf, int max, const char *fmt, ...);
42 
43 #define snprintf osip_snprintf
44 #define vsnprintf osip_vsnprintf
45 #endif
46 
47 #include <osipparser2/osip_const.h>
48 
49 #include <osipparser2/osip_list.h>
50 
51 #define SIP_SYNTAX_ERROR (-1)
52 #define SIP_NETWORK_ERROR (-2)
53 #define SIP_ECONNREFUSED (-3)
54 #define SIP_RESSOURCE_ERROR (-4)
55 #define SIP_GLOBAL_ERROR (-5)
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 /**************************/
62 /* MALLOC redirections */
63 /**************************/
64 
65 #if !defined(WIN32) && !defined(_WIN32_WCE)
66 
67 #ifndef MINISIZE
68  typedef void *osip_malloc_func_t (size_t size);
69  typedef void osip_free_func_t (void *ptr);
70  typedef void *osip_realloc_func_t (void *ptr, size_t size);
71 
75 
76  void osip_set_allocators (osip_malloc_func_t * malloc_func, osip_realloc_func_t * realloc_func, osip_free_func_t * free_func);
77 #endif
78 
79 #ifdef DEBUG_MEM
80 
81  void *_osip_malloc (size_t size, char *file, unsigned short line);
82  void _osip_free (void *ptr);
83  void *_osip_realloc (void *ptr, size_t size, char *file, unsigned short line);
84 
85 #ifndef osip_malloc
86 #define osip_malloc(S) _osip_malloc(S,__FILE__,__LINE__)
87 #endif
88 #ifndef osip_realloc
89 #define osip_realloc(P,S) _osip_realloc(P,S,__FILE__,__LINE__)
90 #endif
91 #ifndef osip_free
92 #define osip_free(P) { if (P!=NULL) { _osip_free(P); } }
93 #endif
94 
95 #else
96 
97 #ifndef MINISIZE
98 #ifndef osip_malloc
99 #define osip_malloc(S) (osip_malloc_func?osip_malloc_func(S):malloc(S))
100 #endif
101 #ifndef osip_realloc
102 #define osip_realloc(P,S) (osip_realloc_func?osip_realloc_func(P,S):realloc(P,S))
103 #endif
104 #ifndef osip_free
105 #define osip_free(P) { if (P!=NULL) { if (osip_free_func) osip_free_func(P); else free(P);} }
106 #endif
107 
108 #else
109  /* MINISIZE code */
110 #ifndef osip_malloc
111 #define osip_malloc(S) malloc(S)
112 #endif
113 #ifndef osip_realloc
114 #define osip_realloc(P,S) realloc(P,S)
115 #endif
116 #ifndef osip_free
117 #define osip_free(P) { if (P!=NULL) { free(P);} }
118 #endif
119 
120 #endif
121 
122 #endif
123 
124 #else
125 
126 #if 0 /* for windows test purpose */
127 #ifndef osip_malloc
128 #define osip_malloc(S) _osip_malloc(S,__FILE__,__LINE__)
129 #endif
130 #ifndef osip_realloc
131 #define osip_realloc(P,S) _osip_realloc(P,S,__FILE__,__LINE__)
132 #endif
133 #ifndef osip_free
134 #define osip_free(P) { if (P!=NULL) { _osip_free(P); } }
135 #endif
136 
137  void *_osip_malloc (size_t size, char *file, unsigned short line);
138  void _osip_free (void *ptr);
139  void *_osip_realloc (void *ptr, size_t size, char *file, unsigned short line);
140 #else
141  void *osip_malloc (size_t size);
142  void *osip_realloc (void *, size_t size);
143  void osip_free (void *);
144 #endif
145 
146 #endif
147 
148 #ifdef WIN32
149 #define alloca _alloca
150 #endif
151 
152 /**************************/
153 /* RANDOM number support */
154 /**************************/
155 
156  unsigned int osip_build_random_number (void);
157 
158 /**************************/
159 /* TIMER support */
160 /**************************/
161 
162 #define SP " \0"
163 
164  void osip_usleep (int useconds);
165 
166 #ifndef MINISIZE
167  int osip_atoi (const char *number);
168  int osip_strcasecmp (const char *s1, const char *s2);
169  int osip_strncasecmp (const char *s1, const char *s2, size_t len);
170 
171 #else
172 #define osip_atoi atoi
173 #define osip_strcasecmp strcasecmp
174 #define osip_strncasecmp strncasecmp
175 #endif
176 
177  char *osip_strcasestr (const char *haystack, const char *needle);
178 
179 /**************************/
180 /* STRING support */
181 /**************************/
182 
183  char *osip_strncpy (char *dest, const char *src, size_t length);
184  char *osip_strdup (const char *ch);
185  char *osip_strdup_without_quote (const char *ch);
186  int osip_tolower (char *word);
187  int osip_clrspace (char *word);
188  int __osip_set_next_token (char **dest, char *buf, int end_separator, char **next);
189  /* find the next unescaped quote and return its index. */
190  const char *__osip_quote_find (const char *qstring);
191  char *osip_enquote (const char *s);
192  void osip_dequote (char *s);
193 
194  unsigned long osip_hash (const char *str);
195  char *osip_str_append (char *dst, const char *src);
196  char *osip_strn_append (char *dst, const char *src, size_t len);
197  char *osip_clrncpy (char *dst, const char *src, size_t len);
198 
199 /**************************/
200 /* LOG&DEBUG support */
201 /**************************/
202 
203 #define LOG_TRUE 1
204 #define LOG_FALSE 0
205 /* levels */
206  typedef enum _trace_level {
208 #define OSIP_FATAL TRACE_LEVEL0
210 #define OSIP_BUG TRACE_LEVEL1
212 #define OSIP_ERROR TRACE_LEVEL2
214 #define OSIP_WARNING TRACE_LEVEL3
216 #define OSIP_INFO1 TRACE_LEVEL4
218 #define OSIP_INFO2 TRACE_LEVEL5
220 #define OSIP_INFO3 TRACE_LEVEL6
222 #define OSIP_INFO4 TRACE_LEVEL7
225 
226 
227  typedef void osip_trace_func_t (char *fi, int li, osip_trace_level_t level, char *chfr, va_list ap);
228 
229 /* these are defined in all cases, but are empty when oSIP is compiled
230  without trace */
232  void osip_trace_initialize_syslog (osip_trace_level_t level, char *ident);
233  int osip_trace_initialize (osip_trace_level_t level, FILE * file);
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, char *chfr, ...);
261 
262 #ifdef ENABLE_TRACE
263 #define OSIP_TRACE(P) P
264 #else
265 #define OSIP_TRACE(P) do {} while (0)
266 #endif
267 
268 #define REMOVE_ELEMENT(first_element, element) \
269  if (element->parent==NULL) \
270  { first_element = element->next; \
271  if (first_element!=NULL) \
272  first_element->parent = NULL; } \
273  else \
274  { element->parent->next = element->next; \
275  if (element->next!=NULL) \
276  element->next->parent = element->parent; \
277  element->next = NULL; \
278  element->parent = NULL; }
279 
280 #define ADD_ELEMENT(first_element, element) \
281  if (first_element==NULL) \
282  { \
283  first_element = element; \
284  element->next = NULL; \
285  element->parent = NULL; \
286  } \
287  else \
288  { \
289  element->next = first_element; \
290  element->parent = NULL; \
291  element->next->parent = element; \
292  first_element = element; \
293  }
294 
295 #define APPEND_ELEMENT(type_of_element_t, first_element, element) \
296  if (first_element==NULL) \
297  { first_element = element; \
298  element->next = NULL; /* useless */ \
299  element->parent = NULL; /* useless */ } \
300  else \
301  { type_of_element_t *f; \
302  for (f=first_element; f->next!=NULL; f=f->next) \
303  { } \
304  f->next = element; \
305  element->parent = f; \
306  element->next = NULL; \
307  }
308 
309  const char *osip_strerror (int err);
310 
311 #ifdef __cplusplus
312 }
313 #endif
314 #define OSIP_SUCCESS 0
315 #define OSIP_UNDEFINED_ERROR -1
316 #define OSIP_BADPARAMETER -2
317 #define OSIP_WRONG_STATE -3
318 #define OSIP_NOMEM -4
319 #define OSIP_SYNTAXERROR -5
320 #define OSIP_NOTFOUND -6
321 #define OSIP_API_NOT_INITIALIZED -7
322 #define OSIP_NO_NETWORK -10
323 #define OSIP_PORT_BUSY -11
324 #define OSIP_UNKNOWN_HOST -12
325 #define OSIP_DISK_FULL -30
326 #define OSIP_NO_RIGHTS -31
327 #define OSIP_FILE_NOT_EXIST -32
328 #define OSIP_TIMEOUT -50
329 #define OSIP_TOOMUCHCALL -51
330 #define OSIP_WRONG_FORMAT -52
331 #define OSIP_NOCOMMONCODEC -53
332 #endif /* _PORT_H_ */
void osip_trace_enable_level(osip_trace_level_t level)
_trace_level
Definition: osip_port.h:206
int osip_is_trace_level_activate(osip_trace_level_t level)
char * osip_str_append(char *dst, const char *src)
void osip_usleep(int useconds)
int osip_atoi(const char *number)
unsigned long osip_hash(const char *str)
void osip_trace_initialize_syslog(osip_trace_level_t level, char *ident)
#define osip_malloc(S)
Definition: osip_port.h:99
const char * __osip_quote_find(const char *qstring)
void osip_free_func_t(void *ptr)
Definition: osip_port.h:69
char * osip_strn_append(char *dst, const char *src, size_t len)
char * osip_strcasestr(const char *haystack, const char *needle)
const char * osip_strerror(int err)
int osip_tolower(char *word)
char * osip_enquote(const char *s)
void osip_trace_disable_level(osip_trace_level_t level)
osip_free_func_t * osip_free_func
oSIP list Routines
enum _trace_level osip_trace_level_t
osip_realloc_func_t * osip_realloc_func
osip_malloc_func_t * osip_malloc_func
void * osip_realloc_func_t(void *ptr, size_t size)
Definition: osip_port.h:70
void osip_set_allocators(osip_malloc_func_t *malloc_func, osip_realloc_func_t *realloc_func, osip_free_func_t *free_func)
#define osip_free(P)
Definition: osip_port.h:105
#define osip_realloc(P, S)
Definition: osip_port.h:102
int osip_strncasecmp(const char *s1, const char *s2, size_t len)
void osip_trace_func_t(char *fi, int li, osip_trace_level_t level, char *chfr, va_list ap)
Definition: osip_port.h:227
int osip_strcasecmp(const char *s1, const char *s2)
int osip_trace_initialize(osip_trace_level_t level, FILE *file)
void osip_trace_initialize_func(osip_trace_level_t level, osip_trace_func_t *func)
unsigned int osip_build_random_number(void)
int __osip_set_next_token(char **dest, char *buf, int end_separator, char **next)
int osip_trace(char *fi, int li, osip_trace_level_t level, FILE *f, char *chfr,...)
char * osip_strdup_without_quote(const char *ch)
void * osip_malloc_func_t(size_t size)
Definition: osip_port.h:68
void osip_dequote(char *s)
char * osip_strdup(const char *ch)
int osip_clrspace(char *word)
char * osip_clrncpy(char *dst, const char *src, size_t len)
char * osip_strncpy(char *dest, const char *src, size_t length)
void osip_trace_enable_until_level(osip_trace_level_t level)