aboutsummaryrefslogtreecommitdiffstats
path: root/channels
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-12-02 23:51:10 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-12-02 23:51:10 +0000
commit1fd5fcef34bd10630db249bf17a75fa8365c4a84 (patch)
treee280b816a04008b79cea59f3fda62740653fe99a /channels
parent2fbcd440b8c3c050f834528667cdcbb789ef26a2 (diff)
Add nasty sip get header, too (bug #2838)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@4374 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rwxr-xr-xchannels/chan_sip.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 41ff1eca2..02bafe167 100755
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -9004,6 +9004,16 @@ static char *descrip_sipaddheader = ""
"Adding the wrong headers may jeopardize the SIP dialog.\n"
"Always returns 0\n";
+static char *app_sipgetheader = "SIPGetHeader";
+static char *synopsis_sipgetheader = "Get a SIP header from an incoming call";
+
+static char *descrip_sipgetheader = ""
+" SIPGetHeader(var=headername): \n"
+"Sets a channel variable to the content of a SIP header\n"
+"Skips to priority+101 if header does not exist\n"
+"Otherwise returns 0\n";
+
+
/*--- sip_dtmfmode: change the DTMFmode for a SIP call (application) ---*/
static int sip_dtmfmode(struct ast_channel *chan, void *data)
{
@@ -9090,6 +9100,50 @@ static int sip_addheader(struct ast_channel *chan, void *data)
return 0;
}
+
+/*--- sip_getheader: Get a SIP header (dialplan app) ---*/
+static int sip_getheader(struct ast_channel *chan, void *data)
+{
+ struct sip_pvt *p;
+ char *argv, *varname = NULL, *header = NULL, *content;
+
+ argv = strdupa(data);
+ if (!argv) {
+ ast_log(LOG_DEBUG, "Memory allocation failed\n");
+ return 0;
+ }
+
+ if (strchr (argv, '=') ) { /* Pick out argumenet */
+ varname = strsep (&argv, "=");
+ header = strsep (&argv, "\0");
+ }
+
+ if (!varname || !header) {
+ ast_log(LOG_DEBUG, "SipGetHeader: Ignoring command, Syntax error in argument\n");
+ return 0;
+ }
+
+ ast_mutex_lock(&chan->lock);
+ if (chan->type != type) {
+ ast_log(LOG_WARNING, "Call this application only on incoming SIP calls\n");
+ ast_mutex_unlock(&chan->lock);
+ return 0;
+ }
+
+ p = chan->pvt->pvt;
+ content = get_header(&p->initreq, header); /* Get the header */
+ if (!ast_strlen_zero(content)) {
+ pbx_builtin_setvar_helper(chan, varname, content);
+ } else {
+ ast_log(LOG_WARNING,"SIP Header %s not found for channel variable %s\n", header, varname);
+ if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num))
+ chan->priority += 100;
+ }
+
+ ast_mutex_unlock(&chan->lock);
+ return 0;
+}
+
static int sip_get_codec(struct ast_channel *chan)
{
struct sip_pvt *p = chan->pvt->pvt;
@@ -9265,6 +9319,7 @@ int load_module()
ast_rtp_proto_register(&sip_rtp);
ast_register_application(app_dtmfmode, sip_dtmfmode, synopsis_dtmfmode, descrip_dtmfmode);
ast_register_application(app_sipaddheader, sip_addheader, synopsis_sipaddheader, descrip_sipaddheader);
+ ast_register_application(app_sipgetheader, sip_getheader, synopsis_sipgetheader, descrip_sipgetheader);
ast_mutex_lock(&peerl.lock);
for (peer = peerl.peers; peer; peer = peer->next)
sip_poke_peer(peer);
@@ -9288,6 +9343,7 @@ int unload_module()
/* First, take us out of the channel loop */
ast_unregister_application(app_dtmfmode);
ast_unregister_application(app_sipaddheader);
+ ast_unregister_application(app_sipgetheader);
ast_cli_unregister(&cli_show_users);
ast_cli_unregister(&cli_show_channels);
ast_cli_unregister(&cli_show_channel);