Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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 <since>
44 <version>0.7.0</version>
45 </since>
46 <synopsis>
47 Says a specified time in a custom format.
48 </synopsis>
49 <syntax>
50 <parameter name="unixtime" required="false">
51 <para>time, in seconds since Jan 1, 1970. May be negative. Defaults to now.</para>
52 </parameter>
53 <parameter name="timezone" required="false" >
54 <para>timezone, see <directory>/usr/share/zoneinfo</directory> for a list. Defaults to machine default.</para>
55 </parameter>
56 <parameter name="format" required="false" >
57 <para>a format the time is to be said in. See <filename>voicemail.conf</filename>.
58 Defaults to <literal>ABdY "digits/at" IMp</literal></para>
59 </parameter>
60 <parameter name="options" required="false">
61 <optionlist>
62 <option name="j">
63 <para>Allow the calling user to dial digits to jump to that extension.
64 This option is automatically enabled if
65 <variable>SAY_DTMF_INTERRUPT</variable> is present on the channel and
66 set to 'true' (case insensitive)</para>
67 </option>
68 </optionlist>
69 </parameter>
70 </syntax>
71 <description>
72 <para>Uses some of the sound files stored in <directory>/var/lib/asterisk/sounds</directory> to construct a phrase
73 saying the specified date and/or time in the specified format. </para>
74 </description>
75 <see-also>
76 <ref type="function">STRFTIME</ref>
77 <ref type="function">STRPTIME</ref>
78 <ref type="function">IFTIME</ref>
79 </see-also>
80 </application>
81 <application name="DateTime" language="en_US">
82 <since>
83 <version>0.2.0</version>
84 </since>
85 <synopsis>
86 Says a specified time in a custom format.
87 </synopsis>
88 <syntax>
89 <parameter name="unixtime">
90 <para>time, in seconds since Jan 1, 1970. May be negative. Defaults to now.</para>
91 </parameter>
92 <parameter name="timezone">
93 <para>timezone, see <filename>/usr/share/zoneinfo</filename> for a list. Defaults to machine default.</para>
94 </parameter>
95 <parameter name="format">
96 <para>a format the time is to be said in. See <filename>voicemail.conf</filename>.
97 Defaults to <literal>ABdY "digits/at" IMp</literal></para>
98 </parameter>
99 </syntax>
100 <description>
101 <para>Say the date and time in a specified format.</para>
102 </description>
103 </application>
104
105 ***/
106
107enum {
108 OPT_JUMP = (1 << 0),
109};
110
111enum {
113 /* note: this entry _MUST_ be the last one in the enum */
115};
116
120
121static char *app_sayunixtime = "SayUnixTime";
122static char *app_datetime = "DateTime";
123
124static int sayunixtime_exec(struct ast_channel *chan, const char *data)
125{
127 AST_APP_ARG(timeval);
128 AST_APP_ARG(timezone);
129 AST_APP_ARG(format);
131 );
132 char *parse;
133 int res = 0;
134 time_t unixtime;
135 /* New default behavior is do not jump on key pressed */
136 const char * haltondigits = AST_DIGIT_NONE;
137 struct ast_flags64 opts = { 0, };
138 char *opt_args[OPT_ARG_ARRAY_SIZE];
139 const char *interrupt_string;
140
141 if (!data) {
142 return 0;
143 }
144
145 parse = ast_strdupa(data);
146
148
149 /* check if we had the 'j' jump flag in option list */
150 if (!ast_strlen_zero(args.options)) {
151 ast_app_parse_options64(sayunixtime_exec_options, &opts, opt_args, args.options);
152 if (ast_test_flag64(&opts, OPT_JUMP)){
153 haltondigits = AST_DIGIT_ANY;
154 }
155 }
156
157 /* Check if 'SAY_DTMF_INTERRUPT' is true and apply the same behavior as the j flag. */
158 ast_channel_lock(chan);
159 interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
160 if (ast_true(interrupt_string)) {
161 haltondigits = AST_DIGIT_ANY;
162 }
163 ast_channel_unlock(chan);
164
165 ast_get_time_t(ast_strlen_zero(args.timeval) ? NULL : args.timeval, &unixtime, time(NULL), NULL);
166
167 if (ast_channel_state(chan) != AST_STATE_UP) {
168 res = ast_answer(chan);
169 }
170
171 if (!res) {
172 res = ast_say_date_with_format(chan, unixtime, haltondigits,
173 ast_channel_language(chan), ast_strlen_zero(args.format) ? NULL : args.format, ast_strlen_zero(args.timezone) ? NULL : args.timezone);
174 }
175
176 return res;
177}
178
179static int unload_module(void)
180{
181 int res;
182
185
186 return res;
187}
188
189static int load_module(void)
190{
191 int res;
192
195
196 return res;
197}
198
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:2970
const char * ast_channel_language(const struct ast_channel *chan)
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2834
#define ast_channel_unlock(chan)
Definition: channel.h:2971
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