📄 dcpsys.c
字号:
/* End UUCP session negotiation */
/*--------------------------------------------------------------------*/
CONN_STATE sysend()
{
char msg[80];
wmsg("OOOOOO", TRUE);
rmsg(msg, TRUE, 5, sizeof msg);
wmsg("OOOOOO", TRUE);
ssleep(2); /* Wait for it to be transmitted */
return CONN_DROPLINE;
} /*sysend*/
/*--------------------------------------------------------------------*/
/* w m s g */
/* */
/* write a ^P type msg to the remote uucp */
/*--------------------------------------------------------------------*/
void wmsg(const char *msg, const boolean synch)
{
if (synch)
swrite("\0\020", 2);
printmsg( 4, "==> %s%s", synch ? "^p" : "", msg );
swrite(msg, strlen(msg));
if (synch)
swrite("\0", 1);
} /*wmsg*/
/*--------------------------------------------------------------------*/
/* r m s g */
/* */
/* read a ^P msg from UUCP */
/*--------------------------------------------------------------------*/
int rmsg(char *msg, const boolean synch, unsigned int msgtime, int max_len)
{
int i;
char ch = '?'; /* Initialize to non-zero value */ /* ahd */
/*--------------------------------------------------------------------*/
/* flush until next ^P */
/*--------------------------------------------------------------------*/
if (synch == 1)
{
do {
if (sread(&ch, 1, msgtime) < 1)
{
printmsg(2 ,"rmsg: Timeout waiting for sync");
return TIMEOUT;
} /* if */
} while ((ch & 0x7f) != '\020');
}
/*--------------------------------------------------------------------*/
/* Read until timeout, next newline, or we fill the input buffer */
/*--------------------------------------------------------------------*/
for (i = 0; (i < max_len) && (ch != '\0'); )
{
if (sread(&ch, 1, msgtime) < 1)
{
printmsg(1 ,"rmsg: Timeout reading message");
return TIMEOUT;
}
/*--------------------------------------------------------------------*/
/* Process backspaces if not in sync mode */
/*--------------------------------------------------------------------*/
if ((synch != 1) &&
(ch != '\r') &&
(ch != '\n') &&
(ch != '\0') &&
iscntrl( ch ))
{
if ( i && ((ch == 0x7f) || (ch == '\b')))
{
i--;
if ( synch == 2 )
swrite( "\b \b", 3);
}
else {
swrite( "\a", 1 ); /* Beep in response to invalid
cntrl characters, including
extra backspaces */
} /* else */
} /* if */
else { /* else a normal character */
/*--------------------------------------------------------------------*/
/* Echo the character if requested by caller */
/*--------------------------------------------------------------------*/
if ( synch == 2 )
swrite( &ch, 1);
ch &= 0x7f;
if (ch == '\r' || ch == '\n')
ch = '\0';
msg[i++] = ch;
} /* else */
}
msg[max_len - 1] = '\0';
printmsg( 4, "<== %s%s",
(synch == 1) ? "^p" : "",
msg);
return strlen(msg);
} /*rmsg*/
/*--------------------------------------------------------------------*/
/* s t a r t u p _ s e r v e r */
/* */
/* Exchange host and protocol information for a system we called */
/*--------------------------------------------------------------------*/
CONN_STATE startup_server(const char recvgrade )
{
char msg[80];
char *s;
hostp->hstatus = startup_failed;
hostp->via = hostp->hostname; // Save true hostname
/*--------------------------------------------------------------------*/
/* Handle the special case of '*' protocol, which is really our */
/* NBS time setting support */
/*--------------------------------------------------------------------*/
if (*protocols == '*')
{
if (nbstime())
{
hostp->hstatus = called;
time( &hostp->hstats->lconnect );
}
return CONN_DROPLINE;
}
/*--------------------------------------------------------------------*/
/* Begin normal processing */
/*--------------------------------------------------------------------*/
if (rmsg(msg, TRUE, M_startupTimeout, sizeof msg) == TIMEOUT)
{
printmsg(0,"Startup: Timeout for first message");
return CONN_TERMINATE;
}
/*--------------------------------------------------------------------*/
/* The first message must begin with Shere */
/*--------------------------------------------------------------------*/
if (!equaln(msg,"Shere",5))
{
printmsg(0,"Startup: First message not Shere, was \"%s\"", msg);
return CONN_TERMINATE;
}
/*--------------------------------------------------------------------*/
/* The host can send either a simple Shere, or Shere=hostname; */
/* we allow either. */
/*--------------------------------------------------------------------*/
if ((msg[5] == '=') && !equaln(&msg[6], rmtname, HOSTLEN))
{
printmsg(0,"Startup: Wrong host %s, expected %s",
&msg[6], rmtname);
hostp->hstatus = wrong_host;
return CONN_TERMINATE; /* wrong host */ /* ahd */
}
/*--------------------------------------------------------------------*/
/* Setup our hello message with system name and optional debug */
/* and call grade levels. */
/*--------------------------------------------------------------------*/
sprintf(msg, "S%s", securep->myname );
if ( bflag[F_SENDDEBUG] )
sprintf( msg + strlen(msg), " -x%d", debuglevel );
if (recvgrade != ALL_GRADES)
sprintf( msg + strlen(msg), " -p%c -vgrade=%c",
recvgrade, recvgrade );
wmsg(msg, TRUE);
/*--------------------------------------------------------------------*/
/* Second message is system is okay */
/*--------------------------------------------------------------------*/
if (rmsg(msg, TRUE, M_startupTimeout, sizeof msg) == TIMEOUT)
{
printmsg(0,"Startup: Timeout for second message");
return CONN_TERMINATE;
}
if (!equaln(&msg[1], "OK", 2))
{
printmsg(0,"Unexpected second message: %s",&msg[1]);
return CONN_TERMINATE;
}
/*--------------------------------------------------------------------*/
/* Third message is protocol exchange */
/*--------------------------------------------------------------------*/
if (rmsg(msg, TRUE, M_startupTimeout, sizeof msg) == TIMEOUT)
return CONN_TERMINATE;
if (*msg != 'P')
{
printmsg(0,"Unexpected third message: %s",&msg[1]);
return CONN_TERMINATE;
}
/*--------------------------------------------------------------------*/
/* Locate a common procotol */
/*--------------------------------------------------------------------*/
s = strpbrk( protocols, &msg[1] );
if ( s == NULL )
{
printmsg(0,"Startup: No common protocol");
wmsg("UN", TRUE);
return CONN_TERMINATE; /* no common protocol */
}
/*--------------------------------------------------------------------*/
/* While the remote is waiting for us, update our status */
/*--------------------------------------------------------------------*/
hostp->hstatus = inprogress;
hostp->hstats->lconnect = time( &remote_stats.lconnect );
/*--------------------------------------------------------------------*/
/* Tell the remote host the protocol to use */
/*--------------------------------------------------------------------*/
sprintf(msg, "U%c", *s);
wmsg(msg, TRUE);
setproto(*s);
/*--------------------------------------------------------------------*/
/* The connection is complete; report this and return to caller */
/*--------------------------------------------------------------------*/
printmsg(0,"%s connected to %s: %ld bps, %c protocol, %c grade",
E_nodename, rmtname, (long) GetSpeed() , *s, recvgrade );
return CONN_SERVER;
} /*startup_server*/
/*--------------------------------------------------------------------*/
/* s t a r t u p _ c l i e n t */
/* */
/* Setup a host connection with a system which has called us */
/*--------------------------------------------------------------------*/
CONN_STATE startup_client( char *sendgrade )
{
char plist[20];
char msg[80];
int xdebug = debuglevel;
char *sysname = rmtname;
Proto *tproto;
char *s;
char *flds[10];
int kflds,i;
char grade = ALL_GRADES;
/*--------------------------------------------------------------------*/
/* Challange the host calling in with the name defined for this */
/* login (if available) otherwise our regular node name. (It's */
/* a valid session if the securep pointer is NULL, but this is */
/* trapped below in the call to ValidateHost() */
/*--------------------------------------------------------------------*/
sprintf(msg, "Shere=%s", securep == NULL ?
E_nodename : securep->myname );
wmsg(msg, TRUE);
if (rmsg(msg, TRUE, M_startupTimeout, sizeof msg) == TIMEOUT)
return CONN_TERMINATE;
printmsg(2, "1st msg from remote = %s", msg);
/*--------------------------------------------------------------------*/
/* Parse additional flags from remote system */
/*--------------------------------------------------------------------*/
kflds = getargs(msg,flds);
strcpy(sysname,&flds[0][1]);
for (i=1; i < kflds; i++)
{
if (flds[i][0] != '-')
printmsg(0,"Invalid argument \"%s\" from system %s",
flds[i],
sysname);
else
switch(flds[i][1])
{
case 'Q' : /* Ignore the remote sequence number */
break;
case 'x' :
if ( bflag[ F_HONORDEBUG ] )
sscanf(flds[i], "-x%d", &xdebug);
break;
case 'p' :
sscanf(flds[i], "-p%c", &grade);
break;
case 'v' :
sscanf(flds[i], "-vgrade=%c", &grade);
break;
default :
printmsg(0,"Invalid argument \"%s\" from system %s",
flds[i],
sysname);
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -