aboutsummaryrefslogtreecommitdiffstats
path: root/channel.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-04-12 16:25:34 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-04-12 16:25:34 +0000
commitec4d7ac59660395beabd6ac391603070942d46f3 (patch)
tree2b86c51f9df3ab7bbd8bbde1d221588b53c1badc /channel.c
parentf1248d73487597d50a24172f6dc2e31f0f3e793b (diff)
Fix implementation of waitfordigit_full
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@2677 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channel.c')
-rwxr-xr-xchannel.c53
1 files changed, 38 insertions, 15 deletions
diff --git a/channel.c b/channel.c
index 50aea5e0a..f0b8e8f9e 100755
--- a/channel.c
+++ b/channel.c
@@ -1004,34 +1004,57 @@ int ast_settimeout(struct ast_channel *c, int samples, int (*func)(void *data),
#endif
return res;
}
-char ast_waitfordigit_full(struct ast_channel *c, int ms, int audio, int ctrl)
+char ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int cmdfd)
{
struct ast_frame *f;
- char result = 0;
struct ast_channel *rchan;
int outfd;
+ int res;
/* Stop if we're a zombie or need a soft hangup */
if (c->zombie || ast_check_hangup(c))
return -1;
/* Wait for a digit, no more than ms milliseconds total. */
- while(ms && !result) {
- rchan = ast_waitfor_nandfds(&c, 1, &audio, (audio > -1) ? 1 : 0, NULL, &outfd, &ms);
- if ((!rchan) && (outfd < 0) && (ms)) /* Error */
- result = -1;
- else if (outfd > -1) {
- result = 1;
+ while(ms) {
+ rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);
+ if ((!rchan) && (outfd < 0) && (ms)) {
+ ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
+ return -1;
+ } else if (outfd > -1) {
+ /* The FD we were watching has something waiting */
+ return 1;
} else if (rchan) {
- /* Read something */
f = ast_read(c);
- if (f) {
- if (f->frametype == AST_FRAME_DTMF)
- result = f->subclass;
+ if(!f) {
+ return -1;
+ }
+
+ switch(f->frametype) {
+ case AST_FRAME_DTMF:
+ res = f->subclass;
ast_frfree(f);
- } else
- result = -1;
+ return res;
+ case AST_FRAME_CONTROL:
+ switch(f->subclass) {
+ case AST_CONTROL_HANGUP:
+ ast_frfree(f);
+ return -1;
+ case AST_CONTROL_RINGING:
+ case AST_CONTROL_ANSWER:
+ /* Unimportant */
+ break;
+ default:
+ ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass);
+ }
+ case AST_FRAME_VOICE:
+ /* Write audio if appropriate */
+ if (audiofd > -1)
+ write(audiofd, f->data, f->datalen);
+ }
+ /* Ignore */
+ ast_frfree(f);
}
}
- return result;
+ return 0; // Time is up
}
struct ast_frame *ast_read(struct ast_channel *chan)