From 27830cb3f422316e5cda992a8ff5e51a9bea1990 Mon Sep 17 00:00:00 2001 From: myun2 Date: Mon, 9 Jul 2012 09:25:23 +0900 Subject: [PATCH] net/http delete --- roast/include/roast/net/http.hpp | 10 - roast/include/roast/net/http/http.hpp | 219 --------------------- roast/include/roast/net/http/http_core.hpp | 215 -------------------- roast/include/roast/net/http/http_header_names.hpp | 170 ---------------- roast/include/roast/net/http/http_rule.hpp | 31 --- 5 files changed, 645 deletions(-) delete mode 100644 roast/include/roast/net/http.hpp delete mode 100644 roast/include/roast/net/http/http.hpp delete mode 100644 roast/include/roast/net/http/http_core.hpp delete mode 100644 roast/include/roast/net/http/http_header_names.hpp delete mode 100644 roast/include/roast/net/http/http_rule.hpp diff --git a/roast/include/roast/net/http.hpp b/roast/include/roast/net/http.hpp deleted file mode 100644 index a746b1b6..00000000 --- a/roast/include/roast/net/http.hpp +++ /dev/null @@ -1,10 +0,0 @@ -// Roast+ License - -/* -*/ -#ifndef __SFJP_ROAST__net__http_HPP__ -#define __SFJP_ROAST__net__http_HPP__ - -#include "roast/net/http/http.hpp" - -#endif//__SFJP_ROAST__net__http_HPP__ diff --git a/roast/include/roast/net/http/http.hpp b/roast/include/roast/net/http/http.hpp deleted file mode 100644 index 611dfe5f..00000000 --- a/roast/include/roast/net/http/http.hpp +++ /dev/null @@ -1,219 +0,0 @@ -// Roast+ License - -/* -*/ -#ifndef __SFJP_ROAST__net__http__http_HPP__ -#define __SFJP_ROAST__net__http__http_HPP__ - -#include "roast/net/base64.hpp" -#include -#include -#include - -#define ROAST_HTTP_VER_0_9 "0.9" -#define ROAST_HTTP_VER_1_0 "1.0" -#define ROAST_HTTP_VER_1_1 "1.1" - -#define _ROAST_HTTP_REQUEST_DEFAULT_VERSION ROAST_HTTP_VER_1_0 - -namespace roast -{ - class http - { - public: - //typedef ::std::map< ::std::string, ::std::string > _request_header_t, _request_header, request_header; - typedef class request_header : public ::std::map< ::std::string, ::std::string > - { - public: - void set_authorization(const char* auth_str) { operator []("Authorization") = auth_str; } - - void set_authorization_by_basic(const char* user, const char* pass) - { - ::std::string plain_user_pass = user; - plain_user_pass += ':'; - plain_user_pass += pass; - base64_enc be(plain_user_pass.c_str()); - //printf("%s\n", be.c_str()); - - set_authorization( (::std::string("Basic ") + be.c_str()).c_str() ); - } - } - _request_header_t, _request_header; - - ////////////////////////////////////////////////////////////////////////////////////////////////////// - - typedef ::std::map< ::std::string, ::std::string > _response_header_t, _response_header, response_header; - - class response - { - private: - int m_now_flg; - public: - const char* version; - int status_code; - _response_header headers; - ::std::string body; - - public: - response(){ - m_now_flg = 0; - } - - bool operator << (_TelnetT &tn) - { - ::std::string s; - tn _ROAST_STREAM_OROP s; - - // 0: Status Line - if ( m_now_flg == 0 ) - { - const char* p_s = s.c_str(); - version = p_s + 5; - status_code = atoi(p_s + 8); - - m_now_flg = 1; - } - - // 1: Header Lines - else if ( m_now_flg == 1 ) - { - /*if ( s.size() <= 2 ) - m_now_flg = 2; - else - {*/ - size_t n_colon = s.find(':'); - if ( n_colon == ::std::string::npos ) - m_now_flg = 2; - else - { - ::std::string s_header_name = s.substr(0, n_colon); - headers[ s_header_name ] = s.c_str() + n_colon + 1; - } - //} - } - // 2: Body - else - { - body += s; - } - - // Debug Print - //fputs(s.c_str(), stdout); - - //m_n_line++; - return !tn.is_eos(); - } - }; - - private: - const char* m_httpver; - const char* _CRLF; - - void _init() - { - _CRLF = "\r\n"; - m_httpver = _ROAST_HTTP_REQUEST_DEFAULT_VERSION; - } - stream::tie_ostream _req_ost(){ - return rstie(*this,stream::cout); } - - protected: - url m_url; - public: - http_() : m_url(""){ _init(); } - http_(const http_& from) : - m_url(from.m_url) - { - _init(); - connect(m_url.get_host(), m_url.get_portno()); - } - http_(const char* url_in) : - m_url(url_in) - { - _init(); - connect(m_url.get_host(), m_url.get_portno()); - } - http_(const char* url_in, int port_no) : - m_url(url_in) - { - _init(); - connect(m_url.get_host(), port_no); - } - - ::std::string make_request_line(const char* method, const char* path=NULL) - { - if ( path == NULL ) - path = m_url.get_path(); - ::std::string s = method; - s += ' '; - s += path; - s += " HTTP/"; - s += m_httpver; - s += _CRLF; - return s; - } - void request(const char* method, const char* path=NULL, _request_header *p_req_header=NULL) - { - *this << make_request_line(method, path); - if ( p_req_header ) - { - _request_header::iterator it = p_req_header->begin(); - for(; it != p_req_header->end(); it++){ - *this << it->first << ": " << it->second << _CRLF; - - // Debug Print - //::roast::stream::cout << it->first << ": " << it->second << _CRLF; - } - } - *this << _CRLF; - } - http_& operator << ( const ::std::string &s ) - { - //printf("[Send] %s\n", s.c_str() ); - //fputs(s.c_str(), stdout ); - _Base::operator << (s.c_str()); - return *this; - } - - response get_response() - { - response rs; - while( rs << *this ); - return rs; - } - response get(const char* path=NULL, _request_header *p_req_header=NULL) - { - ////////////////////////////////////////////////////////////////////// - // Path is considered to be URL if called by the default constructor. - if ( *(m_url.get_host()) == '\0' ){ - m_url = url(path); - connect(m_url.get_host(), m_url.get_portno()); - path = NULL;//m_url.get_path(); - } - ////////////////////////////////////////////////////////////////////// - - request("GET", path, p_req_header); - return get_response(); - } - response post(const char* path=NULL, _request_header *p_req_header=NULL) - { - ////////////////////////////////////////////////////////////////////// - // Path is considered to be URL if called by the default constructor. - if ( *(m_url.get_host()) == '\0' ){ - m_url = url(path); - connect(m_url.get_host(), m_url.get_portno()); - path = NULL;//m_url.get_path(); - } - ////////////////////////////////////////////////////////////////////// - - request("POST", path, p_req_header); - return get_response(); - } - - void set_httpver(const char* httpver_str){ m_httpver = httpver_str; } - }; - - typedef http_<> http; -} - -#endif//__SFJP_ROAST__net__http__http_HPP__ diff --git a/roast/include/roast/net/http/http_core.hpp b/roast/include/roast/net/http/http_core.hpp deleted file mode 100644 index e689c5af..00000000 --- a/roast/include/roast/net/http/http_core.hpp +++ /dev/null @@ -1,215 +0,0 @@ -// Roast+ License - -/* -*/ -#ifndef __SFJP_ROAST__net__http_core_HPP__ -#define __SFJP_ROAST__net__http_core_HPP__ - -#include "roast/net/telnet.hpp" -#include "roast/stream/stream.hpp" // for Debug Print -#include -#include -#include - -#define ROAST_HTTP_VER_0_9 "0.9" -#define ROAST_HTTP_VER_1_0 "1.0" -#define ROAST_HTTP_VER_1_1 "1.1" -#define _ROAST_HTTP_CRLF "\r\n" - -namespace roast -{ - typedef ::std::map<::std::string, ::std::string> http_request_header; - typedef ::std::map<::std::string, ::std::string> http_response_header; - - /////////////////// - - template - class http_core_ : public _TelnetT - { - public: - typedef ::roast::http_request_header request_header; - typedef ::roast::http_response_header response_header; - - enum httpver - { - v09=9, - v10, - v11 - }; -//#define _ROAST_HTTP_DEFAULT_HTTP_VERSION v11 -//#define _ROAST_HTTP_DEFAULT_HTTP_VERSION_STR ROAST_HTTP_VER_1_1 -#define _ROAST_HTTP_DEFAULT_HTTP_VERSION v10 -#define _ROAST_HTTP_DEFAULT_HTTP_VERSION_STR ROAST_HTTP_VER_1_0 - - class response - { - private: - int m_now_flg; - public: - const char* version; - int status_code; - response_header headers; - ::std::string body; - - public: - response(){ - m_now_flg = 0; - } - - bool operator << (_TelnetT &tn) - { - ::std::string s; - tn _ROAST_STREAM_OROP s; - - // 0: Status Line - if ( m_now_flg == 0 ) - { - const char* p_s = s.c_str(); - version = p_s + 5; - status_code = atoi(p_s + 8); - - m_now_flg = 1; - } - - // 1: Header Lines - else if ( m_now_flg == 1 ) - { - /*if ( s.size() <= 2 ) - m_now_flg = 2; - else - {*/ - size_t n_colon = s.find(':'); - if ( n_colon == ::std::string::npos ) - m_now_flg = 2; - else - { - ::std::string s_header_name = s.substr(0, n_colon); - headers[ s_header_name ] = s.c_str() + n_colon + 1; - } - //} - } - // 2: Body - else - { - body += s; - } - - // Debug Print - //fputs(s.c_str(), stdout); - - //m_n_line++; - return !tn.is_eos(); - } - }; - - private: - typedef _TelnetT _Base; - - const ::std::string m_host; - const int m_port; - const char* m_httpver_str; - httpver m_httpver; - - stream::tie_ostream _req_ost(){ - return rstie(*this,stream::cout); } - - ::std::string make_request_line(const char* method, const char* path) - { - ::std::string s = method; - s += ' '; - s += path; - s += " HTTP/"; - s += m_httpver_str; - s += _ROAST_HTTP_CRLF; - return s; - } - - public: - http_core_(const char* host, int port_no=80, httpver http_version=_ROAST_HTTP_DEFAULT_HTTP_VERSION) : - m_host(host), m_port(port_no), m_httpver(http_version) - { - m_httpver_str = _ROAST_HTTP_DEFAULT_HTTP_VERSION_STR; - - switch(m_httpver) - { - case v09: - m_httpver_str = ROAST_HTTP_VER_0_9; - break; - case v10: - m_httpver_str = ROAST_HTTP_VER_1_0; - break; - case v11: - m_httpver_str = ROAST_HTTP_VER_1_1; - break; - } - } - virtual ~http_core_() - { - end(); - } - - bool start() - { - if ( is_connected() ) - return true; - return connect(m_host.c_str(), m_port); - } - bool end(){ return close(); } - - ///////////////////////////////////////////////// - - bool request(const char* method, const char* path, const request_header &req_header=request_header()) - { - if ( !start() ) - return false; - - // Request Line - *this << make_request_line(method, path); - - // Request Header - request_header::const_iterator it = req_header.begin(); - for(; it != req_header.end(); it++) - { - *this << it->first << ": " << it->second << _ROAST_HTTP_CRLF; - - // Debug Print - //::roast::stream::cout << it->first << ": " << it->second << _ROAST_HTTP_CRLF; - } - - // Request End - *this << _ROAST_HTTP_CRLF; - - //if ( !end() ) - // return false; - return false; - } - http_core_& operator << ( const ::std::string &s ) - { - //printf("[Send] %s\n", s.c_str() ); - //fputs(s.c_str(), stdout ); - _Base::operator << (s.c_str()); - return *this; - } - - response get_response() - { - response rs; - while( rs << *this ); - return rs; - } - response get(const char* path="/", const request_header &req_header=request_header()) - { - request("GET", path, req_header); - return get_response(); - } - response post(const char* path, const request_header &req_header=request_header()) - { - request("POST", path, req_header); - return get_response(); - } - }; - - typedef http_core_<> http_core; -} - -#endif//__SFJP_ROAST__net__http_core_HPP__ diff --git a/roast/include/roast/net/http/http_header_names.hpp b/roast/include/roast/net/http/http_header_names.hpp deleted file mode 100644 index df8c2c19..00000000 --- a/roast/include/roast/net/http/http_header_names.hpp +++ /dev/null @@ -1,170 +0,0 @@ -// Roast+ License - -/* -*/ -#ifndef __SFJP_ROAST__net__http_header_names_HPP__ -#define __SFJP_ROAST__net__http_header_names_HPP__ - -namespace roast -{ - template - struct http_header_names_ - { - // General Headers - static const char* cache_control ; - static const char* connection ; - static const char* date ; - static const char* pragma ; - static const char* trailer ; - static const char* transfer_encoding ; - static const char* upgrade ; - static const char* via ; - static const char* warning ; - - // Request Headers - static const char* accept ; - static const char* accept_charset ; - static const char* accept_encoding ; - static const char* accept_language ; - static const char* authorization ; - static const char* expect ; - static const char* from ; - static const char* host ; - static const char* if_match ; - static const char* if_modified_since ; - static const char* if_none_match ; - static const char* if_range ; - static const char* if_unmodified_since ; - static const char* max_forwards ; - static const char* proxy_authorization ; - static const char* range ; - static const char* referer ; - static const char* te ; - static const char* user_agent ; - - // Response Headers - static const char* accept_ranges ; - static const char* age ; - static const char* etag ; - static const char* location ; - static const char* proxy_authenticate ; - static const char* retry_after ; - static const char* server ; - static const char* vary ; - static const char* www_authenticate ; - - // Entity Headers - static const char* allow ; - static const char* content_encoding ; - static const char* content_language ; - static const char* content_length ; - static const char* content_location ; - static const char* content_md5 ; - static const char* content_range ; - static const char* content_type ; - static const char* expires ; - static const char* last_modified ; - - /* - static const char* accept ; - static const char* accept_charset ; - static const char* accept_encoding ; - static const char* accept_language ; - static const char* accept_ranges ; - static const char* age ; - static const char* allow ; - static const char* authorization ; - static const char* cache_control ; - static const char* connection ; - static const char* content_encoding ; - static const char* content_language ; - static const char* content_length ; - static const char* content_location ; - static const char* content_md5 ; - static const char* content_range ; - static const char* content_type ; - static const char* date ; - static const char* etag ; - static const char* expect ; - static const char* expires ; - static const char* from ; - static const char* host ; - static const char* if_match ; - static const char* if_modified_since ; - static const char* if_none_match ; - static const char* if_range ; - static const char* if_unmodified_since ; - static const char* last_modified ; - static const char* location ; - static const char* max_forwards ; - static const char* pragma ; - static const char* proxy_authenticate ; - static const char* proxy_authorization ; - static const char* range ; - static const char* referer ; - static const char* retry_after ; - static const char* server ; - static const char* te ; - static const char* trailer ; - static const char* transfer_encoding ; - static const char* upgrade ; - static const char* user_agent ; - static const char* vary ; - static const char* via ; - static const char* warning ; - static const char* www_authenticate ; - */ - }; - - template const char* http_header_names_<_Dummy>:: accept ="Accept"; - template const char* http_header_names_<_Dummy>:: accept_charset ="Accept-Charset"; - template const char* http_header_names_<_Dummy>:: accept_encoding ="Accept-Encoding"; - template const char* http_header_names_<_Dummy>:: accept_language ="Accept-Language"; - template const char* http_header_names_<_Dummy>:: accept_ranges ="Accept-Ranges"; - template const char* http_header_names_<_Dummy>:: age ="Age"; - template const char* http_header_names_<_Dummy>:: allow ="Allow"; - template const char* http_header_names_<_Dummy>:: authorization ="Authorization"; - template const char* http_header_names_<_Dummy>:: cache_control ="Cache-Control"; - template const char* http_header_names_<_Dummy>:: connection ="Connection"; - template const char* http_header_names_<_Dummy>:: content_encoding ="Content-Encoding"; - template const char* http_header_names_<_Dummy>:: content_language ="Content-Language"; - template const char* http_header_names_<_Dummy>:: content_length ="Content-Length"; - template const char* http_header_names_<_Dummy>:: content_location ="Content-Location"; - template const char* http_header_names_<_Dummy>:: content_md5 ="Content-MD5"; - template const char* http_header_names_<_Dummy>:: content_range ="Content-Range"; - template const char* http_header_names_<_Dummy>:: content_type ="Content-Type"; - template const char* http_header_names_<_Dummy>:: date ="Date"; - template const char* http_header_names_<_Dummy>:: etag ="ETag"; - template const char* http_header_names_<_Dummy>:: expect ="Expect"; - template const char* http_header_names_<_Dummy>:: expires ="Expires"; - template const char* http_header_names_<_Dummy>:: from ="From"; - template const char* http_header_names_<_Dummy>:: host ="Host"; - template const char* http_header_names_<_Dummy>:: if_match ="If-Match"; - template const char* http_header_names_<_Dummy>:: if_modified_since ="If-Modified-Since"; - template const char* http_header_names_<_Dummy>:: if_none_match ="If-None-Match"; - template const char* http_header_names_<_Dummy>:: if_range ="If-Range"; - template const char* http_header_names_<_Dummy>:: if_unmodified_since ="If-Unmodified-Since"; - template const char* http_header_names_<_Dummy>:: last_modified ="Last-Modified"; - template const char* http_header_names_<_Dummy>:: location ="Location"; - template const char* http_header_names_<_Dummy>:: max_forwards ="Max-Forwards"; - template const char* http_header_names_<_Dummy>:: pragma ="Pragma"; - template const char* http_header_names_<_Dummy>:: proxy_authenticate ="Proxy-Authenticate"; - template const char* http_header_names_<_Dummy>:: proxy_authorization ="Proxy-Authorization"; - template const char* http_header_names_<_Dummy>:: range ="Range"; - template const char* http_header_names_<_Dummy>:: referer ="Referer"; - template const char* http_header_names_<_Dummy>:: retry_after ="Retry-After"; - template const char* http_header_names_<_Dummy>:: server ="Server"; - template const char* http_header_names_<_Dummy>:: te ="TE"; - template const char* http_header_names_<_Dummy>:: trailer ="Trailer"; - template const char* http_header_names_<_Dummy>:: transfer_encoding ="Transfer-Encoding"; - template const char* http_header_names_<_Dummy>:: upgrade ="Upgrade"; - template const char* http_header_names_<_Dummy>:: user_agent ="User-Agent"; - template const char* http_header_names_<_Dummy>:: vary ="Vary"; - template const char* http_header_names_<_Dummy>:: via ="Via"; - template const char* http_header_names_<_Dummy>:: warning ="Warning"; - template const char* http_header_names_<_Dummy>:: www_authenticate ="WWW-Authenticate"; - - typedef http_header_names_<0> http_header_names; -} - -#endif//__SFJP_ROAST__net__http_header_names_HPP__ diff --git a/roast/include/roast/net/http/http_rule.hpp b/roast/include/roast/net/http/http_rule.hpp deleted file mode 100644 index 2be660a5..00000000 --- a/roast/include/roast/net/http/http_rule.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Roast+ License - -/* -*/ -#ifndef __SFJP_ROAST__net__http__http_rule_HPP__ -#define __SFJP_ROAST__net__http__http_rule_HPP__ - -#include "roast/lexical.hpp" - -namespace roast -{ - namespace net - { - namespace http - { - template - struct request : public ::roast::lexical::seq< - _Header, - ::lexical::chars::cr, ::lexical::chars::lf, - _Body> {}; - - template - struct response : public ::roast::lexical::seq< - _Header, - ::lexical::chars::cr, ::lexical::chars::lf, - _Body> {}; - } - } -} - -#endif//__SFJP_ROAST__net__http__http_rule_HPP__ -- 2.11.0