| 1 |
/* |
| 2 |
* Copyright (C) 1994-1998 T. Teranishi |
| 3 |
* (C) 2009- TeraTerm Project |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* Redistribution and use in source and binary forms, with or without |
| 7 |
* modification, are permitted provided that the following conditions |
| 8 |
* are met: |
| 9 |
* |
| 10 |
* 1. Redistributions of source code must retain the above copyright |
| 11 |
* notice, this list of conditions and the following disclaimer. |
| 12 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
* notice, this list of conditions and the following disclaimer in the |
| 14 |
* documentation and/or other materials provided with the distribution. |
| 15 |
* 3. The name of the author may not be used to endorse or promote products |
| 16 |
* derived from this software without specific prior written permission. |
| 17 |
* |
| 18 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR |
| 19 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 |
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 23 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 |
*/ |
| 29 |
|
| 30 |
#ifndef __ZMODEM_H__ |
| 31 |
#define __ZMODEM_H__ |
| 32 |
|
| 33 |
#include "session.h" |
| 34 |
#include "util.h" |
| 35 |
|
| 36 |
#define ZMODEM_BLOCK_SIZE 1024 |
| 37 |
|
| 38 |
/* ZMODEM function id */ |
| 39 |
#define IdZReceive 1 |
| 40 |
#define IdZSend 2 |
| 41 |
#define IdZAutoR 3 |
| 42 |
#define IdZAutoS 4 |
| 43 |
|
| 44 |
enum { |
| 45 |
ZMODEM_MODE, |
| 46 |
ZMODEM_BINFLAG |
| 47 |
}; |
| 48 |
|
| 49 |
struct zmodem_session { |
| 50 |
struct session *session; |
| 51 |
|
| 52 |
FILE *file; |
| 53 |
unsigned long file_size; |
| 54 |
char file_name[64]; |
| 55 |
char *upload_file_path; |
| 56 |
unsigned long file_mtime; |
| 57 |
|
| 58 |
unsigned char RxHdr[4], TxHdr[4]; |
| 59 |
unsigned char RxType, TERM; |
| 60 |
unsigned char PktIn[1032], PktOut[1032]; |
| 61 |
short PktInPtr, PktOutPtr; |
| 62 |
short PktInCount, PktOutCount; |
| 63 |
short PktInLen; |
| 64 |
bool BinFlag; |
| 65 |
bool Sending; |
| 66 |
short ZMode, ZState, ZPktState; |
| 67 |
short MaxDataLen, TimeOut, CanCount; |
| 68 |
bool CtlEsc, CRC32, HexLo, Quoted, CRRecv, DoIACEscape; |
| 69 |
short CRC; |
| 70 |
long CRC3, Pos, LastPos, WinSize; |
| 71 |
unsigned char LastSent, LastIAC; |
| 72 |
|
| 73 |
unsigned long TimeOutAt; |
| 74 |
}; |
| 75 |
|
| 76 |
struct zmodem_session * ZCreateSender(struct session *session, FILE *fp, |
| 77 |
char *file_name); |
| 78 |
struct zmodem_session * ZCreateReceiver(struct session *session, char *path); |
| 79 |
|
| 80 |
bool ZInit(struct zmodem_session *zs); |
| 81 |
void ZDestroy(struct zmodem_session *zs); |
| 82 |
bool ZParse(struct zmodem_session *zs); |
| 83 |
void ZCancel(struct zmodem_session *zs); |
| 84 |
bool ZHaveTimedOut(struct zmodem_session *zs); |
| 85 |
void ZTimeOutProc(struct zmodem_session *zs); |
| 86 |
|
| 87 |
#endif |