1
0

Protocol.h 966 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef PROTOCOL_H
  2. #define PROTOCOL_H
  3. #include "Util/Util.h"
  4. #include <string>
  5. #include <utility>
  6. namespace Protocol {
  7. class Protocol
  8. {
  9. public:
  10. class State
  11. {
  12. public:
  13. enum type
  14. {
  15. Connected,
  16. Disconnected
  17. };
  18. };
  19. typedef std::pair<State::type, std::string> Result;
  20. public:
  21. explicit Protocol(const Util::Context& context);
  22. Result OpenConnection(const std::string& address);
  23. Result ProcessMessage(const std::string& message);
  24. private:
  25. class InternalState
  26. {
  27. public:
  28. enum type
  29. {
  30. None,
  31. Connect,
  32. Helo,
  33. Auth_login_user,
  34. Auth_login_pass,
  35. Mail_from,
  36. Rcpt_to,
  37. Data,
  38. Mime_boundary,
  39. Image_data,
  40. Disconnect
  41. };
  42. };
  43. private:
  44. Result Answer(State::type state, std::string answer) const;
  45. void AppendMessage(const std::string& message);
  46. private:
  47. InternalState::type m_internalState;
  48. std::string m_address;
  49. std::string m_message;
  50. const Util::Context& m_context;
  51. };
  52. } // namespace Protocol
  53. #endif // PROTOCOL_H