101{
102 int ms, i;
103 double timeout = 0, poll = 0;
104 int timeout_ms = 0;
105 int poll_ms = 50;
107 char dollarsignrep;
108 int brackets = 0;
109 char *pos, *open_bracket, *expression, *optargs =
NULL;
110 char condition[512];
111
115 );
116
118
122 return 0;
123 }
124
125
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");
129 return 0;
130 }
131
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);
137 return 0;
138 }
139 ++pos;
140 if (pos[0] != ',') {
143 return 0;
144 }
145 ++pos;
146 if (pos[0] != dollarsignrep) {
147 ast_log(
LOG_ERROR,
"Expression start does not match provided replacement: %c\n", pos[0]);
149 return 0;
150 }
151
152 expression = pos;
153
154
155 while (++pos) {
156 if (pos[0] == '\0') {
159 return 0;
160 }
161 if (pos[0] == '[') {
162 brackets++;
163 } else if (pos[0] == ']') {
164 brackets--;
165 }
166 if (brackets == 0) {
167 break;
168 }
169 }
170 ++pos;
171 if (pos[0] != '\0') {
172 ++pos;
173 if (pos[0] != '\0') {
177 if (sscanf(
args.timeout,
"%30lg", &timeout) != 1) {
179 return -1;
180 }
181 timeout_ms = timeout * 1000.0;
182 }
183
185 if (sscanf(
args.interval,
"%30lg", &poll) != 1) {
187 return -1;
188 }
189 if (poll < 0.001) {
190 ast_log(
LOG_WARNING,
"Polling interval cannot be less than 1ms. Default unchanged.\n");
191 return -1;
192 }
193 poll_ms = poll * 1000.0;
194 }
195 }
196 }
197
198 for (i = 0; expression[i] != '\0'; i++) {
199 if (expression[i] == dollarsignrep) {
200 expression[i] = '$';
201 }
202 }
203
204 if (timeout_ms > 0) {
205 ast_debug(1,
"Waiting for condition for %f seconds: %s (checking every %d ms)", timeout, expression, poll_ms);
206 } else {
207 ast_debug(1,
"Waiting for condition, forever: %s (checking every %d ms)", expression, poll_ms);
208 }
209
210 while (1) {
211
215 return 0;
216 }
217
220 return 0;
221 }
224 return -1;
225 }
226 }
227}
#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().