Move phone numbers into struct datalink.

Make "show modem" look a bit prettier.
This commit is contained in:
Brian Somers 1998-03-09 19:24:58 +00:00
parent f8543b9e45
commit f95458053f
8 changed files with 86 additions and 65 deletions

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: chat.c,v 1.44.2.11 1998/02/23 00:38:20 brian Exp $
* $Id: chat.c,v 1.44.2.12 1998/02/26 17:54:40 brian Exp $
*/
#include <sys/param.h>
@ -502,7 +502,8 @@ 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, int emptybuf,
const char *phone)
{
c->desc.type = CHAT_DESCRIPTOR;
c->desc.next = NULL;
@ -532,6 +533,7 @@ chat_Init(struct chat *c, struct physical *p, const char *data, int emptybuf)
c->TimeoutSec = 30;
c->TimedOut = 0;
c->phone = phone;
c->abort.num = 0;
StopTimer(&c->pause);
@ -620,7 +622,6 @@ chat_ExpandString(struct chat *c, const char *str, char *result, int reslen,
int sendmode)
{
int addcr = 0;
char *phone;
result[--reslen] = '\0';
if (sendmode)
@ -664,19 +665,11 @@ chat_ExpandString(struct chat *c, const char *str, char *result, int reslen,
result += strlen(result);
break;
case 'T':
if (VarAltPhone == NULL) {
if (VarNextPhone == NULL) {
strncpy(VarPhoneCopy, VarPhoneList, sizeof VarPhoneCopy - 1);
VarPhoneCopy[sizeof VarPhoneCopy - 1] = '\0';
VarNextPhone = VarPhoneCopy;
}
VarAltPhone = strsep(&VarNextPhone, ":");
}
phone = strsep(&VarAltPhone, "|");
strncpy(result, phone, reslen);
reslen -= strlen(result);
result += strlen(result);
LogPrintf(LogPHASE, "Phone: %s\n", phone);
if (c != NULL) {
strncpy(result, c->phone, reslen);
reslen -= strlen(result);
result += strlen(result);
}
break;
case 'U':
strncpy(result, VarAuthName, reslen);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: chat.h,v 1.9.2.2 1998/02/13 05:10:08 brian Exp $
* $Id: chat.h,v 1.9.2.3 1998/02/26 17:54:43 brian Exp $
*/
#define CHAT_EXPECT 0
@ -56,6 +56,8 @@ struct chat {
int TimeoutSec; /* Expect timeout value */
int TimedOut; /* We timed out */
const char *phone; /* Our phone number */
struct {
struct {
char *data; /* Abort the dial if we get one */
@ -72,7 +74,8 @@ struct chat {
#define descriptor2chat(d) \
((d)->type == CHAT_DESCRIPTOR ? (struct chat *)(d) : NULL)
void chat_Init(struct chat *, struct physical *, const char *, int);
void chat_Init(struct chat *, struct physical *, const char *, int,
const char *);
void chat_Destroy(struct chat *);
extern struct chat chat;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.c,v 1.131.2.30 1998/03/01 01:07:42 brian Exp $
* $Id: command.c,v 1.131.2.31 1998/03/06 00:34:42 brian Exp $
*
*/
#include <sys/param.h>
@ -1337,12 +1337,8 @@ SetVariable(struct cmdargs const *arg)
VarAccmap = map;
break;
case VAR_PHONE:
strncpy(VarPhoneList, argp, sizeof VarPhoneList - 1);
VarPhoneList[sizeof VarPhoneList - 1] = '\0';
strncpy(VarPhoneCopy, VarPhoneList, sizeof VarPhoneCopy - 1);
VarPhoneCopy[sizeof VarPhoneCopy - 1] = '\0';
VarNextPhone = VarPhoneCopy;
VarAltPhone = NULL;
strncpy(cx->cfg.phone.list, argp, sizeof cx->cfg.phone.list - 1);
cx->cfg.phone.list[sizeof cx->cfg.phone.list - 1] = '\0';
break;
case VAR_HANGUP:
if (!(mode & (MODE_DIRECT|MODE_DEDICATED))) {
@ -1447,7 +1443,7 @@ static struct cmdtab const SetCommands[] = {
"Set open mode", "set openmode [active|passive]"},
{"parity", NULL, SetModemParity, LOCAL_AUTH | LOCAL_CX,
"Set modem parity", "set parity [odd|even|none]"},
{"phone", NULL, SetVariable, LOCAL_AUTH, "Set telephone number(s)",
{"phone", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX, "Set telephone number(s)",
"set phone phone1[:phone2[...]]", (const void *) VAR_PHONE},
{"reconnect", NULL, SetReconnect, LOCAL_AUTH | LOCAL_CX,
"Set Reconnect timeout", "set reconnect value ntries"},

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: datalink.c,v 1.1.2.15 1998/02/27 01:22:20 brian Exp $
* $Id: datalink.c,v 1.1.2.16 1998/03/01 01:07:43 brian Exp $
*/
#include <sys/param.h>
@ -100,6 +100,7 @@ static void
datalink_HangupDone(struct datalink *dl)
{
modem_Close(dl->physical);
dl->phone.chosen = "[N/A]";
if (!dl->dial_tries || (dl->dial_tries < 0 && !dl->reconnect_tries)) {
LogPrintf(LogPHASE, "%s: Entering CLOSED state\n", dl->name);
@ -117,7 +118,7 @@ datalink_HangupDone(struct datalink *dl)
dl->reconnect_tries--;
} else {
dl->dial_tries--;
if (VarNextPhone == NULL)
if (dl->phone.next == NULL)
datalink_StartDialTimer(dl, dl->cfg.dial_timeout);
else
datalink_StartDialTimer(dl, dl->cfg.dial_next_timeout);
@ -125,6 +126,26 @@ datalink_HangupDone(struct datalink *dl)
}
}
static const char *
datalink_ChoosePhoneNumber(struct datalink *dl)
{
char *phone;
if (dl->phone.alt == NULL) {
if (dl->phone.next == NULL) {
strncpy(dl->phone.list, dl->cfg.phone.list, sizeof dl->phone.list - 1);
dl->phone.list[sizeof dl->phone.list - 1] = '\0';
dl->phone.next = dl->phone.list;
}
dl->phone.alt = strsep(&dl->phone.next, ":");
}
phone = strsep(&dl->phone.alt, "|");
dl->phone.chosen = *phone ? phone : "[NONE]";
if (*phone)
LogPrintf(LogPHASE, "Phone: %s\n", phone);
return phone;
}
static void
datalink_LoginDone(struct datalink *dl)
{
@ -139,7 +160,7 @@ datalink_LoginDone(struct datalink *dl)
LogPrintf(LogPHASE, "%s: Entering HANGUP state\n", dl->name);
dl->state = DATALINK_HANGUP;
modem_Offline(dl->physical);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1, NULL);
} else
datalink_HangupDone(dl);
} else {
@ -175,7 +196,8 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
if (dl->script.run) {
LogPrintf(LogPHASE, "%s: Entering DIAL state\n", dl->name);
dl->state = DATALINK_DIAL;
chat_Init(&dl->chat, dl->physical, dl->cfg.script.dial, 1);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.dial, 1,
datalink_ChoosePhoneNumber(dl));
if (!(mode & MODE_DDIAL) && dl->cfg.max_dial)
LogPrintf(LogCHAT, "%s: Dial attempt %u of %d\n",
dl->name, dl->cfg.max_dial - dl->dial_tries,
@ -215,7 +237,7 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
case DATALINK_DIAL:
LogPrintf(LogPHASE, "%s: Entering LOGIN state\n", dl->name);
dl->state = DATALINK_LOGIN;
chat_Init(&dl->chat, dl->physical, dl->cfg.script.login, 0);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.login, 0, NULL);
break;
case DATALINK_LOGIN:
datalink_LoginDone(dl);
@ -234,7 +256,7 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
LogPrintf(LogPHASE, "%s: Entering HANGUP state\n", dl->name);
dl->state = DATALINK_HANGUP;
modem_Offline(dl->physical);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1, NULL);
break;
}
break;
@ -338,7 +360,7 @@ datalink_ComeDown(struct datalink *dl, int stay)
if (dl->script.run && dl->state != DATALINK_OPENING) {
LogPrintf(LogPHASE, "%s: Entering HANGUP state\n", dl->name);
dl->state = DATALINK_HANGUP;
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1, NULL);
} else
datalink_HangupDone(dl);
}
@ -449,6 +471,11 @@ datalink_Create(const char *name, struct bundle *bundle,
*dl->cfg.script.dial = '\0';
*dl->cfg.script.login = '\0';
*dl->cfg.script.hangup = '\0';
*dl->cfg.phone.list = '\0';
*dl->phone.list = '\0';
dl->phone.next = NULL;
dl->phone.alt = NULL;
dl->phone.chosen = "N/A";
dl->script.run = 1;
dl->script.packetmode = 1;
@ -472,7 +499,7 @@ datalink_Create(const char *name, struct bundle *bundle,
free(dl);
return NULL;
}
chat_Init(&dl->chat, dl->physical, NULL, 1);
chat_Init(&dl->chat, dl->physical, NULL, 1, NULL);
dl->parent = parent;
dl->fsm.LayerStart = datalink_LayerStart;

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: datalink.h,v 1.1.2.9 1998/02/27 01:22:21 brian Exp $
* $Id: datalink.h,v 1.1.2.10 1998/03/01 01:07:43 brian Exp $
*/
#define DATALINK_CLOSED (0)
@ -56,6 +56,9 @@ struct datalink {
char login[SCRIPT_LEN]; /* login */
char hangup[SCRIPT_LEN]; /* hangup */
} script;
struct {
char list[SCRIPT_LEN]; /* Telephone Numbers */
} phone;
int max_dial; /* initially try again this number of times */
int dial_timeout; /* Redial timeout value */
int dial_next_timeout; /* Redial next timeout value */
@ -63,6 +66,13 @@ struct datalink {
int reconnect_timeout; /* Timeout before reconnect on carrier loss */
} cfg; /* All our config data is in here */
struct {
char list[SCRIPT_LEN]; /* copy of cfg.list for strsep() */
char *next; /* Next phone from the list */
char *alt; /* Next phone from the list */
char *chosen; /* Chosen phone number after DIAL */
} phone;
int dial_tries; /* currently try again this number of times */
unsigned reconnect_tries; /* currently try again this number of times */

View File

@ -15,19 +15,19 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: defs.h,v 1.29.2.3 1998/02/16 19:11:06 brian Exp $
* $Id: defs.h,v 1.29.2.4 1998/03/06 00:34:43 brian Exp $
*
* TODO:
*/
/* Check the following definitions for your machine environment */
#ifdef __FreeBSD__
# define MODEM_LIST "/dev/cuaa1,/dev/cuaa0" /* name of tty device */
# define MODEM_LIST "/dev/cuaa1, /dev/cuaa0" /* name of tty device */
#else
# ifdef __OpenBSD__
# define MODEM_LIST "/dev/cua01,/dev/cua00" /* name of tty device */
# define MODEM_LIST "/dev/cua01, /dev/cua00" /* name of tty device */
# else
# define MODEM_LIST "/dev/tty01,/dev/tty00" /* name of tty device */
# define MODEM_LIST "/dev/tty01, /dev/tty00" /* name of tty device */
# endif
#endif

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: modem.c,v 1.77.2.27 1998/03/01 01:07:47 brian Exp $
* $Id: modem.c,v 1.77.2.28 1998/03/06 00:34:44 brian Exp $
*
* TODO:
*/
@ -910,31 +910,30 @@ modem_ShowStatus(struct cmdargs const *arg)
dev = *arg->cx->physical->name.full ?
arg->cx->physical->name.full : "stdin";
prompt_Printf(&prompt, "device configuration: %s\n",
arg->cx->physical->cfg.devlist);
prompt_Printf(&prompt, "device: %s speed: ", dev);
prompt_Printf(&prompt, "device list: %s\n", arg->cx->physical->cfg.devlist);
prompt_Printf(&prompt, "device: %s\n ", dev);
if (Physical_IsSync(arg->cx->physical))
prompt_Printf(&prompt, "sync\n");
prompt_Printf(&prompt, "sync");
else
prompt_Printf(&prompt, "%d\n", arg->cx->physical->cfg.speed);
prompt_Printf(&prompt, "%dbps", arg->cx->physical->cfg.speed);
switch (arg->cx->physical->cfg.parity & CSIZE) {
case CS7:
prompt_Printf(&prompt, "cs7, ");
prompt_Printf(&prompt, ", cs7");
break;
case CS8:
prompt_Printf(&prompt, "cs8, ");
prompt_Printf(&prompt, ", cs8");
break;
}
if (arg->cx->physical->cfg.parity & PARENB) {
if (arg->cx->physical->cfg.parity & PARODD)
prompt_Printf(&prompt, "odd parity, ");
prompt_Printf(&prompt, ", odd parity");
else
prompt_Printf(&prompt, "even parity, ");
prompt_Printf(&prompt, ", even parity");
} else
prompt_Printf(&prompt, "no parity, ");
prompt_Printf(&prompt, ", no parity");
prompt_Printf(&prompt, "CTS/RTS %s.\n",
prompt_Printf(&prompt, ", CTS/RTS %s\n",
(arg->cx->physical->cfg.rts_cts ? "on" : "off"));
if (LogIsKept(LogDEBUG))
@ -945,15 +944,16 @@ modem_ShowStatus(struct cmdargs const *arg)
#ifdef TIOCOUTQ
if (arg->cx->physical->fd >= 0)
if (ioctl(arg->cx->physical->fd, TIOCOUTQ, &nb) >= 0)
prompt_Printf(&prompt, "outq: %d\n", nb);
prompt_Printf(&prompt, "outq: %d\n", nb);
else
prompt_Printf(&prompt, "outq: ioctl probe failed: %s\n", strerror(errno));
#endif
prompt_Printf(&prompt, "outqlen: %d\n",
prompt_Printf(&prompt, "outq packets: %d\n",
link_QueueLen(&arg->cx->physical->link));
prompt_Printf(&prompt, "DialScript = %s\n", arg->cx->cfg.script.dial);
prompt_Printf(&prompt, "LoginScript = %s\n", arg->cx->cfg.script.login);
prompt_Printf(&prompt, "PhoneNumber(s) = %s\n", arg->cx->cfg.script.hangup);
prompt_Printf(&prompt, "DialScript: %s\n", arg->cx->cfg.script.dial);
prompt_Printf(&prompt, "LoginScript: %s\n", arg->cx->cfg.script.login);
prompt_Printf(&prompt, "Phone list: %s\n", arg->cx->cfg.phone.list);
prompt_Printf(&prompt, "Phone Number: %s\n", arg->cx->phone.chosen);
prompt_Printf(&prompt, "\n");
throughput_disp(&arg->cx->physical->link.throughput);

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: vars.h,v 1.42.2.9 1998/02/17 19:28:01 brian Exp $
* $Id: vars.h,v 1.42.2.10 1998/03/06 00:34:47 brian Exp $
*
* TODO:
*/
@ -80,10 +80,6 @@ struct pppvars {
#ifdef HAVE_DES
int use_MSChap; /* Use MSCHAP encryption */
#endif
char phone_numbers[200]; /* Telephone Numbers */
char phone_copy[200]; /* copy for strsep() */
char *next_phone; /* Next phone from the list */
char *alt_phone; /* Next phone from the list */
char shostname[MAXHOSTNAMELEN]; /* Local short Host Name */
struct aliasHandlers handler; /* Alias function pointers */
};
@ -103,10 +99,6 @@ struct pppvars {
#ifdef HAVE_DES
#define VarMSChap pppVars.use_MSChap
#endif
#define VarPhoneList pppVars.phone_numbers
#define VarPhoneCopy pppVars.phone_copy
#define VarNextPhone pppVars.next_phone
#define VarAltPhone pppVars.alt_phone
#define VarShortHost pppVars.shostname
#define VarLoopback pppVars.loopback