home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / tmp9 / p.h < prev    next >
C/C++ Source or Header  |  2002-01-20  |  43KB  |  1,394 lines

  1. /*****************************************************************************/
  2. /*             Copyright (c) 1994 by Jyrki Salmi <jytasa@jyu.fi>             */
  3. /*        You may modify, recompile and distribute this file freely.         */
  4. /*****************************************************************************/
  5.  
  6. #ifndef _P_H_
  7. #define _P_H_
  8.  
  9. #include "p_type.h"             /* U32, U16, U8, etc typedefs */
  10.  
  11. #ifdef __EMX__
  12. #define _System                 /* EMX/GCC doesn't have _System */
  13. #endif
  14. #ifdef _WIN32
  15. #define _System         /* Neither does Win32 */
  16. #define _Inline __inline
  17. #define APIRET DWORD
  18. #endif /* _WIN32 */
  19.  
  20. /******************/
  21. /* Protocol types */
  22. /******************/
  23.  
  24. #define PROTOCOL_X                      0x01    /* Xmodem */
  25. #define PROTOCOL_Y                      0x02    /* Ymodem */
  26. #define PROTOCOL_G                      0x03    /* Ymodem-g */
  27. #define PROTOCOL_Z                      0x04    /* Zmodem */
  28.  
  29.  
  30. /****************************************/
  31. /* Supported communication device types */
  32. /****************************************/
  33.  
  34. #define DEV_TYPE_ASYNC                  0x01 /* COM1, COM2, COM3, etc. */
  35. #define DEV_TYPE_PIPE                   0x02 /* OS/2's named pipe */
  36. #define DEV_TYPE_SOCKET                 0x03 /* TCP/IP's stream socket */
  37. #define DEV_TYPE_EXE_IO                 0x04 /* Use EXE I/O system */
  38.  
  39. /***************/
  40. /* Error types */
  41. /***************/
  42.  
  43. #define is_os2_error(i)         (i < 0x30) /* A macro used to distinguish */
  44.                                            /* OS/2 API errors from others */
  45.  
  46. #define P_ERROR_DOSOPEN                 0x01
  47.  /* Optional argument:
  48.   *  dev_path from P_CFG structure passed to p_transfer() function.
  49.   */
  50. #define P_ERROR_DOSCLOSE                0x02
  51.  /* Optional argument: same as with P_ERROR_DOSOPEN */
  52.  
  53. #define P_ERROR_DOSREAD                 0x03
  54.  /* Optional argument: same as with P_ERROR_DOSOPEN */
  55.  
  56. #define P_ERROR_DOSWRITE                0x04
  57.  /* Optional argument: same as with P_ERROR_DOSOPEN */
  58.  
  59. #define P_ERROR_DOSDEVIOCTL             0x05
  60.  /* Optional argument: same as with P_ERROR_DOSOPEN */
  61.  
  62. #define P_ERROR_DOSALLOCMEM             0x06
  63.  /* Optional argument: Number of bytes we tried to allocate (U32) */
  64.  
  65. #define P_ERROR_DOSFREEMEM              0x07
  66.  /* Optional argument: None (NULL) */
  67.  
  68. /*************************/
  69. /* Named pipe API errors */
  70. /*************************/
  71.  
  72. #define P_ERROR_DOSCREATENPIPE          0x08
  73.  /* Optional argument: same as with P_ERROR_DOSOPEN */
  74.  
  75. #define P_ERROR_DOSCONNECTNPIPE         0x09
  76.  /* Optional argument: same as with P_ERROR_DOSOPEN */
  77.  
  78. #define P_ERROR_DOSDISCONNECTNPIPE      0x0a
  79.  /* Optional argument: same as with P_ERROR_DOSOPEN */
  80.  
  81. #define P_ERROR_DOSPEEKNPIPE            0x0b
  82.  /* Optional argument: same as with P_ERROR_DOSOPEN */
  83.  
  84. #define P_ERROR_DOSSETNPHSTATE          0x0c
  85.  /* Optional argument: same as with P_ERROR_DOSOPEN */
  86.  
  87. /******************/
  88. /* DLL API errors */
  89. /******************/
  90.  
  91. #define P_ERROR_DOSLOADMODULE           0x0d
  92.  /* Optional argument: Name of DLL we tried to load (U8 *) */
  93.  
  94. #define P_ERROR_DOSFREEMODULE           0x0e
  95.  /* Optional argument: Name of DLL we tried to free (U8 *) */
  96.  
  97. #define P_ERROR_DOSQUERYPROCADDR        0x0f
  98.  /* Optional argument: Name of procedure we queried for (U8 *) */
  99.  
  100. /*********************/
  101. /* Socket API errors */
  102. /*********************/
  103.  
  104. #define is_tcpip_error(i)               (i >= 0x30) /* A macro used to */
  105.                                                     /* distinguish TCP/IP */
  106.                                                     /* API errors from */
  107.                                                     /* others */
  108.  
  109. #define P_ERROR_SOCK_INIT               0x30
  110.  /* Optional argument: None (NULL) */
  111.  
  112. #define P_ERROR_IOCTL                   0x31
  113.  /* Optional argument: Handle of socket error occurred with (U32) */
  114.  
  115. #define P_ERROR_RECV                    0x32
  116.  /* Optional argument: Handle of socket error occurred with (U32) */
  117.  
  118. #define P_ERROR_SEND                    0x33
  119.  /* Optional argument: Handle of socket error occurred with (U32) */
  120.  
  121. #define P_ERROR_SOCKET                  0x34
  122.  /* Optional argument: None (NULL) */
  123.  
  124. #define P_ERROR_BIND                    0x35
  125.  /* Optional argument: Handle of socket error occurred with (U32) */
  126.  
  127. #define P_ERROR_LISTEN                  0x36
  128.  /* Optional argument: Handle of socket error occurred with (U32) */
  129.  
  130. #define P_ERROR_ACCEPT                  0x37
  131.  /* Optional argument: Handle of socket error occurred with (U32) */
  132.  
  133. #define P_ERROR_GETHOSTBYADDR           0x38
  134.  /* Optional argument: The address we tried to resolve (U8 *) */
  135.  
  136. #define P_ERROR_GETHOSTBYNAME           0x39
  137.  /* Optional argument: The address we tried to resolve (U8 *) */
  138.  
  139. #define P_ERROR_CONNECT                 0x3A
  140.  /* Optional argument: Handle of socket error occurred with (U32) */
  141.  
  142. #define P_ERROR_SETSOCKOPT              0x3B
  143.  /* Optional argument: Handle of socket error occurred with (U32) */
  144.  
  145. #define P_ERROR_GETSOCKOPT              0x3C
  146.  /* Optional argument: Handle of socket error occurred with (U32) */
  147.  
  148. #define P_ERROR_SELECT                  0x3D
  149.  /* Optional argument: Handle of socket error occurred with (U32) */
  150.  
  151.  
  152. /***********************/
  153. /* Zmodem header types */
  154. /***********************/
  155.  
  156. /* One of these is passed as an argument for PS_HEADER ja PS_INVALID_HEADER */
  157. /* messages. It's not necessary really to understand the meaning of these. */
  158.  
  159. #define HEADER_TIMEOUT                  0
  160. #define HEADER_RQINIT                   1
  161. #define HEADER_RINIT                    2
  162. #define HEADER_SINIT                    3
  163. #define HEADER_ACK                      4
  164. #define HEADER_FILE                     5
  165. #define HEADER_SKIP                     6
  166. #define HEADER_NAK                      7
  167. #define HEADER_ABORT                    8
  168. #define HEADER_FIN                      9
  169. #define HEADER_RPOS                     10
  170. #define HEADER_DATA                     11
  171. #define HEADER_EOF                      12
  172. #define HEADER_FERR                     13
  173. #define HEADER_CRC                      14
  174. #define HEADER_CHALLENGE                15
  175. #define HEADER_COMPL                    16
  176. #define HEADER_CAN                      17
  177. #define HEADER_FREECNT                  18
  178. #define HEADER_COMMAND                  19
  179. #define HEADER_STDERR                   20
  180.  
  181. /*
  182.    Zmodem headers in string format if one wants to display them in the
  183.    caller program.
  184.  
  185.    U8 *z_header[] = {
  186.  
  187.    "TIMEOUT",
  188.    "ZRQINIT",
  189.    "ZRINIT",
  190.    "ZSINIT",
  191.    "ZACK",
  192.    "ZFILE",
  193.    "ZSKIP",
  194.    "ZNAK",
  195.    "ZABORT",
  196.    "ZFIN",
  197.    "ZRPOS",
  198.    "ZDATA",
  199.    "ZEOF",
  200.    "ZFERR",
  201.    "ZCRC",
  202.    "ZCHALLENGE",
  203.    "ZCOMPL",
  204.    "ZCAN",
  205.    "ZFREECNT",
  206.    "ZCOMMAND",
  207.    "ZSTDERR"
  208.    };
  209. */
  210.  
  211. /**************/
  212. /* Frame ends */
  213. /**************/
  214.  
  215. #define FRAME_TIMEOUT                   0   /* Frame receive routine has */
  216.                                             /* timed out */
  217. #define FRAME_CRCE                      1   /* Frame end indicating end of */
  218.                                             /* transfer*/
  219. #define FRAME_CRCG                      2   /* Frame end inditcating */
  220.                                             /* continuous data flow */
  221. #define FRAME_CRCQ                      3   /* Frame end expecting */
  222.                                             /* an acknowledge */
  223. #define FRAME_CRCW                      4   /* Frame end indicating that */
  224.                                             /* a Zmodem header will follow */
  225.                                             /* instead of next frame */
  226. #define FRAME_ERROR                     5   /* An error has occurred while */
  227.                                             /* receiving a frame */
  228. #define FRAME_CAN                       6   /* Other end has sent a CAN */
  229.                                             /* sequence while we were */
  230.                                             /* trying to receive a frame */
  231.  
  232. /*
  233.    Frame ends in string format:
  234.  
  235.    U8 *z_frame_end[] = {
  236.  
  237.    "TIMEOUT",
  238.    "ZCRCE",
  239.    "ZCRCG",
  240.    "ZCRCQ",
  241.    "ZCRCW",
  242.    "ZERROR",
  243.    "ZCAN"
  244.    };
  245. */
  246.  
  247. /*********************************************/
  248. /* PS_Z_RECEIVER_FLAGS parameter's bit masks */
  249. /*********************************************/
  250.  
  251. #define RZ_FLAG_CANFDX                  0x01 /* Receiver is capable of true */
  252.                                              /* full duplex transfer */
  253. #define RZ_FLAG_CANOVIO                 0x02 /* Receiver can receive data */
  254.                                              /* during disk I/O */
  255. #define RZ_FLAG_CANBRK                  0x04 /* Receiver can send a break */
  256.                                              /* signal */
  257. #define RZ_FLAG_CANCRY                  0x08 /* Receiver can decrypt */
  258. #define RZ_FLAG_CANLZW                  0x10 /* Receiver can uncompress */
  259. #define RZ_FLAG_CANFC32                 0x20 /* Receiver can do 32-bit CRC */
  260.                                              /* checking */
  261. #define RZ_FLAG_ESC_CTRL                0x40 /* Receiver wants control */
  262.                                              /* characters to be escaped */
  263. #define RZ_FLAG_ESC_8TH                 0x80 /* Receiver wants characters */
  264.                                              /* with 8th bit set to be */
  265.                                              /* escaped */
  266.  
  267. /*******************************************/
  268. /* PS_Z_SENDER_FLAGS parameter's bit masks */
  269. /*******************************************/
  270.  
  271. #define SZ_FLAG_ESC_CTRL                0x40 /* Sender wants control */
  272.                                              /* characters to be escaped */
  273. #define SZ_FLAG_ESC_8TH                 0x80 /* Sender wants characters */
  274.                                              /* with 8th bit set to be */
  275.                                              /* escaped */
  276.  
  277. /******************************/
  278. /* Zmodem conversion options. */
  279. /******************************/
  280.  
  281. /* One of these is passed as 7th argument to r_open_func() and */
  282. /* s_open_func() */
  283.  
  284. #define Z_CONVERSION_UNDEFINED          0x00
  285. #define Z_CONVERSION_BINARY             0x01
  286. #define Z_CONVERSION_TEXT               0x02
  287. #define Z_CONVERSION_RESUME             0x03
  288.  
  289. /*****************************/
  290. /* Zmodem management options */
  291. /*****************************/
  292.  
  293. /* One of these is passed as 8th argument to r_open_func() and */
  294. /* s_open_func() */
  295.  
  296. #define Z_MANAGEMENT_UNDEFINED          0x00 /* No special management */
  297.                                              /* option given */
  298. #define Z_MANAGEMENT_UPDATE             0x01 /* Already existing files */
  299.                                              /* should be replaced only */
  300.                                              /* if the new file is longer */
  301.                                              /* or newer*/
  302. #define Z_MANAGEMENT_COMPARE            0x02 /* A 32-bit CRC of already */
  303.                                              /* existing files should be */
  304.                                              /* calculated and compared to */
  305.                                              /* that of new file, and */
  306.                                              /* only if they differ the */
  307.                                              /* should proceeed. This */
  308.                                              /* option is not supported by */
  309.                                              /* P.DLL, for following */
  310.                                              /* reasons: */
  311.                                              /* 1 - Implementing would */
  312.                                              /* need at least one more */
  313.                                              /* entry function. That would */
  314.                                              /* make things much more */
  315.                                              /* complex and break the */
  316.                                              /* modularity somewhat. */
  317.                                              /* 2 - Haven't found any */
  318.                                              /* other implementation that */
  319.                                              /* supports this. */
  320.                                              /* 3 - Isn't really important */
  321.                                              /* feature, isn't it? */
  322. #define Z_MANAGEMENT_APPEND             0x03 /* If some files already exist */
  323.                                              /* the new data should be */
  324.                                              /* appended to the old files */
  325. #define Z_MANAGEMENT_REPLACE            0x04 /* Already existing files (if */
  326.                                              /* any) should be replaced */
  327. #define Z_MANAGEMENT_NEWER              0x05 /* Already existing files */
  328.                                              /* should be replaced if the */
  329.                                              /* new file is newer. */
  330. #define Z_MANAGEMENT_DIFFERENT          0x06 /* Already existing files */
  331.                                              /* should be replaced only */
  332.                                              /* if the date or length of the */
  333.                                              /* new and old file differ. */
  334. #define Z_MANAGEMENT_PROTECT            0x07 /* Already existing files */
  335.                                              /* should NOT be replaced */
  336.                                              /* under any circumstances. */
  337. #define Z_MANAGEMENT_RENAME             0x08 /* If file already exists */
  338.                                              /* it should be written with */
  339.                                              /* some other name. */
  340. #define Z_MANAGEMENT_BACKUP             0x09 /* If file already exists  */
  341.                                              /* The existing file should be renamed */
  342.  
  343. /* Mask for all of the options in previous list */
  344.  
  345. #define Z_MANAGEMENT_MASK               0x1f
  346.  
  347. /* This can be masked (ORred) to the management options */
  348.  
  349. #define Z_MANAGEMENT_MUST_EXIST         0x80
  350.  
  351. /****************************/
  352. /* Zmodem transport options */
  353. /****************************/
  354.  
  355. /* NONE OF THESE ARE SUPPORTED BY P.DLL */
  356.  
  357. #define Z_TRANSPORT_UNDEFINED           0x00 /* Nothing special will */
  358.                                              /* be done */
  359. #define Z_TRANSPORT_LZW                 0x01 /* Data should compressed */
  360.                                              /* with Lempel-Ziv algorithm. */
  361. #define Z_TRANSPORT_CRYPT               0x02 /* Data should encrypted */
  362. #define Z_TRANSPORT_RLE                 0x03 /* Data should compressed with */
  363.                                              /* RLE algorithm. */
  364.  
  365. /**************************/
  366. /* Error checking methods */
  367. /**************************/
  368.  
  369. #define CHECKING_CHECKSUM               0x01 /* 1 byte checksum of the */
  370.                                              /* data, not very reliable */
  371.                                              /* method */
  372. #define CHECKING_CRC16                  0x02 /* 2 byte CRC of the data, */
  373.                                              /* pretty reliable */
  374. #define CHECKING_CRC32                  0x03 /* 4 byte CRC of the data, */
  375.                                              /* very reliable */
  376.  
  377.  
  378. /***********************/
  379. /* Transfer directions */
  380. /***********************/
  381.  
  382. #define DIR_RECV                        0x01 /* We receive files */
  383. #define DIR_SEND                        0x02 /* We send files */
  384.  
  385.  
  386. /************************/
  387. /* Status message types */
  388. /************************/
  389.  
  390. #define PS_ERROR                        0x00
  391. /*
  392.    A system error has occurred in P.DLL
  393.  
  394.    Parameters:
  395.  
  396.     1 - U32 error_type
  397.  
  398.       Indicates in which system function the error occurred.
  399.       See P_ERROR_* defines above.
  400.  
  401.     2 - U32 error_code
  402.  
  403.       The error code of failed system function. In case of TCP/IP API
  404.       error the value returned by psock_errno(), otherwise the return
  405.       value of the system function itself.
  406.  
  407.     3 - U32 module
  408.  
  409.       ID of the module where the error occurred, this is meant
  410.       for possible bug reports.
  411.  
  412.     4 - U32 line_number
  413.  
  414.       Line number of the module where the error occurred. Also meant
  415.       only for bug reports.
  416.  
  417.     5 - U32 opt_arg
  418.  
  419.       An optional argument depending on error_type. See PS_ERROR_* defines.
  420.  
  421.    p_transfer() will return soon after this with a return value of 1.
  422. */
  423.  
  424. #define PS_CARRIER_LOST                 0x01
  425. /*
  426.    Indicates that carrier signal has been lost. p_transfer() will return
  427.    very soon after this with a return value of 1.
  428.  
  429.    No parameters.
  430. */
  431.  
  432. #define PS_TIMEOUT                      0x02
  433. /*
  434.    Indicates that we have timed out abnormally long
  435.  
  436.    Parameters:
  437.  
  438.     1 - U32 secs
  439.  
  440.       How many seconds did we time out. Note that is only
  441.       an approximation, might be few seconds off.
  442.  
  443.       Could be also zero (0) indicating that the timeout
  444.       period was not specified.
  445. */
  446.  
  447. #define PS_TRANSFER_DONE                0x03
  448. /*
  449.    Indicates that we are successfully done with transferring, p_transfer()
  450.    will exit very soon.
  451.  
  452.    No parameters.
  453. */
  454.  
  455. #define PS_PROGRESS                     0x04
  456. /*
  457.    Indicates the progress of the file transfer.
  458.  
  459.    Parameters:
  460.  
  461.     1 - U32 offset
  462.  
  463.       The offset of the file currently being transferred.
  464. */
  465.  
  466. #define PS_CANNOT_SEND_BLOCK            0x05
  467. /*
  468.    We have tried to send one block for several times and the retry
  469.    count has been exceeded. p_transfer() will return soon after this with
  470.    return value of 1.
  471.  
  472.    No parameters.
  473. */
  474.  
  475. #define PS_CHECKING_METHOD              0x06
  476. /*
  477.    We have determined the error checking method to be used.
  478.  
  479.    Parameters:
  480.  
  481.     1 - U32 checking_method
  482.  
  483.       The method to be used, see CHECKING_* defines above for values.
  484.  
  485.    Note: This will be called several times during a transfer of
  486.          multiple files, even if there is no change in the method.
  487. */
  488.  
  489. #define PS_INVALID_FILE_INFO            0x07
  490. /*
  491.    We have received an invalid file information from the other end.
  492.    The transfer cannot proceed, p_transfer() will return soon with
  493.    a return value of 1.
  494.  
  495.    No parameters.
  496. */
  497.  
  498. #define PS_NON_STD_FILE_INFO            0x08
  499. /*
  500.    We have received a non-standard file information (one missing some
  501.    null-terminations). The transfer will proceed.
  502.  
  503.    No parameters.
  504. */
  505.  
  506. #define PS_XY_FALLBACK_TO_CHECKSUM      0x09
  507. /*
  508.    We have failed to initialize the file transfer for CRC-16 checking,
  509.    from now on we will try to initialize it for checksum checking.
  510.  
  511.    No parameters.
  512. */
  513.  
  514. #define PS_CHECK_FAILED                 0x0a
  515. /*
  516.    We have found an error in a transferred block of data. If we are
  517.    transferring with Ymodem-g, we will get a PS_G_ABORTED status
  518.    soon and the transfer will be aborted. Otherwise we will retry to
  519.    transfer the failed block of data.
  520.  
  521.    Parameters
  522.  
  523.     1 - U32 checking_method
  524.  
  525.       The error checking method we used. For possible values see
  526.       CHECKING_* defines above.
  527.  
  528. */
  529.  
  530. #define PS_REMOTE_ABORTED               0x0b
  531. /*
  532.    The other end has aborted the file transfer.
  533.  
  534.    No parameters.
  535. */
  536.  
  537. #define PS_G_ABORTED                    0x0c
  538. /*
  539.    Some sort of error has occurred in a Ymodem-g transfer and due to a fact
  540.    that Ymodem-g does not provide any kind of error recovery the transfer
  541.    will be aborted.
  542.  
  543.    No parameters.
  544. */
  545.  
  546. #define PS_XYG_NAK                      0x0d
  547. /*
  548.    We have got a NAK response to a block we sent to the remote.
  549.  
  550.    Parameters:
  551.  
  552.     1 - U32 offset
  553.  
  554.       The offset for which we got the NAK. If all bits are set
  555.       (offset == 4294967295), we got the NAK on the file information
  556.       block.
  557. */
  558.  
  559. #define PS_XYG_BLK_NUM_MISMATCH         0x0e
  560. /*
  561.    We have found inconsistency in the block numbering. The block will be
  562.    retried or if the protocol is Ymodem-g the transfer will be aborted.
  563.  
  564.    Parameters:
  565.  
  566.     1 - U8 rcvd_blk_num1
  567.     2 - U8 rcvd_blk_num2
  568.  
  569.       The block numbers we got from the remote.
  570.  
  571.     3 - U8 expected_blk_num1
  572.     4 - U8 expected_blk_num2
  573.  
  574.       The block numbers we expected from the remote.
  575. */
  576.  
  577. #define PS_Z_HEADER                     0x0f
  578. /*
  579.    We have received a Zmodem header.
  580.  
  581.    Parameters:
  582.  
  583.     1 - U32 header_type
  584.  
  585.       The type of received header. For possible values see Z* defines
  586.       above.
  587.  
  588.     2 - U32 header_value
  589.  
  590.       The value of received header.
  591. */
  592.  
  593. #define PS_Z_UNEXPECTED_HEADER          0x10
  594. /*
  595.    We have received an unexpected Zmodem header.
  596.  
  597.    Parameters:
  598.  
  599.     < See PS_Z_HEADER above >
  600. */
  601.  
  602. #define PS_Z_FRAME_END                  0x11
  603. /*
  604.    We have received a Zmodem frame and this is its end type.
  605.  
  606.    Parameters:
  607.  
  608.     1 - U32 frame_end
  609.  
  610.       Received frame's end type. For possible values see FRAME_*
  611.       defines below.
  612. */
  613.  
  614. #define PS_Z_INVALID_FRAME_END          0x12
  615. /*
  616.    We have receive a Zmodem frame with an invalid frame end.
  617.  
  618.    Parameters:
  619.  
  620.     < See PS_Z_FRAME_END above >
  621.  
  622. */
  623.  
  624. #define PS_Z_PHONY_ZEOF                 0x13
  625. /*
  626.    A phony ZEOF header has been received.
  627.  
  628.    No parameters.
  629. */
  630.  
  631. #define PS_Z_RETRY_CNT_EXCEEDED         0x14
  632. /*
  633.    We have got 100 consecutive non-ZDATA Zmodem headers. The transfer
  634.    will be aborted.
  635.  
  636.    No parameters.
  637. */
  638.  
  639. #define PS_Z_DATA_FROM_INVALID_POS      0x15
  640. /*
  641.    We have received data from an invalid offset.
  642.  
  643.    Parameters:
  644.  
  645.     1 - U32 offset
  646.  
  647.       The invalid offset we got data from.
  648.  
  649. */
  650.  
  651. #define PS_Z_COMMAND                    0x16
  652. /*
  653.    We have received a ZCOMMAND.
  654.  
  655.    Parameters:
  656.  
  657.     1 - U8 *command;
  658.  
  659.       This is a command meant to be executed by command shell, but for
  660.       security reasons it might be unwise to allow this. Usually used
  661.       only to execute shell command "echo" to announce something.
  662. */
  663.  
  664. #define PS_Z_CTRL_CHAR_IGNORED          0x17
  665. /*
  666.    We have received an control character though the remote should
  667.    escape them.
  668.  
  669.    Parameters:
  670.  
  671.     1 - U8 ctrl_ch;
  672.  
  673.       The control character we received.
  674. */
  675.  
  676. #define PS_Z_INVALID_ZDLE_SEQUENCE      0x18
  677. /*
  678.    We have received an invalid ZDLE escape sequence, we will retry.
  679.  
  680.    No parameters.
  681. */
  682.  
  683. #define PS_Z_CHECK_FAILED_FOR_HEADER    0x19
  684. /*
  685.    We have found a CRC error in a received Zmodem header.
  686.  
  687.    Parameters:
  688.  
  689.     1 - U32 checking_method
  690.  
  691.       The error checking method we are using, for possible values
  692.       see CHECKING:_* defines above.
  693. */
  694.  
  695. #define PS_Z_INVALID_HEX_HEADER         0x1a
  696. /*
  697.    We have received an invalid Zmodem hexadecimal header. We will retry.
  698.  
  699.    No parameters.
  700. */
  701.  
  702. #define PS_Z_SUBPACKET_TOO_LONG         0x1b
  703. /*
  704.    We have received too long Zmodem subpacket.
  705.  
  706.    Parameters:
  707.  
  708.     1 - U32 max_length
  709.  
  710.       The maximum length of Zmodem subpackets.
  711. */
  712.  
  713. #define PS_Z_CRASH_RECOVERY             0x1c
  714. /*
  715.    We are recovering from a crashed file transfer.
  716.  
  717.    Parameters:
  718.  
  719.     1 - U32 offset
  720.  
  721.       The offset from where on we are recovering.
  722. */
  723.  
  724. #define PS_Z_RECEIVER_FLAGS             0x1d
  725. /*
  726.    The have found out what the receiver is capable of.
  727.  
  728.    Parameters:
  729.  
  730.     1 - U32 receiver_flags
  731.  
  732.       The receiver capabilities are saved in this variable as bit
  733.       values, for possible values see RFLAG_* defines below.
  734. */
  735.  
  736. #define PS_Z_RECEIVER_WINDOW_SIZE       0x1e
  737. /*
  738.    We have found out that the receiver wants a transmit window of specified
  739.    bytes (in parameter #1) to be used. However, if a window size was
  740.    specified in the parameter structure passed to p_transfer() it will
  741.    be used instead of what the receiver proposes.
  742.  
  743.    Parameters:
  744.  
  745.     1 - U32 remote_window_size
  746.  
  747.       The proposed transfer window size.
  748. */
  749.  
  750.  
  751. #define PS_Z_SENDER_FLAGS               0x1f
  752. /*
  753.    The have found out what the receiver is capable of.
  754.  
  755.    Parameters:
  756.  
  757.     1 - U32 receiver_flags
  758.  
  759.       The receiver capabilities are saved in this variable as bit
  760.       values, for possible values see SFLAG_* defines below.
  761. */
  762.  
  763. #define PS_SERVER_WAITING               0x20
  764.  
  765. /*
  766.    This status message is send when we are acting as a server for a file
  767.    transfer (named pipes or stream sockets) and waiting for a client to make
  768.    a connection. This is always called at least once.
  769.  
  770.    When the status_func() returns a zero value the DLL will recheck for any
  771.    inbound connections. Thus, time-outting can be implemented by returning
  772.    a non-zero value when waited long enough.
  773.  
  774.    Parameters:
  775.  
  776.     1 - U32 count
  777.  
  778.       The number of PS_SERVER_WAITING status message.
  779. */
  780.  
  781. #define PS_FILE_SKIPPED                 0x21
  782.  
  783. /*
  784.    This status is posted when we have sent a file information to the receiver
  785.    and as response got a skip request (indicating that the receiver already
  786.    has the file, or had some problems with creating it.)
  787.  
  788.    No parameters.
  789. */
  790.  
  791. #define PS_Z_SERIAL_NUM                 0x22
  792.  
  793. /*
  794.    This status is posted when we are sending files with Zmodem and have
  795.    received the serial number of the receiver. The receiver sends the
  796.    serial number as a response to ZSINIT header that's send by us to tell
  797.    that we wish to have control characters escaped or our attention sequence,
  798.    or when we simply want to query the serial number (See
  799.    CFG_QUERY_SERIAL_NUM configuration flag).
  800.  
  801.    Parameters:
  802.  
  803.     1 - U32 serial_num
  804.  
  805.       A 32-bit serial number we've received.
  806. */
  807.  
  808. #define PS_PACKET_LENGTH                0x23
  809.  
  810.  
  811.  
  812. /***************************/
  813. /* P_CFG structure version */
  814. /***************************/
  815.  
  816. #define P_INTERFACE_VERSION             1 /* This is the version number of */
  817.                                           /* P.DLL interface we use */
  818.  
  819.  
  820. /****************************/
  821. /* Configuration attributes */
  822. /****************************/
  823.  
  824. #define CFG_ALTERNATIVE_CHECKING        0x00000001
  825. /*
  826.    If this attribute is set, an alternative checking method of
  827.    corresponding protocol will be used.
  828.  
  829.    Protocol        Default         Alternative
  830.    --------        -------         -----------
  831.    Zmodem          CRC-32          CRC-16
  832.    Ymodem-g        CRC-16          N/A
  833.    Ymodem          CRC-16          Checksum
  834.    Xmodem          Checksum        CRC-16
  835.  
  836.    Note: with X and Y transfers the receiver decides the error checking
  837.    method to be used.
  838. */
  839.  
  840. #define CFG_1K_BLOCKS                   0x00000002
  841. /*
  842.    If set and sending files with X, Y or G protocol, a 1024 byte blocks
  843.    will be used instead of default 128 byte.
  844.  
  845.    Has no effect to Z transfers.
  846. */
  847.  
  848. #define CFG_SEND_RZ_CR                  0x00000004
  849. /*
  850.    If set, we will send "rz\r" string to the remote in the initialization
  851.    phase of Zmodem sending. The "rz\r" string is used to trigger UN*X
  852.    systems to start their Zmodem receive programs.
  853.  
  854.    Has an effect to Zmodem sending only.
  855. */
  856. #define CFG_SHARED_DEVICE               0x00000008
  857. /*
  858.    If set, we will open the communication device in DENYNONE mode.
  859.    Needed, for example, if you are passing a path, instead of handle, to
  860.    an already open communication device.
  861.  
  862.    Has an effect only if dev_handle is zero.
  863. */
  864.  
  865. #define CFG_WATCH_CARRIER               0x00000010
  866. /*
  867.    If set and the communication device is an asynchronous one, we will
  868.    monitor the carrier signal and abort the transfer if it drops.
  869.  
  870.    Has no effect if the device is a named pipe.
  871. */
  872.  
  873. #define CFG_DEV_SERVER                  0x00000020
  874. /*
  875.    If set and dev_handle is zero, we will act as a server for named pipe
  876.    and socket connections.
  877.  
  878.    In case of named pipe, a new pipe will be created to which other
  879.    programs can connect to.
  880.  
  881.    In case of socket, we will listen a socket for incoming connections.
  882.  
  883.    Has no effect if dev_handle is non-zero or the dev_path refers to
  884.    an asynchronous device.
  885. */
  886.  
  887. #define CFG_DEV_TELNET                  0x00000040
  888.  
  889. #define CFG_ESC_MINIMAL                 0x00000080
  890. /*
  891.    If set, we will try to get more throughput by minimizing the escaping
  892.    used for Zmodem transfers.
  893.  
  894.    Affects only to Zmodem transfers.
  895. */
  896.  
  897. #define CFG_ESC_CTRL                    0x00000100
  898. /*
  899.    If set, we will escape all control characters (ASCII 0-31) with
  900.    Zmodem transfers. Needed if the connection can not pass through
  901.    some of the control characters.
  902.  
  903.    Affects only to Zmodem transfers.
  904. */
  905.  
  906. #define CFG_QUERY_SERIAL_NUM            0x00000200
  907. /*
  908.    If set, we will query the remote's serial number and tell it
  909.    to the calling application with PS_Z_SERIAL_NUM status message.
  910.  
  911.    Affects only to Zmodem sending.
  912. */
  913.  
  914. #define CFG_DEV_TELNET_U_BINARY         0x000000400
  915. #define CFG_DEV_TELNET_ME_BINARY        0x000000800
  916. #define CFG_DEV_TELNET_IAC_NOT_ESCAPED  0x000001000
  917.  
  918. #define CFG_FILE_MOVE                   0x000002000
  919. /*
  920.    If set, a file transfer is only SUCCESSFUL if the file was
  921.    actually sent across the wire.  In other words, a SKIPPED file
  922.    will not be considered a successfully transfered file.
  923. */
  924.  
  925. #define CFG_ESC_TABLE              0x000002000
  926. /*
  927.    If set, we will use a table specified by control_prefix_table
  928.    to determine which control characters should be escaped
  929.  
  930.    Affects only Zmodem transfers.
  931. */
  932.  
  933. #define CFG_ESC_8TH                0x000004000
  934. /*
  935.    If set, we will escape all characters with the 8th bit set.
  936.    Needed on 7-bit connections.
  937.  
  938.    Affects only Zmodem transfers.
  939. */
  940.  
  941. #pragma pack(1)                     /* Use 1 byte alignment */
  942.                                     /* in the structure */
  943.  
  944. typedef struct _P_CFG {
  945.  
  946.   U32 version;                      /* This structure's version, use */
  947.                                     /* the P_VERSION constant */
  948.  
  949.   U32 attr;                         /* Configuration attributes, see */
  950.                                     /* CFG_* defines above. */
  951.  
  952.   U32 transfer_direction;           /* Transfer direction, see DIR_* */
  953.                                     /* defines above. */
  954.   U32 protocol_type;                /* Protocol to use, see PROTOCOL_* */
  955.                                     /* defines above. */
  956.  
  957.   U32 serial_num;                   /* Our serial number that will be sent */
  958.                                     /* to the remote when requested. 0 for */
  959.                                     /* no serial number. For more */
  960.                                     /* information, see PS_Z_SERIAL_NUM */
  961.                                     /* define. */
  962.   U8 *attn_seq;                     /* This is a pointer to a string that */
  963.                                     /* will be sent when we are receving */
  964.                                     /* files and have detected an error or */
  965.                                     /* have something else to report to the */
  966.                                     /* sender. Usually not needed can be set */
  967.                                     /* point to NULL. */
  968.                                     /* In attention sequence following */
  969.                                     /* characters have a special meaning: */
  970.                                     /* ASCII 221 -- Break signal (275 ms) */
  971.                                     /* ASCII 222 -- One second pause */
  972.                                     /* Maximum length of the attention */
  973.                                     /* sequence is 31 characters + */
  974.                                     /* terminating NULL */
  975.   U32 dev_type;                     /* Communication device type, for values */
  976.                                     /* see DEV_TYPE_* defines */
  977.   U8 *dev_path;                     /* Path to the communication device, */
  978.                                     /* used only if dev_handle is zero. */
  979.   U8 *socket_host;                  /* Internet address of the host to be */
  980.                                     /* connected to */
  981.   U16 socket_port;                  /* Stream socket port to be used. */
  982.  
  983.   U32 dev_handle;                   /* Handle to an already open */
  984.                                     /* communication device */
  985.  
  986.   U32 inbuf_size;                   /* Size of communication input buffer */
  987.   U32 outbuf_size;                  /* Size of communication output buffer */
  988.  
  989.   U32 blk_size;                     /* Block size if protocol is X, Y or G. */
  990.                                     /* If Z, this is the window size to be */
  991.                                     /* used. */
  992.  
  993. /*
  994.    Here are the callback functions that P.DLL calls to inform the
  995.    parent program about the progress of the file transfer, to get more
  996.    data to be sent and to give away the received data.
  997.  
  998.    Each of the callback functions has its own specific parameters, but
  999.    the meaning of return values is common.
  1000.  
  1001.    A return value of zero (0) is used to indicate that the processing
  1002.    should continue normally.
  1003.  
  1004.    A non-zero return value is used to indicate that the calling
  1005.    program wants to abort the file transfer for some reason (user
  1006.    aborted, an unrecoverable error has occurred, etc).  In case of
  1007.    non-zero return value the p_transfer() entry will return very soon,
  1008.    however some calls to the callback/ functions may still come, so if
  1009.    the error condition prevents the proper callback function handling,
  1010.    it should be taken in consideration when writing the callback
  1011.    functions.
  1012. */
  1013.  
  1014.   U32 (* _System status_func)(U32, ...);
  1015. /*
  1016.    This function is called to inform the calling program about
  1017.    progress of file transfer.
  1018.  
  1019.    Parameters:
  1020.  
  1021.    1 - U32 status_type
  1022.  
  1023.         The type of posted status message, for possible values
  1024.         see PS_* defines above.
  1025.  
  1026.    n - A number of parameter will follow depending on the
  1027.  
  1028.         status_type. For each status_type's parameters see
  1029.         the comments in PS_* defines above.
  1030. */
  1031.  
  1032.   U32 (* _System r_open_func)(U8 **,
  1033.                                 U32,
  1034.                                 U32,
  1035.                                 U32,
  1036.                                 U32,
  1037.                                 U32,
  1038.                                 U8,
  1039.                                 U8,
  1040.                                 U8,
  1041.                                 U32 *);
  1042.  
  1043. /*
  1044.    This function is called before we start receiving a file.
  1045.  
  1046.    Parameters:
  1047.  
  1048.    1 - U8 **path
  1049.  
  1050.         This is a pointer to a character string which has been
  1051.         dynamically allocated with OS/2's DosAllocMem() function.
  1052.  
  1053.         If we are receiving files with a protocol other than Xmodem,
  1054.         this string will contain the file path information that the
  1055.         sender has provided to us. The variable can be freely changed
  1056.         in the function and if the new value is longer than the old
  1057.         one the variable must be freed (with DosFreeMem) first and
  1058.         then reallocated (with DosAllocMem).  File can also be skipped
  1059.         (works only with Zmodem transfers, others will abort) by freeing
  1060.         the variable and assigning a NULL value to it.
  1061.  
  1062.         In case of Xmodem, this parameter will be a pointer to a NULL
  1063.         string and the parent program will have to allocate memory (with
  1064.         DosAllocMem) for it and save the name of the file to be received
  1065.         in it.
  1066.  
  1067.         If path contains directory or drive information, backslashes are
  1068.         used as separators. For example: C:\FISH\FOO.BAR
  1069.  
  1070.    2 - U32 length
  1071.  
  1072.         The length of the file to be received. In case of Zmodem this
  1073.         can be an estimate, with Ymodem and Ymodem-g it will be accurate, and
  1074.         with Xmodem (which doesn't provide this information) it will be -1.
  1075.  
  1076.    3 - U32 date
  1077.  
  1078.         The date of the file to be received in seconds since 1st of January
  1079.         1970, 00:00. In case of Xmodem this will have a value of -1. Might be
  1080.         -1 also if a non-standard file information has been received.
  1081.  
  1082.    4 - U32 mode
  1083.  
  1084.         This is a UNIX style mode information for the file. Zero (0) if
  1085.         information is not available.
  1086.  
  1087.    5 - U32 f_left
  1088.  
  1089.         This is the number files left to transfer. Zero (0) if information
  1090.         is not available.
  1091.  
  1092.    6 - U32 b_left
  1093.  
  1094.         This is the number bytes left to transfer. Zero (0) if information
  1095.         is not available.
  1096.  
  1097.    7 - U32 zconv
  1098.  
  1099.         Zmodem conversion option. One of the Z_CONVERSION_* defines.
  1100.  
  1101.    8 - U32 zmanag
  1102.  
  1103.         Zmodem management option. Constructed of the Z_MANAGEMENT_* defines.
  1104.  
  1105.    9 - U32 ztrans
  1106.  
  1107.         Zmodem transport option. One of the Z_TRANSPORT_* defines.
  1108.  
  1109.    10 - U32 *offset
  1110.  
  1111.         This value will have a NULL value if the protocol is something
  1112.         else than Zmodem.
  1113.  
  1114.         In case of Zmodem, this is a pointer to a variable telling
  1115.         the offset where at the sender should start sending the file.
  1116. */
  1117.  
  1118.   U32 (* _System s_open_func)(U8 **,
  1119.                                 U32 *,
  1120.                                 U32 *,
  1121.                                 U32 *,
  1122.                                 U32 *,
  1123.                                 U32 *,
  1124.                                 U8 *,
  1125.                                 U8 *,
  1126.                                 U8 *);
  1127.  
  1128. /*
  1129.    This function is called before we start sending a file.
  1130.  
  1131.    Parameters:
  1132.  
  1133.    1 - U8 **path
  1134.  
  1135.         This is a pointer to a character string which has initially a
  1136.         value of NULL. The calling program must allocate memory (with
  1137.         DosAllocMem) for the string and save the path to the file to be
  1138.         sent in it. Either backslashes ('\') or slashes ('/') can be used
  1139.         as separators for possible directory information.
  1140.  
  1141.         If there are no more files to be transferred the string value
  1142.         should be left as NULL.
  1143.  
  1144.    2 - U32 *length
  1145.  
  1146.         This is a pointer to a variable where function should save
  1147.         the length of the file to be sent. With Zmodem an estimate
  1148.         will do, and Xmodem does not need this at all.
  1149.  
  1150.    3 - U32 *date
  1151.  
  1152.         To the variable pointed by this pointer, the function should
  1153.         save the last modification time of the file to be sent, in
  1154.         seconds since 00:00, 1st of January 1970.
  1155.  
  1156.         This is not required for Xmodem transfers.
  1157.  
  1158.    4 - U32 *mode
  1159.  
  1160.         This is UNIX style mode information for the file. Zero (0) if
  1161.         information is not available.
  1162.  
  1163.    5 - U32 f_left
  1164.  
  1165.         This is the number files left to transfer. Zero (0) if information
  1166.         is not available.
  1167.  
  1168.    6 - U32 b_left
  1169.  
  1170.         This is the number bytes left to transfer. Zero (0) if information
  1171.         is not available.
  1172.  
  1173.    7 - U32 zconv
  1174.  
  1175.         Zmodem conversion option. One of the Z_CONVERSION_* defines.
  1176.  
  1177.    8 - U32 zmanag
  1178.  
  1179.         Zmodem management option. Constructed of the Z_MANAGEMENT_* defines.
  1180.  
  1181.    9 - U32 ztrans
  1182.  
  1183.         Zmodem transport option. One of the Z_TRANSPORT_* defines.
  1184.  
  1185. */
  1186.  
  1187.   U32 (* _System close_func)(U8 **,
  1188.                                U32,
  1189.                                U32,
  1190.                                U32,
  1191.                                BOOLEAN,
  1192.                                U32);
  1193.  
  1194. /*
  1195.    This function will be called when we are done with transferring a file
  1196.    (successful or not).
  1197.  
  1198.    Parameters:
  1199.  
  1200.    1 - U8 **path
  1201.  
  1202.         This is a pointer to character string containing path to the
  1203.         file we have been transferring. This function should free this
  1204.         DosAllocMem allocated variable and place a NULL value to it.
  1205.  
  1206.    2 - U32 length
  1207.  
  1208.         The file length information the sender sent us in the beginning of
  1209.         the file transfer. With Zmodem transfer might have been just an
  1210.         estimate and might not equal to offset (parameter 6).
  1211.  
  1212.    3 - U32 date
  1213.  
  1214.         The file date informating provided to us in the beginning of the
  1215.         transfer. The user function should set the date of the actual file
  1216.         to this. Value will be -1 if the information has not been provided
  1217.         by the sender.
  1218.  
  1219.    4 - U32 retransmits
  1220.  
  1221.         Number of times data was retransmitted during the file transfer.
  1222.  
  1223.    5 - U32 successful
  1224.  
  1225.         Non-zero if the file transfer was successful.
  1226.  
  1227.    6 - U32 offset
  1228.  
  1229.         This variable contains the offset where the transfer ended
  1230.         (successful or not). Note that is does not necessary equal to
  1231.         the bytes transferred, we might have recovered from a crashed
  1232.         transfer.
  1233.  
  1234. */
  1235.   U32 (* _System seek_func)(U32);
  1236. /*
  1237.    This function is called when we are starting to send a file with Zmodem
  1238.    protocol and the remote indicates that it already has a part of that
  1239.    file and it would like to recover from it by not starting the transfer
  1240.    from the beginning.
  1241.  
  1242.    Parameters:
  1243.  
  1244.    1 - U32 offset
  1245.  
  1246.         This is the position the receiver would like to start receiving
  1247.         from, rather than from the beginning of the file.
  1248. */
  1249.  
  1250.   U32 (* _System read_func)(U8 *,
  1251.                               U32,
  1252.                               U32 *);
  1253.   /*
  1254.    This function is called when we need more data to send to the remote.
  1255.  
  1256.    Parameters:
  1257.  
  1258.    1 - U8 *buf
  1259.  
  1260.         Pointer to a character buffer where the function should place
  1261.         the data.
  1262.  
  1263.    2 - U32 bytes_wanted
  1264.  
  1265.         Bytes of data we want to get.
  1266.  
  1267.    3 - U32 *bytes_got
  1268.  
  1269.         To this variable the function should place the number of bytes
  1270.         it got received. If this is less than bytes_wanted we expect
  1271.         that there are no more data in the file and read_func() will
  1272.         not be called for this file anymore (unless there is a
  1273.         transmission error).
  1274. */
  1275.  
  1276.   U32 (* _System write_func)(U8 *,
  1277.                                U32);
  1278. /*
  1279.    This function is called when we have received data to be written to the
  1280.    file.
  1281.  
  1282.    Parameters:
  1283.  
  1284.    1 - U8 *buf
  1285.  
  1286.         Pointer to character buffer where the data to be written is.
  1287.  
  1288.    2 - U32 bytes_to_write
  1289.  
  1290.         The number of bytes to write from buf.
  1291. */
  1292.  
  1293.   U32 (* _System exe_in_func)(U8 *,
  1294.                               U32,
  1295.                               U32 *);
  1296.   /*
  1297.    This function is called when we need more data received from the remote.
  1298.  
  1299.    Parameters:
  1300.  
  1301.    1 - U8 *buf
  1302.  
  1303.         Pointer to a character buffer where the function should place
  1304.         the data.
  1305.  
  1306.    2 - U32 bytes_wanted
  1307.  
  1308.         Bytes of data we want to get.
  1309.  
  1310.    3 - U32 *bytes_got
  1311.  
  1312.         To this variable the function should place the number of bytes
  1313.         it got received. If this is less than bytes_wanted we expect
  1314.         that there are no more data in the file and read_func() will
  1315.         not be called for this file anymore (unless there is a
  1316.         transmission error).
  1317. */
  1318.  
  1319.   U32 (* _System exe_out_func)(U8 *,
  1320.                                U32, U32 *);
  1321. /*
  1322.    This function is called when we have data to send to the host.
  1323.  
  1324.    Parameters:
  1325.  
  1326.    1 - U8 *buf
  1327.  
  1328.         Pointer to character buffer where the data to be written is.
  1329.  
  1330.    2 - U32 bytes_to_write
  1331.  
  1332.         The number of bytes to write from buf.
  1333.  
  1334.    3 - U32 * bytes_written
  1335.  
  1336.         Returns number of bytes actually written.
  1337. */
  1338.   U32 (* _System exe_break_func)(U8);
  1339.  
  1340. /*
  1341.    This function is called to manipulate the Break Signal
  1342.  
  1343.    Parameters:
  1344.  
  1345.    1 - U8 toggle
  1346.  
  1347.        0 for Off; 1 for On.
  1348. */
  1349.  
  1350.   U32 (* _System exe_available_func)(U32 *);
  1351. /*
  1352.   This function is called to check the number of available bytes
  1353.  
  1354.   Parameters:
  1355.  
  1356.   1 - U32 * available_bytes
  1357.  
  1358.        Returns the number of available bytes
  1359.  
  1360. */
  1361.  
  1362.     U16 * control_prefix_table ;
  1363.  
  1364.     /* A pointer to a 256 element array in which each cell is either */
  1365.     /* 0 or 1 depending on whether that character position is to be  */
  1366.     /* prefixed.                                                     */
  1367.  
  1368.     U32 (* _System exe_pushback_func)(U8 *, U32);
  1369.     /*
  1370.     This function is called to push back the unused bytes left over
  1371.     at the end of the transfer.
  1372.  
  1373.     Parameters:
  1374.  
  1375.     1 - U8 * bytes to restore
  1376.     2 - U32  number of bytes
  1377.  
  1378.     Returns 0 for success
  1379.  
  1380.     */
  1381.  
  1382. } P_CFG;
  1383.  
  1384. #pragma pack()                  /* Back to default alignment */
  1385.  
  1386. /*
  1387.    Prototype for p_transfer() function. Commented because one might want to
  1388.    use DosLoadLibrary instead of import library.
  1389.  
  1390.    extern U32 _System p_transfer(P_CFG *);
  1391. */
  1392.  
  1393. #endif /* _P_H_ */
  1394.