98 static char *app =
"WaitForCondition";
100 static int waitforcond_exec(
struct ast_channel *chan,
const char *data)
103 double timeout = 0, poll = 0;
109 char *pos, *open_bracket, *expression, *optargs = NULL;
119 if (ast_strlen_zero(pos)) {
120 ast_log(LOG_ERROR,
"WaitForCondition requires a condition\n");
126 if (!(open_bracket = strchr(pos,
'[')) || !strchr(open_bracket,
']')) {
127 ast_log(LOG_ERROR,
"No expression detected. Did you forget to replace the $ signs?\n");
132 dollarsignrep = pos[0];
133 if (dollarsignrep ==
'$' || dollarsignrep ==
'[' || dollarsignrep ==
']'
134 || dollarsignrep ==
'{' || dollarsignrep ==
'}') {
135 ast_log(LOG_ERROR,
"Dollar sign replacement cannot be %c.\n", dollarsignrep);
141 ast_log(LOG_ERROR,
"Invalid separator: %c\n", pos[0]);
146 if (pos[0] != dollarsignrep) {
147 ast_log(LOG_ERROR,
"Expression start does not match provided replacement: %c\n", pos[0]);
156 if (pos[0] ==
'\0') {
157 ast_log(LOG_ERROR,
"Could not parse end of expression.\n");
163 }
else if (pos[0] ==
']') {
171 if (pos[0] !=
'\0') {
173 if (pos[0] !=
'\0') {
176 if (!ast_strlen_zero(args.timeout)) {
177 if (sscanf(args.timeout,
"%30lg", &timeout) != 1) {
178 ast_log(LOG_WARNING,
"Invalid timeout provided: %s. No timeout set.\n", args.timeout);
181 timeout_ms = timeout * 1000.0;
184 if (!ast_strlen_zero(args.interval)) {
185 if (sscanf(args.interval,
"%30lg", &poll) != 1) {
186 ast_log(LOG_WARNING,
"Invalid polling interval provided: %s. Default unchanged.\n", args.interval);
190 ast_log(LOG_WARNING,
"Polling interval cannot be less than 1ms. Default unchanged.\n");
193 poll_ms = poll * 1000.0;
198 for (i = 0; expression[i] !=
'\0'; i++) {
199 if (expression[i] == dollarsignrep) {
204 if (timeout_ms > 0) {
205 ast_debug(1,
"Waiting for condition for %f seconds: %s (checking every %d ms)", timeout, expression, poll_ms);
207 ast_debug(1,
"Waiting for condition, forever: %s (checking every %d ms)", expression, poll_ms);
212 pbx_substitute_variables_helper(chan, expression, condition,
sizeof(condition) - 1);
229 static int unload_module(
void)
234 static int load_module(
void)
239 AST_MODULE_INFO_STANDARD_EXTENDED(
ASTERISK_GPL_KEY,
"Wait until condition is true");
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
int pbx_checkcondition(const char *condition)
Evaluate a condition.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int ast_unregister_application(const char *app)
Unregister an application.
General Asterisk PBX channel definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ast_debug(level,...)
Log a DEBUG message.
Core PBX routines and definitions.
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Support for logging to various files, console and syslog Configuration in file logger.conf.
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
#define AST_APP_ARG(name)
Define an application argument.