diff options
author | George Joseph <gjoseph@digium.com> | 2018-01-28 09:10:00 -0700 |
---|---|---|
committer | George Joseph <gjoseph@digium.com> | 2018-01-30 09:29:51 -0600 |
commit | 2b9aa6b5bbe8d3ada6e4a9b0bc614f2f77470cd0 (patch) | |
tree | a9dff42e45491c719a4a08fc402472b9a82885cc /res/res_pjsip.c | |
parent | 81db0aca0fb8d288a780ca664817ef231a9a4ac0 (diff) |
res_pjsip_pubsub: Prune subs with reliable transports at startup
In an earlier release, inbound registrations on a reliable transport
were pruned on Asterisk restart since the TCP connection would have
been torn down and become unusable when Asterisk stopped. This same
process is now also applied to inbound subscriptions.
Also fixed issues in res_pjsip_registrar where it wasn't handling the
monitoring correctly when multiple registrations came in over the same
transport.
To accomplish this, the pjsip_transport_event feature needed to
be refactored to allow multiple monitors (multiple subcriptions or
registrations from the same endpoint) to exist on the same transport.
Since this changed the API, any external modules that may have used the
transport monitor feature (highly unlikey) will need to be changed.
ASTERISK-27612
Reported by: Ross Beer
Change-Id: Iee87cf4eb9b7b2b93d5739a72af52d6ca8fbbe36
Diffstat (limited to 'res/res_pjsip.c')
-rw-r--r-- | res/res_pjsip.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/res/res_pjsip.c b/res/res_pjsip.c index 6a7d918c4..bf859fe88 100644 --- a/res/res_pjsip.c +++ b/res/res_pjsip.c @@ -3118,6 +3118,45 @@ pjsip_endpoint *ast_sip_get_pjsip_endpoint(void) return ast_pjsip_endpoint; } +int ast_sip_will_uri_survive_restart(pjsip_sip_uri *uri, struct ast_sip_endpoint *endpoint, + pjsip_rx_data *rdata) +{ + pj_str_t host_name; + int result = 1; + + /* Determine if the contact cannot survive a restart/boot. */ + if (uri->port == rdata->pkt_info.src_port + && !pj_strcmp(&uri->host, + pj_cstr(&host_name, rdata->pkt_info.src_name)) + /* We have already checked if the URI scheme is sip: or sips: */ + && PJSIP_TRANSPORT_IS_RELIABLE(rdata->tp_info.transport)) { + pj_str_t type_name; + + /* Determine the transport parameter value */ + if (!strcasecmp("WSS", rdata->tp_info.transport->type_name)) { + /* WSS is special, as it needs to be ws. */ + pj_cstr(&type_name, "ws"); + } else { + pj_cstr(&type_name, rdata->tp_info.transport->type_name); + } + + if (!pj_stricmp(&uri->transport_param, &type_name) + && (endpoint->nat.rewrite_contact + /* Websockets are always rewritten */ + || !pj_stricmp(&uri->transport_param, + pj_cstr(&type_name, "ws")))) { + /* + * The contact was rewritten to the reliable transport's + * source address. Disconnecting the transport for any + * reason invalidates the contact. + */ + result = 0; + } + } + + return result; +} + int ast_sip_get_transport_name(const struct ast_sip_endpoint *endpoint, pjsip_sip_uri *sip_uri, char *buf, size_t buf_len) { |