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 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <unistd.h>
00028 #include <string.h>
00029
00030 #include "asterisk.h"
00031
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
00033
00034 #include "asterisk/file.h"
00035 #include "asterisk/logger.h"
00036 #include "asterisk/options.h"
00037 #include "asterisk/channel.h"
00038 #include "asterisk/pbx.h"
00039 #include "asterisk/module.h"
00040 #include "asterisk/say.h"
00041
00042
00043 static char *tdesc = "Say time";
00044
00045 static char *app_sayunixtime = "SayUnixTime";
00046 static char *app_datetime = "DateTime";
00047
00048 static char *sayunixtime_synopsis = "Says a specified time in a custom format";
00049
00050 static char *sayunixtime_descrip =
00051 "SayUnixTime([unixtime][|[timezone][|format]])\n"
00052 " unixtime: time, in seconds since Jan 1, 1970. May be negative.\n"
00053 " defaults to now.\n"
00054 " timezone: timezone, see /usr/share/zoneinfo for a list.\n"
00055 " defaults to machine default.\n"
00056 " format: a format the time is to be said in. See voicemail.conf.\n"
00057 " defaults to \"ABdY 'digits/at' IMp\"\n";
00058 static char *datetime_descrip =
00059 "DateTime([unixtime][|[timezone][|format]])\n"
00060 " unixtime: time, in seconds since Jan 1, 1970. May be negative.\n"
00061 " defaults to now.\n"
00062 " timezone: timezone, see /usr/share/zoneinfo for a list.\n"
00063 " defaults to machine default.\n"
00064 " format: a format the time is to be said in. See voicemail.conf.\n"
00065 " defaults to \"ABdY 'digits/at' IMp\"\n";
00066
00067 STANDARD_LOCAL_USER;
00068
00069 LOCAL_USER_DECL;
00070
00071 static int sayunixtime_exec(struct ast_channel *chan, void *data)
00072 {
00073 int res=0;
00074 struct localuser *u;
00075 char *s,*zone=NULL,*timec,*format;
00076 time_t unixtime;
00077 struct timeval tv;
00078
00079 LOCAL_USER_ADD(u);
00080
00081 tv = ast_tvnow();
00082 unixtime = (time_t)tv.tv_sec;
00083
00084 if( !strcasecmp(chan->language, "da" ) ) {
00085 format = "A dBY HMS";
00086 } else if ( !strcasecmp(chan->language, "de" ) ) {
00087 format = "A dBY HMS";
00088 } else if ( !strcasecmp(chan->language, "pt_BR" ) ) {
00089 format = "Ad 'digits/pt-de' B 'digits/pt-de' Y 'digits/pt-as' HMS";
00090 } else {
00091 format = "ABdY 'digits/at' IMp";
00092 }
00093
00094 if (data) {
00095 s = data;
00096 s = ast_strdupa(s);
00097 if (s) {
00098 timec = strsep(&s,"|");
00099 if ((timec) && (*timec != '\0')) {
00100 long timein;
00101 if (sscanf(timec,"%ld",&timein) == 1) {
00102 unixtime = (time_t)timein;
00103 }
00104 }
00105 if (s) {
00106 zone = strsep(&s,"|");
00107 if (zone && (*zone == '\0'))
00108 zone = NULL;
00109 if (s) {
00110 format = s;
00111 }
00112 }
00113 } else {
00114 ast_log(LOG_ERROR, "Out of memory error\n");
00115 }
00116 }
00117
00118 if (chan->_state != AST_STATE_UP) {
00119 res = ast_answer(chan);
00120 }
00121 if (!res)
00122 res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY, chan->language, format, zone);
00123
00124 LOCAL_USER_REMOVE(u);
00125 return res;
00126 }
00127
00128 int unload_module(void)
00129 {
00130 int res;
00131
00132 res = ast_unregister_application(app_sayunixtime);
00133 res |= ast_unregister_application(app_datetime);
00134
00135 STANDARD_HANGUP_LOCALUSERS;
00136
00137 return res;
00138 }
00139
00140 int load_module(void)
00141 {
00142 int res;
00143
00144 res = ast_register_application(app_sayunixtime, sayunixtime_exec, sayunixtime_synopsis, sayunixtime_descrip);
00145 res |= ast_register_application(app_datetime, sayunixtime_exec, sayunixtime_synopsis, datetime_descrip);
00146
00147 return res;
00148 }
00149
00150 char *description(void)
00151 {
00152 return tdesc;
00153 }
00154
00155 int usecount(void)
00156 {
00157 int res;
00158 STANDARD_USECOUNT(res);
00159 return res;
00160 }
00161
00162 char *key()
00163 {
00164 return ASTERISK_GPL_KEY;
00165 }