/* belle-sip - SIP (RFC3261) library. Copyright (C) 2010 Belledonne Communications SARL This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef BELLE_SIP_UTILS_H #define BELLE_SIP_UTILS_H #include #include #include #include /***************/ /* logging api */ /***************/ typedef enum { BELLE_SIP_LOG_FATAL=1, BELLE_SIP_LOG_ERROR=1<<1, BELLE_SIP_LOG_WARNING=1<<2, BELLE_SIP_LOG_MESSAGE=1<<3, BELLE_SIP_LOG_DEBUG=1<<4, BELLE_SIP_LOG_END=1<<5 } belle_sip_log_level; typedef void (*belle_sip_log_function_t)(belle_sip_log_level lev, const char *fmt, va_list args); BELLE_SIP_BEGIN_DECLS extern belle_sip_log_function_t belle_sip_logv_out; extern unsigned int __belle_sip_log_mask; #define belle_sip_log_level_enabled(level) (__belle_sip_log_mask & (level)) #if !defined(WIN32) && !defined(_WIN32_WCE) #define belle_sip_logv(level,fmt,args) \ {\ if (belle_sip_logv_out!=NULL && belle_sip_log_level_enabled(level)) \ belle_sip_logv_out(level,fmt,args);\ if ((level)==BELLE_SIP_LOG_FATAL) abort();\ }while(0) #else void belle_sip_logv(int level, const char *fmt, va_list args); #endif #ifdef BELLE_SIP_DEBUG_MODE static inline void belle_sip_debug(const char *fmt,...) { va_list args; va_start (args, fmt); belle_sip_logv(BELLE_SIP_LOG_DEBUG, fmt, args); va_end (args); } #else #define belle_sip_debug(...) #endif #ifdef BELLE_SIP_NOMESSAGE_MODE #define belle_sip_log(...) #define belle_sip_message(...) #define belle_sip_warning(...) #else static inline void belle_sip_log(belle_sip_log_level lev, const char *fmt,...){ va_list args; va_start (args, fmt); belle_sip_logv(lev, fmt, args); va_end (args); } static inline void belle_sip_message(const char *fmt,...) { va_list args; va_start (args, fmt); belle_sip_logv(BELLE_SIP_LOG_MESSAGE, fmt, args); va_end (args); } static inline void belle_sip_warning(const char *fmt,...) { va_list args; va_start (args, fmt); belle_sip_logv(BELLE_SIP_LOG_WARNING, fmt, args); va_end (args); } #endif static inline void belle_sip_error(const char *fmt,...) { va_list args; va_start (args, fmt); belle_sip_logv(BELLE_SIP_LOG_ERROR, fmt, args); va_end (args); } static inline void belle_sip_fatal(const char *fmt,...) { va_list args; va_start (args, fmt); belle_sip_logv(BELLE_SIP_LOG_FATAL, fmt, args); va_end (args); } void belle_sip_set_log_file(FILE *file); void belle_sip_set_log_handler(belle_sip_log_function_t func); void belle_sip_set_log_level(int level); char * belle_sip_random_token(char *ret, size_t size); #if defined(WIN32) || defined(WIN32_WCE) typedef SOCKET belle_sip_fd_t; #else typedef int belle_sip_fd_t; #endif BELLE_SIP_END_DECLS #endif