From b35646e8adbb760611eefd8c2cd738c3d20c5eda Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 18 Oct 2012 13:40:15 -0700 Subject: [PATCH] Delete dead code. --- src/HttpReply.cpp | 241 ------------------------------ src/HttpReply.h | 50 ------- src/HttpRequest.h | 24 --- src/RequestParser.cpp | 330 ------------------------------------------ src/RequestParser.h | 72 --------- 5 files changed, 717 deletions(-) delete mode 100644 src/HttpReply.cpp delete mode 100644 src/HttpReply.h delete mode 100644 src/HttpRequest.h delete mode 100644 src/RequestParser.cpp delete mode 100644 src/RequestParser.h diff --git a/src/HttpReply.cpp b/src/HttpReply.cpp deleted file mode 100644 index 4dbb9182db..0000000000 --- a/src/HttpReply.cpp +++ /dev/null @@ -1,241 +0,0 @@ -#include "HttpReply.h" -#include -#include -#include - - -namespace status_strings -{ - const std::string ok = - "HTTP/1.0 200 OK\r\n"; - const std::string created = - "HTTP/1.0 201 Created\r\n"; - const std::string accepted = - "HTTP/1.0 202 Accepted\r\n"; - const std::string no_content = - "HTTP/1.0 204 No Content\r\n"; - const std::string multiple_choices = - "HTTP/1.0 300 Multiple Choices\r\n"; - const std::string moved_permanently = - "HTTP/1.0 301 Moved Permanently\r\n"; - const std::string moved_temporarily = - "HTTP/1.0 302 Moved Temporarily\r\n"; - const std::string not_modified = - "HTTP/1.0 304 Not Modified\r\n"; - const std::string bad_request = - "HTTP/1.0 400 Bad Request\r\n"; - const std::string unauthorized = - "HTTP/1.0 401 Unauthorized\r\n"; - const std::string forbidden = - "HTTP/1.0 403 Forbidden\r\n"; - const std::string not_found = - "HTTP/1.0 404 Not Found\r\n"; - const std::string internal_server_error = - "HTTP/1.0 500 Internal Server Error\r\n"; - const std::string not_implemented = - "HTTP/1.0 501 Not Implemented\r\n"; - const std::string bad_gateway = - "HTTP/1.0 502 Bad Gateway\r\n"; - const std::string service_unavailable = - "HTTP/1.0 503 Service Unavailable\r\n"; - - boost::asio::const_buffer to_buffer(HttpReply::status_type status) - { - switch (status) - { - case HttpReply::ok: - return boost::asio::buffer(ok); - case HttpReply::created: - return boost::asio::buffer(created); - case HttpReply::accepted: - return boost::asio::buffer(accepted); - case HttpReply::no_content: - return boost::asio::buffer(no_content); - case HttpReply::multiple_choices: - return boost::asio::buffer(multiple_choices); - case HttpReply::moved_permanently: - return boost::asio::buffer(moved_permanently); - case HttpReply::moved_temporarily: - return boost::asio::buffer(moved_temporarily); - case HttpReply::not_modified: - return boost::asio::buffer(not_modified); - case HttpReply::bad_request: - return boost::asio::buffer(bad_request); - case HttpReply::unauthorized: - return boost::asio::buffer(unauthorized); - case HttpReply::forbidden: - return boost::asio::buffer(forbidden); - case HttpReply::not_found: - return boost::asio::buffer(not_found); - case HttpReply::internal_server_error: - return boost::asio::buffer(internal_server_error); - case HttpReply::not_implemented: - return boost::asio::buffer(not_implemented); - case HttpReply::bad_gateway: - return boost::asio::buffer(bad_gateway); - case HttpReply::service_unavailable: - return boost::asio::buffer(service_unavailable); - default: - return boost::asio::buffer(internal_server_error); - } - } - -} // namespace status_strings - -namespace misc_strings -{ - const char name_value_separator[] = { ':', ' ' }; - const char crlf[] = { '\r', '\n' }; -} // namespace misc_strings - -std::vector HttpReply::to_buffers() -{ - std::vector buffers; - buffers.push_back(status_strings::to_buffer(status)); - for (std::size_t i = 0; i < headers.size(); ++i) - { - HttpHeader& h = headers[i]; - buffers.push_back(boost::asio::buffer(h.name)); - buffers.push_back(boost::asio::buffer(misc_strings::name_value_separator)); - buffers.push_back(boost::asio::buffer(h.value)); - buffers.push_back(boost::asio::buffer(misc_strings::crlf)); - } - buffers.push_back(boost::asio::buffer(misc_strings::crlf)); - buffers.push_back(boost::asio::buffer(content)); - return buffers; -} - -namespace stock_replies { - -const char ok[] = ""; -const char created[] = - "" - "Created" - "

