sip: Register log callback function with sofia-sip
sofia-sip allows applications to register a log backend function which will be called every time the library wants to log something. We register such a call-back and make it log using the libosmocore logging framework. The problem is that sofia-sip has its own log level management, and by the time the message hits libosmocore, we don't know which log level we shall use :( Change-Id: Ib269b6b50f9d79bbd13acc43a626834921f05edb Related: OS#3105
This commit is contained in:
parent
65fa803f0c
commit
6369f30c4d
|
@ -9,6 +9,7 @@ struct app_config {
|
||||||
struct {
|
struct {
|
||||||
const char *local_addr;
|
const char *local_addr;
|
||||||
int local_port;
|
int local_port;
|
||||||
|
int sofia_log_level;
|
||||||
|
|
||||||
const char *remote_addr;
|
const char *remote_addr;
|
||||||
int remote_port;
|
int remote_port;
|
||||||
|
|
|
@ -126,7 +126,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
|
|
||||||
/* parsing and setup */
|
/* parsing and setup */
|
||||||
|
g_app.sip.sofia_log_level = 2;
|
||||||
handle_options(argc, argv);
|
handle_options(argc, argv);
|
||||||
rc = vty_read_config_file(config_file, NULL);
|
rc = vty_read_config_file(config_file, NULL);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
|
13
src/sip.c
13
src/sip.c
|
@ -27,6 +27,7 @@
|
||||||
#include <osmocom/core/utils.h>
|
#include <osmocom/core/utils.h>
|
||||||
|
|
||||||
#include <sofia-sip/sip_status.h>
|
#include <sofia-sip/sip_status.h>
|
||||||
|
#include <sofia-sip/su_log.h>
|
||||||
|
|
||||||
#include <talloc.h>
|
#include <talloc.h>
|
||||||
|
|
||||||
|
@ -383,12 +384,24 @@ char *make_sip_uri(struct sip_agent *agent)
|
||||||
agent->app->sip.local_port);
|
agent->app->sip.local_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* http://sofia-sip.sourceforge.net/refdocs/debug_logs.html */
|
||||||
|
static void sip_logger(void *stream, char const *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
/* this is ugly, as unfortunately sofia-sip does not pass the log level to
|
||||||
|
* the log handler call-back function, so we have no clue what log level the
|
||||||
|
* currently logged message was sent for :( As a result, we can only use one
|
||||||
|
* hard-coded LOGL_NOTICE here */
|
||||||
|
osmo_vlogp(DSIP, LOGL_NOTICE, "", 0, 0, fmt, ap);
|
||||||
|
}
|
||||||
|
|
||||||
void sip_agent_init(struct sip_agent *agent, struct app_config *app)
|
void sip_agent_init(struct sip_agent *agent, struct app_config *app)
|
||||||
{
|
{
|
||||||
agent->app = app;
|
agent->app = app;
|
||||||
|
|
||||||
su_init();
|
su_init();
|
||||||
su_home_init(&agent->home);
|
su_home_init(&agent->home);
|
||||||
|
su_log_redirect(su_log_default, &sip_logger, NULL);
|
||||||
|
su_log_redirect(su_log_global, &sip_logger, NULL);
|
||||||
agent->root = su_glib_root_create(NULL);
|
agent->root = su_glib_root_create(NULL);
|
||||||
su_root_threading(agent->root, 0);
|
su_root_threading(agent->root, 0);
|
||||||
}
|
}
|
||||||
|
|
18
src/vty.c
18
src/vty.c
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* (C) 2016 by Holger Hans Peter Freyther
|
* (C) 2016 by Holger Hans Peter Freyther
|
||||||
|
* (C) 2018 by Harald Welte <laforge@gnumonks.org>
|
||||||
*
|
*
|
||||||
* All Rights Reserved
|
* All Rights Reserved
|
||||||
*
|
*
|
||||||
|
@ -25,6 +26,8 @@
|
||||||
|
|
||||||
#include <talloc.h>
|
#include <talloc.h>
|
||||||
|
|
||||||
|
#include <sofia-sip/su_log.h>
|
||||||
|
|
||||||
extern void *tall_mncc_ctx;
|
extern void *tall_mncc_ctx;
|
||||||
|
|
||||||
struct app_config g_app;
|
struct app_config g_app;
|
||||||
|
@ -88,6 +91,7 @@ static int config_write_sip(struct vty *vty)
|
||||||
vty_out(vty, "sip%s", VTY_NEWLINE);
|
vty_out(vty, "sip%s", VTY_NEWLINE);
|
||||||
vty_out(vty, " local %s %d%s", g_app.sip.local_addr, g_app.sip.local_port, VTY_NEWLINE);
|
vty_out(vty, " local %s %d%s", g_app.sip.local_addr, g_app.sip.local_port, VTY_NEWLINE);
|
||||||
vty_out(vty, " remote %s %d%s", g_app.sip.remote_addr, g_app.sip.remote_port, VTY_NEWLINE);
|
vty_out(vty, " remote %s %d%s", g_app.sip.remote_addr, g_app.sip.remote_port, VTY_NEWLINE);
|
||||||
|
vty_out(vty, " sofia-sip log-level %d%s", g_app.sip.sofia_log_level, VTY_NEWLINE);
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +137,19 @@ DEFUN(cfg_sip_remote_addr, cfg_sip_remote_addr_cmd,
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFUN(cfg_sip_sofia_log_level, cfg_sip_sofia_log_level_cmd,
|
||||||
|
"sofia-sip log-level <0-9>",
|
||||||
|
"sofia-sip library configuration\n"
|
||||||
|
"global log-level for sofia-sip\n"
|
||||||
|
"(0 = nothing, 9 = super-verbose)\n")
|
||||||
|
{
|
||||||
|
g_app.sip.sofia_log_level = atoi(argv[0]);
|
||||||
|
su_log_set_level(su_log_default, g_app.sip.sofia_log_level);
|
||||||
|
su_log_set_level(su_log_global, g_app.sip.sofia_log_level);
|
||||||
|
|
||||||
|
return CMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
DEFUN(cfg_mncc, cfg_mncc_cmd,
|
DEFUN(cfg_mncc, cfg_mncc_cmd,
|
||||||
"mncc",
|
"mncc",
|
||||||
"MNCC\n")
|
"MNCC\n")
|
||||||
|
@ -302,6 +319,7 @@ void mncc_sip_vty_init(void)
|
||||||
install_node(&sip_node, config_write_sip);
|
install_node(&sip_node, config_write_sip);
|
||||||
install_element(SIP_NODE, &cfg_sip_local_addr_cmd);
|
install_element(SIP_NODE, &cfg_sip_local_addr_cmd);
|
||||||
install_element(SIP_NODE, &cfg_sip_remote_addr_cmd);
|
install_element(SIP_NODE, &cfg_sip_remote_addr_cmd);
|
||||||
|
install_element(SIP_NODE, &cfg_sip_sofia_log_level_cmd);
|
||||||
|
|
||||||
install_element(CONFIG_NODE, &cfg_mncc_cmd);
|
install_element(CONFIG_NODE, &cfg_mncc_cmd);
|
||||||
install_node(&mncc_node, config_write_mncc);
|
install_node(&mncc_node, config_write_mncc);
|
||||||
|
|
Loading…
Reference in New Issue