[complement-svn] SF.net SVN: complement: [1847] trunk/complement/explore/app/SMTP-tools
Status: Pre-Alpha
Brought to you by:
complement
From: <oke...@us...> - 2008-04-22 11:42:59
|
Revision: 1847 http://complement.svn.sourceforge.net/complement/?rev=1847&view=rev Author: okechina Date: 2008-04-22 04:42:53 -0700 (Tue, 22 Apr 2008) Log Message: ----------- Added Paths: ----------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile.inc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.h trunk/complement/explore/app/SMTP-tools/smtp_server_ut/unit_test.cc Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,74 @@ +# -*- Makefile -*- Time-stamp: <07/08/03 22:38:12 ptr> + +SRCROOT := ../../.. + +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak + + +INCLUDES += -I$(SRCROOT)/include +ifdef BOOST_DIR +INCLUDES += -I$(BOOST_INCLUDE_DIR) +endif +DEFS += -D__FIT_EXAM + +# temporary, before dums fix strings: +# DEFS += -D_STLP_DONT_USE_TEMPLATE_EXPRESSION + +# RPATH := $(realpath ${CoMT_LIB_DIR}) +# ifndef WITHOUT_STLPORT +# RPATH := ${RPATH}:$(realpath ${STLPORT_LIB_DIR}):$(realpath /usr/lib) +# endif + +LIBMT_DIR = ${CoMT_DIR}/lib/mt +# LIBUTF_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/test/unit_test_framework +LIBEXAM_DIR = ${CoMT_DIR}/lib/exam +LIBFS_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/filesystem + +ifeq ($(OSNAME),linux) + +release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBFS_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBFS_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} + +dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBFS_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBFS_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} + +ifndef WITHOUT_STLPORT +stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBFS_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBFS_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +endif + +endif + +ifeq ($(OSNAME),openbsd) + +release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} + +dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} + +ifndef WITHOUT_STLPORT +stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +endif + +endif + +release-shared : LDLIBS = -lxmt -lexam +dbg-shared : LDLIBS = -lxmtg -lexamg +ifndef WITHOUT_STLPORT +stldbg-shared : LDLIBS = -lxmtstlg -lexamstlg +endif + +ifeq ($(OSNAME),freebsd) +release-shared : LDLIBS += -lthr +dbg-shared : LDLIBS += -lthr +ifndef WITHOUT_STLPORT +stldbg-shared : LDLIBS += -lthr +endif +endif + +ifeq ($(OSNAME),sunos) +release-shared : LDLIBS += -lrt +dbg-shared : LDLIBS += -lrt +ifndef WITHOUT_STLPORT +stldbg-shared : LDLIBS += -lrt +endif +endif + + Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile.inc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile.inc (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile.inc 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,7 @@ +# -*- makefile -*- Time-stamp: <08/03/26 10:12:36 ptr> + +PRGNAME = my_ut +SRC_CC = unit_test.cc \ + my_test.cc \ + my_test_suite.cc \ + SMTP_Server.cc Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,151 @@ +#include <iostream> +#include <string> +#include "SMTP_Server.h" + +using namespace std; + +command setCom(const string& str) { + string Str(str); + for(int i = 0; Str[i] != '\0'; i++) + Str[i] = tolower(Str[i]); + if (Str == "helo") return helo; + else if (Str == "ehlo") return ehlo; + else if (Str == "mail") return mail; + else if (Str == "rcpt") return rcpt; + else if (Str == "data") return data; + else if (Str == "rset") return rset; + else if (Str == "vrfy") return vrfy; + else if (Str == "expn") return expn; + else if (Str == "help") return help; + else if (Str == "noop") return noop; + else if (Str == "quit") return quit; + else return none; +} + +void change(state& st, command& com, string& param, string& stout) { + switch (com) { + case helo: + if (st == connect) { + stout = "250 localhost Hello localhost, pleased to meet you\n"; + st = hello; + return; + } + else { + stout = "503 localhost Duplicate HELO/EHLO\n"; + return; + } + case ehlo: + if (st == connect) { + stout = "250-localhost Hello localhost, pleased to meet you\n"; + stout += "250-8BITMIME\n"; + stout += "250-SIZE 8000000\n"; + stout += "250 HELP\n"; + st = hello; + return; + } + else { + stout = "503 localhost Duplicate HELO/EHLO\n"; + return; + } + case mail: + switch (st) { + case connect: + stout = "503 Polite people say HELO first\n"; + return; + case hello: + stout = "250 " + param + "... Sender ok\n"; + st = sender; + return; + case sender: + stout = "503 Sender already specified\n"; + return; + case recipient: + stout = "503 Sender already specified\n"; + return; + } + case rcpt: + switch (st) { + case connect: + stout = "503 Need MAIL before RCPT\n"; + return; + case hello: + stout = "503 Need MAIL before RCPT\n"; + return; + case sender: + stout = "250 " + param + "... Recipient ok\n"; + st = recipient; + return; + case recipient: + stout = "250 " + param + "... Recipient ok\n"; + return; + } + case data: + switch (st) { + case connect: + stout = "503 Need MAIL command\n"; + return; + case hello: + stout = "503 Need MAIL command\n"; + return; + case sender: + stout = "503 Need RCPT (recipient)\n"; + return; + case recipient: + stout = "354 Enter mail, end with '.' on a line by itself\n"; + st = letter; + return; + } + case rset: + stout = "250 Reset state\n"; + if (st!=connect) st = hello; + return; + case vrfy: + stout = "502 Command not implemented\n"; + return; + case expn: + stout = "502 Command not implemented\n"; + return; + case help: + stout = "214-This is SMTP_Server\n"; + stout += "214 End of HELP info\n"; + return; + case noop: + stout = "250 OK\n"; + return; + case quit: + stout = "221 localhost closing connection\n"; + stout += "Connection closed by foreign host.\n"; + st = disconnect; + return; + case none: + stout = "500 Command unrecognized\n"; + return; + } +} + + +int ServerWork() { + state st = connect; + command com; + string param, message, stout; + while (st != disconnect) { + if (st != letter) { + string str; + cin >> str; + getline(cin, param); + com = setCom(str); + change(st, com, param, stout); + cout << stout; + } + else { + getline(cin, param); + if (param != ".") message = message + param + "\n"; + else { + st = hello; + cout << message; + message = ""; + } + }; + }; + return 0; +} Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,32 @@ +using namespace std; + +enum state { + disconnect, + connect, + hello, + sender, + recipient, + letter + }; +enum command { + helo, + ehlo, + mail, + rcpt, + data, + rset, + vrfy, + expn, + help, + noop, + quit, + none + }; + + +int ServerWork(); + +command setCom(const string& str); + +void change(state& st, command& com, string& param, string& stout); + Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,97 @@ +// -*- C++ -*- Time-stamp: <08/03/26 01:53:46 ptr> + +#include "my_test.h" +#include "SMTP_Server.h" + +#include <mt/thread> +#include <mt/mutex> +#include <mt/condition_variable> +#include <misc/type_traits.h> +#include <typeinfo> + +#include <iostream> +#include <semaphore.h> + +#include <sys/wait.h> +#include <sys/ipc.h> +#include <sys/shm.h> + +#include <unistd.h> + +using namespace std; + +static int fd1[2], fd2[2]; + +const int buf_size = 1024; +const int com_length = 4; + +void server_thread() +{ + char buffer[buf_size]; + state st = connect; + command com; + string param, message, stout; + + while (st != disconnect) { + if (st != letter) { + + if (read (fd2[0], buffer, sizeof(buffer)) < 1) fprintf(stderr,"Reading error\n"); + else fprintf (stderr,"%s\n",buffer); + + string str(buffer); + param.assign (str, com_length, str.size()); + str.erase (com_length, str.size() - com_length + 1); + com = setCom (str); + change (st, com, param, stout); + + strcpy (buffer, stout.c_str()); + write (fd1[1], buffer, sizeof(buffer)); + } + else { + read (fd2[0], buffer, sizeof(buffer)); + param.assign (buffer, 0, sizeof(buffer)); + if (param != ".") message = message + param + "\n"; + else { + st = hello; +// cout << message; + message = ""; + } + }; + }; + cerr << "Server's loop may be here" << endl; +} + +int EXAM_IMPL(my_test::thread_call) +{ + char r_buffer[buf_size], w_buffer[buf_size]; + pipe (fd1); + pipe (fd2); + std::tr2::basic_thread<0,0> t( server_thread ); + + strcpy (w_buffer, "ehlo"); + write (fd2[1], w_buffer, sizeof(w_buffer)); + read (fd1[0], r_buffer, sizeof(r_buffer)); + cerr << r_buffer; + + strcpy (w_buffer, "help"); + write (fd2[1], w_buffer, sizeof(w_buffer)); + read (fd1[0], r_buffer, sizeof(r_buffer)); + cerr << r_buffer; + + strcpy (w_buffer, "quit"); + write (fd2[1], w_buffer, sizeof(w_buffer)); + read (fd1[0], r_buffer, sizeof(r_buffer)); + cerr << r_buffer; + + cerr << "Client's text may be here" << endl; + t.join(); + + // EXAM_CHECK( val == 1 ); + // std::tr2::basic_thread<0,0> t2( thread_func_int, 2 ); + // t2.join(); + // EXAM_CHECK( val == 2 ); + // val = 0; + + return EXAM_RESULT; +} + Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,18 @@ +// -*- C++ -*- Time-stamp: <08/02/25 12:12:20 ptr> + + +#ifndef __MY_TEST_H +#define __MY_TEST_H + +#define FIT_EXAM + +#include <exam/suite.h> +// #include <mt/shm.h> + +class my_test +{ + public: + int EXAM_DECL(thread_call); +}; + +#endif // __MY_TEST_H Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,16 @@ +// -*- C++ -*- Time-stamp: <08/03/26 10:12:21 ptr> + +#include "my_test_suite.h" +#include "my_test.h" + +#include <config/feature.h> + +int EXAM_IMPL(my_test_suite) +{ + exam::test_suite t( "my test" ); + my_test test; + + t.add( &my_test::thread_call, test, "my_test::thread_call" ); + + return t.girdle(); +}; Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.h =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.h (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.h 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,10 @@ +// -*- C++ -*- Time-stamp: <07/07/16 22:08:39 ptr> + +#ifndef __MY_TEST_SUITE_H +#define __MY_TEST_SUITE_H + +#include <exam/suite.h> + +int EXAM_DECL(my_test_suite); + +#endif // __MY_TEST_SUITE_H Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/unit_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/unit_test.cc (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/unit_test.cc 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,11 @@ +// -*- C++ -*- Time-stamp: <07/07/16 22:12:10 ptr> + +#include <exam/suite.h> +#include <config/feature.h> + +#include "my_test_suite.h" + +int main( int, char ** ) +{ + return my_test_suite(0); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |