diff options
author | George Joseph <george.joseph@fairview5.com> | 2016-02-11 10:01:05 -0700 |
---|---|---|
committer | George Joseph <george.joseph@fairview5.com> | 2016-02-19 17:56:27 -0700 |
commit | d2a1457e0b4ecdd512fe58fdb55ecc07fd141bea (patch) | |
tree | db97ca4b365f3bd4bad2110c69a0e4ff9fe268a7 /res/res_pjsip_pubsub.c | |
parent | b4fdf93d06753c580b4ef7e34fe07670a8e4aff4 (diff) |
res_pjsip/config_transport: Allow reloading transports.
The 'reload' mechanism actually involves closing the underlying
socket and calling the appropriate udp, tcp or tls start functions
again. Only outbound_registration, pubsub and session needed work
to reset the transport before sending requests to insure that the
pjsip transport didn't get pulled out from under them.
In my testing, no calls were dropped when a transport was changed
for any of the 3 transport types even if ip addresses or ports were
changed. To be on the safe side however, a new transport option was
added (allow_reload) which defaults to 'no'. Unless it's explicitly
set to 'yes' for a transport, changes to that transport will be ignored
on a reload of res_pjsip. This should preserve the current behavior.
Change-Id: I5e759850e25958117d4c02f62ceb7244d7ec9edf
Diffstat (limited to 'res/res_pjsip_pubsub.c')
-rw-r--r-- | res/res_pjsip_pubsub.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c index 8b37dd07b..643ed850f 100644 --- a/res/res_pjsip_pubsub.c +++ b/res/res_pjsip_pubsub.c @@ -1559,6 +1559,28 @@ void *ast_sip_subscription_get_header(const struct ast_sip_subscription *sub, co return pjsip_msg_find_hdr_by_name(msg, &name, NULL); } +/*! + * \internal + * \brief Wrapper for pjsip_evsub_send_request + * + * This function (re)sets the transport before sending to catch cases + * where the transport might have changed. + * + * If pjproject gives us the ability to resend, we'll only reset the transport + * if PJSIP_ETPNOTAVAIL is returned from send. + * + * \returns pj_status_t + */ +static pj_status_t internal_pjsip_evsub_send_request(struct sip_subscription_tree *sub_tree, pjsip_tx_data *tdata) +{ + pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, }; + + ast_sip_set_tpselector_from_transport_name(sub_tree->endpoint->transport, &selector); + pjsip_dlg_set_transport(sub_tree->dlg, &selector); + + return pjsip_evsub_send_request(sub_tree->evsub, tdata); +} + /* XXX This function is not used. */ struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_subscription_handler *handler, struct ast_sip_endpoint *endpoint, const char *resource) @@ -1606,7 +1628,7 @@ struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_su evsub = sub_tree->evsub; if (pjsip_evsub_initiate(evsub, NULL, -1, &tdata) == PJ_SUCCESS) { - pjsip_evsub_send_request(evsub, tdata); + internal_pjsip_evsub_send_request(sub_tree, tdata); } else { /* pjsip_evsub_terminate will result in pubsub_on_evsub_state, * being called and terminating the subscription. Therefore, we don't @@ -1687,8 +1709,8 @@ static int sip_subscription_send_request(struct sip_subscription_tree *sub_tree, { #ifdef TEST_FRAMEWORK struct ast_sip_endpoint *endpoint = sub_tree->endpoint; -#endif pjsip_evsub *evsub = sub_tree->evsub; +#endif int res; if (allocate_tdata_buffer(tdata)) { @@ -1696,7 +1718,8 @@ static int sip_subscription_send_request(struct sip_subscription_tree *sub_tree, return -1; } - res = pjsip_evsub_send_request(evsub, tdata) == PJ_SUCCESS ? 0 : -1; + res = internal_pjsip_evsub_send_request(sub_tree, tdata); + subscription_persistence_update(sub_tree, NULL); ast_test_suite_event_notify("SUBSCRIPTION_STATE_SET", @@ -1705,7 +1728,7 @@ static int sip_subscription_send_request(struct sip_subscription_tree *sub_tree, pjsip_evsub_get_state_name(evsub), ast_sorcery_object_get_id(endpoint)); - return res; + return (res == PJ_SUCCESS ? 0 : -1); } /*! |