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

📄 ckcpro.c

📁 linux终端仿真程序
💻 C
📖 第 1 页 / 共 4 页
字号:
	if (!ENABLED(en_que)) { /* Security */	    errpkt((CHAR *)"REMOTE QUERY disabled");	    RESUME;	} else {			/* Query allowed */	    int n; char *p, *q;	    qbufp = querybuf;		/* Wipe out old stuff */	    qbufn = 0;	    querybuf[0] = NUL;	    p = (char *) srvcmd + 3;	/* Pointer for making wrapper */	    n = strlen((char *)srvcmd);	/* Position of end */	    c = *(srvcmd+4);		/* Which type of variable */	    if (*(srvcmd+6) == CMDQ) {	/* Starts with command quote? */		p = (char *) srvcmd + 6; /* Take it literally */		if (*p == CMDQ) p++;	    } else {			/* They played by the rules */		if (c == 'K') {		/* Kermit variable */		    int k;		    k = (int) strlen(p);		    if (k > 0 && p[k-1] == ')') {			p = (char *)(srvcmd + 4);			*(srvcmd+4) = CMDQ;			*(srvcmd+5) = 'f'; /* Function, so make it \f...() */		    } else {			*(srvcmd+3) = CMDQ; /* Stuff wrapping into buffer */			*(srvcmd+4) = 'v';  /* Variable, so make it \v(...) */			*(srvcmd+5) = '(';  /* around variable name */			*(srvcmd+n) = ')';			*(srvcmd+n+1) = NUL;		    }		} else {		    *(srvcmd+3) = CMDQ; /* Stuff wrapping into buffer */		    *(srvcmd+4) = 'v'; /*  Variable, so make it \v(...) */		    *(srvcmd+5) = '(';	/* around variable name */		    *(srvcmd+n) = ')';		    *(srvcmd+n+1) = NUL;		    if (c == 'S') {	/* System variable */			*(srvcmd+4) = '$'; /*  so it's \$(...) */		    } else if (c == 'G') { /* Non-\ Global variable */			*(srvcmd+4) = 'm'; /*  so wrap it in \m(...) */		    }		}	    }				/* Now evaluate it */	    n = QBUFL;			/* Max length */	    q = querybuf;		/* Where to put it */	    if (zzstring(p,&q,&n) < 0) {		errpkt((n > 0) ? (CHAR *)"Can't get value"		               : (CHAR *)"Value too long"		       );		RESUME;	    } else {		if (encstr((CHAR *)querybuf) > -1) { /* Encode it */		    ack1(data);		/* If it fits, send it back in ACK */		    RESUME;		} else if (sndhlp(querybuf)) { /* Long form response */		    BEGIN ssinit;		} else {		/* sndhlp() fails */		    errpkt((CHAR *)"Can't send value");		    RESUME;		}	    }	}    } else if (c == 'S') {		/* Set (assign) */	if (!ENABLED(en_asg)) {		/* Security */	    errpkt((CHAR *)"REMOTE ASSIGN disabled");	    RESUME;	} else {			/* OK */	    int n;	    n = xunchar(*(srvcmd+3));	/* Length of name */	    n = 3 + n + 1;		/* Position of length of value */	    *(srvcmd+n) = NUL;		/* Don't need it */	    if (addmac((char *)(srvcmd+4),(char *)(srvcmd+n+1)) < 0)	      errpkt((CHAR *)"REMOTE ASSIGN failed");	    else	      ack();	    RESUME;	}    } else {	errpkt((CHAR *)"Badly formed server command");	RESUME;    }#else    errpkt((CHAR *)"Variable query/set not available");    RESUME;#endif /* NOSPL */#endif /* NOSERVER */}    break;case 39:    {#ifndef NOSERVER    if (!ENABLED(en_fin)) {		/* Ctrl-C typed */	errpkt((CHAR *)"QUIT disabled");	RESUME;    } else {	success = 0; QUIT;    }#endif /* NOSERVER */}    break;case 40:    {				/* Anything else in this state... */#ifndef NOSERVER    errpkt((CHAR *)"Unimplemented REMOTE command"); /* Complain */    RESUME;				/* and return to server command wait */#endif /* NOSERVER */}    break;case 41:    {				/* Short-Form reply */#ifndef NOSERVER#ifndef NOSPL    if (query) {			/* If to query, */	qbufp = querybuf;		/*  initialize query response buffer */	qbufn = 0;	querybuf[0] = NUL;    }#endif /* NOSPL */    decode(rdatap,puttrm,0);		/* Text is in ACK Data field */    if (rdatap)				/* If we had data */      if (*rdatap)	 conoll("");			/* Then add a CRLF */    if (bye_active && network) {	/* I sent a BYE command and got */	msleep(500);			/* the ACK... */	tthang();    }    success = 1;    RESUME;#endif /* NOSERVER */}    break;case 42:    {				/* File header */    xflg = 0;				/* Not screen data */    if (!rcvfil(filnam)) {		/* Figure out local filename */	errpkt((CHAR *)rf_err);		/* Trouble */	screen(SCR_EM,0,0L,rf_err);	RESUME;    } else {				/* Real file, OK to receive */	if (filcnt == 1)		/* rcvfil set this to 1 for 1st file */	  crc16 = 0L;			/* Clear file CRC */#ifndef NOFULLNAME#ifdef ZFNQFP				/* Because of zfnqfp() */#ifdef BIGBUFOK				/* Because it's another 1K buffer */#define USEFULLNAME			/* Memory to burn - do it */#endif /* BIGBUFOK */#endif /* ZFNQFP */#endif /* NOFULLNAME */#ifdef USEFULLNAME			/* Name to send back in ACK */	if (!isabsolute(filnam)) {	    CHAR tmpbuf[91];		/* Must fit in ACK Data field */	    struct zfnfp * fnp;	    fnp = zfnqfp(filnam,90,(char *)tmpbuf);	    encstr(fnp ? tmpbuf: (CHAR *)filnam); /* Send the full pathname */	} else#endif /* USEFULLNAME */	  encstr((CHAR *)filnam);	/* Encode the local filename */	ack1(data);			/* Send it back in ACK */	initattr(&iattr);		/* Clear file attribute structure */	if (window(wslotn) < 0) {	/* Allocate negotiated window slots */	    errpkt((CHAR *)"Can't open window");	    RESUME;	}	BEGIN rattr;			/* Now expect Attribute packets */    }}    break;case 43:    {				/* X-packet instead of file header */    xflg = 1;				/* Screen data */    ack();				/* Acknowledge the X-packet */    initattr(&iattr);			/* Initialize attribute structure */    if (window(wslotn) < 0) {		/* allocate negotiated window slots */	errpkt((CHAR *)"Can't open window");	RESUME;    }#ifndef NOSPL    if (query) {			/* If this is the response to */	qbufp = querybuf;		/* a query that we sent, initialize */	qbufn = 0;			/* the response buffer */	querybuf[0] = NUL;    }#endif /* NOSPL */    what = W_REMO;			/* we're doing a REMOTE command */    BEGIN rattr;			/* Expect Attribute packets */}    break;case 44:    {				/* Attribute packet */    if (gattr(rdatap,&iattr) == 0) {	/* Read into attribute structure */#ifdef CK_RESEND	ack1((CHAR *)iattr.reply.val);	/* Reply with data */#else	ack();				/* If OK, acknowledge */#endif /* CK_RESEND */    } else {				/* Otherwise */	ack1((CHAR *)iattr.reply.val);	/* refuse to accept the file */	screen(SCR_ST,ST_REFU,0L,getreason(iattr.reply.val)); /* give reason */    }}    break;case 45:    {				/* First data packet */    if (discard) {			/* if we're discarding the file */	ack1((CHAR *)"X");		/* just ack the data like this. */	BEGIN rdata;			/* and wait for more data packets. */    } else {				/* Not discarding. */	rf_err = "Can't open file";	if (xflg) {			/* If screen data */	    if (remfile) {		/* redirected to file */		if (rempipe)		/* or pipe */		  x = zxcmd(ZOFILE,remdest); /* Pipe: start command */		else		  x = opena(remdest,&iattr); /* File: open with attributes */	    } else {			/* otherwise */		x = opent(&iattr);	/* "open" the screen */	    }	} else {			/* otherwise */	    x = opena(filnam,&iattr);	/* open the file, with attributes */	}	if (x) {			/* If file was opened ok */	    if (decode(rdatap, #ifndef NOSPL		       query ? puttrm : #endif /* NOSPL */		       putfil, 1) < 0) {		errpkt((CHAR *)"Error writing data");		RESUME;	    }	    ack();			/* acknowledge it */	    BEGIN rdata;		/* and switch to receive-data state */	} else {			/* otherwise */	    errpkt((CHAR *) rf_err);	/* send error message */	    RESUME;			/* and quit. */	}    }}    break;case 46:    {				/* EOT, no more files */    ack();				/* Acknowledge */    tsecs = gtimer();			/* Get timing for statistics */    reot();				/* Do EOT things */#ifdef CK_TMPDIR/* If we were cd'd temporarily to another device or directory ... */    if (f_tmpdir) {	int x;	x = zchdir((char *) savdir);	/* ... restore previous directory */	f_tmpdir = 0;			/* and remember we did it. */	debug(F111,"ckcpro.w B tmpdir restoring",savdir,x);    }#endif /* CK_TMPDIR */    RESUME;				/* and quit */}    break;case 47:    {				/* Data packet */    if (cxseen || discard)		/* If file interrupt */      ack1((CHAR *)"X");		/* put "X" in ACK */    else if (czseen)			/* If file-group interrupt */      ack1((CHAR *)"Z");		/* put "Z" in ACK */    else if (decode(rdatap, #ifndef NOSPL		       query ? puttrm : #endif /* NOSPL */		       putfil, 1) < 0) {	errpkt((CHAR *)"Error writing data"); /* If failure, */	clsof(!keep);			/*   Close & keep/discard the file */	RESUME;				/* Send ACK only after data */    } else ack();			/* written to file OK. */}    break;case 48:    {				/* EOF immediately after A-Packet. */    rf_err = "Can't create file";    if (discard) {			/* Discarding a real file... */	x = 1;    } else if (xflg) {			/* If screen data */	if (remfile) {			/* redirected to file */	    if (rempipe)		/* or pipe */	      x = zxcmd(ZOFILE,remdest); /* Pipe: start command */	    else	      x = opena(remdest,&iattr); /* File: open with attributes */	} else {			/* otherwise */	    x = opent(&iattr);		/* "open" the screen */	}    } else {				/* otherwise */	x = opena(filnam,&iattr);	/* open the file, with attributes */    }    if (!x || reof(filnam, &iattr) < 0) { /* Now close & dispose of the file */	errpkt((CHAR *) rf_err);	/* If problem, send error msg */	RESUME;				/* and quit */    } else {				/* otherwise */	ack();				/* acknowledge the EOF packet */	BEGIN rfile;			/* and await another file */    }}    break;case 49:    {				/* End Of File (EOF) Packet *//*  wslots = 1;	*/			/* Window size back to 1 */#ifndef COHERENT/*  Coherent compiler blows up on this switch() statement.*/    x = reof(filnam, &iattr);		/* Handle the EOF packet */    switch (x) {			/* reof() sets the success flag */      case -3:				/* If problem, send error msg */	errpkt((CHAR *)"Can't print file"); /* Fatal */        RESUME;	break;      case -2:	errpkt((CHAR *)"Can't mail file"); /* Fatal */        RESUME;	break;      case 2:      case 3:	screen(SCR_EM,0,0L,"Can't delete temp file"); /* Not fatal */        RESUME;	break;      default:	if (x < 0) {			/* Fatal */	    errpkt((CHAR *)"Can't close file");	    RESUME;	} else {			/* Success */#ifndef NOSPL	    if (query)			/* Query reponses generally */	      conoll("");		/* don't have line terminators */#endif /* NOSPL */	    ack();			/* Acknowledge the EOF packet */	    BEGIN rfile;		/* and await another file */	}    }#else    if (reof(filnam, &iattr) < 0) {	/* Close and dispose of the file */	errpkt((CHAR *)"Error at end of file");	RESUME;    } else {				/* reof() sets success flag */	ack();	BEGIN rfile;    }#endif /* COHERENT */}    break;case 50:    {				/* ACK for Send-Init */    spar(rdatap);			/* set parameters from it */    bctu = bctr;			/* switch to agreed-upon block check */    bctl = (bctu == 4) ? 2 : bctu;	/* Set block-check length */#ifdef CK_RESEND    if ((sendmode == SM_RESEND) && (!atcapu || !rscapu)) { /* RESEND */	errpkt((CHAR *) "RESEND capabilities not negotiated");	ermsg("RESEND capabilities not negotiated");	RESUME;    } else {#endif /* CK_RESEND */	what = W_SEND;			/* Remember we're sending */	x = sfile(xflg);		/* Send X or F header packet */	if (x) {			/* If the packet was sent OK */	    if (!xflg && filcnt == 1)	/* and it's a real file */	      crc16 = 0L;		/* Clear the file CRC */	    resetc();			/* reset per-transaction counters */	    rtimer();			/* reset timers */	    BEGIN ssfile;		/* and switch to receive-file state */	} else {			/* otherwise send error msg & quit */	    s = xflg ? "Can't execute command" : "Can't open file";	    errpkt((CHAR *)s);	    RESUME;	}#ifdef CK_RESEND    }#endif /* CK_RESEND */}    break;case 51:    {				/* R packet was retransmitted. */    xsinit();				/* Resend packet 0 */}    break;case 52:    {				/* Same deal if G packet comes again */    xsinit();}    break;case 53:    {				/* Same deal if C packet comes again */    xsinit();}    break;case 54:    {				/* ACK for F packet */    srvptr = srvcmd;			/* Point to string buffer */    decode(rdatap,putsrv,0);		/* Decode data field, if any */    putsrv(NUL);			/* Terminate with null */    ffc = 0L;				/* Reset file byte counter */    if (*srvcmd) {			/* If remote name was recorded */        if (sendmode != SM_RESEND) {	    if (fdispla == XYFD_C) 	      screen(SCR_AN,0,0L,(char *)srvcmd);	    tlog(F110," remote name:",(char *) srvcmd,0L);        }    }    if (atcapu) {			/* If attributes are to be used */	if (sattr(xflg | stdinf) < 0) {	/* set and send them */	    errpkt((CHAR *)"Can't send attributes"); /* if problem, say so */	    RESUME;			     /* and quit */	} else BEGIN ssattr;		/* if ok, switch to attribute state */    } else {	if (window(wslotn) < 0) {	    errpkt((CHAR *)"Can't open window");	    RESUME;	}	if ((x = sdata()) == -2) {	/* No attributes, send data */	    return(success = 0);	/* Failed */	} else if (x == -1) {		/* EOF (eh?) */	    clsif();			/* If not ok, close input file, */	    window(1);			/* put window size back to 1, */	    seof((CHAR *)"");		/* send EOF packet, */	    BEGIN sseof;		/* and switch to EOF state. */	} else BEGIN ssdata;		/* All ok, switch to send-data state */    }}    break;case 55:    {				/* Got ACK to A packet */    ffc = 0L;				/* Reset file byte counter */    if (rsattr(rdatap) < 0) {		/* Was the file refused? */	discard = 1;			/* Set the discard flag */	clsif();			/* Close the file */	sxeof((CHAR *)"D");		/* send EOF with "discard" code */	BEGIN sseof;			/* switch to send-EOF state */    } else {	if (window(wslotn) < 0) {	/* Allocate negotiated window slots */	    errpkt((CHAR *)"Can't open window");	    RESUME;	}	if ((x = sdata()) == -2) {	/* File accepted, send data */	    return(success = 0);	/* Failed */	} else if (x == -1) {		/* EOF */	    clsif();			/* If not ok, close input file, */	    window(1);			/* put window size back to 1, */	    seof((CHAR *)"");		/* send EOF packet, */	    BEGIN sseof;		/* and switch to EOF state. */	} else BEGIN ssdata;		/* All ok, switch to send-data state */    }}    break;case 56:    {				/* Got ACK to Data packet */    canned(rdatap);			/* Check if file transfer cancelled */    if ((x = sdata()) == -2) {		/* Try to send next data */	return(success = 0);		/* Failed */    } else if (x == -1) {		/* EOF - finished sending data */	clsif();			/* Close file */	window(1);			/* Set window size back to 1... */	if (cxseen || czseen)		/* If interrupted */	  seof((CHAR *)"D");		/* send special EOF packet */	else				/* otherwise */	  seof((CHAR *)"");		/* regular EOF packet */	BEGIN sseof;			/* and enter send-eof state */    }}    break;case 57:    {				/* Got ACK to EOF */    success = (cxseen == 0 && czseen == 0); /* Transfer status... */    if (success && rejection > 0)	    /* If rejected, succeed if */      if (rejection != '#' &&		    /* reason was date */	  rejection != 1 && rejection != '?') /* or name; */	success = 0;			    /* fail otherwise. */    cxseen = 0;				/* This goes back to zero. */    if (success && moving) {		/* If MOVE'ing */	tlog(F110," deleting",filnam,0); /* delete the file */	zdelet(filnam);    }    if (gnfile() > 0) {			/* Any more files to send? */	if (sfile(xflg))		/* Yes, try to send next file header */	  BEGIN ssfile;			/* if ok, enter send-file state */	else {				/* otherwise */	    errpkt((CHAR *)"Can't open file");	/* send error message */

⌨️ 快捷键说明

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