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