chan_sip: Fix a small TEST_FRAMEWORK related error that prevents compiling
[asterisk/asterisk.git] / channels / sip / dialplan_functions.c
index 297f9f5..fd8b04f 100644 (file)
@@ -39,7 +39,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 int sip_acf_channel_read(struct ast_channel *chan, const char *funcname, char *preparse, char *buf, size_t buflen)
 {
-       struct sip_pvt *p = chan->tech_pvt;
+       struct sip_pvt *p = ast_channel_tech_pvt(chan);
        char *parse = ast_strdupa(preparse);
        int res = 0;
        AST_DECLARE_APP_ARGS(args,
@@ -47,10 +47,17 @@ int sip_acf_channel_read(struct ast_channel *chan, const char *funcname, char *p
                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(chan->tech)) {
+       if (!IS_SIP_TECH(ast_channel_tech(chan))) {
                ast_log(LOG_ERROR, "Cannot call %s on a non-SIP channel\n", funcname);
                return 0;
        }
@@ -62,9 +69,9 @@ int sip_acf_channel_read(struct ast_channel *chan, const char *funcname, char *p
        }
 
        if (!strcasecmp(args.param, "peerip")) {
-               ast_copy_string(buf, p->sa.sin_addr.s_addr ? ast_inet_ntoa(p->sa.sin_addr) : "", buflen);
+               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, p->recv.sin_addr.s_addr ? ast_inet_ntoa(p->recv.sin_addr) : "", buflen);
+               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")) {
@@ -76,7 +83,7 @@ int sip_acf_channel_read(struct ast_channel *chan, const char *funcname, char *p
        } 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 sockaddr_in sin;
+               struct ast_sockaddr addr;
                struct ast_rtp_instance *stream;
 
                if (ast_strlen_zero(args.type))
@@ -91,14 +98,15 @@ int sip_acf_channel_read(struct ast_channel *chan, const char *funcname, char *p
                else
                        return -1;
 
+               /* Return 0 to suppress a console warning message */
                if (!stream) {
-                       return -1;
+                       return 0;
                }
 
-               ast_rtp_instance_get_remote_address(stream, &sin);
-               snprintf(buf, buflen, "%s:%d", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
+               ast_rtp_instance_get_remote_address(stream, &addr);
+               snprintf(buf, buflen, "%s", ast_sockaddr_stringify(&addr));
        } else if (!strcasecmp(args.param, "rtpsource")) {
-               struct sockaddr_in sin;
+               struct ast_sockaddr sa;
                struct ast_rtp_instance *stream;
 
                if (ast_strlen_zero(args.type))
@@ -113,19 +121,20 @@ int sip_acf_channel_read(struct ast_channel *chan, const char *funcname, char *p
                else
                        return -1;
 
+               /* Return 0 to suppress a console warning message */
                if (!stream) {
-                       return -1;
+                       return 0;
                }
 
-               ast_rtp_instance_get_local_address(stream, &sin);
+               ast_rtp_instance_get_local_address(stream, &sa);
 
-               if (!sin.sin_addr.s_addr) {
-                       struct sockaddr_in dest_sin;
-                       ast_rtp_instance_get_remote_address(stream, &dest_sin);
-                       ast_ouraddrfor(&dest_sin.sin_addr, &sin.sin_addr);
+               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:%d", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
+               snprintf(buf, buflen, "%s", ast_sockaddr_stringify(&sa));
        } else if (!strcasecmp(args.param, "rtpqos")) {
                struct ast_rtp_instance *rtp = NULL;
 
@@ -165,8 +174,8 @@ int sip_acf_channel_read(struct ast_channel *chan, const char *funcname, char *p
                        } lookup[] = {
                                { "txcount",               INT, { .i4 = &stats.txcount, }, },
                                { "rxcount",               INT, { .i4 = &stats.rxcount, }, },
-                               { "txjitter",              INT, { .i4 = &stats.txjitter, }, },
-                               { "rxjitter",              INT, { .i4 = &stats.rxjitter, }, },
+                               { "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, }, },
@@ -185,7 +194,7 @@ int sip_acf_channel_read(struct ast_channel *chan, const char *funcname, char *p
                                { "local_minrxploss",      DBL, { .d8 = &stats.local_minrxploss, }, },
                                { "local_normdevrxploss",  DBL, { .d8 = &stats.local_normdevrxploss, }, },
                                { "local_stdevrxploss",    DBL, { .d8 = &stats.local_stdevrxploss, }, },
-                               { "rtt",                   INT, { .i4 = &stats.rtt, }, },
+                               { "rtt",                   DBL, { .d8 = &stats.rtt, }, },
                                { "maxrtt",                DBL, { .d8 = &stats.maxrtt, }, },
                                { "minrtt",                DBL, { .d8 = &stats.minrtt, }, },
                                { "normdevrtt",            DBL, { .d8 = &stats.normdevrtt, }, },
@@ -212,6 +221,10 @@ int sip_acf_channel_read(struct ast_channel *chan, const char *funcname, char *p
                        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;
        }
@@ -219,7 +232,7 @@ int sip_acf_channel_read(struct ast_channel *chan, const char *funcname, char *p
 }
 
 #ifdef TEST_FRAMEWORK
-static int test_sip_rtpqos_1_new(struct ast_rtp_instance *instance, struct sched_context *sched, struct sockaddr_in *sin, void *data)
+static int test_sip_rtpqos_1_new(struct ast_rtp_instance *instance, struct ast_sched_context *sched, struct ast_sockaddr *addr, void *data)
 {
        /* Needed to pass sanity checks */
        ast_rtp_instance_set_data(instance, data);
@@ -262,7 +275,7 @@ AST_TEST_DEFINE(test_sip_rtpqos_1)
                .write = test_sip_rtpqos_1_write,
                .get_stat = test_sip_rtpqos_1_get_stat,
        };
-       struct sockaddr_in sin = { .sin_port = 31337, .sin_addr = { 4 * 16777216 + 3 * 65536 + 2 * 256 + 1 } };
+       struct ast_sockaddr sa = { {0, } };
        struct ast_rtp_instance_stats mine = { 0, };
        struct sip_pvt *p = NULL;
        struct ast_channel *chan = NULL;
@@ -277,8 +290,8 @@ AST_TEST_DEFINE(test_sip_rtpqos_1)
        } lookup[] = {
                { "txcount",               INT, { .i4 = &mine.txcount, }, },
                { "rxcount",               INT, { .i4 = &mine.rxcount, }, },
-               { "txjitter",              INT, { .i4 = &mine.txjitter, }, },
-               { "rxjitter",              INT, { .i4 = &mine.rxjitter, }, },
+               { "txjitter",              DBL, { .d8 = &mine.txjitter, }, },
+               { "rxjitter",              DBL, { .d8 = &mine.rxjitter, }, },
                { "remote_maxjitter",      DBL, { .d8 = &mine.remote_maxjitter, }, },
                { "remote_minjitter",      DBL, { .d8 = &mine.remote_minjitter, }, },
                { "remote_normdevjitter",  DBL, { .d8 = &mine.remote_normdevjitter, }, },
@@ -297,7 +310,7 @@ AST_TEST_DEFINE(test_sip_rtpqos_1)
                { "local_minrxploss",      DBL, { .d8 = &mine.local_minrxploss, }, },
                { "local_normdevrxploss",  DBL, { .d8 = &mine.local_normdevrxploss, }, },
                { "local_stdevrxploss",    DBL, { .d8 = &mine.local_stdevrxploss, }, },
-               { "rtt",                   INT, { .i4 = &mine.rtt, }, },
+               { "rtt",                   DBL, { .d8 = &mine.rtt, }, },
                { "maxrtt",                DBL, { .d8 = &mine.maxrtt, }, },
                { "minrtt",                DBL, { .d8 = &mine.minrtt, }, },
                { "normdevrtt",            DBL, { .d8 = &mine.normdevrtt, }, },
@@ -310,7 +323,7 @@ AST_TEST_DEFINE(test_sip_rtpqos_1)
        switch (cmd) {
        case TEST_INIT:
                info->name = "test_sip_rtpqos";
-               info->category = "channels/chan_sip/";
+               info->category = "/channels/chan_sip/";
                info->summary = "Test retrieval of SIP RTP QOS stats";
                info->description =
                        "Verify values in the RTP instance structure can be accessed through the dialplan.";
@@ -321,21 +334,22 @@ AST_TEST_DEFINE(test_sip_rtpqos_1)
 
        ast_rtp_engine_register2(&test_engine, NULL);
        /* Have to associate this with a SIP pvt and an ast_channel */
-       if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL))) {
+       if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL, NULL))) {
                res = AST_TEST_NOT_RUN;
                goto done;
        }
+
        if (!(p->rtp = ast_rtp_instance_new("test", sched, &bindaddr, &mine))) {
                res = AST_TEST_NOT_RUN;
                goto done;
        }
-       ast_rtp_instance_set_remote_address(p->rtp, &sin);
+       ast_rtp_instance_set_remote_address(p->rtp, &sa);
        if (!(chan = ast_dummy_channel_alloc())) {
                res = AST_TEST_NOT_RUN;
                goto done;
        }
-       chan->tech = &sip_tech;
-       chan->tech_pvt = p;
+       ast_channel_tech_set(chan, &sip_tech);
+       ast_channel_tech_pvt_set(chan, p);
        p->owner = chan;
 
        varstr = ast_str_create(16);