[asterisk-commits] trunk r20389 - /trunk/channel.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sun Apr 16 00:53:27 MST 2006


Author: rizzo
Date: Sun Apr 16 02:53:25 2006
New Revision: 20389

URL: http://svn.digium.com/view/asterisk?rev=20389&view=rev
Log:
implement ast_waitfordigit() and ast_readstring() in terms
of their '_full()' version, so we can remove the replicated
implementation and, especially, the risk that they get out of sync.


Modified:
    trunk/channel.c

Modified: trunk/channel.c
URL: http://svn.digium.com/view/asterisk/trunk/channel.c?rev=20389&r1=20388&r2=20389&view=diff
==============================================================================
--- trunk/channel.c (original)
+++ trunk/channel.c Sun Apr 16 02:53:25 2006
@@ -1746,31 +1746,7 @@
 /* XXX never to be called with ms = -1 */
 int ast_waitfordigit(struct ast_channel *c, int ms)
 {
-	/* XXX Should I be merged with waitfordigit_full XXX */
-	struct ast_frame *f;
-	int result = 0;
-
-	/* Stop if we're a zombie or need a soft hangup */
-	if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
-		return -1;
-
-	/* Wait for a digit, no more than ms milliseconds total. */
-	while(ms && !result) {
-		ms = ast_waitfor(c, ms);
-		if (ms < 0) /* Error */
-			result = -1;
-		else if (ms > 0) {
-			/* 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;
+	return ast_waitfordigit_full(c, ms, -1, -1);
 }
 
 int ast_settimeout(struct ast_channel *c, int samples, int (*func)(void *data), void *data)
@@ -2718,42 +2694,7 @@
 
 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders)
 {
-	int pos=0;
-	int to = ftimeout;
-	int d;
-
-	/* XXX Merge with full version? XXX */
-	/* Stop if we're a zombie or need a soft hangup */
-	if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
-		return -1;
-	if (!len)
-		return -1;
-	for (;;) {
-		if (c->stream) {
-			d = ast_waitstream(c, AST_DIGIT_ANY);
-			ast_stopstream(c);
-			usleep(1000);
-			if (!d)
-				d = ast_waitfordigit(c, to);
-		} else {
-			d = ast_waitfordigit(c, to);
-		}
-		if (d < 0)
-			return -1;
-		if (d == 0) {
-			s[pos]='\0';
-			return 1;
-		}
-		if (!strchr(enders, d))
-			s[pos++] = d;
-		if (strchr(enders, d) || (pos >= len)) {
-			s[pos]='\0';
-			return 0;
-		}
-		to = timeout;
-	}
-	/* Never reached */
-	return 0;
+	return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1);
 }
 
 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders, int audiofd, int ctrlfd)



More information about the asterisk-commits mailing list