📄 dial.c
字号:
/* * dial.c Functions to dial, retry etc. Als contains the dialing * directory code, _and_ the famous tu-di-di music. * * This file is part of the minicom communications package, * Copyright 1991-1995 Miquel van Smoorenburg. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * jl 22.06.97 Logging connects and disconnects. * jl 23.06.97 Adjustable DTR droptime * jl 21.09.97 Conversion table filenames in dialdir * jl 05.10.97 Line speed changed to long in dial() * jl 26.01.98 last login date & time added to dialing window * jl 16.04.98 start searching for dialing tags from the highlighted entry * jl 12.06.98 save the old dialdir if it was an old version * er 18-Apr-99 When calling a multiline BBS * tagged entries with same name are untagged * jl 01.09.99 Move entry up/down in directory * jl 10.02.2000 Stopbits field added */#ifdef HAVE_CONFIG_H#include <config.h>#endif#include <stdint.h>#include <arpa/inet.h>#include "rcsid.h"RCSID("$Id: dial.c,v 1.26 2007-10-10 20:18:20 al-guest Exp $")#include "port.h"#include "minicom.h"#include "intl.h"#ifdef VC_MUSIC# if defined(__GLIBC__)# include <sys/ioctl.h># include <sys/kd.h># include <sys/time.h># endif# if defined(_COH42) || defined(_SCO)# include <sys/vtkd.h># endif#endif/* Dialing directory. */struct v1_dialent { char name[32]; char number[16]; char script[16]; char username[32]; char password[32]; char term; char baud[8]; char parity[2]; char dialtype; char flags; /* Localecho in v0 */ char bits[2]; struct dialent *next;};struct v3_dialent { char name[32]; char number[32]; char script[32]; char username[32]; char password[32]; char term; char baud[8]; char parity[2]; char dialtype; char flags; char bits[2]; struct dialent *next;};struct v4_dialent { char name[32]; char number[32]; char script[32]; char username[32]; char password[32]; char term; char baud[8]; char parity[2]; char dialtype; char flags; char bits[2]; char lastdate[9]; /* jl 22.06.97 */ char lasttime[9]; /* jl 22.06.97 */ int count; /* jl 22.06.97 */ char convfile[16]; /* jl 21.09.97 */ char stopb[2]; /* jl 10.02.2000 */ struct dialent *next;};/* v5 is a packed version of v4 so that there's no difference between 32 and * 64 bit versions as well as LE and BE. */struct dialent { char name[32]; char number[32]; char script[32]; char username[32]; char password[32]; char term; char baud[8]; char parity[2]; char dialtype; char flags; char bits[2]; char lastdate[9]; char lasttime[9]; uint32_t count; char convfile[16]; char stopb[2]; struct dialent *next;} __attribute__((packed));/* Version info. */#define DIALMAGIC 0x55AAstruct dver { short magic; short version; unsigned short size; short res1; short res2; short res3; short res4;} __attribute__((packed));/* Forward declaration */static void writedialdir(void);#define dialentno(di, no) ((struct dialent *)((char *)(di) + ((no) * sizeof(struct dialent)))) static struct dialent *dialents;static struct dialent *d_man;static int nrents = 1;static int newtype;/* Access to ".dialdir" denied? */static int dendd = 0;static char *tagged;char *dial_user;char *dial_pass;/* Change the baud rate. Treat all characters in the given array as if * they were key presses within the comm parameters dialog (C-A P) and * change the line speed accordingly. Terminate when a space or other * unrecognised character is found. */const char* change_baud(const char *s){ while (s && *s && update_bbp_from_char(*s, P_BAUDRATE, P_BITS, P_PARITY, P_STOPB, 0)) ++s; // reinitialise the port and update the status line if (portfd >= 0) port_init(); if (st) mode_status(); return s;}/* * Functions to talk to the modem. *//* * Send a string to the modem. * If how == 0, '~' sleeps 1 second. * If how == 1, "^~" sleeps 1 second. */void mputs(const char *s, int how){ char c; while(*s) { if (*s == '^' && (*(s + 1))) { s++; if (*s == '^') c = *s; else if (how == 1 && *s == '~') { sleep(1); s++; continue; } else c = (*s) & 31; } else if (*s == '\\' && (*(s + 1))) { s++; switch (toupper (*s)) { case '\\': c = *s; break; case 'U': if (dial_user && *dial_user) mputs (dial_user, how); s++; continue; case 'P': if (dial_pass && *dial_pass) mputs (dial_pass, how); s++; continue; case 'B': /* line speed change. */ s = change_baud(++s); continue; case 'L': /* toggle linefeed addition */ toggle_addlf(); s++; /* nothing to do with the modem, move along */ continue; case 'E': /* toggle local echo */ toggle_local_echo(); s++; /* again, move along. */ continue; default: s++; continue; } } else c = *s; if (how == 0 && c == '~') sleep(1); else write(portfd, &c, 1); s++; }}/* * Initialize the modem. */void modeminit(void){ WIN *w; if (P_MINIT[0] == '\0') return; w = mc_tell(_("Initializing Modem")); m_dtrtoggle(portfd, 1); /* jl 23.06.97 */ mputs(P_MINIT, 0); mc_wclose(w, 1);}/* * Reset the modem. */void modemreset(void){ WIN *w; if (P_MRESET[0] == '\0') return; w = mc_tell(_("Resetting Modem")); mputs(P_MRESET, 0); sleep(1); mc_wclose(w, 1);}/* * Hang the line up. */void hangup(void){ WIN *w; int sec=1; w = mc_tell(_("Hanging up")); timer_update(); if (P_LOGCONN[0] == 'Y') do_log(_("Hangup (%ld:%02ld:%02ld)"), online / 3600, (online / 60) % 60, online>0 ? online % 60 : 0); online = -1; old_online = -1; if (isdigit(P_MDROPDTR[0])) sscanf(P_MDROPDTR,"%2d",&sec); if (P_MDROPDTR[0] == 'Y' || (isdigit(P_MDROPDTR[0]) && sec>0)) { m_dtrtoggle(portfd, sec); /* jl 23.06.97 */ } else { mputs(P_MHANGUP, 0); sleep(1); }#ifdef _DCDFLOW /* DCD has dropped, turn off hw flow control. */ m_sethwf(portfd, 0);#endif /* If we don't have DCD support fake DCD dropped */ bogus_dcd = 0; mc_wclose(w, 1); if (st) time_status();}/* * This seemed to fit best in this file * Send a break signal. */void sendbreak(){ WIN *w; w = mc_tell(_("Sending BREAK")); mc_wcursor(w, CNONE); m_break(portfd); mc_wclose(w, 1);}WIN *dialwin;int dialtime;#ifdef VC_MUSIC/* * Play music until key is pressed. */void music(void){ int x, i, k; int consolefd = 0; char *disp; /* If we're in X, we have to explicitly use the console */ if (strncmp(getenv("TERM"), "xterm", 5) == 0 && (disp = getenv("DISPLAY")) != NULL && (strcmp(disp, ":0.0") == 0 || (strcmp(disp, ":0") == 0))) { consolefd = open("/dev/console", O_WRONLY); if (consolefd < 0) consolefd = 0; } /* Tell keyboard handler what we want. */ keyboard(KSIGIO, 0); /* And loop forever :-) */ for(i = 0; i < 9; i++) { k = 2000 - 200 * (i % 3); ioctl(consolefd, KIOCSOUND, k); /* Check keypress with timeout 160 ms */ x = check_io(-1, 0, 160, NULL, NULL); if (x & 2) break; } ioctl(consolefd, KIOCSOUND, 0); if (consolefd) close(consolefd); /* Wait for keypress and absorb it */ while ((x & 2) == 0) { x = check_io(-1, 0, 10000, NULL, NULL); timer_update(); } keyboard(KGETKEY, 0);}#endif/* * The dial has failed. Tell user. * Count down until retrytime and return. */static int dialfailed(char *s, int rtime){ int f, x; int ret = 0; mc_wlocate(dialwin, 1, 5); mc_wprintf(dialwin, _(" No connection: %s. \n"), s); if (rtime < 0) { mc_wprintf(dialwin, _(" Press any key to continue.. ")); if (check_io(-1, 0, 10000, NULL, NULL) & 2) keyboard(KGETKEY, 0); return 0; } mc_wprintf(dialwin, _(" Retry in %2d seconds "), rtime); for (f = rtime - 1; f >= 0; f--) { x = check_io(-1, 0, 1000, NULL, NULL); if (x & 2) { /* Key pressed - absorb it. */ x = keyboard(KGETKEY, 0); if (x != ' ') ret = -1; break; } mc_wlocate(dialwin, 0, 6); mc_wprintf(dialwin, _(" Retry in %2d seconds "), f); }#ifdef HAVE_USLEEP /* MARK updated 02/17/94 - Min dial delay set to 0.35 sec instead of 1 sec */ if (f < 0) /* Allow modem time to hangup if redial time == 0 */ usleep(350000);#else if (f < 0) sleep(1);#endif mc_wlocate(dialwin, 1, 5); mc_wprintf(dialwin, " \n"); mc_wprintf(dialwin, " "); return ret;}/* * Dial a number, and display the name. */long dial(struct dialent *d, struct dialent **d2){ char *s = 0, *t = 0; int f, x = 0; int modidx, retries = 0; int maxretries = 1, rdelay = 45; long nb, retst = -1; char *reason = _("Max retries"); time_t now, last; struct tm *ptime; char buf[128]; char modbuf[128]; /* char logline[128]; */ timer_update(); /* Statusline may still show 'Online' / jl 16.08.97 */ /* don't do anything if already online! jl 07.07.98 */ if (P_HASDCD[0]=='Y' && online >= 0) { werror(_("You are already online! Hang up first.")); return(retst); } dialwin = mc_wopen(18, 9, 62, 16, BSINGLE, stdattr, mfcolor, mbcolor, 0, 0, 1); mc_wtitle(dialwin, TMID, _("Autodial")); mc_wcursor(dialwin, CNONE); mc_wputs(dialwin, "\n"); mc_wprintf(dialwin, " %s : %s\n", _("Dialing"), d->name); mc_wprintf(dialwin, _(" At : %s"), d->number); mc_wprintf(dialwin, "\n"); /* help translators */ if (d->lastdate[0] && d->lasttime[0]) /* jl 26.01.98 */ mc_wprintf(dialwin, _(" Last on : %s at %s"), d->lastdate, d->lasttime); mc_wprintf(dialwin, "\n"); mc_wredraw(dialwin, 1); /* Tell keyboard routines we need them. */ keyboard(KSIGIO, 0); maxretries = atoi(P_MRETRIES); if (maxretries <= 0) maxretries = 1; rdelay = atoi(P_MRDELAY);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -