Merged revisions 126573 via svnmerge from
[asterisk-bristuff.git] / apps / app_sayunixtime.c
blobd0e23449ed0e9c78dbe78433f172f6e08b52379b
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (c) 2003, 2006 Tilghman Lesher. All rights reserved.
5 * Copyright (c) 2006 Digium, Inc.
7 * Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com>
9 * This code is released by the author with no restrictions on usage.
11 * See http://www.asterisk.org for more information about
12 * the Asterisk project. Please do not directly contact
13 * any of the maintainers of this project for assistance;
14 * the project provides a web site, mailing lists and IRC
15 * channels for your use.
19 /*! \file
21 * \brief SayUnixTime application
23 * \author Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com>
25 * \ingroup applications
28 #include "asterisk.h"
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
32 #include "asterisk/file.h"
33 #include "asterisk/channel.h"
34 #include "asterisk/pbx.h"
35 #include "asterisk/module.h"
36 #include "asterisk/say.h"
37 #include "asterisk/app.h"
39 static char *app_sayunixtime = "SayUnixTime";
40 static char *app_datetime = "DateTime";
42 static char *sayunixtime_synopsis = "Says a specified time in a custom format";
44 static char *sayunixtime_descrip =
45 "SayUnixTime([unixtime][,[timezone][,format]])\n"
46 " unixtime - time, in seconds since Jan 1, 1970. May be negative.\n"
47 " defaults to now.\n"
48 " timezone - timezone, see /usr/share/zoneinfo for a list.\n"
49 " defaults to machine default.\n"
50 " format - a format the time is to be said in. See voicemail.conf.\n"
51 " defaults to \"ABdY 'digits/at' IMp\"\n";
52 static char *datetime_descrip =
53 "DateTime([unixtime][,[timezone][,format]])\n"
54 " unixtime - time, in seconds since Jan 1, 1970. May be negative.\n"
55 " defaults to now.\n"
56 " timezone - timezone, see /usr/share/zoneinfo for a list.\n"
57 " defaults to machine default.\n"
58 " format: - a format the time is to be said in. See voicemail.conf.\n"
59 " defaults to \"ABdY 'digits/at' IMp\"\n";
62 static int sayunixtime_exec(struct ast_channel *chan, void *data)
64 AST_DECLARE_APP_ARGS(args,
65 AST_APP_ARG(timeval);
66 AST_APP_ARG(timezone);
67 AST_APP_ARG(format);
69 char *parse;
70 int res = 0;
71 time_t unixtime;
73 if (!data)
74 return 0;
76 parse = ast_strdupa(data);
78 AST_STANDARD_APP_ARGS(args, parse);
80 ast_get_time_t(args.timeval, &unixtime, time(NULL), NULL);
82 if (chan->_state != AST_STATE_UP)
83 res = ast_answer(chan);
85 if (!res)
86 res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY,
87 chan->language, args.format, args.timezone);
89 return res;
92 static int unload_module(void)
94 int res;
96 res = ast_unregister_application(app_sayunixtime);
97 res |= ast_unregister_application(app_datetime);
99 return res;
102 static int load_module(void)
104 int res;
106 res = ast_register_application(app_sayunixtime, sayunixtime_exec, sayunixtime_synopsis, sayunixtime_descrip);
107 res |= ast_register_application(app_datetime, sayunixtime_exec, sayunixtime_synopsis, datetime_descrip);
109 return res;
112 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say time");