📄 ecudce.c
字号:
eCONINT on interrupt sets #I0 to 0==connect, 1==failed to connect, 2==interrupted 3==modem error sets #S0 to modem result code or uucp status code string This function has gotten quite NASTY and needs rewriting!------------------------------------------------------------------------*/intDCE_dial(){ char s128[128]; int itmp; int erc = -1; /* assume error unless chg'd */ int s7; char *result = ""; int restart_rcvr = need_rcvr_restart(); ulong colors_at_entry = colors_current; char s64[64]; char *_doproc_args[3]; FILE *fp; char *cptr; char credit_file[128]; extern char kbdintr; /* current input INTR */ kill_rcvr_process(SIGUSR1); lclear_xmtr_xoff(); if(shm->Ldescr[0]) { setcolor(colors_success); get_tod(1,s64); pprintf("%s %s\n", (shm->Ltelno[0]) ? "Dialing" : "Connecting to",shm->Ldescr); pprintf("on %s at %u baud (%s)\n",shm->Lline,shm->Lbaud,s64); } DCE_hangup(); last_dial_result[0] = 0; setcolor(colors_alert); if(!shm->Ltelno[0]) /* if no phone number, direct connect */ { sprintf(s64,"CONNECT %u",shm->Lbaud); result = s64; iv[0] = 0; erc = 0; shm->Lconnected = 1; Ldial_debug_level = 0; goto CONNECTED; } else { itmp = hdb_dial(&result); lreset_ksr(); /* dialer may have changed termio */ switch(itmp) { case 0: /* success */ goto CONNECTED; case 1: /* failure -- iv[0] set by hdb_dial */ DCE_report_iv_set(0); erc = eConnectFailed; goto START_RCVR_PROCESS; case 2: /* interrupted -- iv[0] set by hdb_dial */ DCE_report_iv_set(0); erc = eCONINT; goto START_RCVR_PROCESS; case 3: /* modem error */ setcolor(colors_error); pprintf("%s\n",result); goto CANNOT_TALK_TO_MODEM; case 4: /* try local */ pputs("\ntrying ecu dialer\n"); break; } /* * brain-damaged "built-in dialer" */ DCE_modem_init();#if defined(USE_S7) if((s7 = DCE_get_sreg_value(7)) < 0) s7 = 30;#else s7 = 30;#endif /* * build dial command */ strcpy(s128,Lmodem_dial); strcat(s128,shm->Ltelno); /* * if trailing '$', read and append ~/.ecu/.credit */ if(*(cptr = s128 + strlen(s128) - 1) == '$') { *cptr = 0; get_home_dir(credit_file); strcat(credit_file,"/.ecu/.credit"); if(fp = fopen(credit_file,"r")) { fgets(cptr,30,fp); fclose(fp); } if(!fp || !(*cptr)) { result = "!CREDIT CARD ERROR"; goto CONNECT_FAILED; } if(*(cptr + strlen(cptr) - 1) == 0x0A) *(cptr + strlen(cptr) - 1) = 0; /* kill NL */ } if(sigint || check_queued_sigint()) goto SEND_CMD_ERROR; if(DCE_send_cmd(s128)) goto SEND_CMD_ERROR; /* some modems (ahem, the Hayes 2400) do not accurately honor S7 so our timer is twice sreg 7 */ pprintf("Type %s to abort ... ",make_char_graphic(kbdintr,1)); setcolor(colors_normal); lflush(0); strcpy(s64,DCE_get_result(s7 * 2 * 1000L)); result = s64; if(sigint || !strcmp(result,interrupted_string)) { setcolor(colors_error); pprintf("%s\n",result); sigint = 0; lputc(0); /* send char in case DTR ignored */ lflash_dtr(); /* force on hook */ (void)DCE_get_result(2000L); /* wait for any result code */ erc = eCONINT; iv[0] = 2; DCE_report_iv_set(0); goto START_RCVR_PROCESS; } if(!strncmp(result,"CONNECT",7)) { if(strlen(result) > (unsigned)7) { if(shm->Lbaud != (unsigned)atoi(result + 7)) { setcolor(colors_error); pprintf("%s (incorrect rate)\n",result); iv[0] = 2; DCE_report_iv_set(0); goto START_RCVR_PROCESS; } }CONNECTED:#if defined(WHT2) && defined(XTERM_FRIEND) /* * if xterm, put connection in title bar * but this really should be done in _connect.ep */ sprintf(s128,"connected to %s",shm->Llogical); xterm_title(s128,1);#endif setcolor(colors_success); pprintf("%s\n",result); sprintf(s128,"CONNECT %s (%s) %u baud", shm->Llogical,shm->Ltelno,shm->Lbaud); strcpy(shm->Lrname,shm->Llogical); ecu_log_event(getpid(),s128); if(isalpha(shm->Llogical[0])) { if(!keyset_read(shm->Llogical)) pprintf("[autoloaded fkeys for %s]\n",shm->Llogical); } shmx_connect(); shm->xmit_chars_this_connect = 0L; shm->Loff_hook_time = time((long *)0); iv[0] = 0; DCE_report_iv_set(0); erc = 0; shm->Lconnected = 1; lCLOCAL(!shm->Ldcdwatch); /* set CLOCAL per DCD watcher */ goto START_RCVR_PROCESS; }CONNECT_FAILED: ; setcolor(colors_error); pprintf("%s\n",result); iv[0] = 1; DCE_report_iv_set(0); erc = eConnectFailed; goto START_RCVR_PROCESS; }SEND_CMD_ERROR: ; if(sigint) { sigint = 0; result = interrupted_string; iv[0] = 2; DCE_report_iv_set(0); erc = eCONINT; } else {CANNOT_TALK_TO_MODEM: ; setcolor(colors_error); pprintf("Cannot talk to modem\n"); result = "!Modem Error"; iv[0] = 3; DCE_report_iv_set(0); erc = eConnectFailed; }START_RCVR_PROCESS: ; setcolor(colors_at_entry); strcpy(sv[0]->pb,result); sv[0]->cb = strlen(result); strcpy(last_dial_result,result); /* * do the _connect.ep or _connfail.ep execution */ if(!iv[0]) { if(find_procedure("_connect")) { int erc2; _doproc_args[0] = "_connect"; /* _connect.ep */ _doproc_args[1] = result; /* "CONNECT XXXX" */ if(erc2 = do_proc(2,_doproc_args)) { DCE_hangup(); if(erc2 < 256) { sprintf(s64,"!CONNECT PROCEDURE RETURNED %d",erc2); result = s64; } else result = "!CONNECT PROCEDURE ABNORMAL TERMINATION"; strcpy(sv[0]->pb,result); sv[0]->cb = strlen(result); setcolor(colors_error); pprintf("%s\n",result); iv[0] = 1; DCE_report_iv_set(0); erc = eConnectFailed; } } } else if(find_procedure("_connfail")) { _doproc_args[0] = "_connfail"; /* _connfail.ep */ _doproc_args[1] = shm->Llogical; _doproc_args[2] = result; (void)do_proc(3,_doproc_args); } if(restart_rcvr) start_rcvr_process(1); return(erc);} /* end of DCE_dial *//*+------------------------------------------------------------------------- DCE_redial(arg,argc)--------------------------------------------------------------------------*/DCE_redial(arg,argc)char **arg;int argc;{ int erc = 0; int delay = 60; int retries = 10; long nap_msec; int ans; if(shm->Ltelno[0] == 0) { pprintf(" no previous number\n"); return(-1); } if((argc > 1) && ((retries = atoi(arg[1])) == 0)) { pprintf(" invalid retry count\n"); return(-1); } if((argc > 2) && ((delay = atoi(arg[2])) == 0)) { pprintf(" invalid delay\n"); return(-1); } if(delay < 0) /* try to be nice to telcos */ delay = 0; /* (they are our friends :-) */ pprintf(" for %d retries, pause between: %d secs\n", retries,delay); kill_rcvr_process(SIGUSR1); /* kill rcvr process */ DCE_hangup(); while(retries--) { if(!isdigit(shm->Llogical[0]) && find_procedure(shm->Llogical)) { char *pargv[2]; ulong colors_at_entry = colors_current; pargv[0] = shm->Llogical; pargv[1] = "!REDIAL;"; sigint = 0; ttymode(2); erc = do_proc(2,pargv); proc_file_reset(); ttymode(1); setcolor(colors_notify); ff(se,"[procedure finished]"); setcolor(colors_at_entry); ff(se,"\r\n"); if(!erc) { start_rcvr_process(0); return(0); } lflash_dtr(); sigint = 0; } else if(!(erc = DCE_dial())) { start_rcvr_process(1); return(0); } if(sigint || !strcmp(last_dial_result,interrupted_string)) goto ABORT_CYCLE; if((retries == 0) || (erc >= e_FATAL)) break; pprintf("%d %s left ... ",retries,(retries == 1) ? "retry" : "retries"); nap_msec = delay * 1000L; ff(se,"waiting %d seconds ... 'c' to cycle, %s to abort\r\n", delay,(kbdintr == DEL) ?"DEL":make_char_graphic(kbdintr,0)); while(nap_msec > 0) { nap_msec -= Nap(100L); while(ttyrdchk()) { ans = to_lower(ttygetc(1)); if(ans == 'c') goto CONTINUE_CYCLE; else if(ans == kbdintr) goto ABORT_CYCLE; else ring_bell(); } if(sigint) goto ABORT_CYCLE; }CONTINUE_CYCLE: DCE_hangup(); }ERROR_RETURN: DCE_hangup(); start_rcvr_process(1); return(-1);ABORT_CYCLE: DCE_hangup(); ff(se,"redial ABORTED\r\n"); sigint = 0; goto ERROR_RETURN;} /* end of DCE_redial *//*+------------------------------------------------------------------------- DCE_now_on_hook() - DCE no longer in connectionThis may be called, however, when no connection is active--------------------------------------------------------------------------*/voidDCE_now_on_hook(){ char s128[128]; long connect_secs; lCLOCAL(1); /* turn on CLOCAL */ if(shm->Lconnected) { connect_secs = time((long *)0) - shm->Loff_hook_time; sprintf(s128,"DISCONNECT %s (%s) %ld %s", shm->Llogical,shm->Ltelno,connect_secs, get_elapsed_time(connect_secs)); ecu_log_event(getpid(),s128);#if defined(WHT2) || defined(XTERM_FRIEND) /* * if xterm, put disconnected status in title bar * but this really should be done in _hangup.ep */ xterm_title("disconnected",1);#endif /* * do the _hangup.ep execution */ if(find_procedure("_hangup")) { char *_hangup_args[2]; sprintf(s128,"%ld",connect_secs); _hangup_args[0] = "_hangup"; _hangup_args[1] = s128; (void)do_proc(2,_hangup_args); } shm->Lconnected = 0; } shm->Lrname[0] = 0; set_default_escape_prompt();} /* end of DCE_now_on_hook *//*+------------------------------------------------------------------------- DCE_hangup() - terminate any active connection--------------------------------------------------------------------------*/voidDCE_hangup(){ int restart_rcvr = need_rcvr_restart(); if(restart_rcvr) kill_rcvr_process(SIGUSR1); lflash_dtr(); DCE_now_on_hook(); if(restart_rcvr) start_rcvr_process(0);} /* end of DCE_hangup *//*+------------------------------------------------------------------------- DCE_get_sreg_value(regnum) assumes rcvr process has been killed--------------------------------------------------------------------------*/intDCE_get_sreg_value(regnum)int regnum;{ char s128[128]; LRWT lr; sprintf(s128,"ATS%d?",regnum); DCE_send_cmd(s128); lflush(0); lr.to1 = 2000L; lr.to2 = 140L; lr.raw_flag = 0; lr.buffer = s128; lr.bufsize = sizeof(s128); lr.delim = (char *)0; lr.echo_flag = 0; lgets_timeout(&lr); if(lr.count != 3) return(-1); return(atoi(s128));} /* end of DCE_get_sreg_value *//*+------------------------------------------------------------------------- DCE_set_sreg(regnum,value) assumes rcvr process has been killed returns 0 if no error (reads back value set), else -1 and error message has been printed--------------------------------------------------------------------------*/intDCE_set_sreg(regnum,value)int regnum;int value;{ char s128[128]; int value2; LRWT lr; sprintf(s128,"ATS%d=%d",regnum,value); DCE_send_cmd(s128); lflush(0); lr.to1 = 2000L; lr.to2 = 140L; lr.raw_flag = 0; lr.buffer = s128; lr.bufsize = sizeof(s128); lr.delim = (char *)0; lr.echo_flag = 0; lgets_timeout(&lr); value2 = DCE_get_sreg_value(regnum); if(value2 < 0) pprintf("PROBLEM setting modem S%d=%d; cannot talk to modem\n", regnum,value); else if(value != value2) pprintf("PROBLEM setting modem S%d=%d; got %d back\n", regnum,value,value2); return((value != value2) ? -1 : 0);} /* end of DCE_set_sreg *//*+------------------------------------------------------------------------- DCE_autoanswer()--------------------------------------------------------------------------*/voidDCE_autoanswer(){ if(!Lmodem_autoans[0]) return; (void)Nap(200L); lputs_paced(20,"AT\r"); (void)Nap(100L); lputs_paced(20,Lmodem_autoans); /* quiet modem */ lputs_paced(20,"\r"); (void)Nap(200L); lputs_paced(20,Lmodem_autoans); /* quiet modem */ lputs_paced(20,"\r"); (void)Nap(200L); lflush(0);} /* end of DCE_autoanswer *//* end of ecuDCE.c *//* vi: set tabstop=4 shiftwidth=4: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -