| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#include "asterisk.h" |
| 33 |
|
| 34 |
#include "asterisk/logger.h" |
| 35 |
#include "asterisk/channel.h" |
| 36 |
#include "asterisk/pbx.h" |
| 37 |
#include "asterisk/module.h" |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
static char *app = "WaitUntil"; |
| 74 |
|
| 75 |
static int waituntil_exec(struct ast_channel *chan, const char *data) |
| 76 |
{ |
| 77 |
int res; |
| 78 |
double fraction; |
| 79 |
long seconds; |
| 80 |
struct timeval future = { 0, }; |
| 81 |
struct timeval now = ast_tvnow(); |
| 82 |
int msec; |
| 83 |
|
| 84 |
if (ast_strlen_zero(data)) { |
| 85 |
ast_log(LOG_WARNING, "WaitUntil requires an argument(epoch)\n"); |
| 86 |
pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "FAILURE"); |
| 87 |
return 0; |
| 88 |
} |
| 89 |
|
| 90 |
if (sscanf(data, "%30ld%30lf", &seconds, &fraction) == 0) { |
| 91 |
ast_log(LOG_WARNING, "WaitUntil called with non-numeric argument\n"); |
| 92 |
pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "FAILURE"); |
| 93 |
return 0; |
| 94 |
} |
| 95 |
|
| 96 |
future.tv_sec = seconds; |
| 97 |
future.tv_usec = fraction * 1000000; |
| 98 |
|
| 99 |
if ((msec = ast_tvdiff_ms(future, now)) < 0) { |
| 100 |
ast_log(LOG_NOTICE, "WaitUntil called in the past (now %ld, arg %ld)\n", (long)now.tv_sec, (long)future.tv_sec); |
| 101 |
pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "PAST"); |
| 102 |
return 0; |
| 103 |
} |
| 104 |
|
| 105 |
if ((res = ast_safe_sleep(chan, msec))) |
| 106 |
pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "HANGUP"); |
| 107 |
else |
| 108 |
pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "OK"); |
| 109 |
|
| 110 |
return res; |
| 111 |
} |
| 112 |
|
| 113 |
static int unload_module(void) |
| 114 |
{ |
| 115 |
return ast_unregister_application(app); |
| 116 |
} |
| 117 |
|
| 118 |
static int load_module(void) |
| 119 |
{ |
| 120 |
return ast_register_application_xml(app, waituntil_exec); |
| 121 |
} |
| 122 |
|
| 123 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Wait until specified time"); |