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 /*** MODULEINFO 00029 <support_level>core</support_level> 00030 ***/ 00031 00032 #include "asterisk.h" 00033 00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $") 00035 00036 #include "asterisk/file.h" 00037 #include "asterisk/channel.h" 00038 #include "asterisk/pbx.h" 00039 #include "asterisk/module.h" 00040 #include "asterisk/say.h" 00041 #include "asterisk/app.h" 00042 00043 /*** DOCUMENTATION 00044 <application name="SayUnixTime" language="en_US"> 00045 <synopsis> 00046 Says a specified time in a custom format. 00047 </synopsis> 00048 <syntax> 00049 <parameter name="unixtime"> 00050 <para>time, in seconds since Jan 1, 1970. May be negative. Defaults to now.</para> 00051 </parameter> 00052 <parameter name="timezone"> 00053 <para>timezone, see <directory>/usr/share/zoneinfo</directory> for a list. Defaults to machine default.</para> 00054 </parameter> 00055 <parameter name="format"> 00056 <para>a format the time is to be said in. See <filename>voicemail.conf</filename>. 00057 Defaults to <literal>ABdY "digits/at" IMp</literal></para> 00058 </parameter> 00059 </syntax> 00060 <description> 00061 <para>Uses some of the sound files stored in <directory>/var/lib/asterisk/sounds</directory> to construct a phrase 00062 saying the specified date and/or time in the specified format. </para> 00063 </description> 00064 <see-also> 00065 <ref type="function">STRFTIME</ref> 00066 <ref type="function">STRPTIME</ref> 00067 <ref type="function">IFTIME</ref> 00068 </see-also> 00069 </application> 00070 <application name="DateTime" language="en_US"> 00071 <synopsis> 00072 Says a specified time in a custom format. 00073 </synopsis> 00074 <syntax> 00075 <parameter name="unixtime"> 00076 <para>time, in seconds since Jan 1, 1970. May be negative. Defaults to now.</para> 00077 </parameter> 00078 <parameter name="timezone"> 00079 <para>timezone, see <filename>/usr/share/zoneinfo</filename> for a list. Defaults to machine default.</para> 00080 </parameter> 00081 <parameter name="format"> 00082 <para>a format the time is to be said in. See <filename>voicemail.conf</filename>. 00083 Defaults to <literal>ABdY "digits/at" IMp</literal></para> 00084 </parameter> 00085 </syntax> 00086 <description> 00087 <para>Say the date and time in a specified format.</para> 00088 </description> 00089 </application> 00090 00091 ***/ 00092 00093 static char *app_sayunixtime = "SayUnixTime"; 00094 static char *app_datetime = "DateTime"; 00095 00096 static int sayunixtime_exec(struct ast_channel *chan, const char *data) 00097 { 00098 AST_DECLARE_APP_ARGS(args, 00099 AST_APP_ARG(timeval); 00100 AST_APP_ARG(timezone); 00101 AST_APP_ARG(format); 00102 ); 00103 char *parse; 00104 int res = 0; 00105 time_t unixtime; 00106 00107 if (!data) 00108 return 0; 00109 00110 parse = ast_strdupa(data); 00111 00112 AST_STANDARD_APP_ARGS(args, parse); 00113 00114 ast_get_time_t(args.timeval, &unixtime, time(NULL), NULL); 00115 00116 if (chan->_state != AST_STATE_UP) 00117 res = ast_answer(chan); 00118 00119 if (!res) 00120 res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY, 00121 chan->language, args.format, args.timezone); 00122 00123 return res; 00124 } 00125 00126 static int unload_module(void) 00127 { 00128 int res; 00129 00130 res = ast_unregister_application(app_sayunixtime); 00131 res |= ast_unregister_application(app_datetime); 00132 00133 return res; 00134 } 00135 00136 static int load_module(void) 00137 { 00138 int res; 00139 00140 res = ast_register_application_xml(app_sayunixtime, sayunixtime_exec); 00141 res |= ast_register_application_xml(app_datetime, sayunixtime_exec); 00142 00143 return res; 00144 } 00145 00146 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say time");