zrtp_log.h 4.7 KB

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