Asterisk func sipchaninfo

Synopsis:

Gets the specified SIP parameter from the current channel

Deprecation

SIPCHANINFO() is deprecated in 1.6. Use CHANNEL.

Description:

SIPCHANINFO(item)

Valid items are:
  • peerip: The IP address of the peer.
  • recvip: The source IP address of the peer.
  • from: The URI from the From: header.
  • uri : The URI from the Contact: header.
  • useragent: The useragent.
  • peername: The name of the peer.


Notes


  • *CLI> show function SIPCHANINFO

Return value

Returns the resulting string.

Example

exten => s,1,Set(foo=${SIPCHANINFO(peername)})

Remarks

Following is an user-submitted code,not official digium/asterisk information

Adding Custom fields to function
In the dialplan, we needed to retrieve the codec used for the channel in progress. Though it was possible via a tweak by grepping the status Manager "sip show channels" and extracting the output, it wasn't a good solution.So, we proceed to change the sipchaninfo code to include the codec as well:

Note: This patch is not necessary as the CHANNEL() function already presents the format (=codec) information nowadays.

Filename: channels/chan_sip.c

http://www.asterisk.org/doxygen/1.2/chansip_8c.html#b51bdb11155c99496e7286153da6f813

/*! \brief function_sipchaninfo_read: ${SIPCHANINFO()} Dialplan function - reads sip channel data */
static char *function_sipchaninfo_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
...
...
if (!strcasecmp(data, "peerip")) {
17151 ast_copy_string(buf, p->sa.sin_addr.s_addr ? ast_inet_ntoa(p->sa.sin_addr) : "", len);
17152 } else if (!strcasecmp(data, "recvip")) {
17153 ast_copy_string(buf, p->recv.sin_addr.s_addr ? ast_inet_ntoa(p->recv.sin_addr) : "", len);
17154 } else if (!strcasecmp(data, "from")) {
17155 ast_copy_string(buf, p->from, len);
17156 } else if (!strcasecmp(data, "uri")) {
17157 ast_copy_string(buf, p->uri, len);
17158 } else if (!strcasecmp(data, "useragent")) {
17159 ast_copy_string(buf, p->useragent, len);
17160 } else if (!strcasecmp(data, "peername")) {
17161 ast_copy_string(buf, p->peername, len);
17162 } else if (!strcasecmp(data, "codec")) {
ast_copy_string(buf, ast_getformatname(p->owner ? p->owner->nativeformats : 0),len);
}


Essentially, what you do is do a simple call over existant channel's various attributes present in sip_pvt structure. http://www.asterisk.org/doxygen/1.2/structsippvt.html

See also



Synopsis:

Gets the specified SIP parameter from the current channel

Deprecation

SIPCHANINFO() is deprecated in 1.6. Use CHANNEL.

Description:

SIPCHANINFO(item)

Valid items are:
  • peerip: The IP address of the peer.
  • recvip: The source IP address of the peer.
  • from: The URI from the From: header.
  • uri : The URI from the Contact: header.
  • useragent: The useragent.
  • peername: The name of the peer.


Notes


  • *CLI> show function SIPCHANINFO

Return value

Returns the resulting string.

Example

exten => s,1,Set(foo=${SIPCHANINFO(peername)})

Remarks

Following is an user-submitted code,not official digium/asterisk information

Adding Custom fields to function
In the dialplan, we needed to retrieve the codec used for the channel in progress. Though it was possible via a tweak by grepping the status Manager "sip show channels" and extracting the output, it wasn't a good solution.So, we proceed to change the sipchaninfo code to include the codec as well:

Note: This patch is not necessary as the CHANNEL() function already presents the format (=codec) information nowadays.

Filename: channels/chan_sip.c

http://www.asterisk.org/doxygen/1.2/chansip_8c.html#b51bdb11155c99496e7286153da6f813

/*! \brief function_sipchaninfo_read: ${SIPCHANINFO()} Dialplan function - reads sip channel data */
static char *function_sipchaninfo_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
...
...
if (!strcasecmp(data, "peerip")) {
17151 ast_copy_string(buf, p->sa.sin_addr.s_addr ? ast_inet_ntoa(p->sa.sin_addr) : "", len);
17152 } else if (!strcasecmp(data, "recvip")) {
17153 ast_copy_string(buf, p->recv.sin_addr.s_addr ? ast_inet_ntoa(p->recv.sin_addr) : "", len);
17154 } else if (!strcasecmp(data, "from")) {
17155 ast_copy_string(buf, p->from, len);
17156 } else if (!strcasecmp(data, "uri")) {
17157 ast_copy_string(buf, p->uri, len);
17158 } else if (!strcasecmp(data, "useragent")) {
17159 ast_copy_string(buf, p->useragent, len);
17160 } else if (!strcasecmp(data, "peername")) {
17161 ast_copy_string(buf, p->peername, len);
17162 } else if (!strcasecmp(data, "codec")) {
ast_copy_string(buf, ast_getformatname(p->owner ? p->owner->nativeformats : 0),len);
}


Essentially, what you do is do a simple call over existant channel's various attributes present in sip_pvt structure. http://www.asterisk.org/doxygen/1.2/structsippvt.html

See also



Created by: murf, Last modification: Wed 30 of Jun, 2010 (03:20 UTC) by JustRumours
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+