<p>Kevin Harwell <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18736">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_header_funcs: Add functions PJSIP_RESPONSE_HEADER and PJSIP_RESPONSE_HEADERS<br><br>These new functions allow retrieving information from headers on 200 OK<br>INVITE response.<br><br>ASTERISK-29999<br><br>Change-Id: I264a610a9333359297a0825feb29a1bb4f4ad144<br>---<br>A doc/CHANGES-staging/res_pjsip_header_funcs.txt<br>M res/res_pjsip_header_funcs.c<br>2 files changed, 247 insertions(+), 12 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/res_pjsip_header_funcs.txt b/doc/CHANGES-staging/res_pjsip_header_funcs.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..88946e4</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/res_pjsip_header_funcs.txt</span><br><span>@@ -0,0 +1,5 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: res_pjsip_header_funcs</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Add function PJSIP_RESPONSE_HEADERS() to get list of header names from 200 response, in the same way as PJSIP_HEADERS() from the request.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Add function PJSIP_RESPONSE_HEADER() to read header from 200 response, in the same way as PJSIP_HEADER() from the request.</span><br><span>diff --git a/res/res_pjsip_header_funcs.c b/res/res_pjsip_header_funcs.c</span><br><span>index fa6db34..cca2b78 100644</span><br><span>--- a/res/res_pjsip_header_funcs.c</span><br><span>+++ b/res/res_pjsip_header_funcs.c</span><br><span>@@ -4,6 +4,7 @@</span><br><span> * Copyright (C) 2013, Fairview 5 Engineering, LLC</span><br><span> *</span><br><span> * George Joseph <george.joseph@fairview5.com></span><br><span style="color: hsl(120, 100%, 40%);">+ * José Lopes <jose.lopes@nfon.com></span><br><span> *</span><br><span> * See http://www.asterisk.org for more information about</span><br><span> * the Asterisk project. Please do not directly contact</span><br><span>@@ -166,6 +167,89 @@</span><br><span> <ref type="function">PJSIP_HEADER</ref></span><br><span> </see-also></span><br><span> </function></span><br><span style="color: hsl(120, 100%, 40%);">+ <function name="PJSIP_RESPONSE_HEADER" language="en_US"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ Gets headers of 200 response from an outbound PJSIP channel.</span><br><span style="color: hsl(120, 100%, 40%);">+ </synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ <syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="action" required="true"></span><br><span style="color: hsl(120, 100%, 40%);">+ <enumlist></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name="read"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Returns instance <replaceable>number</replaceable></span><br><span style="color: hsl(120, 100%, 40%);">+ of response header <replaceable>name</replaceable>.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </enum></span><br><span style="color: hsl(120, 100%, 40%);">+ </enumlist></span><br><span style="color: hsl(120, 100%, 40%);">+ </parameter></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="name" required="true"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>The <replaceable>name</replaceable> of the response header.</span><br><span style="color: hsl(120, 100%, 40%);">+ A <literal>*</literal> can be appended to the <replaceable>name</replaceable></span><br><span style="color: hsl(120, 100%, 40%);">+ to iterate over all response headers <emphasis>beginning with</emphasis></span><br><span style="color: hsl(120, 100%, 40%);">+ <replaceable>name</replaceable>.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </parameter></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="number" required="false"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>If there's more than 1 header with the same name, this specifies which header</span><br><span style="color: hsl(120, 100%, 40%);">+ to read. If not specified, defaults to <literal>1</literal> meaning</span><br><span style="color: hsl(120, 100%, 40%);">+ the first matching header.</span><br><span style="color: hsl(120, 100%, 40%);">+ </para></span><br><span style="color: hsl(120, 100%, 40%);">+ </parameter></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ </syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ <description></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>PJSIP_RESPONSE_HEADER allows you to read specific SIP headers of 200 response</span><br><span style="color: hsl(120, 100%, 40%);">+ from the outbound PJSIP channel.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Examples:</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <example title="Set 'somevar' to the value of the 'From' header"></span><br><span style="color: hsl(120, 100%, 40%);">+ exten => 1,1,Set(somevar=${PJSIP_RESPONSE_HEADER(read,From)})</span><br><span style="color: hsl(120, 100%, 40%);">+ </example></span><br><span style="color: hsl(120, 100%, 40%);">+ <example title="Set 'via2' to the value of the 2nd 'Via' header"></span><br><span style="color: hsl(120, 100%, 40%);">+ exten => 1,1,Set(via2=${PJSIP_RESPONSE_HEADER(read,Via,2)})</span><br><span style="color: hsl(120, 100%, 40%);">+ </example></span><br><span style="color: hsl(120, 100%, 40%);">+ <example title="Set 'xhdr' to the value of the 1sx X-header"></span><br><span style="color: hsl(120, 100%, 40%);">+ exten => 1,1,Set(xhdr=${PJSIP_RESPONSE_HEADER(read,X-*,1)})</span><br><span style="color: hsl(120, 100%, 40%);">+ </example></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <note><para>If you call PJSIP_RESPONSE_HEADER in a normal dialplan context you'll be</span><br><span style="color: hsl(120, 100%, 40%);">+ operating on the <emphasis>caller's (incoming)</emphasis> channel which</span><br><span style="color: hsl(120, 100%, 40%);">+ may not be what you want. To operate on the <emphasis>callee's (outgoing)</emphasis></span><br><span style="color: hsl(120, 100%, 40%);">+ channel call PJSIP_RESPONSE_HEADER in a pre-connect handler.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </note></span><br><span style="color: hsl(120, 100%, 40%);">+ <example title="Usage on pre-connect handler"></span><br><span style="color: hsl(120, 100%, 40%);">+ [handler]</span><br><span style="color: hsl(120, 100%, 40%);">+ exten => readheader,1,NoOp(PJSIP_RESPONSE_HEADER(read,X-MyHeader))</span><br><span style="color: hsl(120, 100%, 40%);">+ [somecontext]</span><br><span style="color: hsl(120, 100%, 40%);">+ exten => 1,1,Dial(PJSIP/${EXTEN},,U(handler^readheader^1))</span><br><span style="color: hsl(120, 100%, 40%);">+ </example></span><br><span style="color: hsl(120, 100%, 40%);">+ </description></span><br><span style="color: hsl(120, 100%, 40%);">+ <see-also></span><br><span style="color: hsl(120, 100%, 40%);">+ <ref type="function">PJSIP_RESPONSE_HEADERS</ref></span><br><span style="color: hsl(120, 100%, 40%);">+ <ref type="function">PJSIP_HEADER</ref></span><br><span style="color: hsl(120, 100%, 40%);">+ </see-also></span><br><span style="color: hsl(120, 100%, 40%);">+ </function></span><br><span style="color: hsl(120, 100%, 40%);">+ <function name="PJSIP_RESPONSE_HEADERS" language="en_US"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ Gets the list of SIP header names from the 200 response of INVITE message.</span><br><span style="color: hsl(120, 100%, 40%);">+ </synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ <syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="prefix"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>If specified, only the headers matching the given prefix are returned.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </parameter></span><br><span style="color: hsl(120, 100%, 40%);">+ </syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ <description></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Returns a comma-separated list of header names (without values) from the 200</span><br><span style="color: hsl(120, 100%, 40%);">+ response of INVITE message. Multiple headers with the same name are included in the</span><br><span style="color: hsl(120, 100%, 40%);">+ list only once.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>For example, <literal>${PJSIP_RESPONSE_HEADERS(Co)}</literal> might return</span><br><span style="color: hsl(120, 100%, 40%);">+ <literal>Contact,Content-Length,Content-Type</literal>. As a practical example,</span><br><span style="color: hsl(120, 100%, 40%);">+ you may use <literal>${PJSIP_RESPONSE_HEADERS(X-)}</literal> to enumerate optional</span><br><span style="color: hsl(120, 100%, 40%);">+ extended headers.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </description></span><br><span style="color: hsl(120, 100%, 40%);">+ <see-also></span><br><span style="color: hsl(120, 100%, 40%);">+ <ref type="function">PJSIP_RESPONSE_HEADER</ref></span><br><span style="color: hsl(120, 100%, 40%);">+ <ref type="function">PJSIP_HEADERS</ref></span><br><span style="color: hsl(120, 100%, 40%);">+ </see-also></span><br><span style="color: hsl(120, 100%, 40%);">+ </function></span><br><span> </span><br><span> ***/</span><br><span> </span><br><span>@@ -180,6 +264,10 @@</span><br><span> static const struct ast_datastore_info header_datastore = {</span><br><span> .type = "header_datastore",</span><br><span> };</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief Datastore for saving response headers */</span><br><span style="color: hsl(120, 100%, 40%);">+static const struct ast_datastore_info response_header_datastore = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .type = "response_header_datastore",</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span> </span><br><span> /*! \brief Data structure used for ast_sip_push_task_wait_serializer */</span><br><span> struct header_data {</span><br><span>@@ -189,6 +277,7 @@</span><br><span> char *buf;</span><br><span> int header_number;</span><br><span> size_t len;</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_datastore_info *header_datastore;</span><br><span> };</span><br><span> </span><br><span> /*!</span><br><span>@@ -245,6 +334,42 @@</span><br><span> </span><br><span> /*!</span><br><span> * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Session supplement callback on an incoming INVITE response</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Retrieve the response_header_datastore from the session or create one if it doesn't exist.</span><br><span style="color: hsl(120, 100%, 40%);">+ * Create and initialize the list if needed.</span><br><span style="color: hsl(120, 100%, 40%);">+ * Insert the headers.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static void incoming_response(struct ast_sip_session *session, pjsip_rx_data * rdata)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_pool_t *pool = session->inv_session->dlg->pool;</span><br><span style="color: hsl(120, 100%, 40%);">+ RAII_VAR(struct ast_datastore *, datastore,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_get_datastore(session, response_header_datastore.type), ao2_cleanup);</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_status_line status = rdata->msg_info.msg->line.status;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Skip responses different of 200 OK, when 2xx is received. */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (session->inv_session->state != PJSIP_INV_STATE_CONNECTING || status.code!=200) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</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%);">+ if (!datastore) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(datastore =</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_alloc_datastore(&response_header_datastore, response_header_datastore.type))</span><br><span style="color: hsl(120, 100%, 40%);">+ ||</span><br><span style="color: hsl(120, 100%, 40%);">+ !(datastore->data = pj_pool_alloc(pool, sizeof(struct hdr_list))) ||</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_add_datastore(session, datastore)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(AST_LOG_ERROR, "Unable to create datastore for header functions.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_LIST_HEAD_INIT_NOLOCK((struct hdr_list *) datastore->data);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ insert_headers(pool, (struct hdr_list *) datastore->data, rdata->msg_info.msg);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</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%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span> * \brief Search list for nth occurrence of specific header.</span><br><span> */</span><br><span> static pjsip_hdr *find_header(struct hdr_list *list, const char *header_name,</span><br><span>@@ -270,7 +395,7 @@</span><br><span> </span><br><span> /*!</span><br><span> * \internal</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief Implements PJSIP_HEADERS by searching for the requested header prefix.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Implements PJSIP_HEADERS/PJSIP_RESPONSE_HEADERS by searching for the requested header prefix.</span><br><span> *</span><br><span> * Retrieve the header_datastore.</span><br><span> * Search for the all matching headers.</span><br><span>@@ -292,7 +417,7 @@</span><br><span> struct hdr_list *list;</span><br><span> </span><br><span> RAII_VAR(struct ast_datastore *, datastore,</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sip_session_get_datastore(data->channel->session, header_datastore.type),</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_get_datastore(data->channel->session, data->header_datastore->type),</span><br><span> ao2_cleanup);</span><br><span> </span><br><span> if (!datastore || !datastore->data) {</span><br><span>@@ -354,10 +479,9 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> /*!</span><br><span> * \internal</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief Implements PJSIP_HEADER 'read' by searching the for the requested header.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Implements PJSIP_HEADER/PJSIP_RESPONSE_HEADER 'read' by searching the for the requested header.</span><br><span> *</span><br><span> * Retrieve the header_datastore.</span><br><span> * Search for the nth matching header.</span><br><span>@@ -378,7 +502,7 @@</span><br><span> struct hdr_list *list;</span><br><span> int i = 1;</span><br><span> RAII_VAR(struct ast_datastore *, datastore,</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sip_session_get_datastore(data->channel->session, header_datastore.type),</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_get_datastore(data->channel->session, data->header_datastore->type),</span><br><span> ao2_cleanup);</span><br><span> </span><br><span> if (!datastore || !datastore->data) {</span><br><span>@@ -459,11 +583,11 @@</span><br><span> struct hdr_list *list;</span><br><span> </span><br><span> RAII_VAR(struct ast_datastore *, datastore,</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sip_session_get_datastore(session, header_datastore.type), ao2_cleanup);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_get_datastore(session, data->header_datastore->type), ao2_cleanup);</span><br><span> </span><br><span> if (!datastore) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(datastore = ast_sip_session_alloc_datastore(&header_datastore,</span><br><span style="color: hsl(0, 100%, 40%);">- header_datastore.type))</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(datastore = ast_sip_session_alloc_datastore(data->header_datastore,</span><br><span style="color: hsl(120, 100%, 40%);">+ data->header_datastore->type))</span><br><span> || !(datastore->data = pj_pool_alloc(pool, sizeof(struct hdr_list)))</span><br><span> || ast_sip_session_add_datastore(session, datastore)) {</span><br><span> ast_log(AST_LOG_ERROR, "Unable to create datastore for header functions.\n");</span><br><span>@@ -502,7 +626,7 @@</span><br><span> struct header_data *data = obj;</span><br><span> pjsip_hdr *hdr = NULL;</span><br><span> RAII_VAR(struct ast_datastore *, datastore,</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sip_session_get_datastore(data->channel->session, header_datastore.type),</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_get_datastore(data->channel->session, data->header_datastore->type),</span><br><span> ao2_cleanup);</span><br><span> </span><br><span> if (!datastore || !datastore->data) {</span><br><span>@@ -539,7 +663,7 @@</span><br><span> struct hdr_list_entry *le;</span><br><span> int removed_count = 0;</span><br><span> RAII_VAR(struct ast_datastore *, datastore,</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sip_session_get_datastore(data->channel->session, header_datastore.type),</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_get_datastore(data->channel->session, data->header_datastore->type),</span><br><span> ao2_cleanup);</span><br><span> </span><br><span> if (!datastore || !datastore->data) {</span><br><span>@@ -597,13 +721,47 @@</span><br><span> header_data.header_value = NULL;</span><br><span> header_data.buf = buf;</span><br><span> header_data.len = len;</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.header_datastore = &header_datastore;</span><br><span> </span><br><span> return ast_sip_push_task_wait_serializer(channel->session->serializer, read_headers, &header_data);</span><br><span> </span><br><span> }</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief Implements function 'read' callback.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Read list of unique SIP response headers</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int func_response_read_headers(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_channel_pvt *channel = chan ? ast_channel_tech_pvt(chan) : NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct header_data header_data;</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_DECLARE_APP_ARGS(args,</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_APP_ARG(header_pattern);</span><br><span style="color: hsl(120, 100%, 40%);">+ );</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_STANDARD_APP_ARGS(args, data);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!chan || strncmp(ast_channel_name(chan), "PJSIP/", 6)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "This function requires a PJSIP channel.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</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%);">+ if (ast_strlen_zero(args.header_pattern)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(AST_LOG_ERROR, "This function requires a pattern.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</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%);">+ header_data.channel = channel;</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.header_name = args.header_pattern;</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.header_value = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.buf = buf;</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.len = len;</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.header_datastore = &response_header_datastore;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_sip_push_task_wait_serializer(channel->session->serializer, read_headers, &header_data);</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Implements PJSIP_HEADER function 'read' callback.</span><br><span> *</span><br><span> * Valid actions are 'read' and 'remove'.</span><br><span> */</span><br><span>@@ -645,6 +803,7 @@</span><br><span> header_data.header_value = NULL;</span><br><span> header_data.buf = buf;</span><br><span> header_data.len = len;</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.header_datastore = &header_datastore;</span><br><span> </span><br><span> if (!strcasecmp(args.action, "read")) {</span><br><span> return ast_sip_push_task_wait_serializer(channel->session->serializer, read_header, &header_data);</span><br><span>@@ -660,7 +819,62 @@</span><br><span> }</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief Implements function 'write' callback.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Implements PJSIP_RESPONSE_HEADER function 'read' callback.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Valid actions are 'read'</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int func_response_read_header(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_channel_pvt *channel = chan ? ast_channel_tech_pvt(chan) : NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct header_data header_data;</span><br><span style="color: hsl(120, 100%, 40%);">+ int number;</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_DECLARE_APP_ARGS(args,</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_APP_ARG(action);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_APP_ARG(header_name); AST_APP_ARG(header_number););</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_STANDARD_APP_ARGS(args, data);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!channel || strncmp(ast_channel_name(chan), "PJSIP/", 6)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "This function requires a PJSIP channel.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</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%);">+ if (ast_strlen_zero(args.action)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(AST_LOG_ERROR, "This function requires an action.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(args.header_name)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(AST_LOG_ERROR, "This function requires a header name.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!args.header_number) {</span><br><span style="color: hsl(120, 100%, 40%);">+ number = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ sscanf(args.header_number, "%30d", &number);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (number < 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ number = 1;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.channel = channel;</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.header_name = args.header_name;</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.header_number = number;</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.header_value = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.buf = buf;</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.len = len;</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.header_datastore = &response_header_datastore;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!strcasecmp(args.action, "read")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_sip_push_task_wait_serializer(channel->session->serializer, read_header, &header_data);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(AST_LOG_ERROR,</span><br><span style="color: hsl(120, 100%, 40%);">+ "Unknown action '%s' is not valid, must be 'read'.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ args.action);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Implements PJSIP_HEADER function 'write' callback.</span><br><span> *</span><br><span> * Valid actions are 'add', 'update' and 'remove'.</span><br><span> */</span><br><span>@@ -703,6 +917,7 @@</span><br><span> header_data.header_value = value;</span><br><span> header_data.buf = NULL;</span><br><span> header_data.len = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ header_data.header_datastore = &header_datastore;</span><br><span> </span><br><span> if (!strcasecmp(args.action, "add")) {</span><br><span> return ast_sip_push_task_wait_serializer(channel->session->serializer,</span><br><span>@@ -732,6 +947,16 @@</span><br><span> .read = func_read_headers</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_custom_function pjsip_response_header_function = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .name = "PJSIP_RESPONSE_HEADER",</span><br><span style="color: hsl(120, 100%, 40%);">+ .read = func_response_read_header</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%);">+static struct ast_custom_function pjsip_response_headers_function = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .name = "PJSIP_RESPONSE_HEADERS",</span><br><span style="color: hsl(120, 100%, 40%);">+ .read = func_response_read_headers</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*!</span><br><span> * \internal</span><br><span> * \brief Session supplement callback for outgoing INVITE requests</span><br><span>@@ -768,6 +993,7 @@</span><br><span> .priority = AST_SIP_SUPPLEMENT_PRIORITY_CHANNEL - 1000,</span><br><span> .incoming_request = incoming_request,</span><br><span> .outgoing_request = outgoing_request,</span><br><span style="color: hsl(120, 100%, 40%);">+ .incoming_response = incoming_response,</span><br><span> };</span><br><span> </span><br><span> static int load_module(void)</span><br><span>@@ -775,6 +1001,8 @@</span><br><span> ast_sip_session_register_supplement(&header_funcs_supplement);</span><br><span> ast_custom_function_register(&pjsip_header_function);</span><br><span> ast_custom_function_register(&pjsip_headers_function);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_custom_function_register(&pjsip_response_header_function);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_custom_function_register(&pjsip_response_headers_function);</span><br><span> </span><br><span> return AST_MODULE_LOAD_SUCCESS;</span><br><span> }</span><br><span>@@ -783,6 +1011,8 @@</span><br><span> {</span><br><span> ast_custom_function_unregister(&pjsip_header_function);</span><br><span> ast_custom_function_unregister(&pjsip_headers_function);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_custom_function_unregister(&pjsip_response_header_function);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_custom_function_unregister(&pjsip_response_headers_function);</span><br><span> ast_sip_session_unregister_supplement(&header_funcs_supplement);</span><br><span> return 0;</span><br><span> }</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18736">change 18736</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/+/18736"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I264a610a9333359297a0825feb29a1bb4f4ad144 </div>
<div style="display:none"> Gerrit-Change-Number: 18736 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: José Lopes <jose.lopes@nfon.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>