diff 3rdparty/vmime/examples/example6_tracer.hpp @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/vmime/examples/example6_tracer.hpp	Tue Aug 17 11:19:54 2021 +0200
@@ -0,0 +1,53 @@
+
+/** Tracer used to demonstrate logging communication between client and server.
+  */
+
+class myTracer : public vmime::net::tracer
+{
+public:
+
+	myTracer(vmime::shared_ptr <std::ostringstream> stream,
+	         vmime::shared_ptr <vmime::net::service> serv, const int connectionId)
+		: m_stream(stream), m_service(serv), m_connectionId(connectionId)
+	{
+	}
+
+	void traceSend(const vmime::string& line)
+	{
+		*m_stream << "[" << m_service->getProtocolName() << ":" << m_connectionId
+		          << "] C: " << line << std::endl;
+	}
+
+	void traceReceive(const vmime::string& line)
+	{
+		*m_stream << "[" << m_service->getProtocolName() << ":" << m_connectionId
+		          << "] S: " << line << std::endl;
+	}
+
+private:
+
+	vmime::shared_ptr <std::ostringstream> m_stream;
+	vmime::shared_ptr <vmime::net::service> m_service;
+	const int m_connectionId;
+};
+
+class myTracerFactory : public vmime::net::tracerFactory
+{
+public:
+
+	myTracerFactory(vmime::shared_ptr <std::ostringstream> stream)
+		: m_stream(stream)
+	{
+	}
+
+	vmime::shared_ptr <vmime::net::tracer> create
+		(vmime::shared_ptr <vmime::net::service> serv, const int connectionId)
+	{
+		return vmime::make_shared <myTracer>(m_stream, serv, connectionId);
+	}
+
+private:
+
+	vmime::shared_ptr <std::ostringstream> m_stream;
+};
+