Advertisement
Guest User

ProtocolParser.h

a guest
Dec 26th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. // Copyright (c) 2008 Martin Knafve / hMailServer.com.  
  2. // http://www.hmailserver.com
  3.  
  4. #pragma once
  5.  
  6. namespace HM
  7. {
  8.    class ByteBuffer;
  9.    class TCPConnection;
  10.    class SecurityRange;
  11.  
  12.    class ProtocolParser
  13.    {
  14.    public:
  15.       ProtocolParser();
  16.       ~ProtocolParser();
  17.  
  18.       void Initialize(TCPConnection* parentConnection);
  19.      
  20.       virtual AnsiString GetCommandSeparator() const = 0;
  21.      
  22.       shared_ptr<TCPConnection> GetTCPConnectionTemporaryPointer();
  23.  
  24.       // The connection to the server has failed
  25.       virtual void OnCouldNotConnect(const AnsiString &sErrorDescription) {};
  26.       virtual void OnConnected() = 0;
  27.       virtual void OnConnectionTimeout() = 0;
  28.       virtual void OnExcessiveDataReceived() = 0;
  29.       virtual void OnDataSent() {};
  30.       virtual void OnReadError(int errorCode) {};
  31.  
  32.       int GetTimeout();
  33.  
  34.       /* PARSING METHODS */
  35.       virtual void ParseData(const AnsiString &sAnsiString) = 0;
  36.       virtual void ParseData(shared_ptr<ByteBuffer> pByteBuffer) = 0;
  37.  
  38.       bool SendData(const AnsiString &sAnsiString);
  39.       bool SendData(shared_ptr<ByteBuffer> pByteBuffer);
  40.  
  41.       void PostReceive();
  42.       void PostBufferReceive();
  43.  
  44.       void PostShutdown(int what);
  45.  
  46.       void UpdateLogoutTimer();
  47.       int GetBufferSize();
  48.  
  49.       int GetSessionID() const;
  50.  
  51.    protected:
  52.  
  53.       void PostDisconnect();
  54.       void SetTimeout(int seconds);
  55.      
  56.  
  57.       /* UTILITY FUNCTIONS */
  58.      
  59.       void SetReceiveBinary(bool binary);
  60.      
  61.       const IPAddress GetIPAddress() const;
  62.       unsigned long GetPort() const;
  63.       unsigned long GetLocalPort() const;
  64.       AnsiString GetIPAddressString() const;
  65.  
  66.       shared_ptr<SecurityRange> GetSecurityRange() const;
  67.       void ProtocolParser::StartTLS();
  68.    private:
  69.  
  70.       TCPConnection *_parentConnection;
  71.       int _sessionID;
  72.       int _timeout;
  73.    };
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement