00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _OSIP_PORT_H_
00022 #define _OSIP_PORT_H_
00023
00024
00025
00026 #include <stdio.h>
00027
00028 #if defined(__arc__)
00029 #include "includes_api.h"
00030 #include "os_cfg_pub.h"
00031 #include <posix_time_pub.h>
00032 #endif
00033
00034 #if defined(__PALMOS__) && (__PALMOS__ >= 0x06000000)
00035 # define STDC_HEADERS 1
00036 # define HAVE_CTYPE_H 1
00037 # define HAVE_STRING_H 1
00038 # define HAVE_SYS_TYPES_H 1
00039 # define HAVE_TIME_H 1
00040 # define HAVE_STDARG_H 1
00041
00042 #elif defined _WIN32_WCE
00043
00044 #define STDC_HEADERS 1
00045 #define HAVE_CTYPE_H 1
00046 #define HAVE_STRING_H 1
00047 #define HAVE_TIME_H 1
00048 #define HAVE_STDARG_H 1
00049
00050 #define snprintf _snprintf
00051 #define EBUSY 16
00052
00053 #elif defined(WIN32)
00054
00055 #define STDC_HEADERS 1
00056 #define HAVE_CTYPE_H 1
00057 #define HAVE_STRING_H 1
00058 #define HAVE_SYS_TYPES_H 1
00059 #define HAVE_TIME_H 1
00060 #define HAVE_STDARG_H 1
00061
00062 #define snprintf _snprintf
00063
00064
00065
00066 #if _MSC_VER >= 1300
00067 #define WIN32_USE_CRYPTO 1
00068 #endif
00069
00070 #endif
00071
00072 #if defined(__VXWORKS_OS__) || defined(__rtems__)
00073 #include <string.h>
00074 #include <time.h>
00075 #include <sys/times.h>
00076 #include <stdarg.h>
00077 #include <sys/types.h>
00078 #include <stdlib.h>
00079 #define VA_START(a, f) va_start(a, f)
00080
00081 #if defined(__VXWORKS_OS__)
00082
00083 int osip_vsnprintf (char *buf, int max, const char *fmt, va_list ap);
00084 int osip_snprintf (char *buf, int max, const char *fmt, ...);
00085
00086 #define snprintf osip_snprintf
00087 #define vsnprintf osip_vsnprintf
00088 #endif
00089
00090 #else
00091
00092 #if defined (HAVE_CONFIG_H)
00093 #include <config.h>
00094 # if defined (HAVE_STRING_H)
00095 # include <string.h>
00096 # else
00097 # include <strings.h>
00098 # endif
00099 #else
00100 # include <string.h>
00101 #endif
00102
00103 #if defined (HAVE_SYS_TYPES_H)
00104 # include <sys/types.h>
00105 #endif
00106
00107 #ifdef STDC_HEADERS
00108 # include <stdlib.h>
00109 #endif
00110
00111 #if defined(HAVE_STDARG_H) || defined(WIN32)
00112 # include <stdarg.h>
00113 # define VA_START(a, f) va_start(a, f)
00114 #else
00115 # if defined(HAVE_VARARGS_H)
00116 # include <varargs.h>
00117 # define VA_START(a, f) va_start(a)
00118 # else
00119 # include <stdarg.h>
00120 # define VA_START(a, f) va_start(a, f)
00121 # endif
00122 #endif
00123
00124 #ifdef HAVE_TIME_H
00125 # include <time.h>
00126 #endif
00127
00128 #if defined (HAVE_SYS_TIME_H)
00129 # include <sys/time.h>
00130 #endif
00131
00132 #endif
00133
00134 #ifdef _WIN32_WCE
00135 #define VA_START(a, f) va_start(a, f)
00136 #endif
00137
00138 #ifdef WIN32
00139 #define VA_START(a, f) va_start(a, f)
00140 #endif
00141
00142 #ifdef __PSOS__
00143 #define VA_START(a, f) va_start(a, f)
00144 #include "pna.h"
00145 #include "stdlib.h"
00146 #include "time.h"
00147 #define timercmp(tvp, uvp, cmp) \
00148 ((tvp)->tv_sec cmp (uvp)->tv_sec || \
00149 (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
00150 #define snprintf osip_snprintf
00151 #ifndef INT_MAX
00152 #define INT_MAX 0x7FFFFFFF
00153 #endif
00154
00155 #endif
00156
00157
00158 #if __STDC__
00159 # ifndef NOPROTOS
00160 # define PARAMS(args) args
00161 # endif
00162 #endif
00163
00164 #ifndef PARAMS
00165 # define PARAMS(args) ()
00166 #endif
00167
00168 #include <osipparser2/osip_const.h>
00169
00170 #include <osipparser2/osip_list.h>
00171
00172 #define SIP_SYNTAX_ERROR (-1)
00173 #define SIP_NETWORK_ERROR (-2)
00174 #define SIP_ECONNREFUSED (-3)
00175 #define SIP_RESSOURCE_ERROR (-4)
00176 #define SIP_GLOBAL_ERROR (-5)
00177
00178 #ifdef __cplusplus
00179 extern "C"
00180 {
00181 #endif
00182
00183
00184
00185
00186
00187 #if !defined(WIN32) && !defined(_WIN32_WCE)
00188
00189 #ifndef MINISIZE
00190 typedef void *osip_malloc_func_t (size_t size);
00191 typedef void osip_free_func_t (void *ptr);
00192 typedef void *osip_realloc_func_t (void *ptr, size_t size);
00193
00194 extern osip_malloc_func_t *osip_malloc_func;
00195 extern osip_realloc_func_t *osip_realloc_func;
00196 extern osip_free_func_t *osip_free_func;
00197
00198 void osip_set_allocators (osip_malloc_func_t * malloc_func,
00199 osip_realloc_func_t * realloc_func,
00200 osip_free_func_t * free_func);
00201 #endif
00202
00203 #ifdef DEBUG_MEM
00204
00205 void *_osip_malloc (size_t size, char *file, unsigned short line);
00206 void _osip_free (void *ptr);
00207 void *_osip_realloc (void *ptr, size_t size, char *file, unsigned short line);
00208
00209 #ifndef osip_malloc
00210 #define osip_malloc(S) _osip_malloc(S,__FILE__,__LINE__)
00211 #endif
00212 #ifndef osip_realloc
00213 #define osip_realloc(P,S) _osip_realloc(P,S,__FILE__,__LINE__)
00214 #endif
00215 #ifndef osip_free
00216 #define osip_free(P) { if (P!=NULL) { _osip_free(P); } }
00217 #endif
00218
00219 #else
00220
00221 #ifndef MINISIZE
00222 #ifndef osip_malloc
00223 #define osip_malloc(S) (osip_malloc_func?osip_malloc_func(S):malloc(S))
00224 #endif
00225 #ifndef osip_realloc
00226 #define osip_realloc(P,S) (osip_realloc_func?osip_realloc_func(P,S):realloc(P,S))
00227 #endif
00228 #ifndef osip_free
00229 #define osip_free(P) { if (P!=NULL) { if (osip_free_func) osip_free_func(P); else free(P);} }
00230 #endif
00231
00232 #else
00233
00234 #ifndef osip_malloc
00235 #define osip_malloc(S) malloc(S)
00236 #endif
00237 #ifndef osip_realloc
00238 #define osip_realloc(P,S) realloc(P,S)
00239 #endif
00240 #ifndef osip_free
00241 #define osip_free(P) { if (P!=NULL) { free(P);} }
00242 #endif
00243
00244 #endif
00245
00246 #endif
00247
00248 #else
00249
00250 void *osip_malloc (size_t size);
00251 void *osip_realloc (void *, size_t size);
00252 void osip_free (void *);
00253
00254 #endif
00255
00256 #ifdef WIN32
00257 #define alloca _alloca
00258 #endif
00259
00260
00261
00262
00263
00264 unsigned int osip_build_random_number (void);
00265
00266
00267
00268
00269
00270 #define SP " \0"
00271
00272 void osip_usleep (int useconds);
00273
00274 #ifndef MINISIZE
00275 int osip_atoi (const char *number);
00276 int osip_strcasecmp (const char *s1, const char *s2);
00277 int osip_strncasecmp (const char *s1, const char *s2, size_t len);
00278 #else
00279 #define osip_atoi atoi
00280 #define osip_strcasecmp strcasecmp
00281 #define osip_strncasecmp strncasecmp
00282 #endif
00283
00284
00285
00286
00287
00288 char *osip_strncpy (char *dest, const char *src, size_t length);
00289 char *osip_strdup (const char *ch);
00290 char *osip_strdup_without_quote (const char *ch);
00291 int osip_tolower (char *word);
00292 int osip_clrspace (char *word);
00293 char *__osip_sdp_append_string (char *string, size_t size,
00294 char *cur, char *string_osip_to_append);
00295 int __osip_set_next_token (char **dest, char *buf, int end_separator,
00296 char **next);
00297
00298 char *__osip_quote_find (const char *qstring);
00299 char *osip_enquote (const char *s);
00300 void osip_dequote (char *s);
00301
00302 unsigned long osip_hash (const char *str);
00303 char *osip_str_append (char *dst, const char *src);
00304 char *osip_strn_append (char *dst, const char *src, size_t len);
00305 char *osip_clrncpy (char *dst, const char *src, size_t len);
00306
00307
00308
00309
00310
00311 #define LOG_TRUE 1
00312 #define LOG_FALSE 0
00313
00314 typedef enum _trace_level
00315 {
00316 TRACE_LEVEL0 = 0,
00317 #define OSIP_FATAL 0
00318 TRACE_LEVEL1 = 1,
00319 #define OSIP_BUG 1
00320 TRACE_LEVEL2 = 2,
00321 #define OSIP_ERROR 2
00322 TRACE_LEVEL3 = 3,
00323 #define OSIP_WARNING 3
00324 TRACE_LEVEL4 = 4,
00325 #define OSIP_INFO1 4
00326 TRACE_LEVEL5 = 5,
00327 #define OSIP_INFO2 5
00328 TRACE_LEVEL6 = 6,
00329 #define OSIP_INFO3 6
00330 TRACE_LEVEL7 = 7,
00331 #define OSIP_INFO4 7
00332 END_TRACE_LEVEL = 8
00333 }
00334 osip_trace_level_t;
00335
00336
00337 typedef void osip_trace_func_t (char *fi, int li, osip_trace_level_t level,
00338 char *chfr, va_list ap);
00339
00340
00341
00342 void osip_trace_initialize_func (osip_trace_level_t level,
00343 osip_trace_func_t * func);
00344 void osip_trace_initialize_syslog (osip_trace_level_t level, char *ident);
00345 void osip_trace_initialize (osip_trace_level_t level, FILE * file);
00346 void osip_trace_enable_until_level (osip_trace_level_t level);
00347 void osip_trace_enable_level (osip_trace_level_t level);
00348 void osip_trace_disable_level (osip_trace_level_t level);
00349 int osip_is_trace_level_activate (osip_trace_level_t level);
00350
00351 #ifndef ENABLE_TRACE
00352
00353 #define TRACE_INITIALIZE(level, file) do { } while (0)
00354 #define TRACE_ENABLE_LEVEL(level) do { } while (0)
00355 #define TRACE_DISABLE_LEVEL(level) do { } while (0)
00356 #define IS_TRACE_LEVEL_ACTIVATE(level) (-1)
00357
00358 #else
00359
00360 #define TRACE_INITIALIZE(level, file) osip_trace_initialize(level, file)
00361 #define TRACE_ENABLE_LEVEL(level) osip_trace_enable_level ( level )
00362 #define TRACE_DISABLE_LEVEL(level) osip_trace_disable_level ( level )
00363 #define IS_TRACE_LEVEL_ACTIVATE(level) osip_is_trace_level_activate( level )
00364
00365 #endif
00366
00367
00368
00369
00370
00371
00372 int osip_trace (char *fi, int li, osip_trace_level_t level, FILE * f,
00373 char *chfr, ...);
00374
00375 #ifdef ENABLE_TRACE
00376 #define OSIP_TRACE(P) P
00377 #else
00378 #define OSIP_TRACE(P) do {} while (0)
00379 #endif
00380
00381 #define REMOVE_ELEMENT(first_element, element) \
00382 if (element->parent==NULL) \
00383 { first_element = element->next; \
00384 if (first_element!=NULL) \
00385 first_element->parent = NULL; } \
00386 else \
00387 { element->parent->next = element->next; \
00388 if (element->next!=NULL) \
00389 element->next->parent = element->parent; \
00390 element->next = NULL; \
00391 element->parent = NULL; }
00392
00393 #define ADD_ELEMENT(first_element, element) \
00394 if (first_element==NULL) \
00395 { \
00396 first_element = element; \
00397 element->next = NULL; \
00398 element->parent = NULL; \
00399 } \
00400 else \
00401 { \
00402 element->next = first_element; \
00403 element->parent = NULL; \
00404 element->next->parent = element; \
00405 first_element = element; \
00406 }
00407
00408 #define APPEND_ELEMENT(type_of_element_t, first_element, element) \
00409 if (first_element==NULL) \
00410 { first_element = element; \
00411 element->next = NULL; \
00412 element->parent = NULL; } \
00413 else \
00414 { type_of_element_t *f; \
00415 for (f=first_element; f->next!=NULL; f=f->next) \
00416 { } \
00417 f->next = element; \
00418 element->parent = f; \
00419 element->next = NULL; \
00420 }
00421
00422 #ifdef __cplusplus
00423 }
00424 #endif
00425
00426 #endif