diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-01-16 15:51:43 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-01-16 15:51:43 +0000 |
commit | 52acc4c45786fc04da9536c2801eb2b483cc2009 (patch) | |
tree | 3e0b68760b7b6d49c72de4fd5b747ed4d5726ad3 /apps/app_sayunixtime.c | |
parent | 5d9d64e584ec5220835eb10a124b555d449fa3d3 (diff) | |
parent | caebf8461f9849f484eb5bbd649880e457c20e31 (diff) |
Creating tag for the release of asterisk-1.4.23-rc4
git-svn-id: http://svn.digium.com/svn/asterisk/tags/1.4.23-rc4@168755 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_sayunixtime.c')
-rw-r--r-- | apps/app_sayunixtime.c | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/apps/app_sayunixtime.c b/apps/app_sayunixtime.c new file mode 100644 index 000000000..2e9c9b323 --- /dev/null +++ b/apps/app_sayunixtime.c @@ -0,0 +1,126 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (c) 2003, 2006 Tilghman Lesher. All rights reserved. + * Copyright (c) 2006 Digium, Inc. + * + * Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com> + * + * This code is released by the author with no restrictions on usage. + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + */ + +/*! \file + * + * \brief SayUnixTime application + * + * \author Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com> + * + * \ingroup applications + */ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +#include "asterisk/file.h" +#include "asterisk/logger.h" +#include "asterisk/options.h" +#include "asterisk/channel.h" +#include "asterisk/pbx.h" +#include "asterisk/module.h" +#include "asterisk/say.h" +#include "asterisk/app.h" + +static char *app_sayunixtime = "SayUnixTime"; +static char *app_datetime = "DateTime"; + +static char *sayunixtime_synopsis = "Says a specified time in a custom format"; + +static char *sayunixtime_descrip = +"SayUnixTime([unixtime][|[timezone][|format]])\n" +" unixtime: time, in seconds since Jan 1, 1970. May be negative.\n" +" defaults to now.\n" +" timezone: timezone, see /usr/share/zoneinfo for a list.\n" +" defaults to machine default.\n" +" format: a format the time is to be said in. See voicemail.conf.\n" +" defaults to \"ABdY 'digits/at' IMp\"\n"; +static char *datetime_descrip = +"DateTime([unixtime][|[timezone][|format]])\n" +" unixtime: time, in seconds since Jan 1, 1970. May be negative.\n" +" defaults to now.\n" +" timezone: timezone, see /usr/share/zoneinfo for a list.\n" +" defaults to machine default.\n" +" format: a format the time is to be said in. See voicemail.conf.\n" +" defaults to \"ABdY 'digits/at' IMp\"\n"; + + +static int sayunixtime_exec(struct ast_channel *chan, void *data) +{ + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(timeval); + AST_APP_ARG(timezone); + AST_APP_ARG(format); + ); + char *parse; + int res = 0; + struct ast_module_user *u; + time_t unixtime; + + if (!data) + return 0; + + parse = ast_strdupa(data); + + u = ast_module_user_add(chan); + + AST_STANDARD_APP_ARGS(args, parse); + + ast_get_time_t(args.timeval, &unixtime, time(NULL), NULL); + + if (chan->_state != AST_STATE_UP) + res = ast_answer(chan); + + if (!res) + res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY, + chan->language, args.format, args.timezone); + + ast_module_user_remove(u); + + return res; +} + +static int unload_module(void) +{ + int res; + + res = ast_unregister_application(app_sayunixtime); + res |= ast_unregister_application(app_datetime); + + ast_module_user_hangup_all(); + + return res; +} + +static int load_module(void) +{ + int res; + + res = ast_register_application(app_sayunixtime, sayunixtime_exec, sayunixtime_synopsis, sayunixtime_descrip); + res |= ast_register_application(app_datetime, sayunixtime_exec, sayunixtime_synopsis, datetime_descrip); + + return res; +} + +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say time"); |