1 /* 2 * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 * Contact: http://philzimmermann.com 5 * For licensing and other legal details, see the file zrtp_legal.c. 6 * 7 * Viktor Krykun <v.krikun at zfoneproject.com> 8 */ 9 10 #ifndef __ZRTP_LOG_H__ 11 #define __ZRTP_LOG_H__ 12 13 #include "zrtp_config.h" 14 #include "zrtp_types.h" 15 #include "zrtp_base.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #define ZRTP_LOG_SENDER_MAX_LEN 12 22 #define ZRTP_LOG_BUFFER_SIZE 512 23 24 25 /*! 26 * \defgroup iface_log Functions for debug and information logging 27 * \ingroup interfaces 28 * \{ 29 */ 30 31 /** 32 * @brief Write log message. 33 * This is the main macro used to write text to the logging backend. 34 * @param level The logging verbosity level. Lower number indicates higher 35 * importance, with level zero indicates fatal error. Only 36 * numeral argument is permitted (e.g. not variable). 37 * @param arg Enclosed 'printf' like arguments, with the first 38 * argument is the sender, the second argument is format 39 * string and the following arguments are variable number of 40 * arguments suitable for the format string. 41 * 42 * Sample: 43 * @code 44 * ZRTP_LOG(2, (__UNITE__, "Some log message with id %d", id)); 45 * @endcode 46 */ 47 48 #define ZRTP_LOG(level,arg) do { \ 49 zrtp_log_wrapper_##level(arg); \ 50 } while (0) 51 52 #define ZRTP_LOGC(level,arg) do { \ 53 zrtp_log_wrapperc_##level(arg); \ 54 } while (0) 55 56 57 /** 58 * @brief Signature for function to be registered to the logging subsystem to 59 * write the actual log message to some output device. 60 * 61 * @param level Log level. 62 * @param data Log message, which will be NULL terminated. 63 * @param len Message length. (prefix + text) 64 * @param offset Log message prefix length 65 */ 66 typedef void zrtp_log_engine(int level, char *data, int len, int offset); 67 68 69 #if ZRTP_LOG_MAX_LEVEL >= 1 70 71 /** 72 * @brief Changes default log writer function. 73 * This function may be used to implement log writer in a way native for target 74 * OS or product. By default libzrtp uses console output. 75 * @param engine - log writer. 76 */ 77 void zrtp_log_set_log_engine(zrtp_log_engine *engine); 78 79 /** 80 * @brief Changes Log-Level in run-time mode 81 * Libzrtp uses 3 log levels: 82 * - 1 - system related errors; 83 * - 2 - security, ZRTP protocol related errors and warnings; 84 * - 3 - debug logging. 85 * By default, libzrtp uses debug logging - level 3. 86 * @param level - log level. 87 */ 88 void zrtp_log_set_level(uint32_t level); 89 90 /* \} */ 91 92 #else /* If logger is enabled */ 93 94 # define zrtp_log_set_log_engine(engine) 95 # define zrtp_log_set_level(level) 96 97 #endif /* If logger is enabled */ 98 99 100 #if ZRTP_LOG_MAX_LEVEL >= 1 101 # define zrtp_log_wrapper_1(arg) zrtp_log_1 arg 102 void zrtp_log_1(const char *src, const char *format, ...); 103 # define zrtp_log_wrapperc_1(arg) zrtp_logc_1 arg 104 void zrtp_logc_1(const char *format, ...); 105 #else 106 # define zrtp_log_wrapper_1(arg) 107 # define zrtp_log_wrapperc_1(arg) 108 #endif 109 110 #if ZRTP_LOG_MAX_LEVEL >= 2 111 # define zrtp_log_wrapper_2(arg) zrtp_log_2 arg 112 void zrtp_log_2(const char *src, const char *format, ...); 113 # define zrtp_log_wrapperc_2(arg) zrtp_logc_2 arg 114 void zrtp_logc_2(const char *format, ...); 115 #else 116 #define zrtp_log_wrapper_2(arg) 117 #define zrtp_log_wrapperc_2(arg) 118 #endif 119 120 #if ZRTP_LOG_MAX_LEVEL >= 3 121 # define zrtp_log_wrapper_3(arg) zrtp_log_3 arg 122 void zrtp_log_3(const char *src, const char *format, ...); 123 # define zrtp_log_wrapperc_3(arg) zrtp_logc_3 arg 124 void zrtp_logc_3(const char *format, ...); 125 126 #else 127 # define zrtp_log_wrapper_3(arg) 128 # define zrtp_log_wrapperc_3(arg) 129 #endif 130 131 const char* zrtp_log_error2str(zrtp_protocol_error_t error); 132 const char* zrtp_log_status2str(zrtp_status_t error); 133 134 /** Returns symbolical name of ZRTP protocol state for the current stream. */ 135 const char* zrtp_log_state2str(zrtp_state_t state); 136 137 /** Returns symbolical name of ZXRTP protocol packet by it's code. */ 138 const char* zrtp_log_pkt2str(zrtp_msg_type_t type); 139 140 /** Returns symbolical name of the PK Exchange mode for the current stream. */ 141 const char* zrtp_log_mode2str(zrtp_stream_mode_t mode); 142 143 /** Returns symbolical name of the protocol and security events. */ 144 const char* zrtp_log_event2str(uint8_t event); 145 146 /** 147 * Returns character name of the Signaling role. 148 * 149 * @param role One of zrtp_signaling_role_t values. 150 * @return character name of the \c role. 151 */ 152 const char* zrtp_log_sign_role2str(unsigned role); 153 154 155 /** Print out ZRTP environment configuration setting to log level 3. */ 156 void zrtp_print_env_settings(); 157 158 /** Print out ZRTP stream info strxucture. (use ZRTP log-level 3). */ 159 void zrtp_log_print_streaminfo(zrtp_stream_info_t* info); 160 161 /** Print out ZRTP session info structure. (use ZRTP log-level 3). */ 162 void zrtp_log_print_sessioninfo(zrtp_session_info_t* info); 163 164 #ifdef __cplusplus 165 } 166 #endif 167 168 169 #endif /* __ZRTP_LOG_H__ */ 170