more refactoring!

This commit is contained in:
Peter Thorson
2011-10-30 09:12:23 -05:00
parent d806bea762
commit 7ff1e6a546
8 changed files with 263 additions and 18 deletions

195
src/http/constants.hpp Normal file
View File

@@ -0,0 +1,195 @@
/*
* Copyright (c) 2011, Peter Thorson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This Makefile was derived from a similar one included in the libjson project
* It's authors were Jonathan Wallace and Bernhard Fluehmann.
*/
#ifndef HTTP_CONSTANTS_HPP
#define HTTP_CONSTANTS_HPP
namespace websocketpp {
namespace http {
namespace status_code {
enum value {
CONTINUE = 100,
SWITCHING_PROTOCOLS = 101,
OK = 200,
CREATED = 201,
ACCEPTED = 202,
NON_AUTHORITATIVE_INFORMATION = 203,
NO_CONTENT = 204,
RESET_CONTENT = 205,
PARTIAL_CONTENT = 206,
MULTIPLE_CHOICES = 300,
MOVED_PERMANENTLY = 301,
FOUND = 302,
SEE_OTHER = 303,
NOT_MODIFIED = 304,
USE_PROXY = 305,
TEMPORARY_REDIRECT = 307,
BAD_REQUEST = 400,
UNAUTHORIZED = 401,
PAYMENT_REQUIRED = 402,
FORBIDDEN = 403,
NOT_FOUND = 404,
METHOD_NOT_ALLOWED = 405,
NOT_ACCEPTABLE = 406,
PROXY_AUTHENTICATION_REQUIRED = 407,
REQUEST_TIMEOUT = 408,
CONFLICT = 409,
GONE = 410,
LENGTH_REQUIRED = 411,
PRECONDITION_FAILED = 412,
REQUEST_ENTITY_TOO_LARGE = 413,
REQUEST_URI_TOO_LONG = 414,
UNSUPPORTED_MEDIA_TYPE = 415,
REQUEST_RANGE_NOT_SATISFIABLE = 416,
EXPECTATION_FAILED = 417,
IM_A_TEAPOT = 418,
UPGRADE_REQUIRED = 426,
PRECONDITION_REQUIRED = 428,
TOO_MANY_REQUESTS = 429,
REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
INTERNAL_SERVER_ERROR = 500,
NOT_IMPLIMENTED = 501,
BAD_GATEWAY = 502,
SERVICE_UNAVAILABLE = 503,
GATEWAY_TIMEOUT = 504,
HTTP_VERSION_NOT_SUPPORTED = 505,
NOT_EXTENDED = 510,
NETWORK_AUTHENTICATION_REQUIRED = 511
};
std::string get_string(value c) {
switch (c) {
case CONTINUE:
return "Continue";
case SWITCHING_PROTOCOLS:
return "Switching Protocols";
case OK:
return "OK";
case CREATED:
return "Created";
case ACCEPTED:
return "Accepted";
case NON_AUTHORITATIVE_INFORMATION:
return "Non Authoritative Information";
case NO_CONTENT:
return "No Content";
case RESET_CONTENT:
return "Reset Content";
case PARTIAL_CONTENT:
return "Partial Content";
case MULTIPLE_CHOICES:
return "Multiple Choices";
case MOVED_PERMANENTLY:
return "Moved Permanently";
case FOUND:
return "Found";
case SEE_OTHER:
return "See Other";
case NOT_MODIFIED:
return "Not Modified";
case USE_PROXY:
return "Use Proxy";
case TEMPORARY_REDIRECT:
return "Temporary Redirect";
case BAD_REQUEST:
return "Bad Request";
case UNAUTHORIZED:
return "Unauthorized";
case FORBIDDEN:
return "Forbidden";
case NOT_FOUND:
return "Not Found";
case METHOD_NOT_ALLOWED:
return "Method Not Allowed";
case NOT_ACCEPTABLE:
return "Not Acceptable";
case PROXY_AUTHENTICATION_REQUIRED:
return "Proxy Authentication Required";
case REQUEST_TIMEOUT:
return "Request Timeout";
case CONFLICT:
return "Conflict";
case GONE:
return "Gone";
case LENGTH_REQUIRED:
return "Length Required";
case PRECONDITION_FAILED:
return "Precondition Failed";
case REQUEST_ENTITY_TOO_LARGE:
return "Request Entity Too Large";
case REQUEST_URI_TOO_LONG:
return "Request-URI Too Long";
case UNSUPPORTED_MEDIA_TYPE:
return "Unsupported Media Type";
case REQUEST_RANGE_NOT_SATISFIABLE:
return "Requested Range Not Satisfiable";
case EXPECTATION_FAILED:
return "Expectation Failed";
case IM_A_TEAPOT:
return "I'm a teapot";
case UPGRADE_REQUIRED:
return "Upgrade Required";
case PRECONDITION_REQUIRED:
return "Precondition Required";
case TOO_MANY_REQUESTS:
return "Too Many Requests";
case REQUEST_HEADER_FIELDS_TOO_LARGE:
return "Request Header Fields Too Large";
case INTERNAL_SERVER_ERROR:
return "Internal Server Error";
case NOT_IMPLIMENTED:
return "Not Implimented";
case BAD_GATEWAY:
return "Bad Gateway";
case SERVICE_UNAVAILABLE:
return "Service Unavailable";
case GATEWAY_TIMEOUT:
return "Gateway Timeout";
case HTTP_VERSION_NOT_SUPPORTED:
return "HTTP Version Not Supported";
case NOT_EXTENDED:
return "Not Extended";
case NETWORK_AUTHENTICATION_REQUIRED:
return "Network Authentication Required";
default:
return "Unknown";
}
}
}
}
}
#endif // HTTP_CONSTANTS_HPP

