File indexing completed on 2024-03-24 15:43:25

0001 /***************************************************************************
0002                           cmccp.h  -  MCCP support
0003                              -------------------
0004     begin                : Pi feb 14 2003
0005     copyright            : (C) 2003 by Tomas Mecir
0006     email                : kmuddy@kmuddy.com
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #ifndef CMCCP_H
0019 #define CMCCP_H
0020 
0021 #include <zlib.h>
0022 
0023 class cTelnet;
0024 
0025 /**
0026 MCCP v1/v2 parser and decompressor.
0027   *@author Tomas Mecir
0028   */
0029 
0030 class cMCCP {
0031 public: 
0032   cMCCP (cTelnet *_telnet);
0033   ~cMCCP ();
0034   /** Prepare decompression, params are input/output buffers and size of
0035   output buffer. */
0036   void prepareDecompression (char *_inBuf, char *_outBuf, int inSize, int buflen);
0037   /** Uncompress as much as fits in the output buffer. Uncompressed
0038   portions are placed there as well. */
0039   int uncompressNext ();
0040   /** MCCP v1 changes state */
0041   void setMCCP1 (bool val);
0042   /** MCCP v2 changes state */
0043   void setMCCP2 (bool val);
0044   /** returns amount of compressed bytes received so far */
0045   int compressedBytes () { return compressed; };
0046   /** returns size of all received data after decompression */
0047   int uncompressedBytes () { return decompressed; };
0048   /** reset the object */
0049   void reset ();
0050   bool usingMCCP () { return usemccp; };
0051   int MCCPVer () { return usemccp ? (mccp2 ? 2 : 1) : 0; };
0052 private:
0053   /** this function does the actual decompression */
0054   int doUncompressNext ();
0055   
0056   char *inBuf;
0057   char *outBuf;
0058   int len;
0059   z_stream stream;
0060 
0061   cTelnet *telnet;
0062   bool usemccp;
0063   bool mccp1, mccp2;
0064   bool instream;
0065   char seqData[8];
0066   int state;
0067 
0068   int compressed, decompressed;
0069 };
0070 
0071 #endif