[Asterisk-code-review] res_pjsip: Create outgoing_stateful_response supplement callback (...asterisk[13])

George Joseph asteriskteam at digium.com
Thu Aug 29 07:02:08 CDT 2019


George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/12816


Change subject: res_pjsip: Create outgoing_stateful_response supplement callback
......................................................................

res_pjsip: Create outgoing_stateful_response supplement callback

In res_pjsip, ast_sip_send_stateful_response is special in that it's
one of the few places where both a request's rdata and a response's
tdata are available at the same time.  This offers an opportunity
for modules to store something in the incoming requests's rdata
mod_data in an incoming_request callback, then retrieve it again
in this new callback to update the response.

This capability is currently only available for requests handled by
pjsip_options, res_pjsip_registrar, and res_pjsip_messaging because
only they call ast_sip_send_stateful_response.

Change-Id: I5b53a95ae6f3cda0ea5240316b26689c4ebfbbd4
---
M include/asterisk/res_pjsip.h
M res/res_pjsip.c
2 files changed, 25 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/16/12816/1

diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index 5e8dd3a..4a307bc 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -2730,6 +2730,13 @@
 	void (*outgoing_response)(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, struct pjsip_tx_data *tdata);
 	/*! Next item in the list */
 	AST_LIST_ENTRY(ast_sip_supplement) next;
+	/*!
+	 * \brief Called on an outgoing stateful SIP response before the message is sent
+	 * The outgoing_response callbacks will also be called just after this callback.
+	 * This method is always called from a SIP servant thread.
+	 */
+	void (*outgoing_stateful_response)(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact,
+		const struct pjsip_rx_data *rdata,  struct pjsip_tx_data *tdata);
 };
 
 /*!
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index c41b545..44875d6 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -4638,6 +4638,23 @@
 	ao2_cleanup(contact);
 }
 
+static void supplement_outgoing_stateful_response(const pjsip_rx_data *rdata, pjsip_tx_data *tdata,
+	struct ast_sip_endpoint *sip_endpoint)
+{
+	struct ast_sip_supplement *supplement;
+	struct ast_sip_contact *contact =
+		ast_sip_mod_data_get(tdata->mod_data, supplement_module.id, MOD_DATA_CONTACT);
+
+	AST_RWLIST_RDLOCK(&supplements);
+	AST_LIST_TRAVERSE(&supplements, supplement, next) {
+		if (supplement->outgoing_stateful_response && does_method_match(
+			&rdata->msg_info.msg->line.req.method.name, supplement->method)) {
+			supplement->outgoing_stateful_response(sip_endpoint, contact, rdata, tdata);
+		}
+	}
+	AST_RWLIST_UNLOCK(&supplements);
+}
+
 int ast_sip_send_response(pjsip_response_addr *res_addr, pjsip_tx_data *tdata, struct ast_sip_endpoint *sip_endpoint)
 {
 	pj_status_t status;
@@ -4669,6 +4686,7 @@
 	}
 	pjsip_tsx_recv_msg(tsx, rdata);
 
+	supplement_outgoing_stateful_response(rdata, tdata, sip_endpoint);
 	supplement_outgoing_response(tdata, sip_endpoint);
 
 	if (pjsip_tsx_send_msg(tsx, tdata) != PJ_SUCCESS) {

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/12816
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: I5b53a95ae6f3cda0ea5240316b26689c4ebfbbd4
Gerrit-Change-Number: 12816
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190829/e163e66d/attachment.html>


More information about the asterisk-code-review mailing list