Wed Aug 18 22:33:42 2010

Asterisk developer's documentation


app_sayunixtime.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (c) 2003, 2006 Tilghman Lesher.  All rights reserved.
00005  * Copyright (c) 2006 Digium, Inc.
00006  *
00007  * Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com>
00008  *
00009  * This code is released by the author with no restrictions on usage.
00010  *
00011  * See http://www.asterisk.org for more information about
00012  * the Asterisk project. Please do not directly contact
00013  * any of the maintainers of this project for assistance;
00014  * the project provides a web site, mailing lists and IRC
00015  * channels for your use.
00016  *
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief SayUnixTime application
00022  *
00023  * \author Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com>
00024  * 
00025  * \ingroup applications
00026  */
00027 
00028 #include "asterisk.h"
00029 
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 89512 $")
00031 
00032 #include "asterisk/file.h"
00033 #include "asterisk/channel.h"
00034 #include "asterisk/pbx.h"
00035 #include "asterisk/module.h"
00036 #include "asterisk/say.h"
00037 #include "asterisk/app.h"
00038 
00039 static char *app_sayunixtime = "SayUnixTime";
00040 static char *app_datetime = "DateTime";
00041 
00042 static char *sayunixtime_synopsis = "Says a specified time in a custom format";
00043 
00044 static char *sayunixtime_descrip =
00045 "SayUnixTime([unixtime][,[timezone][,format]])\n"
00046 "  unixtime  - time, in seconds since Jan 1, 1970.  May be negative.\n"
00047 "              defaults to now.\n"
00048 "  timezone  - timezone, see /usr/share/zoneinfo for a list.\n"
00049 "              defaults to machine default.\n"
00050 "  format    - a format the time is to be said in.  See voicemail.conf.\n"
00051 "              defaults to \"ABdY 'digits/at' IMp\"\n";
00052 static char *datetime_descrip =
00053 "DateTime([unixtime][,[timezone][,format]])\n"
00054 "  unixtime  - time, in seconds since Jan 1, 1970.  May be negative.\n"
00055 "              defaults to now.\n"
00056 "  timezone  - timezone, see /usr/share/zoneinfo for a list.\n"
00057 "              defaults to machine default.\n"
00058 "  format:   - a format the time is to be said in.  See voicemail.conf.\n"
00059 "              defaults to \"ABdY 'digits/at' IMp\"\n";
00060 
00061 
00062 static int sayunixtime_exec(struct ast_channel *chan, void *data)
00063 {
00064    AST_DECLARE_APP_ARGS(args,
00065       AST_APP_ARG(timeval);
00066       AST_APP_ARG(timezone);
00067       AST_APP_ARG(format);
00068    );
00069    char *parse;
00070    int res = 0;
00071    time_t unixtime;
00072    
00073    if (!data)
00074       return 0;
00075 
00076    parse = ast_strdupa(data);
00077 
00078    AST_STANDARD_APP_ARGS(args, parse);
00079 
00080    ast_get_time_t(args.timeval, &unixtime, time(NULL), NULL);
00081 
00082    if (chan->_state != AST_STATE_UP)
00083       res = ast_answer(chan);
00084 
00085    if (!res)
00086       res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY,
00087                       chan->language, args.format, args.timezone);
00088 
00089    return res;
00090 }
00091 
00092 static int unload_module(void)
00093 {
00094    int res;
00095    
00096    res = ast_unregister_application(app_sayunixtime);
00097    res |= ast_unregister_application(app_datetime);
00098    
00099    return res;
00100 }
00101 
00102 static int load_module(void)
00103 {
00104    int res;
00105    
00106    res = ast_register_application(app_sayunixtime, sayunixtime_exec, sayunixtime_synopsis, sayunixtime_descrip);
00107    res |= ast_register_application(app_datetime, sayunixtime_exec, sayunixtime_synopsis, datetime_descrip);
00108    
00109    return res;
00110 }
00111 
00112 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say time");

Generated on Wed Aug 18 22:33:42 2010 for Asterisk - the Open Source PBX by  doxygen 1.4.7