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: 328209 $")
00035
00036 #include "asterisk/logger.h"
00037 #include "asterisk/channel.h"
00038 #include "asterisk/pbx.h"
00039 #include "asterisk/module.h"
00040
00041
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 static char *app = "WaitUntil";
00073
00074 static int waituntil_exec(struct ast_channel *chan, const char *data)
00075 {
00076 int res;
00077 double fraction;
00078 long seconds;
00079 struct timeval future = { 0, };
00080 struct timeval now = ast_tvnow();
00081 int msec;
00082
00083 if (ast_strlen_zero(data)) {
00084 ast_log(LOG_WARNING, "WaitUntil requires an argument(epoch)\n");
00085 pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "FAILURE");
00086 return 0;
00087 }
00088
00089 if (sscanf(data, "%30ld%30lf", &seconds, &fraction) == 0) {
00090 ast_log(LOG_WARNING, "WaitUntil called with non-numeric argument\n");
00091 pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "FAILURE");
00092 return 0;
00093 }
00094
00095 future.tv_sec = seconds;
00096 future.tv_usec = fraction * 1000000;
00097
00098 if ((msec = ast_tvdiff_ms(future, now)) < 0) {
00099 ast_log(LOG_NOTICE, "WaitUntil called in the past (now %ld, arg %ld)\n", (long)now.tv_sec, (long)future.tv_sec);
00100 pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "PAST");
00101 return 0;
00102 }
00103
00104 if ((res = ast_safe_sleep(chan, msec)))
00105 pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "HANGUP");
00106 else
00107 pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "OK");
00108
00109 return res;
00110 }
00111
00112 static int unload_module(void)
00113 {
00114 return ast_unregister_application(app);
00115 }
00116
00117 static int load_module(void)
00118 {
00119 return ast_register_application_xml(app, waituntil_exec);
00120 }
00121
00122 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Wait until specified time");