| 
									
										
										
										
											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> | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +00:00
										 |  |  |  *  | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \ingroup applications | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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"> | 
					
						
							|  |  |  | 		<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 <directory>/usr/share/zoneinfo</directory> 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>Uses some of the sound files stored in <directory>/var/lib/asterisk/sounds</directory> to construct a phrase  | 
					
						
							|  |  |  | 			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"> | 
					
						
							|  |  |  | 		<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> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | static int sayunixtime_exec(struct ast_channel *chan, void *data) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2006-02-15 00:33:07 +00:00
										 |  |  | 	); | 
					
						
							|  |  |  | 	char *parse; | 
					
						
							|  |  |  | 	int res = 0; | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  | 	time_t unixtime; | 
					
						
							| 
									
										
										
										
											2004-11-13 16:13:07 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-02-15 00:33:07 +00:00
										 |  |  | 	if (!data) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-23 17:13:57 +00:00
										 |  |  | 	ast_get_time_t(args.timeval, &unixtime, time(NULL), NULL); | 
					
						
							| 
									
										
										
										
											2003-09-30 23:03:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 00:24:24 +00:00
										 |  |  | 	if (chan->_state != AST_STATE_UP) | 
					
						
							| 
									
										
										
										
											2003-11-21 05:26:39 +00:00
										 |  |  | 		res = ast_answer(chan); | 
					
						
							| 
									
										
										
										
											2006-02-15 00:33:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-11-21 05:26:39 +00:00
										 |  |  | 	if (!res) | 
					
						
							| 
									
										
										
										
											2006-02-15 00:33:07 +00:00
										 |  |  | 		res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY, | 
					
						
							|  |  |  | 					       chan->language, args.format, args.timezone); | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2005-10-18 22:52:21 +00: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); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	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; | 
					
						
							| 
									
										
										
										
											2005-10-18 22:52:21 +00: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); | 
					
						
							| 
									
										
										
										
											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"); |