Asterisk cmd SIPCallPickup

SIPCallPickup()

Version comments

  • This is not in ANY version of Asterisk. See notes for more info.
  • Patch below developed for Asterisk 1.0.7 with SIPGetHeader patch. (See bug 2838 for patch.)
  • Stability: UNKNOWN Not recommended for a production environment.
  • Developed by: flobi
  • Nearly the same functionality is now available as patch for app_directed_pickup in 1.2 and 1.4: via Digium Bugtracker here: Issue #10404

Synopsis

Intercept a call ringing on a phone in the same callgroup as the current channel.

Description

SIPCallPickup([pickupgroup])

This is an unofficial and barely tested patch to intercept incoming calls from the dialplan instead of the built-in interception that normally occurs before the dialplan is reached in the call flow.

Parameters:
Optional parameter pickupgroup specifies the group to check for an incoming call that should be picked up. If this is omitted, the group specified in sip.conf will be used.

Return codes

Always returns 0.

Notes

I don't actually know C, however, I was faced with a delima that I couldn't find any other way around so I had to write something and I figured I'd share it with you guys. What I've done is taken the general structure of the SIPGetHeader app, copied, renamed and added in the functions that pickup a ringing call. If I had been a C programmer, I probably would have done a better job, but for those in a bind, this might be of some assistance. - flobi

  • You might want to change the pickupexten in the features.conf file if you plan on continuing to use *8 for call pickups.

Install:
In any text editor, open the chan_sip.c insert as follows. With the text below, search for the lines indicated by the label "FIND:" and insert the lines labled "INSERT:" directly below them.

FIND: static char *app_sipgetheader = "SIPGetHeader";
INSERT: static char *app_sipcallpickup = "SIPCallPickup";

FIND: static char *synopsis_sipgetheader = "Get a SIP header from an incoming call";
INSERT:static char *synopsis_sipcallpickup = "Pickup a ringing SIP phone in pickup group.";

FIND: 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";
INSERT: static char *descrip_sipcallpickup = ""
" SIPCallPickup(): \n"
"Pick up a ringing call in the pickup group.\n"
"Skips to priority+101 if call does not exist\n"
"Otherwise returns 0\n";

FIND: static int sip_getheader(struct ast_channel *chan, void *data)
{
struct sip_pvt *p;
char *argv, *varname = (char *) NULL, *header = (char *) NULL, *content;
... truncated ...
ast_mutex_unlock(&chan->lock);
return 0;
}
INSERT: static int sip_callpickup(struct ast_channel *chan, void *data)
{
struct sip_pvt *p;
unsigned int pickupgroup, tmpgroup;

tmpgroup = 0;
pickupgroup = 0;

if (data) {
pickupgroup = ast_get_group(data);
}


if (pickupgroup) {
tmpgroup = chan->pickupgroup;
chan->pickupgroup = pickupgroup;
}

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;

ast_mutex_unlock(&chan->lock);
if (ast_pickup_call(chan)) {
ast_log(LOG_NOTICE, "Nothing to pick up\n");
p->alreadygone = 1;
if (tmpgroup) {
pickupgroup = chan->pickupgroup;
chan->pickupgroup = tmpgroup;
}
return -1;
}

if (tmpgroup) {
pickupgroup = chan->pickupgroup;
chan->pickupgroup = tmpgroup;
}

ast_mutex_unlock(&chan->lock);
return 0;
}

FIND: ast_register_application(app_sipgetheader, sip_getheader, synopsis_sipgetheader, descrip_sipgetheader);
INSERT: ast_register_application(app_sipcallpickup, sip_callpickup, synopsis_sipcallpickup, descrip_sipcallpickup);

FIND: ast_unregister_application(app_sipgetheader);
INSERT: ast_unregister_application(app_sipcallpickup);


After inserting all this into your chan_sip.c file in the channels folder, you are going to have to recompile it. This is easily enough done by deleting the chan_sip.o and chan_sip.so files then execute

make
make install

from the root source directory (/path/to/asterisk-1.0.7/). You are, of course, going to have to restart Asterisk to enable this.

CVS Version

Patched by Alessandro Viganò- Movinfo
There are some changes to do to make it working with cvs version:

FIND: static int sip_getheader(struct ast_channel *chan, void *data)
{
struct sip_pvt *p;
char *argv, *varname = (char *) NULL, *header = (char *) NULL, *content;
... truncated ...
ast_mutex_unlock(&chan->lock);
return 0;
}
INSERT: static int sip_callpickup(struct ast_channel *chan, void *data)
struct sip_pvt *p;
unsigned int pickupgroup, tmpgroup;

tmpgroup = 0;
pickupgroup = 0;

if (data) {
pickupgroup = ast_get_group(data);
}


if (pickupgroup) {
tmpgroup = chan->pickupgroup;
chan->pickupgroup = pickupgroup;
}

ast_mutex_lock(&chan->lock);
if (chan->type != channeltype) {
ast_log(LOG_WARNING, "Call this application only on incoming SIP calls\n");
ast_mutex_unlock(&chan->lock);
return 0;
}

p = chan->tech_pvt;

ast_mutex_unlock(&chan->lock);
if (ast_pickup_call(chan)) {
ast_log(LOG_NOTICE, "Nothing to pick up\n");
ast_set_flag(p, SIP_ALREADYGONE);

if (tmpgroup) {
pickupgroup = chan->pickupgroup;
chan->pickupgroup = tmpgroup;
}

return -1;
}

if (tmpgroup) {
pickupgroup = chan->pickupgroup;
chan->pickupgroup = tmpgroup;
}

ast_mutex_unlock(&chan->lock);
return 0;
}


See also



Asterisk | Configuration | The Dialplan - extensions.conf | Dialplan Commands

SIPCallPickup()

