⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hdbintf.c

📁 一个通讯程序源码
💻 C
📖 第 1 页 / 共 3 页
字号:
		if(tdve)		{			switch(utmpst = utmp_status(shm->Lline))			{				case US_WEGOTIT:					goto RETURN;				case US_NOTFOUND:	/* not in utmp, or getty dead */#if 0					if(access(shm->Lline,6))						break;#endif					if((lerr = line_lock_status(shm->Lline)) &&						(lerr != LINST_WEGOTIT))					{						break;					}					goto RETURN;				case US_LOGIN:		/* enabled for login, idle */					goto RETURN;			}		}	}	/*	 * we've got to pick a new line	 */#ifdef CHOOSE_DEBUG	sprintf(s128,"must pick new line utmpst=%u lerr=%u",utmpst,lerr);	ecu_log_event(getpid(),s128);#endif	done = 0;	lerr = 0;	while(!done)	{		/*		 * get Devices entry matching type		 */		if(!(tdve = getdvtype(type)))		{#ifdef CHOOSE_DEBUG			sprintf(s128,"no line matches type '%s'",type);			ecu_log_event(getpid(),s128);#endif			break;		}		/*		 * does baud rate match?		 */		if((tdve->low_baud > baud) || (baud > tdve->high_baud))			continue;		sprintf(s32,"/dev/%s",tdve->line);		itmp = utmp_status(s32);#ifdef CHOOSE_DEBUG		sprintf(s128,"%s: utmp_status = %d  lock status=%d",s32,itmp,				line_lock_status(s32));		ecu_log_event(getpid(),s128);#endif		switch(itmp)		{			case US_NOTFOUND:	/* not in utmp, or getty dead */#if 0				if(access(s32,6))	/* ecuungetty won't be able to help us */					break;#endif				if(!(itmp = line_lock_status(s32)) || (itmp == LINST_WEGOTIT))					done = 1;				break;			case US_WEGOTIT:	/* we own the line */				/* this would be a curious case to succeed */				done = 1;				break;			case US_LOGIN:		/* enabled for login, idle */				done = 1;				break;			default:				break;		}	}RETURN:	enddvent();	return(tdve);}	/* end of hdb_choose_Device *//*+-------------------------------------------------------------------------	hdb_dial_error(errcode) - dialer program error code to textalso sets iv[0] to dial command status--------------------------------------------------------------------------*/char *hdb_dial_error_text(errcode)int errcode;{	static char errant[64];	iv[0] = 1;	switch(errcode &= 0x7F)	{		case RCE_INUSE:			return("!Line in use");		case RCE_SIG:			iv[0] = 2;			return("!Interrupted");		case RCE_ARGS:			return("!Invalid arguments");		case RCE_PHNO:			return("!Invalid phone number");		case RCE_SPEED:			return("!Bad baud rate");		case RCE_OPEN:			return("!Line open error");		case RCE_IOCTL:			return("!Ioctl error");		case RCE_TIMOUT:			iv[0] = 3;			return("!Modem Error");		case RCE_NOTONE:			return("NO DIAL TONE");		case RCE_BUSY:			return("BUSY");		case RCE_NOCARR:			return("NO CARRIER");		case RCE_ANSWER:			return("NO ANSWER");		default:		case RCE_NULL:			sprintf(errant,"unknown dialer error code %d",errcode);			return(errant);	}	/*NOTREACHED*/}	/* end of hdb_dial_error *//*+-------------------------------------------------------------------------	hdb_dial(presult) - dial with uucp dialer if we canreturn 0 if connected       1 if dial failed       2 if interrupted       3 if modem error       4 if use ecu DCE dialer--------------------------------------------------------------------------*/inthdb_dial(presult)char **presult;{	int itmp;	PID_T dial_pid;	int wait_status;	int old_ttymode = get_ttymode();	SIGTYPE (*original_sighdlr)();	DVE *tdve;	struct dlent *tdle = (struct dlent *)0;	char baudstr[16];	char dbgstr[16];	char dial_log[100];	char *stripped_num;	char *sptr;	char *dptr;	static char stat_s64[64];	ulong colors_at_entry = colors_current;	extern char *make_char_graphic();	char token[128];        /* translated dialer token */	FILE *fp;	char credit_file[128];	char *error_name = "";	int error_baud = 0;	int rcvr_restart = need_rcvr_restart();	/*	 * we may do nothing	 */	if(sigint)	/* don't even start if console interrupt posted */	{		sigint = 0;		return(2);	}	if(!there_is_hdb_on_this_machine)		return(4);	/*	 * kill receiver if it is active	 */	if(rcvr_restart)		kill_rcvr_process(SIGUSR1);#if defined(CHOOSE_DEBUG)	sprintf(dial_log,"HDB_DIAL Lline=%s Lbaud=%d",		shm->Lline,shm->Lbaud);	ecu_log_event(getpid(),dial_log);#endif	/*	 * get a Devices entry appropriate for dialing on the line;	 */	enddvent();	while(tdve = getdvline(shm->Lline + 5))	{		if((tdve->low_baud <= shm->Lbaud) &&			(shm->Lbaud <= tdve->high_baud)) 		{			break;		}	}	error_name = shm->Lline + 5;	error_baud = shm->Lbaud;	enddvent();	if(!tdve)	{		pprintf("no Devices entry for %s at %u baud ... trying ecu dialer\n",			error_name,error_baud);		return(4);	}	dial_log[0] = 0;	if(*tdve->dialprog != '/')	{		tdle = getdlentname(tdve->dialprog);		enddlent();		if(!tdle)		{			sprintf(dial_log,				"UUCPDIAL Devices entry %s: '%s' not found in Dialers",				shm->Lline + 5,tdve->dialprog);		}	}	else if(access(tdve->dialprog,1))	{		sprintf(dial_log,"UUCPDIAL Devices entry %s: (%s) %s",			shm->Lline + 5,tdve->dialprog,errno_text(errno));	}	if(dial_log[0])	{#if defined(LOG_HDBDIAL)		ecu_log_event(getpid(),dial_log);#endif		pputs(dial_log + 9);		pputs("\n");		return(4);	}	stripped_num = strip_phone_num(shm->Ltelno);	/*	 * if trailing '$', read and append ~/.ecu/.credit	 */	dptr = stripped_num;	if(*(dptr - 1) == '$')	{		*--dptr = 0;		get_home_dir(credit_file);		strcat(credit_file,"/.ecu/.credit");		chmod(credit_file,0400);	/* let's keep this one quiet */		if(fp = fopen(credit_file,"r"))		{			fgets(dptr,30,fp);			fclose(fp);		}		if(!fp || !(*dptr))		{			strcpy(sv[0]->pb,"!CREDIT CARD ERROR");			sv[0]->cb = strlen(sv[0]->pb);			pputs("\ncredit card error\n");			iv[0] = 1;			return(1);		}		if(*(dptr + strlen(dptr) - 1) == 0x0A)			*(dptr + strlen(dptr) - 1) = 0; /* kill NL */	}  /* Translate Token now (thanks to ache@hq.demos.su) */	if (tdve->token == (char *)0 || !tdve->token[0])		strcpy(token, stripped_num);	else {		dptr = token;		for (sptr = tdve->token; *sptr; sptr++)			if (*sptr != '\\')				*dptr++ = *sptr;			else {				char *s, *t;				switch (*(sptr + 1)) {				/* Direct */				case 'D':					sptr++;					s = stripped_num;					while (*s)						*dptr++ = *s++;					break;				/* Dialcodes Translate */				case 'T':					sptr++;					s = stripped_num;					t = dialcodes_translate(&s);					while(*t)						*dptr++ = *t++;					while (*s)						*dptr++ = *s++;					break;				default:					*dptr++ = '\\';					break;				}			}		*dptr = 0;	}	pprintf("Type %s to abort ... ",		(kbdintr == 0x7F) ? "DEL" : make_char_graphic(kbdintr,0));	setcolor(colors_normal);	if(Ldial_debug_level)	{		ttymode(0);		pputs("\n");	}	else		ttymode(2);	if(!tdle)	{		if(access(tdve->dialprog,1))		{			pperror(tdve->dialprog);			pputs("trying ecu dialer\n");			return(4);		}		sprintf(baudstr,"%u",shm->Lbaud);		sprintf(dbgstr,"-x%d",Ldial_debug_level);		original_sighdlr = signal(SIGCLD,SIG_DFL);		if((dial_pid = smart_fork()) == 0)		{			signal(SIGINT,SIG_DFL);			execl(tdve->dialprog,#if defined(WHT) || defined(ECUdial)				"ECUdial",		/* tell dialer ECU is calling */#else				tdve->dialprog,#endif				dbgstr, shm->Lline,token,baudstr,(char *)0);			_exit(0xFF);	/* did not execute */		}		wait_status = (RC_FAIL | RCE_SIG) << 8;		while(((itmp = wait(&wait_status)) != dial_pid) && (itmp != -1))			;		signal(SIGCLD,original_sighdlr);		ttymode(old_ttymode);		ttyflush(0);		if(sigint)	/* keyboard interrupt? */		{			kill(dial_pid,9);	/* kill dialer */			lflash_dtr();		/* drop line */			sigint = 0;			/* reset SIGINT indication */		}		lreset_ksr(); /* uucp dialers are nice guys, but lets use our termio */#if defined(LOG_HDBDIAL)		if(wait_status)		{			sprintf(dial_log,"UUCPDIAL %s %s exit status0x%04x",				tdve->dialprog,token,wait_status & 0xFFFF);			ecu_log_event(getpid(),dial_log);		}#endif		/*		 * if system reports interrupt, fake dial-reported status		 */		if(wait_status & 0xFF)			wait_status = (RC_FAIL | RCE_SIG) << 8;		if((wait_status & 0xFF00) == 0xFF00)		{			pprintf("%s failed  ... trying ecu dialer\n",tdve->dialprog);			return(4);		}		wait_status = (wait_status >> 8) & 0xFF;		if(!(wait_status & ~RC_BAUD))		{			char *cptr;			wait_status &= RC_BAUD;			switch (wait_status) 			{			case 0:         cptr = baudstr; break;  /* SAME */			case B50:       cptr = "50"; break;			case B75:       cptr = "75"; break;			case B110:      cptr = "110"; break;			case B134:      cptr = "134.5"; break;			case B150:      cptr = "150"; break;			case B200:      cptr = "200"; break;			case B300:      cptr = "300"; break;			case B600:      cptr = "600"; break;			case B1200:     cptr = "1200"; break;			case B1800:     cptr = "1800"; break;			case B2400:     cptr = "2400"; break;			case B4800:     cptr = "4800"; break;			case B9600:     cptr = "9600"; break;#if defined(B19200)			case B19200:    cptr = "19200"; break;#endif#if defined(B38400)			case B38400:    cptr = "38400"; break;#endif			default:				switch (wait_status) {				case EXTA:      cptr = "EXTA"; break;				case EXTB:      cptr = "EXTB"; break;				default:        cptr = "????"; break;				}			}			sprintf(stat_s64,"CONNECT %s",cptr);			*presult = stat_s64;    /* DCE_dial will report result code */			return(0);		}		*presult = hdb_dial_error_text(wait_status);		setcolor(colors_error);		pputs(*presult);		setcolor(colors_at_entry);		pputc('\n');		lflash_dtr();	}	else	{		pprintf("using Dialers entry '%s'\n",tdle->name);		expresp_verbosity = (proc_level & proctrace) ? proctrace : 0;		if(execute_expresp(tdle->script))		{			*presult = "DIALER SCRIPT FAILED";			setcolor(colors_error);			pputs(*presult);			setcolor(colors_at_entry);			pputc('\n');			iv[0] = 1;		}		else		{			extern char last_Speed_result[];			if(last_Speed_result[0])				*presult = last_Speed_result;			else			{				sprintf(stat_s64,"CONNECT %u",shm->Lbaud);				*presult = stat_s64;	/* DCE_dial will report result code */			}			setcolor(colors_at_entry);			iv[0] = 0;		}	}	/*	 * restart receiver if we killed it	 */	if(rcvr_restart)		start_rcvr_process(1);	return((int)iv[0]);}	/* end of hdb_dial *//*+-------------------------------------------------------------------------	hdb_init() - initialize HoneyDanBerInterface--------------------------------------------------------------------------*/voidhdb_init(){	char *hdblibdir = HDBLIBDIR;		/* system independent location */	int itmp;	int buflen = strlen(hdblibdir) + 64;	char *emsg = "hdb_init memory allocation failed!\n";	if(!(Devices_file = malloc(buflen)))	{		pputs(emsg);		termecu(TERMECU_MALLOC);	}	strcpy(Devices_file,hdblibdir);	strcat(Devices_file,"/Devices");	if(!(Dialers_file = malloc(buflen)))	{		pputs(emsg);		termecu(TERMECU_MALLOC);	}	for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++)	{		if(!(ungetty_list[itmp] = malloc(64)))		{			pputs(emsg);			termecu(TERMECU_MALLOC);		}	}	strcpy(Dialers_file,hdblibdir);	strcat(Dialers_file,"/Dialers");	if(!(Dialcodes_file = malloc(buflen)))	{		pputs(emsg);		termecu(TERMECU_MALLOC);	}	strcpy(Dialcodes_file,hdblibdir);	strcat(Dialcodes_file,"/Dialcodes");	there_is_hdb_on_this_machine = !access(Devices_file,4);}	/* end of hdb_init *//*+-------------------------------------------------------------------------dialcodes_translate(phone)  -  translate first part of phone using Dialcodes--------------------------------------------------------------------------*/char *dialcodes_translate(phone)char **phone;{	FILE *f;	int itmp;#define MAX_DLC_TOKENS 2	char *tokens[MAX_DLC_TOKENS];	static char dlstr[128];	if(!(f = fopen(Dialcodes_file, "r")))		return("");	while(fgets(dlstr,sizeof(dlstr),f))	{		if(((itmp = strlen(dlstr)) > 0) && (dlstr[itmp - 1] == '\n'))			dlstr[--itmp] = 0;		if((dlstr[0] == '#') || (dlstr[0] == ' ') || (!itmp))			continue;		if(tokens[0] = arg_token(dlstr," \t\r\n"))		{			if (!(tokens[1] = arg_token((char *)0," \t\r\n")))				tokens[1] = "";			itmp = strlen(tokens[0]);			if (strncmp(*phone, tokens[0], itmp))				continue;			fclose(f);			*phone += itmp;			fclose(f);			return(tokens[1]);		}		break;	}	fclose(f);	return("");}/*+-------------------------------------------------------------------------      strip_phone_num(sptr) - remove junk characters from phone--------------------------------------------------------------------------*/char *strip_phone_num(sptr)char *sptr;{	static char stripped_num[64];	char *dptr;	dptr = stripped_num;	while(*sptr)	{		if((*sptr == '(') || (*sptr == ')')#if defined(WHT) || defined(STRIP_TELNO_HYPHENS)			|| (*sptr == '-')	/* some want '-' for pauses; I use ',' */#endif			)		{			sptr++;			continue;		}		*dptr++ = *sptr++;	}	*dptr = 0;	return(stripped_num);}/* vi: set tabstop=4 shiftwidth=4: *//* end of hdbintf.c */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -