| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-02-23 17:13:57 +00:00
										 |  |  |  * Copyright (c) 2003, 2006 Tilghman Lesher.  All rights reserved. | 
					
						
							| 
									
										
										
										
											2006-02-15 00:33:07 +00:00
										 |  |  |  * Copyright (c) 2006 Digium, Inc. | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2003-10-05 22:17:32 +00:00
										 |  |  |  * This code is released by the author with no restrictions on usage. | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +00:00
										 |  |  |  * 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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  | /*! \file
 | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  |  * \brief SayUnixTime application | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \author Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com> | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \ingroup applications | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 20:28:54 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<support_level>core</support_level> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 06:02:45 +00:00
										 |  |  | #include "asterisk/file.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/say.h"
 | 
					
						
							| 
									
										
										
										
											2006-02-15 00:33:07 +00:00
										 |  |  | #include "asterisk/app.h"
 | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | /*** DOCUMENTATION
 | 
					
						
							|  |  |  | 	<application name="SayUnixTime" language="en_US"> | 
					
						
							| 
									
										
										
										
											2025-01-23 16:35:58 -05:00
										 |  |  | 		<since> | 
					
						
							|  |  |  | 			<version>0.7.0</version> | 
					
						
							|  |  |  | 		</since> | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 		<synopsis> | 
					
						
							|  |  |  | 			Says a specified time in a custom format. | 
					
						
							|  |  |  | 		</synopsis> | 
					
						
							|  |  |  | 		<syntax> | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | 			<parameter name="unixtime" required="false"> | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 				<para>time, in seconds since Jan 1, 1970.  May be negative. Defaults to now.</para> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | 			<parameter name="timezone" required="false" > | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 				<para>timezone, see <directory>/usr/share/zoneinfo</directory> for a list. Defaults to machine default.</para> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | 			<parameter name="format" required="false" > | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 				<para>a format the time is to be said in.  See <filename>voicemail.conf</filename>. | 
					
						
							|  |  |  | 				Defaults to <literal>ABdY "digits/at" IMp</literal></para> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | 			<parameter name="options" required="false"> | 
					
						
							|  |  |  | 				 <optionlist> | 
					
						
							|  |  |  | 					<option name="j"> | 
					
						
							| 
									
										
										
										
											2013-11-14 20:32:45 +00:00
										 |  |  | 						<para>Allow the calling user to dial digits to jump to that extension. | 
					
						
							|  |  |  | 						This option is automatically enabled if | 
					
						
							|  |  |  | 						<variable>SAY_DTMF_INTERRUPT</variable> is present on the channel and | 
					
						
							|  |  |  | 						set to 'true' (case insensitive)</para> | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | 					</option> | 
					
						
							|  |  |  | 				</optionlist> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 		</syntax> | 
					
						
							|  |  |  | 		<description> | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 			<para>Uses some of the sound files stored in <directory>/var/lib/asterisk/sounds</directory> to construct a phrase | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 			saying the specified date and/or time in the specified format. </para> | 
					
						
							|  |  |  | 		</description> | 
					
						
							| 
									
										
										
										
											2008-11-05 14:37:07 +00:00
										 |  |  | 		<see-also> | 
					
						
							|  |  |  | 			<ref type="function">STRFTIME</ref> | 
					
						
							|  |  |  | 			<ref type="function">STRPTIME</ref> | 
					
						
							|  |  |  | 			<ref type="function">IFTIME</ref> | 
					
						
							|  |  |  | 		</see-also> | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 	</application> | 
					
						
							|  |  |  | 	<application name="DateTime" language="en_US"> | 
					
						
							| 
									
										
										
										
											2025-01-23 16:35:58 -05:00
										 |  |  | 		<since> | 
					
						
							|  |  |  | 			<version>0.2.0</version> | 
					
						
							|  |  |  | 		</since> | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 		<synopsis> | 
					
						
							|  |  |  | 			Says a specified time in a custom format. | 
					
						
							|  |  |  | 		</synopsis> | 
					
						
							|  |  |  | 		<syntax> | 
					
						
							|  |  |  | 			<parameter name="unixtime"> | 
					
						
							|  |  |  | 				<para>time, in seconds since Jan 1, 1970.  May be negative. Defaults to now.</para> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							|  |  |  | 			<parameter name="timezone"> | 
					
						
							|  |  |  | 				<para>timezone, see <filename>/usr/share/zoneinfo</filename> for a list. Defaults to machine default.</para> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							|  |  |  | 			<parameter name="format"> | 
					
						
							|  |  |  | 				<para>a format the time is to be said in.  See <filename>voicemail.conf</filename>. | 
					
						
							|  |  |  | 				Defaults to <literal>ABdY "digits/at" IMp</literal></para> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							|  |  |  | 		</syntax> | 
					
						
							|  |  |  | 		<description> | 
					
						
							|  |  |  | 			<para>Say the date and time in a specified format.</para> | 
					
						
							|  |  |  | 		</description> | 
					
						
							|  |  |  | 	</application> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | enum { | 
					
						
							|  |  |  | 	OPT_JUMP =          (1 << 0), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | enum { | 
					
						
							|  |  |  | 	OPT_ARG_JUMP = 0, | 
					
						
							|  |  |  | 	/* note: this entry _MUST_ be the last one in the enum */ | 
					
						
							|  |  |  | 	OPT_ARG_ARRAY_SIZE, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AST_APP_OPTIONS(sayunixtime_exec_options, BEGIN_OPTIONS | 
					
						
							|  |  |  | 	AST_APP_OPTION_ARG('j', OPT_JUMP, OPT_ARG_JUMP), | 
					
						
							|  |  |  | END_OPTIONS ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  | static char *app_sayunixtime = "SayUnixTime"; | 
					
						
							| 
									
										
										
										
											2004-03-19 18:23:33 +00:00
										 |  |  | static char *app_datetime = "DateTime"; | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int sayunixtime_exec(struct ast_channel *chan, const char *data) | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-15 00:33:07 +00:00
										 |  |  | 	AST_DECLARE_APP_ARGS(args, | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 		AST_APP_ARG(timeval); | 
					
						
							|  |  |  | 		AST_APP_ARG(timezone); | 
					
						
							|  |  |  | 		AST_APP_ARG(format); | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | 		AST_APP_ARG(options); | 
					
						
							| 
									
										
										
										
											2006-02-15 00:33:07 +00:00
										 |  |  | 	); | 
					
						
							|  |  |  | 	char *parse; | 
					
						
							|  |  |  | 	int res = 0; | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  | 	time_t unixtime; | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | 	/* New default behavior is do not jump on key pressed */ | 
					
						
							|  |  |  | 	const char * haltondigits = AST_DIGIT_NONE; | 
					
						
							|  |  |  | 	struct ast_flags64 opts = { 0, }; | 
					
						
							|  |  |  | 	char *opt_args[OPT_ARG_ARRAY_SIZE]; | 
					
						
							| 
									
										
										
										
											2013-11-14 20:32:45 +00:00
										 |  |  | 	const char *interrupt_string; | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!data) { | 
					
						
							| 
									
										
										
										
											2006-02-15 00:33:07 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-02-15 00:33:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-10 13:22:15 +00:00
										 |  |  | 	parse = ast_strdupa(data); | 
					
						
							| 
									
										
										
										
											2006-02-15 00:33:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	AST_STANDARD_APP_ARGS(args, parse); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | 	/* check if we had the 'j' jump flag in option list */ | 
					
						
							|  |  |  | 	if (!ast_strlen_zero(args.options))	{ | 
					
						
							|  |  |  | 		ast_app_parse_options64(sayunixtime_exec_options, &opts, opt_args, args.options); | 
					
						
							|  |  |  | 		if (ast_test_flag64(&opts, OPT_JUMP)){ | 
					
						
							|  |  |  | 			haltondigits = AST_DIGIT_ANY; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-14 20:32:45 +00:00
										 |  |  | 	/* Check if 'SAY_DTMF_INTERRUPT' is true and apply the same behavior as the j flag. */ | 
					
						
							|  |  |  | 	ast_channel_lock(chan); | 
					
						
							|  |  |  | 	interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT"); | 
					
						
							|  |  |  | 	if (ast_true(interrupt_string)) { | 
					
						
							|  |  |  | 		haltondigits = AST_DIGIT_ANY; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ast_channel_unlock(chan); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | 	ast_get_time_t(ast_strlen_zero(args.timeval) ? NULL : args.timeval, &unixtime, time(NULL), NULL); | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 	if (ast_channel_state(chan) != AST_STATE_UP) { | 
					
						
							| 
									
										
										
										
											2003-11-21 05:26:39 +00:00
										 |  |  | 		res = ast_answer(chan); | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-02-15 00:33:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | 	if (!res) { | 
					
						
							|  |  |  | 		res = ast_say_date_with_format(chan, unixtime, haltondigits, | 
					
						
							| 
									
										
										
										
											2012-01-24 20:12:09 +00:00
										 |  |  | 					       ast_channel_language(chan), ast_strlen_zero(args.format) ? NULL : args.format, ast_strlen_zero(args.timezone) ? NULL : args.timezone); | 
					
						
							| 
									
										
										
										
											2011-12-09 20:27:03 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-03-19 18:23:33 +00:00
										 |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-19 18:23:33 +00:00
										 |  |  | 	res = ast_unregister_application(app_sayunixtime); | 
					
						
							| 
									
										
										
										
											2005-10-18 22:52:21 +00:00
										 |  |  | 	res |= ast_unregister_application(app_datetime); | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-18 22:52:21 +00:00
										 |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-03-19 18:23:33 +00:00
										 |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 	res = ast_register_application_xml(app_sayunixtime, sayunixtime_exec); | 
					
						
							|  |  |  | 	res |= ast_register_application_xml(app_datetime, sayunixtime_exec); | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-18 22:52:21 +00:00
										 |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say time"); |