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.
21 * \brief SayUnixTime application
23 * \author Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com>
25 * \ingroup applications
30 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
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"
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"
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
,
73 AST_APP_ARG(timezone
);
78 struct ast_module_user
*u
;
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
);
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
);
104 static int unload_module(void)
108 res
= ast_unregister_application(app_sayunixtime
);
109 res
|= ast_unregister_application(app_datetime
);
111 ast_module_user_hangup_all();
116 static int load_module(void)
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
);
126 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Say time");