00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (c) 2003, 2006 Tilghman Lesher. All rights reserved. 00005 * Copyright (c) 2006 Digium, Inc. 00006 * 00007 * Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com> 00008 * 00009 * This code is released by the author with no restrictions on usage. 00010 * 00011 * See http://www.asterisk.org for more information about 00012 * the Asterisk project. Please do not directly contact 00013 * any of the maintainers of this project for assistance; 00014 * the project provides a web site, mailing lists and IRC 00015 * channels for your use. 00016 * 00017 */ 00018 00019 /*! \file 00020 * 00021 * \brief SayUnixTime application 00022 * 00023 * \author Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com> 00024 * 00025 * \ingroup applications 00026 */ 00027 00028 #include "asterisk.h" 00029 00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 196072 $") 00031 00032 #include "asterisk/file.h" 00033 #include "asterisk/channel.h" 00034 #include "asterisk/pbx.h" 00035 #include "asterisk/module.h" 00036 #include "asterisk/say.h" 00037 #include "asterisk/app.h" 00038 00039 /*** DOCUMENTATION 00040 <application name="SayUnixTime" language="en_US"> 00041 <synopsis> 00042 Says a specified time in a custom format. 00043 </synopsis> 00044 <syntax> 00045 <parameter name="unixtime"> 00046 <para>time, in seconds since Jan 1, 1970. May be negative. Defaults to now.</para> 00047 </parameter> 00048 <parameter name="timezone"> 00049 <para>timezone, see <directory>/usr/share/zoneinfo</directory> for a list. Defaults to machine default.</para> 00050 </parameter> 00051 <parameter name="format"> 00052 <para>a format the time is to be said in. See <filename>voicemail.conf</filename>. 00053 Defaults to <literal>ABdY "digits/at" IMp</literal></para> 00054 </parameter> 00055 </syntax> 00056 <description> 00057 <para>Uses some of the sound files stored in <directory>/var/lib/asterisk/sounds</directory> to construct a phrase 00058 saying the specified date and/or time in the specified format. </para> 00059 </description> 00060 <see-also> 00061 <ref type="function">STRFTIME</ref> 00062 <ref type="function">STRPTIME</ref> 00063 <ref type="function">IFTIME</ref> 00064 </see-also> 00065 </application> 00066 <application name="DateTime" language="en_US"> 00067 <synopsis> 00068 Says a specified time in a custom format. 00069 </synopsis> 00070 <syntax> 00071 <parameter name="unixtime"> 00072 <para>time, in seconds since Jan 1, 1970. May be negative. Defaults to now.</para> 00073 </parameter> 00074 <parameter name="timezone"> 00075 <para>timezone, see <filename>/usr/share/zoneinfo</filename> for a list. Defaults to machine default.</para> 00076 </parameter> 00077 <parameter name="format"> 00078 <para>a format the time is to be said in. See <filename>voicemail.conf</filename>. 00079 Defaults to <literal>ABdY "digits/at" IMp</literal></para> 00080 </parameter> 00081 </syntax> 00082 <description> 00083 <para>Say the date and time in a specified format.</para> 00084 </description> 00085 </application> 00086 00087 ***/ 00088 00089 static char *app_sayunixtime = "SayUnixTime"; 00090 static char *app_datetime = "DateTime"; 00091 00092 static int sayunixtime_exec(struct ast_channel *chan, const char *data) 00093 { 00094 AST_DECLARE_APP_ARGS(args, 00095 AST_APP_ARG(timeval); 00096 AST_APP_ARG(timezone); 00097 AST_APP_ARG(format); 00098 ); 00099 char *parse; 00100 int res = 0; 00101 time_t unixtime; 00102 00103 if (!data) 00104 return 0; 00105 00106 parse = ast_strdupa(data); 00107 00108 AST_STANDARD_APP_ARGS(args, parse); 00109 00110 ast_get_time_t(args.timeval, &unixtime, time(NULL), NULL); 00111 00112 if (chan->_state != AST_STATE_UP) 00113 res = ast_answer(chan); 00114 00115 if (!res) 00116 res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY, 00117 chan->language, args.format, args.timezone); 00118 00119 return res; 00120 } 00121 00122 static int unload_module(void) 00123 { 00124 int res; 00125 00126 res = ast_unregister_application(app_sayunixtime); 00127 res |= ast_unregister_application(app_datetime); 00128 00129 return res; 00130 } 00131 00132 static int load_module(void) 00133 { 00134 int res; 00135 00136 res = ast_register_application_xml(app_sayunixtime, sayunixtime_exec); 00137 res |= ast_register_application_xml(app_datetime, sayunixtime_exec); 00138 00139 return res; 00140 } 00141 00142 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say time");