Annotation of sbbs/src/sbbs3/zmodem.h, revision 1.1

1.1     ! root        1: /*
        !             2:  * zmodem.h
        !             3:  * zmodem constants
        !             4:  * (C) Mattheij Computer Service 1994
        !             5:  */
        !             6: 
        !             7: /* $Id: zmodem.h,v 1.39 2006/02/24 09:50:50 rswindell Exp $ */
        !             8: 
        !             9: #ifndef _ZMODEM_H
        !            10: #define _ZMODEM_H
        !            11: 
        !            12: #include <stdio.h>     /* FILE */
        !            13: 
        !            14: /*
        !            15:  * ascii constants
        !            16:  */
        !            17: 
        !            18: #ifndef SOH
        !            19: #define        SOH                     0x01
        !            20: #define        STX                     0x02
        !            21: #define        EOT                     0x04
        !            22: #define        ENQ                     0x05
        !            23: #define        ACK                     0x06
        !            24: #if 0
        !            25: #define        LF                      0x0a
        !            26: #define        CR                      0x0d
        !            27: #endif
        !            28: #define DLE                    0x10
        !            29: #define        XON                     0x11
        !            30: #define        XOFF            0x13
        !            31: #define        NAK                     0x15
        !            32: #define        CAN                     0x18
        !            33: #endif
        !            34: 
        !            35: /*
        !            36:  * zmodem constants
        !            37:  */
        !            38: 
        !            39: #define ZBLOCKLEN      1024            /* "true" Zmodem max subpacket length */
        !            40: 
        !            41: #define ZMAXHLEN    0x10               /* maximum header information length */
        !            42: #define ZMAXSPLEN      0x400           /* maximum subpacket length */
        !            43: 
        !            44: 
        !            45: #define        ZPAD            0x2a            /* pad character; begins frames */
        !            46: #define        ZDLE            0x18            /* ctrl-x zmodem escape */
        !            47: #define        ZDLEE           0x58            /* escaped ZDLE */      
        !            48: 
        !            49: #define        ZBIN            0x41            /* binary frame indicator (CRC16) */
        !            50: #define        ZHEX            0x42            /* hex frame indicator */
        !            51: #define        ZBIN32          0x43            /* binary frame indicator (CRC32) */
        !            52: #define        ZBINR32         0x44            /* run length encoded binary frame (CRC32) */
        !            53: 
        !            54: #define        ZVBIN           0x61            /* binary frame indicator (CRC16) */
        !            55: #define        ZVHEX           0x62            /* hex frame indicator */
        !            56: #define        ZVBIN32         0x63            /* binary frame indicator (CRC32) */
        !            57: #define        ZVBINR32        0x64            /* run length encoded binary frame (CRC32) */
        !            58: 
        !            59: #define        ZRESC           0x7e            /* run length encoding flag / escape character */
        !            60: 
        !            61: /*
        !            62:  * zmodem frame types
        !            63:  */
        !            64: 
        !            65: #define        ZRQINIT         0x00            /* request receive init (s->r) */
        !            66: #define        ZRINIT          0x01            /* receive init (r->s) */
        !            67: #define        ZSINIT          0x02            /* send init sequence (optional) (s->r) */
        !            68: #define        ZACK            0x03            /* ack to ZRQINIT ZRINIT or ZSINIT (s<->r) */
        !            69: #define        ZFILE           0x04            /* file name (s->r) */
        !            70: #define        ZSKIP           0x05            /* skip this file (r->s) */
        !            71: #define        ZNAK            0x06            /* last packet was corrupted (?) */
        !            72: #define        ZABORT          0x07            /* abort batch transfers (?) */
        !            73: #define        ZFIN            0x08            /* finish session (s<->r) */
        !            74: #define        ZRPOS           0x09            /* resume data transmission here (r->s) */
        !            75: #define        ZDATA           0x0a            /* data packet(s) follow (s->r) */
        !            76: #define        ZEOF            0x0b            /* end of file reached (s->r) */
        !            77: #define        ZFERR           0x0c            /* fatal read or write error detected (?) */
        !            78: #define        ZCRC            0x0d            /* request for file CRC and response (?) */
        !            79: #define        ZCHALLENGE      0x0e            /* security challenge (r->s) */
        !            80: #define        ZCOMPL          0x0f            /* request is complete (?) */   
        !            81: #define        ZCAN            0x10            /* pseudo frame; 
        !            82:                                                                   other end cancelled session with 5* CAN */
        !            83: #define        ZFREECNT        0x11            /* request free bytes on file system (s->r) */
        !            84: #define        ZCOMMAND        0x12            /* issue command (s->r) */
        !            85: #define        ZSTDERR         0x13            /* output data to stderr (??) */
        !            86: 
        !            87: /*
        !            88:  * ZDLE sequences
        !            89:  */
        !            90: 
        !            91: #define        ZCRCE           0x68            /* CRC next, frame ends, header packet follows */
        !            92: #define        ZCRCG           0x69            /* CRC next, frame continues nonstop */
        !            93: #define        ZCRCQ           0x6a            /* CRC next, frame continuous, ZACK expected */
        !            94: #define        ZCRCW           0x6b            /* CRC next, frame ends,       ZACK expected */
        !            95: #define        ZRUB0           0x6c            /* translate to rubout 0x7f */
        !            96: #define        ZRUB1           0x6d            /* translate to rubout 0xff */
        !            97: 
        !            98: /*
        !            99:  * frame specific data.
        !           100:  * entries are prefixed with their location in the header array.
        !           101:  */
        !           102: 
        !           103: /*
        !           104:  * Byte positions within header array
        !           105:  */
        !           106: 
        !           107: #define FTYPE 0                                        /* frame type */
        !           108: 
        !           109: #define ZF0    4                                       /* First flags byte */
        !           110: #define ZF1    3
        !           111: #define ZF2    2
        !           112: #define ZF3    1
        !           113: 
        !           114: #define ZP0    1                                       /* Low order 8 bits of position */
        !           115: #define ZP1    2
        !           116: #define ZP2    3
        !           117: #define ZP3    4                                       /* High order 8 bits of file position */
        !           118: 
        !           119: /*
        !           120:  * ZRINIT frame
        !           121:  * zmodem receiver capability flags
        !           122:  */
        !           123: 
        !           124: #define        ZF0_CANFDX              0x01    /* Receiver can send and receive true full duplex */
        !           125: #define        ZF0_CANOVIO             0x02    /* receiver can receive data during disk I/O */
        !           126: #define        ZF0_CANBRK              0x04    /* receiver can send a break signal */
        !           127: #define        ZF0_CANCRY              0x08    /* Receiver can decrypt DONT USE */
        !           128: #define        ZF0_CANLZW              0x10    /* Receiver can uncompress DONT USE */
        !           129: #define        ZF0_CANFC32             0x20    /* Receiver can use 32 bit Frame Check */
        !           130: #define        ZF0_ESCCTL              0x40    /* Receiver expects ctl chars to be escaped */
        !           131: #define        ZF0_ESC8                0x80    /* Receiver expects 8th bit to be escaped */
        !           132: 
        !           133: #define ZF1_CANVHDR            0x01    /* Variable headers OK */
        !           134: 
        !           135: /*
        !           136:  * ZSINIT frame
        !           137:  * zmodem sender capability
        !           138:  */
        !           139: 
        !           140: #define ZF0_TESCCTL    0x40    /* Transmitter expects ctl chars to be escaped */
        !           141: #define ZF0_TESC8      0x80    /* Transmitter expects 8th bit to be escaped */
        !           142: 
        !           143: #define ZATTNLEN               0x20    /* Max length of attention string */
        !           144: #define ALTCOFF                        ZF1             /* Offset to alternate canit string, 0 if not used */
        !           145: 
        !           146: /*
        !           147:  * ZFILE frame
        !           148:  */
        !           149: 
        !           150: /*
        !           151:  * Conversion options one of these in ZF0
        !           152:  */
        !           153: 
        !           154: #define ZF0_ZCBIN              1               /* Binary transfer - inhibit conversion */
        !           155: #define ZF0_ZCNL               2               /* Convert NL to local end of line convention */
        !           156: #define ZF0_ZCRESUM            3               /* Resume interrupted file transfer */
        !           157: 
        !           158: /*
        !           159:  * Management include options, one of these ored in ZF1
        !           160:  */
        !           161: 
        !           162: #define ZF1_ZMSKNOLOC  0x80    /* Skip file if not present at rx */
        !           163: #define ZF1_ZMMASK             0x1f    /* Mask for the choices below */
        !           164: #define ZF1_ZMNEWL             1               /* Transfer if source newer or longer */
        !           165: #define ZF1_ZMCRC              2               /* Transfer if different file CRC or length */
        !           166: #define ZF1_ZMAPND             3               /* Append contents to existing file (if any) */
        !           167: #define ZF1_ZMCLOB             4               /* Replace existing file */
        !           168: #define ZF1_ZMNEW              5               /* Transfer if source newer */
        !           169: #define ZF1_ZMDIFF             6               /* Transfer if dates or lengths different */
        !           170: #define ZF1_ZMPROT             7               /* Protect destination file */
        !           171: #define ZF1_ZMCHNG             8               /* Change filename if destination exists */
        !           172: 
        !           173: /*
        !           174:  * Transport options, one of these in ZF2
        !           175:  */
        !           176: 
        !           177: #define ZF2_ZTNOR              0               /* no compression */
        !           178: #define ZF2_ZTLZW              1               /* Lempel-Ziv compression */
        !           179: #define ZF2_ZTRLE              3               /* Run Length encoding */
        !           180: 
        !           181: /*
        !           182:  * Extended options for ZF3, bit encoded
        !           183:  */
        !           184: 
        !           185: #define ZF3_ZCANVHDR   0x01    /* Variable headers OK */
        !           186:                                                                /* Receiver window size override */
        !           187: #define ZF3_ZRWOVR             0x04    /* byte position for receive window override/256 */
        !           188: #define ZF3_ZXSPARS            0x40    /* encoding for sparse file operations */
        !           189: 
        !           190: /*
        !           191:  * ZCOMMAND frame
        !           192:  */
        !           193: 
        !           194: #define ZF0_ZCACK1             0x01    /* Acknowledge, then do command */
        !           195: 
        !           196: typedef struct {
        !           197: 
        !           198:        BYTE    rxd_header[ZMAXHLEN];                                                   /* last received header */
        !           199:        int             rxd_header_len;                                                                 /* last received header size */
        !           200:        ulong   rxd_header_pos;                                                                 /* last received header position value */
        !           201: 
        !           202:        /*
        !           203:         * receiver capability flags
        !           204:         * extracted from the ZRINIT frame as received
        !           205:         */
        !           206: 
        !           207:        BOOL can_full_duplex;
        !           208:        BOOL can_overlap_io;
        !           209:        BOOL can_break;
        !           210:        BOOL can_fcs_32;
        !           211:        BOOL want_fcs_16;
        !           212:        BOOL escape_ctrl_chars; 
        !           213:        BOOL escape_8th_bit;
        !           214: 
        !           215:        /*
        !           216:         * file management options.
        !           217:         * only one should be on
        !           218:         */
        !           219: 
        !           220:        int management_newer;
        !           221:        int management_clobber;
        !           222:        int management_protect;
        !           223: 
        !           224:        /* from zmtx.c */
        !           225: 
        !           226:        BYTE tx_data_subpacket[8192];
        !           227:        BYTE rx_data_subpacket[8192];                                                   /* zzap = 8192 */
        !           228: 
        !           229:        char            current_file_name[MAX_PATH+1];
        !           230:        ulong           current_file_size;
        !           231:        time_t          current_file_time;
        !           232:        unsigned        current_file_num;
        !           233:        unsigned        total_files;
        !           234:        ulong           total_bytes;
        !           235:        unsigned        files_remaining;
        !           236:        unsigned        bytes_remaining;
        !           237:        ulong           transfer_start_pos;
        !           238:        time_t          transfer_start_time;
        !           239: 
        !           240:        int receive_32bit_data;
        !           241:        int use_crc16;
        !           242:        long ack_file_pos;                              /* file position used in acknowledgement of correctly */
        !           243:                                                                        /* received data subpackets */
        !           244: 
        !           245:        int last_sent;
        !           246: 
        !           247:        int n_cans;
        !           248: 
        !           249:        /* Stuff added by RRS */
        !           250: 
        !           251:        /* Status */
        !           252:        BOOL            cancelled;
        !           253:        BOOL            local_abort;
        !           254:        BOOL            file_skipped;
        !           255:        BOOL            no_streaming;
        !           256:        unsigned        recv_bufsize;   /* Receiver specified buffer size */
        !           257:        long            crc_request;
        !           258:        unsigned        errors;
        !           259:        unsigned        consecutive_errors;
        !           260: 
        !           261:        /* Configuration */
        !           262:        BOOL            escape_telnet_iac;
        !           263:        unsigned        init_timeout;
        !           264:        unsigned        send_timeout;
        !           265:        unsigned        recv_timeout;
        !           266:        unsigned        crc_timeout;
        !           267:        unsigned        max_errors;
        !           268:        unsigned        block_size;
        !           269:        unsigned        max_block_size;
        !           270: 
        !           271:        /* Callbacks */
        !           272:        void*           cbdata;
        !           273:        int                     (*lputs)(void*, int level, const char* str);
        !           274:        int                     (*send_byte)(void*, BYTE ch, unsigned timeout);
        !           275:        int                     (*recv_byte)(void*, unsigned timeout);
        !           276:        void            (*progress)(void*, ulong current_pos);
        !           277:        BOOL            (*is_connected)(void*);
        !           278:        BOOL            (*is_cancelled)(void*);
        !           279:        BOOL            (*data_waiting)(void*, unsigned timeout);
        !           280: 
        !           281: } zmodem_t;
        !           282: 
        !           283: void           zmodem_init(zmodem_t*, void* cbdata
        !           284:                                                ,int    (*lputs)(void*, int level, const char* str)
        !           285:                                                ,void   (*progress)(void*, ulong current_pos)
        !           286:                                                ,int    (*send_byte)(void*, BYTE ch, unsigned timeout)
        !           287:                                                ,int    (*recv_byte)(void*, unsigned timeout)
        !           288:                                                ,BOOL   (*is_connected)(void*)
        !           289:                                                ,BOOL   (*is_cancelled)(void*)
        !           290:                                                ,BOOL   (*data_waiting)(void*, unsigned timeout)
        !           291:                                                );
        !           292: char*          zmodem_ver(char *buf);
        !           293: const char* zmodem_source(void);
        !           294: int                    zmodem_rx(zmodem_t* zm);
        !           295: int                    zmodem_tx(zmodem_t* zm, BYTE ch);
        !           296: int                    zmodem_abort_receive(zmodem_t*);
        !           297: int                    zmodem_send_ack(zmodem_t*, long pos);
        !           298: int                    zmodem_send_nak(zmodem_t*);
        !           299: int                    zmodem_send_zskip(zmodem_t* zm);
        !           300: int                    zmodem_send_zrinit(zmodem_t*);
        !           301: int                    zmodem_send_pos_header(zmodem_t* zm, int type, long pos, BOOL hex);
        !           302: int                    zmodem_get_zrinit(zmodem_t*);
        !           303: int                    zmodem_get_zfin(zmodem_t* zm);
        !           304: BOOL           zmodem_get_crc(zmodem_t*, long length, ulong* crc);
        !           305: void           zmodem_parse_zrinit(zmodem_t*);
        !           306: void           zmodem_parse_zfile_subpacket(zmodem_t* zm);
        !           307: int                    zmodem_send_zfin(zmodem_t*);
        !           308: BOOL           zmodem_send_file(zmodem_t*, char* name, FILE* fp, BOOL request_init, time_t* start, ulong* bytes_sent);
        !           309: int                    zmodem_recv_files(zmodem_t* zm, const char* download_dir, ulong* bytes_received);
        !           310: int                    zmodem_recv_init(zmodem_t* zm);
        !           311: unsigned       zmodem_recv_file_data(zmodem_t*, FILE*, ulong offset);
        !           312: int                    zmodem_recv_file_frame(zmodem_t* zm, FILE* fp);
        !           313: int                    zmodem_recv_header_and_check(zmodem_t* zm);
        !           314: #endif
        !           315: 
        !           316: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.