Make SIP tests compile again.
[asterisk/asterisk.git] / channels / sip / dialplan_functions.c
index 473199c..d39a277 100644 (file)
@@ -28,6 +28,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #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"
@@ -76,19 +77,56 @@ int sip_acf_channel_read(struct ast_channel *chan, const char *funcname, char *p
                ast_copy_string(buf, (p->t38.state == T38_DISABLED) ? "0" : "1", buflen);
        } else if (!strcasecmp(args.param, "rtpdest")) {
                struct sockaddr_in sin;
+               struct ast_rtp_instance *stream;
 
                if (ast_strlen_zero(args.type))
                        args.type = "audio";
 
                if (!strcasecmp(args.type, "audio"))
-                       ast_rtp_instance_get_remote_address(p->rtp, &sin);
+                       stream = p->rtp;
                else if (!strcasecmp(args.type, "video"))
-                       ast_rtp_instance_get_remote_address(p->vrtp, &sin);
+                       stream = p->vrtp;
                else if (!strcasecmp(args.type, "text"))
-                       ast_rtp_instance_get_remote_address(p->trtp, &sin);
+                       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, &sin);
+               snprintf(buf, buflen, "%s:%d", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
+       } else if (!strcasecmp(args.param, "rtpsource")) {
+               struct sockaddr_in sin;
+               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, &sin);
+
+               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);
+               }
+
                snprintf(buf, buflen, "%s:%d", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
        } else if (!strcasecmp(args.param, "rtpqos")) {
                struct ast_rtp_instance *rtp = NULL;
@@ -129,8 +167,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, }, },
@@ -149,7 +187,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, }, },
@@ -226,7 +264,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 sockaddr_in sin = { .sin_port = 31337, .sin_addr = { .s_addr = 4 * 16777216 + 3 * 65536 + 2 * 256 + 1 } };
        struct ast_rtp_instance_stats mine = { 0, };
        struct sip_pvt *p = NULL;
        struct ast_channel *chan = NULL;
@@ -241,8 +279,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, }, },
@@ -261,7 +299,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, }, },