201 Created

" - ""; -const char accepted[] = - "" - "Accepted" - "

202 Accepted

" - ""; -const char no_content[] = - "" - "No Content" - "

204 Content

" - ""; -const char multiple_choices[] = - "" - "Multiple Choices" - "

300 Multiple Choices

" - ""; -const char moved_permanently[] = - "" - "Moved Permanently" - "

301 Moved Permanently

" - ""; -const char moved_temporarily[] = - "" - "Moved Temporarily" - "

302 Moved Temporarily

" - ""; -const char not_modified[] = - "" - "Not Modified" - "

304 Not Modified

" - ""; -const char bad_request[] = - "" - "Bad Request" - "

400 Bad Request

" - ""; -const char unauthorized[] = - "" - "Unauthorized" - "

401 Unauthorized

" - ""; -const char forbidden[] = - "" - "Forbidden" - "

403 Forbidden

" - ""; -const char not_found[] = - "" - "Not Found" - "

404 Not Found

" - ""; -const char internal_server_error[] = - "" - "Internal Server Error" - "

500 Internal Server Error

" - ""; -const char not_implemented[] = - "" - "Not Implemented" - "

501 Not Implemented

" - ""; -const char bad_gateway[] = - "" - "Bad Gateway" - "

502 Bad Gateway

" - ""; -const char service_unavailable[] = - "" - "Service Unavailable" - "

503 Service Unavailable

