diff options
author | George Joseph <gjoseph@digium.com> | 2017-03-07 07:33:26 -0700 |
---|---|---|
committer | George Joseph <gjoseph@digium.com> | 2017-03-16 09:49:07 -0600 |
commit | 5013d8f5d31153c243e4a426bd0720e08be3ddc4 (patch) | |
tree | 0054aa7e9620fd4cba35a0b599a430e510474096 /res/res_pjsip_pubsub.c | |
parent | 84f0871cba30a9f3562f01fd347c6674d9058aad (diff) |
res_pjsip: Symmetric transports
A new transport parameter 'symmetric_transport' has been added.
When a request from a dynamic contact comes in on a transport with
this option set to 'yes', the transport name will be saved and used
for subsequent outgoing requests like OPTIONS, NOTIFY and INVITE.
It's saved as a contact uri parameter named 'x-ast-txp' and will
display with the contact uri in CLI, AMI, and ARI output. On the
outgoing request, if a transport wasn't explicitly set on the
endpoint AND the request URI is not a hostname, the saved transport
will be used and the 'x-ast-txp' parameter stripped from the
outgoing packet.
* config_transport was modified to accept and store the new parameter.
* config_transport/transport_apply was updated to store the transport
name in the pjsip_transport->info field using the pjsip_transport->pool
on UDP transports.
* A 'multihomed_on_rx_message' function was added to
pjsip_message_ip_updater that, for incoming requests, retrieves the
transport name from pjsip_transport->info and retrieves the transport.
If transport->symmetric_transport is set, an 'x-ast-txp' uri parameter
containing the transport name is added to the incoming Contact header.
* An 'ast_sip_get_transport_name' function was added to res_pjsip.
It takes an ast_sip_endpoint and a pjsip_sip_uri and returns a
transport name if endpoint->transport is set or if there's an
'x-ast-txp' parameter on the uri and the uri host is an ipv4 or
ipv6 address. Otherwise it returns NULL.
* An 'ast_sip_dlg_set_transport' function was added to res_pjsip
which takes an ast_sip_endpoint, a pjsip_dialog, and an optional
pjsip_tpselector. It calls ast_sip_get_transport_name() and if
a non-NULL is returned, sets the selector and sets the transport
on the dialog. If a selector was passed in, it's updated.
* res_pjsip/ast_sip_create_dialog_uac and ast_sip_create_dialog_uas
were modified to call ast_sip_dlg_set_transport() instead of their
original logic.
* res_pjsip/create_out_of_dialog_request was modified to call
ast_sip_get_transport_name() and pjsip_tx_data_set_transport()
instead of its original logic.
* Existing transport logic was removed from endpt_send_request
since that can only be called after a create_out_of_dialog_request.
* res_pjsip/ast_sip_create_rdata was converted to a wrapper around
a new 'ast_sip_create_rdata_with_contact' function which allows
a contact_uri to be specified in addition to the existing
parameters. (See below)
* res_pjsip_pubsub/internal_pjsip_evsub_send_request was eliminated
since all it did was transport selection and that is now done in
ast_sip_create_dialog_uac and ast_sip_create_dialog_uas.
* 'contact_uri' was added to subscription_persistence. This was
necessary because although the parsed rdata contact header has the
x-ast-txp parameter added (if appropriate),
subscription_persistence_update stores the raw packet which
doesn't have it. subscription_persistence_recreate was then
updated to call ast_sip_create_rdata_with_contact with the
persisted contact_uri so the recreated subscription has the
correct transport info to send the NOTIFYs.
* res_pjsip_session/internal_pjsip_inv_send_msg was eliminated since
all it did was transport selection and that is now done in
ast_sip_create_dialog_uac.
* pjsip_message_ip_updater/multihomed_on_tx_message was updated
to remove all traces of the x-ast-txp parameter from the
outgoing headers.
NOTE: This change does NOT modify the behavior of permanent
contacts specified on an aor. To do so would require that the
permanent contact's contact uri be updated with the x-ast-txp
parameter and the aor sorcery object updated. If we need to
persue this, we need to think about cloning permanent contacts into
the same store as the dynamic ones on an aor load so they can be
updated without disturbing the originally configured value.
You CAN add the x-ast-txp parameter to a permanent contact's uri
but it would be much simpler to just set endpoint->transport.
Change-Id: I4ee1f51473da32ca54b877cd158523efcef9655f
Diffstat (limited to 'res/res_pjsip_pubsub.c')
-rw-r--r-- | res/res_pjsip_pubsub.c | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c index e90502485..f0467627e 100644 --- a/res/res_pjsip_pubsub.c +++ b/res/res_pjsip_pubsub.c @@ -123,6 +123,9 @@ <configOption name="expires"> <synopsis>The time at which the subscription expires</synopsis> </configOption> + <configOption name="contact_uri"> + <synopsis>The Contact URI of the dialog for the subscription</synopsis> + </configOption> </configObject> <configObject name="resource_list"> <synopsis>Resource list configuration parameters.</synopsis> @@ -376,6 +379,8 @@ struct subscription_persistence { char *tag; /*! When this subscription expires */ struct timeval expires; + /*! Contact URI */ + char contact_uri[PJSIP_MAX_URL_SIZE]; }; /*! @@ -591,8 +596,8 @@ static void subscription_persistence_update(struct sip_subscription_tree *sub_tr return; } - ast_debug(3, "Updating persistence for '%s->%s'\n", - ast_sorcery_object_get_id(sub_tree->endpoint), sub_tree->root->resource); + ast_debug(3, "Updating persistence for '%s->%s'\n", sub_tree->persistence->endpoint, + sub_tree->root->resource); dlg = sub_tree->dlg; sub_tree->persistence->cseq = dlg->local.cseq; @@ -600,10 +605,14 @@ static void subscription_persistence_update(struct sip_subscription_tree *sub_tr if (rdata) { int expires; pjsip_expires_hdr *expires_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES, NULL); + pjsip_contact_hdr *contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL); expires = expires_hdr ? expires_hdr->ivalue : DEFAULT_PUBLISH_EXPIRES; sub_tree->persistence->expires = ast_tvadd(ast_tvnow(), ast_samp2tv(expires, 1)); + pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, contact_hdr->uri, + sub_tree->persistence->contact_uri, sizeof(sub_tree->persistence->contact_uri)); + /* When receiving a packet on an streaming transport, it's possible to receive more than one SIP * message at a time into the rdata->pkt_info.packet buffer. However, the rdata->msg_info.msg_buf * will always point to the proper SIP message that is to be processed. When updating subscription @@ -1550,8 +1559,9 @@ static int subscription_persistence_recreate(void *obj, void *arg, int flags) pj_pool_reset(pool); rdata.tp_info.pool = pool; - if (ast_sip_create_rdata(&rdata, persistence->packet, persistence->src_name, persistence->src_port, - persistence->transport_key, persistence->local_name, persistence->local_port)) { + if (ast_sip_create_rdata_with_contact(&rdata, persistence->packet, persistence->src_name, + persistence->src_port, persistence->transport_key, persistence->local_name, + persistence->local_port, persistence->contact_uri)) { ast_log(LOG_WARNING, "Failed recreating '%s' subscription: The message could not be parsed\n", persistence->endpoint); ast_sorcery_delete(ast_sip_get_sorcery(), persistence); @@ -1703,28 +1713,6 @@ 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) @@ -1772,7 +1760,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) { - internal_pjsip_evsub_send_request(sub_tree, tdata); + pjsip_evsub_send_request(sub_tree->evsub, tdata); } else { /* pjsip_evsub_terminate will result in pubsub_on_evsub_state, * being called and terminating the subscription. Therefore, we don't @@ -1869,7 +1857,7 @@ static int sip_subscription_send_request(struct sip_subscription_tree *sub_tree, return -1; } - res = internal_pjsip_evsub_send_request(sub_tree, tdata); + res = pjsip_evsub_send_request(sub_tree->evsub, tdata); subscription_persistence_update(sub_tree, NULL, SUBSCRIPTION_PERSISTENCE_SEND_REQUEST); @@ -5283,6 +5271,8 @@ static int load_module(void) persistence_tag_str2struct, persistence_tag_struct2str, NULL, 0, 0); ast_sorcery_object_field_register_custom(sorcery, "subscription_persistence", "expires", "", persistence_expires_str2struct, persistence_expires_struct2str, NULL, 0, 0); + ast_sorcery_object_field_register(sorcery, "subscription_persistence", "contact_uri", "", OPT_CHAR_ARRAY_T, 0, + CHARFLDSET(struct subscription_persistence, contact_uri)); if (apply_list_configuration(sorcery)) { ast_sip_unregister_service(&pubsub_module); |