2003-09-30 23:03:57 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- A telephony toolkit for Linux.
|
|
|
|
*
|
|
|
|
* SayUnixTime application
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 Tilghman Lesher. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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"
|
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"
|
|
|
|
" defaults to \"ABdY 'digits/at' IMp\"\n"
|
|
|
|
" Returns 0 or -1 on hangup.\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"
|
|
|
|
" defaults to \"ABdY 'digits/at' IMp\"\n"
|
|
|
|
" Returns 0 or -1 on hangup.\n";
|
2003-09-30 23:03:57 +00:00
|
|
|
|
|
|
|
STANDARD_LOCAL_USER;
|
|
|
|
|
|
|
|
LOCAL_USER_DECL;
|
|
|
|
|
|
|
|
static int sayunixtime_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
|
|
|
int res=0;
|
|
|
|
struct localuser *u;
|
2004-11-13 16:13:07 +00:00
|
|
|
char *s,*zone=NULL,*timec,*format;
|
2003-09-30 23:03:57 +00:00
|
|
|
time_t unixtime;
|
|
|
|
struct timeval tv;
|
2004-11-13 16:13:07 +00:00
|
|
|
|
2003-09-30 23:03:57 +00:00
|
|
|
LOCAL_USER_ADD(u);
|
|
|
|
|
|
|
|
gettimeofday(&tv,NULL);
|
|
|
|
unixtime = (time_t)tv.tv_sec;
|
|
|
|
|
2005-05-25 17:28:32 +00:00
|
|
|
if( !strcasecmp(chan->language, "da" ) ) {
|
|
|
|
format = "A dBY HMS";
|
|
|
|
} else if ( !strcasecmp(chan->language, "de" ) ) {
|
2004-11-13 16:13:07 +00:00
|
|
|
format = "A dBY HMS";
|
|
|
|
} else {
|
|
|
|
format = "ABdY 'digits/at' IMp";
|
|
|
|
}
|
|
|
|
|
2003-09-30 23:03:57 +00:00
|
|
|
if (data) {
|
|
|
|
s = data;
|
2003-10-13 12:23:31 +00:00
|
|
|
s = ast_strdupa(s);
|
2003-09-30 23:03:57 +00:00
|
|
|
if (s) {
|
|
|
|
timec = strsep(&s,"|");
|
|
|
|
if ((timec) && (*timec != '\0')) {
|
|
|
|
long timein;
|
|
|
|
if (sscanf(timec,"%ld",&timein) == 1) {
|
|
|
|
unixtime = (time_t)timein;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (s) {
|
|
|
|
zone = strsep(&s,"|");
|
|
|
|
if (zone && (*zone == '\0'))
|
|
|
|
zone = NULL;
|
|
|
|
if (s) {
|
|
|
|
format = s;
|
|
|
|
}
|
|
|
|
}
|
2003-12-05 17:33:30 +00:00
|
|
|
} else {
|
|
|
|
ast_log(LOG_ERROR, "Out of memory error\n");
|
2003-09-30 23:03:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-21 05:26:39 +00:00
|
|
|
if (chan->_state != AST_STATE_UP) {
|
|
|
|
res = ast_answer(chan);
|
|
|
|
}
|
|
|
|
if (!res)
|
|
|
|
res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY, chan->language, format, zone);
|
2003-09-30 23:03:57 +00:00
|
|
|
|
|
|
|
LOCAL_USER_REMOVE(u);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int unload_module(void)
|
|
|
|
{
|
2004-03-19 18:23:33 +00:00
|
|
|
int res;
|
2003-09-30 23:03:57 +00:00
|
|
|
STANDARD_HANGUP_LOCALUSERS;
|
2004-03-19 18:23:33 +00:00
|
|
|
res = ast_unregister_application(app_sayunixtime);
|
|
|
|
if (! res)
|
|
|
|
return ast_unregister_application(app_datetime);
|
|
|
|
else
|
|
|
|
return res;
|
2003-09-30 23:03:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int load_module(void)
|
|
|
|
{
|
2004-03-19 18:23:33 +00:00
|
|
|
int res;
|
|
|
|
res = ast_register_application(app_sayunixtime, sayunixtime_exec, sayunixtime_synopsis, sayunixtime_descrip);
|
|
|
|
if (! res)
|
|
|
|
return ast_register_application(app_datetime, sayunixtime_exec, sayunixtime_synopsis, datetime_descrip);
|
|
|
|
else
|
|
|
|
return res;
|
2003-09-30 23:03:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *description(void)
|
|
|
|
{
|
|
|
|
return tdesc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usecount(void)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
STANDARD_USECOUNT(res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *key()
|
|
|
|
{
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
}
|