46
src/rng/blank_rng.hpp Normal file
View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2011, Peter Thorson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This Makefile was derived from a similar one included in the libjson project
* It's authors were Jonathan Wallace and Bernhard Fluehmann.
*/
#ifndef BLANK_RNG_HPP
#define BLANK_RNG_HPP
#include <stdint.h>
namespace websocketpp {
class blank_rng {
public:
int32_t gen() {
throw "Random Number generation not supported";
}
};
}
#endif // BLANK_RNG_HPP

View File

@@ -42,7 +42,7 @@ namespace po = boost::program_options;
#include <boost/date_time/posix_time/posix_time.hpp>
#include "policy/rng/blank_rng.hpp"
#include "rng/blank_rng.hpp"
using boost::asio::ip::tcp;

View File

@@ -129,6 +129,12 @@
B6138766145AD1F700ED9B19 /* chat.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = chat.hpp; path = examples/chat_server/chat.hpp; sourceTree = "<group>"; };
B6138767145AD1F700ED9B19 /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; name = Makefile; path = examples/chat_server/Makefile; sourceTree = "<group>"; };
B6138791145CA6F700ED9B19 /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
B61387A0145D846400ED9B19 /* blank_rng.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = blank_rng.cpp; path = src/rng/blank_rng.cpp; sourceTree = "<group>"; };
B61387A1145D846400ED9B19 /* blank_rng.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = blank_rng.hpp; path = src/rng/blank_rng.hpp; sourceTree = "<group>"; };
B61387A2145D846400ED9B19 /* boost_rng.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = boost_rng.cpp; path = src/rng/boost_rng.cpp; sourceTree = "<group>"; };
B61387A3145D846400ED9B19 /* boost_rng.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = boost_rng.hpp; path = src/rng/boost_rng.hpp; sourceTree = "<group>"; };
B61387A5145D849E00ED9B19 /* constants.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = constants.hpp; path = src/http/constants.hpp; sourceTree = "<group>"; };
B61387A6145D849E00ED9B19 /* parser.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = parser.hpp; path = src/http/parser.hpp; sourceTree = "<group>"; };
B6828875143745DA002BA48B /* chat_client_handler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = chat_client_handler.cpp; path = examples/chat_client/chat_client_handler.cpp; sourceTree = "<group>"; };
B6828876143745DA002BA48B /* chat_client_handler.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = chat_client_handler.hpp; path = examples/chat_client/chat_client_handler.hpp; sourceTree = "<group>"; };
B6828877143745DA002BA48B /* chat_client.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = chat_client.cpp; path = examples/chat_client/chat_client.cpp; sourceTree = "<group>"; };
@@ -179,10 +185,6 @@
B6FE8CE2144DE17F00B32547 /* readme.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = readme.txt; sourceTree = "<group>"; };
B6FE8CEB145A0F1900B32547 /* libboost_program_options.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libboost_program_options.dylib; path = usr/local/lib/libboost_program_options.dylib; sourceTree = SDKROOT; };
B6FE8D05145AFF5F00B32547 /* websocket_constants.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = websocket_constants.hpp; path = src/websocket_constants.hpp; sourceTree = "<group>"; };
B6FE8D0A145B0FA400B32547 /* blank_rng.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = blank_rng.cpp; path = src/policy/rng/blank_rng.cpp; sourceTree = "<group>"; };
B6FE8D0B145B0FA400B32547 /* blank_rng.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = blank_rng.hpp; path = src/policy/rng/blank_rng.hpp; sourceTree = "<group>"; };
B6FE8D0C145B0FA400B32547 /* boost_rng.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = boost_rng.cpp; path = src/policy/rng/boost_rng.cpp; sourceTree = "<group>"; };
B6FE8D0D145B0FA400B32547 /* boost_rng.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = boost_rng.hpp; path = src/policy/rng/boost_rng.hpp; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -239,6 +241,15 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
B61387A4145D847A00ED9B19 /* http */ = {
isa = PBXGroup;
children = (
B61387A5145D849E00ED9B19 /* constants.hpp */,
B61387A6145D849E00ED9B19 /* parser.hpp */,
);
name = http;
sourceTree = "<group>";
};
B6CF18121437C370009295BE /* echo_client */ = {
isa = PBXGroup;
children = (
@@ -284,7 +295,8 @@
B6DF1C7F1434ABB70029A1B1 /* src */ = {
isa = PBXGroup;
children = (
B6FE8D08145B0F6600B32547 /* policy */,
B61387A4145D847A00ED9B19 /* http */,
B6FE8D09145B0F7400B32547 /* rng */,
B6FE8D05145AFF5F00B32547 /* websocket_constants.hpp */,
B6DF1C921434AC470029A1B1 /* websocket_client_session.cpp */,
B6DF1C931434AC470029A1B1 /* websocket_client_session.hpp */,
@@ -403,21 +415,13 @@
name = documentation;
sourceTree = "<group>";
};
B6FE8D08145B0F6600B32547 /* policy */ = {
isa = PBXGroup;
children = (
B6FE8D09145B0F7400B32547 /* rng */,
);
name = policy;
sourceTree = "<group>";
};
B6FE8D09145B0F7400B32547 /* rng */ = {
isa = PBXGroup;
children = (
B6FE8D0A145B0FA400B32547 /* blank_rng.cpp */,
B6FE8D0B145B0FA400B32547 /* blank_rng.hpp */,
B6FE8D0C145B0FA400B32547 /* boost_rng.cpp */,
B6FE8D0D145B0FA400B32547 /* boost_rng.hpp */,
B61387A0145D846400ED9B19 /* blank_rng.cpp */,
B61387A1145D846400ED9B19 /* blank_rng.hpp */,
B61387A2145D846400ED9B19 /* boost_rng.cpp */,
B61387A3145D846400ED9B19 /* boost_rng.hpp */,
);
name = rng;
sourceTree = "<group>";