<p>Kirill Katsnelson has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/6118">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">chan_sip: Access incoming REFER headers in dialplan<br><br>This adds a way to access information passed along with SIP headers in<br>a REFER message that initiates a transfer. Headers matching a dialplan<br>variable GET_TRANSFERRER_DATA in the transferrer channel are added to<br>a HASH object TRANSFER_DATA to be accessed with functions HASHKEY and HASH.<br><br>The variable GET_TRANSFERRER_DATA is interpreted to be a prefix for<br>headers that should be put into the hash. If not set, no headers are<br>included. If set to a string (perhaps 'X-' in a typical case), all headers<br>starting this string are added. Empty string matches all headers.<br><br>If there are multiple of the same header, only the latest occurrence in<br>the REFER message is available in the hash.<br><br>Obviously, the variable GET_TRANSFERRER_DATA must be inherited by the<br>referrer channel, and should be set with the '_' or '__' prefix.<br><br>I avoided a specific reference to SIP or REFER, as in my mind the mechanism<br>can be generalized to other channel techs.<br><br>ASTERISK-27162<br><br>Change-Id: I73d7a1e95981693bc59aa0d5093c074b555f708e<br>---<br>M channels/chan_sip.c<br>1 file 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/18/6118/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/channels/chan_sip.c b/channels/chan_sip.c<br>index f2daf2b..626f220 100644<br>--- a/channels/chan_sip.c<br>+++ b/channels/chan_sip.c<br>@@ -18631,6 +18631,23 @@<br>       return 0;<br> }<br> <br>+static void extract_transferrer_headers(const char *prefix, struct ast_channel *peer, const struct sip_request *req)<br>+{<br>+  int i;<br>+       for (i = 0; i < req->headers; i++) {<br>+           const char *header = REQ_OFFSET_TO_STR(req, header[i]);<br>+              if (ast_begins_with(header, prefix)) {<br>+                       int hdrlen = strcspn(header, " \t:");<br>+                      const char *val = ast_skip_blanks(header + hdrlen);<br>+                  if (*val == ':') {<br>+                           struct ast_str *pbxvar = ast_str_alloca(50);<br>+                         ast_str_set(&pbxvar, -1, "~HASH~TRANSFER_DATA~%.*s~", hdrlen, header);<br>+                         pbx_builtin_setvar_helper(peer, ast_str_buffer(pbxvar), ast_skip_blanks(val + 1));<br>+                   }<br>+            }<br>+    }<br>+}<br>+<br> /*! \brief Call transfer support (the REFER method)<br>  *     Extracts Refer headers into pvt dialog structure<br>  *<br>@@ -18693,10 +18710,18 @@<br> <br>           peer = ast_channel_bridge_peer(owner_ref);<br>            if (peer) {<br>+                  const char *get_xfrdata;<br>+<br>                   pbx_builtin_setvar_helper(peer, "SIPREFERRINGCONTEXT",<br>                              S_OR(transferer->context, NULL));<br>                  pbx_builtin_setvar_helper(peer, "__SIPREFERREDBYHDR",<br>                               S_OR(p_referred_by, NULL));<br>+<br>+                       ast_channel_lock(peer);<br>+                      get_xfrdata = pbx_builtin_getvar_helper(peer, "GET_TRANSFERRER_DATA");<br>+                     if (get_xfrdata != NULL) {<br>+                           extract_transferrer_headers(get_xfrdata, peer, req);<br>+                 }<br>                     ast_channel_unlock(peer);<br>             }<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/6118">change 6118</a>. To unsubscribe, 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/6118"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I73d7a1e95981693bc59aa0d5093c074b555f708e </div>
<div style="display:none"> Gerrit-Change-Number: 6118 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Kirill Katsnelson <kkm@smartaction.com> </div>