[Asterisk-code-review] chan sip: Access incoming REFER headers in dialplan (asterisk[master])

Kirill Katsnelson asteriskteam at digium.com
Sat Jul 29 21:07:16 CDT 2017


Kirill Katsnelson has uploaded this change for review. ( https://gerrit.asterisk.org/6118


Change subject: chan_sip: Access incoming REFER headers in dialplan
......................................................................

chan_sip: Access incoming REFER headers in dialplan

This adds a way to access information passed along with SIP headers in
a REFER message that initiates a transfer. Headers matching a dialplan
variable GET_TRANSFERRER_DATA in the transferrer channel are added to
a HASH object TRANSFER_DATA to be accessed with functions HASHKEY and HASH.

The variable GET_TRANSFERRER_DATA is interpreted to be a prefix for
headers that should be put into the hash. If not set, no headers are
included. If set to a string (perhaps 'X-' in a typical case), all headers
starting this string are added. Empty string matches all headers.

If there are multiple of the same header, only the latest occurrence in
the REFER message is available in the hash.

Obviously, the variable GET_TRANSFERRER_DATA must be inherited by the
referrer channel, and should be set with the '_' or '__' prefix.

I avoided a specific reference to SIP or REFER, as in my mind the mechanism
can be generalized to other channel techs.

ASTERISK-27162

Change-Id: I73d7a1e95981693bc59aa0d5093c074b555f708e
---
M channels/chan_sip.c
1 file changed, 25 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/18/6118/1

diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index f2daf2b..626f220 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -18631,6 +18631,23 @@
 	return 0;
 }
 
+static void extract_transferrer_headers(const char *prefix, struct ast_channel *peer, const struct sip_request *req)
+{
+	int i;
+	for (i = 0; i < req->headers; i++) {
+		const char *header = REQ_OFFSET_TO_STR(req, header[i]);
+		if (ast_begins_with(header, prefix)) {
+			int hdrlen = strcspn(header, " \t:");
+			const char *val = ast_skip_blanks(header + hdrlen);
+			if (*val == ':') {
+				struct ast_str *pbxvar = ast_str_alloca(50);
+				ast_str_set(&pbxvar, -1, "~HASH~TRANSFER_DATA~%.*s~", hdrlen, header);
+				pbx_builtin_setvar_helper(peer, ast_str_buffer(pbxvar), ast_skip_blanks(val + 1));
+			}
+		}
+	}
+}
+
 /*! \brief Call transfer support (the REFER method)
  * 	Extracts Refer headers into pvt dialog structure
  *
@@ -18693,10 +18710,18 @@
 
 		peer = ast_channel_bridge_peer(owner_ref);
 		if (peer) {
+			const char *get_xfrdata;
+
 			pbx_builtin_setvar_helper(peer, "SIPREFERRINGCONTEXT",
 				S_OR(transferer->context, NULL));
 			pbx_builtin_setvar_helper(peer, "__SIPREFERREDBYHDR",
 				S_OR(p_referred_by, NULL));
+
+			ast_channel_lock(peer);
+			get_xfrdata = pbx_builtin_getvar_helper(peer, "GET_TRANSFERRER_DATA");
+			if (get_xfrdata != NULL) {
+				extract_transferrer_headers(get_xfrdata, peer, req);
+			}
 			ast_channel_unlock(peer);
 		}
 

-- 
To view, visit https://gerrit.asterisk.org/6118
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I73d7a1e95981693bc59aa0d5093c074b555f708e
Gerrit-Change-Number: 6118
Gerrit-PatchSet: 1
Gerrit-Owner: Kirill Katsnelson <kkm at smartaction.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20170729/5938eeef/attachment.html>


More information about the asterisk-code-review mailing list