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
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
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>
|
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">
|
|
|
|
<para>Allow the calling user to dial digits to jump to that extension.</para>
|
|
|
|
</option>
|
|
|
|
</optionlist>
|
|
|
|
</parameter>
|
2008-11-01 21:10:07 +00:00
|
|
|
</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>
|
|
|
|
|
|
|
|
***/
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
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");
|