From 6910d50e9b1e80fe758b259149012e7e062eecd0 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Mon, 6 Jun 2016 10:14:12 +0200 Subject: net: make networking code re-entrant - The network instance is now in struct network and does not use any local/static data - A new top-level struct in baresip.c owns the single instance of struct network it is a long-term goal to remove all local/static data from libbaresip and make it fully re-entrant. --- modules/account/account.c | 2 +- modules/contact/contact.c | 2 +- modules/menu/menu.c | 8 +++++++- modules/natbd/natbd.c | 8 +++++--- modules/rst/rst.c | 3 ++- 5 files changed, 16 insertions(+), 7 deletions(-) (limited to 'modules') diff --git a/modules/account/account.c b/modules/account/account.c index 46a6861..9cd4235 100644 --- a/modules/account/account.c +++ b/modules/account/account.c @@ -45,7 +45,7 @@ static int account_write_template(const char *file) pass = "pass"; } - domain = net_domain(); + domain = net_domain(baresip_network()); if (!domain) domain = "domain"; diff --git a/modules/contact/contact.c b/modules/contact/contact.c index ef10bc8..42ff614 100644 --- a/modules/contact/contact.c +++ b/modules/contact/contact.c @@ -139,7 +139,7 @@ static int write_template(const char *file) user = sys_username(); if (!user) user = "user"; - domain = net_domain(); + domain = net_domain(baresip_network()); if (!domain) domain = "domain"; diff --git a/modules/menu/menu.c b/modules/menu/menu.c index de179c1..039cf45 100644 --- a/modules/menu/menu.c +++ b/modules/menu/menu.c @@ -429,6 +429,12 @@ static int cmd_config_print(struct re_printf *pf, void *unused) } +static int cmd_net_debug(struct re_printf *pf, void *unused) +{ + return net_debug(pf, baresip_network()); +} + + static const struct cmd cmdv[] = { {'M', 0, "Main loop debug", re_debug }, {'\n', 0, "Accept incoming call", cmd_answer }, @@ -440,7 +446,7 @@ static const struct cmd cmdv[] = { {'i', 0, "SIP debug", ua_print_sip_status }, {'l', 0, "List active calls", cmd_print_calls }, {'m', 0, "Module debug", mod_debug }, - {'n', 0, "Network debug", net_debug }, + {'n', 0, "Network debug", cmd_net_debug }, {'o', CMD_PRM, "Options", options_command }, {'r', 0, "Registration info", ua_print_reg_status }, {'s', 0, "System info", print_system_info }, diff --git a/modules/natbd/natbd.c b/modules/natbd/natbd.c index 0aad61f..428a51a 100644 --- a/modules/natbd/natbd.c +++ b/modules/natbd/natbd.c @@ -244,6 +244,7 @@ static void destructor(void *arg) static int natbd_start(struct natbd *natbd) { + struct network *net = baresip_network(); int err = 0; if (!natbd->nh) { @@ -258,7 +259,8 @@ static int natbd_start(struct natbd *natbd) } if (!natbd->nm) { - err |= nat_mapping_alloc(&natbd->nm, net_laddr_af(net_af()), + err |= nat_mapping_alloc(&natbd->nm, + net_laddr_af(net, net_af(net)), &natbd->stun_srv, natbd->proto, NULL, nat_mapping_handler, natbd); err |= nat_mapping_start(natbd->nm); @@ -370,9 +372,9 @@ static void timeout_init(void *arg) goto out; } - err = stun_server_discover(&natbd->dns, net_dnsc(), + err = stun_server_discover(&natbd->dns, net_dnsc(baresip_network()), stun_usage_binding, - proto_str, net_af(), + proto_str, net_af(baresip_network()), natbd->host, natbd->port, dns_handler, natbd); if (err) diff --git a/modules/rst/rst.c b/modules/rst/rst.c index 8f2fea3..83298a9 100644 --- a/modules/rst/rst.c +++ b/modules/rst/rst.c @@ -308,7 +308,8 @@ static int rst_connect(struct rst *rst) } } else { - err = dnsc_query(&rst->dnsq, net_dnsc(), rst->host, DNS_TYPE_A, + err = dnsc_query(&rst->dnsq, net_dnsc(baresip_network()), + rst->host, DNS_TYPE_A, DNS_CLASS_IN, true, dns_handler, rst); if (err) { warning("rst: dns query error: %m\n", err); -- cgit v1.2.3