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

📄 ckcpro.c

📁 C-Kermit源码。是使用串口/Modem和网络通讯的程序
💻 C
📖 第 1 页 / 共 5 页
字号:
	bctl = bctu = 1;		/* set it to 1 */    }#endif /* pdp11 */    errpkt((CHAR *)"User cancelled");	/* Send the packet */#ifndef pdp11    if (epktflg) {			/* Restore the block check */	epktflg = 0;	bctl = b1; bctu = b2;    }#endif /* pdp11 */    success = 0;    return(0);				/* Return from protocol. */}    break;case 12:    {		/* Receive Send-Init packet. */    rc = rcv_s_pkt();    debug(F101,"rcv_s_pkt","",rc);    if (rc > -1) return(rc);		/* (see below) */}    break;case 13:    {				/* Get ack for I-packet */    int x = 0;#ifdef PKTZEROHACK    ckstrncpy(ipktack,(char *)rdatap,PKTZEROLEN); /* Save a copy of the ACK */    ipktlen = strlen(ipktack);#endif /* PKTZEROHACK */    spar(rdatap);			/* Set parameters */    winlo = 0;				/* Set window-low back to zero */    debug(F101,"<ipkt>Y winlo","",winlo);    urserver = 1;			/* So I know I'm talking to a server */    if (vcmd) {				/* If sending a generic command */	if (tinit(0) < 0) return(-9);	/* Initialize many things */	x = scmd(vcmd,(CHAR *)cmarg);	/* Do that */	if (x >= 0) x = 0;		/* (because of O-Packet) */	debug(F101,"proto G packet scmd","",x);	vcmd = 0;			/* and then un-remember it. */    } else if (vstate == get) {	debug(F101,"REGET sstate","",sstate);	x = srinit(reget, retrieve, opkt); /* GET or REGET, etc */    }    if (x < 0) {			/* If command was too long */	if (!srimsg)	  srimsg = "Error sending string";	errpkt((CHAR *)srimsg);		/* cancel both sides. */	success = 0;	RESUME;    } else if (x > 0) {			/* Need to send more O-Packets */	BEGIN ssopkt;    } else {	rtimer();			/* Reset the elapsed seconds timer. */#ifdef GFTIMER	rftimer();#endif /* GFTIMER */	winlo = 0;			/* Window back to 0, again. */	debug(F101,"<ipkt>Y vstate","",vstate);	nakstate = 1;			/* Can send NAKs from here. */	BEGIN vstate;			/* Switch to desired state */    }}    break;case 14:    {				/* Got ACK to O-Packet */    debug(F100,"CPCPRO <ssopkt>Y","",0);    x = sopkt();    debug(F101,"CPCPRO <ssopkt>Y x","",x);    if (x < 0) {			/* If error */	errpkt((CHAR *)srimsg);		/* cancel both sides. */	success = 0;	RESUME;    } else if (x == 0) {		/* This was the last O-Packet */	rtimer();			/* Reset the elapsed seconds timer. */#ifdef GFTIMER	rftimer();#endif /* GFTIMER */	winlo = 0;			/* Window back to 0, again. */	debug(F101,"<ssopkt>Y winlo","",winlo);	nakstate = 1;			/* Can send NAKs from here. */	BEGIN vstate;			/* Switch to desired state */    }    debug(F101,"CPCPRO <ssopkt>Y not changing state","",x);}    break;case 15:    {				/* Ignore Error reply to I packet */    int x = 0;    winlo = 0;				/* Set window-low back to zero */    debug(F101,"<ipkt>E winlo","",winlo);    if (vcmd) {				/* In case other Kermit doesn't */	if (tinit(0) < 0) return(-9);	x = scmd(vcmd,(CHAR *)cmarg);	/* understand I-packets. */	if (x >= 0) x = 0;		/* (because of O-Packet) */	vcmd = 0;			/* Otherwise act as above... */    } else if (vstate == get) x = srinit(reget, retrieve, opkt);    if (x < 0) {			/* If command was too long */	errpkt((CHAR *)srimsg);		/* cancel both sides. */	success = 0;	RESUME;    } else if (x > 0) {			/* Need to send more O-Packets */	BEGIN ssopkt;    } else {	winlo = 0;			/* Back to packet 0 again. */	debug(F101,"<ipkt>E winlo","",winlo);	freerpkt(winlo);		/* Discard the Error packet. */	nakstate = 1;			/* Can send NAKs from here. */	BEGIN vstate;    }}    break;case 16:    {		/* Resend of previous I-pkt ACK, same seq number! */    srinit(reget, retrieve, opkt);	/* Send the GET packet again. */}    break;case 17:    {				/* Get I-packet */#ifndef NOSERVER    spar(rdatap);			/* Set parameters from it */    ack1(rpar());			/* Respond with our own parameters */#ifdef COMMENT    pktinit();				/* Reinitialize packet numbers */#else#ifdef COMMENT    /* This can't be right - it undoes the stuff we just negotiated */    x = justone;    tinit(1);				/* Reinitialize EVERYTHING */    justone = x;			/* But this... */#else    tinit(0);				/* Initialize most things */#endif /* COMMENT */#endif /* COMMENT */#endif /* NOSERVER */}    break;case 18:    {				/* GET */#ifndef NOSERVER    if (x_login && !x_logged) {	errpkt((CHAR *)"Login required");	SERVE;    } else if (sgetinit(0,0) < 0) {	RESUME;    } else {#ifdef CKSYSLOG	if (ckxsyslog >= SYSLG_PR && ckxlogging)	  cksyslog(SYSLG_PR, 1, "server", "GET", (char *)srvcmd);#endif /* CKSYSLOG */	BEGIN ssinit;    }#endif /* NOSERVER */}    break;case 19:    {				/* GET /DELETE (RETRIEVE) */#ifndef NOSERVER    if (x_login && !x_logged) {	errpkt((CHAR *)"Login required");	RESUME;    } else if (!ENABLED(en_del)) {	errpkt((CHAR *)"Deleting files is disabled");	RESUME;    } else if (sgetinit(0,0) < 0) {	RESUME;    } else {	moving = 1;#ifdef CKSYSLOG	if (ckxsyslog >= SYSLG_PR && ckxlogging)	  cksyslog(SYSLG_PR, 1, "server", "GET /DELETE", (char *)srvcmd);#endif /* CKSYSLOG */	BEGIN ssinit;    }#endif /* NOSERVER */}    break;case 20:    {				/* GET /RECURSIVE */#ifndef NOSERVER    recursive = 1;			/* Set these before sgetinit() */    if (fnspath == PATH_OFF)      fnspath = PATH_REL;		/* Don't worry, they will be */    if (x_login && !x_logged) {		/* reset next time through. */	errpkt((CHAR *)"Login required");	RESUME;    } else if (sgetinit(0,0) < 0) {	RESUME;    } else {#ifdef CKSYSLOG	if (ckxsyslog >= SYSLG_PR && ckxlogging)	  cksyslog(SYSLG_PR, 1, "server", "GET /RECURSIVE", (char *)srvcmd);#endif /* CKSYSLOG */	BEGIN ssinit;    }#endif /* NOSERVER */}    break;case 21:    {				/* GET /RECURSIVE /DELETE */#ifndef NOSERVER    recursive = 1;			/* Set these before sgetinit() */    if (fnspath == PATH_OFF)      fnspath = PATH_REL;		/* Don't worry, they will be */    moving = 1;				/* reset next time through. */    if (x_login && !x_logged) {	errpkt((CHAR *)"Login required");	RESUME;    } else if (!ENABLED(en_del)) {	errpkt((CHAR *)"Deleting files is disabled");	RESUME;    } else if (sgetinit(0,0) < 0) {	RESUME;    } else {#ifdef CKSYSLOG	if (ckxsyslog >= SYSLG_PR && ckxlogging)	  cksyslog(SYSLG_PR,1,"server",		   "GET /RECURSIVE /DELETE",(char *)srvcmd);#endif /* CKSYSLOG */	BEGIN ssinit;    }#endif /* NOSERVER */}    break;case 22:    {				/* GET /RECOVER (REGET) */#ifndef NOSERVER    if (x_login && !x_logged) {	errpkt((CHAR *)"Login required");	SERVE;    } else if (sgetinit(1,0) < 0) {	RESUME;    } else {#ifdef CKSYSLOG	if (ckxsyslog >= SYSLG_PR && ckxlogging)	  cksyslog(SYSLG_PR, 1, "server", "GET /RECOVER", (char *)srvcmd);#endif /* CKSYSLOG */	BEGIN ssinit;    }#endif /* NOSERVER */}    break;case 23:    {				/* Extended GET */#ifndef NOSERVER    if (x_login && !x_logged) {		/* (any combination of options) */	errpkt((CHAR *)"Login required");	SERVE;    } else if ((x = sgetinit(0,1)) < 0) {	debug(F101,"CKCPRO <serve>O sgetinit fail","",x);	RESUME;    } else if (x == 0) {	debug(F101,"CKCPRO <serve>O sgetinit done","",x);#ifdef CKSYSLOG	if (ckxsyslog >= SYSLG_PR && ckxlogging)	  cksyslog(SYSLG_PR, 1, "server", "EXTENDED GET", (char *)srvcmd);#endif /* CKSYSLOG */	BEGIN ssinit;    } else {				/* Otherwise stay in this state */	debug(F101,"CKCPRO <serve>O sgetinit TBC","",x);	ack();	BEGIN ropkt;    }#endif /* NOSERVER */}    break;case 24:    {#ifndef NOSERVER    if (x_login && !x_logged) {		/* (any combination of options) */	errpkt((CHAR *)"Login required");	SERVE;    } else if ((x = sgetinit(0,1)) < 0) {	debug(F101,"CKCPRO <ropkt>O sgetinit fail","",x);	RESUME;    } else if (x == 0) {	debug(F101,"CKCPRO <ropkt>O sgetinit done","",x);#ifdef CKSYSLOG	if (ckxsyslog >= SYSLG_PR && ckxlogging)	  cksyslog(SYSLG_PR, 1, "server", "EXTENDED GET", (char *)srvcmd);#endif /* CKSYSLOG */	BEGIN ssinit;    } else {				/* Otherwise stay in this state */	debug(F101,"CKCPRO <ropkt>O sgetinit TBC","",x);	ack();    }#endif /* NOSERVER */}    break;case 25:    {				/* Generic server command */#ifndef NOSERVER    srvptr = srvcmd;			/* Point to command buffer */    decode(rdatap,putsrv,0);		/* Decode packet data into it */    putsrv(NUL);			/* Insert a couple nulls */    putsrv(NUL);			/* for termination */    if (srvcmd[0]) {	sstate = srvcmd[0];		/* Set requested start state */	if (x_login && !x_logged &&	/* Login required? */	    /* Login, Logout, and Help are allowed when not logged in */	    sstate != 'I' && sstate != 'L' && sstate != 'H') {	    errpkt((CHAR *)"Login required");	    SERVE;	} else {	    nakstate = 0;		/* Now I'm the sender. */	    what = W_REMO;		/* Doing a REMOTE command. */#ifdef STREAMING	    if (!streaming)#endif /* STREAMING */	      if (timint < 1)		timint = chktimo(rtimo,timef); /* Switch to per-packet timer */	    binary = XYFT_T;		/* Switch to text mode */	    BEGIN generic;		/* Switch to generic command state */	}    } else {	errpkt((CHAR *)"Badly formed server command"); /* report error */	RESUME;			/* & go back to server command wait */    }#endif /* NOSERVER */}    break;case 26:    {				/* Receive Host command */#ifndef NOSERVER    if (x_login && !x_logged) {	errpkt((CHAR *)"Login required");	SERVE;    } else if (!ENABLED(en_hos)) {	errpkt((CHAR *)"REMOTE HOST disabled");	RESUME;    } else if (nopush) {	errpkt((CHAR *)"HOST commands not available");	RESUME;    } else {	srvptr = srvcmd;		/* Point to command buffer */	decode(rdatap,putsrv,0);	/* Decode command packet into it */	putsrv(NUL);			/* Null-terminate */	nakstate = 0;			/* Now sending, not receiving */	binary = XYFT_T;		/* Switch to text mode */	if (syscmd((char *)srvcmd,"")) { /* Try to execute the command */	    what = W_REMO;		/* Doing a REMOTE command. */#ifdef STREAMING	    if (!streaming)#endif /* STREAMING */	      if (timint < 1)		timint = chktimo(rtimo,timef); /* Switch to per-packet timer */#ifdef CKSYSLOG	    if (ckxsyslog >= SYSLG_PR && ckxlogging)	      cksyslog(SYSLG_PR, 1, "server", "REMOTE HOST", (char *)srvcmd);#endif /* CKSYSLOG */	    BEGIN ssinit;		/* If OK, send back its output */	} else {			/* Otherwise */	    errpkt((CHAR *)"Can't do system command"); /* report error */	    RESUME;			/* & go back to server command wait */	}    }#endif /* NOSERVER */}    break;case 27:    {				/* Interrupted or connection lost */    rc = srv_timeout();    debug(F101,"srv_timeout","",rc);    if (rc > -1) return(rc);		/* (see below) */}    break;case 28:    {				/* Server got a NAK in command-wait */#ifndef NOSERVER    errpkt((CHAR *)"Did you say RECEIVE instead of GET?");    RESUME;#endif /* NOSERVER */}    break;case 29:    {				/* Any other command in this state */#ifndef NOSERVER    if (c != ('E' - SP) && c != ('Y' - SP)) /* except E and Y packets. */      errpkt((CHAR *)"Unimplemented server function");    /* If we answer an E with an E, we get an infinite loop. */    /* A Y (ACK) can show up here if we sent back a short-form reply to */    /* a G packet and it was echoed.  ACKs can be safely ignored here. */    RESUME;				/* Go back to server command wait. */#endif /* NOSERVER */}    break;case 30:    {				/* Login/Out */    rc = srv_login();    debug(F101,"<generic>I srv_login","",rc);    if (rc > -1) return(rc);		/* (see below) */}    break;case 31:    {				/* Got REMOTE CD command */#ifndef NOSERVER#ifdef CKSYSLOG    if (ckxsyslog >= SYSLG_PR && ckxlogging)      cksyslog(SYSLG_PR, 1, "server", "REMOTE CD", (char *)srvcmd);#endif /* CKSYSLOG */    if (!ENABLED(en_cwd)) {	errpkt((CHAR *)"REMOTE CD disabled");	RESUME;    } else {	char * p = NULL;	x = cwd((char *)(srvcmd+1));	/* Try to change directory */#ifdef IKSDB	if (ikdbopen) slotstate(what,"REMOTE CD", (char *)(srvcmd+2), "");#endif /* IKSDB */	if (!x) {			/* Failed */	    errpkt((CHAR *)"Can't change directory");	    RESUME;			/* Back to server command wait */	} else if (x == 2) {		/* User wants message */	    if (!ENABLED(en_typ)) {	/* Messages (REMOTE TYPE) disabled? */		errpkt((CHAR *)"REMOTE TYPE disabled");		RESUME;	    } else {			/* TYPE is enabled */		int i;		for (i = 0; i < 8; i++) {		    if (zchki(cdmsgfile[i]) > -1) {			break;		    }		}		binary = XYFT_T;	/* Use text mode for this. */		if (i < 8 && sndtype(cdmsgfile[i])) { /* Have readme file? */		    BEGIN ssinit;	/* OK */		} else {		/* not OK */		    p = zgtdir();		    if (!p) p = "";		    success = (*p) ? 1 : 0;		    ack1((CHAR *)p);	/* ACK with new directory name */		    success = 1;		    RESUME;		/* wait for next server command */

⌨️ 快捷键说明

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