|
@@ -8,7 +8,9 @@ session::session(boost::asio::ip::tcp::socket socket,
|
|
|
std::string port)
|
|
|
: socket_(std::move(socket)),
|
|
|
io_service_{io_service}, resolver_{io_service}, server_{io_service},
|
|
|
- timer_{io_service}, host{hostname}, port{port} {}
|
|
|
+ timer_{io_service}, host{hostname}, port{port} {
|
|
|
+ server_sent = 0;
|
|
|
+}
|
|
|
|
|
|
void session::start(void) {
|
|
|
std::cout << "session" << std::endl;
|
|
@@ -42,7 +44,7 @@ void session::on_connect(const boost::system::error_code error) {
|
|
|
connected = true;
|
|
|
if (rlogin_auth[0] != 0) {
|
|
|
// Ok, the rlogin information was junk --
|
|
|
- do_write("Let me make up some rlogin for you...\n\r");
|
|
|
+ do_write("Let me make up some fake rlogin data for you...\n\r");
|
|
|
char temp[] = "\0test\0test\0terminal/9600\0";
|
|
|
std::string tmp(temp, sizeof(temp));
|
|
|
server_write(tmp);
|
|
@@ -66,6 +68,44 @@ void session::on_connect(const boost::system::error_code error) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void session::dispatch_line(std::string line) {
|
|
|
+ // Does this have \n\r still on it? I don't want them.
|
|
|
+ std::cout << "SL: " << line << std::endl;
|
|
|
+ // is echo on? if so:
|
|
|
+}
|
|
|
+
|
|
|
+void session::process_lines(void) {
|
|
|
+ // break server_prompt into lines and send/process one by one.
|
|
|
+ size_t pos;
|
|
|
+ while ((pos = server_prompt.find("\n\r")) != std::string::npos) {
|
|
|
+ // line
|
|
|
+ std::string line = server_prompt.substr(0, pos + 2);
|
|
|
+ server_prompt = server_prompt.substr(pos + 2);
|
|
|
+
|
|
|
+ // Remove \n\r for dispatching
|
|
|
+ std::string part = line.substr(0, pos);
|
|
|
+ if (server_sent != 0) {
|
|
|
+ line = line.substr(server_sent);
|
|
|
+ server_sent = 0;
|
|
|
+ };
|
|
|
+ // display on?
|
|
|
+ do_write(line);
|
|
|
+
|
|
|
+ dispatch_line(part);
|
|
|
+ }
|
|
|
+
|
|
|
+ // display on?
|
|
|
+ if (server_sent != 0) {
|
|
|
+ std::string part = server_prompt.substr(server_sent);
|
|
|
+ do_write(part);
|
|
|
+ server_sent = server_prompt.size();
|
|
|
+ } else {
|
|
|
+ do_write(server_prompt);
|
|
|
+ server_sent = server_prompt.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ // server_sent is the # of chars we've already sent of this.
|
|
|
+}
|
|
|
void session::server_read(void) {
|
|
|
auto self(shared_from_this());
|
|
|
|
|
@@ -76,11 +116,17 @@ void session::server_read(void) {
|
|
|
if (!ec) {
|
|
|
server_buffer[length] = 0;
|
|
|
|
|
|
+ server_prompt.append(server_buffer, length);
|
|
|
+ process_lines();
|
|
|
+
|
|
|
+ /*
|
|
|
if (length) {
|
|
|
// std::cout << length << std::endl;
|
|
|
std::cout << "S: " << server_buffer << std::endl;
|
|
|
do_write(server_buffer);
|
|
|
}
|
|
|
+ */
|
|
|
+
|
|
|
server_read();
|
|
|
} else {
|
|
|
std::cout << "S: read_failed: connection closed" << std::endl;
|