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"
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) |
| void | sip_dialplan_function_register_tests (void) |
| SIP test registration. | |
| void | sip_dialplan_function_unregister_tests (void) |
| SIP test registration. | |
sip channel dialplan functions and unit tests
Definition in file dialplan_functions.c.
| int sip_acf_channel_read | ( | struct ast_channel * | chan, |
| const char * | funcname, | ||
| char * | preparse, | ||
| char * | buf, | ||
| size_t | buflen | ||
| ) |
Definition at line 44 of file 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_STANDARD_APP_ARGS, ast_strlen_zero(), 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, parse(), 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, ast_rtp_instance_stats::rtt, ast_rtp_instance_stats::rxcount, ast_rtp_instance_stats::rxjitter, ast_rtp_instance_stats::rxploss, ast_rtp_instance_stats::stdevrtt, ast_rtp_instance_stats::txcount, ast_rtp_instance_stats::txjitter, ast_rtp_instance_stats::txploss, and type.
{
struct sip_pvt *p = ast_channel_tech_pvt(chan);
char *parse = ast_strdupa(preparse);
int res = 0;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(param);
AST_APP_ARG(type);
AST_APP_ARG(field);
);
/* Check for zero arguments */
if (ast_strlen_zero(parse)) {
ast_log(LOG_ERROR, "Cannot call %s without arguments\n", funcname);
return -1;
}
AST_STANDARD_APP_ARGS(args, parse);
/* Sanity check */
if (!IS_SIP_TECH(ast_channel_tech(chan))) {
ast_log(LOG_ERROR, "Cannot call %s on a non-SIP channel\n", funcname);
return 0;
}
memset(buf, 0, buflen);
if (p == NULL) {
return -1;
}
if (!strcasecmp(args.param, "peerip")) {
ast_copy_string(buf, ast_sockaddr_isnull(&p->sa) ? "" : ast_sockaddr_stringify_addr(&p->sa), buflen);
} else if (!strcasecmp(args.param, "recvip")) {
ast_copy_string(buf, ast_sockaddr_isnull(&p->recv) ? "" : ast_sockaddr_stringify_addr(&p->recv), buflen);
} else if (!strcasecmp(args.param, "from")) {
ast_copy_string(buf, p->from, buflen);
} else if (!strcasecmp(args.param, "uri")) {
ast_copy_string(buf, p->uri, buflen);
} else if (!strcasecmp(args.param, "useragent")) {
ast_copy_string(buf, p->useragent, buflen);
} else if (!strcasecmp(args.param, "peername")) {
ast_copy_string(buf, p->peername, buflen);
} else if (!strcasecmp(args.param, "t38passthrough")) {
ast_copy_string(buf, (p->t38.state == T38_DISABLED) ? "0" : "1", buflen);
} else if (!strcasecmp(args.param, "rtpdest")) {
struct ast_sockaddr addr;
struct ast_rtp_instance *stream;
if (ast_strlen_zero(args.type))
args.type = "audio";
if (!strcasecmp(args.type, "audio"))
stream = p->rtp;
else if (!strcasecmp(args.type, "video"))
stream = p->vrtp;
else if (!strcasecmp(args.type, "text"))
stream = p->trtp;
else
return -1;
/* Return 0 to suppress a console warning message */
if (!stream) {
return 0;
}
ast_rtp_instance_get_remote_address(stream, &addr);
snprintf(buf, buflen, "%s", ast_sockaddr_stringify(&addr));
} else if (!strcasecmp(args.param, "rtpsource")) {
struct ast_sockaddr sa;
struct ast_rtp_instance *stream;
if (ast_strlen_zero(args.type))
args.type = "audio";
if (!strcasecmp(args.type, "audio"))
stream = p->rtp;
else if (!strcasecmp(args.type, "video"))
stream = p->vrtp;
else if (!strcasecmp(args.type, "text"))
stream = p->trtp;
else
return -1;
/* Return 0 to suppress a console warning message */
if (!stream) {
return 0;
}
ast_rtp_instance_get_local_address(stream, &sa);
if (ast_sockaddr_isnull(&sa)) {
struct ast_sockaddr dest_sa;
ast_rtp_instance_get_remote_address(stream, &dest_sa);
ast_ouraddrfor(&dest_sa, &sa);
}
snprintf(buf, buflen, "%s", ast_sockaddr_stringify(&sa));
} else if (!strcasecmp(args.param, "rtpqos")) {
struct ast_rtp_instance *rtp = NULL;
if (ast_strlen_zero(args.type)) {
args.type = "audio";
}
if (!strcasecmp(args.type, "audio")) {
rtp = p->rtp;
} else if (!strcasecmp(args.type, "video")) {
rtp = p->vrtp;
} else if (!strcasecmp(args.type, "text")) {
rtp = p->trtp;
} else {
return -1;
}
if (ast_strlen_zero(args.field) || !strcasecmp(args.field, "all")) {
char quality_buf[AST_MAX_USER_FIELD];
if (!ast_rtp_instance_get_quality(rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf))) {
return -1;
}
ast_copy_string(buf, quality_buf, buflen);
return res;
} else {
struct ast_rtp_instance_stats stats;
int i;
struct {
const char *name;
enum { INT, DBL } type;
union {
unsigned int *i4;
double *d8;
};
} lookup[] = {
{ "txcount", INT, { .i4 = &stats.txcount, }, },
{ "rxcount", INT, { .i4 = &stats.rxcount, }, },
{ "txjitter", DBL, { .d8 = &stats.txjitter, }, },
{ "rxjitter", DBL, { .d8 = &stats.rxjitter, }, },
{ "remote_maxjitter", DBL, { .d8 = &stats.remote_maxjitter, }, },
{ "remote_minjitter", DBL, { .d8 = &stats.remote_minjitter, }, },
{ "remote_normdevjitter", DBL, { .d8 = &stats.remote_normdevjitter, }, },
{ "remote_stdevjitter", DBL, { .d8 = &stats.remote_stdevjitter, }, },
{ "local_maxjitter", DBL, { .d8 = &stats.local_maxjitter, }, },
{ "local_minjitter", DBL, { .d8 = &stats.local_minjitter, }, },
{ "local_normdevjitter", DBL, { .d8 = &stats.local_normdevjitter, }, },
{ "local_stdevjitter", DBL, { .d8 = &stats.local_stdevjitter, }, },
{ "txploss", INT, { .i4 = &stats.txploss, }, },
{ "rxploss", INT, { .i4 = &stats.rxploss, }, },
{ "remote_maxrxploss", DBL, { .d8 = &stats.remote_maxrxploss, }, },
{ "remote_minrxploss", DBL, { .d8 = &stats.remote_minrxploss, }, },
{ "remote_normdevrxploss", DBL, { .d8 = &stats.remote_normdevrxploss, }, },
{ "remote_stdevrxploss", DBL, { .d8 = &stats.remote_stdevrxploss, }, },
{ "local_maxrxploss", DBL, { .d8 = &stats.local_maxrxploss, }, },
{ "local_minrxploss", DBL, { .d8 = &stats.local_minrxploss, }, },
{ "local_normdevrxploss", DBL, { .d8 = &stats.local_normdevrxploss, }, },
{ "local_stdevrxploss", DBL, { .d8 = &stats.local_stdevrxploss, }, },
{ "rtt", DBL, { .d8 = &stats.rtt, }, },
{ "maxrtt", DBL, { .d8 = &stats.maxrtt, }, },
{ "minrtt", DBL, { .d8 = &stats.minrtt, }, },
{ "normdevrtt", DBL, { .d8 = &stats.normdevrtt, }, },
{ "stdevrtt", DBL, { .d8 = &stats.stdevrtt, }, },
{ "local_ssrc", INT, { .i4 = &stats.local_ssrc, }, },
{ "remote_ssrc", INT, { .i4 = &stats.remote_ssrc, }, },
{ NULL, },
};
if (ast_rtp_instance_get_stats(rtp, &stats, AST_RTP_INSTANCE_STAT_ALL)) {
return -1;
}
for (i = 0; !ast_strlen_zero(lookup[i].name); i++) {
if (!strcasecmp(args.field, lookup[i].name)) {
if (lookup[i].type == INT) {
snprintf(buf, buflen, "%u", *lookup[i].i4);
} else {
snprintf(buf, buflen, "%f", *lookup[i].d8);
}
return 0;
}
}
ast_log(LOG_WARNING, "Unrecognized argument '%s' to %s\n", preparse, funcname);
return -1;
}
} else if (!strcasecmp(args.param, "secure_signaling")) {
snprintf(buf, buflen, "%s", p->socket.type == SIP_TRANSPORT_TLS ? "1" : "");
} else if (!strcasecmp(args.param, "secure_media")) {
snprintf(buf, buflen, "%s", p->srtp ? "1" : "");
} else {
res = -1;
}
return res;
}
| void sip_dialplan_function_register_tests | ( | void | ) |
SIP test registration.
Definition at line 411 of file dialplan_functions.c.
References AST_TEST_REGISTER.
Referenced by sip_register_tests().
{
AST_TEST_REGISTER(test_sip_rtpqos_1);
}
| void sip_dialplan_function_unregister_tests | ( | void | ) |
SIP test registration.
Definition at line 417 of file dialplan_functions.c.
References AST_TEST_UNREGISTER.
Referenced by sip_unregister_tests().
{
AST_TEST_UNREGISTER(test_sip_rtpqos_1);
}