<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12816">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip: Create outgoing_stateful_response supplement callback<br><br>In res_pjsip, ast_sip_send_stateful_response is special in that it's<br>one of the few places where both a request's rdata and a response's<br>tdata are available at the same time. This offers an opportunity<br>for modules to store something in the incoming requests's rdata<br>mod_data in an incoming_request callback, then retrieve it again<br>in this new callback to update the response.<br><br>This capability is currently only available for requests handled by<br>pjsip_options, res_pjsip_registrar, and res_pjsip_messaging because<br>only they call ast_sip_send_stateful_response.<br><br>Change-Id: I5b53a95ae6f3cda0ea5240316b26689c4ebfbbd4<br>---<br>M include/asterisk/res_pjsip.h<br>M res/res_pjsip.c<br>2 files changed, 25 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/16/12816/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h</span><br><span>index 5e8dd3a..4a307bc 100644</span><br><span>--- a/include/asterisk/res_pjsip.h</span><br><span>+++ b/include/asterisk/res_pjsip.h</span><br><span>@@ -2730,6 +2730,13 @@</span><br><span> void (*outgoing_response)(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, struct pjsip_tx_data *tdata);</span><br><span> /*! Next item in the list */</span><br><span> AST_LIST_ENTRY(ast_sip_supplement) next;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Called on an outgoing stateful SIP response before the message is sent</span><br><span style="color: hsl(120, 100%, 40%);">+ * The outgoing_response callbacks will also be called just after this callback.</span><br><span style="color: hsl(120, 100%, 40%);">+ * This method is always called from a SIP servant thread.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ void (*outgoing_stateful_response)(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact,</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct pjsip_rx_data *rdata, struct pjsip_tx_data *tdata);</span><br><span> };</span><br><span> </span><br><span> /*!</span><br><span>diff --git a/res/res_pjsip.c b/res/res_pjsip.c</span><br><span>index c41b545..44875d6 100644</span><br><span>--- a/res/res_pjsip.c</span><br><span>+++ b/res/res_pjsip.c</span><br><span>@@ -4638,6 +4638,23 @@</span><br><span> ao2_cleanup(contact);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void supplement_outgoing_stateful_response(const pjsip_rx_data *rdata, pjsip_tx_data *tdata,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_endpoint *sip_endpoint)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_supplement *supplement;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_contact *contact =</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_mod_data_get(tdata->mod_data, supplement_module.id, MOD_DATA_CONTACT);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_RWLIST_RDLOCK(&supplements);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_LIST_TRAVERSE(&supplements, supplement, next) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (supplement->outgoing_stateful_response && does_method_match(</span><br><span style="color: hsl(120, 100%, 40%);">+ &rdata->msg_info.msg->line.req.method.name, supplement->method)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ supplement->outgoing_stateful_response(sip_endpoint, contact, rdata, tdata);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_RWLIST_UNLOCK(&supplements);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> int ast_sip_send_response(pjsip_response_addr *res_addr, pjsip_tx_data *tdata, struct ast_sip_endpoint *sip_endpoint)</span><br><span> {</span><br><span> pj_status_t status;</span><br><span>@@ -4669,6 +4686,7 @@</span><br><span> }</span><br><span> pjsip_tsx_recv_msg(tsx, rdata);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ supplement_outgoing_stateful_response(rdata, tdata, sip_endpoint);</span><br><span> supplement_outgoing_response(tdata, sip_endpoint);</span><br><span> </span><br><span> if (pjsip_tsx_send_msg(tsx, tdata) != PJ_SUCCESS) {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/12816">change 12816</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/12816"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: I5b53a95ae6f3cda0ea5240316b26689c4ebfbbd4 </div>
<div style="display:none"> Gerrit-Change-Number: 12816 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>