diff --git a/usr.sbin/ppp/Makefile b/usr.sbin/ppp/Makefile index 9096ae34458..84ff9fde213 100644 --- a/usr.sbin/ppp/Makefile +++ b/usr.sbin/ppp/Makefile @@ -1,10 +1,10 @@ -# $Id: Makefile,v 1.36.2.4 1998/02/06 02:23:26 brian Exp $ +# $Id: Makefile,v 1.36.2.5 1998/02/07 20:49:12 brian Exp $ PROG= ppp SRCS= arp.c async.c auth.c bundle.c ccp.c chap.c chat.c command.c deflate.c \ defs.c filter.c fsm.c hdlc.c id.c ip.c ipcp.c iplist.c lcp.c \ - link.c log.c lqr.c main.c mbuf.c modem.c pap.c physical.c \ - pred.c route.c server.c sig.c slcompress.c systems.c throughput.c \ + link.c log.c lqr.c main.c mbuf.c modem.c pap.c physical.c pred.c \ + prompt.c route.c server.c sig.c slcompress.c systems.c throughput.c \ timer.c tun.c vars.c vjcomp.c CFLAGS+=-Wall -Wpointer-arith LDADD+= -lmd -lcrypt -lutil -lz diff --git a/usr.sbin/ppp/alias_cmd.c b/usr.sbin/ppp/alias_cmd.c index 9f0898bacf0..c59dde4d1ed 100644 --- a/usr.sbin/ppp/alias_cmd.c +++ b/usr.sbin/ppp/alias_cmd.c @@ -2,7 +2,7 @@ * The code in this file was written by Eivind Eklund , * who places it in the public domain without restriction. * - * $Id: alias_cmd.c,v 1.12 1998/01/21 02:15:07 brian Exp $ + * $Id: alias_cmd.c,v 1.12.2.1 1998/01/29 23:11:30 brian Exp $ */ #include @@ -14,6 +14,7 @@ #include #include #include +#include #include "defs.h" #include "command.h" @@ -22,6 +23,8 @@ #include "loadalias.h" #include "vars.h" #include "alias_cmd.h" +#include "descriptor.h" +#include "prompt.h" static int StrToAddr(const char *, struct in_addr *); @@ -33,8 +36,7 @@ int AliasRedirectPort(struct cmdargs const *arg) { if (!(mode & MODE_ALIAS)) { - if (VarTerm) - fprintf(VarTerm, "Alias not enabled\n"); + prompt_Printf(&prompt, "Alias not enabled\n"); return 1; } else if (arg->argc == 3) { char proto_constant; @@ -52,28 +54,24 @@ AliasRedirectPort(struct cmdargs const *arg) } else if (strcmp(proto, "udp") == 0) { proto_constant = IPPROTO_UDP; } else { - if (VarTerm) { - fprintf(VarTerm, "port redirect: protocol must be tcp or udp\n"); - fprintf(VarTerm, "Usage: alias %s %s\n", arg->cmd->name, - arg->cmd->syntax); - } + prompt_Printf(&prompt, "port redirect: protocol must be tcp or udp\n"); + prompt_Printf(&prompt, "Usage: alias %s %s\n", arg->cmd->name, + arg->cmd->syntax); return 1; } error = StrToAddrAndPort(arg->argv[1], &local_addr, &local_port, proto); if (error) { - if (VarTerm) { - fprintf(VarTerm, "port redirect: error reading local addr:port\n"); - fprintf(VarTerm, "Usage: alias %s %s\n", arg->cmd->name, arg->cmd->syntax); - } + prompt_Printf(&prompt, "port redirect: error reading local addr:port\n"); + prompt_Printf(&prompt, "Usage: alias %s %s\n", arg->cmd->name, + arg->cmd->syntax); return 1; } error = StrToPort(arg->argv[2], &alias_port, proto); if (error) { - if (VarTerm) { - fprintf(VarTerm, "port redirect: error reading alias port\n"); - fprintf(VarTerm, "Usage: alias %s %s\n", arg->cmd->name, arg->cmd->syntax); - } + prompt_Printf(&prompt, "port redirect: error reading alias port\n"); + prompt_Printf(&prompt, "Usage: alias %s %s\n", arg->cmd->name, + arg->cmd->syntax); return 1; } null_addr.s_addr = INADDR_ANY; @@ -83,8 +81,8 @@ AliasRedirectPort(struct cmdargs const *arg) null_addr, alias_port, proto_constant); - if (link == NULL && VarTerm) - fprintf(VarTerm, "port redirect: error returned by packed" + if (link == NULL) + prompt_Printf(&prompt, "port redirect: error returned by packed" " aliasing engine (code=%d)\n", error); } else return -1; @@ -97,8 +95,7 @@ int AliasRedirectAddr(struct cmdargs const *arg) { if (!(mode & MODE_ALIAS)) { - if (VarTerm) - fprintf(VarTerm, "alias not enabled\n"); + prompt_Printf(&prompt, "alias not enabled\n"); return 1; } else if (arg->argc == 2) { int error; @@ -108,22 +105,22 @@ AliasRedirectAddr(struct cmdargs const *arg) error = StrToAddr(arg->argv[0], &local_addr); if (error) { - if (VarTerm) - fprintf(VarTerm, "address redirect: invalid local address\n"); + prompt_Printf(&prompt, "address redirect: invalid local address\n"); return 1; } error = StrToAddr(arg->argv[1], &alias_addr); if (error) { - if (VarTerm) { - fprintf(VarTerm, "address redirect: invalid alias address\n"); - fprintf(VarTerm, "Usage: alias %s %s\n", arg->cmd->name, arg->cmd->syntax); - } + prompt_Printf(&prompt, "address redirect: invalid alias address\n"); + prompt_Printf(&prompt, "Usage: alias %s %s\n", arg->cmd->name, + arg->cmd->syntax); return 1; } link = VarPacketAliasRedirectAddr(local_addr, alias_addr); - if (link == NULL && VarTerm) { - fprintf(VarTerm, "address redirect: packet aliasing engine error\n"); - fprintf(VarTerm, "Usage: alias %s %s\n", arg->cmd->name, arg->cmd->syntax); + if (link == NULL) { + prompt_Printf(&prompt, "address redirect: packet aliasing" + " engine error\n"); + prompt_Printf(&prompt, "Usage: alias %s %s\n", arg->cmd->name, + arg->cmd->syntax); } } else return -1; diff --git a/usr.sbin/ppp/bundle.c b/usr.sbin/ppp/bundle.c index a15c091b5c9..bffb50efa81 100644 --- a/usr.sbin/ppp/bundle.c +++ b/usr.sbin/ppp/bundle.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: bundle.c,v 1.1.2.6 1998/02/08 19:29:43 brian Exp $ + * $Id: bundle.c,v 1.1.2.7 1998/02/09 19:20:33 brian Exp $ */ #include @@ -73,6 +73,7 @@ #include "pap.h" #include "chap.h" #include "tun.h" +#include "prompt.h" static const char *PhaseNames[] = { "Dead", "Establish", "Authenticate", "Network", "Terminate" @@ -115,7 +116,7 @@ bundle_NewPhase(struct bundle *bundle, struct physical *physical, u_int new) if (LcpInfo.want_auth == PROTO_CHAP) StartAuthChallenge(&AuthChapInfo, physical); bundle->phase = new; - Prompt(bundle); + prompt_Display(&prompt, bundle); } else bundle_NewPhase(bundle, physical, PHASE_NETWORK); break; @@ -130,7 +131,7 @@ bundle_NewPhase(struct bundle *bundle, struct physical *physical, u_int new) case PHASE_TERMINATE: bundle->phase = new; - Prompt(bundle); + prompt_Display(&prompt, bundle); break; } } @@ -286,8 +287,8 @@ bundle_Create(const char *prefix) } if (bundle.unit > MAX_TUN) { - if (VarTerm) - fprintf(VarTerm, "No tunnel device is available (%s).\n", strerror(err)); + prompt_Printf(&prompt, "No tunnel device is available (%s).\n", + strerror(err)); return NULL; } @@ -339,8 +340,7 @@ bundle_Create(const char *prefix) return NULL; } - if (VarTerm) - fprintf(VarTerm, "Using interface: %s\n", bundle.ifname); + prompt_Printf(&prompt, "Using interface: %s\n", bundle.ifname); LogPrintf(LogPHASE, "Using interface: %s\n", bundle.ifname); bundle.routing_seq = 0; diff --git a/usr.sbin/ppp/ccp.c b/usr.sbin/ppp/ccp.c index 338975120ac..9bc22460b4e 100644 --- a/usr.sbin/ppp/ccp.c +++ b/usr.sbin/ppp/ccp.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: ccp.c,v 1.30.2.7 1998/02/07 20:49:26 brian Exp $ + * $Id: ccp.c,v 1.30.2.8 1998/02/08 11:04:45 brian Exp $ * * TODO: * o Support other compression protocols @@ -27,6 +27,7 @@ #include #include +#include #include "command.h" #include "mbuf.h" @@ -42,6 +43,8 @@ #include "pred.h" #include "deflate.h" #include "bundle.h" +#include "descriptor.h" +#include "prompt.h" static void CcpSendConfigReq(struct fsm *); static void CcpSendTerminateReq(struct fsm *); @@ -128,15 +131,13 @@ static const struct ccp_algorithm *algorithm[] = { int ReportCcpStatus(struct cmdargs const *arg) { - if (VarTerm) { - fprintf(VarTerm, "%s [%s]\n", CcpInfo.fsm.name, - StateNames[CcpInfo.fsm.state]); - fprintf(VarTerm, "My protocol = %s, His protocol = %s\n", - protoname(CcpInfo.my_proto), protoname(CcpInfo.his_proto)); - fprintf(VarTerm, "Output: %ld --> %ld, Input: %ld --> %ld\n", - CcpInfo.uncompout, CcpInfo.compout, - CcpInfo.compin, CcpInfo.uncompin); - } + prompt_Printf(&prompt, "%s [%s]\n", CcpInfo.fsm.name, + StateNames[CcpInfo.fsm.state]); + prompt_Printf(&prompt, "My protocol = %s, His protocol = %s\n", + protoname(CcpInfo.my_proto), protoname(CcpInfo.his_proto)); + prompt_Printf(&prompt, "Output: %ld --> %ld, Input: %ld --> %ld\n", + CcpInfo.uncompout, CcpInfo.compout, + CcpInfo.compin, CcpInfo.uncompin); return 0; } diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c index d0d096e2d91..65eeaa16417 100644 --- a/usr.sbin/ppp/chat.c +++ b/usr.sbin/ppp/chat.c @@ -18,7 +18,7 @@ * Columbus, OH 43221 * (614)451-1883 * - * $Id: chat.c,v 1.44.2.4 1998/02/06 02:23:30 brian Exp $ + * $Id: chat.c,v 1.44.2.5 1998/02/09 19:20:36 brian Exp $ * * TODO: * o Support more UUCP compatible control sequences. @@ -58,6 +58,7 @@ #include "descriptor.h" #include "physical.h" #include "chat.h" +#include "prompt.h" #ifndef isblank #define isblank(c) ((c) == '\t' || (c) == ' ') @@ -202,8 +203,7 @@ ExpandString(const char *str, char *result, int reslen, int sendmode) strncpy(result, phone, reslen); reslen -= strlen(result); result += strlen(result); - if (VarTerm) - fprintf(VarTerm, "Phone: %s\n", phone); + prompt_Printf(&prompt, "Phone: %s\n", phone); LogPrintf(LogPHASE, "Phone: %s\n", phone); break; case 'U': diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index b5a495cfff9..f558d90f11b 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -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.13 1998/02/09 19:23:58 brian Exp $ + * $Id: command.c,v 1.131.2.14 1998/02/10 03:21:39 brian Exp $ * */ #include @@ -77,6 +77,7 @@ #include "descriptor.h" #include "physical.h" #include "server.h" +#include "prompt.h" struct in_addr ifnetmask; static const char *HIDDEN = "********"; @@ -105,14 +106,11 @@ HelpCommand(struct cmdargs const *arg) struct cmdtab const *cmd; int n, cmax, dmax, cols; - if (!VarTerm) - return 0; - if (arg->argc > 0) { for (cmd = arg->cmd; cmd->name; cmd++) if (strcasecmp(cmd->name, *arg->argv) == 0 && (cmd->lauth & VarLocalAuth)) { - fprintf(VarTerm, "%s\n", cmd->syntax); + prompt_Printf(&prompt, "%s\n", cmd->syntax); return 0; } return -1; @@ -130,13 +128,13 @@ HelpCommand(struct cmdargs const *arg) n = 0; for (cmd = arg->cmd; cmd->func; cmd++) if (cmd->name && (cmd->lauth & VarLocalAuth)) { - fprintf(VarTerm, " %-*.*s: %-*.*s", + prompt_Printf(&prompt, " %-*.*s: %-*.*s", cmax, cmax, cmd->name, dmax, dmax, cmd->helpmes); if (++n % cols == 0) - fprintf(VarTerm, "\n"); + prompt_Printf(&prompt, "\n"); } if (n % cols != 0) - fprintf(VarTerm, "\n"); + prompt_Printf(&prompt, "\n"); return 0; } @@ -159,8 +157,8 @@ IsInteractive(int Display) else if (mode & MODE_INTER) m = "interactive"; if (m) { - if (Display && VarTerm) - fprintf(VarTerm, "Working in %s mode\n", m); + if (Display) + prompt_Printf(&prompt, "Working in %s mode\n", m); } return mode & MODE_INTER; } @@ -172,8 +170,8 @@ DialCommand(struct cmdargs const *arg) int res; if (LcpInfo.fsm.state > ST_CLOSED) { - if (VarTerm) - fprintf(VarTerm, "LCP state is [%s]\n", StateNames[LcpInfo.fsm.state]); + prompt_Printf(&prompt, "LCP state is [%s]\n", + StateNames[LcpInfo.fsm.state]); return 0; } @@ -193,11 +191,9 @@ DialCommand(struct cmdargs const *arg) VarRedialNextTimeout); nointr_sleep(VarRedialNextTimeout); } - if (VarTerm) - fprintf(VarTerm, "Dial attempt %u of %d\n", ++tries, VarDialTries); + prompt_Printf(&prompt, "Dial attempt %u of %d\n", ++tries, VarDialTries); if (modem_Open(arg->bundle->physical, arg->bundle) < 0) { - if (VarTerm) - fprintf(VarTerm, "Failed to open modem.\n"); + prompt_Printf(&prompt, "Failed to open modem.\n"); break; } if ((res = modem_Dial(arg->bundle->physical, arg->bundle)) == EX_DONE) { @@ -246,7 +242,7 @@ ShellCommand(struct cmdargs const *arg, int bg) * we want to stop shell commands when we've got a telnet connection to an * auto mode ppp */ - if (VarTerm && !(mode & MODE_INTER)) { + if (prompt_Active(&prompt) && !(mode & MODE_INTER)) { LogPrintf(LogWARN, "Shell is not allowed interactively in auto mode\n"); return 1; } @@ -254,7 +250,7 @@ ShellCommand(struct cmdargs const *arg, int bg) if (arg->argc == 0) if (!(mode & MODE_INTER)) { - if (VarTerm) + if (prompt_Active(&prompt)) LogPrintf(LogWARN, "Can't start an interactive shell from" " a telnet session\n"); else @@ -279,8 +275,8 @@ ShellCommand(struct cmdargs const *arg, int bg) signal(SIGHUP, SIG_DFL); signal(SIGALRM, SIG_DFL); - if (VarTerm) - fd = fileno(VarTerm); + if (prompt_Active(&prompt)) + fd = prompt.fd_out; else if ((fd = open("/dev/null", O_RDWR)) == -1) { LogPrintf(LogALERT, "Failed to open /dev/null: %s\n", strerror(errno)); exit(1); @@ -291,7 +287,7 @@ ShellCommand(struct cmdargs const *arg, int bg) for (dtablesize = getdtablesize(), i = 3; i < dtablesize; i++) close(i); - TtyOldMode(); + prompt_TtyOldMode(&prompt); setuid(geteuid()); if (arg->argc > 0) { /* substitute pseudo args */ @@ -315,11 +311,11 @@ ShellCommand(struct cmdargs const *arg, int bg) LogPrintf(LogERROR, "%d: daemon: %s\n", p, strerror(errno)); exit(1); } - } else if (VarTerm) + } else if (prompt_Active(&prompt)) printf("ppp: Pausing until %s finishes\n", arg->argv[0]); execvp(argv[0], argv); } else { - if (VarTerm) + if (prompt_Active(&prompt)) printf("ppp: Pausing until %s finishes\n", shell); execl(shell, shell, NULL); } @@ -336,7 +332,7 @@ ShellCommand(struct cmdargs const *arg, int bg) waitpid(shpid, &status, 0); } - TtyCommandMode(arg->bundle, 0); + prompt_TtyCommandMode(&prompt); return (0); } @@ -412,9 +408,7 @@ static struct cmdtab const Commands[] = { static int ShowLoopback(struct cmdargs const *arg) { - if (VarTerm) - fprintf(VarTerm, "Local loopback is %s\n", VarLoopback ? "on" : "off"); - + prompt_Printf(&prompt, "Local loopback is %s\n", VarLoopback ? "on" : "off"); return 0; } @@ -423,20 +417,17 @@ ShowLogLevel(struct cmdargs const *arg) { int i; - if (!VarTerm) - return 0; - - fprintf(VarTerm, "Log: "); + prompt_Printf(&prompt, "Log: "); for (i = LogMIN; i <= LogMAX; i++) if (LogIsKept(i) & LOG_KEPT_SYSLOG) - fprintf(VarTerm, " %s", LogName(i)); + prompt_Printf(&prompt, " %s", LogName(i)); - fprintf(VarTerm, "\nLocal:"); + prompt_Printf(&prompt, "\nLocal:"); for (i = LogMIN; i <= LogMAX; i++) if (LogIsKept(i) & LOG_KEPT_LOCAL) - fprintf(VarTerm, " %s", LogName(i)); + prompt_Printf(&prompt, " %s", LogName(i)); - fprintf(VarTerm, "\n"); + prompt_Printf(&prompt, "\n"); return 0; } @@ -446,15 +437,13 @@ ShowEscape(struct cmdargs const *arg) { int code, bit; - if (!VarTerm) - return 0; if (EscMap[32]) { for (code = 0; code < 32; code++) if (EscMap[code]) for (bit = 0; bit < 8; bit++) if (EscMap[code] & (1 << bit)) - fprintf(VarTerm, " 0x%02x", (code << 3) + bit); - fprintf(VarTerm, "\n"); + prompt_Printf(&prompt, " 0x%02x", (code << 3) + bit); + prompt_Printf(&prompt, "\n"); } return 0; } @@ -462,44 +451,43 @@ ShowEscape(struct cmdargs const *arg) static int ShowTimeout(struct cmdargs const *arg) { - if (VarTerm) { - int remaining; + int remaining; + + prompt_Printf(&prompt, " Idle Timer: %d secs LQR Timer: %d secs" + " Retry Timer: %d secs\n", VarIdleTimeout, VarLqrTimeout, + VarRetryTimeout); + remaining = RemainingIdleTime(); + if (remaining != -1) + prompt_Printf(&prompt, " %d secs remaining\n", remaining); - fprintf(VarTerm, " Idle Timer: %d secs LQR Timer: %d secs" - " Retry Timer: %d secs\n", VarIdleTimeout, VarLqrTimeout, - VarRetryTimeout); - remaining = RemainingIdleTime(); - if (remaining != -1) - fprintf(VarTerm, " %d secs remaining\n", remaining); - } return 0; } static int ShowStopped(struct cmdargs const *arg) { - if (!VarTerm) - return 0; - - fprintf(VarTerm, " Stopped Timer: LCP: "); + prompt_Printf(&prompt, " Stopped Timer: LCP: "); if (!LcpInfo.fsm.StoppedTimer.load) - fprintf(VarTerm, "Disabled"); + prompt_Printf(&prompt, "Disabled"); else - fprintf(VarTerm, "%ld secs", LcpInfo.fsm.StoppedTimer.load / SECTICKS); + prompt_Printf(&prompt, "%ld secs", + LcpInfo.fsm.StoppedTimer.load / SECTICKS); - fprintf(VarTerm, ", IPCP: "); + prompt_Printf(&prompt, ", IPCP: "); if (!IpcpInfo.fsm.StoppedTimer.load) - fprintf(VarTerm, "Disabled"); + prompt_Printf(&prompt, "Disabled"); else - fprintf(VarTerm, "%ld secs", IpcpInfo.fsm.StoppedTimer.load / SECTICKS); + prompt_Printf(&prompt, "%ld secs", + IpcpInfo.fsm.StoppedTimer.load / SECTICKS); - fprintf(VarTerm, ", CCP: "); + prompt_Printf(&prompt, ", CCP: "); if (!CcpInfo.fsm.StoppedTimer.load) - fprintf(VarTerm, "Disabled"); + prompt_Printf(&prompt, "Disabled"); else - fprintf(VarTerm, "%ld secs", CcpInfo.fsm.StoppedTimer.load / SECTICKS); + prompt_Printf(&prompt, "%ld secs", + CcpInfo.fsm.StoppedTimer.load / SECTICKS); - fprintf(VarTerm, "\n"); + prompt_Printf(&prompt, "\n"); return 0; } @@ -507,12 +495,10 @@ ShowStopped(struct cmdargs const *arg) static int ShowAuthKey(struct cmdargs const *arg) { - if (!VarTerm) - return 0; - fprintf(VarTerm, "AuthName = %s\n", VarAuthName); - fprintf(VarTerm, "AuthKey = %s\n", HIDDEN); + prompt_Printf(&prompt, "AuthName = %s\n", VarAuthName); + prompt_Printf(&prompt, "AuthKey = %s\n", HIDDEN); #ifdef HAVE_DES - fprintf(VarTerm, "Encrypt = %s\n", VarMSChap ? "MSChap" : "MD5" ); + prompt_Printf(&prompt, "Encrypt = %s\n", VarMSChap ? "MSChap" : "MD5" ); #endif return 0; } @@ -520,64 +506,56 @@ ShowAuthKey(struct cmdargs const *arg) static int ShowVersion(struct cmdargs const *arg) { - if (VarTerm) - fprintf(VarTerm, "%s - %s \n", VarVersion, VarLocalVersion); + prompt_Printf(&prompt, "%s - %s \n", VarVersion, VarLocalVersion); return 0; } static int ShowInitialMRU(struct cmdargs const *arg) { - if (VarTerm) - fprintf(VarTerm, " Initial MRU: %d\n", VarMRU); + prompt_Printf(&prompt, " Initial MRU: %d\n", VarMRU); return 0; } static int ShowPreferredMTU(struct cmdargs const *arg) { - if (VarTerm) - if (VarPrefMTU) - fprintf(VarTerm, " Preferred MTU: %d\n", VarPrefMTU); - else - fprintf(VarTerm, " Preferred MTU: unspecified\n"); + if (VarPrefMTU) + prompt_Printf(&prompt, " Preferred MTU: %d\n", VarPrefMTU); + else + prompt_Printf(&prompt, " Preferred MTU: unspecified\n"); return 0; } static int ShowReconnect(struct cmdargs const *arg) { - if (VarTerm) - fprintf(VarTerm, " Reconnect Timer: %d, %d tries\n", - VarReconnectTimer, VarReconnectTries); + prompt_Printf(&prompt, " Reconnect Timer: %d, %d tries\n", + VarReconnectTimer, VarReconnectTries); return 0; } static int ShowRedial(struct cmdargs const *arg) { - if (!VarTerm) - return 0; - fprintf(VarTerm, " Redial Timer: "); + prompt_Printf(&prompt, " Redial Timer: "); - if (VarRedialTimeout >= 0) { - fprintf(VarTerm, " %d seconds, ", VarRedialTimeout); - } else { - fprintf(VarTerm, " Random 0 - %d seconds, ", REDIAL_PERIOD); - } + if (VarRedialTimeout >= 0) + prompt_Printf(&prompt, " %d seconds, ", VarRedialTimeout); + else + prompt_Printf(&prompt, " Random 0 - %d seconds, ", REDIAL_PERIOD); - fprintf(VarTerm, " Redial Next Timer: "); + prompt_Printf(&prompt, " Redial Next Timer: "); - if (VarRedialNextTimeout >= 0) { - fprintf(VarTerm, " %d seconds, ", VarRedialNextTimeout); - } else { - fprintf(VarTerm, " Random 0 - %d seconds, ", REDIAL_PERIOD); - } + if (VarRedialNextTimeout >= 0) + prompt_Printf(&prompt, " %d seconds, ", VarRedialNextTimeout); + else + prompt_Printf(&prompt, " Random 0 - %d seconds, ", REDIAL_PERIOD); if (VarDialTries) - fprintf(VarTerm, "%d dial tries", VarDialTries); + prompt_Printf(&prompt, "%d dial tries", VarDialTries); - fprintf(VarTerm, "\n"); + prompt_Printf(&prompt, "\n"); return 0; } @@ -586,17 +564,16 @@ ShowRedial(struct cmdargs const *arg) static int ShowMSExt(struct cmdargs const *arg) { - if (VarTerm) { - fprintf(VarTerm, " MS PPP extention values \n"); - fprintf(VarTerm, " Primary NS : %s\n", - inet_ntoa(IpcpInfo.ns_entries[0])); - fprintf(VarTerm, " Secondary NS : %s\n", - inet_ntoa(IpcpInfo.ns_entries[1])); - fprintf(VarTerm, " Primary NBNS : %s\n", - inet_ntoa(IpcpInfo.nbns_entries[0])); - fprintf(VarTerm, " Secondary NBNS : %s\n", - inet_ntoa(IpcpInfo.nbns_entries[1])); - } + prompt_Printf(&prompt, " MS PPP extention values \n"); + prompt_Printf(&prompt, " Primary NS : %s\n", + inet_ntoa(IpcpInfo.ns_entries[0])); + prompt_Printf(&prompt, " Secondary NS : %s\n", + inet_ntoa(IpcpInfo.ns_entries[1])); + prompt_Printf(&prompt, " Primary NBNS : %s\n", + inet_ntoa(IpcpInfo.nbns_entries[0])); + prompt_Printf(&prompt, " Secondary NBNS : %s\n", + inet_ntoa(IpcpInfo.nbns_entries[1])); + return 0; } @@ -722,37 +699,6 @@ FindExec(struct bundle *bundle, struct cmdtab const *cmds, int argc, return val; } -int aft_cmd = 1; - -void -Prompt(struct bundle *bundle) -{ - const char *pconnect, *pauth; - - if (!VarTerm || TermMode || CleaningUp) - return; - - if (!aft_cmd) - fprintf(VarTerm, "\n"); - else - aft_cmd = 0; - - if (VarLocalAuth == LOCAL_AUTH) - pauth = " ON "; - else - pauth = " on "; - if (IpcpInfo.fsm.state == ST_OPENED) - pconnect = "PPP"; - else if (bundle_Phase(bundle) == PHASE_NETWORK) - pconnect = "PPp"; - else if (bundle_Phase(bundle) == PHASE_AUTHENTICATE) - pconnect = "Ppp"; - else - pconnect = "ppp"; - fprintf(VarTerm, "%s%s%s> ", pconnect, pauth, VarShortHost); - fflush(VarTerm); -} - void InterpretCommand(char *buff, int nb, int *argc, char ***argv) { @@ -831,10 +777,12 @@ DecodeCommand(struct bundle *bundle, char *buff, int nb, const char *label) static int ShowCommand(struct cmdargs const *arg) { - if (arg->argc > 0) + if (!prompt_Active(&prompt)) + LogPrintf(LogWARN, "show: Cannot show without a prompt\n"); + else if (arg->argc > 0) FindExec(arg->bundle, ShowCommands, arg->argc, arg->argv, "show "); - else if (VarTerm) - fprintf(VarTerm, "Use ``show ?'' to get a list.\n"); + else if (prompt_Active(&prompt)) + prompt_Printf(&prompt, "Use ``show ?'' to get a list.\n"); else LogPrintf(LogWARN, "show command must have arguments\n"); @@ -845,30 +793,27 @@ static int TerminalCommand(struct cmdargs const *arg) { if (LcpInfo.fsm.state > ST_CLOSED) { - if (VarTerm) - fprintf(VarTerm, "LCP state is [%s]\n", StateNames[LcpInfo.fsm.state]); + prompt_Printf(&prompt, "LCP state is [%s]\n", + StateNames[LcpInfo.fsm.state]); return 1; } if (!IsInteractive(1)) return (1); if (modem_Open(arg->bundle->physical, arg->bundle) < 0) { - if (VarTerm) - fprintf(VarTerm, "Failed to open modem.\n"); + prompt_Printf(&prompt, "Failed to open modem.\n"); return (1); } - if (VarTerm) { - fprintf(VarTerm, "Entering terminal mode.\n"); - fprintf(VarTerm, "Type `~?' for help.\n"); - } - TtyTermMode(); - return (0); + prompt_Printf(&prompt, "Entering terminal mode.\n"); + prompt_Printf(&prompt, "Type `~?' for help.\n"); + prompt_TtyTermMode(&prompt); + return 0; } static int QuitCommand(struct cmdargs const *arg) { - if (VarTerm) { - DropClient(1); + if (prompt_Active(&prompt)) { + prompt_Drop(&prompt, 1); if ((mode & MODE_INTER) || (arg->argc > 0 && !strcasecmp(*arg->argv, "all") && (VarLocalAuth & LOCAL_AUTH))) @@ -1526,8 +1471,8 @@ SetCommand(struct cmdargs const *arg) { if (arg->argc > 0) FindExec(arg->bundle, SetCommands, arg->argc, arg->argv, "set "); - else if (VarTerm) - fprintf(VarTerm, "Use `set ?' to get a list or `set ? ' for" + else if (prompt_Active(&prompt)) + prompt_Printf(&prompt, "Use `set ?' to get a list or `set ? ' for" " syntax help.\n"); else LogPrintf(LogWARN, "set command must have arguments\n"); @@ -1634,8 +1579,8 @@ AliasCommand(struct cmdargs const *arg) { if (arg->argc > 0) FindExec(arg->bundle, AliasCommands, arg->argc, arg->argv, "alias "); - else if (VarTerm) - fprintf(VarTerm, "Use `alias help' to get a list or `alias help" + else if (prompt_Active(&prompt)) + prompt_Printf(&prompt, "Use `alias help' to get a list or `alias help" "