Version comments

  • This is not in ANY version of Asterisk. See notes for more info.
  • Patch below developed for Asterisk 1.0.7 with SIPGetHeader patch. (See bug 2838 for patch.)
  • Stability: UNKNOWN Not recommended for a production environment.
  • Developed by: flobi
  • Nearly the same functionality is now available as patch for app_directed_pickup in 1.2 and 1.4: via Digium Bugtracker here: Issue #10404

Synopsis

Intercept a call ringing on a phone in the same callgroup as the current channel.

Description

SIPCallPickup([pickupgroup])

This is an unofficial and barely tested patch to intercept incoming calls from the dialplan instead of the built-in interception that normally occurs before the dialplan is reached in the call flow.

Parameters:
Optional parameter pickupgroup specifies the group to check for an incoming call that should be picked up. If this is omitted, the group specified in sip.conf will be used.

Return codes

Always returns 0.

Notes

I don't actually know C, however, I was faced with a delima that I couldn't find any other way around so I had to write something and I figured I'd share it with you guys. What I've done is taken the general structure of the SIPGetHeader app, copied, renamed and added in the functions that pickup a ringing call. If I had been a C programmer, I probably would have done a better job, but for those in a bind, this might be of some assistance. - flobi

  • You might want to change the pickupexten in the features.conf file if you plan on continuing to use *8 for call pickups.

Install:
In any text editor, open the chan_sip.c insert as follows. With the text below, search for the lines indicated by the label "FIND:" and insert the lines labled "INSERT:" directly below them.

FIND: static char *app_sipgetheader = "SIPGetHeader";
INSERT: static char *app_sipcallpickup = "SIPCallPickup";

FIND: static char *synopsis_sipgetheader = "Get a SIP header from an incoming call";
INSERT:static char *synopsis_sipcallpickup = "Pickup a ringing SIP phone in pickup group.";

FIND: 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";
INSERT: static char *descrip_sipcallpickup = ""
" SIPCallPickup(): \n"
"Pick up a ringing call in the pickup group.\n"
"Skips to priority+101 if call does not exist\n"
"Otherwise returns 0\n";

FIND: static int sip_getheader(struct ast_channel *chan, void *data)
{
struct sip_pvt *p;
char *argv, *varname = (char *) NULL, *header = (char *) NULL, *content;
... truncated ...
ast_mutex_unlock(&chan->lock);
return 0;
}
INSERT: static int sip_callpickup(struct ast_channel *chan, void *data)
{
struct sip_pvt *p;
unsigned int pickupgroup, tmpgroup;

tmpgroup = 0;
pickupgroup = 0;

if (data) {
pickupgroup = ast_get_group(data);
}


if (pickupgroup) {
tmpgroup = chan->pickupgroup;
chan->pickupgroup = pickupgroup;
}

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;

ast_mutex_unlock(&chan->lock);
if (ast_pickup_call(chan)) {
ast_log(LOG_NOTICE, "Nothing to pick up\n");
p->alreadygone = 1;
if (tmpgroup) {
pickupgroup = chan->pickupgroup;
chan->pickupgroup = tmpgroup;
}
return -1;
}

if (tmpgroup) {
pickupgroup = chan->pickupgroup;
chan->pickupgroup = tmpgroup;
}

ast_mutex_unlock(&chan->lock);
return 0;
}

FIND: ast_register_application(app_sipgetheader, sip_getheader, synopsis_sipgetheader, descrip_sipgetheader);
INSERT: ast_register_application(app_sipcallpickup, sip_callpickup, synopsis_sipcallpickup, descrip_sipcallpickup);

FIND: ast_unregister_application(app_sipgetheader);
INSERT: ast_unregister_application(app_sipcallpickup);


After inserting all this into your chan_sip.c file in the channels folder, you are going to have to recompile it. This is easily enough done by deleting the chan_sip.o and chan_sip.so files then execute

make
make install

from the root source directory (/path/to/asterisk-1.0.7/). You are, of course, going to have to restart Asterisk to enable this.

CVS Version

Patched by Alessandro Viganò- Movinfo
There are some changes to do to make it working with cvs version:

FIND: static int sip_getheader(struct ast_channel *chan, void *data)
{
struct sip_pvt *p;
char *argv, *varname = (char *) NULL, *header = (char *) NULL, *content;
... truncated ...
ast_mutex_unlock(&chan->lock);
return 0;
}
INSERT: static int sip_callpickup(struct ast_channel *chan, void *data)
struct sip_pvt *p;
unsigned int pickupgroup, tmpgroup;

tmpgroup = 0;
pickupgroup = 0;

if (data) {
pickupgroup = ast_get_group(data);
}


if (pickupgroup) {
tmpgroup = chan->pickupgroup;
chan->pickupgroup = pickupgroup;
}

ast_mutex_lock(&chan->lock);
if (chan->type != channeltype) {
ast_log(LOG_WARNING, "Call this application only on incoming SIP calls\n");
ast_mutex_unlock(&chan->lock);
return 0;
}

p = chan->tech_pvt;

ast_mutex_unlock(&chan->lock);
if (ast_pickup_call(chan)) {
ast_log(LOG_NOTICE, "Nothing to pick up\n");
ast_set_flag(p, SIP_ALREADYGONE);

if (tmpgroup) {
pickupgroup = chan->pickupgroup;
chan->pickupgroup = tmpgroup;
}

return -1;
}

if (tmpgroup) {
pickupgroup = chan->pickupgroup;
chan->pickupgroup = tmpgroup;
}

ast_mutex_unlock(&chan->lock);
return 0;
}


See also



Asterisk | Configuration | The Dialplan - extensions.conf | Dialplan Commands
Created by: flobi, Last modification: Wed 08 of Aug, 2007 (14:58 UTC) by fork
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+