Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "asterisk.h"
00033
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 356042 $")
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
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 enum {
00101 OPT_JUMP = (1 << 0),
00102 };
00103
00104 enum {
00105 OPT_ARG_JUMP = 0,
00106
00107 OPT_ARG_ARRAY_SIZE,
00108 };
00109
00110 AST_APP_OPTIONS(sayunixtime_exec_options, BEGIN_OPTIONS
00111 AST_APP_OPTION_ARG('j', OPT_JUMP, OPT_ARG_JUMP),
00112 END_OPTIONS );
00113
00114 static char *app_sayunixtime = "SayUnixTime";
00115 static char *app_datetime = "DateTime";
00116
00117 static int sayunixtime_exec(struct ast_channel *chan, const char *data)
00118 {
00119 AST_DECLARE_APP_ARGS(args,
00120 AST_APP_ARG(timeval);
00121 AST_APP_ARG(timezone);
00122 AST_APP_ARG(format);
00123 AST_APP_ARG(options);
00124 );
00125 char *parse;
00126 int res = 0;
00127 time_t unixtime;
00128
00129 const char * haltondigits = AST_DIGIT_NONE;
00130 struct ast_flags64 opts = { 0, };
00131 char *opt_args[OPT_ARG_ARRAY_SIZE];
00132
00133 if (!data) {
00134 return 0;
00135 }
00136
00137 parse = ast_strdupa(data);
00138
00139 AST_STANDARD_APP_ARGS(args, parse);
00140
00141
00142 if (!ast_strlen_zero(args.options)) {
00143 ast_app_parse_options64(sayunixtime_exec_options, &opts, opt_args, args.options);
00144 if (ast_test_flag64(&opts, OPT_JUMP)){
00145 haltondigits = AST_DIGIT_ANY;
00146 }
00147 }
00148
00149 ast_get_time_t(ast_strlen_zero(args.timeval) ? NULL : args.timeval, &unixtime, time(NULL), NULL);
00150
00151 if (ast_channel_state(chan) != AST_STATE_UP) {
00152 res = ast_answer(chan);
00153 }
00154
00155 if (!res) {
00156 res = ast_say_date_with_format(chan, unixtime, haltondigits,
00157 ast_channel_language(chan), ast_strlen_zero(args.format) ? NULL : args.format, ast_strlen_zero(args.timezone) ? NULL : args.timezone);
00158 }
00159
00160 return res;
00161 }
00162
00163 static int unload_module(void)
00164 {
00165 int res;
00166
00167 res = ast_unregister_application(app_sayunixtime);
00168 res |= ast_unregister_application(app_datetime);
00169
00170 return res;
00171 }
00172
00173 static int load_module(void)
00174 {
00175 int res;
00176
00177 res = ast_register_application_xml(app_sayunixtime, sayunixtime_exec);
00178 res |= ast_register_application_xml(app_datetime, sayunixtime_exec);
00179
00180 return res;
00181 }
00182
00183 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say time");