00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 89512 $")
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 static char *app_sayunixtime = "SayUnixTime";
00040 static char *app_datetime = "DateTime";
00041
00042 static char *sayunixtime_synopsis = "Says a specified time in a custom format";
00043
00044 static char *sayunixtime_descrip =
00045 "SayUnixTime([unixtime][,[timezone][,format]])\n"
00046 " unixtime - time, in seconds since Jan 1, 1970. May be negative.\n"
00047 " defaults to now.\n"
00048 " timezone - timezone, see /usr/share/zoneinfo for a list.\n"
00049 " defaults to machine default.\n"
00050 " format - a format the time is to be said in. See voicemail.conf.\n"
00051 " defaults to \"ABdY 'digits/at' IMp\"\n";
00052 static char *datetime_descrip =
00053 "DateTime([unixtime][,[timezone][,format]])\n"
00054 " unixtime - time, in seconds since Jan 1, 1970. May be negative.\n"
00055 " defaults to now.\n"
00056 " timezone - timezone, see /usr/share/zoneinfo for a list.\n"
00057 " defaults to machine default.\n"
00058 " format: - a format the time is to be said in. See voicemail.conf.\n"
00059 " defaults to \"ABdY 'digits/at' IMp\"\n";
00060
00061
00062 static int sayunixtime_exec(struct ast_channel *chan, void *data)
00063 {
00064 AST_DECLARE_APP_ARGS(args,
00065 AST_APP_ARG(timeval);
00066 AST_APP_ARG(timezone);
00067 AST_APP_ARG(format);
00068 );
00069 char *parse;
00070 int res = 0;
00071 time_t unixtime;
00072
00073 if (!data)
00074 return 0;
00075
00076 parse = ast_strdupa(data);
00077
00078 AST_STANDARD_APP_ARGS(args, parse);
00079
00080 ast_get_time_t(args.timeval, &unixtime, time(NULL), NULL);
00081
00082 if (chan->_state != AST_STATE_UP)
00083 res = ast_answer(chan);
00084
00085 if (!res)
00086 res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY,
00087 chan->language, args.format, args.timezone);
00088
00089 return res;
00090 }
00091
00092 static int unload_module(void)
00093 {
00094 int res;
00095
00096 res = ast_unregister_application(app_sayunixtime);
00097 res |= ast_unregister_application(app_datetime);
00098
00099 return res;
00100 }
00101
00102 static int load_module(void)
00103 {
00104 int res;
00105
00106 res = ast_register_application(app_sayunixtime, sayunixtime_exec, sayunixtime_synopsis, sayunixtime_descrip);
00107 res |= ast_register_application(app_datetime, sayunixtime_exec, sayunixtime_synopsis, datetime_descrip);
00108
00109 return res;
00110 }
00111
00112 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say time");