| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2010, Digium, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							|  |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \file | 
					
						
							|  |  |  |  * \brief sip channel dialplan functions and unit tests | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-15 16:20:16 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							| 
									
										
										
										
											2018-10-10 08:09:15 -04:00
										 |  |  | 	<support_level>deprecated</support_level> | 
					
						
							| 
									
										
										
										
											2012-06-15 16:20:16 +00:00
										 |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 11:15:38 -05:00
										 |  |  | /*** DOCUMENTATION
 | 
					
						
							| 
									
										
										
										
											2016-08-15 16:29:53 -04:00
										 |  |  | <info name="CHANNEL" language="en_US" tech="SIP"> | 
					
						
							| 
									
										
										
										
											2016-08-12 11:15:38 -05:00
										 |  |  | 	<enumlist> | 
					
						
							|  |  |  | 		<enum name="peerip"> | 
					
						
							|  |  |  | 			<para>R/O Get the IP address of the peer.</para> | 
					
						
							|  |  |  | 		</enum> | 
					
						
							|  |  |  | 		<enum name="recvip"> | 
					
						
							|  |  |  | 			<para>R/O Get the source IP address of the peer.</para> | 
					
						
							|  |  |  | 		</enum> | 
					
						
							|  |  |  | 		<enum name="recvport"> | 
					
						
							|  |  |  | 			<para>R/O Get the source port of the peer.</para> | 
					
						
							|  |  |  | 		</enum> | 
					
						
							|  |  |  | 		<enum name="from"> | 
					
						
							|  |  |  | 			<para>R/O Get the URI from the From: header.</para> | 
					
						
							|  |  |  | 		</enum> | 
					
						
							|  |  |  | 		<enum name="uri"> | 
					
						
							|  |  |  | 			<para>R/O Get the URI from the Contact: header.</para> | 
					
						
							|  |  |  | 		</enum> | 
					
						
							| 
									
										
										
										
											2017-09-19 10:34:01 -04:00
										 |  |  | 		<enum name="ruri"> | 
					
						
							|  |  |  | 			<para>R/O Get the Request-URI from the INVITE header.</para> | 
					
						
							|  |  |  | 		</enum> | 
					
						
							| 
									
										
										
										
											2016-08-12 11:15:38 -05:00
										 |  |  | 		<enum name="useragent"> | 
					
						
							|  |  |  | 			<para>R/O Get the useragent.</para> | 
					
						
							|  |  |  | 		</enum> | 
					
						
							|  |  |  | 		<enum name="peername"> | 
					
						
							|  |  |  | 			<para>R/O Get the name of the peer.</para> | 
					
						
							|  |  |  | 		</enum> | 
					
						
							|  |  |  | 		<enum name="t38passthrough"> | 
					
						
							|  |  |  | 			<para>R/O <literal>1</literal> if T38 is offered or enabled in this channel, | 
					
						
							|  |  |  | 			otherwise <literal>0</literal></para> | 
					
						
							|  |  |  | 		</enum> | 
					
						
							|  |  |  | 		<enum name="rtpqos"> | 
					
						
							|  |  |  | 			<para>R/O Get QOS information about the RTP stream</para> | 
					
						
							|  |  |  | 			<para>    This option takes two additional arguments:</para> | 
					
						
							|  |  |  | 			<para>    Argument 1:</para> | 
					
						
							|  |  |  | 			<para>     <literal>audio</literal>             Get data about the audio stream</para> | 
					
						
							|  |  |  | 			<para>     <literal>video</literal>             Get data about the video stream</para> | 
					
						
							|  |  |  | 			<para>     <literal>text</literal>              Get data about the text stream</para> | 
					
						
							|  |  |  | 			<para>    Argument 2:</para> | 
					
						
							|  |  |  | 			<para>     <literal>local_ssrc</literal>        Local SSRC (stream ID)</para> | 
					
						
							|  |  |  | 			<para>     <literal>local_lostpackets</literal> Local lost packets</para> | 
					
						
							|  |  |  | 			<para>     <literal>local_jitter</literal>      Local calculated jitter</para> | 
					
						
							|  |  |  | 			<para>     <literal>local_maxjitter</literal>   Local calculated jitter (maximum)</para> | 
					
						
							|  |  |  | 			<para>     <literal>local_minjitter</literal>   Local calculated jitter (minimum)</para> | 
					
						
							|  |  |  | 			<para>     <literal>local_normdevjitter</literal>Local calculated jitter (normal deviation)</para> | 
					
						
							|  |  |  | 			<para>     <literal>local_stdevjitter</literal> Local calculated jitter (standard deviation)</para> | 
					
						
							|  |  |  | 			<para>     <literal>local_count</literal>       Number of received packets</para> | 
					
						
							|  |  |  | 			<para>     <literal>remote_ssrc</literal>       Remote SSRC (stream ID)</para> | 
					
						
							|  |  |  | 			<para>     <literal>remote_lostpackets</literal>Remote lost packets</para> | 
					
						
							|  |  |  | 			<para>     <literal>remote_jitter</literal>     Remote reported jitter</para> | 
					
						
							|  |  |  | 			<para>     <literal>remote_maxjitter</literal>  Remote calculated jitter (maximum)</para> | 
					
						
							|  |  |  | 			<para>     <literal>remote_minjitter</literal>  Remote calculated jitter (minimum)</para> | 
					
						
							|  |  |  | 			<para>     <literal>remote_normdevjitter</literal>Remote calculated jitter (normal deviation)</para> | 
					
						
							|  |  |  | 			<para>     <literal>remote_stdevjitter</literal>Remote calculated jitter (standard deviation)</para> | 
					
						
							|  |  |  | 			<para>     <literal>remote_count</literal>      Number of transmitted packets</para> | 
					
						
							|  |  |  | 			<para>     <literal>rtt</literal>               Round trip time</para> | 
					
						
							|  |  |  | 			<para>     <literal>maxrtt</literal>            Round trip time (maximum)</para> | 
					
						
							|  |  |  | 			<para>     <literal>minrtt</literal>            Round trip time (minimum)</para> | 
					
						
							|  |  |  | 			<para>     <literal>normdevrtt</literal>        Round trip time (normal deviation)</para> | 
					
						
							|  |  |  | 			<para>     <literal>stdevrtt</literal>          Round trip time (standard deviation)</para> | 
					
						
							|  |  |  | 			<para>     <literal>all</literal>               All statistics (in a form suited to logging, | 
					
						
							|  |  |  | 			but not for parsing)</para> | 
					
						
							|  |  |  | 		</enum> | 
					
						
							|  |  |  | 		<enum name="rtpdest"> | 
					
						
							|  |  |  | 			<para>R/O Get remote RTP destination information.</para> | 
					
						
							|  |  |  | 			<para>   This option takes one additional argument:</para> | 
					
						
							|  |  |  | 			<para>    Argument 1:</para> | 
					
						
							|  |  |  | 			<para>     <literal>audio</literal>             Get audio destination</para> | 
					
						
							|  |  |  | 			<para>     <literal>video</literal>             Get video destination</para> | 
					
						
							|  |  |  | 			<para>     <literal>text</literal>              Get text destination</para> | 
					
						
							|  |  |  | 			<para>   Defaults to <literal>audio</literal> if unspecified.</para> | 
					
						
							|  |  |  | 		</enum> | 
					
						
							|  |  |  | 		<enum name="rtpsource"> | 
					
						
							|  |  |  | 			<para>R/O Get source RTP destination information.</para> | 
					
						
							|  |  |  | 			<para>   This option takes one additional argument:</para> | 
					
						
							|  |  |  | 			<para>    Argument 1:</para> | 
					
						
							|  |  |  | 			<para>     <literal>audio</literal>             Get audio destination</para> | 
					
						
							|  |  |  | 			<para>     <literal>video</literal>             Get video destination</para> | 
					
						
							|  |  |  | 			<para>     <literal>text</literal>              Get text destination</para> | 
					
						
							|  |  |  | 			<para>   Defaults to <literal>audio</literal> if unspecified.</para> | 
					
						
							|  |  |  | 		</enum> | 
					
						
							|  |  |  | 	</enumlist> | 
					
						
							|  |  |  | </info> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <math.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/rtp_engine.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							| 
									
										
										
										
											2010-03-25 17:29:47 +00:00
										 |  |  | #include "asterisk/acl.h"
 | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "include/sip.h"
 | 
					
						
							|  |  |  | #include "include/globals.h"
 | 
					
						
							|  |  |  | #include "include/dialog.h"
 | 
					
						
							|  |  |  | #include "include/dialplan_functions.h"
 | 
					
						
							|  |  |  | #include "include/sip_utils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int sip_acf_channel_read(struct ast_channel *chan, const char *funcname, char *preparse, char *buf, size_t buflen) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 	struct sip_pvt *p = ast_channel_tech_pvt(chan); | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 	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); | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-08 20:34:05 +00:00
										 |  |  | 	/* Check for zero arguments */ | 
					
						
							|  |  |  | 	if (ast_strlen_zero(parse)) { | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Cannot call %s without arguments\n", funcname); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 	AST_STANDARD_APP_ARGS(args, parse); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Sanity check */ | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 	if (!IS_SIP_TECH(ast_channel_tech(chan))) { | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 		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")) { | 
					
						
							| 
									
										
										
										
											2010-07-08 22:08:07 +00:00
										 |  |  | 		ast_copy_string(buf, ast_sockaddr_isnull(&p->sa) ? "" : ast_sockaddr_stringify_addr(&p->sa), buflen); | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 	} else if (!strcasecmp(args.param, "recvip")) { | 
					
						
							| 
									
										
										
										
											2010-07-08 22:08:07 +00:00
										 |  |  | 		ast_copy_string(buf, ast_sockaddr_isnull(&p->recv) ? "" : ast_sockaddr_stringify_addr(&p->recv), buflen); | 
					
						
							| 
									
										
										
										
											2014-08-04 20:25:16 +00:00
										 |  |  | 	} else if (!strcasecmp(args.param, "recvport")) { | 
					
						
							|  |  |  | 		ast_copy_string(buf, ast_sockaddr_isnull(&p->recv) ? "" : ast_sockaddr_stringify_port(&p->recv), buflen); | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 	} 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); | 
					
						
							| 
									
										
										
										
											2017-09-19 10:34:01 -04:00
										 |  |  | 	} else if (!strcasecmp(args.param, "ruri")) { | 
					
						
							| 
									
										
										
										
											2021-11-24 02:21:23 +00:00
										 |  |  | 		if (p->initreq.data) { | 
					
						
							|  |  |  | 			char *tmpruri = REQ_OFFSET_TO_STR(&p->initreq, rlpart2); | 
					
						
							|  |  |  | 			ast_copy_string(buf, tmpruri, buflen); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 	} 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")) { | 
					
						
							| 
									
										
										
										
											2010-07-08 22:08:07 +00:00
										 |  |  | 		struct ast_sockaddr addr; | 
					
						
							| 
									
										
										
										
											2010-03-25 17:29:47 +00:00
										 |  |  | 		struct ast_rtp_instance *stream; | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (ast_strlen_zero(args.type)) | 
					
						
							|  |  |  | 			args.type = "audio"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!strcasecmp(args.type, "audio")) | 
					
						
							| 
									
										
										
										
											2010-03-25 17:29:47 +00:00
										 |  |  | 			stream = p->rtp; | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 		else if (!strcasecmp(args.type, "video")) | 
					
						
							| 
									
										
										
										
											2010-03-25 17:29:47 +00:00
										 |  |  | 			stream = p->vrtp; | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 		else if (!strcasecmp(args.type, "text")) | 
					
						
							| 
									
										
										
										
											2010-03-25 17:29:47 +00:00
										 |  |  | 			stream = p->trtp; | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-05 18:28:05 +00:00
										 |  |  | 		/* Return 0 to suppress a console warning message */ | 
					
						
							| 
									
										
										
										
											2010-03-25 17:29:47 +00:00
										 |  |  | 		if (!stream) { | 
					
						
							| 
									
										
										
										
											2010-05-05 18:28:05 +00:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2010-03-25 17:29:47 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-08 22:08:07 +00:00
										 |  |  | 		ast_rtp_instance_get_remote_address(stream, &addr); | 
					
						
							|  |  |  | 		snprintf(buf, buflen, "%s", ast_sockaddr_stringify(&addr)); | 
					
						
							| 
									
										
										
										
											2010-03-25 17:29:47 +00:00
										 |  |  | 	} else if (!strcasecmp(args.param, "rtpsource")) { | 
					
						
							| 
									
										
										
										
											2010-07-08 22:08:07 +00:00
										 |  |  | 		struct ast_sockaddr sa; | 
					
						
							| 
									
										
										
										
											2010-03-25 17:29:47 +00:00
										 |  |  | 		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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-05 18:28:05 +00:00
										 |  |  | 		/* Return 0 to suppress a console warning message */ | 
					
						
							| 
									
										
										
										
											2010-03-25 17:29:47 +00:00
										 |  |  | 		if (!stream) { | 
					
						
							| 
									
										
										
										
											2010-05-05 18:28:05 +00:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2010-03-25 17:29:47 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-08 22:08:07 +00:00
										 |  |  | 		ast_rtp_instance_get_local_address(stream, &sa); | 
					
						
							| 
									
										
										
										
											2010-03-25 17:29:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-08 22:08:07 +00:00
										 |  |  | 		if (ast_sockaddr_isnull(&sa)) { | 
					
						
							|  |  |  | 			struct ast_sockaddr dest_sa; | 
					
						
							|  |  |  | 			ast_rtp_instance_get_remote_address(stream, &dest_sa); | 
					
						
							|  |  |  | 			ast_ouraddrfor(&dest_sa, &sa); | 
					
						
							| 
									
										
										
										
											2010-03-25 17:29:47 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-08 22:08:07 +00:00
										 |  |  | 		snprintf(buf, buflen, "%s", ast_sockaddr_stringify(&sa)); | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 	} 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")) { | 
					
						
							| 
									
										
										
										
											2012-06-11 15:23:30 +00:00
										 |  |  | 			char quality_buf[AST_MAX_USER_FIELD]; | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-11 15:23:30 +00:00
										 |  |  | 			if (!ast_rtp_instance_get_quality(rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf))) { | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 				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, }, }, | 
					
						
							| 
									
										
										
										
											2010-06-07 19:52:39 +00:00
										 |  |  | 				{ "txjitter",              DBL, { .d8 = &stats.txjitter, }, }, | 
					
						
							|  |  |  | 				{ "rxjitter",              DBL, { .d8 = &stats.rxjitter, }, }, | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 				{ "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, }, }, | 
					
						
							| 
									
										
										
										
											2010-06-07 19:52:39 +00:00
										 |  |  | 				{ "rtt",                   DBL, { .d8 = &stats.rtt, }, }, | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 				{ "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; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-06-08 05:29:08 +00:00
										 |  |  | 	} else if (!strcasecmp(args.param, "secure_signaling")) { | 
					
						
							| 
									
										
										
										
											2013-05-17 17:36:10 +00:00
										 |  |  | 		snprintf(buf, buflen, "%s", p->socket.type == AST_TRANSPORT_TLS ? "1" : ""); | 
					
						
							| 
									
										
										
										
											2010-06-08 05:29:08 +00:00
										 |  |  | 	} else if (!strcasecmp(args.param, "secure_media")) { | 
					
						
							|  |  |  | 		snprintf(buf, buflen, "%s", p->srtp ? "1" : ""); | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		res = -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef TEST_FRAMEWORK
 | 
					
						
							| 
									
										
										
										
											2010-12-20 17:15:54 +00:00
										 |  |  | static int test_sip_rtpqos_1_new(struct ast_rtp_instance *instance, struct ast_sched_context *sched, struct ast_sockaddr *addr, void *data) | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* Needed to pass sanity checks */ | 
					
						
							|  |  |  | 	ast_rtp_instance_set_data(instance, data); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int test_sip_rtpqos_1_destroy(struct ast_rtp_instance *instance) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* Needed to pass sanity checks */ | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ast_frame *test_sip_rtpqos_1_read(struct ast_rtp_instance *instance, int rtcp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* Needed to pass sanity checks */ | 
					
						
							|  |  |  | 	return &ast_null_frame; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int test_sip_rtpqos_1_write(struct ast_rtp_instance *instance, struct ast_frame *frame) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* Needed to pass sanity checks */ | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int test_sip_rtpqos_1_get_stat(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_rtp_instance_stats *s = ast_rtp_instance_get_data(instance); | 
					
						
							|  |  |  | 	memcpy(stats, s, sizeof(*stats)); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AST_TEST_DEFINE(test_sip_rtpqos_1) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i, res = AST_TEST_PASS; | 
					
						
							| 
									
										
										
										
											2016-03-15 14:51:25 -05:00
										 |  |  | 	static struct ast_rtp_engine test_engine = { | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 		.name = "test", | 
					
						
							|  |  |  | 		.new = test_sip_rtpqos_1_new, | 
					
						
							|  |  |  | 		.destroy = test_sip_rtpqos_1_destroy, | 
					
						
							|  |  |  | 		.read = test_sip_rtpqos_1_read, | 
					
						
							|  |  |  | 		.write = test_sip_rtpqos_1_write, | 
					
						
							|  |  |  | 		.get_stat = test_sip_rtpqos_1_get_stat, | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2010-07-08 22:08:07 +00:00
										 |  |  | 	struct ast_sockaddr sa = { {0, } }; | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 	struct ast_rtp_instance_stats mine = { 0, }; | 
					
						
							|  |  |  | 	struct sip_pvt *p = NULL; | 
					
						
							|  |  |  | 	struct ast_channel *chan = NULL; | 
					
						
							|  |  |  | 	struct ast_str *varstr = NULL, *buffer = NULL; | 
					
						
							|  |  |  | 	struct { | 
					
						
							|  |  |  | 		const char *name; | 
					
						
							|  |  |  | 		enum { INT, DBL } type; | 
					
						
							|  |  |  | 		union { | 
					
						
							|  |  |  | 			unsigned int *i4; | 
					
						
							|  |  |  | 			double *d8; | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	} lookup[] = { | 
					
						
							|  |  |  | 		{ "txcount",               INT, { .i4 = &mine.txcount, }, }, | 
					
						
							|  |  |  | 		{ "rxcount",               INT, { .i4 = &mine.rxcount, }, }, | 
					
						
							| 
									
										
										
										
											2010-06-08 00:45:13 +00:00
										 |  |  | 		{ "txjitter",              DBL, { .d8 = &mine.txjitter, }, }, | 
					
						
							|  |  |  | 		{ "rxjitter",              DBL, { .d8 = &mine.rxjitter, }, }, | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 		{ "remote_maxjitter",      DBL, { .d8 = &mine.remote_maxjitter, }, }, | 
					
						
							|  |  |  | 		{ "remote_minjitter",      DBL, { .d8 = &mine.remote_minjitter, }, }, | 
					
						
							|  |  |  | 		{ "remote_normdevjitter",  DBL, { .d8 = &mine.remote_normdevjitter, }, }, | 
					
						
							|  |  |  | 		{ "remote_stdevjitter",    DBL, { .d8 = &mine.remote_stdevjitter, }, }, | 
					
						
							|  |  |  | 		{ "local_maxjitter",       DBL, { .d8 = &mine.local_maxjitter, }, }, | 
					
						
							|  |  |  | 		{ "local_minjitter",       DBL, { .d8 = &mine.local_minjitter, }, }, | 
					
						
							|  |  |  | 		{ "local_normdevjitter",   DBL, { .d8 = &mine.local_normdevjitter, }, }, | 
					
						
							|  |  |  | 		{ "local_stdevjitter",     DBL, { .d8 = &mine.local_stdevjitter, }, }, | 
					
						
							|  |  |  | 		{ "txploss",               INT, { .i4 = &mine.txploss, }, }, | 
					
						
							|  |  |  | 		{ "rxploss",               INT, { .i4 = &mine.rxploss, }, }, | 
					
						
							|  |  |  | 		{ "remote_maxrxploss",     DBL, { .d8 = &mine.remote_maxrxploss, }, }, | 
					
						
							|  |  |  | 		{ "remote_minrxploss",     DBL, { .d8 = &mine.remote_minrxploss, }, }, | 
					
						
							|  |  |  | 		{ "remote_normdevrxploss", DBL, { .d8 = &mine.remote_normdevrxploss, }, }, | 
					
						
							|  |  |  | 		{ "remote_stdevrxploss",   DBL, { .d8 = &mine.remote_stdevrxploss, }, }, | 
					
						
							|  |  |  | 		{ "local_maxrxploss",      DBL, { .d8 = &mine.local_maxrxploss, }, }, | 
					
						
							|  |  |  | 		{ "local_minrxploss",      DBL, { .d8 = &mine.local_minrxploss, }, }, | 
					
						
							|  |  |  | 		{ "local_normdevrxploss",  DBL, { .d8 = &mine.local_normdevrxploss, }, }, | 
					
						
							|  |  |  | 		{ "local_stdevrxploss",    DBL, { .d8 = &mine.local_stdevrxploss, }, }, | 
					
						
							| 
									
										
										
										
											2010-06-08 00:45:13 +00:00
										 |  |  | 		{ "rtt",                   DBL, { .d8 = &mine.rtt, }, }, | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 		{ "maxrtt",                DBL, { .d8 = &mine.maxrtt, }, }, | 
					
						
							|  |  |  | 		{ "minrtt",                DBL, { .d8 = &mine.minrtt, }, }, | 
					
						
							|  |  |  | 		{ "normdevrtt",            DBL, { .d8 = &mine.normdevrtt, }, }, | 
					
						
							|  |  |  | 		{ "stdevrtt",              DBL, { .d8 = &mine.stdevrtt, }, }, | 
					
						
							|  |  |  | 		{ "local_ssrc",            INT, { .i4 = &mine.local_ssrc, }, }, | 
					
						
							|  |  |  | 		{ "remote_ssrc",           INT, { .i4 = &mine.remote_ssrc, }, }, | 
					
						
							|  |  |  | 		{ NULL, }, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (cmd) { | 
					
						
							|  |  |  | 	case TEST_INIT: | 
					
						
							|  |  |  | 		info->name = "test_sip_rtpqos"; | 
					
						
							| 
									
										
										
										
											2010-07-09 17:00:22 +00:00
										 |  |  | 		info->category = "/channels/chan_sip/"; | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 		info->summary = "Test retrieval of SIP RTP QOS stats"; | 
					
						
							|  |  |  | 		info->description = | 
					
						
							|  |  |  | 			"Verify values in the RTP instance structure can be accessed through the dialplan."; | 
					
						
							|  |  |  | 		return AST_TEST_NOT_RUN; | 
					
						
							|  |  |  | 	case TEST_EXECUTE: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-04 15:26:37 -04:00
										 |  |  | 	ast_rtp_engine_register(&test_engine); | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 	/* Have to associate this with a SIP pvt and an ast_channel */ | 
					
						
							| 
									
										
										
										
											2015-03-13 01:12:35 +00:00
										 |  |  | 	if (!(p = sip_alloc(0, NULL, 0, SIP_NOTIFY, NULL, 0))) { | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 		res = AST_TEST_NOT_RUN; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-07-08 22:08:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 	if (!(p->rtp = ast_rtp_instance_new("test", sched, &bindaddr, &mine))) { | 
					
						
							|  |  |  | 		res = AST_TEST_NOT_RUN; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-07-08 22:08:07 +00:00
										 |  |  | 	ast_rtp_instance_set_remote_address(p->rtp, &sa); | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 	if (!(chan = ast_dummy_channel_alloc())) { | 
					
						
							|  |  |  | 		res = AST_TEST_NOT_RUN; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 	ast_channel_tech_set(chan, &sip_tech); | 
					
						
							| 
									
										
										
										
											2013-08-20 16:25:33 +00:00
										 |  |  | 	ast_channel_tech_pvt_set(chan, dialog_ref(p, "Give the owner channel a reference to the dialog")); | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 	p->owner = chan; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	varstr = ast_str_create(16); | 
					
						
							|  |  |  | 	buffer = ast_str_create(16); | 
					
						
							|  |  |  | 	if (!varstr || !buffer) { | 
					
						
							|  |  |  | 		res = AST_TEST_NOT_RUN; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Populate "mine" with values, then retrieve them with the CHANNEL dialplan function */ | 
					
						
							|  |  |  | 	for (i = 0; !ast_strlen_zero(lookup[i].name); i++) { | 
					
						
							|  |  |  | 		ast_str_set(&varstr, 0, "${CHANNEL(rtpqos,audio,%s)}", lookup[i].name); | 
					
						
							|  |  |  | 		if (lookup[i].type == INT) { | 
					
						
							|  |  |  | 			int j; | 
					
						
							|  |  |  | 			char cmpstr[256]; | 
					
						
							|  |  |  | 			for (j = 1; j < 25; j++) { | 
					
						
							|  |  |  | 				*lookup[i].i4 = j; | 
					
						
							|  |  |  | 				ast_str_substitute_variables(&buffer, 0, chan, ast_str_buffer(varstr)); | 
					
						
							|  |  |  | 				snprintf(cmpstr, sizeof(cmpstr), "%d", j); | 
					
						
							|  |  |  | 				if (strcmp(cmpstr, ast_str_buffer(buffer))) { | 
					
						
							|  |  |  | 					res = AST_TEST_FAIL; | 
					
						
							|  |  |  | 					ast_test_status_update(test, "%s != %s != %s\n", ast_str_buffer(varstr), cmpstr, ast_str_buffer(buffer)); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			double j, cmpdbl = 0.0; | 
					
						
							|  |  |  | 			for (j = 1.0; j < 10.0; j += 0.3) { | 
					
						
							|  |  |  | 				*lookup[i].d8 = j; | 
					
						
							|  |  |  | 				ast_str_substitute_variables(&buffer, 0, chan, ast_str_buffer(varstr)); | 
					
						
							| 
									
										
										
										
											2015-03-31 17:04:18 +00:00
										 |  |  | 				if (sscanf(ast_str_buffer(buffer), "%lf", &cmpdbl) != 1 || fabs(j - cmpdbl) > .05) { | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 					res = AST_TEST_FAIL; | 
					
						
							|  |  |  | 					ast_test_status_update(test, "%s != %f != %s\n", ast_str_buffer(varstr), j, ast_str_buffer(buffer)); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | done: | 
					
						
							|  |  |  | 	ast_free(varstr); | 
					
						
							|  |  |  | 	ast_free(buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-20 16:25:33 +00:00
										 |  |  | 	/* This unlink and unref will take care of destroying the channel, RTP instance, and SIP pvt */ | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 	if (p) { | 
					
						
							| 
									
										
										
										
											2013-08-20 16:25:33 +00:00
										 |  |  | 		dialog_unlink_all(p); | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 		dialog_unref(p, "Destroy test object"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-03 21:58:25 -04:00
										 |  |  | 	if (chan) { | 
					
						
							|  |  |  | 		ast_channel_unref(chan); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-02-17 06:25:15 +00:00
										 |  |  | 	ast_rtp_engine_unregister(&test_engine); | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \brief SIP test registration */ | 
					
						
							|  |  |  | void sip_dialplan_function_register_tests(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	AST_TEST_REGISTER(test_sip_rtpqos_1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \brief SIP test registration */ | 
					
						
							|  |  |  | void sip_dialplan_function_unregister_tests(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	AST_TEST_UNREGISTER(test_sip_rtpqos_1); | 
					
						
							|  |  |  | } |