sip/dialplan_functions.c File Reference

sip channel dialplan functions and unit tests More...

#include "asterisk.h"
#include <math.h>
#include "asterisk/channel.h"
#include "asterisk/rtp_engine.h"
#include "asterisk/pbx.h"
#include "asterisk/acl.h"
#include "include/sip.h"
#include "include/globals.h"
#include "include/dialog.h"
#include "include/dialplan_functions.h"
#include "include/sip_utils.h"

Include dependency graph for sip/dialplan_functions.c:

Go to the source code of this file.

Functions

int sip_acf_channel_read (struct ast_channel *chan, const char *funcname, char *preparse, char *buf, size_t buflen)
 Channel read dialplan function for SIP.
void sip_dialplan_function_register_tests (void)
 SIP test registration.
void sip_dialplan_function_unregister_tests (void)
 SIP test registration.


Detailed Description

sip channel dialplan functions and unit tests

Definition in file sip/dialplan_functions.c.


Function Documentation

int sip_acf_channel_read ( struct ast_channel chan,
const char *  funcname,
char *  preparse,
char *  buf,
size_t  buflen 
)

Channel read dialplan function for SIP.

Definition at line 44 of file sip/dialplan_functions.c.

References args, AST_APP_ARG, ast_channel_tech(), ast_channel_tech_pvt(), ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log, AST_MAX_USER_FIELD, ast_ouraddrfor(), ast_rtp_instance_get_local_address(), ast_rtp_instance_get_quality(), ast_rtp_instance_get_remote_address, ast_rtp_instance_get_stats(), AST_RTP_INSTANCE_STAT_ALL, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, ast_sockaddr_isnull(), ast_sockaddr_stringify(), ast_sockaddr_stringify_addr(), ast_sockaddr_stringify_port(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero, AST_TRANSPORT_TLS, sip_pvt::from, IS_SIP_TECH, ast_rtp_instance_stats::local_maxjitter, ast_rtp_instance_stats::local_maxrxploss, ast_rtp_instance_stats::local_minjitter, ast_rtp_instance_stats::local_minrxploss, ast_rtp_instance_stats::local_normdevjitter, ast_rtp_instance_stats::local_normdevrxploss, ast_rtp_instance_stats::local_ssrc, ast_rtp_instance_stats::local_stdevjitter, ast_rtp_instance_stats::local_stdevrxploss, LOG_ERROR, LOG_WARNING, ast_rtp_instance_stats::maxrtt, ast_rtp_instance_stats::minrtt, name, ast_rtp_instance_stats::normdevrtt, NULL, parse(), sip_pvt::peername, sip_pvt::recv, ast_rtp_instance_stats::remote_maxjitter, ast_rtp_instance_stats::remote_maxrxploss, ast_rtp_instance_stats::remote_minjitter, ast_rtp_instance_stats::remote_minrxploss, ast_rtp_instance_stats::remote_normdevjitter, ast_rtp_instance_stats::remote_normdevrxploss, ast_rtp_instance_stats::remote_ssrc, ast_rtp_instance_stats::remote_stdevjitter, ast_rtp_instance_stats::remote_stdevrxploss, sip_pvt::rtp, ast_rtp_instance_stats::rtt, ast_rtp_instance_stats::rxcount, ast_rtp_instance_stats::rxjitter, ast_rtp_instance_stats::rxploss, sip_pvt::sa, sip_pvt::socket, sip_pvt::srtp, t38properties::state, ast_rtp_instance_stats::stdevrtt, sip_pvt::t38, T38_DISABLED, sip_pvt::trtp, ast_rtp_instance_stats::txcount, ast_rtp_instance_stats::txjitter, ast_rtp_instance_stats::txploss, sip_socket::type, type, sip_pvt::uri, sip_pvt::useragent, and sip_pvt::vrtp.

00045 {
00046    struct sip_pvt *p = ast_channel_tech_pvt(chan);
00047    char *parse = ast_strdupa(preparse);
00048    int res = 0;
00049    AST_DECLARE_APP_ARGS(args,
00050       AST_APP_ARG(param);
00051       AST_APP_ARG(type);
00052       AST_APP_ARG(field);
00053    );
00054       
00055    /* Check for zero arguments */
00056    if (ast_strlen_zero(parse)) {
00057       ast_log(LOG_ERROR, "Cannot call %s without arguments\n", funcname);
00058       return -1;
00059    }
00060 
00061    AST_STANDARD_APP_ARGS(args, parse);
00062 
00063    /* Sanity check */
00064    if (!IS_SIP_TECH(ast_channel_tech(chan))) {
00065       ast_log(LOG_ERROR, "Cannot call %s on a non-SIP channel\n", funcname);
00066       return 0;
00067    }
00068 
00069    memset(buf, 0, buflen);
00070 
00071    if (p == NULL) {
00072       return -1;
00073    }
00074 
00075    if (!strcasecmp(args.param, "peerip")) {
00076       ast_copy_string(buf, ast_sockaddr_isnull(&p->sa) ? "" : ast_sockaddr_stringify_addr(&p->sa), buflen);
00077    } else if (!strcasecmp(args.param, "recvip")) {
00078       ast_copy_string(buf, ast_sockaddr_isnull(&p->recv) ? "" : ast_sockaddr_stringify_addr(&p->recv), buflen);
00079    } else if (!strcasecmp(args.param, "recvport")) {
00080       ast_copy_string(buf, ast_sockaddr_isnull(&p->recv) ? "" : ast_sockaddr_stringify_port(&p->recv), buflen);
00081    } else if (!strcasecmp(args.param, "from")) {
00082       ast_copy_string(buf, p->from, buflen);
00083    } else if (!strcasecmp(args.param, "uri")) {
00084       ast_copy_string(buf, p->uri, buflen);
00085    } else if (!strcasecmp(args.param, "useragent")) {
00086       ast_copy_string(buf, p->useragent, buflen);
00087    } else if (!strcasecmp(args.param, "peername")) {
00088       ast_copy_string(buf, p->peername, buflen);
00089    } else if (!strcasecmp(args.param, "t38passthrough")) {
00090       ast_copy_string(buf, (p->t38.state == T38_DISABLED) ? "0" : "1", buflen);
00091    } else if (!strcasecmp(args.param, "rtpdest")) {
00092       struct ast_sockaddr addr;
00093       struct ast_rtp_instance *stream;
00094 
00095       if (ast_strlen_zero(args.type))
00096          args.type = "audio";
00097 
00098       if (!strcasecmp(args.type, "audio"))
00099          stream = p->rtp;
00100       else if (!strcasecmp(args.type, "video"))
00101          stream = p->vrtp;
00102       else if (!strcasecmp(args.type, "text"))
00103          stream = p->trtp;
00104       else
00105          return -1;
00106 
00107       /* Return 0 to suppress a console warning message */
00108       if (!stream) {
00109          return 0;
00110       }
00111 
00112       ast_rtp_instance_get_remote_address(stream, &addr);
00113       snprintf(buf, buflen, "%s", ast_sockaddr_stringify(&addr));
00114    } else if (!strcasecmp(args.param, "rtpsource")) {
00115       struct ast_sockaddr sa;
00116       struct ast_rtp_instance *stream;
00117 
00118       if (ast_strlen_zero(args.type))
00119          args.type = "audio";
00120 
00121       if (!strcasecmp(args.type, "audio"))
00122          stream = p->rtp;
00123       else if (!strcasecmp(args.type, "video"))
00124          stream = p->vrtp;
00125       else if (!strcasecmp(args.type, "text"))
00126          stream = p->trtp;
00127       else
00128          return -1;
00129 
00130       /* Return 0 to suppress a console warning message */
00131       if (!stream) {
00132          return 0;
00133       }
00134 
00135       ast_rtp_instance_get_local_address(stream, &sa);
00136 
00137       if (ast_sockaddr_isnull(&sa)) {
00138          struct ast_sockaddr dest_sa;
00139          ast_rtp_instance_get_remote_address(stream, &dest_sa);
00140          ast_ouraddrfor(&dest_sa, &sa);
00141       }
00142 
00143       snprintf(buf, buflen, "%s", ast_sockaddr_stringify(&sa));
00144    } else if (!strcasecmp(args.param, "rtpqos")) {
00145       struct ast_rtp_instance *rtp = NULL;
00146 
00147       if (ast_strlen_zero(args.type)) {
00148          args.type = "audio";
00149       }
00150 
00151       if (!strcasecmp(args.type, "audio")) {
00152          rtp = p->rtp;
00153       } else if (!strcasecmp(args.type, "video")) {
00154          rtp = p->vrtp;
00155       } else if (!strcasecmp(args.type, "text")) {
00156          rtp = p->trtp;
00157       } else {
00158          return -1;
00159       }
00160 
00161       if (ast_strlen_zero(args.field) || !strcasecmp(args.field, "all")) {
00162          char quality_buf[AST_MAX_USER_FIELD];
00163 
00164          if (!ast_rtp_instance_get_quality(rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf))) {
00165             return -1;
00166          }
00167 
00168          ast_copy_string(buf, quality_buf, buflen);
00169          return res;
00170       } else {
00171          struct ast_rtp_instance_stats stats;
00172          int i;
00173          struct {
00174             const char *name;
00175             enum { INT, DBL } type;
00176             union {
00177                unsigned int *i4;
00178                double *d8;
00179             };
00180          } lookup[] = {
00181             { "txcount",               INT, { .i4 = &stats.txcount, }, },
00182             { "rxcount",               INT, { .i4 = &stats.rxcount, }, },
00183             { "txjitter",              DBL, { .d8 = &stats.txjitter, }, },
00184             { "rxjitter",              DBL, { .d8 = &stats.rxjitter, }, },
00185             { "remote_maxjitter",      DBL, { .d8 = &stats.remote_maxjitter, }, },
00186             { "remote_minjitter",      DBL, { .d8 = &stats.remote_minjitter, }, },
00187             { "remote_normdevjitter",  DBL, { .d8 = &stats.remote_normdevjitter, }, },
00188             { "remote_stdevjitter",    DBL, { .d8 = &stats.remote_stdevjitter, }, },
00189             { "local_maxjitter",       DBL, { .d8 = &stats.local_maxjitter, }, },
00190             { "local_minjitter",       DBL, { .d8 = &stats.local_minjitter, }, },
00191             { "local_normdevjitter",   DBL, { .d8 = &stats.local_normdevjitter, }, },
00192             { "local_stdevjitter",     DBL, { .d8 = &stats.local_stdevjitter, }, },
00193             { "txploss",               INT, { .i4 = &stats.txploss, }, },
00194             { "rxploss",               INT, { .i4 = &stats.rxploss, }, },
00195             { "remote_maxrxploss",     DBL, { .d8 = &stats.remote_maxrxploss, }, },
00196             { "remote_minrxploss",     DBL, { .d8 = &stats.remote_minrxploss, }, },
00197             { "remote_normdevrxploss", DBL, { .d8 = &stats.remote_normdevrxploss, }, },
00198             { "remote_stdevrxploss",   DBL, { .d8 = &stats.remote_stdevrxploss, }, },
00199             { "local_maxrxploss",      DBL, { .d8 = &stats.local_maxrxploss, }, },
00200             { "local_minrxploss",      DBL, { .d8 = &stats.local_minrxploss, }, },
00201             { "local_normdevrxploss",  DBL, { .d8 = &stats.local_normdevrxploss, }, },
00202             { "local_stdevrxploss",    DBL, { .d8 = &stats.local_stdevrxploss, }, },
00203             { "rtt",                   DBL, { .d8 = &stats.rtt, }, },
00204             { "maxrtt",                DBL, { .d8 = &stats.maxrtt, }, },
00205             { "minrtt",                DBL, { .d8 = &stats.minrtt, }, },
00206             { "normdevrtt",            DBL, { .d8 = &stats.normdevrtt, }, },
00207             { "stdevrtt",              DBL, { .d8 = &stats.stdevrtt, }, },
00208             { "local_ssrc",            INT, { .i4 = &stats.local_ssrc, }, },
00209             { "remote_ssrc",           INT, { .i4 = &stats.remote_ssrc, }, },
00210             { NULL, },
00211          };
00212 
00213          if (ast_rtp_instance_get_stats(rtp, &stats, AST_RTP_INSTANCE_STAT_ALL)) {
00214             return -1;
00215          }
00216 
00217          for (i = 0; !ast_strlen_zero(lookup[i].name); i++) {
00218             if (!strcasecmp(args.field, lookup[i].name)) {
00219                if (lookup[i].type == INT) {
00220                   snprintf(buf, buflen, "%u", *lookup[i].i4);
00221                } else {
00222                   snprintf(buf, buflen, "%f", *lookup[i].d8);
00223                }
00224                return 0;
00225             }
00226          }
00227          ast_log(LOG_WARNING, "Unrecognized argument '%s' to %s\n", preparse, funcname);
00228          return -1;
00229       }
00230    } else if (!strcasecmp(args.param, "secure_signaling")) {
00231       snprintf(buf, buflen, "%s", p->socket.type == AST_TRANSPORT_TLS ? "1" : "");
00232    } else if (!strcasecmp(args.param, "secure_media")) {
00233       snprintf(buf, buflen, "%s", p->srtp ? "1" : "");
00234    } else {
00235       res = -1;
00236    }
00237    return res;
00238 }

void sip_dialplan_function_register_tests ( void   ) 

SIP test registration.

register dialplan function tests

Definition at line 413 of file sip/dialplan_functions.c.

References AST_TEST_REGISTER.

Referenced by sip_register_tests().

00414 {
00415    AST_TEST_REGISTER(test_sip_rtpqos_1);
00416 }

void sip_dialplan_function_unregister_tests ( void   ) 

SIP test registration.

unregister dialplan function tests

Definition at line 419 of file sip/dialplan_functions.c.

References AST_TEST_UNREGISTER.

Referenced by sip_unregister_tests().

00420 {
00421    AST_TEST_UNREGISTER(test_sip_rtpqos_1);
00422 }


Generated on Thu Apr 16 06:30:40 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6