1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-10-18 02:19:39 +00:00

Introduce ``set logout''; another chat script. This is in preparation

for the abstraction of ``set dial'' and ``set hangup''.
This commit is contained in:
Brian Somers 1999-10-25 13:49:44 +00:00
parent bacfb041e0
commit c116e0c0aa
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=52488
7 changed files with 73 additions and 32 deletions

View File

@ -531,7 +531,7 @@ chat_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
}
void
chat_Init(struct chat *c, struct physical *p, const char *data, int emptybuf,
chat_Init(struct chat *c, struct physical *p, const char *data,
const char *phone)
{
c->desc.type = CHAT_DESCRIPTOR;
@ -556,7 +556,7 @@ chat_Init(struct chat *c, struct physical *p, const char *data, int emptybuf,
c->argptr = NULL;
c->nargptr = NULL;
if (emptybuf)
if (c->bufstart == NULL)
c->bufstart = c->bufend = c->buf;
c->TimeoutSec = 30;

View File

@ -76,6 +76,6 @@ struct chat {
((d)->type == CHAT_DESCRIPTOR ? (struct chat *)(d) : NULL)
#define VECSIZE(v) (sizeof(v) / sizeof(v[0]))
extern void chat_Init(struct chat *, struct physical *, const char *, int,
extern void chat_Init(struct chat *, struct physical *, const char *,
const char *);
extern void chat_Destroy(struct chat *);

View File

@ -123,6 +123,7 @@
#define VAR_PARITY 31
#define VAR_CRTSCTS 32
#define VAR_URGENTPORTS 33
#define VAR_LOGOUT 34
/* ``accept|deny|disable|enable'' masks */
#define NEG_HISMASK (1)
@ -1595,6 +1596,11 @@ SetVariable(struct cmdargs const *arg)
cx->cfg.script.hangup[sizeof cx->cfg.script.hangup - 1] = '\0';
break;
case VAR_LOGOUT:
strncpy(cx->cfg.script.logout, argp, sizeof cx->cfg.script.logout - 1);
cx->cfg.script.logout[sizeof cx->cfg.script.logout - 1] = '\0';
break;
case VAR_IDLETIMEOUT:
if (arg->argc > arg->argn+2)
err = "Too many idle timeout values\n";
@ -1894,6 +1900,8 @@ static struct cmdtab const SetCommands[] = {
"ipcp|lcp|lqm|phase|physical|sync|tcp/ip|timer|tun..."},
{"login", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
"login script", "set login chat-script", (const void *) VAR_LOGIN},
{"logout", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
"logout script", "set logout chat-script", (const void *) VAR_LOGOUT},
{"lqrperiod", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX_OPT,
"LQR period", "set lqrperiod value", (const void *)VAR_LQRPERIOD},
{"mode", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX, "mode value",

View File

@ -120,6 +120,7 @@ datalink_HangupDone(struct datalink *dl)
return;
}
chat_Destroy(&dl->chat);
physical_Close(dl->physical);
dl->phone.chosen = "N/A";
@ -202,6 +203,8 @@ datalink_ChoosePhoneNumber(struct datalink *dl)
static void
datalink_LoginDone(struct datalink *dl)
{
chat_Destroy(&dl->chat);
if (!dl->script.packetmode) {
dl->dial.tries = -1;
dl->dial.incs = 0;
@ -210,9 +213,8 @@ datalink_LoginDone(struct datalink *dl)
dl->dial.tries = 0;
log_Printf(LogWARN, "datalink_LoginDone: Not connected.\n");
if (dl->script.run) {
datalink_NewState(dl, DATALINK_HANGUP);
physical_Offline(dl->physical);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1, NULL);
datalink_NewState(dl, DATALINK_LOGOUT);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.logout, NULL);
} else {
physical_StopDeviceTimer(dl->physical);
if (dl->physical->type == PHYS_DEDICATED)
@ -270,7 +272,7 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
dl->physical->name.full);
if (dl->script.run) {
datalink_NewState(dl, DATALINK_DIAL);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.dial, 1,
chat_Init(&dl->chat, dl->physical, dl->cfg.script.dial,
*dl->cfg.script.dial ?
datalink_ChoosePhoneNumber(dl) : "");
if (!(dl->physical->type & (PHYS_DDIAL|PHYS_DEDICATED)) &&
@ -320,7 +322,7 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
case CARRIER_OK:
if (dl->script.run) {
datalink_NewState(dl, DATALINK_LOGIN);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.login, 0, NULL);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.login, NULL);
} else
datalink_LoginDone(dl);
return datalink_UpdateSet(d, r, w, e, n);
@ -329,7 +331,7 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
physical_Offline(dl->physical); /* Is this required ? */
if (dl->script.run) {
datalink_NewState(dl, DATALINK_HANGUP);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1, NULL);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, NULL);
} else
datalink_HangupDone(dl);
return datalink_UpdateSet(d, r, w, e, n);
@ -337,12 +339,12 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
case DATALINK_HANGUP:
case DATALINK_DIAL:
case DATALINK_LOGOUT:
case DATALINK_LOGIN:
result = descriptor_UpdateSet(&dl->chat.desc, r, w, e, n);
switch (dl->chat.state) {
case CHAT_DONE:
/* script succeeded */
chat_Destroy(&dl->chat);
switch(dl->state) {
case DATALINK_HANGUP:
datalink_HangupDone(dl);
@ -350,6 +352,11 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
case DATALINK_DIAL:
datalink_NewState(dl, DATALINK_CARRIER);
return datalink_UpdateSet(d, r, w, e, n);
case DATALINK_LOGOUT:
datalink_NewState(dl, DATALINK_HANGUP);
physical_Offline(dl->physical);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, NULL);
return datalink_UpdateSet(d, r, w, e, n);
case DATALINK_LOGIN:
dl->phone.alt = NULL;
datalink_LoginDone(dl);
@ -359,17 +366,16 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
case CHAT_FAILED:
/* Going down - script failed */
log_Printf(LogWARN, "Chat script failed\n");
chat_Destroy(&dl->chat);
switch(dl->state) {
case DATALINK_HANGUP:
datalink_HangupDone(dl);
break;
case DATALINK_DIAL:
case DATALINK_LOGOUT:
case DATALINK_LOGIN:
datalink_NewState(dl, DATALINK_HANGUP);
physical_Offline(dl->physical); /* Is this required ? */
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup,
1, NULL);
physical_Offline(dl->physical);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, NULL);
return datalink_UpdateSet(d, r, w, e, n);
}
break;
@ -406,6 +412,7 @@ datalink_IsSet(struct descriptor *d, const fd_set *fdset)
case DATALINK_HANGUP:
case DATALINK_DIAL:
case DATALINK_LOGOUT:
case DATALINK_LOGIN:
return descriptor_IsSet(&dl->chat.desc, fdset);
@ -432,6 +439,7 @@ datalink_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
case DATALINK_HANGUP:
case DATALINK_DIAL:
case DATALINK_LOGOUT:
case DATALINK_LOGIN:
descriptor_Read(&dl->chat.desc, bundle, fdset);
break;
@ -462,6 +470,7 @@ datalink_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
case DATALINK_HANGUP:
case DATALINK_DIAL:
case DATALINK_LOGOUT:
case DATALINK_LOGIN:
result = descriptor_Write(&dl->chat.desc, bundle, fdset);
break;
@ -497,10 +506,14 @@ datalink_ComeDown(struct datalink *dl, int how)
datalink_NewState(dl, DATALINK_READY);
} else if (dl->state != DATALINK_CLOSED && dl->state != DATALINK_HANGUP) {
physical_Offline(dl->physical);
chat_Destroy(&dl->chat);
if (dl->script.run && dl->state != DATALINK_OPENING) {
datalink_NewState(dl, DATALINK_HANGUP);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1, NULL);
if (dl->state == DATALINK_LOGOUT) {
datalink_NewState(dl, DATALINK_HANGUP);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, NULL);
} else {
datalink_NewState(dl, DATALINK_LOGOUT);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.logout, NULL);
}
} else
datalink_HangupDone(dl);
}
@ -756,6 +769,7 @@ datalink_Create(const char *name, struct bundle *bundle, int type)
*dl->cfg.script.dial = '\0';
*dl->cfg.script.login = '\0';
*dl->cfg.script.logout = '\0';
*dl->cfg.script.hangup = '\0';
*dl->cfg.phone.list = '\0';
*dl->phone.list = '\0';
@ -806,7 +820,9 @@ datalink_Create(const char *name, struct bundle *bundle, int type)
pap_Init(&dl->pap, dl->physical);
chap_Init(&dl->chap, dl->physical);
cbcp_Init(&dl->cbcp, dl->physical);
chat_Init(&dl->chat, dl->physical, NULL, 1, NULL);
memset(&dl->chat, '\0', sizeof dl->chat); /* Force buf{start,end} reset */
chat_Init(&dl->chat, dl->physical, NULL, NULL);
log_Printf(LogPHASE, "%s: Created in %s state\n",
dl->name, datalink_State(dl));
@ -868,7 +884,9 @@ datalink_Clone(struct datalink *odl, const char *name)
sizeof dl->physical->async.cfg);
cbcp_Init(&dl->cbcp, dl->physical);
chat_Init(&dl->chat, dl->physical, NULL, 1, NULL);
memset(&dl->chat, '\0', sizeof dl->chat); /* Force buf{start,end} reset */
chat_Init(&dl->chat, dl->physical, NULL, NULL);
log_Printf(LogPHASE, "%s: Cloned in %s state\n",
dl->name, datalink_State(dl));
@ -1084,6 +1102,8 @@ datalink_Show(struct cmdargs const *arg)
arg->cx->cfg.script.dial);
prompt_Printf(arg->prompt, " Login Script: %s\n",
arg->cx->cfg.script.login);
prompt_Printf(arg->prompt, " Logout Script: %s\n",
arg->cx->cfg.script.logout);
prompt_Printf(arg->prompt, " Hangup Script: %s\n",
arg->cx->cfg.script.hangup);
return 0;
@ -1193,6 +1213,7 @@ static const char *states[] = {
"hangup",
"dial",
"carrier",
"logout",
"login",
"ready",
"lcp",
@ -1301,7 +1322,9 @@ iov2datalink(struct bundle *bundle, struct iovec *iov, int *niov, int maxiov,
dl->chap.auth.cfg.fsm = copy;
cbcp_Init(&dl->cbcp, dl->physical);
chat_Init(&dl->chat, dl->physical, NULL, 1, NULL);
memset(&dl->chat, '\0', sizeof dl->chat); /* Force buf{start,end} reset */
chat_Init(&dl->chat, dl->physical, NULL, NULL);
log_Printf(LogPHASE, "%s: Transferred in %s state\n",
dl->name, datalink_State(dl));

View File

@ -31,12 +31,13 @@
#define DATALINK_HANGUP (2)
#define DATALINK_DIAL (3)
#define DATALINK_CARRIER (4)
#define DATALINK_LOGIN (5)
#define DATALINK_READY (6)
#define DATALINK_LCP (7)
#define DATALINK_AUTH (8)
#define DATALINK_CBCP (9)
#define DATALINK_OPEN (10)
#define DATALINK_LOGOUT (5)
#define DATALINK_LOGIN (6)
#define DATALINK_READY (7)
#define DATALINK_LCP (8)
#define DATALINK_AUTH (9)
#define DATALINK_CBCP (10)
#define DATALINK_OPEN (11)
#define DATALINK_MAXNAME (20) /* Maximum datalink::name length */
@ -65,10 +66,11 @@ struct datalink {
struct {
struct {
char dial[SCRIPT_LEN]; /* dial */
char login[SCRIPT_LEN]; /* login */
char hangup[SCRIPT_LEN]; /* hangup */
} script;
char dial[SCRIPT_LEN];
char login[SCRIPT_LEN];
char logout[SCRIPT_LEN];
char hangup[SCRIPT_LEN];
} script; /* various chat scripts */
struct {
char list[SCRIPT_LEN]; /* Telephone Numbers */
} phone;

View File

@ -1982,7 +1982,8 @@ Generate a CCP packet trace.
.It Li Chat
Generate
.Sq dial ,
.Sq login
.Sq login ,
.Sq logout
and
.Sq hangup
chat script trace logs.
@ -4135,6 +4136,9 @@ This
compliments the dial-script. If both are specified, the login
script will be executed after the dial script. Escape sequences
available in the dial script are also available here.
.It set logout Ar chat-script
This specifies the chat script that will be used to logout
before the hangup script is called. It should not normally be necessary.
.It set lqrperiod Ar frequency
This command sets the
.Ar frequency

View File

@ -1982,7 +1982,8 @@ Generate a CCP packet trace.
.It Li Chat
Generate
.Sq dial ,
.Sq login
.Sq login ,
.Sq logout
and
.Sq hangup
chat script trace logs.
@ -4135,6 +4136,9 @@ This
compliments the dial-script. If both are specified, the login
script will be executed after the dial script. Escape sequences
available in the dial script are also available here.
.It set logout Ar chat-script
This specifies the chat script that will be used to logout
before the hangup script is called. It should not normally be necessary.
.It set lqrperiod Ar frequency
This command sets the
.Ar frequency