home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckc072.zip / ckcmai.c < prev    next >
C/C++ Source or Header  |  1989-02-02  |  14KB  |  327 lines

  1. char *versio = "C-Kermit, 4E(072) 24 Jan 89";
  2.  
  3. /*  C K C M A I  --  C-Kermit Main program  */
  4.  
  5. /*
  6.  4E, add long packet support, plus changes for Apollo and Data General
  7.  support from SAS Institute, and for Macintosh from Planning Research Corp,
  8.  plus several important bug fixes.
  9. */
  10. /*
  11.  Author: Frank da Cruz (fdc@cunixc.cc.columbia.edu, FDCCU@CUVMA.BITNET),
  12.  Columbia University Center for Computing Activities.
  13.  First released January 1985.
  14.  Copyright (C) 1985, 1989, Trustees of Columbia University in the City of New 
  15.  York.  Permission is granted to any individual or institution to use, copy, or
  16.  redistribute this software so long as it is not sold for profit, provided this
  17.  copyright notice is retained. 
  18. */
  19. /*
  20.  The Kermit file transfer protocol was developed at Columbia University.
  21.  It is named after Kermit the Frog, star of the television series THE
  22.  MUPPET SHOW; the name is used by permission of Henson Associates, Inc.
  23.  "Kermit" is also Celtic for "free".
  24. */
  25. /*
  26.  Thanks to Herm Fischer of Encino CA for extensive contributions to version 4,
  27.  and to the following people for their contributions over the years:
  28.  
  29.    Larry Afrin, Clemson U
  30.    Robert Andersson, Oslo, Norway
  31.    Stan Barber, Rice U
  32.    Charles Brooks, EDN
  33.    Mike Brown, Purdue U
  34.    Bill Catchings, formerly of CUCCA
  35.    Bob Cattani, Columbia U CS Dept
  36.    Howard Chu, U of Michigan
  37.    Bill Coalson, McDonnell Douglas
  38.    Alan Crosswell, CUCCA
  39.    Jeff Damens, formerly of CUCCA
  40.    Joe R. Doupnik, Utah State U
  41.    Glenn Everhart, RCA Labs
  42.    Carl Fongheiser, CWRU
  43.    John Gilmore, UC Berkeley
  44.    Yekta Gursel, MIT
  45.    Jim Guyton, Rand Corp
  46.    Stan Hanks, Rice U.
  47.    Ken Harrenstein, SRI
  48.    Chuck Hedrick, Rutgers U
  49.    Ron Heiby, Motorola Micromputer Division
  50.    Steve Hemminger, Tektronix
  51.    Randy Huntziger, NLM
  52.    Phil Julian, SAS Institute
  53.    Jim Knutson, U of Texas at Austin
  54.    John Kunze, UC Berkeley
  55.    David Lawyer, UC Irvine
  56.    S.O. Lidie, Lehigh U
  57.    Chris Maio, Columbia U CS Dept
  58.    Leslie Mikesall, American Farm Bureau
  59.    Martin Minow, DEC
  60.    Ray Moody, Purdue U
  61.    Tony Movshon, NYU
  62.    Dan Murphy, ???
  63.    Jim Noble, Planning Research Corporation
  64.    Paul Placeway, Ohio State U
  65.    Ken Poulton, HP Labs
  66.    Frank Prindle, NADC
  67.    Anton Rang, ???
  68.    Scott Ribe, ???
  69.    Jack Rouse, SAS Institute
  70.    Stew Rubenstein, Harvard
  71.    Dan Schullman, DEC
  72.    Gordon Scott, Micro Focus, Newbury UK
  73.    David Sizeland, U of London Medical School
  74.    Bradley Smith, UCLA
  75.    Andy Tanenbaum, THE, Netherlands
  76.    Markku Toijala, Helsinki U of Technology
  77.    Dave Tweten, AMES-NAS
  78.    Walter Underwood, Ford Aerospace
  79.    Pieter Van Der Linden, Centre Mondial (Paris)
  80.    Wayne Van Pelt, GE/CRD
  81.    Mark Vasoll & Gregg Wonderly, Oklahoma State University
  82.    Stephen Walton, Ametek Computer
  83.    Lauren Weinstein
  84.    Joachim Wiesel, U of Karlsruhe
  85.    Dave Woolley, CAP Communication Systems, London
  86.    John Zeeff, Ann Arbor, MI
  87.  
  88.  and many others.
  89. */
  90.  
  91. #include "ckcsym.h"            /* Macintosh needs this */
  92. #include "ckcker.h"
  93. #include "ckcdeb.h"
  94.  
  95. /* Text message definitions.. each should be 256 chars long, or less. */
  96. #ifdef MAC
  97. char *hlptxt = "\r\
  98. MacKermit Server Commands:\r\
  99. \r\
  100.     BYE\r\
  101.     FINISH\r\
  102.     GET filespec\r\
  103.     REMOTE CWD directory\r\
  104.     REMOTE HELP\r\
  105.     SEND filespec\r\
  106. \r\0";
  107. #else
  108. #ifdef AMIGA
  109. char *hlptxt = "C-Kermit Server Commands:\n\
  110. \n\
  111. GET filespec, SEND filespec, FINISH, BYE, REMOTE HELP\n\
  112. \n\0";
  113. #else
  114. char *hlptxt = "C-Kermit Server REMOTE Commands:\n\
  115. \n\
  116. GET files  REMOTE CWD [dir]    REMOTE DIRECTORY [files]\n\
  117. SEND files REMOTE SPACE [dir]  REMOTE HOST command\n\
  118. FINISH     REMOTE DELETE files REMOTE WHO [user]\n\
  119. BYE        REMOTE HELP         REMOTE TYPE files\n\
  120. \n\0";
  121. #endif
  122. #endif
  123. char *srvtxt = "\r\n\
  124. C-Kermit server starting.  Return to your local machine by typing\r\n\
  125. its escape sequence for closing the connection, and issue further\r\n\
  126. commands from there.  To shut down the C-Kermit server, issue the\r\n\
  127. FINISH or BYE command and then reconnect.\n\
  128. \r\n\0";
  129.  
  130. /* Declarations for Send-Init Parameters */
  131.  
  132. int spsiz = DSPSIZ,                     /* Biggest packet size we can send */
  133.     spsizf = 0,                         /* Flag to override what you ask for */
  134.     rpsiz = DRPSIZ,                     /* Biggest we want to receive */
  135.     urpsiz = DRPSIZ,            /* User-requested rpsiz */
  136.     maxrps = MAXRP,            /* Maximum incoming long packet size */
  137.     maxsps = MAXSP,            /* Maximum outbound l.p. size */
  138.     maxtry = MAXTRY,            /* Maximum retries per packet */
  139.     wsize = 1,                /* Window size */
  140.     timint = DMYTIM,                    /* Timeout interval I use */
  141.     rtimo = URTIME,                     /* Timeout I want you to use */
  142.     timef = 0,                          /* Flag to override what you ask */
  143.     npad = MYPADN,                      /* How much padding to send */
  144.     mypadn = MYPADN,                    /* How much padding to ask for */
  145.     bctr = 1,                           /* Block check type requested */
  146.     bctu = 1,                           /* Block check type used */
  147.     ebq =  MYEBQ,                       /* 8th bit prefix */
  148.     ebqflg = 0,                         /* 8th-bit quoting flag */
  149.     rqf = -1,                /* Flag used in 8bq negotiation */
  150.     rq = 0,                /* Received 8bq bid */
  151.     sq = 'Y',                /* Sent 8bq bid */
  152.     rpt = 0,                            /* Repeat count */
  153.     rptq = MYRPTQ,                      /* Repeat prefix */
  154.     rptflg = 0;                         /* Repeat processing flag */
  155.  
  156. int capas = 10,                /* Position of Capabilities */
  157.     atcapb = 8,                /* Attribute capability */
  158.     atcapr = 0,                /*  requested */
  159.     atcapu = 0,                /*  used */
  160.     swcapb = 4,                /* Sliding Window capability */
  161.     swcapr = 0,                /*  requested */
  162.     swcapu = 0,                /*  used */
  163.     lpcapb = 2,                /* Long Packet capability */
  164.     lpcapr = 1,                /*  requested */
  165.     lpcapu = 0;                /*  used */
  166.  
  167. CHAR padch = MYPADC,                    /* Padding character to send */
  168.     mypadc = MYPADC,                    /* Padding character to ask for */
  169.     seol = MYEOL,                       /* End-Of-Line character to send */
  170.     eol = MYEOL,                        /* End-Of-Line character to look for */
  171.     ctlq = CTLQ,                        /* Control prefix in incoming data */
  172.     myctlq = CTLQ;                      /* Outbound control character prefix */
  173.  
  174.  
  175. /* Packet-related variables */
  176.  
  177. int pktnum = 0,                         /* Current packet number */
  178.     prvpkt = -1,                        /* Previous packet number */
  179.     sndtyp,                             /* Type of packet just sent */
  180.     rsn,                /* Received packet sequence number */
  181.     rln,                /* Received packet length */
  182.     size,                               /* Current size of output pkt data */
  183.     osize,                              /* Previous output packet data size */
  184.     maxsize,                            /* Max size for building data field */
  185.     spktl = 0;                /* Length packet being sent */
  186.  
  187. CHAR sndpkt[MAXSP+100],                 /* Entire packet being sent */
  188.     recpkt[MAXRP+200],                  /* Packet most recently received */
  189.     *rdatap,                /* Pointer to received packet data */
  190.     data[MAXSP+4],            /* Packet data buffer */
  191.     srvcmd[MAXRP+4],                    /* Where to decode server command */
  192.     *srvptr,                            /* Pointer to above */
  193.     mystch = SOH,                       /* Outbound packet-start character */
  194.     stchr = SOH;                        /* Incoming packet-start character */
  195.  
  196. /* File-related variables */
  197.  
  198. #ifdef datageneral
  199. CHAR filnam[256];                       /* Name of current file. */
  200. #else
  201. CHAR filnam[50];                        /* Name of current file. */
  202. #endif
  203.  
  204. int nfils;                              /* Number of files in file group */
  205. long fsize;                             /* Size of current file */
  206.  
  207. /* Communication line variables */
  208.  
  209. CHAR ttname[50];                        /* Name of communication line. */
  210.  
  211. int parity,                             /* Parity specified, 0,'e','o',etc */
  212.     flow,                               /* Flow control, 1 = xon/xoff */
  213.     speed = -1,                         /* Line speed */
  214.     turn = 0,                           /* Line turnaround handshake flag */
  215.     turnch = XON,                       /* Line turnaround character */
  216.     duplex = 0,                         /* Duplex, full by default */
  217.     escape = 034,                       /* Escape character for connect */
  218.     delay = DDELAY,                     /* Initial delay before sending */
  219.     mdmtyp = 0;                         /* Modem type (initially none)  */
  220.  
  221.     int tlevel = -1;            /* Take-file command level */
  222.  
  223. /* Statistics variables */
  224.  
  225. long filcnt,                    /* Number of files in transaction */
  226.     flci,                       /* Characters from line, current file */
  227.     flco,                       /* Chars to line, current file  */
  228.     tlci,                       /* Chars from line in transaction */
  229.     tlco,                       /* Chars to line in transaction */
  230.     ffc,                        /* Chars to/from current file */
  231.     tfc;                        /* Chars to/from files in transaction */
  232.  
  233. int tsecs;                      /* Seconds for transaction */
  234.  
  235. /* Flags */
  236.  
  237. int deblog = 0,                         /* Flag for debug logging */
  238.     pktlog = 0,                         /* Flag for packet logging */
  239.     seslog = 0,                         /* Session logging */
  240.     tralog = 0,                         /* Transaction logging */
  241.     displa = 0,                         /* File transfer display on/off */
  242.     stdouf = 0,                         /* Flag for output to stdout */
  243.     xflg   = 0,                         /* Flag for X instead of F packet */
  244.     hcflg  = 0,                         /* Doing Host command */
  245.     fncnv  = 1,                         /* Flag for file name conversion */
  246.     binary = 0,                         /* Flag for binary file */
  247.     savmod = 0,                         /* Saved file mode */
  248.     cmask  = 0177,            /* Connect byte mask */
  249.     fmask  = 0377,            /* File byte mask */
  250.     warn   = 0,                         /* Flag for file warning */
  251.     quiet  = 0,                         /* Be quiet during file transfer */
  252.     local  = 0,                         /* Flag for external tty vs stdout */
  253.     server = 0,                         /* Flag for being a server */
  254.     cnflg  = 0,                         /* Connect after transaction */
  255.     cxseen = 0,                         /* Flag for cancelling a file */
  256.     czseen = 0,                         /* Flag for cancelling file group */
  257.     keep = 0;                           /* Keep incomplete files */
  258.  
  259. /* Variables passed from command parser to protocol module */
  260.  
  261. char parser();                          /* The parser itself */
  262. char sstate  = 0;                       /* Starting state for automaton */
  263. char *cmarg  = "";                      /* Pointer to command data */
  264. char *cmarg2 = "";                      /* Pointer to 2nd command data */
  265. char **cmlist;                          /* Pointer to file list in argv */
  266.  
  267. /* Miscellaneous */
  268.  
  269. char **xargv;                           /* Global copies of argv */
  270. int  xargc;                             /* and argc  */
  271.  
  272. extern char *dftty;                     /* Default tty name from ckx???.c */
  273. extern int dfloc;                       /* Default location: remote/local */
  274. extern int dfprty;                      /* Default parity */
  275. extern int dfflow;                      /* Default flow control */
  276.  
  277. /*  M A I N  --  C-Kermit main program  */
  278.  
  279. #ifdef apollo
  280. /* On the Apollo, intercept main to insert a cleanup handler */
  281. ckcmai(argc,argv) int argc; char **argv; {
  282. #else
  283. main(argc,argv) int argc; char **argv; {
  284. #endif
  285.  
  286.     char *strcpy();
  287.  
  288. /* Do some initialization */
  289.  
  290.     xargc = argc;                       /* Make global copies of argc */
  291.     xargv = argv;                       /* ...and argv. */
  292.     sstate = 0;                         /* No default start state. */
  293.     strcpy(ttname,dftty);               /* Set up default tty name. */
  294.     local = dfloc;                      /* And whether it's local or remote. */
  295.     parity = dfprty;                    /* Set initial parity, */
  296.     flow = dfflow;                      /* and flow control. */
  297.     if (sysinit() < 0) doexit(BAD_EXIT); /* And system-dependent things. */
  298.  
  299. /*** attempt to take ini file before doing command line ***/
  300.  
  301.     cmdini();                /* Sets tlevel */
  302.     while (tlevel > -1) {        /* Execute init file. */
  303.     sstate = parser();        /* Loop getting commands. */
  304.         if (sstate) proto();            /* Enter protocol if requested. */
  305.     }
  306.  
  307. /* Look for a UNIX-style command line... */
  308.  
  309.     if (argc > 1) {                     /* Command line arguments? */
  310.         sstate = cmdlin();              /* Yes, parse. */
  311.         if (sstate) {
  312.             proto();                    /* Take any requested action, then */
  313.             if (!quiet) conoll("");     /* put cursor back at left margin, */
  314.             if (cnflg) conect();        /* connect if requested, */
  315.             doexit(GOOD_EXIT);          /* and then exit with status 0. */
  316.         }
  317.     }
  318.  
  319. /* If no action requested on command line, enter interactive parser */
  320.  
  321.     herald();                /* Display program herald. */
  322.     while(1) {                /* Loop getting commands. */
  323.     sstate = parser();
  324.         if (sstate) proto();            /* Enter protocol if requested. */
  325.     }
  326. }
  327.