/* CPPDOC_BEGIN_EXCLUDE  */
/***************************************************************************

  OxYD Socket v0.1

  File : OxYDSocketHelper.h


  Versions :
     - v0.1 (20/01/2003) : Initial release

 ---------------------------------------------------------------------------

  Copyright (C) 2003  Grégory WILMES -- Engage Security (http://www.engagesecurity.com)
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

 ***************************************************************************/
/* CPPDOC_END_EXCLUDE  */

#ifndef __COXYDSOCKETHELPER_H
#define __COXYDSOCKETHELPER_H

#include "stdafx.h"
#include "OxYDSocket.h"

// Error codes
#ifndef OXYDSOCKETHELPER_ERRORS
    #define OXYDSOCKETHELPER_ERRORS
    enum ErrorsHelper  // Declare enum type Errors
    {
        ERROR__UNCOMPLETE_PACKET,
        ERROR__CORRUPTED_PACKET_HEADER,
        ERROR__EMPTY_PACKET,
        ERROR__NULL_POINTER
    };
#endif

class COxYDSocketHelper : public COxYDSocket
{
private:
    int     m_nLastError;
//  int     m_nPacketNumber;

public:
    COxYDSocketHelper();
    ~COxYDSocketHelper();

    int     m_nPacketNumber;

    BOOL    Send(const LPSTR szData, int nDataLength = -1, int nMessage = -1, int nPacketNumber = -1);
    BOOL    Encode(const LPSTR szData, int nDataLength, int nMessage, int nPacketNumber, CString &strTmp);

    BOOL    Receive(LPSTR szData, int &nDataLength, int &nMessage, int &nPacketNumber);
    BOOL    Decode(CString strTmp, LPSTR szData, int &nDataLength, int &nMessage, int &nPacketNumber);

    CString FormatMessage(int nLastError = -1);

    int     ConvDataToHex(LPSTR szData, int nDataLength, CString &strHex);
    int     ConvHexToData(CString strHex, LPSTR szData, int nDataLengthMax = -1);
};

#endif