100{
101 int ms, i;
102 double timeout = 0, poll = 0;
103 int timeout_ms = 0;
104 int poll_ms = 50;
106 char dollarsignrep;
107 int brackets = 0;
108 char *pos, *open_bracket, *expression, *optargs =
NULL;
109 char condition[512];
110
114 );
115
117
121 return 0;
122 }
123
124
125 if (!(open_bracket = strchr(pos, '[')) || !strchr(open_bracket, ']')) {
126 ast_log(
LOG_ERROR,
"No expression detected. Did you forget to replace the $ signs?\n");
128 return 0;
129 }
130
131 dollarsignrep = pos[0];
132 if (dollarsignrep == '$' || dollarsignrep == '[' || dollarsignrep == ']'
133 || dollarsignrep == '{' || dollarsignrep == '}') {
134 ast_log(
LOG_ERROR,
"Dollar sign replacement cannot be %c.\n", dollarsignrep);
136 return 0;
137 }
138 ++pos;
139 if (pos[0] != ',') {
142 return 0;
143 }
144 ++pos;
145 if (pos[0] != dollarsignrep) {
146 ast_log(
LOG_ERROR,
"Expression start does not match provided replacement: %c\n", pos[0]);
148 return 0;
149 }
150
151 expression = pos;
152
153
154 while (++pos) {
155 if (pos[0] == '\0') {
158 return 0;
159 }
160 if (pos[0] == '[') {
161 brackets++;
162 } else if (pos[0] == ']') {
163 brackets--;
164 }
165 if (brackets == 0) {
166 break;
167 }
168 }
169 ++pos;
170 if (pos[0] != '\0') {
171 ++pos;
172 if (pos[0] != '\0') {
176 if (sscanf(
args.timeout,
"%30lg", &timeout) != 1) {
178 return -1;
179 }
180 timeout_ms = timeout * 1000.0;
181 }
182
184 if (sscanf(
args.interval,
"%30lg", &poll) != 1) {
186 return -1;
187 }
188 if (poll < 0.001) {
189 ast_log(
LOG_WARNING,
"Polling interval cannot be less than 1ms. Default unchanged.\n");
190 return -1;
191 }
192 poll_ms = poll * 1000.0;
193 }
194 }
195 }
196
197 for (i = 0; expression[i] != '\0'; i++) {
198 if (expression[i] == dollarsignrep) {
199 expression[i] = '$';
200 }
201 }
202
203 if (timeout_ms > 0) {
204 ast_debug(1,
"Waiting for condition for %f seconds: %s (checking every %d ms)", timeout, expression, poll_ms);
205 } else {
206 ast_debug(1,
"Waiting for condition, forever: %s (checking every %d ms)", expression, poll_ms);
207 }
208
209 while (1) {
210
214 return 0;
215 }
216
219 return 0;
220 }
223 return -1;
224 }
225 }
226}
#define ast_strdupa(s)
duplicate a string in memory from the stack
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define ast_debug(level,...)
Log a DEBUG message.
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.
int pbx_checkcondition(const char *condition)
Evaluate a condition.
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
static force_inline int attribute_pure ast_strlen_zero(const char *s)
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().