Thread: [complement-svn] SF.net SVN: complement: [1861] trunk/complement/explore/app/SMTP-tools/ smtp_serve
Status: Pre-Alpha
Brought to you by:
complement
From: <oke...@us...> - 2008-04-28 14:38:30
|
Revision: 1861 http://complement.svn.sourceforge.net/complement/?rev=1861&view=rev Author: okechina Date: 2008-04-28 07:37:50 -0700 (Mon, 28 Apr 2008) Log Message: ----------- Checking whether a proper command string was read Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-25 11:26:22 UTC (rev 1860) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-28 14:37:50 UTC (rev 1861) @@ -29,12 +29,12 @@ // letter const string set_state[] = { - "quit\n", +// "quit\n", "", "helo mail.ru\n", "helo mail.ru\nmail from:se...@ma...\n", "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\n", - "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\ndata\n" +// "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\ndata\n" }; //possible commands @@ -68,13 +68,13 @@ }; const int set_result[][sizeof(set_command)/sizeof(set_command[0])] = { - {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999}, +// {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999}, // {221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221}, {250, 250, 503, 503, 503, 250, 502, 502, 214, 250, 221, 500}, {503, 503, 250, 503, 503, 250, 502, 502, 214, 250, 221, 500}, {503, 503, 503, 250, 503, 250, 502, 502, 214, 250, 221, 500}, {503, 503, 503, 250, 354, 250, 502, 502, 214, 250, 221, 500}, - {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999} +// {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999} }; const int buf_size = 1024; @@ -91,32 +91,48 @@ state st = connect; command com; string param, message, stout; - while ( st != disconnect ) { if ( st != letter ) { - if ( read( fd2[0], buffer, sizeof(buffer) ) < 1 ) { // <-- error (1) + int n = read( fd2[0], buffer, sizeof(buffer) ); + if ( n < 0 ) { cerr << "Reading error\n"; + break; + } else if ( n == 0 ) { + break; } else { + buffer[n] = '\0'; cerr << ">> " << buffer << endl; - string str( buffer ); // <-- error (1) - param.assign( str, com_length, str.size() ); - str.erase( com_length, str.size() - com_length + 1 ); + stringstream st_stream; + st_stream << buffer << " "; + string str; + st_stream >> str >> param; +// param.assign( str, com_length, str.size() ); +// str.erase( com_length, str.size() - com_length + 1 ); com = setCom( str ); change( st, com, param, stout ); write( fd1[1], stout.data(), stout.length() ); } } else { - read( fd2[0], buffer, sizeof(buffer) ); // <-- error (2) - param.assign (buffer, 0, sizeof(buffer) ); // <-- error (2) - if ( param != "." ) { - message += param + "\n"; - } else { - st = hello; - // cout << message; - message = ""; + int n = read( fd2[0], buffer, sizeof(buffer) ); + if ( n < 0 ) { + cerr << "Reading error\n"; + } else if ( n == 0 ) { + cerr << "Empty string\n"; + } else { + buffer[n] = '\0'; + param.assign (buffer, 0, sizeof(buffer) ); + if ( param != "." ) { + message += param + "\n"; + } else { + st = hello; + // cout << message; + message = ""; + } } } } + close(fd2[0]); + close(fd1[1]); active = false; // cerr << "Server's loop may be here" << endl; @@ -131,7 +147,6 @@ string s; string expected; - for ( int i = 0; i <= test_num; ++i ) { char r_buffer[buf_size], w_buffer[buf_size]; @@ -149,13 +164,20 @@ getline( in, s ); if ( !s.empty() ) { write( fd2[1], s.data(), s.length() ); - read( fd1[0], r_buffer, sizeof(r_buffer) ); // <-- error (3) - cerr << "<< " << r_buffer; // <-- error (3) + int n = read( fd1[0], r_buffer, sizeof(r_buffer) ); + if ( n < 0 ) { + cerr << "Reading error\n"; + } else if ( n == 0 ) { + cerr << "Empty string\n"; + } else { + r_buffer[n] = '\0'; + cerr << "<< " << r_buffer; + } } } - + close(fd2[1]); + close(fd1[0]); in.close(); - t.join(); string result(r_buffer); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <oke...@us...> - 2008-04-29 14:13:33
|
Revision: 1867 http://complement.svn.sourceforge.net/complement/?rev=1867&view=rev Author: okechina Date: 2008-04-29 07:12:55 -0700 (Tue, 29 Apr 2008) Log Message: ----------- Checking if the string read is not the whole command or if several commands were sent at once Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-29 12:19:14 UTC (rev 1866) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-29 14:12:55 UTC (rev 1867) @@ -90,39 +90,57 @@ char buffer[buf_size]; state st = connect; command com; - string param, message, stout; while ( st != disconnect ) { if ( st != letter ) { - int n = read( fd2[0], buffer, sizeof(buffer) ); + bool full = false; + stringstream st_stream; + while (!full) { + int n = read( fd2[0], buffer, sizeof(buffer) ); + if ( n < 0 ) { + cerr << "Reading error\n"; + break; + } else if ( n == 0 ) { + break; + } else { + buffer[n] = '\0'; + cerr << ">> " << buffer; + st_stream << buffer; + full = full || (buffer[n-1] == '\n'); + } + }; + if (full) { + cerr << st_stream.str(); + while (st_stream.good()) { + string str; + string param, stout; + st_stream >> str; + if (str != "") { + getline (st_stream, param); + cerr << param; +// param.assign( str, com_length, str.size() ); +// str.erase( com_length, str.size() - com_length + 1 ); + com = setCom( str ); + change( st, com, param, stout ); + write( fd1[1], stout.data(), stout.length() ); + } + } + } else { //error appeared while reading a command + break; + }; + } else { + string message, s; + int n = read( fd2[0], buffer, sizeof(buffer) ); if ( n < 0 ) { cerr << "Reading error\n"; break; } else if ( n == 0 ) { + cerr << "Empty\n"; break; } else { buffer[n] = '\0'; - cerr << ">> " << buffer << endl; - stringstream st_stream; - st_stream << buffer << " "; - string str; - st_stream >> str >> param; -// param.assign( str, com_length, str.size() ); -// str.erase( com_length, str.size() - com_length + 1 ); - com = setCom( str ); - change( st, com, param, stout ); - write( fd1[1], stout.data(), stout.length() ); - } - } else { - int n = read( fd2[0], buffer, sizeof(buffer) ); - if ( n < 0 ) { - cerr << "Reading error\n"; - } else if ( n == 0 ) { - cerr << "Empty string\n"; - } else { - buffer[n] = '\0'; - param.assign (buffer, 0, sizeof(buffer) ); - if ( param != "." ) { - message += param + "\n"; + s.assign (buffer, 0, n); + if ( s != "." ) { + message += s + "\n"; } else { st = hello; // cout << message; @@ -164,17 +182,24 @@ getline( in, s ); if ( !s.empty() ) { write( fd2[1], s.data(), s.length() ); + write( fd2[1], "\n", 1 ); int n = read( fd1[0], r_buffer, sizeof(r_buffer) ); if ( n < 0 ) { cerr << "Reading error\n"; + break; } else if ( n == 0 ) { cerr << "Empty string\n"; + break; } else { r_buffer[n] = '\0'; cerr << "<< " << r_buffer; } } } + +// string str ("helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\nquit\n"); + write( fd2[1], str.data(), str.length() ); + close(fd2[1]); close(fd1[0]); in.close(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <oke...@us...> - 2008-05-05 14:11:37
|
Revision: 1871 http://complement.svn.sourceforge.net/complement/?rev=1871&view=rev Author: okechina Date: 2008-05-05 07:11:27 -0700 (Mon, 05 May 2008) Log Message: ----------- Creating client-server dialog using streams for input/output Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-03 05:38:59 UTC (rev 1870) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-05 14:11:27 UTC (rev 1871) @@ -101,15 +101,39 @@ ifstream in( fd2[0] ); ofstream out( fd1[1] ); #elif defined( __GNUC__ ) - __gnu_cxx::stdio_filebuf _in_buf( fd2[0], std::ios_base::in ); + __gnu_cxx::stdio_filebuf<char> _in_buf( fd2[0], std::ios_base::in ); basic_istream<char> in( &_in_buf ); - __gnu_cxx::stdio_filebuf _out_buf( fd1[1], std::ios_base::out ); - basic_istream<char> in( &_out_buf ); + __gnu_cxx::stdio_filebuf<char> _out_buf( fd1[1], std::ios_base::out ); + basic_ostream<char> out( &_out_buf ); #endif + + string param, message, stout; while ( st != disconnect ) { if ( st != letter ) { + string str; + in >> str; + getline(in, param); + com = setCom(str); + change(st, com, param, stout); + write( fd1[1], stout.data(), stout.length() ); +// out << stout; + } else { + getline( in, param ); + if ( param != "." ) { + message += param + "\n"; + } else { + st = hello; +// out << message; + message = ""; + } + } + } + + +/* while ( st != disconnect ) { + if ( st != letter ) { bool full = false; stringstream st_stream; while (!full) { @@ -127,14 +151,12 @@ } }; if (full) { - cerr << st_stream.str(); while (st_stream.good()) { string str; string param, stout; st_stream >> str; if (str != "") { getline (st_stream, param); - cerr << param; // param.assign( str, com_length, str.size() ); // str.erase( com_length, str.size() - com_length + 1 ); com = setCom( str ); @@ -167,9 +189,10 @@ } } } +*/ + close(fd2[0]); close(fd1[1]); - active = false; // cerr << "Server's loop may be here" << endl; } @@ -180,7 +203,8 @@ string s; string expected; - + string result; + for ( tests_container_type::const_iterator i = tests.begin(); i != tests.end(); ++i ) { pipe( fd1 ); pipe( fd2 ); @@ -189,11 +213,11 @@ ifstream in( fd1[0] ); ofstream out( fd2[1] ); #elif defined( __GNUC__ ) - __gnu_cxx::stdio_filebuf _in_buf( fd1[0], std::ios_base::in ); + __gnu_cxx::stdio_filebuf<char> _in_buf( fd1[0], std::ios_base::in ); basic_istream<char> in( &_in_buf ); - __gnu_cxx::stdio_filebuf _out_buf( fd2[1], std::ios_base::out ); - basic_istream<char> in( &_out_buf ); + __gnu_cxx::stdio_filebuf<char> _out_buf( fd2[1], std::ios_base::out ); + basic_ostream<char> out( &_out_buf ); #endif char r_buffer[buf_size], w_buffer[buf_size]; @@ -204,12 +228,12 @@ getline( in_tst, expected ); - while ( in.good() ){ + while ( in_tst.good() ){ getline( in_tst, s ); if ( !s.empty() ) { write( fd2[1], s.data(), s.length() ); write( fd2[1], "\n", 1 ); - int n = read( fd1[0], r_buffer, sizeof(r_buffer) ); +/* int n = read( fd1[0], r_buffer, sizeof(r_buffer) ); if ( n < 0 ) { cerr << "Reading error\n"; break; @@ -220,24 +244,31 @@ r_buffer[n] = '\0'; cerr << "<< " << r_buffer; } + out << s << "\n"; +*/ cerr << s << "\n"; +// do { + getline (in, result); + cerr << result; +// } while (!result.empty()); +// if (result.empty()) cerr << "Empty"; } } - string str ("helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\nquit\n"); - write( fd2[1], str.data(), str.length() ); +// string str ("helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\nquit\n"); +// write( fd2[1], str.data(), str.length() ); close(fd2[1]); close(fd1[0]); t.join(); - string result(r_buffer); +// string result(r_buffer); if ( expected.compare(0, 3, result, 0, 3) != 0 ) { cerr << expected << "!=" << result << " at " << *i << endl; } EXAM_CHECK( expected.compare(0, 3, result, 0, 3) == 0 ); - + } /* strcpy (w_buffer, "help"); write (fd2[1], w_buffer, sizeof(w_buffer)); read (fd1[0], r_buffer, sizeof(r_buffer)); @@ -250,7 +281,6 @@ cerr << "Client's text may be here" << endl; */ - } // EXAM_CHECK( val == 1 ); // std::tr2::basic_thread<0,0> t2( thread_func_int, 2 ); // t2.join(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-05-05 14:18:47
|
Revision: 1872 http://complement.svn.sourceforge.net/complement/?rev=1872&view=rev Author: complement Date: 2008-05-05 07:18:45 -0700 (Mon, 05 May 2008) Log Message: ----------- flush for output stream, in endl manipulator Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-05 14:11:27 UTC (rev 1871) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-05 14:18:45 UTC (rev 1872) @@ -231,8 +231,8 @@ while ( in_tst.good() ){ getline( in_tst, s ); if ( !s.empty() ) { - write( fd2[1], s.data(), s.length() ); - write( fd2[1], "\n", 1 ); + out << s << endl; // write( fd2[1], s.data(), s.length() ); + // write( fd2[1], "\n", 1 ); /* int n = read( fd1[0], r_buffer, sizeof(r_buffer) ); if ( n < 0 ) { cerr << "Reading error\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |