/* * Copyright (C) 1994-1998 T. Teranishi * (C) 2009- TeraTerm Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __ZMODEM_H__ #define __ZMODEM_H__ #include "session.h" #include "util.h" #define ZMODEM_BLOCK_SIZE 1024 /* ZMODEM function id */ #define IdZReceive 1 #define IdZSend 2 #define IdZAutoR 3 #define IdZAutoS 4 enum { ZMODEM_MODE, ZMODEM_BINFLAG }; struct zmodem_session { struct session *session; FILE *file; unsigned long file_size; char file_name[64]; char *upload_file_path; unsigned long file_mtime; unsigned char RxHdr[4], TxHdr[4]; unsigned char RxType, TERM; unsigned char PktIn[1032], PktOut[1032]; short PktInPtr, PktOutPtr; short PktInCount, PktOutCount; short PktInLen; bool BinFlag; bool Sending; short ZMode, ZState, ZPktState; short MaxDataLen, TimeOut, CanCount; bool CtlEsc, CRC32, HexLo, Quoted, CRRecv, DoIACEscape; short CRC; long CRC3, Pos, LastPos, WinSize; unsigned char LastSent, LastIAC; unsigned long TimeOutAt; }; struct zmodem_session * ZCreateSender(struct session *session, FILE *fp, char *file_name); struct zmodem_session * ZCreateReceiver(struct session *session, char *path); bool ZInit(struct zmodem_session *zs); void ZDestroy(struct zmodem_session *zs); bool ZParse(struct zmodem_session *zs); void ZCancel(struct zmodem_session *zs); bool ZHaveTimedOut(struct zmodem_session *zs); void ZTimeOutProc(struct zmodem_session *zs); #endif