" - ""; - -std::string to_string(HttpReply::status_type status) -{ - switch (status) - { - case HttpReply::ok: - return ok; - case HttpReply::created: - return created; - case HttpReply::accepted: - return accepted; - case HttpReply::no_content: - return no_content; - case HttpReply::multiple_choices: - return multiple_choices; - case HttpReply::moved_permanently: - return moved_permanently; - case HttpReply::moved_temporarily: - return moved_temporarily; - case HttpReply::not_modified: - return not_modified; - case HttpReply::bad_request: - return bad_request; - case HttpReply::unauthorized: - return unauthorized; - case HttpReply::forbidden: - return forbidden; - case HttpReply::not_found: - return not_found; - case HttpReply::internal_server_error: - return internal_server_error; - case HttpReply::not_implemented: - return not_implemented; - case HttpReply::bad_gateway: - return bad_gateway; - case HttpReply::service_unavailable: - return service_unavailable; - default: - return internal_server_error; - } -} - -} // namespace stock_replies - -HttpReply HttpReply::stock_reply(HttpReply::status_type status) -{ - HttpReply rep; - rep.status = status; - rep.content = stock_replies::to_string(status); - rep.headers.resize(2); - rep.headers[0].name = "Content-Length"; - rep.headers[0].value = boost::lexical_cast(rep.content.size()); - rep.headers[1].name = "Content-Type"; - rep.headers[1].value = "text/html"; - return rep; -} diff --git a/src/HttpReply.h b/src/HttpReply.h deleted file mode 100644 index d802327392..0000000000 --- a/src/HttpReply.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef HTTP_REPLY_HPP -#define HTTP_REPLY_HPP - -#include -#include -#include -#include "HttpRequest.h" - -/// A reply to be sent to a client. -class HttpReply -{ -public: - /// The status of the reply. - enum status_type - { - ok = 200, - created = 201, - accepted = 202, - no_content = 204, - multiple_choices = 300, - moved_permanently = 301, - moved_temporarily = 302, - not_modified = 304, - bad_request = 400, - unauthorized = 401, - forbidden = 403, - not_found = 404, - internal_server_error = 500, - not_implemented = 501, - bad_gateway = 502, - service_unavailable = 503 - } status; - - /// The headers to be included in the reply. - std::vector headers; - - /// The content to be sent in the reply. - std::string content; - - /// Convert the reply into a vector of buffers. The buffers do not own the - /// underlying memory blocks, therefore the reply object must remain valid and - /// not be changed until the write operation has completed. - std::vector to_buffers(); - - /// Get a stock reply. - static HttpReply stock_reply(status_type status); -}; - - -#endif // HTTP_REPLY_HPP \ No newline at end of file diff --git a/src/HttpRequest.h b/src/HttpRequest.h deleted file mode 100644 index 2f6b54522c..0000000000 --- a/src/HttpRequest.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef HTTP_REQUEST_HPP -#define HTTP_REQUEST_HPP - -#include -#include - -struct HttpHeader -{ - std::string name; - std::string value; -}; - -/// A request received from a client. -struct HttpRequest -{ - std::string method; - std::string uri; - int http_version_major; - int http_version_minor; - std::vector headers; - std::string mBody; -}; - -#endif // HTTP_REQUEST_HPP diff --git a/src/RequestParser.cpp b/src/RequestParser.cpp deleted file mode 100644 index 8384cd0e19..0000000000 --- a/src/RequestParser.cpp +++ /dev/null @@ -1,330 +0,0 @@ -#include "RequestParser.h" -#include "HttpRequest.h" - - - -HttpRequestParser::HttpRequestParser() - : state_(method_start) -{ -} - -void HttpRequestParser::reset() -{ - state_ = method_start; -} - -//template -boost::tribool HttpRequestParser::parse(HttpRequest& req, - char* begin, char* end) -{ - while (begin != end) - { - boost::tribool result = consume(req, *begin++); - if (result || !result) - { - std::string temp(begin,end); - req.mBody=temp; - return result; - } - } - boost::tribool result = boost::indeterminate; - return result; -} - -boost::tribool HttpRequestParser::consume(HttpRequest& req, char input) -{ - switch (state_) - { - case method_start: - if (!is_char(input) || is_ctl(input) || is_tspecial(input)) - { - return false; - } - else - { - state_ = method; - req.method.push_back(input); - return boost::indeterminate; - } - case method: - if (input == ' ') - { - state_ = uri; - return boost::indeterminate; - } - else if (!is_char(input) || is_ctl(input) || is_tspecial(input)) - { - return false; - } - else - { - req.method.push_back(input); - return boost::indeterminate; - } - case uri_start: - if (is_ctl(input)) - { - return false; - } - else - { - state_ = uri; - req.uri.push_back(input); - return boost::indeterminate; - } - case uri: - if (input == ' ') - { - state_ = http_version_h; - return boost::indeterminate; - } - else if (is_ctl(input)) - { - return false; - } - else - { - req.uri.push_back(input); - return boost::indeterminate; - } - case http_version_h: - if (input == 'H') - { - state_ = http_version_t_1; - return boost::indeterminate; - } - else - { - return false; - } - case http_version_t_1: - if (input == 'T') - { - state_ = http_version_t_2; - return boost::indeterminate; - } - else - { - return false; - } - case http_version_t_2: - if (input == 'T') - { - state_ = http_version_p; - return boost::indeterminate; - } - else - { - return false; - } - case http_version_p: - if (input == 'P') - { - state_ = http_version_slash; - return boost::indeterminate; - } - else - { - return false; - } - case http_version_slash: - if (input == '/') - { - req.http_version_major = 0; - req.http_version_minor = 0; - state_ = http_version_major_start; - return boost::indeterminate; - } - else - { - return false; - } - case http_version_major_start: - if (is_digit(input)) - { - req.http_version_major = req.http_version_major * 10 + input - '0'; - state_ = http_version_major; - return boost::indeterminate; - } - else - { - return false; - } - case http_version_major: - if (input == '.') - { - state_ = http_version_minor_start; - return boost::indeterminate; - } - else if (is_digit(input)) - { - req.http_version_major = req.http_version_major * 10 + input - '0'; - return boost::indeterminate; - } - else - { - return false; - } - case http_version_minor_start: - if (is_digit(input)) - { - req.http_version_minor = req.http_version_minor * 10 + input - '0'; - state_ = http_version_minor; - return boost::indeterminate; - } - else - { - return false; - } - case http_version_minor: - if (input == '\r') - { - state_ = expecting_newline_1; - return boost::indeterminate; - } - else if (is_digit(input)) - { - req.http_version_minor = req.http_version_minor * 10 + input - '0'; - return boost::indeterminate; - } - else - { - return false; - } - case expecting_newline_1: - if (input == '\n') - { - state_ = header_line_start; - return boost::indeterminate; - } - else - { - return false; - } - case header_line_start: - if (input == '\r') - { - state_ = expecting_newline_3; - return boost::indeterminate; - } - else if (!req.headers.empty() && (input == ' ' || input == '\t')) - { - state_ = header_lws; - return boost::indeterminate; - } - else if (!is_char(input) || is_ctl(input) || is_tspecial(input)) - { - return false; - } - else - { - req.headers.push_back(HttpHeader()); - req.headers.back().name.push_back(input); - state_ = header_name; - return boost::indeterminate; - } - case header_lws: - if (input == '\r') - { - state_ = expecting_newline_2; - return boost::indeterminate; - } - else if (input == ' ' || input == '\t') - { - return boost::indeterminate; - } - else if (is_ctl(input)) - { - return false; - } - else - { - state_ = header_value; - req.headers.back().value.push_back(input); - return boost::indeterminate; - } - case header_name: - if (input == ':') - { - state_ = space_before_header_value; - return boost::indeterminate; - } - else if (!is_char(input) || is_ctl(input) || is_tspecial(input)) - { - return false; - } - else - { - req.headers.back().name.push_back(input); - return boost::indeterminate; - } - case space_before_header_value: - if (input == ' ') - { - state_ = header_value; - return boost::indeterminate; - } - else - { - return false; - } - case header_value: - if (input == '\r') - { - state_ = expecting_newline_2; - return boost::indeterminate; - } - else if (is_ctl(input)) - { - return false; - } - else - { - req.headers.back().value.push_back(input); - return boost::indeterminate; - } - case expecting_newline_2: - if (input == '\n') - { - state_ = header_line_start; - return boost::indeterminate; - } - else - { - return false; - } - case expecting_newline_3: - return (input == '\n'); - default: - return false; - } -} - -bool HttpRequestParser::is_char(int c) -{ - return c >= 0 && c <= 127; -} - -bool HttpRequestParser::is_ctl(int c) -{ - return (c >= 0 && c <= 31) || (c == 127); -} - -bool HttpRequestParser::is_tspecial(int c) -{ - switch (c) - { - case '(': case ')': case '<': case '>': case '@': - case ',': case ';': case ':': case '\\': case '"': - case '/': case '[': case ']': case '?': case '=': - case '{': case '}': case ' ': case '\t': - return true; - default: - return false; - } -} - -bool HttpRequestParser::is_digit(int c) -{ - return c >= '0' && c <= '9'; -} diff --git a/src/RequestParser.h b/src/RequestParser.h deleted file mode 100644 index f0906daa88..0000000000 --- a/src/RequestParser.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef HTTP_REQUEST_PARSER_HPP -#define HTTP_REQUEST_PARSER_HPP - -#include -#include - - - -struct HttpRequest; - -/// Parser for incoming requests. -class HttpRequestParser -{ - /// Handle the next character of input. - boost::tribool consume(HttpRequest& req, char input); - - /// Check if a byte is an HTTP character. - static bool is_char(int c); - - /// Check if a byte is an HTTP control character. - static bool is_ctl(int c); - - /// Check if a byte is defined as an HTTP special character. - static bool is_tspecial(int c); - - /// Check if a byte is a digit. - static bool is_digit(int c); - - /// The current state of the parser. - enum state - { - method_start, - method, - uri_start, - uri, - http_version_h, - http_version_t_1, - http_version_t_2, - http_version_p, - http_version_slash, - http_version_major_start, - http_version_major, - http_version_minor_start, - http_version_minor, - expecting_newline_1, - header_line_start, - header_lws, - header_name, - space_before_header_value, - header_value, - expecting_newline_2, - expecting_newline_3 - } state_; -public: - /// Construct ready to parse the request method. - HttpRequestParser(); - - /// Reset to initial parser state. - void reset(); - - /// Parse some data. The tribool return value is true when a complete request - /// has been parsed, false if the data is invalid, indeterminate when more - /// data is required. The InputIterator return value indicates how much of the - /// input has been consumed. - //template - boost::tribool parse(HttpRequest& req, char*, char*); - - -}; - - -#endif // HTTP_REQUEST_PARSER_HPP