X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fcommand_client.cpp;h=c0e863ca44a5990b5c5dd81296505c14055031c2;hp=a603634226a72cd3d2cc33408c5d4ee00eba34d4;hb=8104c8f70605ee24230e5988d7bf68e3fce7465a;hpb=91730468439e21dcf8d275d0f70d803c20ccaa7c diff --git a/src/command_client.cpp b/src/command_client.cpp index a603634..c0e863c 100644 --- a/src/command_client.cpp +++ b/src/command_client.cpp @@ -26,13 +26,61 @@ #include #include +#include + #include "command_client.hxx" +#ifdef HAVE_CONFIG_H +#include +#endif + using namespace std; namespace libt2n { +command_client::command_client(client_connection& _c) + : c(_c) +{ + // for reconnects + c.add_callback(new_connection,bind(&command_client::read_hello, boost::ref(*this))); + + read_hello(); +} + +void command_client::read_hello() +{ + // TODO: fix timeout + string resultpacket; + while(!c.get_packet(resultpacket)) + c.fill_buffer(); + + istringstream hello(resultpacket); + + char chk[5]; + hello.read(chk,4); + chk[4]=0; + if (hello.fail() || hello.eof() || string("T2Nv") != chk) + throw t2n_version_mismatch("illegal hello received (T2N)"); + + int prot_version; + hello >> prot_version; + if (hello.fail() || hello.eof() || prot_version != PROTOCOL_VERSION) + throw t2n_version_mismatch("not compatible with the server protocol version"); + + hello.read(chk,1); + if (hello.fail() || hello.eof() || chk[0] != ';') + throw t2n_version_mismatch("illegal hello received (1. ;)"); + + hello.read(chk,4); + if (hello.fail() || hello.eof() || *((int*)chk) != 1) + throw t2n_version_mismatch("host byte order not matching"); + + hello.read(chk,1); + if (hello.fail() || hello.eof() || chk[0] != ';') + throw t2n_version_mismatch("illegal hello received (2. ;)"); +} + void command_client::send_command(command* cmd, result_container &res) { ostringstream ofs;