#ifndef __NETSOCK_H__
#define __NETSOCK_H__

#ifndef __NETUTILS_H__
#include "netutils.h" 
#endif

class TSocketServer : public TLanServer
{                
  byte* m_pData;
  unsigned int m_dwSize;

protected:  // TLanManager
  virtual bool Boot();
  virtual bool ShutDown();

  virtual bool OnRemoveConnection(CONNID id);

public:   
  byte* GetBuffer(size_t dwSize);
  const byte* GetData() const { return m_pData; }

  bool OnConnect(const TString& topic);
  void OnConnectConfirm(CONNID id);

public:
  virtual bool IsOk() const;

  TSocketServer(const char* name);
  virtual ~TSocketServer();
};

class TSocketClient : public TLanClient
{
  byte* m_pData;
  size_t m_dwSize;
  int m_nTimeout;
    
protected:  // TLanClient
  virtual TConnection* OnQueryConnection(const char* service, const char* server);
  int HttpGetHeader(CONNID id, const char* remote, const char* authorization, TString_array& header);
  
public:
  virtual bool Request(CONNID id, const char* cmd);
  virtual byte* GetBuffer(size_t& dwSize);
  virtual void ReleaseBuffer();
  virtual bool IsOk() const { return TRUE; }

  bool WriteLine(CONNID id, const char* str);
  bool ReadLine(CONNID id, TString& str);

  bool HttpIsRedirectedServer(CONNID id, TString & http_server, TFilename & remote, const char* authorization = NULL);
  bool HttpGetFile(CONNID id, const char* remote, const char* local, const char* authorization = NULL);
  bool HttpGetDir(CONNID id, const char* remote, TString_array& list);
  bool HttpSoap(CONNID id, const char* query);
  bool HttpPostFile(CONNID id, const char* remote, const char* local, const char* authorization = NULL);
  bool HttpPutFile(CONNID id, const char* remote, const char* local);
  bool FtpSendFile(CONNID id, const char* remote, const char* local, const char* user, const char* pass);

  int Timeout() const { return m_nTimeout; }
  void SetTimeout(int sec) { m_nTimeout= sec; }
  TSocketClient();
  virtual ~TSocketClient();
};

class TDDEClient : public TLanClient
{
protected:
  virtual TConnection* OnQueryConnection(const char* service, const char* server);
  virtual bool OnRemoveConnection(CONNID id);
  virtual byte* GetBuffer(unsigned int& dwSize);
  virtual void ReleaseBuffer();

public:
  virtual bool Execute(CONNID id, const char* cmd);
};

#endif