[complement-svn] SF.net SVN: complement: [1783] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-10-31 18:31:51
|
Revision: 1783 http://complement.svn.sourceforge.net/complement/?rev=1783&view=rev Author: complement Date: 2007-10-31 11:31:49 -0700 (Wed, 31 Oct 2007) Log Message: ----------- http moved from intercessor to net library Modified Paths: -------------- trunk/complement/explore/app/intercessor/Makefile trunk/complement/explore/app/intercessor/Makefile.inc trunk/complement/explore/app/intercessor/intercessor.h trunk/complement/explore/app/intercessor/unit/Makefile trunk/complement/explore/app/intercessor/unit/Makefile.inc trunk/complement/explore/app/intercessor/unit/dummy_srv.cc trunk/complement/explore/app/intercessor/unit/dummy_srv.h trunk/complement/explore/app/intercessor/unit/intercessor_test.cc trunk/complement/explore/app/intercessor/unit/intercessor_test.h trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.cc trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.h trunk/complement/explore/app/intercessor/unit/unit_test.cc trunk/complement/explore/include/net/cgi.h trunk/complement/explore/lib/net/Makefile trunk/complement/explore/lib/net/Makefile.inc trunk/complement/explore/lib/net/cgi.cc Added Paths: ----------- trunk/complement/explore/include/net/http.h trunk/complement/explore/lib/net/http.cc trunk/complement/explore/lib/net/samples/ trunk/complement/explore/lib/net/samples/httpclient/ trunk/complement/explore/lib/net/ut/ trunk/complement/explore/lib/net/ut/Makefile trunk/complement/explore/lib/net/ut/Makefile.inc trunk/complement/explore/lib/net/ut/http_test.cc trunk/complement/explore/lib/net/ut/http_test.h trunk/complement/explore/lib/net/ut/intercessor_test_suite.cc trunk/complement/explore/lib/net/ut/intercessor_test_suite.h trunk/complement/explore/lib/net/ut/unit_test.cc Removed Paths: ------------- trunk/complement/explore/app/intercessor/http.cc trunk/complement/explore/app/intercessor/http.h trunk/complement/explore/app/intercessor/unit/http_test.cc trunk/complement/explore/app/intercessor/unit/http_test.h Modified: trunk/complement/explore/app/intercessor/Makefile =================================================================== --- trunk/complement/explore/app/intercessor/Makefile 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/Makefile 2007-10-31 18:31:49 UTC (rev 1783) @@ -9,9 +9,9 @@ INCLUDES += -I${CoMT_INCLUDE_DIR} -I${BOOST_INCLUDE_DIR} LDFLAGS += -L${INSTALL_LIB_DIR} -Wl,-rpath=${INSTALL_LIB_DIR} -release-shared: LDLIBS = -lxmt -lsockios -lstem -lboost_regex -lboost_fs -lboost_program_options -dbg-shared: LDLIBS = -lxmtg -lsockiosg -lstemg -lboost_regexg -lboost_fsg -lboost_program_optionsg -stldbg-shared: LDLIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lboost_regexstlg -lboost_fsstlg -lboost_program_optionsstlg +release-shared: LDLIBS = -lxmt -lsockios -lNet -lstem -lboost_regex -lboost_fs -lboost_program_options +dbg-shared: LDLIBS = -lxmtg -lsockiosg -lNetg -lstemg -lboost_regexg -lboost_fsg -lboost_program_optionsg +stldbg-shared: LDLIBS = -lxmtstlg -lsockiosstlg -lNetstlg -lstemstlg -lboost_regexstlg -lboost_fsstlg -lboost_program_optionsstlg check-shared: all-shared $(MAKE) -C unit check || exit 1 Modified: trunk/complement/explore/app/intercessor/Makefile.inc =================================================================== --- trunk/complement/explore/app/intercessor/Makefile.inc 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/Makefile.inc 2007-10-31 18:31:49 UTC (rev 1783) @@ -2,7 +2,6 @@ PRGNAME = intercessor SRC_CC = intercessor_main.cc \ - http.cc \ intercessor.cc \ server.cc Deleted: trunk/complement/explore/app/intercessor/http.cc =================================================================== --- trunk/complement/explore/app/intercessor/http.cc 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/http.cc 2007-10-31 18:31:49 UTC (rev 1783) @@ -1,329 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/03/07 15:17:27 ptr> - -#include <net/http.h> -#include <istream> -#include <ostream> -#include <iomanip> -#include <boost/regex.hpp> -#include <boost/lexical_cast.hpp> -#include <algorithm> -#include <iterator> - -namespace http { - -using namespace std; - -boost::regex cmd_re( "^((?:OPTIONS)|(?:GET)|(?:HEAD)|(?:POST)|(?:PUT)|(?:DELETE)|(?:TRACE)|(?:CONNECT))(?:\\s+)(\\S+)(?:\\s+)HTTP/1\\.(0|1)\\r?$" ); -boost::regex header_re( "^([[:word:]-]+):\\s+(\\S*(?:\\s+\\S+)*)\\s*\\r?$" ); -boost::regex response_re( "^HTTP/1\\.(0|1)\\s+(\\d{3})\\s+(\\S*(?:\\s+\\S+)*)\\s*\\r?$" ); - -const string opt = "OPTIONS"; -const string get = "GET"; -const string head = "HEAD"; -const string post = "POST"; -const string put = "PUT"; -const string del = "DELETE"; -const string trace = "TRACE"; -const string conn = "CONNECT"; -const string http10 = "HTTP/1.0"; -const string http11 = "HTTP/1.1"; - - -std::ostream& operator <<( std::ostream& s, const command& c ) -{ - if ( c._cmd == command::UNKNOWN || c._proto == command::UNSPEC ) { - s.setstate( ios_base::failbit ); - return s; - } - - switch ( c._cmd ) { - case command::OPTIONS: - s << opt; - break; - case command::GET: - s << get; - break; - case command::HEAD: - s << head; - break; - case command::POST: - s << post; - break; - case command::PUT: - s << put; - break; - case command::DELETE: - s << del; - break; - case command::TRACE: - s << trace; - break; - case command::CONNECT: - s << conn; - break; - default: - s.setstate( ios_base::failbit ); - break; - } - return s << ' ' << c._url << ' ' << (c._proto == command::HTTP10 ? http10 : http11) << "\r\n"; -} - -std::istream& operator >>( std::istream& s, command& c ) -{ - string line; - boost::smatch ma; - - getline( s, line ); - - if ( !s.fail() && regex_match( line, ma, cmd_re /* , boost::regex_constants::match_partial */ ) ) { - if ( ma[1] == opt ) { - c._cmd = command::OPTIONS; - } else if ( ma[1] == get ) { - c._cmd = command::GET; - } else if ( ma[1] == head ) { - c._cmd = command::HEAD; - } else if ( ma[1] == post ) { - c._cmd = command::POST; - } else if ( ma[1] == put ) { - c._cmd = command::PUT; - } else if ( ma[1] == del ) { - c._cmd = command::DELETE; - } else if ( ma[1] == trace ) { - c._cmd = command::TRACE; - } else if ( ma[1] == conn ) { - c._cmd = command::CONNECT; - } else { - s.setstate( ios_base::failbit ); - return s; - } - - c._url = ma[2]; - - if ( ma[3] == '0' ) { - c._proto = command::HTTP10; - } else if ( ma[3] == '1' ) { - c._proto = command::HTTP11; - } else { - s.setstate( ios_base::failbit ); - } - } else { - s.setstate( ios_base::failbit ); - } - return s; -} - -std::ostream& operator <<( std::ostream& s, const header& h ) -{ - if ( h._val.first.length() == 0 ) { - return s; - } - return s << h._val.first << ": " << h._val.second << "\r\n"; -} - -std::istream& operator >>( std::istream& s, header& h ) -{ - string line; - boost::smatch ma; - - getline( s, line ); - if ( !s.fail() && regex_match( line, ma, header_re /* , boost::regex_constants::match_partial */ ) ) { - h._val.first = ma[1]; - h._val.second = ma[2]; - } else { - s.setstate( ios_base::failbit ); - } - return s; -} - -boost::regex cookie_re( "(?:(\\w+)=([^;]*)(?:;\\s+)?)*" ); - -cookie::cookie( const header& h ) -{ - if ( h.key() == "Set-Cookie" ) { - boost::smatch ma; - if ( regex_search( h.value(), ma, cookie_re, boost::match_extra ) ) { -#ifdef BOOST_REGEX_MATCH_EXTRA - for ( int j = 0; j < ma.captures(1).size(); ++j ) { - if ( ma.captures(1)[j] == "path" ) { - _path = ma.captures(2)[j]; - } else if ( ma.captures(1)[j] == "expires" ) { - _expires = ma.captures(2)[j]; - } else if ( ma.captures(1)[j] == "Expires" ) { - _expires = ma.captures(2)[j]; - } else if ( ma.captures(1)[j] == "domain" ) { - _domain = ma.captures(2)[j]; - } else if ( ma.captures(1)[j] == "comment" ) { - } else if ( ma.captures(1)[j] == "max-age" ) { - } else if ( ma.captures(1)[j] == "version" ) { - } else { - _val.first = ma.captures(1)[j]; - _val.second = ma.captures(2)[j]; - } - } -#endif - } - } -} - -std::ostream& operator <<( std::ostream& s, const base_response& r ) -{ - s << (r._proto == command::HTTP10 ? http10 : http11) << ' ' << setfill( '0' ) << setw(3) << r._code << ' '; - switch ( r._code ) { - case 100: - s << "Continue"; - break; - case 101: - s << "Switching Protocols"; - break; - case 200: - s << "Ok"; - break; - case 201: - s << "Created"; - break; - case 202: - s << "Accepted"; - break; - case 203: - s << "Non-Authoritative Information"; - break; - case 204: - s << "No Content"; - break; - case 205: - s << "Reset Content"; - break; - case 206: - s << "Partial Content"; - break; - case 300: - s << "Multiple Choices"; - break; - case 301: - s << "Moved Permanently"; - break; - case 302: - s << "Found"; - break; - case 303: - s << "See Other"; - break; - case 304: - s << "Not Modified"; - break; - case 305: - s << "Use Proxy"; - break; - case 306: - s << "(Unused)"; - break; - case 307: - s << "Temporary Redirect"; - break; - case 400: - s << "Bad Request"; - break; - case 401: - s << "Unauthorized"; - break; - case 402: - s << "Payment Required"; - break; - case 403: - s << "Forbidden"; - break; - case 404: - s << "Not Found"; - break; - case 405: - s << "Method Not Allowed"; - break; - case 406: - s << "Not Acceptable"; - break; - case 407: - s << "Proxy Authentication Required"; - break; - case 408: - s << "Request Timeout"; - break; - case 409: - s << "Conflict"; - break; - case 410: - s << "Gone"; - break; - case 411: - s << "Length Required"; - break; - case 412: - s << "Precondition Failed"; - break; - case 413: - s << "Request Entity Too Large"; - break; - case 414: - s << "Request-URI Too Long"; - break; - case 415: - s << "Unsupported Media Type"; - break; - case 416: - s << "Requested Range Not Satisfiable"; - break; - case 417: - s << "Expectation Failed"; - break; - case 500: - s << "Internal Server Error"; - break; - case 501: - s << "Not Implemented"; - break; - case 502: - s << "Bad Gateway"; - break; - case 503: - s << "Service Unavailable"; - break; - case 504: - s << "Gateway Timeout"; - break; - case 505: - s << "HTTP Version Not Supported"; - break; - default: - s.setstate( ios_base::failbit ); - break; - } - return s << "\r\n"; -} - -std::istream& operator >>( std::istream& s, base_response& r ) -{ - try { - string line; - boost::smatch ma; - - getline( s, line ); - if ( !s.fail() && regex_match( line, ma, response_re /* , boost::regex_constants::match_partial */ ) ) { - if ( ma[1] == '0' ) { - r._proto = command::HTTP10; - } else if ( ma[1] == '1' ) { - r._proto = command::HTTP11; - } else { - s.setstate( ios_base::failbit ); - return s; - } - r._code = boost::lexical_cast<int>(ma[2]); - } else { - s.setstate( ios_base::failbit ); - } - } - catch ( boost::bad_lexical_cast& err ) { - s.setstate( ios_base::failbit ); - } - return s; -} - -} // namespace http Deleted: trunk/complement/explore/app/intercessor/http.h =================================================================== --- trunk/complement/explore/app/intercessor/http.h 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/http.h 2007-10-31 18:31:49 UTC (rev 1783) @@ -1,457 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/03/07 16:11:19 ptr> - -#ifndef __http_h -#define __http_h - -#include <istream> -#include <ostream> -#include <string> -#include <sstream> -#include <functional> -#include <iterator> -#include <list> -#include <boost/lexical_cast.hpp> - -namespace http { - -class command -{ - public: - - enum cmd { - UNKNOWN, - GET, - PUT, - HEAD, - POST, - OPTIONS, - DELETE, - TRACE, - CONNECT - }; - - enum proto { - UNSPEC, - HTTP10, - HTTP11 - }; - - command() : - _cmd( UNKNOWN ), - _proto( UNSPEC ) - { } - - command( const command& c ) : - _cmd( c._cmd ), - _proto( c._proto ), - _url( c._url ) - { } - - cmd value() const - { return _cmd; } - - proto protocol() const - { return _proto; } - - const std::string& URL() const - { return _url; } - - void value( cmd c ) - { _cmd = c; } - - void protocol( proto p ) - { _proto = p; } - - void URL( const std::string& url ) - { _url = url; } - - private: - cmd _cmd; - proto _proto; - std::string _url; - - friend std::ostream& operator <<( std::ostream& s, const command& c ); - friend std::istream& operator >>( std::istream& s, command& c ); -}; - -std::ostream& operator <<( std::ostream& s, const command& c ); -std::istream& operator >>( std::istream& s, command& c ); - -class header -{ - public: - header() : - _val( std::string(), std::string() ) - { } - - header( const std::string& k, const std::string& v ) : - _val( k, v ) - { } - -#if !defined(__GNUC__) || (__GNUC__ > 3) || ((__GNUC__ == 3) && \ - ((__GNUC_MINOR__ > 4) || ((__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ > 4)) ) ) - template <class T> - header( const std::string& k, const T& v ) : - _val( k, boost::lexical_cast<std::string>(v) ) - { } - template <class T> - header( const char *k, const T& v ) : - _val( std::string(k), boost::lexical_cast<std::string>(v) ) - { } -#else - header( const std::string& k, int v ) : - _val( k, boost::lexical_cast<std::string>(v) ) - { } - header( const std::string& k, unsigned v ) : - _val( k, boost::lexical_cast<std::string>(v) ) - { } - header( const std::string& k, long v ) : - _val( k, boost::lexical_cast<std::string>(v) ) - { } - header( const std::string& k, unsigned long v ) : - _val( k, boost::lexical_cast<std::string>(v) ) - { } - header( const std::string& k, short v ) : - _val( k, boost::lexical_cast<std::string>(v) ) - { } - header( const std::string& k, unsigned short v ) : - _val( k, boost::lexical_cast<std::string>(v) ) - { } - header( const std::string& k, char v ) : - _val( k, boost::lexical_cast<std::string>(v) ) - { } - header( const std::string& k, signed char v ) : - _val( k, boost::lexical_cast<std::string>(v) ) - { } - header( const std::string& k, unsigned char v ) : - _val( k, boost::lexical_cast<std::string>(v) ) - { } - header( const std::string& k, double v ) : - _val( k, boost::lexical_cast<std::string>(v) ) - { } - header( const std::string& k, float v ) : - _val( k, boost::lexical_cast<std::string>(v) ) - { } - header( const std::string& k, const char *v ) : - _val( k, std::string(v) ) - { } - header( const char *k, const char *v ) : - _val( std::string(k), std::string(v) ) - { } -#endif - - - header( const header& h ) : - _val( h._val ) - { } - - const std::string& key() const - { return _val.first; } - - const std::string& value() const - { return _val.second; } - - void key( const std::string& k ) - { _val.first = k; } - - // template <> - void value( const std::string& v ) - { _val.second = v; } - - template <class T> - void value( const T& v ) - { _val.second = boost::lexical_cast<std::string>(v); } - - bool operator ==( const header& h ) const - { return _val.first == h._val.first; } - - bool operator ==( const std::string& s ) const - { return _val.first == s; } - - private: - std::pair<std::string,std::string> _val; - - friend std::ostream& operator <<( std::ostream& s, const header& h ); - friend std::istream& operator >>( std::istream& s, header& h ); -}; - -std::ostream& operator <<( std::ostream& s, const header& h ); -std::istream& operator >>( std::istream& s, header& h ); - -class cookie -{ - public: - - cookie() - { } - - cookie( const header& ); - - const std::string& key() const - { return _val.first; } - - const std::string& value() const - { return _val.second; } - - void key( const std::string& k ) - { _val.first = k; } - - // template <> - void value( const std::string& v ) - { _val.second = v; } - - private: - std::pair<std::string,std::string> _val; - std::string _domain; - std::string _path; - std::string _expires; -}; - -class base_response -{ - public: - base_response() : - _code( 0 ), - _proto( command::UNSPEC ) - { } - - base_response( int c, command::proto p = command::HTTP11 ) : - _code( c ), - _proto( p ) - { } - - base_response( const base_response& r ) : - _code( r._code ), - _proto( r._proto ) - { } - - int code() const - { return _code; } - - command::proto protocol() const - { return _proto; } - - void code( int c ) - { _code = c; } - - void protocol( command::proto p ) - { _proto = p; } - - private: - int _code; - command::proto _proto; - - friend std::ostream& operator <<( std::ostream& s, const base_response& r ); - friend std::istream& operator >>( std::istream& s, base_response& r ); -}; - -std::ostream& operator <<( std::ostream& s, const base_response& r ); -std::istream& operator >>( std::istream& s, base_response& r ); - -template <class R> class message_start; -template <class R> typename std::ostream& operator <<( typename std::ostream& s, const message_start<R>& r ); -template <class R> typename std::istream& operator >>( typename std::istream& s, message_start<R>& r ); - - - -struct __imsg_proxy -{ - __imsg_proxy( bool v ) : - _v( v ) - { } - - bool _v; -}; - -inline __imsg_proxy body( bool v ) -{ return __imsg_proxy( v ); } - -struct __imsg_proxy_istream -{ - __imsg_proxy_istream( std::istream& s, const __imsg_proxy& p ) : - _s( s ), - _v( p._v ) - { } - - std::istream& _s; - bool _v; -}; - -struct __imsg_proxy_ostream -{ - __imsg_proxy_ostream( std::ostream& s, const __imsg_proxy& p ) : - _s( s ), - _v( p._v ) - { } - - std::ostream& _s; - bool _v; -}; - -inline __imsg_proxy_istream operator >>( std::istream& s, const __imsg_proxy& p ) -{ return __imsg_proxy_istream( s, p ); } - -inline __imsg_proxy_ostream operator <<( std::ostream& s, const __imsg_proxy& p ) -{ return __imsg_proxy_ostream( s, p ); } - -template <class R> -class message_start -{ - public: - typedef std::list<header> headers_container_type; - - message_start() : - _bodyf( false ) - { } - - message_start( const message_start& r ): - _m( r._m ), - _body( r._body ), - _bodyf( r._bodyf ) - { - std::copy( r._headers.begin(), r._headers.end(), std::back_insert_iterator<headers_container_type>(_headers) ); - } - - R& head() - { return _m; } - - headers_container_type& headers() - { return _headers; } - - const R& head() const - { return _m; } - - const headers_container_type& headers() const - { return _headers; } - - typename headers_container_type::iterator search( const typename std::string& s ) - { return std::find( _headers.begin(), _headers.end(), s ); } - - typename headers_container_type::const_iterator search( const typename std::string& s ) const - { return std::find( _headers.begin(), _headers.end(), s ); } - - std::string& body() - { return _body; } - - const std::string& body() const - { return _body; } - - void bodyf( bool rb ) const - { _bodyf = rb; } - - private: - R _m; - headers_container_type _headers; - std::string _body; - mutable bool _bodyf; - - friend typename std::ostream& operator << <R>( typename std::ostream& s, const message_start<R>& r ); - friend typename std::istream& operator >> <R>( typename std::istream& s, message_start<R>& r ); -}; - -template <class R> -typename std::ostream& operator <<( typename std::ostream& s, const message_start<R>& r ) -{ - if ( !s.good() ) { - return s; - } - s << r._m; - for ( typename message_start<R>::headers_container_type::const_iterator i = r.headers().begin(); i != r.headers().end(); ++i ) { - s << *i; - } - if ( r._bodyf && r.body().length() > 0 && r.search( "Content-Length" ) == r.headers().end() ) { - s << typename http::header( "Content-Length", r.body().length() ); - } - s << "\r\n"; - if ( r._bodyf && r.body().length() > 0 ) { - s << r._body; - } - return s; -} - -template <class R> -typename std::istream& operator >>( typename std::istream& s, message_start<R>& r ) -{ - s >> r._m; - - std::string line; - http::header h; - - while ( !getline( s, line ).fail() && line.length() > 0 && line != "\r" ) { - // line += '\n'; - std::stringstream str( line ); - str >> h; - r._headers.push_back( h ); - } - - if ( r._bodyf ) { - // check Content-Length header (hmm, I can't process something else) - typename message_start<R>::headers_container_type::iterator cl = r.search( "Content-Length" ); - - if ( cl != r.headers().end() ) { - int len = boost::lexical_cast<int>( cl->value() ); - - if ( len > 0 ) { - // and write all body to another file - r._body.reserve( len ); - std::istreambuf_iterator<char> istr( s.rdbuf() ); - while ( len-- > 0 && s.good() ) { - r._body += *istr; - if ( len > 0 ) { - ++istr; - } - } - } - } else { - cl = r.search( "Transfer-Encoding" ); - if ( cl != r.headers().end() && cl->value() == "chunked" ) { - int chunk_size = -1; - int count = 0; - bool skws = (s.flags() & std::ios_base::skipws) != 0; - s >> std::noskipws >> std::hex >> chunk_size >> std::dec; - std::istreambuf_iterator<char> istr( s.rdbuf() ); - ++istr; ++istr; // oh, check CR/LF - count += chunk_size; - while ( chunk_size > 0 && s.good() ) { - r._body.reserve( chunk_size + r._body.length() ); - while ( chunk_size-- > 0 && s.good() ) { - r._body += *istr++; - } - ++istr; ++istr; - s >> std::hex >> chunk_size >> std::dec; - ++istr; ++istr; // oh, check CR/LF - } - r._headers.erase( cl ); - r._headers.push_back( header( "Content-Length", boost::lexical_cast<std::string>(r._body.length()) ) ); - if ( skws ) { - s.setf( std::ios_base::skipws ); - } - } else { // server not HTTP 1.1-compliant (RFC2616, 4.4) - copy( std::istreambuf_iterator<char>(s.rdbuf()), std::istreambuf_iterator<char>(), back_inserter(r._body) ); - } - } - } - - return s; -} - -template <class R> -inline std::istream& operator >>( const __imsg_proxy_istream& _sp, message_start<R>& r ) -{ - r.bodyf( _sp._v ); - return _sp._s >> r; -} - -template <class R> -inline std::ostream& operator <<( const __imsg_proxy_ostream& _sp, const message_start<R>& r ) -{ - r.bodyf( _sp._v ); - return _sp._s << r; -} - -typedef message_start<command> request; -typedef message_start<base_response> response; - -} // namespace http - -#endif // __http_h Modified: trunk/complement/explore/app/intercessor/intercessor.h =================================================================== --- trunk/complement/explore/app/intercessor/intercessor.h 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/intercessor.h 2007-10-31 18:31:49 UTC (rev 1783) @@ -6,7 +6,7 @@ #include <list> #include <deque> #include <mt/xmt.h> -#include "http.h" +#include <net/http.h> #include <stem/Event.h> #include <stem/EventHandler.h> Modified: trunk/complement/explore/app/intercessor/unit/Makefile =================================================================== --- trunk/complement/explore/app/intercessor/unit/Makefile 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/unit/Makefile 2007-10-31 18:31:49 UTC (rev 1783) @@ -12,30 +12,31 @@ LIBSOCK_DIR = ${CoMT_DIR}/lib/sockios LIBSTEM_DIR = ${CoMT_DIR}/lib/stem LIBEXAM_DIR = ${CoMT_DIR}/lib/exam +LIBNET_DIR = ${CoMT_DIR}/lib/net LIBBOOSTFS_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/filesystem LIBBOOSTRE_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/regex ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR} -L${LIBNET_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR}:${LIBNET_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBNET_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG}:${LIBNET_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG} -L${LIBNET_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG}:${LIBNET_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} endif INCLUDES += -I${CoMT_INCLUDE_DIR} -I${BOOST_INCLUDE_DIR} -I.. -release-shared: PROJECT_LIBS = -lxmt -lsockios -lstem -lboost_regex -lboost_fs -lexam -dbg-shared: PROJECT_LIBS = -lxmtg -lsockiosg -lstemg -lboost_regexg -lboost_fsg -lexamg +release-shared: PROJECT_LIBS = -lxmt -lsockios -lNet -lstem -lboost_regex -lboost_fs -lexam +dbg-shared: PROJECT_LIBS = -lxmtg -lsockiosg -lNetg -lstemg -lboost_regexg -lboost_fsg -lexamg ifndef WITHOUT_STLPORT -stldbg-shared: PROJECT_LIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lboost_regexstlg -lboost_fsstlg -lexamstlg +stldbg-shared: PROJECT_LIBS = -lxmtstlg -lsockiosstlg -lNetstlg -lstemstlg -lboost_regexstlg -lboost_fsstlg -lexamstlg endif LDLIBS = ${PROJECT_LIBS} Modified: trunk/complement/explore/app/intercessor/unit/Makefile.inc =================================================================== --- trunk/complement/explore/app/intercessor/unit/Makefile.inc 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/unit/Makefile.inc 2007-10-31 18:31:49 UTC (rev 1783) @@ -3,9 +3,7 @@ PRGNAME = ut_intercessor SRC_CC = unit_test.cc \ dummy_srv.cc \ - ../http.cc \ ../intercessor.cc \ ../server.cc \ - http_test.cc \ intercessor_test.cc \ intercessor_test_suite.cc Modified: trunk/complement/explore/app/intercessor/unit/dummy_srv.cc =================================================================== --- trunk/complement/explore/app/intercessor/unit/dummy_srv.cc 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/unit/dummy_srv.cc 2007-10-31 18:31:49 UTC (rev 1783) @@ -1,5 +1,14 @@ // -*- C++ -*- Time-stamp: <07/03/07 15:54:00 ptr> +/* + * + * Copyright (c) 2006-2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License version 3.0 + * + */ + #include "dummy_srv.h" #include <sockios/sockmgr.h> @@ -12,7 +21,7 @@ #include <exam/suite.h> -#include "http.h" +#include <net/http.h> namespace test { Modified: trunk/complement/explore/app/intercessor/unit/dummy_srv.h =================================================================== --- trunk/complement/explore/app/intercessor/unit/dummy_srv.h 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/unit/dummy_srv.h 2007-10-31 18:31:49 UTC (rev 1783) @@ -1,5 +1,14 @@ // -*- C++ -*- Time-stamp: <07/03/07 14:56:46 ptr> +/* + * + * Copyright (c) 2006-2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License version 3.0 + * + */ + #ifndef __dummy_srv_h #define __dummy_srv_h Deleted: trunk/complement/explore/app/intercessor/unit/http_test.cc =================================================================== --- trunk/complement/explore/app/intercessor/unit/http_test.cc 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/unit/http_test.cc 2007-10-31 18:31:49 UTC (rev 1783) @@ -1,171 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/03/07 16:38:24 ptr> - -/* - * - * Copyright (c) 2007 - * Petr Ovtchenkov - * - */ - -// #include <boost/filesystem/operations.hpp> -// #include <boost/filesystem/path.hpp> -#include "http_test.h" -#include <boost/lexical_cast.hpp> - -#include <string> -#include <iostream> - -#include <sstream> -// #include <fstream> -#include <iterator> -#include <unistd.h> - -#include "http.h" -// #include "intercessor.h" -// #include "server.h" - -// #include "dummy_srv.h" -// #include <sockios/sockmgr.h> -// #include <mt/lfstream.h> - -// boost::filesystem::path dir( boost::filesystem::initial_path() ); -// unsigned rq_timeout = 3; - -using namespace std; -using namespace http; - -int EXAM_IMPL(http_test::header_io) -{ - header h; - string rq = "Content-Length: 100\r\n"; - stringstream s( rq ); - - s >> h; - - EXAM_CHECK( !s.fail() ); - EXAM_CHECK( h.key() == "Content-Length" ); - EXAM_CHECK( h.value() == "100" ); - - stringstream o; - - o << h; - - EXAM_CHECK( !o.fail() ); - EXAM_CHECK( o.str() == "Content-Length: 100\r\n" ); - - return EXAM_RESULT; -} - -int EXAM_IMPL(http_test::header_sp) -{ - header h; - string rq = "Header: fields here \r\n"; - stringstream s( rq ); - - s >> h; - - EXAM_CHECK( !s.fail() ); - EXAM_CHECK( h.key() == "Header" ); - EXAM_CHECK( h.value() == "fields here" ); - - stringstream o; - - o << h; - - EXAM_CHECK( !o.fail() ); - EXAM_CHECK( o.str() == "Header: fields here\r\n" ); - - return EXAM_RESULT; -} - -int EXAM_IMPL(http_test::command) -{ - string cmd = "GET http://myhost.com HTTP/1.1\r\n"; - stringstream s( cmd ); - http::command c; - - s >> c; - - EXAM_CHECK( !s.fail() ); - EXAM_CHECK( c.value() == command::GET ); - EXAM_CHECK( c.URL() == "http://myhost.com" ); - EXAM_CHECK( c.protocol() == command::HTTP11 ); - - stringstream o; - - o << c; - - EXAM_CHECK( !o.fail() ); - EXAM_CHECK( o.str() == "GET http://myhost.com HTTP/1.1\r\n" ); - - return EXAM_RESULT; -} - -int EXAM_IMPL(http_test::base_response) -{ - string rs = "HTTP/1.1 202 Accepted\r\n"; - stringstream s( rs ); - http::base_response r; - - s >> r; - - EXAM_CHECK( !s.fail() ); - EXAM_CHECK( r.code() == 202 ); - EXAM_CHECK( r.protocol() == http::command::HTTP11 ); - - stringstream o; - - o << r; - - EXAM_CHECK( !o.fail() ); - EXAM_CHECK( o.str() == "HTTP/1.1 202 Accepted\r\n" ); - - return EXAM_RESULT; -} - -int EXAM_IMPL(http_test::request) -{ - string rq = "GET /index.html HTTP/1.1\r\n" - "Host: myhost.com\r\n" - "X-Header: test\r\n" - "\r\n"; - stringstream s( rq ); - http::request r; - - s >> r; - - EXAM_CHECK( !s.fail() ); - EXAM_CHECK( r.head().protocol() == http::command::HTTP11 ); - EXAM_CHECK( r.head().value() == http::command::GET ); - EXAM_CHECK( r.head().URL() == "/index.html" ); - EXAM_CHECK( r.headers().size() == 2 ); - EXAM_CHECK( r.headers().begin()->key() == "Host" ); - EXAM_CHECK( r.headers().begin()->value() == "myhost.com" ); - - EXAM_CHECK( r.search( "Host" ) == r.headers().begin() ); - - return EXAM_RESULT; -} - -int EXAM_IMPL(http_test::response) -{ - string rq = "HTTP/1.1 202 Accepted\r\n" - "Content-Length: 100\r\n" - "\r\n"; - stringstream s( rq ); - http::response r; - - s >> r; - - EXAM_CHECK( !s.fail() ); - EXAM_CHECK( r.head().protocol() == http::command::HTTP11 ); - EXAM_CHECK( r.head().code() == 202 ); - EXAM_CHECK( r.headers().size() == 1 ); - EXAM_CHECK( r.headers().begin()->key() == "Content-Length" ); - EXAM_CHECK( boost::lexical_cast<int>( r.headers().begin()->value() ) == 100 ); - - EXAM_CHECK( r.search( "Content-Length" ) == r.headers().begin() ); - - return EXAM_RESULT; -} - Deleted: trunk/complement/explore/app/intercessor/unit/http_test.h =================================================================== --- trunk/complement/explore/app/intercessor/unit/http_test.h 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/unit/http_test.h 2007-10-31 18:31:49 UTC (rev 1783) @@ -1,29 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/10/19 18:38:53 yeti> - -/* - * - * Copyright (c) 2007 - * Petr Ovtchenkov - * - */ - -#ifndef __http_test_h -#define __http_test_h - -#include <exam/suite.h> - -class http_test -{ - public: - - int EXAM_DECL(header_io); - int EXAM_DECL(header_sp); - int EXAM_DECL(command); - int EXAM_DECL(base_response); - int EXAM_DECL(request); - int EXAM_DECL(response); - - private: -}; - -#endif // __http_test_h Modified: trunk/complement/explore/app/intercessor/unit/intercessor_test.cc =================================================================== --- trunk/complement/explore/app/intercessor/unit/intercessor_test.cc 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/unit/intercessor_test.cc 2007-10-31 18:31:49 UTC (rev 1783) @@ -5,6 +5,8 @@ * Copyright (c) 2007 * Petr Ovtchenkov * + * Licensed under the Academic Free License version 3.0 + * */ #include <boost/filesystem/operations.hpp> @@ -20,7 +22,7 @@ #include <iterator> #include <unistd.h> -#include "http.h" +#include <net/http.h> #include "intercessor.h" #include "server.h" Modified: trunk/complement/explore/app/intercessor/unit/intercessor_test.h =================================================================== --- trunk/complement/explore/app/intercessor/unit/intercessor_test.h 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/unit/intercessor_test.h 2007-10-31 18:31:49 UTC (rev 1783) @@ -5,6 +5,8 @@ * Copyright (c) 2007 * Petr Ovtchenkov * + * Licensed under the Academic Free License version 3.0 + * */ #ifndef __intercessor_test_h Modified: trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.cc =================================================================== --- trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.cc 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.cc 2007-10-31 18:31:49 UTC (rev 1783) @@ -5,28 +5,13 @@ * Copyright (c) 2007 * Petr Ovtchenkov * + * Licensed under the Academic Free License version 3.0 + * */ #include "intercessor_test_suite.h" -#include "http_test.h" #include "intercessor_test.h" -int EXAM_IMPL(http_test_suite) -{ - exam::test_suite t( "http test" ); - - http_test test; - - t.add( &http_test::header_io, test, "" ); - t.add( &http_test::header_sp, test, "" ); - t.add( &http_test::command, test, "" ); - t.add( &http_test::base_response, test, "" ); - t.add( &http_test::request, test, "" ); - t.add( &http_test::response, test, "" ); - - return t.girdle(); -} - int EXAM_IMPL(intercessor_test_suite) { exam::test_suite t( "intercessor test" ); Modified: trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.h =================================================================== --- trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.h 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.h 2007-10-31 18:31:49 UTC (rev 1783) @@ -5,6 +5,8 @@ * Copyright (c) 2007 * Petr Ovtchenkov * + * Licensed under the Academic Free License version 3.0 + * */ #ifndef __intercessor_test_suite_h @@ -12,7 +14,6 @@ #include <exam/suite.h> -int EXAM_DECL(http_test_suite); int EXAM_DECL(intercessor_test_suite); #endif // __intercessor_test_suite_h Modified: trunk/complement/explore/app/intercessor/unit/unit_test.cc =================================================================== --- trunk/complement/explore/app/intercessor/unit/unit_test.cc 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/app/intercessor/unit/unit_test.cc 2007-10-31 18:31:49 UTC (rev 1783) @@ -1,15 +1,17 @@ // -*- C++ -*- Time-stamp: <07/03/07 16:38:24 ptr> +/* + * + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License version 3.0 + * + */ + #include "intercessor_test_suite.h" int main( int, char ** ) { - // dir = boost::filesystem::system_complete( boost::filesystem::path( "/tmp", boost::filesystem::native ) ); - int ret = 0; - - if ( ret = http_test_suite(0) ) { - return ret; - } - return intercessor_test_suite(0); } Modified: trunk/complement/explore/include/net/cgi.h =================================================================== --- trunk/complement/explore/include/net/cgi.h 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/include/net/cgi.h 2007-10-31 18:31:49 UTC (rev 1783) @@ -2,33 +2,16 @@ /* * - * Copyright (c) 1997-1999, 2002 + * Copyright (c) 1997-1999, 2002, 2007 * Petr Ovtchenkov * - * Licensed under the Academic Free License Version 1.0 + * Licensed under the Academic Free License version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. - * */ #ifndef __net_cgi_h #define __net_cgi_h -#ifdef __unix -# ifdef __HP_aCC -#pragma VERSIONID "@(#)$Id$" -# else -#pragma ident "@(#)$Id$" -# endif -#endif - #ifndef __config_feature_h #include <config/feature.h> #endif @@ -39,90 +22,88 @@ namespace cgi { -using namespace std; - class environment { public: explicit environment(); const char *ServerSoftware() const - { return server_software.data(); } + { return server_software.c_str(); } const char *ServerName() const - { return server_name.data(); } + { return server_name.c_str(); } const char *GatewayInterface() const - { return gateway_interface.data(); } + { return gateway_interface.c_str(); } const char *Protocol() const - { return server_protocol.data(); } + { return server_protocol.c_str(); } int Port() const { return server_port; } const char *PathInfo() const - { return path_info.data(); } + { return path_info.c_str(); } const char *PathTranslated() const - { return path_translated.data(); } + { return path_translated.c_str(); } const char *ScriptName() const - { return script_name.data(); } + { return script_name.c_str(); } const char *RequestMethod() const - { return request_method.data(); } + { return request_method.c_str(); } const char *Query() const - { return query_string.data(); } + { return query_string.c_str(); } const char *RemoteHost() const - { return remote_host.data(); } + { return remote_host.c_str(); } const char *RemoteAddr() const - { return remote_addr.data(); } + { return remote_addr.c_str(); } const char *AuthType() const - { return auth_type.data(); } + { return auth_type.c_str(); } const char *RemoteUser() const - { return remote_user.data(); } + { return remote_user.c_str(); } const char *RemoteIdent() const - { return remote_ident.data(); } + { return remote_ident.c_str(); } const char *ContentType() const - { return content_type.data(); } + { return content_type.c_str(); } size_t ContentLength() const { return content_length; } const char *HTTPUserAgent() const - { return http_user_agent.data(); } + { return http_user_agent.c_str(); } - static string hexify( const string& ); - static string unhexify( const string& ); + static std::string hexify( const std::string& ); + static std::string unhexify( const std::string& ); - const string& value( const char * ) const; + const std::string& value( const char * ) const; protected: // The following environment variables are not request-specific and // are set for all requests: - mutable string server_software; - mutable string server_name; - mutable string gateway_interface; + mutable std::string server_software; + mutable std::string server_name; + mutable std::string gateway_interface; // The following environment variables are specific to the request // being fulfilled by the gateway program: - mutable string server_protocol; + mutable std::string server_protocol; mutable int server_port; - mutable string path_info; - mutable string path_translated; - mutable string script_name; - mutable string request_method; - mutable string query_string; - mutable string remote_host; - mutable string remote_addr; - mutable string auth_type; - mutable string remote_user; - mutable string remote_ident; - mutable string content_type; + mutable std::string path_info; + mutable std::string path_translated; + mutable std::string script_name; + mutable std::string request_method; + mutable std::string query_string; + mutable std::string remote_host; + mutable std::string remote_addr; + mutable std::string auth_type; + mutable std::string remote_user; + mutable std::string remote_ident; + mutable std::string content_type; mutable size_t content_length; - mutable string http_user_agent; + mutable std::string http_user_agent; private: static const char *get( const char *name ); - static string decode( const string& ); + static std::string decode( const std::string& ); - typedef pair<string,string> value_type; - typedef list<value_type> container_type; + typedef std::pair<std::string,std::string> value_type; + typedef std::list<value_type> container_type; container_type pars; }; Copied: trunk/complement/explore/include/net/http.h (from rev 1781, trunk/complement/explore/app/intercessor/http.h) =================================================================== --- trunk/complement/explore/include/net/http.h (rev 0) +++ trunk/complement/explore/include/net/http.h 2007-10-31 18:31:49 UTC (rev 1783) @@ -0,0 +1,466 @@ +// -*- C++ -*- Time-stamp: <07/03/07 16:11:19 ptr> + +/* + * + * Copyright (c) 2006-2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License version 3.0 + * + */ + +#ifndef __net_http_h +#define __net_http_h + +#include <istream> +#include <ostream> +#include <string> +#include <sstream> +#include <functional> +#include <iterator> +#include <list> +#include <boost/lexical_cast.hpp> + +namespace http { + +class command +{ + public: + + enum cmd { + UNKNOWN, + GET, + PUT, + HEAD, + POST, + OPTIONS, + DELETE, + TRACE, + CONNECT + }; + + enum proto { + UNSPEC, + HTTP10, + HTTP11 + }; + + command() : + _cmd( UNKNOWN ), + _proto( UNSPEC ) + { } + + command( const command& c ) : + _cmd( c._cmd ), + _proto( c._proto ), + _url( c._url ) + { } + + cmd value() const + { return _cmd; } + + proto protocol() const + { return _proto; } + + const std::string& URL() const + { return _url; } + + void value( cmd c ) + { _cmd = c; } + + void protocol( proto p ) + { _proto = p; } + + void URL( const std::string& url ) + { _url = url; } + + private: + cmd _cmd; + proto _proto; + std::string _url; + + friend std::ostream& operator <<( std::ostream& s, const command& c ); + friend std::istream& operator >>( std::istream& s, command& c ); +}; + +std::ostream& operator <<( std::ostream& s, const command& c ); +std::istream& operator >>( std::istream& s, command& c ); + +class header +{ + public: + header() : + _val( std::string(), std::string() ) + { } + + header( const std::string& k, const std::string& v ) : + _val( k, v ) + { } + +#if !defined(__GNUC__) || (__GNUC__ > 3) || ((__GNUC__ == 3) && \ + ((__GNUC_MINOR__ > 4) || ((__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ > 4)) ) ) + template <class T> + header( const std::string& k, const T& v ) : + _val( k, boost::lexical_cast<std::string>(v) ) + { } + template <class T> + header( const char *k, const T& v ) : + _val( std::string(k), boost::lexical_cast<std::string>(v) ) + { } +#else + header( const std::string& k, int v ) : + _val( k, boost::lexical_cast<std::string>(v) ) + { } + header( const std::string& k, unsigned v ) : + _val( k, boost::lexical_cast<std::string>(v) ) + { } + header( const std::string& k, long v ) : + _val( k, boost::lexical_cast<std::string>(v) ) + { } + header( const std::string& k, unsigned long v ) : + _val( k, boost::lexical_cast<std::string>(v) ) + { } + header( const std::string& k, short v ) : + _val( k, boost::lexical_cast<std::string>(v) ) + { } + header( const std::string& k, unsigned short v ) : + _val( k, boost::lexical_cast<std::string>(v) ) + { } + header( const std::string& k, char v ) : + _val( k, boost::lexical_cast<std::string>(v) ) + { } + header( const std::string& k, signed char v ) : + _val( k, boost::lexical_cast<std::string>(v) ) + { } + header( const std::string& k, unsigned char v ) : + _val( k, boost::lexical_cast<std::string>(v) ) + { } + header( const std::string& k, double v ) : + _val( k, boost::lexical_cast<std::string>(v) ) + { } + header( const std::string& k, float v ) : + _val( k, boost::lexical_cast<std::string>(v) ) + { } + header( const std::string& k, const char *v ) : + _val( k, std::string(v) ) + { } + header( const char *k, const char *v ) : + _val( std::string(k), std::string(v) ) + { } +#endif + + + header( const header& h ) : + _val( h._val ) + { } + + const std::string& key() const + { return _val.first; } + + const std::string& value() const + { return _val.second; } + + void key( const std::string& k ) + { _val.first = k; } + + // template <> + void value( const std::string& v ) + { _val.second = v; } + + template <class T> + void value( const T& v ) + { _val.second = boost::lexical_cast<std::string>(v); } + + bool operator ==( const header& h ) const + { return _val.first == h._val.first; } + + bool operator ==( const std::string& s ) const + { return _val.first == s; } + + private: + std::pair<std::string,std::string> _val; + + friend std::ostream& operator <<( std::ostream& s, const header& h ); + friend std::istream& operator >>( std::istream& s, header& h ); +}; + +std::ostream& operator <<( std::ostream& s, const header& h ); +std::istream& operator >>( std::istream& s, header& h ); + +class cookie +{ + public: + + cookie() + { } + + cookie( const header& ); + + const std::string& key() const + { return _val.first; } + + const std::string& value() const + { return _val.second; } + + void key( const std::string& k ) + { _val.first = k; } + + // template <> + void value( const std::string& v ) + { _val.second = v; } + + private: + std::pair<std::string,std::string> _val; + std::string _domain; + std::string _path; + std::string _expires; +}; + +class base_response +{ + public: + base_response() : + _code( 0 ), + _proto( command::UNSPEC ) + { } + + base_response( int c, command::proto p = command::HTTP11 ) : + _code( c ), + _proto( p ) + { } + + base_response( const base_response& r ) : + _code( r._code ), + _proto( r._proto ) + { } + + int code() const + { return _code; } + + command::proto protocol() const + { return _proto; } + + void code( int c ) + { _code = c; } + + void protocol( command::proto p ) + { _proto = p; } + + private: + int _code; + command::proto _proto; + + friend std::ostream& operator <<( std::ostream& s, const base_response& r ); + friend std::istream& operator >>( std::istream& s, base_response& r ); +}; + +std::ostream& operator <<( std::ostream& s, const base_response& r ); +std::istream& operator >>( std::istream& s, base_response& r ); + +template <class R> class message_start; +template <class R> typename std::ostream& operator <<( typename std::ostream& s, const message_start<R>& r ); +template <class R> typename std::istream& operator >>( typename std::istream& s, message_start<R>& r ); + + + +struct __imsg_proxy +{ + __imsg_proxy( bool v ) : + _v( v ) + { } + + bool _v; +}; + +inline __imsg_proxy body( bool v ) +{ return __imsg_proxy( v ); } + +struct __imsg_proxy_istream +{ + __imsg_proxy_istream( std::istream& s, const __imsg_proxy& p ) : + _s( s ), + _v( p._v ) + { } + + std::istream& _s; + bool _v; +}; + +struct __imsg_proxy_ostream +{ + __imsg_proxy_ostream( std::ostream& s, const __imsg_proxy& p ) : + _s( s ), + _v( p._v ) + { } + + std::ostream& _s; + bool _v; +}; + +inline __imsg_proxy_istream operator >>( std::istream& s, const __imsg_proxy& p ) +{ return __imsg_proxy_istream( s, p ); } + +inline __imsg_proxy_ostream operator <<( std::ostream& s, const __imsg_proxy& p ) +{ return __imsg_proxy_ostream( s, p ); } + +template <class R> +class message_start +{ + public: + typedef std::list<header> headers_container_type; + + message_start() : + _bodyf( false ) + { } + + message_start( const message_start& r ): + _m( r._m ), + _body( r._body ), + _bodyf( r._bodyf ) + { + std::copy( r._headers.begin(), r._headers.end(), std::back_insert_iterator<headers_container_type>(_headers) ); + } + + R& head() + { return _m; } + + headers_container_type& headers() + { return _headers; } + + const R& head() const + { return _m; } + + const headers_container_type& headers() const + { return _headers; } + + typename headers_container_type::iterator search( const typename std::string& s ) + { return std::find( _headers.begin(), _headers.end(), s ); } + + typename headers_container_type::const_iterator search( const typename std::string& s ) const + { return std::find( _headers.begin(), _headers.end(), s ); } + + std::string& body() + { return _body; } + + const std::string& body() const + { return _body; } + + void bodyf( bool rb ) const + { _bodyf = rb; } + + private: + R _m; + headers_container_type _headers; + std::string _body; + mutable bool _bodyf; + + friend typename std::ostream& operator << <R>( typename std::ostream& s, const message_start<R>& r ); + friend typename std::istream& operator >> <R>( typename std::istream& s, message_start<R>& r ); +}; + +template <class R> +typename std::ostream& operator <<( typename std::ostream& s, const message_start<R>& r ) +{ + if ( !s.good() ) { + return s; + } + s << r._m; + for ( typename message_start<R>::headers_container_type::const_iterator i = r.headers().begin(); i != r.headers().end(); ++i ) { + s << *i; + } + if ( r._bodyf && r.body().length() > 0 && r.search( "Content-Length" ) == r.headers().end() ) { + s << typename http::header( "Content-Length", r.body().length() ); + } + s << "\r\n"; + if ( r._bodyf && r.body().length() > 0 ) { + s << r._body; + } + return s; +} + +template <class R> +typename std::istream& operator >>( typename std::istream& s, message_start<R>& r ) +{ + s >> r._m; + + std::string line; + http::header h; + + while ( !getline( s, line ).fail() && line.length() > 0 && line != "\r" ) { + // line += '\n'; + std::stringstream str( line ); + str >> h; + r._headers.push_back( h ); + } + + if ( r._bodyf ) { + // check Content-Length header (hmm, I can't process something else) + typename message_start<R>::headers_container_type::iterator cl = r.search( "Content-Length" ); + + if ( cl != r.headers().end() ) { + int len = boost::lexical_cast<int>( cl->value() ); + + if ( len > 0 ) { + // and write all body to another file + r._body.reserve( len ); + std::istreambuf_iterator<char> istr( s.rdbuf() ); + while ( len-- > 0 && s.good() ) { + r._body += *istr; + if ( len > 0 ) { + ++istr; + } + } + } + } else { + cl = r.search( "Transfer-Encoding" ); + if ( cl != r.headers().end() && cl->value() == "chunked" ) { + int chunk_size = -1; + int count = 0; + bool skws = (s.flags() & std::ios_base::skipws) != 0; + s >> std::noskipws >> std::hex >> chunk_size >> std::dec; + std::istreambuf_iterator<char> istr( s.rdbuf() ); + ++istr; ++istr; // oh, check CR/LF + count += chunk_size; + while ( chunk_size > 0 && s.good() ) { + r._body.reserve( chunk_size + r._body.length() ); + while ( chunk_size-- > 0 && s.good() ) { + r._body += *istr++; + } + ++istr; ++istr; + s >> std::hex >> chunk_size >> std::dec; + ++istr; ++istr; // oh, check CR/LF + } + r._headers.erase( cl ); + r._headers.push_back( header( "Content-Length", boost::lexical_cast<std::string>(r._body.length()) ) ); + if ( skws ) { + s.setf( std::ios_base::skipws ); + } + } else { // server not HTTP 1.1-compliant (RFC2616, 4.4) + copy( std::istreambuf_iterator<char>(s.rdbuf()), std::istreambuf_iterator<char>(), back_inserter(r._body) ); + } + } + } + + return s; +} + +template <class R> +inline std::istream& operator >>( const __imsg_proxy_istream& _sp, message_start<R>& r ) +{ + r.bodyf( _sp._v ); + return _sp._s >> r; +} + +template <class R> +inline std::ostream& operator <<( const __imsg_proxy_ostream& _sp, const message_start<R>& r ) +{ + r.bodyf( _sp._v ); + return _sp._s << r; +} + +typedef message_start<command> request; +typedef message_start<base_response> response; + +} // namespace http + +#endif // __net_http_h Modified: trunk/complement/explore/lib/net/Makefile =================================================================== --- trunk/complement/explore/lib/net/Makefile 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/lib/net/Makefile 2007-10-31 18:31:49 UTC (rev 1783) @@ -1,39 +1,37 @@ -# -*- Makefile -*- Time-stamp: <02/09/29 19:26:18 ptr> -# $Id$ +# -*- Makefile -*- Time-stamp: <07/08/03 23:56:04 ptr> -BASEDIR := $(shell xtmp=`pwd`; xtmp=`dirname $$xtmp`; dirname $$xtmp) -LIBDIR := $(shell xtmp=`pwd`; dirname $$xtmp) +SRCROOT := ../.. -COMPILER_NAME = gcc -include $(BASEDIR)/lib/net/Makefile.inc +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak -all: all-release all-debug +INCLUDES += -I$(SRCROOT)/include +HEADERS_BASE = $(SRCROOT)/include/net $(SRCROOT)/include/config $(SRCROOT)/include/misc -install: install-dbg-shared install-stldbg-shared install-release-shared +# LDLIBS += -ldl -lbfd +# LDLIBS += -ldl -all-shared: release-shared dbg-shared stldbg-shared +check: all-shared + $(MAKE) -C ut all-shared + (cd ut; ${OUTPUT_DIR}/net_ut) || exit 1 + (cd ut; ${OUTPUT_DIR_DBG}/net_ut) || exit 1 +ifndef WITHOUT_STLPORT + (cd ut; ${OUTPUT_DIR_STLDBG}/net_ut) || exit 1 +endif -all-debug: dbg-shared stldbg-shared +check-release-shared: release-shared + $(MAKE) -C ut release-shared + (cd ut; ${OUTPUT_DIR}/net_ut) || exit 1 -all-release: release-shared +check-dbg-shared: dbg-shared + $(MAKE) -C ut dbg-shared + (cd ut; ${OUTPUT_DIR_DBG}/net_ut) || exit 1 -include ${BASEDIR}/Makefiles/lib/Makefile.inc - -INCLUDES += -I$(STLPORT_INCLUDE_DIR) - -ifeq ($(OS_VER),Linux) -release-shared: LDSEARCH = -L${STLPORT_LIB_DIR} -stldbg-shared: LDSEARCH = -L${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH = -L${STLPORT_LIB_DIR} +ifndef WITHOUT_STLPORT +check-stldbg-shared: stldbg-shared + $(MAKE) -C ut stldbg-shared + (cd ut; ${OUTPUT_DIR_STLDBG}/net_ut) || exit 1 endif -ifeq ($(OS_VER),SunOS) -release-shared : LDLIBS = -lstlport_gcc -stldbg-shared : LDLIBS = -lstlport_gcc_stldebug -dbg-shared : LDLIBS = -lstlport_gcc -else -release-shared : LDLIBS = -lstlport_gcc -stldbg-shared : LDLIBS = -lstlport_gcc_stldebug -dbg-shared : LDLIBS = -lstlport_gcc -endif - +depend clean distclean mostlyclean maintainer-clean:: + ${MAKE} -C ut $@ Modified: trunk/complement/explore/lib/net/Makefile.inc =================================================================== --- trunk/complement/explore/lib/net/Makefile.inc 2007-10-31 17:42:44 UTC (rev 1782) +++ trunk/complement/explore/lib/net/Makefile.inc 2007-10-31 18:31:49 UTC (rev 1783) @@ -1,8 +1,7 @@ # -*- Makefile -*- Time-stamp: <02/09/29 19:20:27 ptr> -# $Id$ LIBNAME = Net -MAJOR = .0 -MINOR = .1 -PATCH = .0 -SRC_CC = cgi.cc +MAJOR = 0 +MINOR = 2 +PATCH = 0 +SRC_CC = cgi.cc http.cc Modified: trunk/complement/explore/lib/net/cgi.cc ===============================... [truncated message content] |