Asterisk - The Open Source Telephony Project GIT-master-f36a736
app_sayunixtime.c
Go to the documentation of this file.
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/*** MODULEINFO
29 <support_level>core</support_level>
30 ***/
31
32#include "asterisk.h"
33
34#include "asterisk/file.h"
35#include "asterisk/channel.h"
36#include "asterisk/pbx.h"
37#include "asterisk/module.h"
38#include "asterisk/say.h"
39#include "asterisk/app.h"
40
41/*** DOCUMENTATION
42 <application name="SayUnixTime" language="en_US">
43 <synopsis>
44 Says a specified time in a custom format.
45 </synopsis>
46 <syntax>
47 <parameter name="unixtime" required="false">
48 <para>time, in seconds since Jan 1, 1970. May be negative. Defaults to now.</para>
49 </parameter>
50 <parameter name="timezone" required="false" >
51 <para>timezone, see <directory>/usr/share/zoneinfo</directory> for a list. Defaults to machine default.</para>
52 </parameter>
53 <parameter name="format" required="false" >
54 <para>a format the time is to be said in. See <filename>voicemail.conf</filename>.
55 Defaults to <literal>ABdY "digits/at" IMp</literal></para>
56 </parameter>
57 <parameter name="options" required="false">
58 <optionlist>
59 <option name="j">
60 <para>Allow the calling user to dial digits to jump to that extension.
61 This option is automatically enabled if
62 <variable>SAY_DTMF_INTERRUPT</variable> is present on the channel and
63 set to 'true' (case insensitive)</para>
64 </option>
65 </optionlist>
66 </parameter>
67 </syntax>
68 <description>
69 <para>Uses some of the sound files stored in <directory>/var/lib/asterisk/sounds</directory> to construct a phrase
70 saying the specified date and/or time in the specified format. </para>
71 </description>
72 <see-also>
73 <ref type="function">STRFTIME</ref>
74 <ref type="function">STRPTIME</ref>
75 <ref type="function">IFTIME</ref>
76 </see-also>
77 </application>
78 <application name="DateTime" language="en_US">
79 <synopsis>
80 Says a specified time in a custom format.
81 </synopsis>
82 <syntax>
83 <parameter name="unixtime">
84 <para>time, in seconds since Jan 1, 1970. May be negative. Defaults to now.</para>
85 </parameter>
86 <parameter name="timezone">
87 <para>timezone, see <filename>/usr/share/zoneinfo</filename> for a list. Defaults to machine default.</para>
88 </parameter>
89 <parameter name="format">
90 <para>a format the time is to be said in. See <filename>voicemail.conf</filename>.
91 Defaults to <literal>ABdY "digits/at" IMp</literal></para>
92 </parameter>
93 </syntax>
94 <description>
95 <para>Say the date and time in a specified format.</para>
96 </description>
97 </application>
98
99 ***/
100
101enum {
102 OPT_JUMP = (1 << 0),
103};
104
105enum {
107 /* note: this entry _MUST_ be the last one in the enum */
109};
110
114
115static char *app_sayunixtime = "SayUnixTime";
116static char *app_datetime = "DateTime";
117
118static int sayunixtime_exec(struct ast_channel *chan, const char *data)
119{
121 AST_APP_ARG(timeval);
122 AST_APP_ARG(timezone);
123 AST_APP_ARG(format);
125 );
126 char *parse;
127 int res = 0;
128 time_t unixtime;
129 /* New default behavior is do not jump on key pressed */
130 const char * haltondigits = AST_DIGIT_NONE;
131 struct ast_flags64 opts = { 0, };
132 char *opt_args[OPT_ARG_ARRAY_SIZE];
133 const char *interrupt_string;
134
135 if (!data) {
136 return 0;
137 }
138
139 parse = ast_strdupa(data);
140
142
143 /* check if we had the 'j' jump flag in option list */
144 if (!ast_strlen_zero(args.options)) {
145 ast_app_parse_options64(sayunixtime_exec_options, &opts, opt_args, args.options);
146 if (ast_test_flag64(&opts, OPT_JUMP)){
147 haltondigits = AST_DIGIT_ANY;
148 }
149 }
150
151 /* Check if 'SAY_DTMF_INTERRUPT' is true and apply the same behavior as the j flag. */
152 ast_channel_lock(chan);
153 interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
154 if (ast_true(interrupt_string)) {
155 haltondigits = AST_DIGIT_ANY;
156 }
157 ast_channel_unlock(chan);
158
159 ast_get_time_t(ast_strlen_zero(args.timeval) ? NULL : args.timeval, &unixtime, time(NULL), NULL);
160
161 if (ast_channel_state(chan) != AST_STATE_UP) {
162 res = ast_answer(chan);
163 }
164
165 if (!res) {
166 res = ast_say_date_with_format(chan, unixtime, haltondigits,
167 ast_channel_language(chan), ast_strlen_zero(args.format) ? NULL : args.format, ast_strlen_zero(args.timezone) ? NULL : args.timezone);
168 }
169
170 return res;
171}
172
173static int unload_module(void)
174{
175 int res;
176
179
180 return res;
181}
182
183static int load_module(void)
184{
185 int res;
186
189
190 return res;
191}
192
static const struct ast_app_option sayunixtime_exec_options[128]
static int sayunixtime_exec(struct ast_channel *chan, const char *data)
@ OPT_JUMP
@ OPT_ARG_JUMP
@ OPT_ARG_ARRAY_SIZE
static char * app_sayunixtime
static char * app_datetime
static int load_module(void)
static int unload_module(void)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
General Asterisk PBX channel definitions.
#define ast_channel_lock(chan)
Definition: channel.h:2968
const char * ast_channel_language(const struct ast_channel *chan)
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2824
#define ast_channel_unlock(chan)
Definition: channel.h:2969
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_STATE_UP
Definition: channelstate.h:42
Generic File Format Support. Should be included by clients of the file handling routines....
#define AST_DIGIT_NONE
Definition: file.h:47
#define AST_DIGIT_ANY
Definition: file.h:48
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
#define END_OPTIONS
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
#define AST_APP_OPTION_ARG(option, flagno, argno)
Declares an application option that accepts an argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define BEGIN_OPTIONS
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
int ast_app_parse_options64(const struct ast_app_option *options, struct ast_flags64 *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: main/app.c:3071
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:581
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640
Core PBX routines and definitions.
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
#define NULL
Definition: resample.c:96
Say numbers and dates (maybe words one day too)
SAY_EXTERN int(* ast_say_date_with_format)(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezone) SAY_INIT(ast_say_date_with_format)
Definition: say.h:208
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199
int ast_get_time_t(const char *src, time_t *dst, time_t _default, int *consumed)
Parse a time (integer) string.
Definition: utils.c:2446
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Main Channel structure associated with a channel.
Structure used to handle a large number of boolean flags == used only in app_dial?
Definition: utils.h:204
const char * args
static struct test_options options
#define ast_test_flag64(p, flag)
Definition: utils.h:120