update comment to match the state of the code
[asterisk-bristuff.git] / apps / app_sayunixtime.c
blob2e9c9b323546e00d7a3bca8da2148aba2583ec3d
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 <stdio.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <string.h>
37 #include "asterisk/file.h"
38 #include "asterisk/logger.h"
39 #include "asterisk/options.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/module.h"
43 #include "asterisk/say.h"
44 #include "asterisk/app.h"
46 static char *app_sayunixtime = "SayUnixTime";
47 static char *app_datetime = "DateTime";
49 static char *sayunixtime_synopsis = "Says a specified time in a custom format";
51 static char *sayunixtime_descrip =
52 "SayUnixTime([unixtime][|[timezone][|format]])\n"
53 " unixtime: time, in seconds since Jan 1, 1970. May be negative.\n"
54 " defaults to now.\n"
55 " timezone: timezone, see /usr/share/zoneinfo for a list.\n"
56 " defaults to machine default.\n"
57 " format: a format the time is to be said in. See voicemail.conf.\n"
58 " defaults to \"ABdY 'digits/at' IMp\"\n";
59 static char *datetime_descrip =
60 "DateTime([unixtime][|[timezone][|format]])\n"
61 " unixtime: time, in seconds since Jan 1, 1970. May be negative.\n"
62 " defaults to now.\n"
63 " timezone: timezone, see /usr/share/zoneinfo for a list.\n"
64 " defaults to machine default.\n"
65 " format: a format the time is to be said in. See voicemail.conf.\n"
66 " defaults to \"ABdY 'digits/at' IMp\"\n";
69 static int sayunixtime_exec(struct ast_channel *chan, void *data)
71 AST_DECLARE_APP_ARGS(args,
72 AST_APP_ARG(timeval);
73 AST_APP_ARG(timezone);
74 AST_APP_ARG(format);
76 char *parse;
77 int res = 0;
78 struct ast_module_user *u;
79 time_t unixtime;
81 if (!data)
82 return 0;
84 parse = ast_strdupa(data);
86 u = ast_module_user_add(chan);
88 AST_STANDARD_APP_ARGS(args, parse);
90 ast_get_time_t(args.timeval, &unixtime, time(NULL), NULL);
92 if (chan->_state != AST_STATE_UP)
93 res = ast_answer(chan);
95 if (!res)
96 res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY,
97 chan->language, args.format, args.timezone);
99 ast_module_user_remove(u);
101 return res;
104 static int unload_module(void)
106 int res;
108 res = ast_unregister_application(app_sayunixtime);
109 res |= ast_unregister_application(app_datetime);
111 ast_module_user_hangup_all();
113 return res;
116 static int load_module(void)
118 int res;
120 res = ast_register_application(app_sayunixtime, sayunixtime_exec, sayunixtime_synopsis, sayunixtime_descrip);
121 res |= ast_register_application(app_datetime, sayunixtime_exec, sayunixtime_synopsis, datetime_descrip);
123 return res;
126 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say time");