diff options
author | Pascal Bühler <pabuhler@cisco.com> | 2017-02-24 10:51:52 +0100 |
---|---|---|
committer | Pascal Bühler <pabuhler@cisco.com> | 2017-02-24 10:51:52 +0100 |
commit | af151784288060026b4756b15128515f4a438ca8 (patch) | |
tree | f4c70a37754ddd1de491adc9e29ecf355b94703b /srtp | |
parent | 086bd2981da0a543ef0d21e69538a5f2ad768b08 (diff) | |
download | libsrtp2-af151784288060026b4756b15128515f4a438ca8.tar.gz |
Add log handler api to receive log messages from libSRTP
This address the second half of #230
Diffstat (limited to 'srtp')
-rw-r--r-- | srtp/srtp.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/srtp/srtp.c b/srtp/srtp.c index 5d9e152..2dff70b 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -4322,3 +4322,44 @@ srtp_err_status_t srtp_list_debug_modules(void) return srtp_crypto_kernel_list_debug_modules(); } +/* + * srtp_log_handler is a global variable holding a pointer to the + * log handler function; this function is called for any log + * output. + */ + +static srtp_log_handler_func_t *srtp_log_handler = NULL; + +void srtp_err_handler(srtp_err_reporting_level_t level, const char * msg) +{ + if (srtp_log_handler) { + srtp_log_level_t log_level; + switch(level) { + case srtp_err_level_error: log_level = srtp_log_level_error; break; + case srtp_err_level_warning: log_level = srtp_log_level_warning; break; + case srtp_err_level_info: log_level = srtp_log_level_info; break; + case srtp_err_level_debug: log_level = srtp_log_level_debug; break; + } + + srtp_log_handler(log_level, msg); + } +} + +srtp_err_status_t srtp_install_log_handler(srtp_log_handler_func_t func) +{ + + /* + * note that we accept NULL arguments intentionally - calling this + * function with a NULL arguments removes a log handler that's + * been previously installed + */ + + if (srtp_log_handler) { + srtp_install_err_report_handler(NULL); + } + srtp_log_handler = func; + if (srtp_log_handler) { + srtp_install_err_report_handler(srtp_err_handler); + } + return srtp_err_status_ok; +} |