2016-01-18 15:33:29 +00:00
|
|
|
// Copyright (c) 2011-2016 The Cryptonote developers
|
2015-09-18 11:55:31 +00:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2015-05-27 12:08:46 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <system_error>
|
|
|
|
|
|
|
|
namespace CryptoNote {
|
|
|
|
namespace error {
|
|
|
|
|
|
|
|
enum HttpParserErrorCodes {
|
|
|
|
STREAM_NOT_GOOD = 1,
|
|
|
|
END_OF_STREAM,
|
|
|
|
UNEXPECTED_SYMBOL,
|
|
|
|
EMPTY_HEADER
|
|
|
|
};
|
|
|
|
|
|
|
|
// custom category:
|
|
|
|
class HttpParserErrorCategory : public std::error_category {
|
|
|
|
public:
|
|
|
|
static HttpParserErrorCategory INSTANCE;
|
|
|
|
|
2015-12-14 17:40:07 +00:00
|
|
|
virtual const char* name() const throw() override {
|
2015-05-27 12:08:46 +00:00
|
|
|
return "HttpParserErrorCategory";
|
|
|
|
}
|
|
|
|
|
2015-12-14 17:40:07 +00:00
|
|
|
virtual std::error_condition default_error_condition(int ev) const throw() override {
|
2015-05-27 12:08:46 +00:00
|
|
|
return std::error_condition(ev, *this);
|
|
|
|
}
|
|
|
|
|
2015-12-14 17:40:07 +00:00
|
|
|
virtual std::string message(int ev) const override {
|
2015-05-27 12:08:46 +00:00
|
|
|
switch (ev) {
|
|
|
|
case STREAM_NOT_GOOD: return "The stream is not good";
|
|
|
|
case END_OF_STREAM: return "The stream is ended";
|
|
|
|
case UNEXPECTED_SYMBOL: return "Unexpected symbol";
|
|
|
|
case EMPTY_HEADER: return "The header name is empty";
|
|
|
|
default: return "Unknown error";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
HttpParserErrorCategory() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} //namespace error
|
2015-07-30 15:22:07 +00:00
|
|
|
} //namespace CryptoNote
|
2015-05-27 12:08:46 +00:00
|
|
|
|
|
|
|
inline std::error_code make_error_code(CryptoNote::error::HttpParserErrorCodes e) {
|
|
|
|
return std::error_code(static_cast<int>(e), CryptoNote::error::HttpParserErrorCategory::INSTANCE);
|
|
|
|
}
|