Sat Aug 6 00:39:21 2011

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: 40722 $")
00031 
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <unistd.h>
00035 #include <string.h>
00036 
00037 #include "asterisk/file.h"
00038 #include "asterisk/logger.h"
00039 #include "asterisk/options.h"
00040 #include "asterisk/channel.h"
00041 #include "asterisk/pbx.h"
00042 #include "asterisk/module.h"
00043 #include "asterisk/say.h"
00044 #include "asterisk/app.h"
00045 
00046 static char *app_sayunixtime = "SayUnixTime";
00047 static char *app_datetime = "DateTime";
00048 
00049 static char *sayunixtime_synopsis = "Says a specified time in a custom format";
00050 
00051 static char *sayunixtime_descrip =
00052 "SayUnixTime([unixtime][|[timezone][|format]])\n"
00053 "  unixtime: time, in seconds since Jan 1, 1970.  May be negative.\n"
00054 "              defaults to now.\n"
00055 "  timezone: timezone, see /usr/share/zoneinfo for a list.\n"
00056 "              defaults to machine default.\n"
00057 "  format:   a format the time is to be said in.  See voicemail.conf.\n"
00058 "              defaults to \"ABdY 'digits/at' IMp\"\n";
00059 static char *datetime_descrip =
00060 "DateTime([unixtime][|[timezone][|format]])\n"
00061 "  unixtime: time, in seconds since Jan 1, 1970.  May be negative.\n"
00062 "              defaults to now.\n"
00063 "  timezone: timezone, see /usr/share/zoneinfo for a list.\n"
00064 "              defaults to machine default.\n"
00065 "  format:   a format the time is to be said in.  See voicemail.conf.\n"
00066 "              defaults to \"ABdY 'digits/at' IMp\"\n";
00067 
00068 
00069 static int sayunixtime_exec(struct ast_channel *chan, void *data)
00070 {
00071    AST_DECLARE_APP_ARGS(args,
00072               AST_APP_ARG(timeval);
00073               AST_APP_ARG(timezone);
00074               AST_APP_ARG(format);
00075    );
00076    char *parse;
00077    int res = 0;
00078    struct ast_module_user *u;
00079    time_t unixtime;
00080    
00081    if (!data)
00082       return 0;
00083 
00084    parse = ast_strdupa(data);
00085 
00086    u = ast_module_user_add(chan);
00087 
00088    AST_STANDARD_APP_ARGS(args, parse);
00089 
00090    ast_get_time_t(args.timeval, &unixtime, time(NULL), NULL);
00091 
00092    if (chan->_state != AST_STATE_UP)
00093       res = ast_answer(chan);
00094 
00095    if (!res)
00096       res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY,
00097                       chan->language, args.format, args.timezone);
00098 
00099    ast_module_user_remove(u);
00100 
00101    return res;
00102 }
00103 
00104 static int unload_module(void)
00105 {
00106    int res;
00107    
00108    res = ast_unregister_application(app_sayunixtime);
00109    res |= ast_unregister_application(app_datetime);
00110 
00111    ast_module_user_hangup_all();
00112    
00113    return res;
00114 }
00115 
00116 static int load_module(void)
00117 {
00118    int res;
00119    
00120    res = ast_register_application(app_sayunixtime, sayunixtime_exec, sayunixtime_synopsis, sayunixtime_descrip);
00121    res |= ast_register_application(app_datetime, sayunixtime_exec, sayunixtime_synopsis, datetime_descrip);
00122    
00123    return res;
00124 }
00125 
00126 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say time");

Generated on Sat Aug 6 00:39:21 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7