diff options
author | matteo <matteo@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-02-23 06:00:11 +0000 |
---|---|---|
committer | matteo <matteo@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-02-23 06:00:11 +0000 |
commit | b6be24372a79c5fe8568a831bab188db9ea98e8c (patch) | |
tree | e05618b650b51c146c697c794e3e510343de7230 /channel.c | |
parent | acda464eb483efb6dd4a07ab867ae3eb30699d33 (diff) |
Sun Feb 23 07:00:00 CET 2003
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@621 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channel.c')
-rwxr-xr-x | channel.c | 74 |
1 files changed, 74 insertions, 0 deletions
@@ -869,6 +869,7 @@ int ast_waitfor(struct ast_channel *c, int ms) char ast_waitfordigit(struct ast_channel *c, int ms) { + /* XXX Should I be merged with waitfordigit_full XXX */ struct ast_frame *f; char result = 0; /* Stop if we're a zombie or need a soft hangup */ @@ -893,6 +894,36 @@ char ast_waitfordigit(struct ast_channel *c, int ms) return result; } +char ast_waitfordigit_full(struct ast_channel *c, int ms, int audio, int ctrl) +{ + struct ast_frame *f; + char result = 0; + struct ast_channel *rchan; + int outfd; + /* 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; + } else if (rchan) { + /* Read something */ + f = ast_read(c); + if (f) { + if (f->frametype == AST_FRAME_DTMF) + result = f->subclass; + ast_frfree(f); + } else + result = -1; + } + } + return result; +} + struct ast_frame *ast_read(struct ast_channel *chan) { struct ast_frame *f = NULL; @@ -1383,6 +1414,7 @@ int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int fti int pos=0; int to = ftimeout; char d; + /* XXX Merge with full version? XXX */ /* Stop if we're a zombie or need a soft hangup */ if (c->zombie || ast_check_hangup(c)) return -1; @@ -1416,6 +1448,48 @@ int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int fti return 0; } +int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders, int audiofd, int ctrlfd) +{ + int pos=0; + int to = ftimeout; + char d; + /* Stop if we're a zombie or need a soft hangup */ + if (c->zombie || ast_check_hangup(c)) + return -1; + if (!len) + return -1; + do { + if (c->streamid > -1) { + d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd); + ast_stopstream(c); + usleep(1000); + if (!d) + d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); + } else { + d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); + } + if (d < 0) + return -1; + if (d == 0) { + s[pos]='\0'; + return 1; + } + if (d == 1) { + s[pos]='\0'; + return 2; + } + if (!strchr(enders, d)) + s[pos++] = d; + if (strchr(enders, d) || (pos >= len)) { + s[pos]='\0'; + return 0; + } + to = timeout; + } while(1); + /* Never reached */ + return 0; +} + int ast_channel_supports_html(struct ast_channel *chan) { if (chan->pvt->send_html) |