[alt.hackers] Handy HoneyDanBer Hack

bob@omni.com (Bob Weissman) (05/10/91)

HoneyDanBer UUCP has a moderately stupid problem in that it
uses a constant, MAXEXPECTTIME, to control timeouts on *all*
expected responses.

By default, MAXEXPECTTIME is 45 seconds.  This is way too long
for a local modem "OK" response, is often too short for a remote
modem to synch up, and is moderately too long to wait for a "login:"
prompt.

So I decided to extend the HDB chat script to include a new directive,
"WAIT=seconds", in the spirit of the existing "STTY=mode".  Like
STTY, this is really only useful in a Dialers script.

"WAIT=n" may be prepended to any send string, so, for example, you
could say "WAIT=5ATS0=0" or "WAIT=20STTY=crtscts".

This change is local to module conn.c.  Just define VAR_EXP_TIME
in Makefile to get this behavior.  Diffs to conn.c follow.  Enjoy.

SCCS/s.conn.c: 1.1 vs. 1.3
*** /tmp/geta6161	Thu May  9 10:31:46 1991
--- /tmp/getb6161	Thu May  9 10:31:47 1991
***************
*** 25,30 ****
--- 29,47 ----
  
  char	par_tab[128];
  
+ /*
+  * define VAR_EXP_TIME to enable a variable wait time for the expect()
+  * function.  Changing the wait time is accomplished by a send string of
+  * the form "WAIT=nsec" in the chat script.
+  */
+ 
+ #ifdef VAR_EXP_TIME
+ static unsigned expectTime = MAXEXPECTTIME;
+ #ifndef REALMAXEXPECTTIME
+ #define REALMAXEXPECTTIME 180L
+ #endif
+ #endif
+ 
  int alarmtr();
  static void getProto();
  /* static getto(), finds();   PUT this back after altconn is included */
***************
*** 441,447 ****
  		return(FAIL);
  	}
  	(void) signal(SIGALRM, alarmtr);
! 	alarm(MAXEXPECTTIME);
  	while (notin(str, rdvec)) {
  		errno = 0;
  		kr = (*Read)(fn, &nextch, 1);
--- 458,468 ----
  		return(FAIL);
  	}
  	(void) signal(SIGALRM, alarmtr);
! #ifdef VAR_EXP_TIME
! 	(void) alarm(expectTime);
! #else
! 	(void) alarm(MAXEXPECTTIME);
! #endif
  	while (notin(str, rdvec)) {
  		errno = 0;
  		kr = (*Read)(fn, &nextch, 1);
***************
*** 511,516 ****
--- 532,561 ----
  		bld_partab(P_EVEN);
  	}
  
+ #ifdef VAR_EXP_TIME
+ 	/*
+ 	 * Put the "WAIT=" check first, so that we can use strtol to
+ 	 * scan the string and leave us any remaining chars after
+ 	 * the number has been decoded.  This allows us, for example,
+ 	 * to have strings like "WAIT=5ATS0=0" or "WAIT=45STTY=crtscts"
+ 	 * in the chat script.
+ 	 */
+ 	if (PREFIX("WAIT=", str)) {
+ 		char *endptr;
+ 		long w = strtol(str+5, &endptr, 10);
+ 		if (w > 0L && w <= REALMAXEXPECTTIME) {
+ 			CDEBUG(5, "wait time set to %ld sec\n", w);
+ 			expectTime = (unsigned) w;
+ 		} else {
+ 			CDEBUG(3, "wait time (%s) out of range, ignored\n", str+5);
+ 		}
+ 		if (*endptr == '\0')	/* did we run out of string? */
+ 			return;		/* yes, return */
+ 		else
+ 			str = endptr;	/* no, update pointer and continue */
+ 	}
+ #endif
+ 
  	/* should be EQUALS, but previous versions had BREAK n for integer n */
  	if (PREFIX("BREAK", str)) {
  		/* send break */
***************
*** 558,563 ****
--- 603,609 ----
  		return;
  	}
  
+ 
  	if (EQUALS(str, "\"\"")) {
  		CDEBUG(5, "\"\"\n", 0);
  		str += 2;
***************
*** 741,747 ****
--- 787,797 ----
  		if (((*Write)(fn, &par_tab[cout], 1)) != 1)
  			return(FAIL);
  		do {
+ #ifdef VAR_EXP_TIME
+ 			(void) alarm(expectTime);
+ #else
  			(void) alarm(MAXEXPECTTIME);
+ #endif
  			if ((*Read)(fn, &cin, 1) != 1)
  				return(FAIL);
  			(void) alarm(0);


-- 
Bob Weissman
Internet:	bob@omni.com
UUCP:		...!{apple,decwrl,pyramid,sgi,uunet}!omni!bob