osip_port.h

Go to the documentation of this file.
00001 
00025 #ifndef _OSIP_PORT_H_
00026 #define _OSIP_PORT_H_
00027 
00028 /* Include necessary headers for osip */
00029 
00030 #include <stdio.h>
00031 
00032 #if defined(__PALMOS__) && (__PALMOS__ >= 0x06000000)
00033 #       define STDC_HEADERS 1
00034 #       define HAVE_CTYPE_H 1
00035 #       define HAVE_STRING_H 1
00036 #       define HAVE_SYS_TYPES_H 1
00037 #       define HAVE_TIME_H 1
00038 #       define HAVE_STDARG_H 1
00039 
00040 #elif defined(WIN32)
00041 
00042 #define STDC_HEADERS 1
00043 #define HAVE_CTYPE_H 1
00044 #define HAVE_STRING_H 1
00045 #define HAVE_SYS_TYPES_H 1
00046 #define HAVE_TIME_H 1
00047 #define HAVE_STDARG_H 1
00048 
00049 /* use win32 crypto routines for random number generation */
00050 /* only use for vs .net (compiler v. 1300) or greater */
00051 #if _MSC_VER >= 1300
00052 #define WIN32_USE_CRYPTO 1
00053 #endif
00054 
00055 #elif defined _WIN32_WCE
00056 
00057 #define STDC_HEADERS 1
00058 #define HAVE_CTYPE_H 1
00059 #define HAVE_STRING_H 1
00060 #define HAVE_TIME_H 1
00061 #define HAVE_STDARG_H 1
00062 
00063 #define strnicmp        _strnicmp
00064 #define stricmp         _stricmp
00065 #define EBUSY           16
00066 
00067 #endif
00068 
00069 #ifdef __VXWORKS_OS__
00070 #include <string.h>
00071 #include <time.h>
00072 #include <sys/times.h>
00073 #include <stdarg.h>
00074 #include <sys/types.h>
00075 #include <stdlib.h>
00076 #define VA_START(a, f)  va_start(a, f)
00077 
00078 /* VxWorks lacks support for snprintf */
00079 int osip_vsnprintf (char *buf, int max, const char *fmt, va_list ap);
00080 int osip_snprintf (char *buf, int max, const char *fmt, ...);
00081 
00082 #define snprintf  osip_snprintf
00083 #define vsnprintf osip_vsnprintf
00084 
00085 
00086 #else /* end of __VXWORKS_OS__ */
00087 
00088 #if defined (HAVE_CONFIG_H)
00089 #include <config.h>
00090 #  if defined (HAVE_STRING_H)
00091 #    include <string.h>
00092 #  else
00093 #    include <strings.h>
00094 #  endif /* HAVE_STRING_H */
00095 #else
00096 #  include <string.h>
00097 #endif /* !HAVE_CONFIG_H */
00098 
00099 #if defined (HAVE_SYS_TYPES_H)
00100 #  include <sys/types.h>
00101 #endif
00102 
00103 #if STDC_HEADERS
00104 #    include <stdlib.h>
00105 #endif /* !STDC_HEADERS */
00106 
00107 #if defined(HAVE_STDARG_H) || defined(WIN32)
00108 #  include <stdarg.h>
00109 #  define VA_START(a, f)  va_start(a, f)
00110 #else
00111 #  if defined(HAVE_VARARGS_H)
00112 #    include <varargs.h>
00113 #    define VA_START(a, f) va_start(a)
00114 #  else
00115 #    include <stdarg.h>
00116 #    define VA_START(a, f)  va_start(a, f)
00117 #  endif
00118 #endif
00119 
00120 #ifdef HAVE_TIME_H
00121 #  include <time.h>
00122 #endif
00123 
00124 #if defined (HAVE_SYS_TIME_H)
00125 #  include <sys/time.h>
00126 #endif
00127 
00128 #endif /* end of !__VXWORKS_OS__ */
00129 
00130 #ifdef _WIN32_WCE
00131 #define VA_START(a, f)  va_start(a, f)
00132 #endif
00133 
00134 #ifdef WIN32
00135 #define VA_START(a, f)  va_start(a, f)
00136 #endif
00137 
00138 #ifdef __PSOS__
00139 #define VA_START(a, f)  va_start(a, f)
00140 #include "pna.h"
00141 #include "stdlib.h"
00142 #include "time.h"
00143 #define timercmp(tvp, uvp, cmp) \
00144         ((tvp)->tv_sec cmp (uvp)->tv_sec || \
00145          (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
00146 #define snprintf  osip_snprintf
00147 #ifndef INT_MAX
00148 #define INT_MAX 0x7FFFFFFF
00149 #endif
00150 
00151 #endif
00152 
00153 
00154 #if __STDC__
00155 #  ifndef NOPROTOS
00156 #    define PARAMS(args)   args
00157 #  endif
00158 #endif
00159 
00160 #ifndef PARAMS
00161 #  define PARAMS(args)     ()
00162 #endif
00163 
00164 #include "osip_const.h"
00165 #include "osip_list.h"
00166 
00167 #define SIP_SYNTAX_ERROR    (-1)
00168 #define SIP_NETWORK_ERROR   (-2)
00169 #define SIP_ECONNREFUSED    (-3)
00170 #define SIP_RESSOURCE_ERROR (-4)
00171 #define SIP_GLOBAL_ERROR    (-5)
00172 
00173 #ifdef __cplusplus
00174 extern "C"
00175 {
00176 #endif
00177 
00178 /**************************/
00179 /* MALLOC redirections    */
00180 /**************************/
00181 
00182 #ifndef WIN32
00183 
00184   typedef void *osip_malloc_func_t (size_t size);
00185   typedef void osip_free_func_t (void *ptr);
00186   typedef void *osip_realloc_func_t (void *ptr, size_t size);
00187 
00188   extern osip_malloc_func_t *osip_malloc_func;
00189   extern osip_realloc_func_t *osip_realloc_func;
00190   extern osip_free_func_t *osip_free_func;
00191 
00192   void osip_set_allocators (osip_malloc_func_t * malloc_func,
00193                             osip_realloc_func_t * realloc_func,
00194                             osip_free_func_t * free_func);
00195 
00196 
00197 #ifdef DEBUG_MEM
00198 
00199   void *_osip_malloc (size_t size, char *file, unsigned short line);
00200   void _osip_free (void *ptr);
00201   void *_osip_realloc (void *ptr, size_t size, char *file, unsigned short line);
00202 
00203 #ifndef osip_malloc
00204 #define osip_malloc(S) _osip_malloc(S,__FILE__,__LINE__)
00205 #endif
00206 #ifndef osip_realloc
00207 #define osip_realloc(P,S) _osip_realloc(P,S,__FILE__,__LINE__)
00208 #endif
00209 #ifndef osip_free
00210 #define osip_free(P) { if (P!=NULL) { _osip_free(P); } }
00211 #endif
00212 
00213 #else
00214 
00215 #ifndef osip_malloc
00216 #define osip_malloc(S) (osip_malloc_func?osip_malloc_func(S):malloc(S))
00217 #endif
00218 #ifndef osip_realloc
00219 #define osip_realloc(P,S) (osip_realloc_func?osip_realloc_func(P,S):realloc(P,S))
00220 #endif
00221 #ifndef osip_free
00222 #define osip_free(P) { if (P!=NULL) { if (osip_free_func) osip_free_func(P); else free(P);} }
00223 #endif
00224 
00225 #endif
00226 
00227 #else
00228 
00229   void *osip_malloc (size_t size);
00230   void *osip_realloc (void *, size_t size);
00231   void osip_free (void *);
00232 
00233 #endif
00234 
00235 #ifdef WIN32
00236 #define alloca _alloca
00237 #endif
00238 
00239 /**************************/
00240 /* RANDOM number support  */
00241 /**************************/
00242 
00243   unsigned int osip_build_random_number (void);
00244 
00245 /**************************/
00246 /* TIMER support          */
00247 /**************************/
00248 
00249 #define SP   " \0"
00250 
00251   void osip_usleep (int useconds);
00252 
00253 /**************************/
00254 /* STRING support         */
00255 /**************************/
00256 
00257   int osip_atoi (const char *number);
00258   char *osip_strncpy (char *dest, const char *src, size_t length);
00259   char *osip_strdup (const char *ch);
00260   char *osip_strdup_without_quote (const char *ch);
00261   int osip_tolower (char *word);
00262   int osip_clrspace (char *word);
00263   char *__osip_sdp_append_string (char *string, size_t size,
00264                                   char *cur, char *string_osip_to_append);
00265   int __osip_set_next_token (char **dest, char *buf, int end_separator,
00266                              char **next);
00267   /* find the next unescaped quote and return its index. */
00268   char *__osip_quote_find (const char *qstring);
00269   char *osip_enquote (const char *s);
00270   void osip_dequote (char *s);
00271 
00272   int osip_strcasecmp (const char *s1, const char *s2);
00273   int osip_strncasecmp (const char *s1, const char *s2, size_t len);
00274 
00275   unsigned long osip_hash (const char *str);
00276   char *osip_str_append (char *dst, const char *src);
00277   char *osip_strn_append (char *dst, const char *src, size_t len);
00278   char *osip_clrncpy (char *dst, const char *src, size_t len);
00279 
00280 /**************************/
00281 /* LOG&DEBUG support      */
00282 /**************************/
00283 
00284 #define LOG_TRUE  1
00285 #define LOG_FALSE 0
00286 /* levels */
00287   typedef enum _trace_level
00288   {
00289     TRACE_LEVEL0 = 0,
00290 #define OSIP_FATAL    0
00291     TRACE_LEVEL1 = 1,
00292 #define OSIP_BUG      1
00293     TRACE_LEVEL2 = 2,
00294 #define OSIP_ERROR    2
00295     TRACE_LEVEL3 = 3,
00296 #define OSIP_WARNING  3
00297     TRACE_LEVEL4 = 4,
00298 #define OSIP_INFO1    4
00299     TRACE_LEVEL5 = 5,
00300 #define OSIP_INFO2    5
00301     TRACE_LEVEL6 = 6,
00302 #define OSIP_INFO3    6
00303     TRACE_LEVEL7 = 7,
00304 #define OSIP_INFO4    7
00305     END_TRACE_LEVEL = 8
00306   }
00307   osip_trace_level_t;
00308 
00309 
00310   typedef void osip_trace_func_t (char *fi, int li, osip_trace_level_t level,
00311                                   char *chfr, va_list ap);
00312 
00313 /* these are defined in all cases, but are empty when oSIP is compiled
00314    without trace */
00315   void osip_trace_initialize_func (osip_trace_level_t level,
00316                                    osip_trace_func_t * func);
00317   void osip_trace_initialize_syslog (osip_trace_level_t level, char *ident);
00318   void osip_trace_initialize (osip_trace_level_t level, FILE * file);
00319   void osip_trace_enable_until_level (osip_trace_level_t level);
00320   void osip_trace_enable_level (osip_trace_level_t level);
00321   void osip_trace_disable_level (osip_trace_level_t level);
00322   int osip_is_trace_level_activate (osip_trace_level_t level);
00323 
00324 #ifndef ENABLE_TRACE
00325 
00326 #define TRACE_INITIALIZE(level, file)  do { } while (0)
00327 #define TRACE_ENABLE_LEVEL(level)      do { } while (0)
00328 #define TRACE_DISABLE_LEVEL(level)     do { } while (0)
00329 #define IS_TRACE_LEVEL_ACTIVATE(level) (-1)
00330 
00331 #else
00332 
00333 #define TRACE_INITIALIZE(level, file)  osip_trace_initialize(level, file)
00334 #define TRACE_ENABLE_LEVEL(level)      osip_trace_enable_level ( level )
00335 #define TRACE_DISABLE_LEVEL(level)     osip_trace_disable_level ( level )
00336 #define IS_TRACE_LEVEL_ACTIVATE(level) osip_is_trace_level_activate( level )
00337 
00338 #endif
00339 
00340 /* log facility. */
00341 /* if f is NULL, current default log file is used. */
00342 /* INPUT: level | level of the trace               */
00343 /* INPUT: f | use f instead of default log file    */
00344 /* INPUT: chfr | format string for next args       */
00345   int osip_trace (char *fi, int li, osip_trace_level_t level, FILE * f,
00346                   char *chfr, ...);
00347 
00348 #ifdef ENABLE_TRACE
00349 #define OSIP_TRACE(P) P
00350 #else
00351 #define OSIP_TRACE(P) do {} while (0)
00352 #endif
00353 
00354 #ifdef __cplusplus
00355 }
00356 #endif
00357 
00358 #endif                          /* _PORT_H_ */

Generated on Fri Mar 9 20:08:53 2007 for MAD-FCL by  doxygen 1.5.0