136285Sbrian/*-
236285Sbrian * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
336285Sbrian * All rights reserved.
413389Sphk *
536285Sbrian * Redistribution and use in source and binary forms, with or without
636285Sbrian * modification, are permitted provided that the following conditions
736285Sbrian * are met:
836285Sbrian * 1. Redistributions of source code must retain the above copyright
936285Sbrian *    notice, this list of conditions and the following disclaimer.
1036285Sbrian * 2. Redistributions in binary form must reproduce the above copyright
1136285Sbrian *    notice, this list of conditions and the following disclaimer in the
1236285Sbrian *    documentation and/or other materials provided with the distribution.
1313389Sphk *
1436285Sbrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1536285Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1636285Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1736285Sbrian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1836285Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1936285Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2036285Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2136285Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2236285Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2336285Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2436285Sbrian * SUCH DAMAGE.
2513389Sphk *
2650479Speter * $FreeBSD$
2713389Sphk */
2830715Sbrian
2936285Sbrian#define CHAT_EXPECT 0
3036285Sbrian#define CHAT_SEND   1
3136285Sbrian#define CHAT_DONE   2
3236285Sbrian#define CHAT_FAILED 3
3336285Sbrian
3436285Sbrian#define MAXABORTS   50
3536285Sbrian
3636285Sbrianstruct physical;
3736285Sbrian
3836285Sbrianstruct chat {
3958028Sbrian  struct fdescriptor desc;
4036285Sbrian  struct physical *physical;
4136285Sbrian
4236285Sbrian  int state;				/* Our CHAT_* status */
4336285Sbrian
4436285Sbrian  char script[LINE_LEN];		/* Our arg buffer */
4536285Sbrian  char *argv[MAXARGS];			/* Our arguments (pointing to script) */
4636285Sbrian  int argc;				/* Number of argv's */
4736285Sbrian
4836285Sbrian  int arg;				/* Our current arg number */
4936285Sbrian  char exp[LINE_LEN];			/* Our translated current argument */
5036285Sbrian  char *argptr;				/* Our current arg pointer */
5136285Sbrian  int arglen;				/* The length of argptr */
5236285Sbrian  char *nargptr;			/* Our next for expect-send-expect */
5336285Sbrian
5436285Sbrian  char buf[LINE_LEN*2];			/* Our input */
5536285Sbrian  char *bufstart;			/* start of relevent data */
5636285Sbrian  char *bufend;				/* end of relevent data */
5736285Sbrian
5836285Sbrian  int TimeoutSec;			/* Expect timeout value */
5936285Sbrian  int TimedOut;				/* We timed out */
6036285Sbrian
6136285Sbrian  const char *phone;			/* Our phone number */
6236285Sbrian
6336285Sbrian  struct {
6436285Sbrian    struct {
6536285Sbrian      char *data;			/* Abort the dial if we get one */
6636285Sbrian      int len;
6736285Sbrian    } string[MAXABORTS];
6836285Sbrian    int num;				/* How many AbortStrings */
6936285Sbrian  } abort;
7036285Sbrian
7136285Sbrian  struct pppTimer pause;		/* Inactivity timer */
7236285Sbrian  struct pppTimer timeout;		/* TimeoutSec timer */
7336285Sbrian};
7436285Sbrian
7536285Sbrian#define descriptor2chat(d) \
7636285Sbrian  ((d)->type == CHAT_DESCRIPTOR ? (struct chat *)(d) : NULL)
7730715Sbrian#define	VECSIZE(v)	(sizeof(v) / sizeof(v[0]))
7830715Sbrian
7954055Sbrianextern void chat_Init(struct chat *, struct physical *);
8054914Sbrianextern int chat_Setup(struct chat *, const char *, const char *);
8154055Sbrianextern void chat_Finish(struct chat *);
8236285Sbrianextern void chat_Destroy(struct chat *);
83