home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ck9196.zip / ckcpro.w < prev    next >
Text File  |  2000-01-03  |  99KB  |  3,291 lines

  1. char *protv =                                                     /* -*-C-*- */
  2. "C-Kermit Protocol Module 7.0.135, 1 Jan 2000";
  3.  
  4. int kactive = 0;            /* Kermit protocol is active */
  5.  
  6. #define PKTZEROHACK
  7.  
  8. /* C K C P R O  -- C-Kermit Protocol Module, in Wart preprocessor notation. */
  9. /*
  10.   Author: Frank da Cruz <fdc@columbia.edu>,
  11.   Columbia University Academic Information Systems, New York City.
  12.  
  13.   Copyright (C) 1985, 2000,
  14.     Trustees of Columbia University in the City of New York.
  15.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  16.     copyright text in the ckcmai.c module for disclaimer and permissions.
  17. */
  18. #ifndef NOXFER
  19. #include "ckcsym.h"
  20. #include "ckcdeb.h"
  21. #include "ckcasc.h"
  22. #include "ckcker.h"
  23. #ifdef OS2
  24. #ifndef NT
  25. #define INCL_NOPM
  26. #define INCL_VIO            /* Needed for ckocon.h */
  27. #include <os2.h>
  28. #undef COMMENT
  29. #endif /* NT */
  30. #include "ckocon.h"
  31. #endif /* OS2 */
  32.  
  33. /*
  34.  Note -- This file may also be preprocessed by the UNIX Lex program, but
  35.  you must indent the above #include statements before using Lex, and then
  36.  restore them to the left margin in the resulting C program before compilation.
  37.  Also, the invocation of the "wart()" function below must be replaced by an
  38.  invocation  of the "yylex()" function.  It might also be necessary to remove
  39.  comments in the (%)(%)...(%)(%) section.
  40. */
  41.  
  42. /* State definitions for Wart (or Lex) */
  43. %states ipkt rfile rattr rdpkt ssinit ssfile ssattr ssdata sseof sseot
  44. %states serve generic get rgen ssopkt ropkt
  45.  
  46. _PROTOTYP(static VOID xxproto,(void));
  47. _PROTOTYP(int wart,(void));
  48. _PROTOTYP(static int sgetinit,(int,int));
  49. _PROTOTYP(int sndspace,(int));
  50.  
  51. /* External C-Kermit variable declarations */
  52.   extern char *versio, *srvtxt, *cmarg, *cmarg2, **cmlist, *rf_err;
  53.   extern char *cdmsgfile[];
  54.   extern char * snd_move, * snd_rename, * srimsg;
  55.   extern char filnam[], fspec[], ttname[], ofn1[];
  56.   extern CHAR sstate, *srvptr, *data;
  57.   extern int timint, rtimo, nfils, hcflg, xflg, flow, mdmtyp, network;
  58.   extern int oopts, omode, oname, opath, nopush, isguest;
  59.   extern int rejection, moving, fncact, bye_active, urserver, fatalio;
  60.   extern int protocol, prefixing, filcnt, carrier, fnspath, interrupted;
  61.   extern int recursive, inserver, nzxopts, idletmo, srvidl, xfrint;
  62.   extern struct ck_p ptab[];
  63.   extern int remfile, rempipe, xferstat, filestatus, wearealike, fackpath;
  64.   extern char * remdest;
  65.  
  66. #ifdef PKTZEROHACK
  67. #define PKTZEROLEN 32
  68. static char ipktack[PKTZEROLEN];
  69. static int ipktlen = 0;
  70. #endif /* PKTZEROHACK */
  71.  
  72. static int s_timint = -1;        /* For saving timeout value */
  73. static int havefs = 0;
  74. #ifdef CK_LOGIN
  75. static int logtries = 0;
  76. #endif /* CK_LOGIN */
  77.  
  78. #ifdef STREAMING
  79. extern int streaming, streamok;
  80. static int cancel = 0;
  81.  
  82. int fackbug = 0;
  83.  
  84. static VOID
  85. streamon() {
  86.     if (streamok) {
  87.     debug(F100,"streamon","",0);
  88.     streaming = 1;
  89.     timint = 0;            /* No timeouts while streaming. */
  90.     }
  91. }
  92.  
  93. #ifdef COMMENT                /* (not used) */
  94. static VOID
  95. streamoff() {
  96.     if (streaming) {
  97.     debug(F100,"streamoff","",0);
  98.     streaming = 0;
  99.     timint = s_timint;        /* Restore timeout */
  100.     }
  101. }
  102. #endif /* COMMENT */
  103. #else /* STREAMING */
  104. #define streamon()
  105. #define streamoff()
  106. #endif /* STREAMING */
  107.  
  108. #ifndef NOSPL
  109. _PROTOTYP( int addmac, (char *, char *) );
  110. _PROTOTYP( int zzstring, (char *, char **, int *) );
  111. #endif /* NOSPL */
  112. #ifndef NOICP
  113. _PROTOTYP( int cmdsrc, (void) );
  114. #endif /* NOICP */
  115.  
  116. #ifndef NOSERVER
  117.   extern char * x_user, * x_passwd, * x_acct;
  118.   extern int x_login, x_logged;
  119. #endif /* NOSERVER */
  120.  
  121. #ifdef CK_SPEED
  122.   extern int ttnproto;            /* Network protocol */
  123.   extern short ctlp[];            /* Control-character prefix table */
  124. #endif /* CK_SPEED */
  125.  
  126. #include "ckcnet.h"
  127. #ifdef TNCODE
  128.   extern int tn_b_nlm, tn_b_xfer, tn_nlm;
  129. #ifdef CK_ENCRYPTION
  130.   extern int tn_no_encrypt_xfer;
  131. #endif /* CK_ENCRYPTION */
  132. #endif /* TNCODE */
  133.  
  134. #ifdef TCPSOCKET
  135. #ifndef NOLISTEN
  136.   extern int tcpsrfd;
  137. #endif /* NOLISTEN */
  138. #endif /* TCPSOCKET */
  139.  
  140.   extern int cxseen, czseen, server, srvdis, local, displa, bctu, bctr, bctl;
  141.   extern int quiet, tsecs, parity, backgrd, nakstate, atcapu, wslotn, winlo;
  142.   extern int wslots, success, xitsta, rprintf, discard, cdtimo, keep, fdispla;
  143.   extern int timef, stdinf, rscapu, sendmode, epktflg, epktrcvd, epktsent;
  144.   extern int binary, fncnv;
  145.   extern long speed, ffc, crc16, calibrate, dest;
  146. #ifdef COMMENT
  147.   extern char *TYPCMD, *DIRCMD, *DIRCM2;
  148. #endif /* COMMENT */
  149. #ifndef OS2
  150.   extern char *SPACMD, *SPACM2, *WHOCMD;
  151. #endif /* OS2 */
  152.   extern CHAR *rdatap;
  153.   extern struct zattr iattr;
  154.  
  155. #ifdef VMS
  156.   extern int batch;
  157. #endif /* VMS */
  158.  
  159. #ifdef GFTIMER
  160.   extern CKFLOAT fptsecs;
  161. #endif /* GFTIMER */
  162.  
  163.   extern CHAR *srvcmd;
  164.   extern CHAR *epktmsg;
  165.  
  166. #ifdef CK_TMPDIR
  167. extern int f_tmpdir;            /* Directory changed temporarily */
  168. extern char savdir[];            /* For saving current directory */
  169. extern char * dldir;
  170. #endif /* CK_TMPDIR */
  171.  
  172.   extern int query;            /* Query-active flag */
  173. #ifndef NOSPL
  174.   extern int cmdlvl;
  175.   char querybuf[QBUFL+1] = { NUL, NUL }; /* QUERY response buffer */
  176.   char *qbufp = querybuf;        /* Pointer to it */
  177.   int qbufn = 0;            /* Length of data in it */
  178. #else
  179.   extern int tlevel;
  180. #endif /* NOSPL */
  181.  
  182. #ifndef NOICP
  183.   extern int escape;
  184. #endif /* NOICP */
  185. /*
  186.   If the following flag is nonzero when the protocol module is entered,
  187.   then server mode persists for exactly one transaction, rather than
  188.   looping until BYE or FINISH is received.
  189. */
  190. extern int justone;
  191.  
  192. static int r_save = -1;
  193. static int p_save = -1;
  194.  
  195. static VOID
  196. rdebug() {
  197.     if (server)
  198.       debug(F111,"RESUME","server=1",justone);
  199.     else
  200.       debug(F111,"RESUME","server=0",justone);
  201. }
  202.  
  203. /* Flags for the ENABLE and DISABLE commands */
  204. extern int
  205.   en_cpy, en_cwd, en_del, en_dir, en_fin, en_get, en_bye, en_mai, en_pri,
  206.   en_hos, en_ren, en_sen, en_spa, en_set, en_typ, en_who, en_ret, en_xit,
  207.   en_mkd, en_rmd;
  208. #ifndef NOSPL
  209. extern int en_asg, en_que;
  210. #endif /* NOSPL */
  211. extern int what, lastxfer;
  212.  
  213. /* Global variables declared here */
  214.  
  215.   int whatru = 0;            /* What are you. */
  216.   int whatru2 = 0;            /* What are you, cont'd. */
  217.  
  218. /* Local variables */
  219.  
  220.   static char vstate = 0;          /* Saved State   */
  221.   static char vcmd = 0;            /* Saved Command */
  222.   static int reget = 0;            /* Flag for executing REGET */
  223.   static int retrieve = 0;        /* Flag for executing RETRIEVE */
  224.   static int opkt = 0;            /* Send Extended GET packet */
  225.  
  226.   static int x;                /* General-purpose integer */
  227.   static char *s;            /* General-purpose string pointer */
  228.  
  229. /* Macros - Note, BEGIN is predefined by Wart (and Lex) as "state = ", */
  230. /* BEGIN is NOT a GOTO! */
  231. #define TINIT if (tinit(1) < 0) return(-9)
  232. #define SERVE { TINIT; resetc(); nakstate=1; what=W_NOTHING; cmarg2=""; \
  233. sendmode=SM_SEND; havefs=0; recursive=r_save; fnspath=p_save; BEGIN serve; }
  234. #define RESUME { rdebug(); if (!server) { return(0); } else \
  235. if (justone) { justone=0; return(0); } else { SERVE; } }
  236.  
  237. #ifdef GFTIMER
  238. #define QUIT x=quiet; quiet=1; clsif(); clsof(1); tsecs=gtimer(); \
  239.  fptsecs=gftimer(); quiet=x; return(success)
  240. #else
  241. #define QUIT x=quiet; quiet=1; clsif(); clsof(1); tsecs=gtimer(); quiet=x; \
  242.  return(success)
  243. #endif /* GFTIMER */
  244.  
  245. /*
  246.   By late 1999, the big switch() statement generated from the following state
  247.   table began choking even gcc, so here we extract the code from the larger
  248.   states into static void routines to reduce the size of the cases and the
  249.   switch() overall.  The routines follow the state table; the prototypes are
  250.   here.  Each of these routines simply contains the text from the
  251.   corresponding case, but with return(-1) added in appropriate places; see
  252.   instructions after the state table switcher.
  253. */
  254. static int rc;                /* Return code for these routines */
  255. static int rcv_s_pkt();            /* Received an S packet */
  256. static int rcv_firstdata();        /* Received first Data packet */
  257. static int rcv_shortreply();        /* Short reply to a REMOTE command  */
  258. static int srv_query();            /* Server answers an query */
  259. static int srv_copy();            /* Server executes REMOTE COPY */
  260. static int srv_rename();        /* Server executes REMOTE RENAME */
  261. static int srv_login();            /* Server executes REMOTE LOGIN */
  262. static int srv_timeout();        /* Server times out */
  263.  
  264. %%
  265.  
  266. /*
  267.   Protocol entry points, one for each start state (sstate).
  268.   The lowercase letters are internal "inputs" from the user interface.
  269.   NOTE: The start state letters that appear on the left margin immediately
  270.   below can NOT be used as packet types OR as G-packet subcodes.
  271. */
  272.  
  273. s { TINIT;                /* Send file(s) */
  274.     if (sinit() > 0) BEGIN ssinit;
  275.        else RESUME; }
  276.  
  277. v { TINIT; nakstate = 1; BEGIN get; }    /* Receive file(s) */
  278.  
  279. r {                    /* Client sends a GET command */
  280.     TINIT;
  281.     vstate = get;
  282.     reget = 0;
  283.     retrieve = 0;
  284.     opkt = 0;
  285.     vcmd = 0;
  286. #ifdef PKTZEROHACK
  287.     ipktack[0] = NUL;
  288. #endif /* PKTZEROHACK */
  289.     if (sipkt('I') >= 0)
  290.       BEGIN ipkt;
  291.     else
  292.       RESUME;
  293. }
  294.  
  295. h {                    /* Client sends a RETRIEVE command */
  296.     TINIT;
  297.     vstate = get;
  298.     reget = 0;
  299.     retrieve = 1;
  300.     opkt = 0;
  301.     vcmd = 0;
  302.     if (sipkt('I') >= 0)
  303.       BEGIN ipkt;
  304.     else
  305.       RESUME;
  306. }
  307. j {                    /* Client sends a REGET command */
  308.     TINIT;
  309.     vstate = get;
  310.     reget = 1;
  311.     retrieve = 0;
  312.     opkt = 0;
  313.     vcmd = 0;
  314.     if (sipkt('I') >= 0)
  315.       BEGIN ipkt;
  316.     else
  317.       RESUME;
  318. }
  319. o {                    /* Client sends Extended GET Packet */
  320.     TINIT;
  321.     vstate = get;
  322.     reget = oopts & GOPT_RES;
  323.     retrieve = oopts & GOPT_DEL;
  324.     opkt = 1;
  325.     vcmd = 0;
  326.     if (sipkt('I') >= 0)
  327.       BEGIN ipkt;
  328.     else
  329.       RESUME;
  330. }
  331. c {                    /* Client sends a Host command */
  332.     TINIT;
  333.     vstate = rgen;
  334.     vcmd = 'C';
  335.     if (sipkt('I') >= 0)
  336.       BEGIN ipkt;
  337.     else
  338.       RESUME;
  339. }
  340. k { TINIT;                /* Client sends a Kermit command */
  341.     vstate = rgen;
  342.     vcmd = 'K';
  343.     if (sipkt('I') >= 0)
  344.       BEGIN ipkt;
  345.     else
  346.       RESUME;
  347. }
  348. g {                    /* Client sends a REMOTE command */
  349.     TINIT;
  350.     vstate = rgen;
  351.     vcmd = 'G';
  352.     if (sipkt('I') >= 0)
  353.       BEGIN ipkt;
  354.     else
  355.       RESUME;
  356. }
  357. x {                    /* Enter server mode */
  358.     int x;
  359.     x = justone;
  360.     if (!ENABLED(en_del)) {        /* If DELETE is disabled */
  361.     if (fncact == XYFX_B ||        /* undo any file collision action */
  362.         fncact == XYFX_U ||        /* that could result in deletion or */
  363.         fncact == XYFX_A ||        /* modification of existing files. */
  364.         fncact == XYFX_X) {
  365. #ifndef NOICP
  366.         extern int g_fncact;
  367.         g_fncact = fncact;        /* Save current setting */
  368. #endif /* NOICP */
  369.         fncact = XYFX_R;        /* Change to RENAME */
  370.         debug(F101,"server DELETE disabled so fncact RENAME","",fncact);
  371.     }
  372.     }
  373.     SERVE;                /* tinit() clears justone... */
  374.     justone = x;
  375. #ifdef IKSDB
  376.     if (ikdbopen) slotstate(what, "SERVER", "", "");
  377. #endif /* IKSDB */
  378. }
  379.  
  380. a {
  381.     int b1 = 0, b2 = 0;
  382.     if (!data) TINIT;            /* "ABEND" -- Tell other side. */
  383. #ifndef pdp11
  384.     if (epktflg) {            /* If because of E-PACKET command */
  385.     b1 = bctl; b2 = bctu;        /* Save block check type */
  386.     bctl = bctu = 1;        /* set it to 1 */
  387.     }
  388. #endif /* pdp11 */
  389.     errpkt((CHAR *)"User cancelled");    /* Send the packet */
  390. #ifndef pdp11
  391.     if (epktflg) {            /* Restore the block check */
  392.     epktflg = 0;
  393.     bctl = b1; bctu = b2;
  394.     }
  395. #endif /* pdp11 */
  396.     success = 0;
  397.     return(0);                /* Return from protocol. */
  398. }
  399.  
  400. /*
  401.   Dynamic states: <current-states>input-character { action }
  402.   nakstate != 0 means we're in a receiving state, in which we send ACKs & NAKs.
  403. */
  404.  
  405. <rgen,get,serve,ropkt>S {        /* Receive Send-Init packet. */
  406.     rc = rcv_s_pkt();
  407.     debug(F101,"rcv_s_pkt","",rc);
  408.     if (rc > -1) return(rc);        /* (see below) */
  409. }
  410.  
  411. /* States in which we get replies back from commands sent to a server. */
  412. /* Complicated because direction of protocol changes, packet number    */
  413. /* stays at zero through I-G-S sequence, and complicated even more by  */
  414. /* sliding windows buffer allocation. */
  415.  
  416. <ipkt>Y {                /* Get ack for I-packet */
  417.     int x = 0;
  418. #ifdef PKTZEROHACK
  419.     ckstrncpy(ipktack,(char *)rdatap,PKTZEROLEN); /* Save a copy of the ACK */
  420.     ipktlen = strlen(ipktack);
  421. #endif /* PKTZEROHACK */
  422.     spar(rdatap);            /* Set parameters */
  423.     winlo = 0;                /* Set window-low back to zero */
  424.     debug(F101,"<ipkt>Y winlo","",winlo);
  425.     urserver = 1;            /* So I know I'm talking to a server */
  426.     if (vcmd) {                /* If sending a generic command */
  427.     if (tinit(0) < 0) return(-9);    /* Initialize many things */
  428.     x = scmd(vcmd,(CHAR *)cmarg);    /* Do that */
  429.     if (x >= 0) x = 0;        /* (because of O-Packet) */
  430.     debug(F101,"proto G packet scmd","",x);
  431.     vcmd = 0;            /* and then un-remember it. */
  432.     } else if (vstate == get) {
  433.     debug(F101,"REGET sstate","",sstate);
  434.     x = srinit(reget, retrieve, opkt); /* GET or REGET, etc */
  435.     }
  436.     if (x < 0) {            /* If command was too long */
  437.     if (!srimsg)
  438.       srimsg = "Error sending string";
  439.     errpkt((CHAR *)srimsg);        /* cancel both sides. */
  440.     success = 0;
  441.     RESUME;
  442.     } else if (x > 0) {            /* Need to send more O-Packets */
  443.     BEGIN ssopkt;
  444.     } else {
  445.     rtimer();            /* Reset the elapsed seconds timer. */
  446. #ifdef GFTIMER
  447.     rftimer();
  448. #endif /* GFTIMER */
  449.     winlo = 0;            /* Window back to 0, again. */
  450.     debug(F101,"<ipkt>Y vstate","",vstate);
  451.     nakstate = 1;            /* Can send NAKs from here. */
  452.     BEGIN vstate;            /* Switch to desired state */
  453.     }
  454. }
  455.  
  456. <ssopkt>Y {                /* Got ACK to O-Packet */
  457.     debug(F100,"CPCPRO <ssopkt>Y","",0);
  458.     x = sopkt();
  459.     debug(F101,"CPCPRO <ssopkt>Y x","",x);
  460.     if (x < 0) {            /* If error */
  461.     errpkt((CHAR *)srimsg);        /* cancel both sides. */
  462.     success = 0;
  463.     RESUME;
  464.     } else if (x == 0) {        /* This was the last O-Packet */
  465.     rtimer();            /* Reset the elapsed seconds timer. */
  466. #ifdef GFTIMER
  467.     rftimer();
  468. #endif /* GFTIMER */
  469.     winlo = 0;            /* Window back to 0, again. */
  470.     debug(F101,"<ssopkt>Y winlo","",winlo);
  471.     nakstate = 1;            /* Can send NAKs from here. */
  472.     BEGIN vstate;            /* Switch to desired state */
  473.     }
  474.     debug(F101,"CPCPRO <ssopkt>Y not changing state","",x);
  475. }
  476.  
  477. <ipkt>E {                /* Ignore Error reply to I packet */
  478.     int x = 0;
  479.     winlo = 0;                /* Set window-low back to zero */
  480.     debug(F101,"<ipkt>E winlo","",winlo);
  481.     if (vcmd) {                /* In case other Kermit doesn't */
  482.     if (tinit(0) < 0) return(-9);
  483.     x = scmd(vcmd,(CHAR *)cmarg);    /* understand I-packets. */
  484.     if (x >= 0) x = 0;        /* (because of O-Packet) */
  485.     vcmd = 0;            /* Otherwise act as above... */
  486.     } else if (vstate == get) x = srinit(reget, retrieve, opkt);
  487.     if (x < 0) {            /* If command was too long */
  488.     errpkt((CHAR *)srimsg);        /* cancel both sides. */
  489.     success = 0;
  490.     RESUME;
  491.     } else if (x > 0) {            /* Need to send more O-Packets */
  492.     BEGIN ssopkt;
  493.     } else {
  494.     winlo = 0;            /* Back to packet 0 again. */
  495.     debug(F101,"<ipkt>E winlo","",winlo);
  496.     freerpkt(winlo);        /* Discard the Error packet. */
  497.     nakstate = 1;            /* Can send NAKs from here. */
  498.     BEGIN vstate;
  499.     }
  500. }
  501.  
  502. <get>Y {        /* Resend of previous I-pkt ACK, same seq number! */
  503.     srinit(reget, retrieve, opkt);    /* Send the GET packet again. */
  504. }
  505.  
  506. /* States in which we're being a server */
  507.  
  508. <serve,get>I {                /* Get I-packet */
  509. #ifndef NOSERVER
  510.     spar(rdatap);            /* Set parameters from it */
  511.     ack1(rpar());            /* Respond with our own parameters */
  512. #ifdef COMMENT
  513.     pktinit();                /* Reinitialize packet numbers */
  514. #else
  515. #ifdef COMMENT
  516.     /* This can't be right - it undoes the stuff we just negotiated */
  517.     x = justone;
  518.     tinit(1);                /* Reinitialize EVERYTHING */
  519.     justone = x;            /* But this... */
  520. #else
  521.     tinit(0);                /* Initialize most things */
  522. #endif /* COMMENT */
  523. #endif /* COMMENT */
  524. #endif /* NOSERVER */
  525. }
  526.  
  527. <serve>R {                /* GET */
  528. #ifndef NOSERVER
  529.     if (x_login && !x_logged) {
  530.     errpkt((CHAR *)"Login required");
  531.     SERVE;
  532.     } else if (sgetinit(0,0) < 0) {
  533.     RESUME;
  534.     } else {
  535. #ifdef CKSYSLOG
  536.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  537.       cksyslog(SYSLG_PR, 1, "server", "GET", (char *)srvcmd);
  538. #endif /* CKSYSLOG */
  539.     BEGIN ssinit;
  540.     }
  541. #endif /* NOSERVER */
  542. }
  543.  
  544. <serve>H {                /* GET /DELETE (RETRIEVE) */
  545. #ifndef NOSERVER
  546.     if (x_login && !x_logged) {
  547.     errpkt((CHAR *)"Login required");
  548.     RESUME;
  549.     } else if (!ENABLED(en_del)) {
  550.     errpkt((CHAR *)"Deleting files is disabled");
  551.     RESUME;
  552.     } else if (sgetinit(0,0) < 0) {
  553.     RESUME;
  554.     } else {
  555.     moving = 1;
  556. #ifdef CKSYSLOG
  557.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  558.       cksyslog(SYSLG_PR, 1, "server", "GET /DELETE", (char *)srvcmd);
  559. #endif /* CKSYSLOG */
  560.     BEGIN ssinit;
  561.     }
  562. #endif /* NOSERVER */
  563. }
  564.  
  565. <serve>V {                /* GET /RECURSIVE */
  566. #ifndef NOSERVER
  567.     recursive = 1;            /* Set these before sgetinit() */
  568.     if (fnspath == PATH_OFF)
  569.       fnspath = PATH_REL;        /* Don't worry, they will be */
  570.     if (x_login && !x_logged) {        /* reset next time through. */
  571.     errpkt((CHAR *)"Login required");
  572.     RESUME;
  573.     } else if (sgetinit(0,0) < 0) {
  574.     RESUME;
  575.     } else {
  576. #ifdef CKSYSLOG
  577.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  578.       cksyslog(SYSLG_PR, 1, "server", "GET /RECURSIVE", (char *)srvcmd);
  579. #endif /* CKSYSLOG */
  580.     BEGIN ssinit;
  581.     }
  582. #endif /* NOSERVER */
  583. }
  584.  
  585. <serve>W {                /* GET /RECURSIVE /DELETE */
  586. #ifndef NOSERVER
  587.     recursive = 1;            /* Set these before sgetinit() */
  588.     if (fnspath == PATH_OFF)
  589.       fnspath = PATH_REL;        /* Don't worry, they will be */
  590.     moving = 1;                /* reset next time through. */
  591.     if (x_login && !x_logged) {
  592.     errpkt((CHAR *)"Login required");
  593.     RESUME;
  594.     } else if (!ENABLED(en_del)) {
  595.     errpkt((CHAR *)"Deleting files is disabled");
  596.     RESUME;
  597.     } else if (sgetinit(0,0) < 0) {
  598.     RESUME;
  599.     } else {
  600. #ifdef CKSYSLOG
  601.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  602.       cksyslog(SYSLG_PR,1,"server",
  603.            "GET /RECURSIVE /DELETE",(char *)srvcmd);
  604. #endif /* CKSYSLOG */
  605.     BEGIN ssinit;
  606.     }
  607. #endif /* NOSERVER */
  608. }
  609.  
  610. <serve>J {                /* GET /RECOVER (REGET) */
  611. #ifndef NOSERVER
  612.     if (x_login && !x_logged) {
  613.     errpkt((CHAR *)"Login required");
  614.     SERVE;
  615.     } else if (sgetinit(1,0) < 0) {
  616.     RESUME;
  617.     } else {
  618. #ifdef CKSYSLOG
  619.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  620.       cksyslog(SYSLG_PR, 1, "server", "GET /RECOVER", (char *)srvcmd);
  621. #endif /* CKSYSLOG */
  622.     BEGIN ssinit;
  623.     }
  624. #endif /* NOSERVER */
  625. }
  626.  
  627. <serve>O {                /* Extended GET */
  628. #ifndef NOSERVER
  629.     if (x_login && !x_logged) {        /* (any combination of options) */
  630.     errpkt((CHAR *)"Login required");
  631.     SERVE;
  632.     } else if ((x = sgetinit(0,1)) < 0) {
  633.     debug(F101,"CKCPRO <serve>O sgetinit fail","",x);
  634.     RESUME;
  635.     } else if (x == 0) {
  636.     debug(F101,"CKCPRO <serve>O sgetinit done","",x);
  637. #ifdef CKSYSLOG
  638.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  639.       cksyslog(SYSLG_PR, 1, "server", "EXTENDED GET", (char *)srvcmd);
  640. #endif /* CKSYSLOG */
  641.     BEGIN ssinit;
  642.     } else {                /* Otherwise stay in this state */
  643.     debug(F101,"CKCPRO <serve>O sgetinit TBC","",x);
  644.     ack();
  645.     BEGIN ropkt;
  646.     }
  647. #endif /* NOSERVER */
  648. }
  649.  
  650. <ropkt>O {
  651. #ifndef NOSERVER
  652.     if (x_login && !x_logged) {        /* (any combination of options) */
  653.     errpkt((CHAR *)"Login required");
  654.     SERVE;
  655.     } else if ((x = sgetinit(0,1)) < 0) {
  656.     debug(F101,"CKCPRO <ropkt>O sgetinit fail","",x);
  657.     RESUME;
  658.     } else if (x == 0) {
  659.     debug(F101,"CKCPRO <ropkt>O sgetinit done","",x);
  660. #ifdef CKSYSLOG
  661.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  662.       cksyslog(SYSLG_PR, 1, "server", "EXTENDED GET", (char *)srvcmd);
  663. #endif /* CKSYSLOG */
  664.     BEGIN ssinit;
  665.     } else {                /* Otherwise stay in this state */
  666.     debug(F101,"CKCPRO <ropkt>O sgetinit TBC","",x);
  667.     ack();
  668.     }
  669. #endif /* NOSERVER */
  670. }
  671.  
  672. <serve>G {                /* Generic server command */
  673. #ifndef NOSERVER
  674.     srvptr = srvcmd;            /* Point to command buffer */
  675.     decode(rdatap,putsrv,0);        /* Decode packet data into it */
  676.     putsrv(NUL);            /* Insert a couple nulls */
  677.     putsrv(NUL);            /* for termination */
  678.     if (srvcmd[0]) {
  679.     sstate = srvcmd[0];        /* Set requested start state */
  680.     if (x_login && !x_logged &&    /* Login required? */
  681.         /* Login, Logout, and Help are allowed when not logged in */
  682.         sstate != 'I' && sstate != 'L' && sstate != 'H') {
  683.         errpkt((CHAR *)"Login required");
  684.         SERVE;
  685.     } else {
  686.         nakstate = 0;        /* Now I'm the sender. */
  687.         what = W_REMO;        /* Doing a REMOTE command. */
  688. #ifdef STREAMING
  689.         if (!streaming)
  690. #endif /* STREAMING */
  691.           if (timint < 1)
  692.         timint = chktimo(rtimo,timef); /* Switch to per-packet timer */
  693.         binary = XYFT_T;        /* Switch to text mode */
  694.         BEGIN generic;        /* Switch to generic command state */
  695.     }
  696.     } else {
  697.     errpkt((CHAR *)"Badly formed server command"); /* report error */
  698.     RESUME;            /* & go back to server command wait */
  699.     }
  700. #endif /* NOSERVER */
  701. }
  702.  
  703. <serve>C {                /* Receive Host command */
  704. #ifndef NOSERVER
  705.     if (x_login && !x_logged) {
  706.     errpkt((CHAR *)"Login required");
  707.     SERVE;
  708.     } else if (!ENABLED(en_hos)) {
  709.     errpkt((CHAR *)"REMOTE HOST disabled");
  710.     RESUME;
  711.     } else if (nopush) {
  712.     errpkt((CHAR *)"HOST commands not available");
  713.     RESUME;
  714.     } else {
  715.     srvptr = srvcmd;        /* Point to command buffer */
  716.     decode(rdatap,putsrv,0);    /* Decode command packet into it */
  717.     putsrv(NUL);            /* Null-terminate */
  718.     nakstate = 0;            /* Now sending, not receiving */
  719.     binary = XYFT_T;        /* Switch to text mode */
  720.     if (syscmd((char *)srvcmd,"")) { /* Try to execute the command */
  721.         what = W_REMO;        /* Doing a REMOTE command. */
  722. #ifdef STREAMING
  723.         if (!streaming)
  724. #endif /* STREAMING */
  725.           if (timint < 1)
  726.         timint = chktimo(rtimo,timef); /* Switch to per-packet timer */
  727. #ifdef CKSYSLOG
  728.         if (ckxsyslog >= SYSLG_PR && ckxlogging)
  729.           cksyslog(SYSLG_PR, 1, "server", "REMOTE HOST", (char *)srvcmd);
  730. #endif /* CKSYSLOG */
  731.         BEGIN ssinit;        /* If OK, send back its output */
  732.     } else {            /* Otherwise */
  733.         errpkt((CHAR *)"Can't do system command"); /* report error */
  734.         RESUME;            /* & go back to server command wait */
  735.     }
  736.     }
  737. #endif /* NOSERVER */
  738. }
  739.  
  740. <serve>q {                /* Interrupted or connection lost */
  741.     rc = srv_timeout();
  742.     debug(F101,"srv_timeout","",rc);
  743.     if (rc > -1) return(rc);        /* (see below) */
  744. }
  745.  
  746. <serve>N {                /* Server got a NAK in command-wait */
  747. #ifndef NOSERVER
  748.     errpkt((CHAR *)"Did you say RECEIVE instead of GET?");
  749.     RESUME;
  750. #endif /* NOSERVER */
  751. }
  752.  
  753. <serve>. {                /* Any other command in this state */
  754. #ifndef NOSERVER
  755.     if (c != ('E' - SP) && c != ('Y' - SP)) /* except E and Y packets. */
  756.       errpkt((CHAR *)"Unimplemented server function");
  757.     /* If we answer an E with an E, we get an infinite loop. */
  758.     /* A Y (ACK) can show up here if we sent back a short-form reply to */
  759.     /* a G packet and it was echoed.  ACKs can be safely ignored here. */
  760.     RESUME;                /* Go back to server command wait. */
  761. #endif /* NOSERVER */
  762. }
  763.  
  764. <generic>I {                /* Login/Out */
  765.     rc = srv_login();
  766.     debug(F101,"<generic>I srv_login","",rc);
  767.     if (rc > -1) return(rc);        /* (see below) */
  768. }
  769.  
  770. <generic>C {                /* Got REMOTE CD command */
  771. #ifndef NOSERVER
  772. #ifdef CKSYSLOG
  773.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  774.       cksyslog(SYSLG_PR, 1, "server", "REMOTE CD", (char *)srvcmd);
  775. #endif /* CKSYSLOG */
  776.     if (!ENABLED(en_cwd)) {
  777.     errpkt((CHAR *)"REMOTE CD disabled");
  778.     RESUME;
  779.     } else {
  780.     char * p = NULL;
  781.     x = cwd((char *)(srvcmd+1));    /* Try to change directory */
  782. #ifdef IKSDB
  783.     if (ikdbopen) slotstate(what,"REMOTE CD", (char *)(srvcmd+2), "");
  784. #endif /* IKSDB */
  785.     if (!x) {            /* Failed */
  786.         errpkt((CHAR *)"Can't change directory");
  787.         RESUME;            /* Back to server command wait */
  788.     } else if (x == 2) {        /* User wants message */
  789.         if (!ENABLED(en_typ)) {    /* Messages (REMOTE TYPE) disabled? */
  790.         errpkt((CHAR *)"REMOTE TYPE disabled");
  791.         RESUME;
  792.         } else {            /* TYPE is enabled */
  793.         int i;
  794.         for (i = 0; i < 8; i++) {
  795.             if (zchki(cdmsgfile[i]) > -1) {
  796.             break;
  797.             }
  798.         }
  799.         binary = XYFT_T;    /* Use text mode for this. */
  800.         if (i < 8 && sndtype(cdmsgfile[i])) { /* Have readme file? */
  801.             BEGIN ssinit;    /* OK */
  802.         } else {        /* not OK */
  803.             p = zgtdir();
  804.             if (!p) p = "";
  805.             success = (*p) ? 1 : 0;
  806.             ack1((CHAR *)p);    /* ACK with new directory name */
  807.             success = 1;
  808.             RESUME;        /* wait for next server command */
  809.         }
  810.         }
  811.     } else {            /* User doesn't want message */
  812.         p =zgtdir();
  813.         if (!p) p = "";
  814.         success = (*p) ? 1 : 0;
  815.         ack1((CHAR *)p);
  816.         success = 1;
  817.         RESUME;            /* Wait for next server command */
  818.     }
  819.     }
  820. #endif /* NOSERVER */
  821. }
  822.  
  823. <generic>A {                /* Got REMOTE PWD command */
  824. #ifndef NOSERVER
  825. #ifdef CKSYSLOG
  826.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  827.       cksyslog(SYSLG_PR, 1, "server", "REMOTE PWD", NULL);
  828. #endif /* CKSYSLOG */
  829.     if (!ENABLED(en_cwd)) {
  830.     errpkt((CHAR *)"REMOTE CD disabled");
  831.     RESUME;
  832.     } else {
  833.     if (encstr((CHAR *)zgtdir()) > -1) { /* Encode current directory */
  834.         ack1(data);            /* If it fits, send it back in ACK */
  835.         success = 1;
  836.     } else {            /* Failed */
  837.         ack();            /* Send empty ACK */
  838.         success = 0;        /* and indicate failure locally */
  839.     }
  840.     RESUME;                /* Back to server command wait */
  841.     }
  842. #endif /* NOSERVER */
  843. }
  844.  
  845. <generic>D {                /* REMOTE DIRECTORY command */
  846. #ifndef NOSERVER
  847.     char *n2;
  848. #ifdef CKSYSLOG
  849.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  850.       cksyslog(SYSLG_PR, 1, "server", "REMOTE DIRECTORY", (char *)srvcmd);
  851. #endif /* CKSYSLOG */
  852.     if (!ENABLED(en_dir)) {        /* If DIR is disabled, */
  853.     errpkt((CHAR *)"REMOTE DIRECTORY disabled"); /* refuse. */
  854.     RESUME;
  855.     } else {                /* DIR is enabled. */
  856. #ifdef IKSDB
  857.     if (ikdbopen) slotstate(what,"REMOTE DIR", (char *)(srvcmd+2), "");
  858. #endif /* IKSDB */
  859.     if (!ENABLED(en_cwd)) {        /* But CWD is disabled */
  860.         zstrip((char *)(srvcmd+2),&n2); /* and they included a pathname, */
  861.         if (strcmp((char *)(srvcmd+2),n2)) { /* so refuse. */
  862.         errpkt((CHAR *)"Access denied");
  863.         RESUME;            /* Remember, this is not a goto! */
  864.         }
  865.     }
  866.     if (state == generic) {            /* It's OK to go ahead. */
  867. #ifdef COMMENT
  868.         n2 = (*(srvcmd+2)) ? DIRCMD : DIRCM2;
  869.         if (syscmd(n2,(char *)(srvcmd+2)))  /* If it can be done */
  870. #else
  871.         int x;
  872.         if ((x = snddir((char*)(srvcmd+2))) > 0)
  873. #endif /* COMMENT */
  874.         {
  875.         BEGIN ssinit;        /* send the results back; */
  876.         } else {            /* otherwise */
  877.         if (x < 0)
  878.           errpkt((CHAR *)"No files match");
  879.         else
  880.           errpkt((CHAR *)"Can't list directory");
  881.         RESUME;            /* return to server command wait */
  882.         }
  883.     }
  884.     }
  885. #endif /* NOSERVER */
  886. }
  887.  
  888. <generic>E {                /* REMOTE DELETE (Erase) */
  889. #ifndef NOSERVER
  890.     char *n2;
  891. #ifdef CKSYSLOG
  892.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  893.       cksyslog(SYSLG_PR, 1, "server", "REMOTE DELETE", (char *)srvcmd);
  894. #endif /* CKSYSLOG */
  895.     if (!ENABLED(en_del)) {
  896.     errpkt((CHAR *)"REMOTE DELETE disabled");
  897.     RESUME;
  898.     } else {                /* DELETE is enabled */
  899. #ifdef IKSDB
  900.     if (ikdbopen) slotstate(what,"REMOTE DELETE", (char *)(srvcmd+2), "");
  901. #endif /* IKSDB */
  902.     if (!ENABLED(en_cwd)) {        /* but CWD is disabled */
  903.         zstrip((char *)(srvcmd+2),&n2); /* and they included a pathname, */
  904.         if (strcmp((char *)(srvcmd+2),n2)) { /* so refuse. */
  905.         errpkt((CHAR *)"Access denied");
  906.         RESUME;            /* Remember, this is not a goto! */
  907.         }
  908.     } else if (isdir((char *)(srvcmd+2))) { /* A directory name? */
  909.         errpkt((CHAR *)"It's a directory");
  910.         RESUME;
  911.     }
  912.     if (state == generic) {        /* It's OK to go ahead. */
  913.         int x;
  914.         if ((x = snddel((char*)(srvcmd+2))) > 0) {
  915.         BEGIN ssinit;        /* If OK send results back */
  916.         } else {            /* otherwise */
  917.         if (x < 0)
  918.           errpkt((CHAR *)"File not found"); /* report failure */
  919.         else
  920.           errpkt((CHAR *)"DELETE failed");
  921.         RESUME;            /* & return to server command wait */
  922.         }
  923.     }
  924.     }
  925. #endif /* NOSERVER */
  926. }
  927.  
  928. <generic>F {                /* FINISH */
  929. #ifndef NOSERVER
  930. #ifdef CKSYSLOG
  931.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  932.       cksyslog(SYSLG_PR, 1, "server", "FINISH", NULL);
  933. #endif /* CKSYSLOG */
  934. #ifdef IKSDB
  935.     if (ikdbopen) slotstate(what,"SERVER FINISH", "", "");
  936. #endif /* IKSDB */
  937.     if (!ENABLED(en_fin)) {
  938.     errpkt((CHAR *)"FINISH disabled");
  939.     RESUME;
  940.     } else {
  941.     ack();                /* Acknowledge */
  942.     xxscreen(SCR_TC,0,0L,"");    /* Display */
  943.     success = 1;
  944.     return(0);            /* Done */
  945.     }
  946. #endif /* NOSERVER */
  947. }
  948.  
  949. <generic>X {                /* EXIT */
  950. #ifndef NOSERVER
  951. #ifdef CKSYSLOG
  952.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  953.       cksyslog(SYSLG_PR, 1, "server", "REMOTE EXIT", NULL);
  954. #endif /* CKSYSLOG */
  955. #ifdef IKSDB
  956.     if (ikdbopen) slotstate(what,"REMOTE EXIT", "", "");
  957. #endif /* IKSDB */
  958.     if (!ENABLED(en_xit)) {
  959.     errpkt((CHAR *)"EXIT disabled");
  960.     RESUME;
  961.     } else {
  962.     ack();                /* Acknowledge */
  963.     xxscreen(SCR_TC,0,0L,"");    /* Display */
  964.     doexit(GOOD_EXIT,xitsta);
  965.     }
  966. #endif /* NOSERVER */
  967. }
  968.  
  969. <generic>L {                /* BYE (Logout) */
  970. #ifndef NOSERVER
  971. #ifdef CKSYSLOG
  972.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  973.       cksyslog(SYSLG_PR, 1, "server", "BYE", NULL);
  974. #endif /* CKSYSLOG */
  975. #ifdef IKSDB
  976.     if (ikdbopen) slotstate(what,"SERVER BYE", "", "");
  977. #endif /* IKSDB */
  978.     if (!ENABLED(en_bye)) {
  979.     errpkt((CHAR *)"BYE disabled");
  980.     RESUME;
  981.     } else {
  982.     ack();                /* Acknowledge */
  983.     success = 1;
  984.     msleep(750);            /* Give the ACK time to get out */
  985.     if (local)
  986.       ttres();            /* Reset the terminal */
  987.     xxscreen(SCR_TC,0,0L,"");    /* Display */
  988.     doclean(1);            /* Clean up files, etc */
  989. #ifdef DEBUG
  990.     debug(F100,"C-Kermit BYE - Loggin out...","",0);
  991.     zclose(ZDFILE);
  992. #endif /* DEBUG */
  993. #ifdef IKSD
  994. #ifdef CK_LOGIN
  995.     if (inserver)
  996.       ckxlogout();
  997.     else
  998. #endif /* CK_LOGIN */
  999. #endif /* IKSD */
  1000. #ifdef TCPSOCKET
  1001. #ifndef NOLISTEN
  1002.       if (network && tcpsrfd > 0 && !inserver)
  1003.         doexit(GOOD_EXIT,xitsta);
  1004.     else
  1005. #endif /* NOLISTEN */
  1006. #endif /* TCPSOCKET */
  1007.       return(zkself());        /* Try to log self out */
  1008.     }
  1009. #endif /* NOSERVER */
  1010. }
  1011.  
  1012. <generic>H {                /* REMOTE HELP */
  1013. #ifdef CKSYSLOG
  1014.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1015.       cksyslog(SYSLG_PR, 1, "server", "REMOTE HELP", NULL);
  1016. #endif /* CKSYSLOG */
  1017. #ifdef IKSDB
  1018.     if (ikdbopen) slotstate(what,"REMOTE HELP", "", "");
  1019. #endif /* IKSDB */
  1020. #ifndef NOSERVER
  1021.     if (sndhlp(NULL)) {
  1022.     BEGIN ssinit;            /* try to send it */
  1023.     } else {                /* If not ok, */
  1024.     errpkt((CHAR *)"Can't send help"); /* send error message instead */
  1025.     RESUME;                /* and return to server command wait */
  1026.     }
  1027. #endif /* NOSERVER */
  1028. }
  1029.  
  1030. <generic>R {                            /* REMOTE RENAME */
  1031.     rc = srv_rename();
  1032.     debug(F101,"srv_rename","",rc);
  1033.     if (rc > -1) return(rc);        /* (see below) */
  1034. }
  1035.  
  1036. <generic>K {                            /* REMOTE COPY */
  1037.     rc = srv_copy();
  1038.     debug(F101,"srv_copy","",rc);
  1039.     if (rc > -1) return(rc);        /* (see below) */
  1040. }
  1041.  
  1042. <generic>S {                /* REMOTE SET */
  1043. #ifdef CKSYSLOG
  1044.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1045.       cksyslog(SYSLG_PR, 1, "server", "REMOTE SET", (char *)srvcmd);
  1046. #endif /* CKSYSLOG */
  1047. #ifndef NOSERVER
  1048. #ifdef IKSDB
  1049.     if (ikdbopen) slotstate(what,"REMOTE SET", (char *)(srvcmd+1), "");
  1050. #endif /* IKSDB */
  1051.     if (!ENABLED(en_set)) {
  1052.     errpkt((CHAR *)"REMOTE SET disabled");
  1053.     RESUME;
  1054.     } else {
  1055.     if (remset((char *)(srvcmd+1))) { /* Try to do what they ask */
  1056.         success = 1;
  1057.         ack();            /* If OK, then acknowledge */
  1058.     } else                /* Otherwise */
  1059.       errpkt((CHAR *)"Unknown REMOTE SET parameter"); /* give error msg */
  1060.     RESUME;                /* Return to server command wait */
  1061.     }
  1062. #endif /* NOSERVER */
  1063. }
  1064.  
  1065. <generic>T {                /* REMOTE TYPE */
  1066. #ifndef NOSERVER
  1067.     char *n2;
  1068. #ifdef CKSYSLOG
  1069.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1070.       cksyslog(SYSLG_PR, 1, "server", "REMOTE TYPE", (char *)srvcmd);
  1071. #endif /* CKSYSLOG */
  1072.     if (!ENABLED(en_typ)) {
  1073.     errpkt((CHAR *)"REMOTE TYPE disabled");
  1074.     RESUME;
  1075.     } else {
  1076. #ifdef IKSDB
  1077.     if (ikdbopen) slotstate(what,"REMOTE TYPE", (char *)(srvcmd+2), "");
  1078. #endif /* IKSDB */
  1079.     if (!ENABLED(en_cwd)) {        /* If CWD disabled */
  1080.         zstrip((char *)(srvcmd+2),&n2); /* and they included a pathname, */
  1081.         if (strcmp((char *)(srvcmd+2),n2)) { /* refuse. */
  1082.         errpkt((CHAR *)"Access denied");
  1083.         RESUME;            /* Remember, this is not a goto! */
  1084.         }
  1085.     }
  1086.     if (state == generic) {        /* It's OK to go ahead. */
  1087.         binary = XYFT_T;        /* Use text mode for this. */
  1088.         if (            /* (RESUME didn't change state) */
  1089. #ifdef COMMENT
  1090.           syscmd(TYPCMD,(char *)(srvcmd+2))    /* Old way */
  1091. #else
  1092.           sndtype((char *)(srvcmd+2)) /* New way */
  1093. #endif /* COMMENT */
  1094.         )
  1095.           BEGIN ssinit;        /* OK */
  1096.         else {            /* not OK */
  1097.         errpkt((CHAR *)"Can't type file"); /* give error message */
  1098.         RESUME;            /* wait for next server command */
  1099.         }
  1100.     }
  1101.     }
  1102. #endif /* NOSERVER */
  1103. }
  1104.  
  1105. <generic>m {                /* REMOTE MKDIR */
  1106. #ifndef NOSERVER
  1107. #ifdef CK_MKDIR
  1108. #ifdef CKSYSLOG
  1109.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1110.       cksyslog(SYSLG_PR, 1, "server", "REMOTE MKDIR", (char *)srvcmd);
  1111. #endif /* CKSYSLOG */
  1112. #ifdef IKSDB
  1113.     if (ikdbopen) slotstate(what,"REMOTE MKDIR", (char *)(srvcmd+2), "");
  1114. #endif /* IKSDB */
  1115.     if (!ENABLED(en_mkd)) {
  1116.     errpkt((CHAR *)"REMOTE MKDIR disabled");
  1117.     RESUME;
  1118.     } else if (!ENABLED(en_cwd)) {    /* If CWD disabled */
  1119.     errpkt((CHAR *)"Directory access restricted");
  1120.     RESUME;                /* Remember, this is not a goto! */
  1121.     }
  1122.     if (state == generic) {        /* OK to go ahead. */
  1123.     char *p = NULL;
  1124.     x = ckmkdir(0,(char *)(srvcmd+2),&p,0,1); /* Make the directory */
  1125.     if (!p) p = "";
  1126.     if (x > -1) {
  1127.         encstr((CHAR *)p);        /* OK - encode the name */
  1128.         ack1(data);            /* Send short-form response */
  1129.         success = 1;
  1130.         RESUME;
  1131.     } else {            /* not OK */
  1132.         if (!*p) p = "Directory creation failure";
  1133.         errpkt((CHAR *)p);        /* give error message */
  1134.         RESUME;            /* Wait for next server command */
  1135.     }
  1136.     }
  1137. #else
  1138.     errpkt((CHAR *)"REMOTE MKDIR not available");
  1139.     RESUME;
  1140. #endif /* CK_MKDIR */
  1141. #endif /* NOSERVER */
  1142. }
  1143.  
  1144. <generic>d {                /* REMOTE RMDIR */
  1145. #ifndef NOSERVER
  1146. #ifdef CK_MKDIR
  1147. #ifdef CKSYSLOG
  1148.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1149.       cksyslog(SYSLG_PR, 1, "server", "REMOTE RMDIR", (char *)srvcmd);
  1150. #endif /* CKSYSLOG */
  1151. #ifdef IKSDB
  1152.     if (ikdbopen) slotstate(what,"REMOTE RMDIR", (char *)(srvcmd+2), "");
  1153. #endif /* IKSDB */
  1154.     if (!ENABLED(en_rmd)) {
  1155.     errpkt((CHAR *)"REMOTE RMDIR disabled");
  1156.     RESUME;
  1157.     } else if (!ENABLED(en_cwd)) {    /* If CWD disabled */
  1158.     errpkt((CHAR *)"Directory access restricted");
  1159.     RESUME;                /* Remember, this is not a goto! */
  1160.     }
  1161.     if (state == generic) {        /* OK to go ahead. */
  1162.     char *p = NULL;
  1163.     x = ckmkdir(1,(char *)(srvcmd+2),&p,0,1);
  1164.     if (!p) p = "";
  1165.     if (x > -1) {
  1166.         encstr((CHAR *)p);        /* OK - encode the name */
  1167.         ack1(data);            /* Send short-form response */
  1168.         success = 1;
  1169.         RESUME;
  1170.     } else {            /* not OK */
  1171.         if (!*p) p = "Directory removal failure";
  1172.         errpkt((CHAR *)p);        /* give error message */
  1173.         RESUME;            /* Wait for next server command */
  1174.     }
  1175.     }
  1176. #else
  1177.     errpkt((CHAR *)"REMOTE RMDIR not available");
  1178.     RESUME;
  1179. #endif /* CK_MKDIR */
  1180. #endif /* NOSERVER */
  1181. }
  1182.  
  1183. <generic>U {                /* REMOTE SPACE */
  1184. #ifndef NOSERVER
  1185. #ifdef CKSYSLOG
  1186.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1187.       cksyslog(SYSLG_PR, 1, "server", "REMOTE SPACE", (char *)srvcmd);
  1188. #endif /* CKSYSLOG */
  1189.     if (!ENABLED(en_spa)) {
  1190.     errpkt((CHAR *)"REMOTE SPACE disabled");
  1191.     RESUME;
  1192.     } else {
  1193.     x = srvcmd[1];            /* Get area to check */
  1194.     x = ((x == NUL) || (x == SP)
  1195. #ifdef OS2
  1196.          || (x == '!') || (srvcmd[3] == ':')
  1197. #endif /* OS2 */
  1198.          );
  1199. #ifdef IKSDB
  1200.     if (ikdbopen) slotstate(what,
  1201.                   "REMOTE SPACE",
  1202.                   (x ? "" : (char *)srvcmd),
  1203.                   ""
  1204.                   );
  1205. #endif /* IKSDB */
  1206.     if (!x && !ENABLED(en_cwd)) {    /* CWD disabled */
  1207.         errpkt((CHAR *)"Access denied"); /* and non-default area given, */
  1208.         RESUME;            /* refuse. */
  1209.     } else {
  1210. #ifdef OS2
  1211. _PROTOTYP(int sndspace,(int));
  1212.         if (sndspace(x ? toupper(srvcmd[2]) : 0)) {
  1213.         BEGIN ssinit;        /* send the report. */
  1214.         } else {            /* If not ok, */
  1215.         errpkt((CHAR *)"Can't send space"); /* send error message */
  1216.         RESUME;            /* and return to server command wait */
  1217.         }
  1218. #else
  1219.             if (nopush)
  1220.               x = 0;
  1221.             else
  1222.               x = (x ? syscmd(SPACMD,"") : syscmd(SPACM2,(char *)(srvcmd+2)));
  1223.         if (x) {            /* If we got the info */
  1224.         BEGIN ssinit;        /* send it */
  1225.         } else {            /* otherwise */
  1226.         errpkt((CHAR *)"Can't check space"); /* send error message */
  1227.         RESUME;            /* and await next server command */
  1228.         }
  1229. #endif /* OS2 */
  1230.     }
  1231.     }
  1232. #endif /* NOSERVER */
  1233. }
  1234.  
  1235. <generic>W {                /* REMOTE WHO */
  1236. #ifndef NOSERVER
  1237. #ifdef CKSYSLOG
  1238.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1239.       cksyslog(SYSLG_PR, 1, "server", "REMOTE WHO", (char *)srvcmd);
  1240. #endif /* CKSYSLOG */
  1241. #ifdef IKSDB
  1242.     if (ikdbopen) slotstate(what,"REMOTE WHO", (char *)(srvcmd+2), "");
  1243. #endif /* IKSDB */
  1244.     if (!ENABLED(en_who)) {
  1245.     errpkt((CHAR *)"REMOTE WHO disabled");
  1246.     RESUME;
  1247.     } else {
  1248. #ifdef OS2
  1249. _PROTOTYP(int sndwho,(char *));
  1250.         if (sndwho((char *)(srvcmd+2))) {
  1251.         BEGIN ssinit;        /* try to send it */
  1252.         } else {            /* If not ok, */
  1253.         errpkt((CHAR *)"Can't do who command"); /* send error msg */
  1254.         RESUME;            /* and return to server command wait */
  1255.         }
  1256. #else
  1257.     if (syscmd(WHOCMD,(char *)(srvcmd+2))) {
  1258.         BEGIN ssinit;
  1259.     } else {
  1260.         errpkt((CHAR *)"Can't do who command");
  1261.         RESUME;
  1262.     }
  1263. #endif /* OS2 */
  1264.     }
  1265. #endif /* NOSERVER */
  1266. }
  1267.  
  1268. <generic>V {                /* Variable query or set */
  1269.     rc = srv_query();
  1270.     debug(F101,"srv_query","",rc);
  1271.     if (rc > -1) return(rc);
  1272. }
  1273.  
  1274. <generic>q {                /* Interrupted or connection lost */
  1275. #ifndef NOSERVER
  1276.     if (fatalio) {            /* Connection lost */
  1277. #ifdef CKSYSLOG
  1278.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1279.       cksyslog(SYSLG_PR, 1, "server", "Interrupted", NULL);
  1280. #endif /* CKSYSLOG */
  1281.     success = 0;
  1282.     xitsta |= what;
  1283.     QUIT;
  1284.     } else if (interrupted) {
  1285.     if (!ENABLED(en_fin)) {        /* Ctrl-C typed */
  1286.         errpkt((CHAR *)"QUIT disabled");
  1287.         RESUME;
  1288.     } else {
  1289. #ifdef CKSYSLOG
  1290.         if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1291.           cksyslog(SYSLG_PR, 1, "server", "Interrupted", NULL);
  1292. #endif /* CKSYSLOG */
  1293.         success = 0;
  1294.         xitsta |= what;
  1295.         QUIT;
  1296.     }
  1297.     } else {                /* Shouldn't happen */
  1298.     debug(F100,"SERVER (generic) GOT UNEXPECTED 'q'","",0);
  1299.     QUIT;
  1300.     }
  1301. #endif /* NOSERVER */
  1302. }
  1303.  
  1304. <generic>. {                /* Anything else in this state... */
  1305. #ifndef NOSERVER
  1306.     errpkt((CHAR *)"Unimplemented REMOTE command"); /* Complain */
  1307.     RESUME;                /* and return to server command wait */
  1308. #endif /* NOSERVER */
  1309. }
  1310.  
  1311. <rgen>q {                /* Sent BYE and connection broken */
  1312.     if (bye_active && ttchk() < 0) {
  1313.     msleep(500);
  1314.     bye_active = 0;
  1315.     ttclos(0);            /* Close our end of the connection */
  1316.     clsof(0);
  1317.     return(success = 1);
  1318.     } else {                /* Other generic command */
  1319.     return(success = 0);        /* or connection not broken */
  1320.     }
  1321. }
  1322.  
  1323. <rgen>Y {                /* Short-Form reply */
  1324.     rc = rcv_shortreply();
  1325.     debug(F101,"<rgen>Y rcv_shortreply","",rc);
  1326.     if (rc > -1) return(rc);
  1327. }
  1328.  
  1329. <rgen,rfile>F {                /* File header */
  1330.     char *n2;
  1331.     extern int rsn;
  1332.     debug(F101,"<rfile>F winlo 1","",winlo);
  1333.     xflg = 0;                /* Not screen data */
  1334.     cancel = 0;                /* Reset cancellation counter */
  1335. #ifdef CALIBRATE
  1336.     if (dest == DEST_N)
  1337.       calibrate = 1;
  1338. #endif /* CALIBRATE */
  1339.     if (!rcvfil(filnam)) {        /* Figure out local filename */
  1340.     errpkt((CHAR *)rf_err);        /* Trouble */
  1341.     RESUME;
  1342.     } else {                /* Real file, OK to receive */
  1343.     char * fnp;
  1344.     debug(F111,"<rfile>F winlo 2",fspec,winlo);
  1345.     if (filcnt == 1)        /* rcvfil set this to 1 for 1st file */
  1346.       crc16 = 0L;            /* Clear file CRC */
  1347.     fnp = fspec;            /* This is the full path */
  1348.     if (server && !ENABLED(en_cwd) || /* if DISABLE CD */
  1349.         !fackpath              /* or F-ACK-PATH OFF */
  1350.         ) {
  1351.         zstrip(fspec,&fnp);        /* don't send back full path */
  1352.     }
  1353.     encstr((CHAR *)fnp);
  1354.     if (fackbug)
  1355.       ack();
  1356.     else
  1357.       ack1(data);            /* Send it back in ACK */
  1358.     initattr(&iattr);        /* Clear file attribute structure */
  1359.     streamon();
  1360.     if (window(wslotn) < 0) {    /* Allocate negotiated window slots */
  1361.         errpkt((CHAR *)"Can't open window");
  1362.         RESUME;
  1363.     }
  1364. #ifdef IKSDB
  1365.     if (ikdbopen) slotstate(what,
  1366.                   server ? "SERVER" : "",
  1367.                   "RECEIVE",
  1368.                   fspec
  1369.                   );
  1370. #endif /* IKSDB */
  1371.     BEGIN rattr;            /* Now expect Attribute packets */
  1372.     }
  1373. }
  1374.  
  1375. <rgen,rfile>X {                /* X-packet instead of file header */
  1376.     xflg = 1;                /* Screen data */
  1377.     cancel = 0;                /* Reset cancellation counter */
  1378.     ack();                /* Acknowledge the X-packet */
  1379.     initattr(&iattr);            /* Initialize attribute structure */
  1380.     streamon();
  1381.     if (window(wslotn) < 0) {        /* allocate negotiated window slots */
  1382.     errpkt((CHAR *)"Can't open window");
  1383.     RESUME;
  1384.     }
  1385. #ifndef NOSPL
  1386.     if (query) {            /* If this is the response to */
  1387.     qbufp = querybuf;        /* a query that we sent, initialize */
  1388.     qbufn = 0;            /* the response buffer */
  1389.     querybuf[0] = NUL;
  1390.     }
  1391. #endif /* NOSPL */
  1392.     what = W_REMO;            /* we're doing a REMOTE command */
  1393. #ifdef IKSDB
  1394.     if (ikdbopen) slotstate(what,
  1395.               server ? "SERVER" : "",
  1396.               "RECEIVE",
  1397.               fspec
  1398.               );
  1399. #endif /* IKSDB */
  1400.     BEGIN rattr;            /* Expect Attribute packets */
  1401. }
  1402.  
  1403. <rattr>A {                /* Attribute packet */
  1404.     if (gattr(rdatap,&iattr) == 0) {    /* Read into attribute structure */
  1405. #ifdef CK_RESEND
  1406.     ack1((CHAR *)iattr.reply.val);    /* Reply with data */
  1407. #else
  1408.     ack();                /* If OK, acknowledge */
  1409. #endif /* CK_RESEND */
  1410.     } else {                /* Otherwise */
  1411.     extern long fsize;
  1412.     char *r;
  1413.     r = getreason(iattr.reply.val);
  1414.     ack1((CHAR *)iattr.reply.val);    /* refuse to accept the file */
  1415.     xxscreen(SCR_ST,ST_REFU,0L,r);    /* reason */
  1416. #ifdef TLOG
  1417.     if (tralog && !tlogfmt)
  1418.       doxlog(what,filnam,fsize,binary,1,r);
  1419. #endif /* TLOG */
  1420.     }
  1421. }
  1422.  
  1423. <rattr>D {                /* First data packet */
  1424.     rc = rcv_firstdata();
  1425.     debug(F101,"srv_firstdata","",rc);
  1426.     if (rc > -1) return(rc);        /* (see below) */
  1427. }
  1428.  
  1429. <rfile>B {                /* EOT, no more files */
  1430.     ack();                /* Acknowledge the B packet */
  1431.     reot();                /* Do EOT things */
  1432. #ifdef CK_TMPDIR
  1433. /* If we were cd'd temporarily to another device or directory ... */
  1434.     if (f_tmpdir) {
  1435.     int x;
  1436.     x = zchdir((char *) savdir);    /* ... restore previous directory */
  1437.     f_tmpdir = 0;            /* and remember we did it. */
  1438.     debug(F111,"ckcpro.w B tmpdir restoring",savdir,x);
  1439.     }
  1440. #endif /* CK_TMPDIR */
  1441.     RESUME;                /* and quit */
  1442. }
  1443.  
  1444. <rdpkt>D {                /* Data packet */
  1445.     if (cxseen || discard) {        /* If file interrupt */
  1446. #ifdef STREAMING
  1447.     if (streaming) {
  1448.         if (cancel++ == 0)
  1449.           ack1((CHAR *)"X");    /* put "X" in ACK */
  1450.         else
  1451.           fastack();
  1452.     } else
  1453. #endif /* STREAMING */
  1454.         ack1((CHAR *)"X");        /* put "X" in ACK */
  1455.     } else if (czseen) {        /* If file-group interrupt */
  1456. #ifdef STREAMING
  1457.     if (streaming) {
  1458.         if (cancel++ == 0)
  1459.           ack1((CHAR *)"Z");    /* put "Z" in ACK */
  1460.         else
  1461.           fastack();
  1462.     } else
  1463. #endif /* STREAMING */
  1464.         ack1((CHAR *)"Z");        /* put "Z" in ACK */
  1465.     } else {
  1466.     int rc, qf;
  1467. #ifndef NOSPL
  1468.     qf = query;
  1469. #else
  1470.     qf = 0;
  1471. #endif /* NOSPL */
  1472. #ifdef CKTUNING
  1473.     rc = (binary && !parity) ?
  1474.       bdecode(rdatap,putfil):
  1475.         decode(rdatap, qf ? puttrm : putfil, 1);
  1476. #else
  1477.     rc = decode(rdatap, qf ? puttrm : putfil, 1);
  1478. #endif /* CKTUNING */
  1479.     if (rc < 0) {
  1480.         discard = (keep == 0 || (keep == SET_AUTO && binary != XYFT_T));
  1481.         errpkt((CHAR *)"Error writing data"); /* If failure, */
  1482.         RESUME;
  1483.     } else                /* Data written OK, send ACK */
  1484. #ifdef STREAMING
  1485.       if (streaming)
  1486.         fastack();
  1487.     else
  1488. #endif /* STREAMING */
  1489.       ack();
  1490.     }
  1491. }
  1492.  
  1493. <rattr>Z {                /* EOF immediately after A-Packet. */
  1494.     rf_err = "Can't create file";
  1495.     timint = s_timint;
  1496.     if (discard) {            /* Discarding a real file... */
  1497.     x = 1;
  1498.     } else if (xflg) {            /* If screen data */
  1499.     if (remfile) {            /* redirected to file */
  1500.         if (rempipe)        /* or pipe */
  1501.           x = openc(ZOFILE,remdest); /* Pipe: start command */
  1502.         else
  1503.           x = opena(remdest,&iattr); /* File: open with attributes */
  1504.     } else {            /* otherwise */
  1505.         x = opent(&iattr);        /* "open" the screen */
  1506.     }
  1507. #ifdef CALIBRATE
  1508.     } else if (calibrate) {        /* If calibration run */
  1509.     x = ckopenx(&iattr);        /* do this */
  1510. #endif /* CALIBRATE */
  1511.     } else {                /* otherwise */
  1512.     x = opena(filnam,&iattr);    /* open the file, with attributes */
  1513.     }
  1514.     if (!x || reof(filnam, &iattr) < 0) { /* Now close & dispose of the file */
  1515.     errpkt((CHAR *) rf_err);    /* If problem, send error msg */
  1516.     RESUME;                /* and quit */
  1517.     } else {                /* otherwise */
  1518.     ack();                /* acknowledge the EOF packet */
  1519.     BEGIN rfile;            /* and await another file */
  1520.     }
  1521. }
  1522.  
  1523. <rdpkt>q {                  /* Ctrl-C or connection loss. */
  1524.     timint = s_timint;
  1525.     window(1);                /* Set window size back to 1... */
  1526.     cxseen = 1;
  1527.     x = clsof(1);            /* Close file */
  1528.     return(success = 0);        /* Failed */
  1529. }
  1530.  
  1531. <rdpkt>Z {                /* End Of File (EOF) Packet */
  1532. /*  wslots = 1;    */            /* (don't set) Window size back to 1 */
  1533. #ifndef COHERENT /* Coherent compiler blows up on this switch() statement. */
  1534.     x = reof(filnam, &iattr);        /* Handle the EOF packet */
  1535.     switch (x) {            /* reof() sets the success flag */
  1536.       case -3:                /* If problem, send error msg */
  1537.     errpkt((CHAR *)"Can't print file"); /* Fatal */
  1538.     RESUME;
  1539.     break;
  1540.       case -2:
  1541.     errpkt((CHAR *)"Can't mail file"); /* Fatal */
  1542.     RESUME;
  1543.     break;
  1544.       case 2:
  1545.       case 3:
  1546.     xxscreen(SCR_EM,0,0L,"Can't delete temp file"); /* Not fatal */
  1547.     RESUME;
  1548.     break;
  1549.       default:
  1550.     if (x < 0) {            /* Fatal */
  1551.         errpkt((CHAR *)"Can't close file");
  1552.         RESUME;
  1553.     } else {            /* Success */
  1554. #ifndef NOSPL
  1555.         if (query)            /* Query reponses generally */
  1556.           conoll("");        /* don't have line terminators */
  1557. #endif /* NOSPL */
  1558.         ack();            /* Acknowledge the EOF packet */
  1559.         BEGIN rfile;        /* and await another file */
  1560.     }
  1561.     }
  1562. #else
  1563.     if (reof(filnam, &iattr) < 0) {    /* Close the file */
  1564.     errpkt((CHAR *)"Error at end of file");
  1565.     RESUME;
  1566.     } else {                /* reof() sets success flag */
  1567.     ack();
  1568.     BEGIN rfile;
  1569.     }
  1570. #endif /* COHERENT */
  1571. }
  1572.  
  1573. <ssinit>Y {                /* ACK for Send-Init */
  1574.     spar(rdatap);            /* set parameters from it */
  1575.     bctu = bctr;            /* switch to agreed-upon block check */
  1576.     bctl = (bctu == 4) ? 2 : bctu;    /* Set block-check length */
  1577. #ifdef CK_RESEND
  1578.     if ((sendmode == SM_RESEND) && (!atcapu || !rscapu)) { /* RESEND */
  1579.     errpkt((CHAR *) "RESEND capabilities not negotiated");
  1580.     RESUME;
  1581.     } else {
  1582. #endif /* CK_RESEND */
  1583.     what = W_SEND;            /* Remember we're sending */
  1584.     lastxfer = W_SEND;
  1585.     x = sfile(xflg);        /* Send X or F header packet */
  1586.     cancel = 0;            /* Reset cancellation counter */
  1587.     if (x) {            /* If the packet was sent OK */
  1588.         if (!xflg && filcnt == 1)    /* and it's a real file */
  1589.           crc16 = 0L;        /* Clear the file CRC */
  1590.         resetc();            /* reset per-transaction counters */
  1591.         rtimer();            /* reset timers */
  1592. #ifdef GFTIMER
  1593.         rftimer();
  1594. #endif /* GFTIMER */
  1595.         streamon();            /* turn on streaming */
  1596. #ifdef IKSDB
  1597.         if (ikdbopen) slotstate(what,
  1598.                   (server ? "SERVER" : ""),
  1599.                   "SEND",
  1600.                   filnam,
  1601.                   "");
  1602. #endif /* IKSDB */
  1603.         BEGIN ssfile;        /* and switch to receive-file state */
  1604.     } else {            /* otherwise send error msg & quit */
  1605.         s = xflg ? "Can't execute command" : (char *)epktmsg;
  1606.         if (!*s) s = "Can't open file";
  1607.         errpkt((CHAR *)s);
  1608.         RESUME;
  1609.     }
  1610. #ifdef CK_RESEND
  1611.     }
  1612. #endif /* CK_RESEND */
  1613. }
  1614.  
  1615. /*
  1616.  These states are necessary to handle the case where we get a server command
  1617.  packet (R, G, or C) reply with an S packet, but the client retransmits the
  1618.  command packet.  The input() function doesn't catch this because the packet
  1619.  number is still zero.
  1620. */
  1621. <ssinit>R {                /* R packet was retransmitted. */
  1622.     xsinit();                /* Resend packet 0 */
  1623. }
  1624.  
  1625. <ssinit>G {                /* Same deal if G packet comes again */
  1626.     xsinit();
  1627. }
  1628.  
  1629. /* should probably add cases for O, W, V, H, J, ... */
  1630.  
  1631. <ssinit>C {                /* Same deal if C packet comes again */
  1632.     xsinit();
  1633. }
  1634.  
  1635. <ssfile>Y {                /* ACK for F or X packet */
  1636.     srvptr = srvcmd;            /* Point to string buffer */
  1637.     decode(rdatap,putsrv,0);        /* Decode data field, if any */
  1638.     putsrv(NUL);            /* Terminate with null */
  1639.     ffc = 0L;                /* Reset file byte counter */
  1640.     if (*srvcmd) {            /* If remote name was recorded */
  1641.         if (sendmode != SM_RESEND) {
  1642.         extern char * srfspec;
  1643.         if (fdispla == XYFD_C || fdispla == XYFD_S)
  1644.           xxscreen(SCR_AN,0,0L,(char *)srvcmd);
  1645.         tlog(F110," remote name:",(char *) srvcmd,0L);
  1646.         makestr(&srfspec,(char *)srvcmd);
  1647.         }
  1648.     }
  1649.     if (atcapu) {            /* If attributes are to be used */
  1650.     if (sattr(xflg | stdinf, 1) < 0) { /* send them */
  1651.         errpkt((CHAR *)"Can't send attributes"); /* if problem, say so */
  1652.         RESUME;            /* and quit */
  1653.     } else BEGIN ssattr;        /* if ok, switch to attribute state */
  1654.     } else {                /* Attributes not negotiated */
  1655.     if (window(wslotn) < 0) {    /* Open window */
  1656.         errpkt((CHAR *)"Can't open window");
  1657.         RESUME;
  1658.     }
  1659.     if ((x = sdata()) == -2) {    /* Send first data packet data */
  1660.         window(1);            /* Failed, put window size back to 1 */
  1661.         x = clsif();        /* Close input file */
  1662.         return(success = 0);    /* Return failure */
  1663.     } else if (x == -9) {        /* User interrupted */
  1664.         errpkt((CHAR *)"User cancelled"); /* Send Error packet */
  1665.         window(1);            /* Set window size back to 1... */
  1666.         timint = s_timint;        /* Restore timeout */
  1667.         return(success = 0);    /* Failed */
  1668.     } else if (x == -1) {        /* EOF (empty file) */
  1669.         window(1);            /* put window size back to 1, */
  1670.         debug(F101,"<ssfile>Y cxseen","",cxseen);
  1671.         x = clsif();        /* If not ok, close input file, */
  1672.         if (x < 0)            /* treating failure as interruption */
  1673.           cxseen = 1;        /* Send EOF packet */
  1674.         seof(cxseen||czseen);
  1675.         BEGIN sseof;        /* and switch to EOF state. */
  1676.     } else {            /* First data sent OK */
  1677.         BEGIN ssdata;        /* All ok, switch to send-data state */
  1678.     }
  1679.     }
  1680. }
  1681.  
  1682. <ssattr>Y {                /* Got ACK to A packet */
  1683.     ffc = 0L;                /* Reset file byte counter */
  1684.     if (rsattr(rdatap) < 0) {        /* Was the file refused? */
  1685.     discard = 1;            /* Set the discard flag */
  1686.     clsif();            /* Close the file */
  1687.     sxeof(1);            /* send EOF with "discard" code */
  1688.     BEGIN sseof;            /* switch to send-EOF state */
  1689.     } else if ((x = sattr(xflg | stdinf, 0)) < 0) { /* Send more? */
  1690.     errpkt((CHAR *)"Can't send attributes"); /* Trouble... */
  1691.     RESUME;
  1692.     } else if (x == 0) {        /* No more to send so now the data */
  1693.     if (window(wslotn) < 0) {    /* Allocate negotiated window slots */
  1694.         errpkt((CHAR *)"Can't open window");
  1695.         RESUME;
  1696.     }
  1697.     if ((x = sdata()) == -2) {    /* File accepted, send first data */
  1698.         return(success = 0);    /* Failed */
  1699.     } else if (x == -9) {        /* User interrupted */
  1700.         errpkt((CHAR *)"User cancelled"); /* Send Error packet */
  1701.         window(1);            /* Set window size back to 1... */
  1702.         timint = s_timint;        /* Restore timeout */
  1703.         return(success = 0);    /* Failed */
  1704.     } else if (x == -1) {        /* EOF */
  1705.         window(1);            /* put window size back to 1, */
  1706.         debug(F101,"<ssattr>Y cxseen","",cxseen);
  1707.         if (clsif() < 0)        /* Close input file */
  1708.           cxseen = 1;        /* Send EOF packet */
  1709.         seof(cxseen||czseen);
  1710.         BEGIN sseof;        /* and switch to EOF state. */
  1711.     } else {
  1712.         BEGIN ssdata;        /* All ok, switch to send-data state */
  1713.     }
  1714.     }
  1715. }
  1716.  
  1717. <ssdata>q {                  /* Ctrl-C or connection loss. */
  1718.     window(1);                /* Set window size back to 1... */
  1719.     cxseen = 1;                /* To indicate interruption */
  1720.     x = clsif();            /* Close file */
  1721.     return(success = 0);        /* Failed */
  1722. }
  1723.  
  1724. <ssdata>Y {                /* Got ACK to Data packet */
  1725.     canned(rdatap);            /* Check if file transfer cancelled */
  1726.     if ((x = sdata()) == -2) {        /* Try to send next data */
  1727.     window(1);            /* Set window size back to 1... */
  1728.     x = clsif();            /* Close file */
  1729.     return(success = 0);        /* Failed */
  1730.     } else if (x == -9) {        /* User interrupted */
  1731.     errpkt((CHAR *)"User cancelled"); /* Send Error packet */
  1732.     window(1);            /* Set window size back to 1... */
  1733.     timint = s_timint;        /* Restore original timeout */
  1734.     return(success = 0);        /* Failed */
  1735.     } else if (x == -1) {        /* EOF - finished sending data */
  1736.     debug(F101,"<ssdata>Y cxseen","",cxseen);
  1737.     window(1);            /* Set window size back to 1... */
  1738.     if (clsif() < 0)        /* Close input file */
  1739.       cxseen = 1;            /* Send EOF packet*/
  1740.     debug(F101,"<ssdata>Y CALLING SEOF()","",cxseen);
  1741.     seof(cxseen||czseen);
  1742.     BEGIN sseof;            /* and enter send-eof state */
  1743.     }
  1744. }
  1745.  
  1746. <sseof>Y {                /* Got ACK to EOF */
  1747.     int g;
  1748.     success = (cxseen == 0 && czseen == 0); /* Transfer status... */
  1749.     if (success && rejection > 0)        /* If rejected, succeed if */
  1750.       if (rejection != '#' &&            /* reason was date */
  1751.       rejection != 1 && rejection != '?') /* or name; */
  1752.     success = 0;                /* fail otherwise. */
  1753.     cxseen = 0;                /* This goes back to zero. */
  1754.     if (success) {            /* Only if transfer succeeded... */
  1755.     if (moving) {            /* If MOVE'ing */
  1756.         tlog(F110," deleting",filnam,0); /* delete the file */
  1757.         zdelet(filnam);
  1758.     } else if (snd_move) {        /* Or move it */
  1759.         int x;
  1760.         tlog(F110," moving source to",snd_move,0);
  1761.         x = zrename(filnam,snd_move);
  1762.         debug(F111,"send MOVE zrename",snd_move,x);
  1763.     } else if (snd_rename) {    /* Or rename it */
  1764.         char *s = snd_rename;    /* Renaming string */
  1765. #ifndef NOSPL
  1766.         int y;            /* Pass it thru the evaluator */
  1767.         extern int cmd_quoting;    /* for \v(filename) */
  1768.         if (cmd_quoting) {        /* But only if cmd_quoting is on */
  1769.         y = MAXRP;
  1770.         s = (char *)srvcmd;
  1771.         zzstring(snd_rename,&s,&y);
  1772.         s = (char *)srvcmd;
  1773.         }
  1774. #endif /* NOSPL */
  1775.         if (s) if (*s) {
  1776.         int x;
  1777.         x = zrename(filnam,s);
  1778.         debug(F111,"send RENAME zrename",snd_rename,x);
  1779.         if (x > -1)
  1780.           tlog(F110," renaming source to",s,0);
  1781. #ifdef COMMENT
  1782.         *s = NUL;
  1783. #endif /* COMMENT */
  1784.         }
  1785.     }
  1786.     }
  1787.     g = gnfile();
  1788.     debug(F111,"<seof>Y gnfile",filnam,g);
  1789.     if (g > 0) {            /* Any more files to send? */
  1790.     if (sfile(xflg))        /* Yes, try to send next file header */
  1791.       BEGIN ssfile;            /* if ok, enter send-file state */
  1792.     else {                /* otherwise */
  1793.         s = xflg ? "Can't execute command" : (char *)epktmsg;
  1794.         if (!*s) s = "Can't open file";
  1795.         errpkt((CHAR *)s);        /* send error message */
  1796.         RESUME;            /* and quit */
  1797.     }
  1798.     } else {                /* No next file */
  1799.     tsecs = gtimer();        /* get statistics timers */
  1800. #ifdef GFTIMER
  1801.     fptsecs = gftimer();
  1802. #endif /* GFTIMER */
  1803.     seot();                /* send EOT packet */
  1804.     BEGIN sseot;            /* enter send-eot state */
  1805.     }
  1806. }
  1807.  
  1808. <sseot>Y {                /* Got ACK to EOT */
  1809.     debug(F101,"sseot justone","",justone);
  1810.     RESUME;                /* All done, just quit */
  1811. }
  1812.  
  1813. E {                    /* Got Error packet, in any state */
  1814.     char *s = "";
  1815.     window(1);                /* Close window */
  1816.     timint = s_timint;            /* Restore original timeout */
  1817.     if (*epktmsg)            /* Message from Error packet */
  1818.       s = (char *)epktmsg;
  1819.     if (!*s) {                /* If not there then maybe here */
  1820.     s = (char *)rdatap;
  1821.     ckstrncpy((char *)epktmsg,(char *)rdatap,PKTMSGLEN);
  1822.     }
  1823.     if (!*s)                /* Hopefully we'll never see this. */
  1824.       s = "Unknown error";
  1825.     success = 0;            /* For IF SUCCESS/FAIL. */
  1826.     debug(F101,"ckcpro.w justone at E pkt","",justone);
  1827.     x = quiet; quiet = 1;        /* Close files silently, */
  1828.     epktrcvd = 1;            /* Prevent messages from clsof() */
  1829.     clsif(); clsof(1);             /* discarding any output file. */
  1830.     success = 0;            /* Transfer failed */
  1831.     xferstat = success;            /* Remember transfer status */
  1832.     ermsg(s);                /* Issue the message (calls screen). */
  1833.     tstats();                /* Get stats */
  1834.     quiet = x;                /* Restore quiet state */
  1835. /*
  1836.   If we are executing commands from a command file or macro, let the command
  1837.   file or macro decide whether to exit, based on SET { TAKE, MACRO } ERROR.
  1838. */
  1839.     if (
  1840. #ifndef NOICP
  1841.     !cmdsrc() &&
  1842. #endif /* NOICP */
  1843.     backgrd && !server)
  1844.       fatal("Protocol error");
  1845.     xitsta |= what;            /* Save this for doexit(). */
  1846. #ifdef CK_TMPDIR
  1847. /* If we were cd'd temporarily to another device or directory ... */
  1848.     if (f_tmpdir) {
  1849.     int x;
  1850.     x = zchdir((char *) savdir);    /* ... restore previous directory */
  1851.     f_tmpdir = 0;            /* and remember we did it. */
  1852.     debug(F111,"ckcpro.w E tmpdir restored",savdir,x);
  1853.     }
  1854. #endif /* CK_TMPDIR */
  1855. #ifdef IKSDB
  1856.     if (ikdbopen) slotstate(what,"ERROR", (char *)epktmsg, "");
  1857. #endif /* IKSDB */
  1858.     RESUME;
  1859. }
  1860.  
  1861. q { success = 0; QUIT; }        /* Ctrl-C or connection loss. */
  1862.  
  1863. . {                    /* Anything not accounted for above */
  1864.     errpkt((CHAR *)"Unexpected packet type"); /* Give error message */
  1865.     window(1);
  1866.     xitsta |= what;            /* Save this for doexit(). */
  1867.     RESUME;                /* and quit */
  1868. }
  1869.  
  1870. %%
  1871.  
  1872. /*
  1873.   From here down to proto() are routines that were moved out of the state
  1874.   table switcher because the resulting switch() had become too large.
  1875.   To move the contents of a state-table case to a routine:
  1876.     1. Add a prototype to the list above the state table switcher.
  1877.     2. Make a routine with an appropriate name, returning int.
  1878.     3. Move the code into it.
  1879.     4. Put a call to the new routine in the former spot:
  1880.          rc = name_of_routine();
  1881.          if (rc > -1) return(rc);
  1882.     5. Add "return(-1);" after every RESUME, SERVE, or BEGIN macro and
  1883.        at the end if the code is open-ended.
  1884. */
  1885. static int
  1886. rcv_firstdata() {
  1887.     if (discard) {            /* if we're discarding the file */
  1888.     ack1((CHAR *)"X");        /* just ack the data like this. */
  1889.     cancel++;            /* and count it */
  1890.     BEGIN rdpkt;            /* and wait for more data packets. */
  1891.     return(-1);
  1892.     } else {                /* Not discarding. */
  1893.     rf_err = "Can't open file";
  1894.     if (xflg) {            /* If screen data */
  1895.         if (remfile) {        /* redirected to file */
  1896.         if (rempipe)        /* or pipe */
  1897.           x = openc(ZOFILE,remdest); /* Pipe: start command */
  1898.         else
  1899.           x = opena(remdest,&iattr); /* File: open with attributes */
  1900.         } else {            /* otherwise */
  1901.         x = opent(&iattr);    /* "open" the screen */
  1902.         }
  1903.     } else {            /* otherwise */
  1904. #ifdef CALIBRATE
  1905.         if (calibrate) {        /* If calibration run */
  1906.         x = ckopenx(&iattr);    /* open nothing */
  1907. #ifdef STREAMING
  1908.         if (streaming)        /* Streaming */
  1909.           fastack();        /* ACK without ACKing. */
  1910.         else
  1911. #endif /* STREAMING */
  1912.           ack();        /* Send real ACK */
  1913.         BEGIN rdpkt;        /* Proceed to next state */
  1914.         return(-1);
  1915.         } else
  1916. #endif /* CALIBRATE */
  1917. #ifdef UNIX
  1918. /*
  1919.   In UNIX we can pipe the file data into the mail program, which is to be
  1920.   preferred to writing it out to a temp file and then mailing it afterwards.
  1921.   This depends rather heavily on all UNIXes having a mail command that
  1922.   accepts '-s "subject"' on the command line.  MAILCMD (e.g. mail, Mail, mailx)
  1923.   is defined in ckufio.c.
  1924. */
  1925.         if (*(iattr.disp.val) == 'M') {
  1926.         char *s;
  1927.         char tmp[1024];
  1928.         extern char *MAILCMD;
  1929.         s = iattr.disp.val + 1;
  1930.         sprintf(tmp,"%s -s %c%s%c %s", MAILCMD, '"', ofn1, '"', s);
  1931.         x = openc(ZOFILE,(char *)tmp);
  1932.         } else if (*(iattr.disp.val) == 'P') { /* Ditto for print */
  1933.         char tmp[1024];
  1934.         extern char *PRINTCMD;
  1935.         sprintf(tmp,"%s %s", PRINTCMD, iattr.disp.val + 1);
  1936.         x = openc(ZOFILE,(char *)tmp);
  1937.         } else
  1938. #endif /* UNIX */
  1939.           x = opena(filnam,&iattr);    /* open the file, with attributes */
  1940.     }
  1941.     if (x) {            /* If file was opened ok */
  1942.         int rc, qf;
  1943. #ifndef NOSPL
  1944.         qf = query;
  1945. #else
  1946.         qf = 0;
  1947. #endif /* NOSPL */
  1948.  
  1949. #ifdef CKTUNING
  1950.         rc = (binary && !parity) ?
  1951.           bdecode(rdatap,putfil):
  1952.            decode(rdatap, qf ? puttrm : putfil, 1);
  1953. #else
  1954.         rc = decode(rdatap, qf ? puttrm : putfil, 1);
  1955. #endif /* CKTUNING */
  1956.         if (rc < 0) {
  1957.         errpkt((CHAR *)"Error writing data");
  1958.         RESUME;
  1959.         return(-1);
  1960.         }
  1961. #ifdef STREAMING
  1962.         if (streaming)        /* Streaming was negotiated */
  1963.           fastack();        /* ACK without ACKing. */
  1964.         else
  1965. #endif /* STREAMING */
  1966.           ack();            /* acknowledge it */
  1967.         BEGIN rdpkt;        /* and switch to receive-data state */
  1968.         return(-1);
  1969.     } else {            /* otherwise */
  1970.         errpkt((CHAR *) rf_err);    /* send error packet */
  1971.             RESUME;            /* and quit. */
  1972.         return(-1);
  1973.     }
  1974.     }
  1975. }
  1976.  
  1977. static int
  1978. rcv_shortreply() {
  1979. #ifdef PKTZEROHACK
  1980.     success = 0;
  1981.     debug(F111,"rcv_shortreply",rdatap,ipktlen);
  1982.     if (!strncmp(ipktack,(char *)rdatap,ipktlen)) {
  1983.     /* No it's the ACK to the I packet again */
  1984.     x = scmd(vcmd,(CHAR *)cmarg);    /* So send the REMOTE command again */
  1985.     /* Maybe this should be resend() */
  1986.     debug(F110,"IPKTZEROHACK",ipktack,x);
  1987.     if (x < 0) {
  1988.         errpkt((CHAR *)srimsg);
  1989.         RESUME;
  1990.         return(-1);
  1991.     }
  1992.     } else {
  1993.     ipktack[0] = NUL;
  1994. #endif /* PKTZEROHACK */
  1995.     urserver = 1;
  1996. #ifndef NOSERVER
  1997. #ifndef NOSPL
  1998.     if (query) {            /* If to query, */
  1999.         qbufp = querybuf;        /*  initialize query response buffer */
  2000.         qbufn = 0;
  2001.         querybuf[0] = NUL;
  2002.     }
  2003. #endif /* NOSPL */
  2004.     x = 1;
  2005.     if (remfile) {            /* Response redirected to file */
  2006.         rf_err = "Can't open file";
  2007.         if (rempipe)        /* or pipe */
  2008.           x =
  2009. #ifndef NOPUSH
  2010.         zxcmd(ZOFILE,remdest)    /* Pipe: Start command */
  2011. #else
  2012.         0
  2013. #endif /* NOPUSH */
  2014.         ;
  2015.         else
  2016.           x = opena(remdest,&iattr); /* File: Open with attributes */
  2017.         debug(F111,"rcv_shortreply remfile",remdest,x);
  2018.     } else {
  2019.         x = opent(&iattr);        /* "open" the screen */
  2020.     }
  2021.     if (x) {            /* If file was opened ok */
  2022.         if (decode(rdatap,
  2023. #ifndef NOSPL
  2024.                (query || !remfile) ? puttrm :
  2025. #else
  2026.                !remfile ? puttrm :
  2027. #endif /* NOSPL */
  2028.                zputfil, 1) < 0) { /* Note: zputfil, not putfil. */
  2029.         errpkt((CHAR *)"Error writing data");
  2030.         RESUME;
  2031.         return(-1);
  2032.         } else {
  2033.         if (rdatap)        /* If we had data */
  2034.           if (*rdatap)        /* add a line terminator */
  2035.             if (remfile) {    /* to file */
  2036.             zsoutl(ZOFILE,"");
  2037.             } else {        /* or to screen. */
  2038. #ifndef NOICP
  2039.             if (!query || !cmdsrc())
  2040. #endif /* NOICP */
  2041.               conoll("");
  2042.             }
  2043.         if (bye_active && network) { /* I sent BYE or REMOTE LOGOUT */
  2044.             msleep(500);    /* command and got the ACK... */
  2045.             bye_active = 0;
  2046.             ttclos(0);
  2047.         }
  2048.         clsof(0);
  2049.         if (!epktsent && !epktrcvd) /* If no error packet... */
  2050.           success = 1;        /* success. */
  2051.         RESUME;
  2052.         return(-1);
  2053.         }
  2054.     } else {            /* File not opened OK */
  2055.         errpkt((CHAR *) rf_err);    /* send error message */
  2056.         RESUME;            /* and quit. */
  2057.         return(-1);
  2058.     }
  2059. #endif /* NOSERVER */
  2060. #ifdef PKTZEROHACK
  2061.     }
  2062. #endif /* PKTZEROHACK */
  2063.     debug(F101,"rcv_shortreply fallthru","",success);
  2064.     return(-1);
  2065. }
  2066.  
  2067.  
  2068. static int
  2069. srv_query() {
  2070. #ifndef NOSERVER
  2071. #ifndef NOSPL
  2072.     char c;
  2073. #ifdef CKSYSLOG
  2074.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  2075.       cksyslog(SYSLG_PR, 1, "server", "REMOTE QUERY", (char *)srvcmd);
  2076. #endif /* CKSYSLOG */
  2077. #ifdef IKSDB
  2078.     if (ikdbopen) slotstate(what,"REMOTE QUERY", (char *)(srvcmd+2), "");
  2079. #endif /* IKSDB */
  2080.     c = *(srvcmd+2);            /* Q = Query, S = Set */
  2081.     if (c == 'Q') {            /* Query */
  2082.     if (!ENABLED(en_que)) { /* Security */
  2083.         errpkt((CHAR *)"REMOTE QUERY disabled");
  2084.         RESUME;
  2085.         return(-1);
  2086.     } else {            /* Query allowed */
  2087.         int n; char *p, *q;
  2088.         qbufp = querybuf;        /* Wipe out old stuff */
  2089.         qbufn = 0;
  2090.         querybuf[0] = NUL;
  2091.         p = (char *) srvcmd + 3;    /* Pointer for making wrapper */
  2092.         n = strlen((char *)srvcmd);    /* Position of end */
  2093.         c = *(srvcmd+4);        /* Which type of variable */
  2094.  
  2095.         if (*(srvcmd+6) == CMDQ) {    /* Starts with command quote? */
  2096.         p = (char *) srvcmd + 6; /* Take it literally */
  2097.         if (*p == CMDQ) p++;
  2098.         } else {            /* They played by the rules */
  2099.         if (c == 'K') {        /* Kermit variable */
  2100.             int k;
  2101.             k = (int) strlen(p);
  2102.             if (k > 0 && p[k-1] == ')') {
  2103.             p = (char *)(srvcmd + 4);
  2104.             *(srvcmd+4) = CMDQ;
  2105.             *(srvcmd+5) = 'f'; /* Function, so make it \f...() */
  2106.             } else {
  2107.             *(srvcmd+3) = CMDQ; /* Stuff wrapping into buffer */
  2108.             *(srvcmd+4) = 'v';  /* Variable, so make it \v(...) */
  2109.             *(srvcmd+5) = '(';  /* around variable name */
  2110.             *(srvcmd+n) = ')';
  2111.             *(srvcmd+n+1) = NUL;
  2112.             }
  2113.         } else {
  2114.             *(srvcmd+3) = CMDQ; /* Stuff wrapping into buffer */
  2115.             *(srvcmd+4) = 'v'; /*  Variable, so make it \v(...) */
  2116.             *(srvcmd+5) = '(';    /* around variable name */
  2117.             *(srvcmd+n) = ')';
  2118.             *(srvcmd+n+1) = NUL;
  2119.             if (c == 'S') {    /* System variable */
  2120.             *(srvcmd+4) = '$'; /*  so it's \$(...) */
  2121.             } else if (c == 'G') { /* Non-\ Global variable */
  2122.             *(srvcmd+4) = 'm'; /*  so wrap it in \m(...) */
  2123.             }
  2124.         }
  2125.         }                /* Now evaluate it */
  2126.         n = QBUFL;            /* Max length */
  2127.         q = querybuf;        /* Where to put it */
  2128.         if (zzstring(p,&q,&n) < 0) {
  2129.         errpkt((n > 0) ? (CHAR *)"Can't get value"
  2130.                        : (CHAR *)"Value too long"
  2131.                );
  2132.         RESUME;
  2133.         return(-1);
  2134.         } else {
  2135.         if (encstr((CHAR *)querybuf) > -1) { /* Encode it */
  2136.             ack1(data);        /* If it fits, send it back in ACK */
  2137.             success = 1;
  2138.             RESUME;
  2139.             return(-1);
  2140.         } else if (sndstring(querybuf)) { /* Long form response */
  2141.             BEGIN ssinit;
  2142.             return(-1);
  2143.         } else {        /* sndhlp() fails */
  2144.             errpkt((CHAR *)"Can't send value");
  2145.             RESUME;
  2146.             return(-1);
  2147.         }
  2148.         }
  2149.     }
  2150.     } else if (c == 'S') {        /* Set (assign) */
  2151.     if (!ENABLED(en_asg)) {        /* Security */
  2152.         errpkt((CHAR *)"REMOTE ASSIGN disabled");
  2153.         RESUME;
  2154.         return(-1);
  2155.     } else {            /* OK */
  2156.         int n;
  2157.         n = xunchar(*(srvcmd+3));    /* Length of name */
  2158.         n = 3 + n + 1;        /* Position of length of value */
  2159.         *(srvcmd+n) = NUL;        /* Don't need it */
  2160.         if (addmac((char *)(srvcmd+4),(char *)(srvcmd+n+1)) < 0)
  2161.           errpkt((CHAR *)"REMOTE ASSIGN failed");
  2162.         else {
  2163.         ack();
  2164.         success = 1;
  2165.         }
  2166.         RESUME;
  2167.         return(-1);
  2168.     }
  2169.     } else {
  2170.     errpkt((CHAR *)"Badly formed server command");
  2171.     RESUME;
  2172.     return(-1);
  2173.     }
  2174. #else
  2175.     errpkt((CHAR *)"Variable query/set not available");
  2176.     RESUME;
  2177.     return(-1);
  2178. #endif /* NOSPL */
  2179. #endif /* NOSERVER */
  2180. }
  2181.  
  2182. static int
  2183. srv_copy() {
  2184. #ifndef NOSERVER
  2185. #ifdef CKSYSLOG
  2186.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  2187.       cksyslog(SYSLG_PR, 1, "server", "REMOTE COPY", (char *)srvcmd);
  2188. #endif /* CKSYSLOG */
  2189. #ifdef ZCOPY
  2190.     if (!ENABLED(en_cpy)) {
  2191.     errpkt((CHAR *)"REMOTE COPY disabled");
  2192.     RESUME;
  2193.     return(-1);
  2194.     } else {
  2195.     char *str1, *str2, f1[256], f2[256];
  2196.     int  len1, len2;
  2197.         len1 = xunchar(srvcmd[1]);    /* Separate the parameters */
  2198.         len2 = xunchar(srvcmd[2+len1]);
  2199.         strncpy(f1,(char *)(srvcmd+2),len1);
  2200.         f1[len1] = NUL;
  2201.         strncpy(f2,(char *)(srvcmd+3+len1),len2);
  2202.         f2[len2] = NUL;
  2203. #ifdef IKSDB
  2204.     if (ikdbopen) slotstate(what,"REMOTE COPY", f1, f2);
  2205. #endif /* IKSDB */
  2206.     if (!ENABLED(en_cwd)) {        /* If CWD is disabled */
  2207.         zstrip(f1,&str1);        /* and they included a pathname, */
  2208.             zstrip(f2,&str2);
  2209.         if (strcmp(f1,str1) || strcmp(f2,str2)) { /* Refuse. */
  2210.         errpkt((CHAR *)"Access denied");
  2211.         RESUME;            /* Remember, this is not a goto! */
  2212.         return(-1);
  2213.         }
  2214.     }
  2215.     if (state == generic) {        /* It's OK to go ahead. */
  2216.             if (zcopy(f1,f2)) {        /* Try */
  2217.         errpkt((CHAR *)"Can't copy file"); /* give error message */
  2218.         } else {
  2219.         success = 1;
  2220.         ack();
  2221.         }
  2222.             RESUME;            /* wait for next server command */
  2223.         return(-1);
  2224.     }
  2225.     }
  2226.     return(-1);
  2227. #else /* no ZCOPY */
  2228.     errpkt((CHAR *)"REMOTE COPY not available"); /* give error message */
  2229.     RESUME;                /* wait for next server command */
  2230.     return(-1);
  2231. #endif /* ZCOPY */
  2232. #endif /* NOSERVER */
  2233. }
  2234.  
  2235. static int
  2236. srv_rename() {
  2237. #ifndef NOSERVER
  2238. #ifdef CKSYSLOG
  2239.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  2240.       cksyslog(SYSLG_PR, 1, "server", "REMOTE RENAME", (char *)srvcmd);
  2241. #endif /* CKSYSLOG */
  2242. #ifdef ZRENAME
  2243.     if (!ENABLED(en_ren)) {
  2244.     errpkt((CHAR *)"REMOTE RENAME disabled");
  2245.     RESUME;
  2246.     return(-1);
  2247.     } else {                /* RENAME is enabled */
  2248.     char *str1, *str2, f1[256], f2[256];
  2249.     int len1, len2;
  2250.     len1 = xunchar(srvcmd[1]);    /* Separate the parameters */
  2251.     len2 = xunchar(srvcmd[2+len1]);
  2252.     strncpy(f1,(char *)(srvcmd+2),len1);
  2253.     f1[len1] = NUL;
  2254.     strncpy(f2,(char *)(srvcmd+3+len1),len2);
  2255.     f2[len2] = NUL;
  2256.     len2 = xunchar(srvcmd[2+len1]);
  2257.     strncpy(f1,(char *)(srvcmd+2),len1);
  2258.     f1[len1] = NUL;
  2259.     strncpy(f2,(char *)(srvcmd+3+len1),len2);
  2260.     f2[len2] = NUL;
  2261. #ifdef IKSDB
  2262.     if (ikdbopen) slotstate(what,"REMOTE RENAME", f1, f2);
  2263. #endif /* IKSDB */
  2264.     if (!ENABLED(en_cwd)) {        /* If CWD is disabled */
  2265.         zstrip(f1,&str1);        /* and they included a pathname, */
  2266.         zstrip(f2,&str2);
  2267.         if ( strcmp(f1,str1) || strcmp(f2,str2) ) { /* refuse. */
  2268.         errpkt((CHAR *)"Access denied");
  2269.         RESUME;            /* Remember, this is not a goto! */
  2270.         return(-1);
  2271.         }
  2272.     }
  2273.     if (state == generic) {        /* It's OK to go ahead. */
  2274.         if (zrename(f1,f2)) {    /* Try */
  2275.         errpkt((CHAR *)"Can't rename file"); /* Give error msg */
  2276.         } else {
  2277.         success = 1;
  2278.         ack();
  2279.         }
  2280.         RESUME;            /* Wait for next server command */
  2281.         return(-1);
  2282.     }
  2283.     }
  2284.     return(-1);
  2285. #else /* no ZRENAME */
  2286.     /* Give error message */
  2287.     errpkt((CHAR *)"REMOTE RENAME not available");
  2288.     RESUME;                /* Wait for next server command */
  2289.     return(-1);
  2290. #endif /* ZRENAME */
  2291. #endif /* NOSERVER */
  2292. }
  2293.  
  2294. static int
  2295. srv_login() {
  2296. #ifndef NOSERVER
  2297.     char f1[LOGINLEN+1], f2[LOGINLEN+1], f3[LOGINLEN+1];
  2298.     CHAR *p;
  2299.     int len, i;
  2300.  
  2301.     debug(F101,"REMOTE LOGIN x_login","",x_login);
  2302.     debug(F101,"REMOTE LOGIN x_logged","",x_logged);
  2303.  
  2304.     f1[0] = NUL; f2[0] = NUL; f3[0] = NUL;
  2305.     len = 0;
  2306.     if (srvcmd[1])            /* First length field */
  2307.       len = xunchar(srvcmd[1]);        /* Separate the parameters */
  2308.  
  2309.     if (x_login) {            /* Login required */
  2310.     if (x_logged) {            /* And already logged in */
  2311.         if (len > 0) {        /* Logging in again */
  2312.         errpkt((CHAR *)"Already logged in.");
  2313.         } else {            /* Logging out */
  2314.         debug(F101,"REMOTE LOGOUT","",x_logged);
  2315. #ifdef CKSYSLOG
  2316.         if (ckxsyslog >= SYSLG_PR && ckxlogging)
  2317.           cksyslog(SYSLG_PR, 1, "server", "REMOTE LOGOUT", NULL);
  2318. #endif /* CKSYSLOG */
  2319. #ifdef IKSDB
  2320.         if (ikdbopen) slotstate(what,"REMOTE LOGOUT", "", "");
  2321. #endif /* IKSDB */
  2322.         tlog(F110,"Logged out",x_user,0);
  2323.         ack1((CHAR *)"Logged out");
  2324.         success = 1;
  2325.         msleep(500);
  2326. #ifdef CK_LOGIN
  2327.         x_logged = 0;
  2328. #ifdef IKSD
  2329.         if (inserver)
  2330.           ckxlogout();
  2331. #endif /* IKSD */
  2332. #endif /* CK_LOGIN */
  2333.         }
  2334.     } else {            /* Not logged in yet */
  2335.         debug(F101,"REMOTE LOGIN len","",len);
  2336.         if (len > 0) {        /* Have username */
  2337. #ifdef CKSYSLOG
  2338.         if (ckxsyslog >= SYSLG_PR && ckxlogging)
  2339.           cksyslog(SYSLG_PR, 1, "server", "REMOTE LOGIN", NULL);
  2340. #endif /* CKSYSLOG */
  2341.         if (len > LOGINLEN) {
  2342.             errpkt((CHAR *)"Username too long");
  2343.         }
  2344.         p = srvcmd + 2;        /* Point to it */
  2345.         for (i = 0; i < len; i++) /* Copy it */
  2346.           f1[i] = p[i];
  2347.         f1[len] = NUL;        /* Terminate it */
  2348.         p += len;        /* Point to next length field */
  2349.         if (*p) {        /* If we have one */
  2350.             len = xunchar(*p++); /* decode it */
  2351.             if (len > 0 && len <= LOGINLEN) {
  2352.             for (i = 0; i < len; i++) /* Same deal for password */
  2353.               f2[i] = p[i];
  2354.             f2[len] = NUL;
  2355.             p += len;    /* And account */
  2356.             if (*p) {
  2357.                 len = xunchar(*p++);
  2358.                 if (len > 0 && len <= LOGINLEN) {
  2359.                 for (i = 0; i < len; i++)
  2360.                   f3[i] = p[i];    /* Set but never used */
  2361.                 f3[len] = NUL; /* (because account not used) */
  2362.                 }
  2363.             }
  2364.             }
  2365.         }
  2366.         debug(F101,"REMOTE LOGIN 1","",x_logged);
  2367. #ifdef IKSD
  2368. #ifdef CK_LOGIN
  2369.         if (inserver) {        /* Log in to system for real */
  2370.             x_logged = ckxlogin((CHAR *)f1,(CHAR *)f2,NULL,0);
  2371.             debug(F101,"REMOTE LOGIN 2","",x_logged);
  2372.             if (x_logged) {    /* Count attempts */
  2373.             logtries = 0;
  2374.             justone = 1;
  2375.             } else {
  2376.             logtries++;
  2377.             sleep(logtries);
  2378.             }
  2379.         } else
  2380. #endif /* CK_LOGIN */
  2381. #endif /* IKSD */
  2382.           if (x_user && x_passwd) { /* User and password must match */
  2383.               if (!strcmp(x_user,f1)) /* SET SERVER LOGIN */
  2384.             if (!strcmp(x_passwd,f2))
  2385.               x_logged = 1;
  2386.               debug(F101,"REMOTE LOGIN 3","",x_logged);
  2387.           } else if (x_user) {    /* Only username given, no password */
  2388.               if (!strcmp(x_user,f1)) /* so only username must match */
  2389.             x_logged = 1;
  2390.               debug(F101,"REMOTE LOGIN 4","",x_logged);
  2391.           }
  2392.         if (x_logged) {        /* Logged in? */
  2393.             tlog(F110,"Logged in", x_user, 0);
  2394.             if (isguest)
  2395.               ack1((CHAR *)"Logged in as guest - restrictions apply");
  2396.             else
  2397.               ack1((CHAR *)"Logged in");
  2398.             success = 1;
  2399.         } else {
  2400.             tlog(F110,"Login failed", f1, 0);
  2401.             errpkt((CHAR *)"Access denied.");
  2402. #ifdef IKSD
  2403. #ifdef CK_LOGIN
  2404.             if (inserver && logtries > 2)
  2405.               ckxlogout();
  2406. #endif /* CK_LOGIN */
  2407. #endif /* IKSD */
  2408.         }
  2409.         } else {            /* LOGOUT */
  2410.         errpkt((CHAR *)"Logout ignored");
  2411.         }
  2412.     }
  2413.     } else {                /* Login not required */
  2414.     if (len > 0)
  2415.       errpkt((CHAR *)"Login ignored.");
  2416.     else
  2417.       errpkt((CHAR *)"Logout ignored.");
  2418.     }
  2419. #endif /* NOSERVER */
  2420.     RESUME;
  2421.     return(-1);
  2422. }
  2423.  
  2424. static int
  2425. srv_timeout() {
  2426. #ifndef OS2
  2427.     /* K95 does this its own way */
  2428.     if (idletmo) {
  2429. #ifdef IKSD
  2430.         if (inserver) {
  2431.            printf("\r\nIKSD IDLE TIMEOUT: %d sec\r\n", srvidl);
  2432.            doexit(GOOD_EXIT,xitsta);
  2433.         }
  2434. #endif /* IKSD */
  2435.     idletmo = 0;
  2436.     printf("\r\nSERVER IDLE TIMEOUT: %d sec\r\n", srvidl);
  2437.     xitsta |= what;
  2438.     QUIT;
  2439.     }
  2440. #endif /* OS2 */
  2441. #ifndef NOSERVER
  2442. #ifndef OS2
  2443.     else
  2444. #endif /* OS2 */
  2445.       if (fatalio) {            /* Connection lost */
  2446. #ifdef CKSYSLOG
  2447.       if (ckxsyslog >= SYSLG_PR && ckxlogging)
  2448.         cksyslog(SYSLG_PR, 1, "server", "Connection lost", NULL);
  2449. #endif /* CKSYSLOG */
  2450. #ifdef IKSDB
  2451.       if (ikdbopen) slotstate(what,"SERVER DISCONNECT",(char *)srvcmd, "");
  2452. #endif /* IKSDB */
  2453.     xitsta |= what;
  2454.     QUIT;
  2455.     } else if (interrupted) {        /* Interrupted by hand */
  2456.     if (!ENABLED(en_fin)) {
  2457.         errpkt((CHAR *)"QUIT disabled");
  2458.         RESUME;
  2459.         return(-1);
  2460.     } else {
  2461.         if (what == W_SEND || what == W_RECV || what == W_REMO) {
  2462.         success = 0;
  2463. #ifdef CKSYSLOG
  2464.         if (ckxsyslog >= SYSLG_PR && ckxlogging)
  2465.           cksyslog(SYSLG_PR, 1, "server", "Interrupted", NULL);
  2466. #endif /* CKSYSLOG */
  2467.         } else if (what == W_NOTHING && filcnt == 0) {
  2468.         success = 1;
  2469.         } /* Otherwise leave success alone */
  2470.         xitsta |= what;
  2471.         QUIT;
  2472.     }
  2473.     } else {                /* Shouldn't happen */
  2474.     debug(F100,"SERVER (top) GOT UNEXPECTED 'q'","",0);
  2475.     QUIT;
  2476.     }
  2477. #endif /* NOSERVER */
  2478. }
  2479.  
  2480. static int
  2481. rcv_s_pkt() {
  2482. #ifndef NOSERVER
  2483.     if (state == rgen)
  2484.       urserver = 1;
  2485.     if (/* state == serve && */ x_login && !x_logged) {
  2486.     errpkt((CHAR *)"Login required");
  2487.     SERVE;
  2488.     } else
  2489. #endif /* NOSERVER */
  2490.       if (state == serve && !ENABLED(en_sen)) { /* Not in server mode */
  2491.     errpkt((CHAR *)"SEND disabled"); /* when SEND is disabled. */
  2492.     RESUME;
  2493.     return(-1);
  2494.     } else {                /* OK to go ahead. */
  2495. #ifdef CK_TMPDIR
  2496.     if (dldir && !f_tmpdir) {    /* If they have a download directory */
  2497.         debug(F110,"receive download dir",dldir,0);
  2498.         if (s = zgtdir()) {        /* Get current directory */
  2499.         debug(F110,"receive current dir",s,0);
  2500.         if (zchdir(dldir)) {    /* Change to download directory */
  2501.             debug(F100,"receive zchdir ok","",0);
  2502.             ckstrncpy(savdir,s,TMPDIRLEN);
  2503.             f_tmpdir = 1;    /* Remember that we did this */
  2504.         } else
  2505.           debug(F100,"receive zchdir failed","",0);
  2506.         }
  2507.     }
  2508. #endif /* CK_TMPDIR */
  2509.     nakstate = 1;            /* Can send NAKs from here. */
  2510.     rinit(rdatap);            /* Set parameters */
  2511.     bctu = bctr;            /* Switch to agreed-upon block check */
  2512.     bctl = (bctu == 4) ? 2 : bctu;    /* Set block-check length */
  2513.     what = W_RECV;            /* Remember we're receiving */
  2514.     lastxfer = W_RECV;
  2515.     resetc();            /* Reset counters */
  2516.     rtimer();            /* Reset timer */
  2517. #ifdef GFTIMER
  2518.     rftimer();
  2519. #endif /* GFTIMER */
  2520.     streamon();
  2521.     BEGIN rfile;            /* Go into receive-file state */
  2522.     }
  2523.     return(-1);
  2524. }
  2525.  
  2526. /* END OF ROUTINES MOVED OUT OF STATE MACHINE */
  2527.  
  2528.  
  2529. /*  P R O T O  --  Protocol entry function  */
  2530.  
  2531. static int is_tn = 0;            /* It's a Telnet connection */
  2532.  
  2533. #ifdef CK_SPEED
  2534. int f_ctlp = 0;                /* Control-character prefix table */
  2535. #ifdef COMMENT
  2536. short s_ctlp[256];
  2537. #endif /* COMMENT */
  2538. #endif /* CK_SPEED */
  2539.  
  2540. /*
  2541.   This is simply a wrapper for the real protocol function just below,
  2542.   that saves any items that might be changed automatically by protocol
  2543.   negotiations and then restores them upon exit from protocol mode.
  2544. */
  2545. VOID
  2546. proto() {
  2547.     extern int b_save, f_save, c_save, ss_save, slostart, reliable, urclear;
  2548. #ifndef NOCSETS
  2549.     extern int fcharset, fcs_save, tcharset, tcs_save;
  2550. #endif /* NOCSETS */
  2551.  
  2552. #ifdef PIPESEND
  2553.     extern int pipesend;
  2554. #endif /* PIPESEND */
  2555. #ifdef OS2
  2556.     extern int cursorena[], cursor_save, term_io;
  2557.     extern BYTE vmode;
  2558.     extern int display_demo;
  2559.     int term_io_save;
  2560. #endif /* OS2 */
  2561. #ifdef TNCODE
  2562.     int _u_bin=0, _me_bin=0;
  2563. #ifdef IKS_OPTION
  2564.     int _u_start=0, _me_start=0;
  2565. #endif /* IKS_OPTION */
  2566. #endif /* TNCODE */
  2567. #ifdef PATTERNS
  2568.     extern int patterns;
  2569.     int pa_save;
  2570.     int i;
  2571. #endif /* PATTERNS */
  2572.  
  2573. #ifdef PATTERNS
  2574.     pa_save = patterns;
  2575. #endif /* PATTERNS */
  2576.  
  2577. #ifdef CK_LOGIN
  2578.     if (isguest) {            /* If user is anonymous */
  2579.     en_pri = 0;            /* disable printing */
  2580.     en_mai = 0;            /* and disable email */
  2581.     en_del = 0;            /* and file deletion */
  2582.     }
  2583. #endif /* CK_LOGIN */
  2584.  
  2585. #ifdef OS2
  2586.     cursor_save = cursorena[vmode];
  2587.     cursorena[vmode] = 0;
  2588.     term_io_save = term_io;
  2589.     term_io = 0;
  2590. #endif /* OS2 */
  2591.     b_save = binary;            /* SET FILE TYPE */
  2592.     f_save = fncnv;            /* SET FILE NAMES */
  2593.     c_save = bctr;
  2594.     p_save = fnspath;
  2595.     r_save = recursive;
  2596.     s_timint = timint;
  2597.     ss_save = slostart;
  2598. #ifndef NOCSETS
  2599.     fcs_save = fcharset;
  2600.     tcs_save = tcharset;
  2601. #endif /* NOCSETS */
  2602.  
  2603. #ifdef COMMENT
  2604. /* Don't do this because then user can never find out what happened. */
  2605. #ifdef CK_SPEED
  2606.     for (i = 0; i < 256; i++)
  2607.       s_ctlp[i] = ctlp[i];
  2608.     f_ctlp = 1;
  2609. #endif /* CK_SPEED */
  2610. #endif /* COMMENT */
  2611.     if (reliable == SET_ON)
  2612.       slostart = 0;
  2613.     is_tn = (!local && sstelnet)
  2614. #ifdef TNCODE
  2615.       || (local && network && ttnproto == NP_TELNET)
  2616. #endif /* TNCODE */
  2617.     ;
  2618. #ifdef TNCODE
  2619.     if (is_tn) {
  2620.         if (tn_b_xfer && !(sstelnet || inserver)) {
  2621.         /* Save the current state of Telnet Binary */
  2622.         _u_bin = TELOPT_U(TELOPT_BINARY);
  2623.         _me_bin = TELOPT_ME(TELOPT_BINARY);
  2624.  
  2625.         /* If either direction is not Binary attempt to negotiate it */
  2626.         if (!_u_bin && TELOPT_U_MODE(TELOPT_BINARY) != TN_NG_RF) {
  2627.         tn_sopt(DO,TELOPT_BINARY);
  2628.         TELOPT_UNANSWERED_DO(TELOPT_BINARY) = 1;
  2629.         }
  2630.         if (!_me_bin && TELOPT_ME_MODE(TELOPT_BINARY) != TN_NG_RF) {
  2631.         tn_sopt(WILL,TELOPT_BINARY);
  2632.         TELOPT_UNANSWERED_WILL(TELOPT_BINARY) = 1;
  2633.         }
  2634.         if (!(_me_bin && _u_bin))
  2635.           tn_wait("proto set binary mode");
  2636.         }
  2637. #ifdef IKS_OPTION
  2638.         if (sstate == 'x' || sstate == 'v') { /* Responding to a request */
  2639.             if (!inserver && TELOPT_U(TELOPT_KERMIT) &&
  2640.                 TELOPT_SB(TELOPT_KERMIT).kermit.u_start) {
  2641.                 iks_wait(KERMIT_REQ_STOP,0); /* Stop the other Server */
  2642.         _u_start = 1;
  2643.             }
  2644.             if (TELOPT_ME(TELOPT_KERMIT) &&
  2645.                 !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2646.                 tn_siks(KERMIT_START);    /* Send Kermit-Server Start */
  2647.          TELOPT_SB(TELOPT_KERMIT).kermit.me_start = 1;
  2648.             }
  2649.         } else {            /* Initiating a request */
  2650.             if (TELOPT_ME(TELOPT_KERMIT) &&
  2651.                 TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2652.                 tn_siks(KERMIT_STOP);    /* I'm not servering */
  2653.          TELOPT_SB(TELOPT_KERMIT).kermit.me_start = 0;
  2654.         _me_start = 1;
  2655.             }
  2656.             if (TELOPT_U(TELOPT_KERMIT) &&
  2657.             !TELOPT_SB(TELOPT_KERMIT).kermit.u_start) {
  2658.         /* Send Req-Server-Start */
  2659.                 if (!iks_wait(KERMIT_REQ_START,0)) {
  2660.                     if (sstate != 's') {
  2661.             success = 0;    /* Other Kermit refused to serve */
  2662.             if (local)
  2663.               printf("A Kermit server is not available\r\n");
  2664.             debug(F110,"proto()",
  2665.                              "A Kermit Server is not available",0);
  2666.             tlog(F110,"IKS client/server failure",
  2667.                              "A Kermit Server is not available",0);
  2668.             goto xxprotox;
  2669.                     }
  2670.         }
  2671.             }
  2672.         }
  2673. #endif /* IKS_OPTION */
  2674. #ifdef CK_ENCRYPTION
  2675.         if (tn_no_encrypt_xfer && !(sstelnet || inserver)) {
  2676.             ck_tn_enc_stop();
  2677.         }
  2678. #endif /* CK_ENCRYPTION */
  2679.     }
  2680. #endif /* TNCODE */
  2681.  
  2682.     if (!xfrint) connoi();
  2683.     xxproto();                /* Call the real protocol function */
  2684.  
  2685. #ifdef IKS_OPTION
  2686.   xxprotox:
  2687. #endif /* IKS_OPTION */
  2688.     xferstat = success;            /* Remember transfer status */
  2689.     kactive = 0;
  2690.  
  2691. #ifdef TNCODE
  2692. #ifdef CK_ENCRYPTION
  2693.         if (tn_no_encrypt_xfer && !(sstelnet || inserver)) {
  2694.             ck_tn_enc_start();
  2695.         }
  2696. #endif /* CK_ENCRYPTION */
  2697. #ifdef IKS_OPTION
  2698.     if (TELOPT_ME(TELOPT_KERMIT) &&
  2699.         TELOPT_SB(TELOPT_KERMIT).kermit.me_start && !_me_start) {
  2700.         tn_siks(KERMIT_STOP);        /* Server is stopped */
  2701.      TELOPT_SB(TELOPT_KERMIT).kermit.me_start = 0;
  2702.     }
  2703. #endif /* IKS_OPTION */
  2704.     if (is_tn && tn_b_xfer && !(sstelnet || inserver)) {
  2705.         /* if we negotiated Binary mode try to reset it */
  2706.         if (!_u_bin) {
  2707.             /* Check to see if the state changed during the transfer */
  2708.         if (TELOPT_U(TELOPT_BINARY)) {
  2709.         tn_sopt(DONT,TELOPT_BINARY);
  2710.         TELOPT_UNANSWERED_DONT(TELOPT_BINARY) = 1;
  2711.         } else
  2712.           _u_bin = 1;        /* So we don't call tn_wait() */
  2713.         }
  2714.         if (!_me_bin) {
  2715.             /* Check to see if the state changed during the transfer */
  2716.         if (TELOPT_ME(TELOPT_BINARY)) {
  2717.         tn_sopt(WONT,TELOPT_BINARY);
  2718.         TELOPT_UNANSWERED_WONT(TELOPT_BINARY) = 1;
  2719.         } else
  2720.           _me_bin = 1;        /* So we don't call tn_wait() */
  2721.     }
  2722.     if (!(_me_bin && _u_bin))
  2723.       tn_wait("proto reset binary mode");
  2724.     }
  2725. #endif /* TNCODE */
  2726.  
  2727. #ifdef PATTERNS
  2728.     patterns = pa_save;
  2729. #endif /* PATTERNS */
  2730.  
  2731. #ifdef STREAMING
  2732.     streaming = 0;
  2733.     /* streamok = 0; */
  2734. #endif /* STREAMING */
  2735. #ifdef COMMENT
  2736. #ifdef CK_SPEED
  2737.     for (i = 0; i < 256; i++)
  2738.       ctlp[i] = s_ctlp[i];
  2739.     f_ctlp = 0;
  2740. #endif /* CK_SPEED */
  2741. #endif /* COMMENT */
  2742.     urclear = 0;
  2743.     if (!success) {
  2744.     xitsta |= what;
  2745.     tlog(F110," failed:",(char *)epktmsg,0);
  2746.     }
  2747.     debug(F111,"proto xferstat",epktmsg,xferstat);
  2748.     slostart = ss_save;
  2749.     if (s_timint > -1) {        /* Because of REMOTE SET */
  2750.     timint = s_timint;
  2751.     s_timint = -1;
  2752.     }
  2753.     recursive = r_save;
  2754.     fnspath = p_save;
  2755.     if (c_save > -1) {            /* Because of REMOTE SET */
  2756.     bctr = c_save;
  2757.     c_save = -1;
  2758.     }
  2759.     fncnv   = f_save;
  2760.     binary  = b_save;
  2761. #ifdef PIPESEND
  2762.     pipesend = 0;                /* Next time might not be pipesend */
  2763. #endif /* PIPESEND */
  2764. #ifdef OS2
  2765.     cursorena[vmode] = cursor_save;
  2766.     term_io = term_io_save;
  2767.     display_demo = 1;
  2768. #endif /* OS2 */
  2769. }
  2770.  
  2771. static VOID
  2772. xxproto() {
  2773.     int x;
  2774.     long lx;
  2775. #ifdef CK_XYZ
  2776. #ifdef XYZ_INTERNAL
  2777. _PROTOTYP( int pxyz, (int) );
  2778. #endif /* XYZ_INTERNAL */
  2779. #endif /* CK_XYZ */
  2780.  
  2781.     char xss[2];            /* String representation of sstate */
  2782.     xss[0] = sstate;
  2783.     xss[1] = NUL;
  2784.     s_timint = timint;
  2785.  
  2786.     debug(F101,"xxproto entry justone","",justone);
  2787.     success = 0;
  2788.  
  2789.     retrieve = 0;            /* Reset these ... */
  2790.     reget = 0;
  2791.     opkt = 0;
  2792.  
  2793.     if (local && ttchk() < 0) {        /* Giving BYE or FIN */
  2794.     if (bye_active) {        /* but there is no connection */
  2795.         ttclos(0);
  2796.         success = 1;
  2797.         return;
  2798.     }
  2799.     /* Ditto for any REMOTE command */
  2800.     if (sstate == 'g' && cmarg ) {
  2801.         if (*cmarg == 'L' || *cmarg == 'F' || *cmarg == 'X')
  2802.           success = 1;
  2803.         else
  2804.           printf("?No connection\r\n");
  2805.         return;
  2806.     }
  2807.     }
  2808.  
  2809. /* Set up the communication line for file transfer. */
  2810.  
  2811.     if (local && (speed < 0L) && (network == 0)) {
  2812.     xxscreen(SCR_EM,0,0L,"Sorry, you must 'set speed' first");
  2813.     return;
  2814.     }
  2815.     x = -1;
  2816.     if (ttopen(ttname,&x,mdmtyp,cdtimo) < 0) {
  2817.     debug(F111,"failed: proto ttopen local",ttname,local);
  2818.     xxscreen(SCR_EM,0,0L,"Can't open line");
  2819.     return;
  2820.     }
  2821.     if (x > -1) local = x;
  2822.     debug(F111,"proto ttopen local",ttname,local);
  2823.  
  2824.     lx = (local && !network) ? speed : -1;
  2825. #ifdef NETCONN
  2826. #ifdef CK_SPEED
  2827.     if (is_tn) {
  2828.     ctlp[(unsigned)255] = ctlp[CR] = 1;
  2829.     if (parity == 'e' || parity == 'm') ctlp[127] = 1;
  2830.     if (flow == FLO_XONX) {        /* Also watch out for Xon/Xoff */
  2831.         ctlp[17] = ctlp[19] = 1;
  2832.         ctlp[17+128] = ctlp[19+128] = 1;
  2833.     }
  2834.     }
  2835. #endif /* CK_SPEED */
  2836. #endif /* NETCONN */
  2837.     if (ttpkt(lx,flow,parity) < 0) {    /* Put line in packet mode, */
  2838.     xxscreen(SCR_EM,0,0L,"Can't condition line");
  2839.     return;
  2840.     }
  2841.     if (local && !network && carrier != CAR_OFF) {
  2842.     int x;                /* Serial connection */
  2843.     x = ttgmdm();            /* with carrier checking */
  2844.     if (x > -1) {
  2845.         if (!(x & BM_DCD)) {
  2846.         debug(F101,"proto ttgmdm","",0);
  2847.         xxscreen(SCR_EM,0,0L,"Carrier required but not detected");
  2848.         return;
  2849.         }
  2850.     }
  2851.     }
  2852.     /* Send remote side's "receive" or "server" startup string, if any */
  2853.     if (local && ckindex((char *)xss,"srgcjhk",0,0,1)) {
  2854.     char *s = NULL;
  2855.         if (
  2856. #ifdef IKS_OPTION
  2857.         /* Don't send auto-blah string if we know other side is serving */
  2858.         !TELOPT_U(TELOPT_KERMIT) ||
  2859.         !TELOPT_SB(TELOPT_KERMIT).kermit.u_start
  2860. #else
  2861.         1
  2862. #endif /* IKS_OPTION */
  2863.         ) {
  2864.         if (sstate == 's') {    /* Sending file(s) */
  2865.         s = binary ? ptab[protocol].h_b_init : ptab[protocol].h_t_init;
  2866.         } else if (protocol == PROTO_K) { /* Command for server */
  2867.         s = ptab[protocol].h_x_init;
  2868.         }
  2869.     }
  2870. #ifdef CK_SPEED
  2871. #ifndef UNPREFIXZERO
  2872.     if (protocol == PROTO_K)    /* Because of C-strings... */
  2873.       ctlp[0] = 1;
  2874. #endif /* UNPREFIXZERO */
  2875. #endif /* CK_SPEED */
  2876.     if (s) if (*s) {        /* If we have a command to send... */
  2877.         char tmpbuf[356];
  2878.         int stuff = -1, stuff2 = -1, len = 0;
  2879.         extern int tnlm;
  2880.         strcpy(tmpbuf,s);
  2881.         if (sstate == 's')        /* Sending file(s) */
  2882.           sprintf(tmpbuf, s, cmarg2[0] ? cmarg2 : cmarg); /* For XMODEM */
  2883.         else            /* Command for server */
  2884.           sprintf(tmpbuf, s);
  2885.         strcat(tmpbuf, "\015");
  2886.         if (tnlm)            /* TERMINAL NEWLINE ON */
  2887.           stuff = LF;        /* Stuff LF */
  2888. #ifdef TNCODE
  2889.         /* TELNET NEWLINE MODE */
  2890.         if (is_tn) {
  2891.         switch (TELOPT_ME(TELOPT_BINARY) ? tn_b_nlm : tn_nlm) {
  2892.           case TNL_CR:
  2893.             break;
  2894.           case TNL_CRNUL:
  2895.             break;
  2896.           case TNL_CRLF:
  2897.             stuff2 = stuff;
  2898.             stuff = LF;
  2899.             break;
  2900.         }
  2901.         }
  2902. #endif /* TNCODE */
  2903.  
  2904. #ifdef NETCONN
  2905. #ifdef TCPSOCKET
  2906. #ifdef RLOGCODE
  2907.         if (network && ttnproto == NP_RLOGIN) {
  2908.         switch (tn_b_nlm) { /* Always BINARY */
  2909.           case TNL_CR:
  2910.             break;
  2911.           case TNL_CRNUL:
  2912.             stuff2 = stuff;
  2913.             stuff  = NUL;
  2914.             break;
  2915.           case TNL_CRLF:
  2916.             stuff2 = stuff;
  2917.             stuff = LF;
  2918.             break;
  2919.         }
  2920.         }
  2921. #endif /* RLOGCODE */
  2922. #endif /* TCPSOCKET */
  2923. #endif /* NETCONN */
  2924.  
  2925.         len = strlen(tmpbuf);
  2926.         if (stuff >= 0) {
  2927.         tmpbuf[len++] = stuff;
  2928.         if (stuff2 >= 0)
  2929.           tmpbuf[len++] = stuff2;
  2930.         tmpbuf[len] = NUL;
  2931.         }
  2932.         ttol((CHAR *)tmpbuf,len);
  2933.         if (protocol == PROTO_K)    /* Give remote Kermit time to start */
  2934.           msleep(400);
  2935.     }
  2936.     }
  2937.  
  2938. #ifdef CK_XYZ
  2939.     if (protocol != PROTO_K) {        /* Non-Kermit protocol selected */
  2940.     char tmpbuf[356];
  2941.     char * s = "";
  2942. #ifdef XYZ_INTERNAL            /* Internal */
  2943.     success = !pxyz(sstate);
  2944. #else
  2945. #ifdef CK_REDIR                /* External */
  2946.     switch (sstate) {
  2947.       case 's':            /* 'Tis better to SEND... */
  2948.         s = binary ? ptab[protocol].p_b_scmd : ptab[protocol].p_t_scmd;
  2949.         break;
  2950.       case 'v':            /* ... than RECEIVE */
  2951.         s = binary ? ptab[protocol].p_b_rcmd : ptab[protocol].p_t_rcmd;
  2952.         break;
  2953.     }
  2954.     if (!s) s = "";
  2955.     if (*s) {
  2956.         sprintf(tmpbuf,s,(sstate == 's') ? fspec : cmarg2);
  2957.         debug(F110,"ckcpro ttruncmd",tmpbuf,0);
  2958.         success = ttruncmd(tmpbuf);
  2959.     } else {
  2960.         printf("?Sorry, no external protocol defined for %s\r\n",
  2961.            ptab[protocol].p_name
  2962.            );
  2963.     }
  2964. #else
  2965.     printf(
  2966. "Sorry, only Kermit protocol is supported in this version of Kermit\n"
  2967.            );
  2968. #endif /* CK_REDIR */
  2969. #endif /* XYZ_INTERNAL */
  2970.     return;
  2971.     }
  2972. #endif /* CK_XYZ */
  2973.  
  2974. #ifdef NTSIGX
  2975.     conraw();
  2976.     connoi();
  2977. #else
  2978.     if (!local)
  2979.       connoi();                /* No console interrupts if remote */
  2980. #endif /* NTSIG */
  2981.  
  2982.     kactive = 1;
  2983.     if (sstate == 'x') {        /* If entering server mode, */
  2984.     server = 1;            /* set flag, */
  2985.     debug(F101,"server backgrd","",backgrd);
  2986.     debug(F101,"server quiet","",quiet);
  2987.     debug(F100,"SHOULD NOT SEE THIS IF IN BACKGROUND!","",0);
  2988.     if (!local) {            /* and issue appropriate message. */
  2989.         if (!quiet && !backgrd
  2990. #ifdef IKS_OPTION
  2991.                 && !TELOPT_ME(TELOPT_KERMIT) /* User was told by negotiation */
  2992. #endif /* IKS_OPTION */
  2993.         ) {
  2994.         conoll(srvtxt);
  2995.         conoll("KERMIT READY TO SERVE...");
  2996.         }
  2997.     } else {
  2998.         conol("Entering server mode on ");
  2999.         conoll(ttname);
  3000.         conoll("Type Ctrl-C to quit.");
  3001.         if (srvdis) intmsg(-1L);
  3002. #ifdef TCPSOCKET
  3003. #ifndef NOLISTEN
  3004.         if (network && tcpsrfd > 0)
  3005.           ttol((CHAR *)"KERMIT READY TO SERVE...\015\012",26);
  3006. #endif /* NOLISTEN */
  3007. #endif /* TCPSOCKET */
  3008.     }
  3009.     } else
  3010.       server = 0;
  3011. #ifdef VMS
  3012.     if (!quiet && !backgrd)    /* So message doesn't overwrite prompt */
  3013.       conoll("");
  3014.     if (local) conres();       /* So Ctrl-C will work */
  3015. #endif /* VMS */
  3016. /*
  3017.   If in remote mode, not shushed, not in background, and at top command level,
  3018.   issue a helpful message telling what to do...
  3019. */
  3020.     if (!local && !quiet && !backgrd) {
  3021.     if (sstate == 'v') {
  3022.         conoll("Return to your local Kermit and give a SEND command.");
  3023.         conoll("");
  3024.         conoll("KERMIT READY TO RECEIVE...");
  3025.     } else if (sstate == 's') {
  3026.         conoll("Return to your local Kermit and give a RECEIVE command.");
  3027.         conoll("");
  3028.         conoll("KERMIT READY TO SEND...");
  3029.     } else if ( sstate == 'g' || sstate == 'r' || sstate == 'h' ||
  3030.             sstate == 'j' || sstate == 'c' ) {
  3031.         conoll("Return to your local Kermit and give a SERVER command.");
  3032.         conoll("");
  3033.         conoll((sstate == 'r' || sstate == 'j' || sstate == 'h') ?
  3034.            "KERMIT READY TO GET..." :
  3035.            "KERMIT READY TO SEND SERVER COMMAND...");
  3036.     }
  3037.     }
  3038. #ifdef COMMENT
  3039.     if (!local) sleep(1);
  3040. #endif /* COMMENT */
  3041. /*
  3042.   The 'wart()' function is generated by the wart program.  It gets a
  3043.   character from the input() routine and then based on that character and
  3044.   the current state, selects the appropriate action, according to the state
  3045.   table above, which is transformed by the wart program into a big case
  3046.   statement.  The function is active for one transaction.
  3047. */
  3048.     rtimer();                /* Reset elapsed-time timer */
  3049. #ifdef GFTIMER
  3050.     rftimer();
  3051. #endif /* GFTIMER */
  3052.     resetc();                /* & other per-transaction counters. */
  3053.  
  3054.     debug(F101,"proto calling wart, justone","",justone);
  3055.  
  3056.     wart();                /* Enter the state table switcher. */
  3057. /*
  3058.   Note: the following is necessary in case we have just done a remote-mode
  3059.   file transfer, in which case the controlling terminal modes have been
  3060.   changed by ttpkt().  In particular, special characters like Ctrl-C and
  3061.   Ctrl-\ might have been turned off (see ttpkt).  So this call to ttres() is
  3062.   essential.  IMPORTANT: restore interrupt handlers first, otherwise any
  3063.   terminal interrupts that occur before this is done in the normal place
  3064.   later will cause a crash.
  3065. */
  3066. #ifdef OS2
  3067.     ttres();                /* Reset the communication device */
  3068. #else
  3069.     if (!local) {
  3070.     setint();            /* Arm interrupt handlers FIRST */
  3071.     msleep(500);
  3072.     ttres();            /* Then restore terminal. */
  3073.     }
  3074. #endif /* OS2 */
  3075.     xxscreen(SCR_TC,0,0L,"");        /* Transaction complete */
  3076.     x = quiet;
  3077.     quiet=1;
  3078.     clsif();                /* Failsafe in case we missed */
  3079.     clsof(1);                /* a case in the state machine. */
  3080.     quiet = x;
  3081.  
  3082.     if (server) {            /* Back from packet protocol. */
  3083.         if (!quiet && !backgrd
  3084. #ifdef IKSD
  3085.         && !inserver
  3086. #endif /* IKSD */
  3087.         ) {                /* Give appropriate message */
  3088.         conoll("");
  3089.         conoll("C-Kermit server done");
  3090.         }
  3091.         server = 0;            /* Not a server any more */
  3092.     }
  3093. }
  3094.  
  3095. /*  S G E T I N I T  --  Handle incoming GET-Class packets  */
  3096.  
  3097. /*
  3098.   Returns:
  3099.    -1: On error
  3100.     0: GET packet processed OK - ready to Send.
  3101.     1: Extended GET processed OK - wait for another.
  3102. */
  3103. static int
  3104. sgetinit(reget,xget) int reget, xget; {    /* Server end of GET command */
  3105.     char * fs = NULL;            /* Pointer to filespec */
  3106.     int i, n, done = 0;
  3107. #ifdef PATTERNS
  3108.     extern int patterns;
  3109. #endif /* PATTERNS */
  3110. #ifdef PIPESEND
  3111.     extern int usepipes, pipesend;
  3112. #endif /* PIPESEND */
  3113.  
  3114.     if (!ENABLED(en_get)) {        /* Only if not disabled!  */
  3115.     errpkt((CHAR *)"GET disabled");
  3116.     return(-1);
  3117.     }
  3118.  
  3119.     /* OK to proceed */
  3120.  
  3121. #ifdef WHATAMI
  3122.     /* If they are alike this was already done in whoarewe() */
  3123.     debug(F101,"sgetinit whatru","",whatru);
  3124.     if (whatru & WMI_FLAG) {        /* Did we get WHATAMI info? */
  3125.     debug(F101,"sgetinit binary (1)","",binary);
  3126. #ifdef VMS
  3127.     if (binary != XYFT_I && binary != XYFT_L)
  3128. #else
  3129. #ifdef OS2
  3130.       if (binary != XYFT_L)
  3131. #endif /* OS2 */
  3132. #endif /* VMS */
  3133.         binary = (whatru & WMI_FMODE) ? /* Yes, set file type */
  3134.           XYFT_B : XYFT_T;    /* automatically */
  3135.     debug(F101,"sgetinit binary (2)","",binary);
  3136.     if (!wearealike)
  3137.       fncnv = (whatru & WMI_FNAME) ? 1 : 0; /* And name conversion */
  3138.     }
  3139. #endif /* WHATAMI */
  3140.  
  3141.     fs = (char *)srvcmd;
  3142.     srvptr = srvcmd;            /* Point to server command buffer */
  3143.     decode(rdatap,putsrv,0);        /* Decode the GET command into it */
  3144.     /* Accept multiple filespecs */
  3145.     cmarg2 = "";            /* Don't use cmarg2 */
  3146.     cmarg = "";                /* Don't use cmarg */
  3147.  
  3148.     done = 1;                /* Only 1 packet needed... */
  3149.     if (xget) {                /* Special decoding for Extended GET */
  3150.     char L, next, c;        /* PLV items */
  3151.     int len, val;            /* More PLV items */
  3152.     char * p = (char *)srvcmd;    /* String to decode */
  3153.  
  3154.     done = 0;            /* Maybe more packets needed */
  3155.     fs = NULL;            /* We don't know the filespec yet */
  3156.     c = *p++;            /* Get first parameter */
  3157.  
  3158.     while (c) {            /* For all parameters... */
  3159.         debug(F000,"sgetinit c","",c);
  3160.         L = *p++;            /* Get length */
  3161.         if (L >= SP)        /* Decode length */
  3162.           len = xunchar(L);
  3163.         else if (c == '@') {    /* Allow missing EOP length field */
  3164.         len = 0;
  3165.         } else {
  3166.         len = (xunchar(*p++) * 95);
  3167.         len += xunchar(*p++);
  3168.         }
  3169.         debug(F101,"sgetinit len","",len);
  3170.         next = *(p+len);        /* Get next parameter */
  3171.         *(p+len) = NUL;        /* Zero it out to terminal value */
  3172.         debug(F110,"sgetinit p",p,0);
  3173.         switch (c) {        /* Do the parameter */
  3174.           case 'O':            /* GET Options */
  3175.         val = atoi(p);        /* Convert to int */
  3176.         debug(F101,"sgetinit O val","",val);
  3177.         if (val & GOPT_DEL) moving = 1;
  3178.         if (val & GOPT_RES) reget = 1;
  3179.         if (val & GOPT_REC) {
  3180.             recursive = 1;
  3181.             if (fnspath == PATH_OFF)
  3182.               fnspath = PATH_REL;
  3183.         }
  3184.         break;
  3185.           case 'M':            /* Transfer Mode */
  3186.         val = atoi(p);
  3187.         debug(F101,"sgetinit M val","",val);
  3188.         if (val < 1)
  3189.           break;
  3190. #ifdef PATTERNS
  3191.         patterns = 0;        /* Takes precedence over patterns */
  3192. #endif /* PATTERNS */
  3193.         if (val == GMOD_TXT) binary = XYFT_T; /* Text */
  3194.         if (val == GMOD_BIN) binary = XYFT_B; /* Binary */
  3195.         if (val == GMOD_LBL) binary = XYFT_L; /* Labeled */
  3196.         break;
  3197.           case 'F':            /* Filename */
  3198.         fs = p;
  3199.         debug(F110,"sgetinit filename",fs,0);
  3200.         break;
  3201.           case '@':            /* End Of Parameters */
  3202.         done = 1;
  3203.         debug(F100,"sgetinit EOP","",0);
  3204.         break;
  3205.           default:
  3206.         errpkt((CHAR *)"Unknown GET Parameter");
  3207.         debug(F100,"sgetinit unknown parameter","",0);
  3208.         return(-1);
  3209.         }
  3210.         p += (len + 1);
  3211.         c = next;
  3212.     }
  3213.     }
  3214.     if (!fs) fs = "";            /* A filename is required */
  3215.     if (*fs) {
  3216.     havefs = 1;
  3217.     n = 0;                /* Check for quoted name */
  3218.     if ((n = strlen(fs)) > 1) {
  3219.         /* Note: this does not allow for multiple quoted names */
  3220.         if ((fs[0] == '{' && fs[n-1] == '}') ||
  3221.         (fs[0] == '"' && fs[n-1] == '"')) {
  3222.         fs[n-1] = '\0';
  3223.         fs++;
  3224.         debug(F111,"sgetinit unquoted filename",fs,n);
  3225.         } else
  3226.           n = 0;            /* This means no quoting */
  3227.     }
  3228.  
  3229. #ifdef PIPESEND
  3230.     debug(F111,"sgetinit",fs,usepipes);
  3231.     if (usepipes && ENABLED(en_hos) && *fs == '!') {
  3232.         cmarg = fs + 1;        /* Point past the bang */
  3233.         *fs = NUL;
  3234.         nfils = -1;
  3235.         pipesend = 1;
  3236.         debug(F111,"sgetinit pipesend",cmarg,pipesend);
  3237.     }
  3238.     if (!pipesend) {        /* If it's not a pipe */
  3239. #endif /* PIPESEND */
  3240.         if (n == 0) {        /* If the name was not quoted */
  3241. #ifndef NOMSEND
  3242.         nfils = fnparse(fs);    /* Allow it to be a list of names */
  3243.         } else {            /* If it was quoted */
  3244. #endif /* NOMSEND */
  3245.         nzxopts = 0;
  3246. #ifdef UNIXOROSK
  3247.         if (matchdot)  nzxopts |= ZX_MATCHDOT;
  3248. #endif /* UNIXOROSK */
  3249.         if (recursive) nzxopts |= ZX_RECURSE;
  3250.         /* Treat as a single filespec */
  3251.         nfils = 0 - nzxpand(fs,nzxopts);
  3252.         cmarg = fs;
  3253.         }
  3254. #ifdef PIPESEND
  3255.     }
  3256. #endif /* PIPESEND */
  3257.     }
  3258.     if (!done) {            /* Need more O packets... */
  3259.     debug(F100,"sgetinit O-Packet TBC","",0); /* To Be Continued */
  3260.     return(1);
  3261.     }
  3262.     debug(F100,"sgetinit O-Packet done - havefs","",havefs);
  3263.     if (!havefs) {            /* Done - make sure we have filename */
  3264.     errpkt((CHAR *)"GET without filename");
  3265.     return(-1);
  3266.     }
  3267.     freerpkt(winlo);
  3268.     winlo = 0;                /* Back to packet 0 again. */
  3269.     debug(F101,"sgetinit winlo","",winlo);
  3270.     nakstate = 0;            /* Now I'm the sender! */
  3271.     if (reget) sendmode = SM_RESEND;
  3272.     if (sinit() > 0) {            /* Send Send-Init */
  3273. #ifdef STREAMING
  3274.     if (!streaming)
  3275. #endif /* STREAMING */
  3276.       timint = chktimo(rtimo,timef); /* Switch to per-packet timer */
  3277.     return(0);            /* If successful, switch state */
  3278.     } else return(-1);            /* Else back to server command wait */
  3279. }
  3280.  
  3281. #else  /* NOXFER */
  3282.  
  3283. #include "ckcdeb.h"
  3284.  
  3285. VOID
  3286. proto() {
  3287.     extern int success;
  3288.     success = 0;
  3289. }
  3290. #endif /* NOXFER */
  3291.