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
|
|
|
*/
|
|
|
|
|
2003-10-13 12:23:31 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
2005-06-06 22:39:32 +00:00
|
|
|
|
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/options.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
|
|
|
|
|
|
|
static char *tdesc = "Say time";
|
|
|
|
|
|
|
|
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 char *sayunixtime_synopsis = "Says a specified time in a custom format";
|
|
|
|
|
|
|
|
static char *sayunixtime_descrip =
|
|
|
|
"SayUnixTime([unixtime][|[timezone][|format]])\n"
|
|
|
|
" unixtime: time, in seconds since Jan 1, 1970. May be negative.\n"
|
|
|
|
" defaults to now.\n"
|
|
|
|
" timezone: timezone, see /usr/share/zoneinfo for a list.\n"
|
|
|
|
" defaults to machine default.\n"
|
|
|
|
" format: a format the time is to be said in. See voicemail.conf.\n"
|
2005-11-07 22:01:22 +00:00
|
|
|
" defaults to \"ABdY 'digits/at' IMp\"\n";
|
2004-03-19 18:23:33 +00:00
|
|
|
static char *datetime_descrip =
|
|
|
|
"DateTime([unixtime][|[timezone][|format]])\n"
|
|
|
|
" unixtime: time, in seconds since Jan 1, 1970. May be negative.\n"
|
|
|
|
" defaults to now.\n"
|
|
|
|
" timezone: timezone, see /usr/share/zoneinfo for a list.\n"
|
|
|
|
" defaults to machine default.\n"
|
|
|
|
" format: a format the time is to be said in. See voicemail.conf.\n"
|
2005-11-07 22:01:22 +00:00
|
|
|
" defaults to \"ABdY 'digits/at' IMp\"\n";
|
2003-09-30 23:03:57 +00:00
|
|
|
|
|
|
|
LOCAL_USER_DECL;
|
|
|
|
|
|
|
|
static int sayunixtime_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
2006-02-15 00:33:07 +00:00
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
AST_APP_ARG(timeval);
|
|
|
|
AST_APP_ARG(timezone);
|
|
|
|
AST_APP_ARG(format);
|
|
|
|
);
|
|
|
|
char *parse;
|
|
|
|
int res = 0;
|
2003-09-30 23:03:57 +00:00
|
|
|
struct localuser *u;
|
|
|
|
time_t unixtime;
|
2004-11-13 16:13:07 +00:00
|
|
|
|
2006-02-15 00:33:07 +00:00
|
|
|
if (!data)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!(parse = ast_strdupa(data)))
|
|
|
|
return -1;
|
|
|
|
|
2003-09-30 23:03:57 +00:00
|
|
|
LOCAL_USER_ADD(u);
|
|
|
|
|
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
|
|
|
|
|
|
|
LOCAL_USER_REMOVE(u);
|
2006-02-15 00:33:07 +00:00
|
|
|
|
2003-09-30 23:03:57 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static int unload_module(void *mod)
|
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);
|
|
|
|
|
|
|
|
STANDARD_HANGUP_LOCALUSERS;
|
|
|
|
|
|
|
|
return res;
|
2003-09-30 23:03:57 +00:00
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static int load_module(void *mod)
|
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_register_application(app_sayunixtime, sayunixtime_exec, sayunixtime_synopsis, sayunixtime_descrip);
|
2005-10-18 22:52:21 +00:00
|
|
|
res |= ast_register_application(app_datetime, sayunixtime_exec, sayunixtime_synopsis, datetime_descrip);
|
|
|
|
|
|
|
|
return res;
|
2003-09-30 23:03:57 +00:00
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static const char *description(void)
|
2003-09-30 23:03:57 +00:00
|
|
|
{
|
|
|
|
return tdesc;
|
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static const char *key(void)
|
2003-09-30 23:03:57 +00:00
|
|
|
{
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
}
|
2006-04-14 14:08:19 +00:00
|
|
|
|
|
|
|
STD_MOD1;
|