📄 dial.c
字号:
if (rdelay < 0) rdelay = 0; /* Main retry loop of dial() */MainLoop: while (++retries <= maxretries) { /* See if we need to try the next tagged entry. */ if (retries > 1 && (d->flags & FL_TAG)) { do { d = d->next; if (d == (struct dialent *)NULL) d = dialents; } while (!(d->flags & FL_TAG)); mc_wlocate(dialwin, 0, 1); mc_wprintf(dialwin, " %s : %s", _("Dialing"), d->name); mc_wclreol(dialwin); mc_wprintf(dialwin, "\n"); /* helps translators */ mc_wprintf(dialwin, _(" At : %s"), d->number); mc_wclreol(dialwin); if (d->lastdate[0] && d->lasttime[0]) { mc_wprintf(dialwin, "\n"); /* don't merge with next printf, helps translators */ mc_wprintf(dialwin, _(" Last on : %s at %s"), d->lastdate, d->lasttime); mc_wclreol(dialwin); } } /* Calculate dial time */ dialtime = atoi(P_MDIALTIME); if (dialtime == 0) dialtime = 45; time(&now); last = now; /* Show used time */ mc_wlocate(dialwin, 0, 4); mc_wprintf(dialwin, _(" Time : %-3d"), dialtime); if (maxretries > 1) mc_wprintf(dialwin, _(" Attempt #%d"), retries); mc_wputs(dialwin, _("\n\n\n Escape to cancel, space to retry.")); /* Start the dial */ m_flush(portfd); switch (d->dialtype) { case 0: mputs(P_MDIALPRE, 0); mputs(d->number, 0); mputs(P_MDIALSUF, 0); break; case 1: mputs(P_MDIALPRE2, 0); mputs(d->number, 0); mputs(P_MDIALSUF2, 0); break; case 2: mputs(P_MDIALPRE3, 0); mputs(d->number, 0); mputs(P_MDIALSUF3, 0); break; } /* Wait 'till the modem says something */ modbuf[0] = 0; modidx = 0; s = buf; buf[0] = 0; while (dialtime > 0) { if (*s == 0) { x = check_io(portfd_connected, 0, 1000, buf, NULL); s = buf; } if (x & 2) { f = keyboard(KGETKEY, 0); /* Cancel if escape was pressed. */ if (f == K_ESC) mputs(P_MDIALCAN, 0); /* On space retry. */ if (f == ' ') { mputs(P_MDIALCAN, 0); dialfailed(_("Cancelled"), 4); m_flush(portfd); break; } keyboard(KSTOP, 0); mc_wclose(dialwin, 1); return retst; } if (x & 1) { /* Data available from the modem. Put in buffer. */ if (*s == '\r' || *s == '\n') { /* We look for [\r\n]STRING[\r\n] */ modbuf[modidx] = 0; modidx = 0; } else if (modidx < 127) { /* Normal character. Add. */ modbuf[modidx++] = *s; modbuf[modidx] = 0; } /* Skip to next received char */ if (*s) s++; /* Only look when we got a whole line. */ if (modidx == 0 && !strncmp(modbuf, P_MCONNECT, strlen(P_MCONNECT))) { timer_update(); /* the login scipt may take long.. */ retst = 0; /* Try to do auto-bauding */ if (sscanf(modbuf + strlen(P_MCONNECT), "%ld", &nb) == 1) retst = nb; linespd = retst; /* Try to figure out if this system supports DCD */ f = m_getdcd(portfd); bogus_dcd = 1; /* jl 22.05.97, 22.09.97, 05.04.99 */ if (P_LOGCONN[0] == 'Y') do_log("%s %s, %s",modbuf, d->name, d->number); ptime = localtime(&now); sprintf(d->lastdate,"%4.4d%2.2d%2.2d", (ptime->tm_year)+1900,(ptime->tm_mon)+1, ptime->tm_mday); sprintf(d->lasttime,"%02d:%02d", ptime->tm_hour,ptime->tm_min); d->count++; if (d->convfile[0]) { loadconv(d->convfile); /* jl 21.09.97 */ strcpy(P_CONVF, d->convfile); } mc_wlocate(dialwin, 1, 7); if (d->script[0] == 0) { mc_wputs(dialwin, _("Connected. Press any key to continue"));#ifdef VC_MUSIC if (P_SOUND[0] == 'Y') music(); else { x = check_io(-1, 0, 0, NULL, NULL); if ((x & 2) == 2) keyboard(KGETKEY, 0); }#else /* MARK updated 02/17/94 - If VC_MUSIC is not */ /* defined, then at least make some beeps! */ if (P_SOUND[0] == 'Y') mc_wputs(dialwin,"\007\007\007");#endif x = check_io(-1, 0, 0, NULL, NULL); if ((x & 2) == 2) keyboard(KGETKEY, 0); } keyboard(KSTOP, 0); mc_wclose(dialwin, 1); /* Print out the connect strings. */ mc_wprintf(us, "\r\n%s\r\n", modbuf); dialwin = NULL; /* Un-tag this entry. */ d->flags &= ~FL_TAG; /* store pointer to the entry that ANSWERED */ if (d2 != (struct dialent**)NULL) *d2 = d; /* jl 23.09.97 */ /* Here should placed code to untag phones with similar names */ if (P_MULTILINE[0] == 'Y') { struct dialent *d3 = dialents; while (d3 != (struct dialent*)NULL) { if (!strcmp(d3->name, d->name)) d3->flags &= ~FL_TAG; d3 = d3->next; } } /* er 27-Apr-99 */ return retst; } for (f = 0; f < 3; f++) { if (f == 0) t = P_MNOCON1; if (f == 1) t = P_MNOCON2; if (f == 2) t = P_MNOCON3; if (f == 3) t = P_MNOCON4; if ((*t) && (!strncmp(modbuf, t, strlen(t)))) { if (retries < maxretries) { x = dialfailed(t, rdelay); if (x < 0) { keyboard(KSTOP, 0); mc_wclose(dialwin, 1); return retst; } } if (maxretries == 1) reason = t; goto MainLoop; } } } /* Do timer routines here. */ time(&now); if (last != now) { dialtime -= (now - last); if (dialtime < 0) dialtime = 0; mc_wlocate(dialwin, 11, 4); mc_wprintf(dialwin, "%-3d ", dialtime); if (dialtime <= 0) { mputs(P_MDIALCAN, 0); reason = _("Timeout"); retst = -1; if (retries < maxretries) { x = dialfailed(reason, rdelay); if (x < 0) { keyboard(KSTOP, 0); mc_wclose(dialwin, 1); return retst; } } } } last = now; } } /* End of main while cq MainLoop */ dialfailed(reason, -1); keyboard(KSTOP, 0); mc_wclose(dialwin, 1); return retst;}/* * Create an empty entry. */static struct dialent *mkstdent(void){ struct dialent *d = malloc(sizeof(struct dialent)); if (d == NULL) return d; d->name[0] = 0; d->number[0] = 0; d->script[0] = 0; d->username[0] = 0; d->password[0] = 0; d->term = 1; d->dialtype = 0; d->flags = FL_DEL; strcpy(d->baud, "Curr"); strcpy(d->bits, "8"); strcpy(d->parity, "N"); d->lastdate[0] = 0; /* jl 22.06.97 */ d->lasttime[0] = 0; d->count = 0; d->convfile[0] = 0; /* jl 21.09.97 */ strcpy(d->stopb, "1"); d->next = NULL; return d;}static void convert_to_save_order(struct dialent *dst, const struct dialent *src){ memcpy(dst, src, sizeof(*dst)); dst->count = htonl(dst->count);}static void convert_to_host_order(struct dialent *dst, const struct dialent *src){ memcpy(dst, src, sizeof(*dst)); dst->count = ntohl(dst->count);}/* Read version 5 of the dialing directory. */void v5_read(FILE *fp, struct dialent *d){ struct dialent dent_n; fread(&dent_n, sizeof(dent_n), 1, fp); convert_to_host_order(d, &dent_n);}/* Read version 4 of the dialing directory. */void v4_read(FILE *fp, struct dialent *d, struct dver *dv){ struct v4_dialent v4; fread(&v4, dv->size, 1, fp); if (dv->size < sizeof(struct dialent)) { if (dv->size < offsetof(struct dialent, count) + sizeof(struct dialent *)) { d->count = 0; d->lasttime[0] = 0; d->lastdate[0] = 0; } if (dv->size < offsetof(struct dialent, stopb) + sizeof(struct dialent *)) d->convfile[0] = 0; strcpy(d->stopb, "1"); }}/* Read version 3 of the dialing directory. */void v3_read(FILE *fp, struct dialent *d){ struct v3_dialent v3; /* jl 22.06.97 */ fread(&v3, sizeof(v3), 1, fp); memcpy(d, &v3, offsetof(struct v3_dialent, next)); d->lastdate[0] = 0; d->lasttime[0] = 0; d->count = 0; d->convfile[0] = 0; strcpy(d->stopb, "1");}/* Read version 2 of the dialing directory. */void v2_read(FILE *fp, struct dialent *d){ struct v3_dialent v3; /* jl 22.06.97 */ fread((char *)&v3, sizeof(v3), 1, fp); memcpy(d, &v3, offsetof(struct v3_dialent, next)); if (d->flags & FL_ANSI) d->flags |= FL_WRAP; d->lastdate[0] = 0; d->lasttime[0] = 0; d->count = 0; d->convfile[0] = 0; strcpy(d->stopb, "1");}/* Read version 1 of the dialing directory. */void v1_read(FILE *fp, struct dialent *d){ struct v1_dialent v1; fread((char *)&v1, sizeof(v1), (size_t)1, fp); memcpy(d->username, v1.username, sizeof(v1) - offsetof(struct v1_dialent, username)); strncpy(d->name, v1.name, sizeof(d->name)); strncpy(d->number, v1.number, sizeof(d->number)); strncpy(d->script, v1.script, sizeof(d->script)); d->lastdate[0]=0; d->lasttime[0]=0; d->count=0; d->convfile[0]=0; strcpy(d->stopb, "1");}/* Read version 0 of the dialing directory. */void v0_read(FILE *fp, struct dialent *d){ v1_read(fp, d); d->dialtype = 0; d->flags = 0;}/* * Read in the dialing directory from $HOME/.dialdir */int readdialdir(void){ long size; FILE *fp; char dfile[256]; char copycmd[512]; static int didread = 0; int f; struct dialent *d = NULL, *tail = NULL; struct dver dial_ver; WIN *w; if (didread) return 0; didread = 1; nrents = 1; tagged = malloc(1); if (!tagged) return 0; tagged[0] = 0; /* Make the manual dial entry. */ d_man = mkstdent(); strcpy(d_man->name, _("Manually entered number")); /* Construct path */ snprintf(dfile, sizeof(dfile), "%s/.dialdir", homedir); /* Try to open ~/.dialdir */ if ((fp = sfopen(dfile, "r")) == NULL) { if (errno == EPERM) { werror(_("Cannot open ~/.dialdir: permission denied")); dialents = mkstdent(); dendd = 1; return 0; } dialents = mkstdent(); return 0; } /* Get size of the file */ fseek(fp, 0L, SEEK_END); size = ftell(fp); if (size == 0) { dialents = mkstdent(); fclose(fp); return 0; } /* Get version of the dialing directory */ fseek(fp, 0L, SEEK_SET); fread(&dial_ver, sizeof(dial_ver), 1, fp); if (dial_ver.magic != DIALMAGIC) { /* First version without version info. */ dial_ver.version = 0; fseek(fp, 0L, SEEK_SET); } else { dial_ver.size = ntohs(dial_ver.size); size -= sizeof(dial_ver); } /* See if the size of the file is allright. */ switch (dial_ver.version) { case 0: case 1: dial_ver.size = sizeof(struct v1_dialent); break; case 2: case 3: dial_ver.size = sizeof(struct v3_dialent); break; case 4: /* dial_ver.size = sizeof(struct dialent); */ /* Removed the forced setting to add flexibility. * Now you don't need to change the version number * if you just add fields to the end of the dialent structure * before the *next pointer and don't change existing fields. * Just update the initialization in the functions * v4_read/v5_read and mkstdent (and whatever you added the field for) * jl 21.09.97 */ if (dial_ver.size < 200 || dial_ver.size > sizeof(struct v4_dialent)) { werror(_("Phonelist garbled (unknown version?)")); dialents = mkstdent(); return -1; } break; case 5: if (dial_ver.size != sizeof(struct dialent)) { werror(_("Phonelist corrupted")); return -1; } break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -