11541Srgrimes/*-
222521Sdyson * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
31541Srgrimes * All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes *
141541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
151541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
161541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
171541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
181541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
191541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
201541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
221541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
231541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241541Srgrimes * SUCH DAMAGE.
251541Srgrimes *
261541Srgrimes * $FreeBSD$
271541Srgrimes */
281541Srgrimes
291541Srgrimes#define CHAT_EXPECT 0
301541Srgrimes#define CHAT_SEND   1
311541Srgrimes#define CHAT_DONE   2
321541Srgrimes#define CHAT_FAILED 3
331541Srgrimes
341541Srgrimes#define MAXABORTS   50
351541Srgrimes
3622521Sdysonstruct physical;
371541Srgrimes
3850477Speterstruct chat {
391541Srgrimes  struct fdescriptor desc;
401541Srgrimes  struct physical *physical;
411541Srgrimes
421541Srgrimes  int state;				/* Our CHAT_* status */
431541Srgrimes
441541Srgrimes  char script[LINE_LEN];		/* Our arg buffer */
451541Srgrimes  char *argv[MAXARGS];			/* Our arguments (pointing to script) */
461541Srgrimes  int argc;				/* Number of argv's */
4776166Smarkm
4876166Smarkm  int arg;				/* Our current arg number */
493034Sdg  char exp[LINE_LEN];			/* Our translated current argument */
5076166Smarkm  char *argptr;				/* Our current arg pointer */
5189316Salfred  int arglen;				/* The length of argptr */
5276166Smarkm  char *nargptr;			/* Our next for expect-send-expect */
5376166Smarkm
5476166Smarkm  char buf[LINE_LEN*2];			/* Our input */
551541Srgrimes  char *bufstart;			/* start of relevant data */
5676166Smarkm  char *bufend;				/* end of relevant data */
571541Srgrimes
581541Srgrimes  int TimeoutSec;			/* Expect timeout value */
5976166Smarkm  int TimedOut;				/* We timed out */
6076166Smarkm
6177031Sru  const char *phone;			/* Our phone number */
621541Srgrimes
6330354Sphk  struct {
6430354Sphk    struct {
6592727Salfred      char *data;			/* Abort the dial if we get one */
6692727Salfred      int len;
6792727Salfred    } string[MAXABORTS];
6892727Salfred    int num;				/* How many AbortStrings */
6992727Salfred  } abort;
7092727Salfred
7192727Salfred  struct pppTimer pause;		/* Inactivity timer */
7212335Sbde  struct pppTimer timeout;		/* TimeoutSec timer */
731541Srgrimes};
741541Srgrimes
751541Srgrimes#define descriptor2chat(d) \
7612769Sphk  ((d)->type == CHAT_DESCRIPTOR ? (struct chat *)(d) : NULL)
7783366Sjulian#define	VECSIZE(v)	(sizeof(v) / sizeof(v[0]))
781541Srgrimes
791541Srgrimesextern void chat_Init(struct chat *, struct physical *);
801541Srgrimesextern int chat_Setup(struct chat *, const char *, const char *);
811541Srgrimesextern void chat_Finish(struct chat *);
8283366Sjulianextern void chat_Destroy(struct chat *);
831541Srgrimes