| 
					
				 | 
			
			
				@@ -1,28 +1,88 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-#include "dispatchers.h" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+#include <boost/format.hpp> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+#include "dispatchers.h" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #include "logging.h" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-Dispatch::Dispatch(Session &s) : sess{s} {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+Dispatch::Dispatch(Session *s) : sess{s} {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+Dispatch::~Dispatch(){}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void Dispatch::to_server(const std::string &send) { sess->to_server(send); } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void Dispatch::to_client(const std::string &send) { sess->to_client(send); } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+const std::string &Dispatch::get_prompt(void) { return sess->get_prompt(); } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void Dispatch::setNotify(notifyFunc nf) { notify_ = nf; } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void Dispatch::notify(void) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (notify_) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    sess->post(notify_); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    notify_ = nullptr; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+MainDispatch::MainDispatch(Session *s) : Dispatch{s} { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(warning) << "MainDispatch()"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void MainDispatch::activate(void) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // how to set this event to our method? 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  sess->emit_server_line = [this](const std::string &s) { server_line(s); }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  sess->emit_server_prompt = [this](const std::string &s) { server_prompt(s); }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  sess->emit_client_input = [this](const std::string &s) { client_input(s); }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  sess->show_client = false; // don not auto-send server to client 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  sess->talk_direct = false; // do not auto-send client to server 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  count = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  old_prompt = sess->get_prompt(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  to_client("\n\r\x1b[1;34mWELCOME!  You are now in the proxy zone...\n\r"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-Dispatch::~Dispatch() {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void MainDispatch::deactivate(void) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // Since we're the main thing there -- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  sess->emit_server_line = nullptr; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  sess->emit_server_prompt = nullptr; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  sess->emit_client_input = nullptr; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  sess->show_client = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  sess->talk_direct = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  sess->set_prompt(old_prompt); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  notify(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// virtuals 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-/* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-void Dispatch::server_line(const std::string &line){}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-void Dispatch::server_prompt(const std::string &prompt){}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-void Dispatch::client_input(const std::string &input){}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void MainDispatch::server_line(const std::string &line) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(info) << "MDSL: " << line; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  to_client("SL: "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  to_client(line); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  to_client("\n\r"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-void Dispatch::to_server(const std::string &send) { sess.to_server(send); } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-void Dispatch::to_client(const std::string &send) { sess.to_client(send); } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-const std::string &Dispatch::get_prompt(void) { return sess.get_prompt(); } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void MainDispatch::server_prompt(const std::string &prompt) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(info) << "MDSP: " << prompt; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void MainDispatch::client_input(const std::string &input) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // I don't care what the old prompt looked liked at this point. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(warning) << "Got: " << input; //  << " prompt=" << get_prompt(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // Serious problem when the input = "\x1b" ESC.  The output gets gummed/locked 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // up. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (input == "\x1b") { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  ++count; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  std::string output = str(boost::format("MSG %1%: [%2%]\n\r") % count % input); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  to_client(output); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (count >= 5) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    to_client("And we're outta here!\n\r"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-CoreDispatch::CoreDispatch(Session &s) : Dispatch{s} { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    BUGZ_LOG(warning) << "CoreDispatch()"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+CoreDispatch::CoreDispatch(Session *s) : Dispatch{s} { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(warning) << "CoreDispatch()"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 void CoreDispatch::server_line(const std::string &line) {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 void CoreDispatch::server_prompt(const std::string &prompt) {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 void CoreDispatch::client_input(const std::string &input) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    BUGZ_LOG(warning) << "Got: " << input << " prompt=" << get_prompt(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(warning) << "Got: " << input << " prompt=" << get_prompt(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |