summaryrefslogtreecommitdiff
path: root/res/res_pjsip_multihomed.c
diff options
context:
space:
mode:
authorGeorge Joseph <george.joseph@fairview5.com>2016-01-29 16:56:42 -0700
committerGeorge Joseph <george.joseph@fairview5.com>2016-02-08 18:08:32 -0700
commit2451d4e4550336197ee2e482750cc53f30afa352 (patch)
tree10acfac50575f695f66805e5607822e10610d74d /res/res_pjsip_multihomed.c
parent78fa818c1bdcbb5c0bcd5c651e14c7f607ac4997 (diff)
res_pjsip: Fix infinite recursion when loading transports from realtime
Attempting to load a transport from realtime was forcing asterisk into an infinite recursion loop. The first thing transport_apply did was to do a sorcery retrieve by id for an existing transport of the same name. For files, this just returns the previous object from res_sorcery_config's internal container, if any. For realtime, the res_sourcery_realtime driver looks in the database and finds the existing row but now it has to rehydrate it into a sorcery object which means calling... transport_apply. And so it goes. The main issue with loading from realtime (apart from the loop) was that transport stores structures and pointers directly in the ast_sip_transport structure instead of the separate ast_transport_state structure. This patch separates those items into the ast_sip_transport_state structure. The pattern is roughly the same as res_pjsip_outbound_registration. Although all current usages of ast_sip_transport and ast_sip_transport_state were modified to use the new ast_sip_get_transport_state API, the original items are left in ast_sip_transport and kept updated to maintain ABI compatability for third-party modules. They are marked as deprecated and noted that they're now in ast_sip_transport_state. ASTERISK-25606 #close Reported-by: Martin Moučka Change-Id: Ic7a836ea8e786e8def51fe3f8cce855ea54f5f19
Diffstat (limited to 'res/res_pjsip_multihomed.c')
-rw-r--r--res/res_pjsip_multihomed.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/res/res_pjsip_multihomed.c b/res/res_pjsip_multihomed.c
index 437a1cbe9..745bc37ea 100644
--- a/res/res_pjsip_multihomed.c
+++ b/res/res_pjsip_multihomed.c
@@ -33,30 +33,28 @@
/*! \brief Helper function which returns a UDP transport bound to the given address and port */
static pjsip_transport *multihomed_get_udp_transport(pj_str_t *address, int port)
{
- struct ao2_container *transports = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "transport",
- AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
- struct ast_sip_transport *transport;
+ struct ao2_container *transport_states = ast_sip_get_transport_states();
+ struct ast_sip_transport_state *transport_state;
struct ao2_iterator iter;
pjsip_transport *sip_transport = NULL;
- if (!transports) {
+ if (!transport_states) {
return NULL;
}
- for (iter = ao2_iterator_init(transports, 0); (transport = ao2_iterator_next(&iter)); ao2_ref(transport, -1)) {
- if ((transport->type != AST_TRANSPORT_UDP) ||
- (pj_strcmp(&transport->state->transport->local_name.host, address)) ||
- (transport->state->transport->local_name.port != port)) {
+ for (iter = ao2_iterator_init(transport_states, 0); (transport_state = ao2_iterator_next(&iter)); ao2_ref(transport_state, -1)) {
+ if (transport_state && ((transport_state->type != AST_TRANSPORT_UDP) ||
+ (pj_strcmp(&transport_state->transport->local_name.host, address)) ||
+ (transport_state->transport->local_name.port != port))) {
continue;
}
- sip_transport = transport->state->transport;
- ao2_ref(transport, -1);
+ sip_transport = transport_state->transport;
break;
}
ao2_iterator_destroy(&iter);
- ao2_ref(transports, -1);
+ ao2_ref(transport_states, -1);
return sip_transport;
}