home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff236.lzh / XprZmodem / xprzmodem.doc < prev    next >
Text File  |  1989-08-09  |  26KB  |  454 lines

  1.  
  2.                     Documentation for XPRZModem.library
  3.                 Version 1.0, 29 July 1989, by Rick Huebner
  4.  
  5.  
  6.  
  7. 1.  Introduction (or "What is this thing, anyway?")
  8. ---------------------------------------------------
  9.  
  10.      XPRZModem.library is an Amiga shared library (with full Manx C source
  11. code) which provides ZModem file transfer capability to any XPR-compatible
  12. communications program.  The XPR external protocol standard describes an
  13. interface method which allows various file transfer protocols to be
  14. implemented as Amiga shared libraries which may then be used
  15. interchangeably in any compatible communications program.  This takes a
  16. heavy load off of the comm program author, who no longer has to support
  17. scads of different file transfer protocols (many of which are quite tricky
  18. to code) in their program in order to make it widely useful and popular.
  19. The comm program is also smaller and more efficient as a result, since all
  20. those obscure protocols (you know, the ones *you* don't need) are no longer
  21. taking up space.  The XPR standard also helps users, who can mix and match
  22. their favorite file transfer protocols (and implementations thereof) with
  23. their favorite comm programs.  And when new protocols are invented, the
  24. user simply plugs in a new library, and voila!, it's ready to use.
  25. Hopefully, making protocols easy to support will allow more and better comm
  26. programs to be written, as authors can concentrate on their programs
  27. instead of constantly re-inventing the wheel.
  28.  
  29.      Of course, for all of this wonderful stuff to happen, there needs to
  30. be a good selection of these XPR protocol libraries available to the
  31. public.  It's the classic chicken-and-egg problem; comm program authors
  32. won't be motivated to support the XPR standard unless there are a goodly
  33. number of protocols available for it.  And other programmers won't be
  34. motivated to write XPR protocol libraries until there are a goodly number
  35. of comm programs which can use them.  In an effort to do my bit [ B^) ] for
  36. the Amiga community, which has given me so many neat toys to play with over
  37. the past few years, I decided to try and help get the ball rolling.
  38.  
  39.      It just so happens that I run a BBS (see ad at end of file B-)), and I
  40. help work on the BBS software I use (Opus, a popular MS-DOS program [don't
  41. boo and hiss, that's something PClones are well suited for; why waste a
  42. neat machine like an Amiga on sitting around being a BBS all day?]).  And
  43. in that capacity, I wrote the ZModem implementation for Opus back when
  44. ZModem first came out, around 1986.  I went through a period of serious
  45. frustration in the early days of Amiga comm programs, since I'd gone to the
  46. trouble of writing ZModem for my BBS program, and none of my users had a
  47. program which could handle it.  I wasn't yet knowledgeable enough about
  48. programming the Amiga to fix the problem myself, and comm program authors
  49. weren't interested in my ZModem code since it was so MS-DOS-dependant (I
  50. *tried* to give it away), so I had to wait quite a long time before my own
  51. BBS users were able to take advantage of my own ZModem implementation.
  52. Anyway, this means that when I saw the XPR standard published, I was in a
  53. good position to help out.  I had this perfectly good, heavily tested
  54. ZModem code sitting around, and it wasn't very hard to convert that code
  55. into an XPR-type ZModem library.
  56.  
  57.      Hopefully, the early availability of a ZModem library will help
  58. stimulate interest in the XPR standard, resulting in better Amiga telecomms
  59. for all of us.  And by making my source code PD, I hope to help others
  60. interested in writing XPR protocol libraries by giving them some serious
  61. example code.  Also, having ZModem library code readily available to John
  62. Q.  Hacker should help ensure a steady stream of new lemon-fresh enhanced
  63. ZModem libraries (with enzymes) for all of us to use in the future.
  64.  
  65.      Of course, no discussion of the XPR standard would be complete without
  66. giving proper credit to the author, Willy Langeveld of the Stanford Linear
  67. Accelerator Center.  Many thanks are due him for this effort.  If you have
  68. any further questions about the XPR standard, be sure and download the spec;
  69. it should be available on BIX (since he's a sysop there), or on most other
  70. major systems.  And I'll try to keep the current version available on my
  71. BBS, as well.
  72.  
  73.      All files in this archive which are not copyrighted are hereby
  74. released to the public domain (which they were anyway, by way of not being
  75. copyrighted, but I want to make sure YOU realize that).  Do as you like
  76. with them.  Please make lots of copies and distribute them all over the
  77. place, and make lots of derivative works, and everything!  Heck, you can
  78. even publicly perform and/or display this code if you can figure out how...
  79.  
  80.  
  81.  
  82. 2.  Installation (OK, enough chatter; let's get to work)
  83. --------------------------------------------------------
  84.  
  85.      Couldn't be easier.  Just copy the xprzmodem.library file into your
  86. LIBS: directory.  All XPR-compatible comm programs should provide a way for
  87. you to select which XPR protocol you wish to use, either by giving you a
  88. file requester showing LIBS:xpr*.library, or by automatically detecting
  89. these libraries and adding them into their menus.
  90.  
  91. WARNING:  VLT 4.058 appears to have a bug in its xpr_sflush() routine which
  92. causes random Guru 3 crashes (at least on my stock A2000).  Luckily, the
  93. sflush() routine isn't that crucial, so I've included a version of the
  94. library with the sflush() calls commented out for VLT users.  The only
  95. problem caused by not using sflush() is that error recovery and resync when
  96. sending files will be a bit erratic, possibly causing extra timeouts.  The
  97. data should still get sent just fine; the transfer just won't be as
  98. efficient as usual.
  99.  
  100.  
  101.  
  102. 3.  Options
  103. -----------
  104.  
  105.      The XPR standard lays out a way for the comm program user to specify
  106. options for the XPR protocol.  The comm program is supposed to provide some
  107. method of passing an option string to the XPR library before transferring
  108. files.  The precise format and usage of this option string is left up to
  109. the XPR protocol author; the comm program just sends it verbatim.  If an
  110. environment variable is found with the same name as the XPR protocol (i.e.
  111. there's a file in the ENV:  directory called "xprzmodem"), the comm program
  112. is supposed to use this string (contents of file) to initialize the
  113. protocol options.  Also, a menu option or some such should normally be
  114. provided which will allow the user to be prompted for the option string
  115. interactively.
  116.  
  117.      In any case, no matter how your particular comm program feels like
  118. handling it, these are the options supported by this implementation of
  119. ZModem:
  120.  
  121.           T{Y|N|?}    Text translation mode:
  122.              TY = Text Yes; if receiving, translate CR/LF pairs or solo
  123.                   CR chars to normal Amiga LF chars.  Ignore data past ^Z.
  124.                   If sending, suggests to receiver that they should receive
  125.                   this file in text mode.
  126.              TN = Text No; receive file verbatim, without changes.  If
  127.                   sending, suggest to receiver that they receive this
  128.                   file verbatim, without translations.
  129.              T? = Text status unknown; if receiving, use sender's
  130.                   suggestion as to whether to do EOL translations or not.
  131.                   If sending, tell receiver to use default mode, 'cause we
  132.                   don't know either.
  133.  
  134.           O{Y|N|R|S}  Overwrite mode:
  135.              OY = Overwrite Yes; if about to receive file with same name as
  136.                   one which already exists, delete the old file and receive
  137.                   the new file in its place.
  138.              ON = Overwrite No; if about to receive file with same name as
  139.                   one which already exists, append ".dup" onto the name of
  140.                   the new file to keep them separate.
  141.              OR = Overwrite Resume; if about to receive file with same name
  142.                   as one which already exists, resume receiving file data
  143.                   from the current end of the existing file.
  144.              OS = Overwrite Skip; if (etc.), tell sender never mind, skip
  145.                   this file, we don't want it.  Batch transfers will move
  146.                   on to the next file in the set, if any.
  147.  
  148.           Bnnn   Buffer size:
  149.              XPRZModem.library adds a layer of file I/O buffering in
  150.              addition to whatever the comm program may or may not provide.
  151.              This option sets the size of XPRZModem's file I/O buffer in
  152.              kilobytes.  The minimum value is 1 KB, for those using RAM
  153.              drives or fast hard drives, or those whose comm programs
  154.              already provide sufficient buffering.  The maximum value is
  155.              as much contiguous RAM as you have available in your Amiga.
  156.              If you specify more than is actually available, XPRZModem will
  157.              keep decrementing the buffer size requested by 1 KB until the
  158.              memory allocation works.  That way, if your RAM is too
  159.              fragmented to use the amount you request, XPRZModem simply
  160.              uses the largest block available.  Buffering is especially
  161.              helpful for floppy drive users; it keeps your drive from
  162.              continuously gronking and slowing things down all through the
  163.              transfer.
  164.  
  165.           Fnnn   Frame size:
  166.              Although normally avoided, ZModem has the ability to require
  167.              an ACK to be sent from the receiver to the sender every X-many
  168.              data bytes.  Normally you don't want to use this feature,
  169.              because not waiting for ACKs is part of how ZModem works so
  170.              fast.  However, this feature can be very useful in conjunction
  171.              with file I/O buffering on slow devices (namely those floppy
  172.              drives).  If you set up a large I/O buffer to avoid gronking
  173.              your floppy so often, you'll find that when the buffer finally
  174.              *does* get around to being flushed that it can take a looonng
  175.              time; so long, in fact, that the delay can cause timeouts and
  176.              errors.  But if you set your ZModem to require the sender to
  177.              wait for an ACK every buffer's-worth of data, the sender will
  178.              politely wait for you to flush your buffer to the slow floppy
  179.              and send it an ACK saying it's OK to continue now.  This value
  180.              should be set to 0 to disable ACKs (normal mode), or set it to
  181.              the actual number of data bytes allowed between ACKs.  For
  182.              example, if you set B64 because of your floppy, you should
  183.              also set F65536.
  184.  
  185.      Note that the setting for the option must immediately follow the
  186. option character with no intervening characters ("TY", not "T Y" or "T=Y").
  187. When setting multiple options at once, separate the options from each other
  188. with commas and/or spaces; for example, "TN,OR,F0".  You don't have to
  189. specify all options every time; the options you specify will be merged into
  190. the current option settings, replacing their old values.  Upper/lower case
  191. is not significant.  The default option settings if you don't change
  192. anything are "T?,ON,B16,F0".
  193.  
  194.  
  195.  
  196. 4.  Serial port settings
  197. ------------------------
  198.  
  199.      ZModem (at least this implementation of it) requires that your serial
  200. port be set to 8 data bits, no parity, 1 stop bit.  This allows ZModem to
  201. send full 8-bit binary data bytes without having them munged on the way
  202. through the modem.  If your comm program supports the xpr_setserial()
  203. function, XPRZModem will use it to set your serial port to 8N1 before doing
  204. a transfer, and will set your port back the way it was again after it's
  205. done.  If your comm program doesn't support xpr_setserial(), you'll need to
  206. make sure it's in 8N1 mode yourself.
  207.  
  208.      ZModem works well in all serial port handshaking modes; none,
  209. XON/XOFF, or 7-wire/RTS/CTS.  Since any or all of those handshaking modes
  210. may be appropriate at different times, with different modems or remote
  211. systems, XPRZModem lets you set the handshaking mode and doesn't mess with
  212. it.
  213.  
  214.  
  215.  
  216. 5.  Receiving files
  217. -------------------
  218.  
  219.      Once you get the ZModem options and your serial port configuration set
  220. up properly, you're ready to actually use this thing (gasp!).  Receiving
  221. files via ZModem is quite simple.  First, get the file sender going by
  222. using whatever command it wants.  ZModem is a batch file transfer protocol,
  223. meaning that it's capable of transferring several files in a single
  224. exchange, so the remote system may allow you to specify multiple files to
  225. be sent to you at one time.  It may also allow you to use wildcard
  226. characters in the filename(s); this is all system dependant.
  227.  
  228.      Once you've gotten the sender going, use whatever option your comm
  229. program provides to begin receiving files with ZModem; this will usually be
  230. a menu option or button gadget.  The comm program should now prompt you for
  231. the name of the file to be received.  Here's the only non-obvious part of
  232. receiving files; because of the interchangeability of XPR libraries, the
  233. comm program has no way of knowing whether your chosen protocol is a batch
  234. protocol or a single file protocol.  Batch protocols send the names of the
  235. files being transferred along with the data, so the receiving program
  236. doesn't choose the name; you just tell the comm program what directory to
  237. receive the files into, and they are automatically named correctly.
  238. However, single-file protocols like good ol' XModem don't send the filename
  239. with the data, and the receiving comm program has to name the file.  So...
  240. the upshot of all this is that your comm program will probably ask you for
  241. the name of the file to be received, whereas all you need to tell a ZModem
  242. receiver is the name of the directory to put the files into.  The way
  243. XPRZModem handles this is for you to just specify a dummy filename in the
  244. directory which you want to put the files in.  XPRZModem will use the
  245. directory portion of the filename you specify, and will append the actual
  246. names of the received files onto this directory path in order to create the
  247. received files.  So if you want your received files to go into
  248. "HD:Uploads", tell your comm program the name of the file being received is
  249. "HD:Uploads/x" or something similar.  Once you enter the dummy filename,
  250. ZModem should automatically transfer all of the files you specified into
  251. that directory.
  252.  
  253.      Make sure that you have set the ZModem options properly before
  254. starting the transfer; especially, make sure you only use TY if you know
  255. that all of the files being transferred in this batch are printable ASCII
  256. text files.  If you use TY on normal binary files like .ARCs or .ZOOs,
  257. they'll be mangled beyond use.
  258.  
  259.  
  260.  
  261. 6.  Sending files
  262. -----------------
  263.  
  264.      Sending files using ZModem is fairly straightforward.  First, activate
  265. the file receiver with whatever command the remote system requires.  You
  266. may or may not need to specify a filename or directory to the remote
  267. system; this depends on their implementation of ZModem.  Once the remote
  268. system is ready to receive files, activate your comm program's ZModem send
  269. function.  Your comm program will prompt you for which file(s) to send.
  270. Although ZModem is a batch protocol, your comm program may or may not allow
  271. you to specify multiple file names to be sent; also, wildcards may or may
  272. not be supported.  These decisions are up to the comm program author;
  273. ZModem will handle multiple files and wildcards if the comm program allows
  274. them.  Once you've specified the file name(s), the file(s) will be sent to
  275. the remote system.  Note that the directory paths of the files you send
  276. will not be included in the filenames sent to the other system; only the
  277. filename portion will be sent.  Also, note that the T option serves only as
  278. a suggestion to the receiving system when sending files; the receiver makes
  279. the final decision as to whether to take your advice or to force the files
  280. to be received in text or binary mode.
  281.  
  282.      If errors occur while sending the file(s), you'll probably notice a
  283. small enhancement I made to the normal ZModem error recovery procedures.
  284. Normally, file transfer protocols have to compromise between efficient data
  285. transmission on good, clean phone lines and quick error recovery on bad,
  286. noisy phone lines.  If you pick a large packet size, you get high
  287. throughput on clean lines due to low packet overhead, but you have slow
  288. recovery times and large amounts of retransmitted data on noisy lines.  If
  289. you've used YModem on noisy lines you've seen this problem.  But, if you
  290. use small packets to reduce retransmitted data on noisy lines, you increase
  291. the amount of time the protocol spends sending packet overhead, and your
  292. throughput suffers.  The solution is to vary the block size according to
  293. the experienced error rate during the transfer.  That way you aren't stuck
  294. with a rigid packet length which will sometimes be the wrong size no matter
  295. what.  I came up with this idea back when I first wrote the ZModem code for
  296. Opus, and cleared it for future compatibility with ZModem's designer, Chuck
  297. Forsberg, back then.  Since then the basic concept has been extensively
  298. tested in the Opus BBS system, and has proven quite effective; it has also
  299. been incorporated into various other ZModem implementations over time.  The
  300. actual algorithm for deciding what size packets to use when is pretty much
  301. up to the protocol author; XPRZModem uses a modified version of the Opus
  302. algorithm which prevents locking the packet size at a small value when a
  303. large one-time burst of errors occurs.
  304.  
  305.  
  306.  
  307. 7.  Notes for comm program authors
  308. ----------------------------------
  309.  
  310.      That's pretty much everything you need to know in order to use
  311. XPRZModem properly.  Here are some notes for the "other" XPR standard
  312. users, namely the comm program authors:
  313.  
  314.      Certain XPR callback functions *must* be implemented by the comm
  315. program author in order for XPRZModem to be used.  If any of these
  316. functions are not supported by your comm program, XPRZModem will display an
  317. error message and abort when invoked.  These required functions are:
  318.  
  319.           xpr_fopen(), xpr_fclose(), xpr_fread(), xpr_fwrite(),
  320.           xpr_fseek(), xpr_sread(), xpr_swrite(), and xpr_update()
  321.  
  322.      The xpr_update() function provides many data fields for your comm
  323. program to potentially display to the user.  These are the XPR_UPDATE
  324. struct elements which XPRZModem will keep updated during transfers:
  325.  
  326.           xpru_protocol, xpru_filename, xpru_filesize, xpru_msg,
  327.           xpru_errormsg, xpru_blocks, xpru_blocksize, xpru_bytes,
  328.           xpru_errors, xpru_timeouts, xpru_blockcheck, xpru_expecttime,
  329.           xpru_elapsedtime, and xpru_datarate
  330.  
  331.      As you can see, XPRZModem tries to provide as many status fields as
  332. possible.  Although all of them are useful, the ones which are most
  333. important to ZModem users are filename, filesize, msg and/or errormsg, and
  334. bytes.  Please try to provide at least these fields in your status display,
  335. plus as many of the rest as you can manage.
  336.  
  337.      Although only the XPR callback functions listed above are crucial for
  338. XPRZModem, all of them are used if they are provided.  Although XPRZModem
  339. will function without any of the other routines, its performance or
  340. capabilities may be degraded somewhat.  Specifically, this is what you give
  341. up if you choose not to supply any of these other XPR callback functions:
  342.  
  343.           xpr_sflush(): Used when performing error recovery and resync
  344.                when sending files.  If not provided, extra timeout errors
  345.                and delayed error recovery will be likely.  The files will
  346.                still be transferred properly, but errors will degrade
  347.                overall throughput more than usual.
  348.  
  349.           xpr_chkabort(): Called between sending or receiving packets.
  350.                If not provided, there's no way for your comm program user
  351.                to abort a transfer in progress except by trying to somehow
  352.                force it to decide to give up and abort on its own, such as
  353.                by turning off the modem and hoping the protocol will abort
  354.                after enough timeouts.
  355.  
  356.            xpr_chkmisc(): Also called between sending or receiving packets.
  357.                Actually, this is the one routine which doesn't cause any
  358.                problems if missing.  If you don't need a timeslice while
  359.                the transfer is going, don't provide it.
  360.  
  361.            xpr_gets(): Called to prompt the user interactively for options
  362.                when your comm program invokes XProtocolSetup() with a null
  363.                xpr_filename field.  If not provided, you'll have to prompt
  364.                the user for the options string yourself, and pass this
  365.                string in xpr_filename when invoking XProtocolSetup().
  366.  
  367.            xpr_setserial(): Called to obtain the current serial port
  368.                settings, and to change the serial port to 8N1 if it's not
  369.                already set that way.  If not provided, XPRZModem will
  370.                assume all transfers are being done at 2400 bps, which
  371.                won't hurt anything, and your users will have to make sure
  372.                that the serial port is set to 8N1 themselves.
  373.  
  374.            xpr_ffirst() and xpr_fnext(): If either of these routines are
  375.                missing, XPRZModem will lose the ability to send multiple
  376.                files in a batch.  The xpr_filename pointer passed to
  377.                XProtocolSend() will be assumed to point to the actual full
  378.                filename of the single file to be sent in this batch.  If
  379.                both of these routines are provided, XPRZModem will rely
  380.                upon them completely to obtain the names of the files to
  381.                send, and the xpr_filename pointer will not be used for any
  382.                purpose by XPRZModem except to be passed to ffirst/fnext.
  383.                This gives your comm program a way to send not just a single
  384.                filename template's worth of files in a batch, but a list of
  385.                different filenames.  If, for example, you set xpr_filename
  386.                to point to the first node of a linked list of filenames
  387.                and/or templates to be sent, rather than just having it
  388.                point to a string, you can have your ffirst and fnext
  389.                routines traverse this linked list in order to determine the
  390.                next file to be sent.  Or you could have xpr_filename point
  391.                to a buffer containing a list of filenames separated by
  392.                commas, and your ffirst/fnext routines could return each
  393.                filename in this list in turn.  The key here is that if you
  394.                provide these two routines, you're in complete control over
  395.                the series of names fed to XProtocolSend.  If you omit these
  396.                routines, XPRZModem is stuck with single-file mode.  Once
  397.                again, if these two routines are provided, XPRZModem will
  398.                *always* call them; it makes no attempt to use the
  399.                xpr_filename pointer for anything itself.  This is not
  400.                explicitly spelled out in the XPR standard, but it seems the
  401.                only reasonable way to handle batch protocols to me.
  402.                Hopefully other XPR library authors will follow this
  403.                precedent as well, so that comm program authors will be able
  404.                to count on multiple-filename batch sessions being handled
  405.                properly.
  406.  
  407.            xpr_finfo(): Used to determine the filesize of files being sent,
  408.                in order to tell the receiving system how big they are.
  409.                Also used to determine the size of a file which already
  410.                exists when in Overwrite Resume mode; XPRZModem must be able
  411.                to get the size of the current portion of the file in order
  412.                to be able to tell the sender where to resume sending from.
  413.                If this routine isn't provided, Overwrite Resume mode is
  414.                not allowed.
  415.  
  416.  
  417.  
  418. 8.  The future
  419. --------------
  420.  
  421.      I don't want or expect this to be the last or only XPR ZModem library
  422. available.  There are a lot of less-commonly-used ZModem features which
  423. have popped up over the past few years, and many people might like to see
  424. some of them made available.  Such as 32-bit CRC (although I consider
  425. CRC-16 perfectly adequate for the max 1K packets sent by ZModem), full
  426. control-character escaping, or maybe 8th bit escaping to allow use of 7-bit
  427. serial channels.  I didn't want to add a bunch of rarely-used bells and
  428. whistles to this version of the library, because I want it to be able to
  429. serve as comprehensible example code.  I just want to provide a good solid
  430. ZModem which reliably handles the majority of people's needs.  Hopefully,
  431. this will serve as a foundation for future enhanced versions, while
  432. providing a safe fallback for people to come back to if that fancy new
  433. enhanced version (with neo-maxi zoomed weebies) turns out to need some more
  434. debugging.
  435.    
  436.      Bug reports, questions, or comments may be sent to me at:
  437.  
  438.           BIX: rahuebner
  439.           Usenet: rhuebner@cup.portal.com
  440.           Compu$erve: 73105,1022
  441.  
  442.      Or, if you think it's important, and you want an answer in less than a
  443. week or two, call my BBS:
  444.  
  445.           Amiga++
  446.           1-402-291-3636
  447.           1200-9600 bps, HST or V.32
  448.           FidoNet node 1:285/614
  449.  
  450.      I check the messages on my BBS at least once a day, so that's where to
  451. get ahold of me quick.  I'll also try and stock the latest XPR standard
  452. spec and XPR libraries there, in addition to the best collection of Amiga
  453. PD software in the MidWest ( <- blatant ad ).
  454.