home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku200.tar / ckcpro.c < prev    next >
C/C++ Source or Header  |  2001-12-08  |  109KB  |  3,699 lines

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