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 /*** MODULEINFO
00029    <support_level>core</support_level>
00030  ***/
00031 
00032 #include "asterisk.h"
00033 
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 402819 $")
00035 
00036 #include "asterisk/file.h"
00037 #include "asterisk/channel.h"
00038 #include "asterisk/pbx.h"
00039 #include "asterisk/module.h"
00040 #include "asterisk/say.h"
00041 #include "asterisk/app.h"
00042 
00043 /*** DOCUMENTATION
00044    <application name="SayUnixTime" language="en_US">
00045       <synopsis>
00046          Says a specified time in a custom format.
00047       </synopsis>
00048       <syntax>
00049          <parameter name="unixtime" required="false">
00050             <para>time, in seconds since Jan 1, 1970.  May be negative. Defaults to now.</para>
00051          </parameter>
00052          <parameter name="timezone" required="false" >
00053             <para>timezone, see <directory>/usr/share/zoneinfo</directory> for a list. Defaults to machine default.</para>
00054          </parameter>
00055          <parameter name="format" required="false" >
00056             <para>a format the time is to be said in.  See <filename>voicemail.conf</filename>.
00057             Defaults to <literal>ABdY "digits/at" IMp</literal></para>
00058          </parameter>
00059          <parameter name="options" required="false">
00060              <optionlist>
00061                <option name="j">
00062                   <para>Allow the calling user to dial digits to jump to that extension.
00063                   This option is automatically enabled if
00064                   <variable>SAY_DTMF_INTERRUPT</variable> is present on the channel and
00065                   set to 'true' (case insensitive)</para>
00066                </option>
00067             </optionlist>
00068          </parameter>
00069       </syntax>
00070       <description>
00071          <para>Uses some of the sound files stored in <directory>/var/lib/asterisk/sounds</directory> to construct a phrase 
00072          saying the specified date and/or time in the specified format. </para>
00073       </description>
00074       <see-also>
00075          <ref type="function">STRFTIME</ref>
00076          <ref type="function">STRPTIME</ref>
00077          <ref type="function">IFTIME</ref>
00078       </see-also>
00079    </application>
00080    <application name="DateTime" language="en_US">
00081       <synopsis>
00082          Says a specified time in a custom format.
00083       </synopsis>
00084       <syntax>
00085          <parameter name="unixtime">
00086             <para>time, in seconds since Jan 1, 1970.  May be negative. Defaults to now.</para>
00087          </parameter>
00088          <parameter name="timezone">
00089             <para>timezone, see <filename>/usr/share/zoneinfo</filename> for a list. Defaults to machine default.</para>
00090          </parameter>
00091          <parameter name="format">
00092             <para>a format the time is to be said in.  See <filename>voicemail.conf</filename>.
00093             Defaults to <literal>ABdY "digits/at" IMp</literal></para>
00094          </parameter>
00095       </syntax>
00096       <description>
00097          <para>Say the date and time in a specified format.</para>
00098       </description>
00099    </application>
00100 
00101  ***/
00102 
00103 enum {
00104    OPT_JUMP =          (1 << 0),
00105 };
00106 
00107 enum {
00108    OPT_ARG_JUMP = 0,
00109    /* note: this entry _MUST_ be the last one in the enum */
00110    OPT_ARG_ARRAY_SIZE,
00111 };
00112 
00113 AST_APP_OPTIONS(sayunixtime_exec_options, BEGIN_OPTIONS
00114    AST_APP_OPTION_ARG('j', OPT_JUMP, OPT_ARG_JUMP),
00115 END_OPTIONS );
00116 
00117 static char *app_sayunixtime = "SayUnixTime";
00118 static char *app_datetime = "DateTime";
00119 
00120 static int sayunixtime_exec(struct ast_channel *chan, const char *data)
00121 {
00122    AST_DECLARE_APP_ARGS(args,
00123       AST_APP_ARG(timeval);
00124       AST_APP_ARG(timezone);
00125       AST_APP_ARG(format);
00126       AST_APP_ARG(options);
00127    );
00128    char *parse;
00129    int res = 0;
00130    time_t unixtime;
00131    /* New default behavior is do not jump on key pressed */
00132    const char * haltondigits = AST_DIGIT_NONE;
00133    struct ast_flags64 opts = { 0, };
00134    char *opt_args[OPT_ARG_ARRAY_SIZE];
00135    const char *interrupt_string;
00136 
00137    if (!data) {
00138       return 0;
00139    }
00140 
00141    parse = ast_strdupa(data);
00142 
00143    AST_STANDARD_APP_ARGS(args, parse);
00144 
00145    /* check if we had the 'j' jump flag in option list */
00146    if (!ast_strlen_zero(args.options)) {
00147       ast_app_parse_options64(sayunixtime_exec_options, &opts, opt_args, args.options);
00148       if (ast_test_flag64(&opts, OPT_JUMP)){
00149          haltondigits = AST_DIGIT_ANY;
00150       }
00151    }
00152 
00153    /* Check if 'SAY_DTMF_INTERRUPT' is true and apply the same behavior as the j flag. */
00154    ast_channel_lock(chan);
00155    interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
00156    if (ast_true(interrupt_string)) {
00157       haltondigits = AST_DIGIT_ANY;
00158    }
00159    ast_channel_unlock(chan);
00160 
00161    ast_get_time_t(ast_strlen_zero(args.timeval) ? NULL : args.timeval, &unixtime, time(NULL), NULL);
00162 
00163    if (ast_channel_state(chan) != AST_STATE_UP) {
00164       res = ast_answer(chan);
00165    }
00166 
00167    if (!res) {
00168       res = ast_say_date_with_format(chan, unixtime, haltondigits,
00169                       ast_channel_language(chan), ast_strlen_zero(args.format) ? NULL : args.format, ast_strlen_zero(args.timezone) ? NULL : args.timezone);
00170    }
00171 
00172    return res;
00173 }
00174 
00175 static int unload_module(void)
00176 {
00177    int res;
00178    
00179    res = ast_unregister_application(app_sayunixtime);
00180    res |= ast_unregister_application(app_datetime);
00181    
00182    return res;
00183 }
00184 
00185 static int load_module(void)
00186 {
00187    int res;
00188    
00189    res = ast_register_application_xml(app_sayunixtime, sayunixtime_exec);
00190    res |= ast_register_application_xml(app_datetime, sayunixtime_exec);
00191    
00192    return res;
00193 }
00194 
00195 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say time");

Generated on Thu Apr 16 06:27:12 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6