Wed Jan 8 2020 09:49:40

Asterisk developer's documentation


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 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
35 
36 #include "asterisk/file.h"
37 #include "asterisk/channel.h"
38 #include "asterisk/pbx.h"
39 #include "asterisk/module.h"
40 #include "asterisk/say.h"
41 #include "asterisk/app.h"
42 
43 /*** DOCUMENTATION
44  <application name="SayUnixTime" language="en_US">
45  <synopsis>
46  Says a specified time in a custom format.
47  </synopsis>
48  <syntax>
49  <parameter name="unixtime">
50  <para>time, in seconds since Jan 1, 1970. May be negative. Defaults to now.</para>
51  </parameter>
52  <parameter name="timezone">
53  <para>timezone, see <directory>/usr/share/zoneinfo</directory> for a list. Defaults to machine default.</para>
54  </parameter>
55  <parameter name="format">
56  <para>a format the time is to be said in. See <filename>voicemail.conf</filename>.
57  Defaults to <literal>ABdY "digits/at" IMp</literal></para>
58  </parameter>
59  </syntax>
60  <description>
61  <para>Uses some of the sound files stored in <directory>/var/lib/asterisk/sounds</directory> to construct a phrase
62  saying the specified date and/or time in the specified format. </para>
63  </description>
64  <see-also>
65  <ref type="function">STRFTIME</ref>
66  <ref type="function">STRPTIME</ref>
67  <ref type="function">IFTIME</ref>
68  </see-also>
69  </application>
70  <application name="DateTime" language="en_US">
71  <synopsis>
72  Says a specified time in a custom format.
73  </synopsis>
74  <syntax>
75  <parameter name="unixtime">
76  <para>time, in seconds since Jan 1, 1970. May be negative. Defaults to now.</para>
77  </parameter>
78  <parameter name="timezone">
79  <para>timezone, see <filename>/usr/share/zoneinfo</filename> for a list. Defaults to machine default.</para>
80  </parameter>
81  <parameter name="format">
82  <para>a format the time is to be said in. See <filename>voicemail.conf</filename>.
83  Defaults to <literal>ABdY "digits/at" IMp</literal></para>
84  </parameter>
85  </syntax>
86  <description>
87  <para>Say the date and time in a specified format.</para>
88  </description>
89  </application>
90 
91  ***/
92 
93 static char *app_sayunixtime = "SayUnixTime";
94 static char *app_datetime = "DateTime";
95 
96 static int sayunixtime_exec(struct ast_channel *chan, const char *data)
97 {
99  AST_APP_ARG(timeval);
100  AST_APP_ARG(timezone);
102  );
103  char *parse;
104  int res = 0;
105  time_t unixtime;
106 
107  if (!data)
108  return 0;
109 
110  parse = ast_strdupa(data);
111 
112  AST_STANDARD_APP_ARGS(args, parse);
113 
114  ast_get_time_t(args.timeval, &unixtime, time(NULL), NULL);
115 
116  if (chan->_state != AST_STATE_UP)
117  res = ast_answer(chan);
118 
119  if (!res)
120  res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY,
121  chan->language, args.format, args.timezone);
122 
123  return res;
124 }
125 
126 static int unload_module(void)
127 {
128  int res;
129 
130  res = ast_unregister_application(app_sayunixtime);
131  res |= ast_unregister_application(app_datetime);
132 
133  return res;
134 }
135 
136 static int load_module(void)
137 {
138  int res;
139 
140  res = ast_register_application_xml(app_sayunixtime, sayunixtime_exec);
141  res |= ast_register_application_xml(app_datetime, sayunixtime_exec);
142 
143  return res;
144 }
145 
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk main include file. File version handling, generic pbx functions.
static char * app_sayunixtime
#define AST_DIGIT_ANY
Definition: file.h:47
static int sayunixtime_exec(struct ast_channel *chan, const char *data)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static char * app_datetime
int ast_get_time_t(const char *src, time_t *dst, time_t _default, int *consumed)
get values from config variables.
Definition: utils.c:2118
General Asterisk PBX channel definitions.
Core PBX routines and definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static struct @350 args
enum ast_channel_state _state
Definition: channel.h:839
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
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:168
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:3086
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
Say numbers and dates (maybe words one day too)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
static snd_pcm_format_t format
Definition: chan_alsa.c:93
static int unload_module(void)
const ast_string_field language
Definition: channel.h:787
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
static int load_module(void)