We now can have a reference to a filename inside a <see-also> tag.
[asterisk/asterisk.git] / apps / app_sayunixtime.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (c) 2003, 2006 Tilghman Lesher.  All rights reserved.
5  * Copyright (c) 2006 Digium, Inc.
6  *
7  * Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com>
8  *
9  * This code is released by the author with no restrictions on usage.
10  *
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.
16  *
17  */
18
19 /*! \file
20  *
21  * \brief SayUnixTime application
22  *
23  * \author Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com>
24  * 
25  * \ingroup applications
26  */
27
28 #include "asterisk.h"
29
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
31
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"
38
39 /*** DOCUMENTATION
40         <application name="SayUnixTime" language="en_US">
41                 <synopsis>
42                         Says a specified time in a custom format.
43                 </synopsis>
44                 <syntax>
45                         <parameter name="unixtime">
46                                 <para>time, in seconds since Jan 1, 1970.  May be negative. Defaults to now.</para>
47                         </parameter>
48                         <parameter name="timezone">
49                                 <para>timezone, see <directory>/usr/share/zoneinfo</directory> for a list. Defaults to machine default.</para>
50                         </parameter>
51                         <parameter name="format">
52                                 <para>a format the time is to be said in.  See <filename>voicemail.conf</filename>.
53                                 Defaults to <literal>ABdY "digits/at" IMp</literal></para>
54                         </parameter>
55                 </syntax>
56                 <description>
57                         <para>Uses some of the sound files stored in <directory>/var/lib/asterisk/sounds</directory> to construct a phrase 
58                         saying the specified date and/or time in the specified format. </para>
59                 </description>
60         </application>
61         <application name="DateTime" language="en_US">
62                 <synopsis>
63                         Says a specified time in a custom format.
64                 </synopsis>
65                 <syntax>
66                         <parameter name="unixtime">
67                                 <para>time, in seconds since Jan 1, 1970.  May be negative. Defaults to now.</para>
68                         </parameter>
69                         <parameter name="timezone">
70                                 <para>timezone, see <filename>/usr/share/zoneinfo</filename> for a list. Defaults to machine default.</para>
71                         </parameter>
72                         <parameter name="format">
73                                 <para>a format the time is to be said in.  See <filename>voicemail.conf</filename>.
74                                 Defaults to <literal>ABdY "digits/at" IMp</literal></para>
75                         </parameter>
76                 </syntax>
77                 <description>
78                         <para>Say the date and time in a specified format.</para>
79                 </description>
80         </application>
81
82  ***/
83
84 static char *app_sayunixtime = "SayUnixTime";
85 static char *app_datetime = "DateTime";
86
87 static int sayunixtime_exec(struct ast_channel *chan, void *data)
88 {
89         AST_DECLARE_APP_ARGS(args,
90                 AST_APP_ARG(timeval);
91                 AST_APP_ARG(timezone);
92                 AST_APP_ARG(format);
93         );
94         char *parse;
95         int res = 0;
96         time_t unixtime;
97         
98         if (!data)
99                 return 0;
100
101         parse = ast_strdupa(data);
102
103         AST_STANDARD_APP_ARGS(args, parse);
104
105         ast_get_time_t(args.timeval, &unixtime, time(NULL), NULL);
106
107         if (chan->_state != AST_STATE_UP)
108                 res = ast_answer(chan);
109
110         if (!res)
111                 res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY,
112                                                chan->language, args.format, args.timezone);
113
114         return res;
115 }
116
117 static int unload_module(void)
118 {
119         int res;
120         
121         res = ast_unregister_application(app_sayunixtime);
122         res |= ast_unregister_application(app_datetime);
123         
124         return res;
125 }
126
127 static int load_module(void)
128 {
129         int res;
130         
131         res = ast_register_application_xml(app_sayunixtime, sayunixtime_exec);
132         res |= ast_register_application_xml(app_datetime, sayunixtime_exec);
133         
134         return res;
135 }
136
137 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say time");