mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
Merge pull request #106 from sfinktah/sfinktah-64bit-compat-1
recast 64-bit size_t to 32-bit int to remove warnings
This commit is contained in:
commit
5ab2607832
@ -27,7 +27,7 @@ namespace crow
|
|||||||
if (!self)
|
if (!self)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
unsigned int index = (unsigned int)(k.second - self->step_);
|
unsigned int index = static_cast<unsigned>(k.second - self->step_);
|
||||||
if (index < self->dq_.size())
|
if (index < self->dq_.size())
|
||||||
self->dq_[index].second = nullptr;
|
self->dq_[index].second = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -317,7 +317,7 @@ namespace crow
|
|||||||
res.is_alive_helper_ = [this]()->bool{ return adaptor_.is_open(); };
|
res.is_alive_helper_ = [this]()->bool{ return adaptor_.is_open(); };
|
||||||
|
|
||||||
ctx_ = detail::context<Middlewares...>();
|
ctx_ = detail::context<Middlewares...>();
|
||||||
req.middleware_context = (void*)&ctx_;
|
req.middleware_context = static_cast<void*>(&ctx_);
|
||||||
req.io_service = &adaptor_.get_io_service();
|
req.io_service = &adaptor_.get_io_service();
|
||||||
detail::middleware_call_helper<0, decltype(ctx_), decltype(*middlewares_), Middlewares...>(*middlewares_, req, res, ctx_);
|
detail::middleware_call_helper<0, decltype(ctx_), decltype(*middlewares_), Middlewares...>(*middlewares_, req, res, ctx_);
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ namespace crow
|
|||||||
|
|
||||||
// call all after_handler of middlewares
|
// call all after_handler of middlewares
|
||||||
detail::after_handlers_call_helper<
|
detail::after_handlers_call_helper<
|
||||||
((int)sizeof...(Middlewares)-1),
|
(static_cast<int>(sizeof...(Middlewares))-1),
|
||||||
decltype(ctx_),
|
decltype(ctx_),
|
||||||
decltype(*middlewares_)>
|
decltype(*middlewares_)>
|
||||||
(*middlewares_, ctx_, req_, res);
|
(*middlewares_, ctx_, req_, res);
|
||||||
|
@ -1234,7 +1234,7 @@ static const int8_t unhex[256] =
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
parser->method = (enum http_method) 0;
|
parser->method = static_cast<http_method>(0);
|
||||||
parser->index = 1;
|
parser->index = 1;
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'C': parser->method = HTTP_CONNECT; /* or COPY, CHECKOUT */ break;
|
case 'C': parser->method = HTTP_CONNECT; /* or COPY, CHECKOUT */ break;
|
||||||
@ -1357,7 +1357,7 @@ static const int8_t unhex[256] =
|
|||||||
parser->state = s_req_server_start;
|
parser->state = s_req_server_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
parser->state = parse_url_char((enum state)parser->state, ch);
|
parser->state = parse_url_char(static_cast<state>(parser->state), ch);
|
||||||
if (parser->state == s_dead) {
|
if (parser->state == s_dead) {
|
||||||
CROW_SET_ERRNO(HPE_INVALID_URL);
|
CROW_SET_ERRNO(HPE_INVALID_URL);
|
||||||
goto error;
|
goto error;
|
||||||
@ -1379,7 +1379,7 @@ static const int8_t unhex[256] =
|
|||||||
CROW_SET_ERRNO(HPE_INVALID_URL);
|
CROW_SET_ERRNO(HPE_INVALID_URL);
|
||||||
goto error;
|
goto error;
|
||||||
default:
|
default:
|
||||||
parser->state = parse_url_char((enum state)parser->state, ch);
|
parser->state = parse_url_char(static_cast<state>(parser->state), ch);
|
||||||
if (parser->state == s_dead) {
|
if (parser->state == s_dead) {
|
||||||
CROW_SET_ERRNO(HPE_INVALID_URL);
|
CROW_SET_ERRNO(HPE_INVALID_URL);
|
||||||
goto error;
|
goto error;
|
||||||
@ -1412,7 +1412,7 @@ static const int8_t unhex[256] =
|
|||||||
CROW_CALLBACK_DATA(url);
|
CROW_CALLBACK_DATA(url);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
parser->state = parse_url_char((enum state)parser->state, ch);
|
parser->state = parse_url_char(static_cast<state>(parser->state), ch);
|
||||||
if (parser->state == s_dead) {
|
if (parser->state == s_dead) {
|
||||||
CROW_SET_ERRNO(HPE_INVALID_URL);
|
CROW_SET_ERRNO(HPE_INVALID_URL);
|
||||||
goto error;
|
goto error;
|
||||||
@ -2086,7 +2086,7 @@ static const int8_t unhex[256] =
|
|||||||
assert(parser->nread == 1);
|
assert(parser->nread == 1);
|
||||||
assert(parser->flags & F_CHUNKED);
|
assert(parser->flags & F_CHUNKED);
|
||||||
|
|
||||||
unhex_val = unhex[(unsigned char)ch];
|
unhex_val = unhex[static_cast<unsigned char>(ch)];
|
||||||
if (unhex_val == -1) {
|
if (unhex_val == -1) {
|
||||||
CROW_SET_ERRNO(HPE_INVALID_CHUNK_SIZE);
|
CROW_SET_ERRNO(HPE_INVALID_CHUNK_SIZE);
|
||||||
goto error;
|
goto error;
|
||||||
@ -2108,7 +2108,7 @@ static const int8_t unhex[256] =
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
unhex_val = unhex[(unsigned char)ch];
|
unhex_val = unhex[static_cast<unsigned char>(ch)];
|
||||||
|
|
||||||
if (unhex_val == -1) {
|
if (unhex_val == -1) {
|
||||||
if (ch == ';' || ch == ' ') {
|
if (ch == ';' || ch == ' ') {
|
||||||
@ -2567,7 +2567,7 @@ http_parser_parse_url(const char *buf, size_t buflen, int is_connect,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
u->port = (uint16_t) v;
|
u->port = static_cast<uint16_t>(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -172,7 +172,7 @@ namespace crow
|
|||||||
uint8_t owned_{0};
|
uint8_t owned_{0};
|
||||||
friend std::ostream& operator << (std::ostream& os, const r_string& s)
|
friend std::ostream& operator << (std::ostream& os, const r_string& s)
|
||||||
{
|
{
|
||||||
os << (std::string)s;
|
os << static_cast<std::string>(s);
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
@ -292,7 +292,7 @@ namespace crow
|
|||||||
|
|
||||||
explicit operator int() const
|
explicit operator int() const
|
||||||
{
|
{
|
||||||
return (int)i();
|
return static_cast<int>(i());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The type of the JSON value.
|
/// The type of the JSON value.
|
||||||
@ -522,7 +522,7 @@ namespace crow
|
|||||||
#ifndef CROW_JSON_NO_ERROR_CHECK
|
#ifndef CROW_JSON_NO_ERROR_CHECK
|
||||||
if (t() != type::List)
|
if (t() != type::List)
|
||||||
throw std::runtime_error("value is not a list");
|
throw std::runtime_error("value is not a list");
|
||||||
if (index >= (int)lsize_ || index < 0)
|
if (index >= static_cast<int>(lsize_) || index < 0)
|
||||||
throw std::runtime_error("list out of bound");
|
throw std::runtime_error("list out of bound");
|
||||||
#endif
|
#endif
|
||||||
return l_[index];
|
return l_[index];
|
||||||
@ -905,7 +905,7 @@ namespace crow
|
|||||||
switch(*data)
|
switch(*data)
|
||||||
{
|
{
|
||||||
case '0':
|
case '0':
|
||||||
state = (NumberParsingState)"\2\2\7\3\4\6\6"[state];
|
state = static_cast<NumberParsingState>("\2\2\7\3\4\6\6"[state]);
|
||||||
/*if (state == NumberParsingState::Minus || state == NumberParsingState::AfterMinus)
|
/*if (state == NumberParsingState::Minus || state == NumberParsingState::AfterMinus)
|
||||||
{
|
{
|
||||||
state = NumberParsingState::ZeroFirst;
|
state = NumberParsingState::ZeroFirst;
|
||||||
@ -926,7 +926,7 @@ namespace crow
|
|||||||
case '1': case '2': case '3':
|
case '1': case '2': case '3':
|
||||||
case '4': case '5': case '6':
|
case '4': case '5': case '6':
|
||||||
case '7': case '8': case '9':
|
case '7': case '8': case '9':
|
||||||
state = (NumberParsingState)"\3\3\7\3\4\6\6"[state];
|
state = static_cast<NumberParsingState>("\3\3\7\3\4\6\6"[state]);
|
||||||
while(*(data+1) >= '0' && *(data+1) <= '9') data++;
|
while(*(data+1) >= '0' && *(data+1) <= '9') data++;
|
||||||
/*if (state == NumberParsingState::Minus || state == NumberParsingState::AfterMinus)
|
/*if (state == NumberParsingState::Minus || state == NumberParsingState::AfterMinus)
|
||||||
{
|
{
|
||||||
@ -946,7 +946,7 @@ namespace crow
|
|||||||
return {};*/
|
return {};*/
|
||||||
break;
|
break;
|
||||||
case '.':
|
case '.':
|
||||||
state = (NumberParsingState)"\7\7\4\4\7\7\7"[state];
|
state = static_cast<NumberParsingState>("\7\7\4\4\7\7\7"[state]);
|
||||||
/*
|
/*
|
||||||
if (state == NumberParsingState::Digits || state == NumberParsingState::ZeroFirst)
|
if (state == NumberParsingState::Digits || state == NumberParsingState::ZeroFirst)
|
||||||
{
|
{
|
||||||
@ -957,7 +957,7 @@ namespace crow
|
|||||||
*/
|
*/
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
state = (NumberParsingState)"\1\7\7\7\7\6\7"[state];
|
state = static_cast<NumberParsingState>("\1\7\7\7\7\6\7"[state]);
|
||||||
/*if (state == NumberParsingState::Minus)
|
/*if (state == NumberParsingState::Minus)
|
||||||
{
|
{
|
||||||
state = NumberParsingState::AfterMinus;
|
state = NumberParsingState::AfterMinus;
|
||||||
@ -970,7 +970,7 @@ namespace crow
|
|||||||
return {};*/
|
return {};*/
|
||||||
break;
|
break;
|
||||||
case '+':
|
case '+':
|
||||||
state = (NumberParsingState)"\7\7\7\7\7\6\7"[state];
|
state = static_cast<NumberParsingState>("\7\7\7\7\7\6\7"[state]);
|
||||||
/*if (state == NumberParsingState::E)
|
/*if (state == NumberParsingState::E)
|
||||||
{
|
{
|
||||||
state = NumberParsingState::DigitsAfterE;
|
state = NumberParsingState::DigitsAfterE;
|
||||||
@ -979,7 +979,7 @@ namespace crow
|
|||||||
return {};*/
|
return {};*/
|
||||||
break;
|
break;
|
||||||
case 'e': case 'E':
|
case 'e': case 'E':
|
||||||
state = (NumberParsingState)"\7\7\7\5\5\7\7"[state];
|
state = static_cast<NumberParsingState>("\7\7\7\5\5\7\7"[state]);
|
||||||
/*if (state == NumberParsingState::Digits ||
|
/*if (state == NumberParsingState::Digits ||
|
||||||
state == NumberParsingState::DigitsAfterPoints)
|
state == NumberParsingState::DigitsAfterPoints)
|
||||||
{
|
{
|
||||||
|
@ -108,7 +108,7 @@ namespace crow
|
|||||||
//
|
//
|
||||||
static LogLevel& get_log_level_ref()
|
static LogLevel& get_log_level_ref()
|
||||||
{
|
{
|
||||||
static LogLevel current_level = (LogLevel)CROW_LOG_LEVEL;
|
static LogLevel current_level = static_cast<LogLevel>(CROW_LOG_LEVEL);
|
||||||
return current_level;
|
return current_level;
|
||||||
}
|
}
|
||||||
static ILogHandler*& get_handler_ref()
|
static ILogHandler*& get_handler_ref()
|
||||||
|
@ -45,8 +45,8 @@ namespace crow
|
|||||||
int end;
|
int end;
|
||||||
int pos;
|
int pos;
|
||||||
ActionType t;
|
ActionType t;
|
||||||
Action(ActionType t, int start, int end, int pos = 0)
|
Action(ActionType t, size_t start, size_t end, size_t pos = 0)
|
||||||
: start(start), end(end), pos(pos), t(t)
|
: start(static_cast<int>(start)), end(static_cast<int>(end)), pos(static_cast<int>(pos)), t(t)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ namespace crow
|
|||||||
empty_str = "";
|
empty_str = "";
|
||||||
|
|
||||||
int dotPosition = name.find(".");
|
int dotPosition = name.find(".");
|
||||||
if (dotPosition == (int)name.npos)
|
if (dotPosition == static_cast<int>(name.npos))
|
||||||
{
|
{
|
||||||
for(auto it = stack.rbegin(); it != stack.rend(); ++it)
|
for(auto it = stack.rbegin(); it != stack.rend(); ++it)
|
||||||
{
|
{
|
||||||
@ -91,7 +91,7 @@ namespace crow
|
|||||||
{
|
{
|
||||||
std::vector<int> dotPositions;
|
std::vector<int> dotPositions;
|
||||||
dotPositions.push_back(-1);
|
dotPositions.push_back(-1);
|
||||||
while(dotPosition != (int)name.npos)
|
while(dotPosition != static_cast<int>(name.npos))
|
||||||
{
|
{
|
||||||
dotPositions.push_back(dotPosition);
|
dotPositions.push_back(dotPosition);
|
||||||
dotPosition = name.find(".", dotPosition+1);
|
dotPosition = name.find(".", dotPosition+1);
|
||||||
@ -99,7 +99,7 @@ namespace crow
|
|||||||
dotPositions.push_back(name.size());
|
dotPositions.push_back(name.size());
|
||||||
std::vector<std::string> names;
|
std::vector<std::string> names;
|
||||||
names.reserve(dotPositions.size()-1);
|
names.reserve(dotPositions.size()-1);
|
||||||
for(int i = 1; i < (int)dotPositions.size(); i ++)
|
for(int i = 1; i < static_cast<int>(dotPositions.size()); i ++)
|
||||||
names.emplace_back(name.substr(dotPositions[i-1]+1, dotPositions[i]-dotPositions[i-1]-1));
|
names.emplace_back(name.substr(dotPositions[i-1]+1, dotPositions[i]-dotPositions[i-1]-1));
|
||||||
|
|
||||||
for(auto it = stack.rbegin(); it != stack.rend(); ++it)
|
for(auto it = stack.rbegin(); it != stack.rend(); ++it)
|
||||||
@ -216,7 +216,7 @@ namespace crow
|
|||||||
out += ctx.s;
|
out += ctx.s;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw std::runtime_error("not implemented tag type" + boost::lexical_cast<std::string>((int)ctx.t()));
|
throw std::runtime_error("not implemented tag type" + boost::lexical_cast<std::string>(static_cast<int>(ctx.t())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -282,7 +282,7 @@ namespace crow
|
|||||||
current = action.pos;
|
current = action.pos;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw std::runtime_error("{{#: not implemented context type: " + boost::lexical_cast<std::string>((int)ctx.t()));
|
throw std::runtime_error("{{#: not implemented context type: " + boost::lexical_cast<std::string>(static_cast<int>(ctx.t())));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -291,7 +291,7 @@ namespace crow
|
|||||||
stack.pop_back();
|
stack.pop_back();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw std::runtime_error("not implemented " + boost::lexical_cast<std::string>((int)action.t));
|
throw std::runtime_error("not implemented " + boost::lexical_cast<std::string>(static_cast<int>(action.t)));
|
||||||
}
|
}
|
||||||
current++;
|
current++;
|
||||||
}
|
}
|
||||||
@ -305,7 +305,7 @@ namespace crow
|
|||||||
for(int i = fragment.first; i < fragment.second; i ++)
|
for(int i = fragment.first; i < fragment.second; i ++)
|
||||||
{
|
{
|
||||||
out += body_[i];
|
out += body_[i];
|
||||||
if (body_[i] == '\n' && i+1 != (int)body_.size())
|
if (body_[i] == '\n' && i+1 != static_cast<int>(body_.size()))
|
||||||
out.insert(out.size(), indent, ' ');
|
out.insert(out.size(), indent, ' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -348,11 +348,11 @@ namespace crow
|
|||||||
size_t idx = body_.find(tag_open, current);
|
size_t idx = body_.find(tag_open, current);
|
||||||
if (idx == body_.npos)
|
if (idx == body_.npos)
|
||||||
{
|
{
|
||||||
fragments_.emplace_back(current, body_.size());
|
fragments_.emplace_back(static_cast<int>(current), static_cast<int>(body_.size()));
|
||||||
actions_.emplace_back(ActionType::Ignore, 0, 0);
|
actions_.emplace_back(ActionType::Ignore, 0, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fragments_.emplace_back(current, idx);
|
fragments_.emplace_back(static_cast<int>(current), static_cast<int>(idx));
|
||||||
|
|
||||||
idx += tag_open.size();
|
idx += tag_open.size();
|
||||||
size_t endIdx = body_.find(tag_close, idx);
|
size_t endIdx = body_.find(tag_close, idx);
|
||||||
@ -372,7 +372,7 @@ namespace crow
|
|||||||
idx++;
|
idx++;
|
||||||
while(body_[idx] == ' ') idx++;
|
while(body_[idx] == ' ') idx++;
|
||||||
while(body_[endIdx-1] == ' ') endIdx--;
|
while(body_[endIdx-1] == ' ') endIdx--;
|
||||||
blockPositions.emplace_back(actions_.size());
|
blockPositions.emplace_back(static_cast<int>(actions_.size()));
|
||||||
actions_.emplace_back(ActionType::OpenBlock, idx, endIdx);
|
actions_.emplace_back(ActionType::OpenBlock, idx, endIdx);
|
||||||
break;
|
break;
|
||||||
case '/':
|
case '/':
|
||||||
@ -397,7 +397,7 @@ namespace crow
|
|||||||
idx++;
|
idx++;
|
||||||
while(body_[idx] == ' ') idx++;
|
while(body_[idx] == ' ') idx++;
|
||||||
while(body_[endIdx-1] == ' ') endIdx--;
|
while(body_[endIdx-1] == ' ') endIdx--;
|
||||||
blockPositions.emplace_back(actions_.size());
|
blockPositions.emplace_back(static_cast<int>(actions_.size()));
|
||||||
actions_.emplace_back(ActionType::ElseBlock, idx, endIdx);
|
actions_.emplace_back(ActionType::ElseBlock, idx, endIdx);
|
||||||
break;
|
break;
|
||||||
case '!':
|
case '!':
|
||||||
@ -481,7 +481,7 @@ namespace crow
|
|||||||
continue;
|
continue;
|
||||||
auto& fragment_before = fragments_[i];
|
auto& fragment_before = fragments_[i];
|
||||||
auto& fragment_after = fragments_[i+1];
|
auto& fragment_after = fragments_[i+1];
|
||||||
bool is_last_action = i == (int)actions_.size()-2;
|
bool is_last_action = i == static_cast<int>(actions_.size())-2;
|
||||||
bool all_space_before = true;
|
bool all_space_before = true;
|
||||||
int j, k;
|
int j, k;
|
||||||
for(j = fragment_before.second-1;j >= fragment_before.first;j--)
|
for(j = fragment_before.second-1;j >= fragment_before.first;j--)
|
||||||
@ -497,7 +497,7 @@ namespace crow
|
|||||||
if (!all_space_before && body_[j] != '\n')
|
if (!all_space_before && body_[j] != '\n')
|
||||||
continue;
|
continue;
|
||||||
bool all_space_after = true;
|
bool all_space_after = true;
|
||||||
for(k = fragment_after.first; k < (int)body_.size() && k < fragment_after.second; k ++)
|
for(k = fragment_after.first; k < static_cast<int>(body_.size()) && k < fragment_after.second; k ++)
|
||||||
{
|
{
|
||||||
if (body_[k] != ' ')
|
if (body_[k] != ' ')
|
||||||
{
|
{
|
||||||
@ -512,7 +512,7 @@ namespace crow
|
|||||||
body_[k] == '\n'
|
body_[k] == '\n'
|
||||||
||
|
||
|
||||||
(body_[k] == '\r' &&
|
(body_[k] == '\r' &&
|
||||||
k + 1 < (int)body_.size() &&
|
k + 1 < static_cast<int>(body_.size()) &&
|
||||||
body_[k+1] == '\n')))
|
body_[k+1] == '\n')))
|
||||||
continue;
|
continue;
|
||||||
if (actions_[i].t == ActionType::Partial)
|
if (actions_[i].t == ActionType::Partial)
|
||||||
|
@ -145,7 +145,7 @@ namespace crow
|
|||||||
/// Take the parsed HTTP request data and convert it to a \ref crow.request
|
/// Take the parsed HTTP request data and convert it to a \ref crow.request
|
||||||
request to_request() const
|
request to_request() const
|
||||||
{
|
{
|
||||||
return request{(HTTPMethod)method, std::move(raw_url), std::move(url), std::move(url_params), std::move(headers), std::move(body)};
|
return request{static_cast<HTTPMethod>(method), std::move(raw_url), std::move(url), std::move(url_params), std::move(headers), std::move(body)};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_upgrade() const
|
bool is_upgrade() const
|
||||||
|
@ -55,8 +55,8 @@ inline int qs_strncmp(const char * s, const char * qs, size_t n)
|
|||||||
|
|
||||||
while(n-- > 0)
|
while(n-- > 0)
|
||||||
{
|
{
|
||||||
u1 = (unsigned char) *s++;
|
u1 = static_cast<unsigned char>(*s++);
|
||||||
u2 = (unsigned char) *qs++;
|
u2 = static_cast<unsigned char>(*qs++);
|
||||||
|
|
||||||
if ( ! CROW_QS_ISQSCHR(u1) ) { u1 = '\0'; }
|
if ( ! CROW_QS_ISQSCHR(u1) ) { u1 = '\0'; }
|
||||||
if ( ! CROW_QS_ISQSCHR(u2) ) { u2 = '\0'; }
|
if ( ! CROW_QS_ISQSCHR(u2) ) { u2 = '\0'; }
|
||||||
@ -64,8 +64,8 @@ inline int qs_strncmp(const char * s, const char * qs, size_t n)
|
|||||||
if ( u1 == '+' ) { u1 = ' '; }
|
if ( u1 == '+' ) { u1 = ' '; }
|
||||||
if ( u1 == '%' ) // easier/safer than scanf
|
if ( u1 == '%' ) // easier/safer than scanf
|
||||||
{
|
{
|
||||||
unyb = (unsigned char) *s++;
|
unyb = static_cast<unsigned char>(*s++);
|
||||||
lnyb = (unsigned char) *s++;
|
lnyb = static_cast<unsigned char>(*s++);
|
||||||
if ( CROW_QS_ISHEX(unyb) && CROW_QS_ISHEX(lnyb) )
|
if ( CROW_QS_ISHEX(unyb) && CROW_QS_ISHEX(lnyb) )
|
||||||
u1 = (CROW_QS_HEX2DEC(unyb) * 16) + CROW_QS_HEX2DEC(lnyb);
|
u1 = (CROW_QS_HEX2DEC(unyb) * 16) + CROW_QS_HEX2DEC(lnyb);
|
||||||
else
|
else
|
||||||
@ -75,8 +75,8 @@ inline int qs_strncmp(const char * s, const char * qs, size_t n)
|
|||||||
if ( u2 == '+' ) { u2 = ' '; }
|
if ( u2 == '+' ) { u2 = ' '; }
|
||||||
if ( u2 == '%' ) // easier/safer than scanf
|
if ( u2 == '%' ) // easier/safer than scanf
|
||||||
{
|
{
|
||||||
unyb = (unsigned char) *qs++;
|
unyb = static_cast<unsigned char>(*qs++);
|
||||||
lnyb = (unsigned char) *qs++;
|
lnyb = static_cast<unsigned char>(*qs++);
|
||||||
if ( CROW_QS_ISHEX(unyb) && CROW_QS_ISHEX(lnyb) )
|
if ( CROW_QS_ISHEX(unyb) && CROW_QS_ISHEX(lnyb) )
|
||||||
u2 = (CROW_QS_HEX2DEC(unyb) * 16) + CROW_QS_HEX2DEC(lnyb);
|
u2 = (CROW_QS_HEX2DEC(unyb) * 16) + CROW_QS_HEX2DEC(lnyb);
|
||||||
else
|
else
|
||||||
|
@ -63,7 +63,7 @@ namespace crow
|
|||||||
template <typename F>
|
template <typename F>
|
||||||
void foreach_method(F f)
|
void foreach_method(F f)
|
||||||
{
|
{
|
||||||
for(uint32_t method = 0, method_bit = 1; method < (uint32_t)HTTPMethod::InternalMethodCount; method++, method_bit<<=1)
|
for(uint32_t method = 0, method_bit = 1; method < static_cast<uint32_t>(HTTPMethod::InternalMethodCount); method++, method_bit<<=1)
|
||||||
{
|
{
|
||||||
if (methods_ & method_bit)
|
if (methods_ & method_bit)
|
||||||
f(method);
|
f(method);
|
||||||
@ -73,7 +73,7 @@ namespace crow
|
|||||||
const std::string& rule() { return rule_; }
|
const std::string& rule() { return rule_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t methods_{1<<(int)HTTPMethod::Get};
|
uint32_t methods_{1<<static_cast<int>(HTTPMethod::Get)};
|
||||||
|
|
||||||
std::string rule_;
|
std::string rule_;
|
||||||
std::string name_;
|
std::string name_;
|
||||||
@ -357,29 +357,29 @@ namespace crow
|
|||||||
using self_t = T;
|
using self_t = T;
|
||||||
WebSocketRule& websocket()
|
WebSocketRule& websocket()
|
||||||
{
|
{
|
||||||
auto p =new WebSocketRule(((self_t*)this)->rule_);
|
auto p =new WebSocketRule(static_cast<self_t*>(this)->rule_);
|
||||||
((self_t*)this)->rule_to_upgrade_.reset(p);
|
static_cast<self_t*>(this)->rule_to_upgrade_.reset(p);
|
||||||
return *p;
|
return *p;
|
||||||
}
|
}
|
||||||
|
|
||||||
self_t& name(std::string name) noexcept
|
self_t& name(std::string name) noexcept
|
||||||
{
|
{
|
||||||
((self_t*)this)->name_ = std::move(name);
|
static_cast<self_t*>(this)->name_ = std::move(name);
|
||||||
return (self_t&)*this;
|
return static_cast<self_t&>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
self_t& methods(HTTPMethod method)
|
self_t& methods(HTTPMethod method)
|
||||||
{
|
{
|
||||||
((self_t*)this)->methods_ = 1 << (int)method;
|
static_cast<self_t*>(this)->methods_ = 1 << static_cast<int>(method);
|
||||||
return (self_t&)*this;
|
return static_cast<self_t&>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ... MethodArgs>
|
template <typename ... MethodArgs>
|
||||||
self_t& methods(HTTPMethod method, MethodArgs ... args_method)
|
self_t& methods(HTTPMethod method, MethodArgs ... args_method)
|
||||||
{
|
{
|
||||||
methods(args_method...);
|
methods(args_method...);
|
||||||
((self_t*)this)->methods_ |= 1 << (int)method;
|
static_cast<self_t*>(this)->methods_ |= 1 << static_cast<int>(method);
|
||||||
return (self_t&)*this;
|
return static_cast<self_t&>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -606,7 +606,7 @@ namespace crow
|
|||||||
struct Node
|
struct Node
|
||||||
{
|
{
|
||||||
unsigned rule_index{};
|
unsigned rule_index{};
|
||||||
std::array<unsigned, (int)ParamType::MAX> param_childrens{};
|
std::array<unsigned, static_cast<int>(ParamType::MAX)> param_childrens{};
|
||||||
std::unordered_map<std::string, unsigned> children;
|
std::unordered_map<std::string, unsigned> children;
|
||||||
|
|
||||||
bool IsSimpleNode() const
|
bool IsSimpleNode() const
|
||||||
@ -706,7 +706,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (node->param_childrens[(int)ParamType::INT])
|
if (node->param_childrens[static_cast<int>(ParamType::INT)])
|
||||||
{
|
{
|
||||||
char c = req_url[pos];
|
char c = req_url[pos];
|
||||||
if ((c >= '0' && c <= '9') || c == '+' || c == '-')
|
if ((c >= '0' && c <= '9') || c == '+' || c == '-')
|
||||||
@ -717,14 +717,14 @@ public:
|
|||||||
if (errno != ERANGE && eptr != req_url.data()+pos)
|
if (errno != ERANGE && eptr != req_url.data()+pos)
|
||||||
{
|
{
|
||||||
params->int_params.push_back(value);
|
params->int_params.push_back(value);
|
||||||
auto ret = find(req_url, &nodes_[node->param_childrens[(int)ParamType::INT]], eptr - req_url.data(), params);
|
auto ret = find(req_url, &nodes_[node->param_childrens[static_cast<int>(ParamType::INT)]], eptr - req_url.data(), params);
|
||||||
update_found(ret);
|
update_found(ret);
|
||||||
params->int_params.pop_back();
|
params->int_params.pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->param_childrens[(int)ParamType::UINT])
|
if (node->param_childrens[static_cast<int>(ParamType::UINT)])
|
||||||
{
|
{
|
||||||
char c = req_url[pos];
|
char c = req_url[pos];
|
||||||
if ((c >= '0' && c <= '9') || c == '+')
|
if ((c >= '0' && c <= '9') || c == '+')
|
||||||
@ -735,14 +735,14 @@ public:
|
|||||||
if (errno != ERANGE && eptr != req_url.data()+pos)
|
if (errno != ERANGE && eptr != req_url.data()+pos)
|
||||||
{
|
{
|
||||||
params->uint_params.push_back(value);
|
params->uint_params.push_back(value);
|
||||||
auto ret = find(req_url, &nodes_[node->param_childrens[(int)ParamType::UINT]], eptr - req_url.data(), params);
|
auto ret = find(req_url, &nodes_[node->param_childrens[static_cast<int>(ParamType::UINT)]], eptr - req_url.data(), params);
|
||||||
update_found(ret);
|
update_found(ret);
|
||||||
params->uint_params.pop_back();
|
params->uint_params.pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->param_childrens[(int)ParamType::DOUBLE])
|
if (node->param_childrens[static_cast<int>(ParamType::DOUBLE)])
|
||||||
{
|
{
|
||||||
char c = req_url[pos];
|
char c = req_url[pos];
|
||||||
if ((c >= '0' && c <= '9') || c == '+' || c == '-' || c == '.')
|
if ((c >= '0' && c <= '9') || c == '+' || c == '-' || c == '.')
|
||||||
@ -753,14 +753,14 @@ public:
|
|||||||
if (errno != ERANGE && eptr != req_url.data()+pos)
|
if (errno != ERANGE && eptr != req_url.data()+pos)
|
||||||
{
|
{
|
||||||
params->double_params.push_back(value);
|
params->double_params.push_back(value);
|
||||||
auto ret = find(req_url, &nodes_[node->param_childrens[(int)ParamType::DOUBLE]], eptr - req_url.data(), params);
|
auto ret = find(req_url, &nodes_[node->param_childrens[static_cast<int>(ParamType::DOUBLE)]], eptr - req_url.data(), params);
|
||||||
update_found(ret);
|
update_found(ret);
|
||||||
params->double_params.pop_back();
|
params->double_params.pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->param_childrens[(int)ParamType::STRING])
|
if (node->param_childrens[static_cast<int>(ParamType::STRING)])
|
||||||
{
|
{
|
||||||
size_t epos = pos;
|
size_t epos = pos;
|
||||||
for(; epos < req_url.size(); epos ++)
|
for(; epos < req_url.size(); epos ++)
|
||||||
@ -772,20 +772,20 @@ public:
|
|||||||
if (epos != pos)
|
if (epos != pos)
|
||||||
{
|
{
|
||||||
params->string_params.push_back(req_url.substr(pos, epos-pos));
|
params->string_params.push_back(req_url.substr(pos, epos-pos));
|
||||||
auto ret = find(req_url, &nodes_[node->param_childrens[(int)ParamType::STRING]], epos, params);
|
auto ret = find(req_url, &nodes_[node->param_childrens[static_cast<int>(ParamType::STRING)]], epos, params);
|
||||||
update_found(ret);
|
update_found(ret);
|
||||||
params->string_params.pop_back();
|
params->string_params.pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->param_childrens[(int)ParamType::PATH])
|
if (node->param_childrens[static_cast<int>(ParamType::PATH)])
|
||||||
{
|
{
|
||||||
size_t epos = req_url.size();
|
size_t epos = req_url.size();
|
||||||
|
|
||||||
if (epos != pos)
|
if (epos != pos)
|
||||||
{
|
{
|
||||||
params->string_params.push_back(req_url.substr(pos, epos-pos));
|
params->string_params.push_back(req_url.substr(pos, epos-pos));
|
||||||
auto ret = find(req_url, &nodes_[node->param_childrens[(int)ParamType::PATH]], epos, params);
|
auto ret = find(req_url, &nodes_[node->param_childrens[static_cast<int>(ParamType::PATH)]], epos, params);
|
||||||
update_found(ret);
|
update_found(ret);
|
||||||
params->string_params.pop_back();
|
params->string_params.pop_back();
|
||||||
}
|
}
|
||||||
@ -834,12 +834,12 @@ public:
|
|||||||
{
|
{
|
||||||
if (url.compare(i, x.name.size(), x.name) == 0)
|
if (url.compare(i, x.name.size(), x.name) == 0)
|
||||||
{
|
{
|
||||||
if (!nodes_[idx].param_childrens[(int)x.type])
|
if (!nodes_[idx].param_childrens[static_cast<int>(x.type)])
|
||||||
{
|
{
|
||||||
auto new_node_idx = new_node();
|
auto new_node_idx = new_node();
|
||||||
nodes_[idx].param_childrens[(int)x.type] = new_node_idx;
|
nodes_[idx].param_childrens[static_cast<int>(x.type)] = new_node_idx;
|
||||||
}
|
}
|
||||||
idx = nodes_[idx].param_childrens[(int)x.type];
|
idx = nodes_[idx].param_childrens[static_cast<int>(x.type)];
|
||||||
i += x.name.size();
|
i += x.name.size();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -865,12 +865,12 @@ public:
|
|||||||
private:
|
private:
|
||||||
void debug_node_print(Node* n, int level)
|
void debug_node_print(Node* n, int level)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < (int)ParamType::MAX; i ++)
|
for(int i = 0; i < static_cast<int>(ParamType::MAX); i ++)
|
||||||
{
|
{
|
||||||
if (n->param_childrens[i])
|
if (n->param_childrens[i])
|
||||||
{
|
{
|
||||||
CROW_LOG_DEBUG << std::string(2*level, ' ') /*<< "("<<n->param_childrens[i]<<") "*/;
|
CROW_LOG_DEBUG << std::string(2*level, ' ') /*<< "("<<n->param_childrens[i]<<") "*/;
|
||||||
switch((ParamType)i)
|
switch(static_cast<ParamType>(i))
|
||||||
{
|
{
|
||||||
case ParamType::INT:
|
case ParamType::INT:
|
||||||
CROW_LOG_DEBUG << "<int>";
|
CROW_LOG_DEBUG << "<int>";
|
||||||
@ -1006,7 +1006,7 @@ public:
|
|||||||
if (req.method >= HTTPMethod::InternalMethodCount)
|
if (req.method >= HTTPMethod::InternalMethodCount)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto& per_method = per_methods_[(int)req.method];
|
auto& per_method = per_methods_[static_cast<int>(req.method)];
|
||||||
auto& rules = per_method.rules;
|
auto& rules = per_method.rules;
|
||||||
unsigned rule_index = per_method.trie.find(req.url).first;
|
unsigned rule_index = per_method.trie.find(req.url).first;
|
||||||
|
|
||||||
@ -1050,7 +1050,7 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CROW_LOG_DEBUG << "Matched rule (upgrade) '" << rules[rule_index]->rule_ << "' " << (uint32_t)req.method << " / " << rules[rule_index]->get_methods();
|
CROW_LOG_DEBUG << "Matched rule (upgrade) '" << rules[rule_index]->rule_ << "' " << static_cast<uint32_t>(req.method) << " / " << rules[rule_index]->get_methods();
|
||||||
|
|
||||||
// any uncaught exceptions become 500s
|
// any uncaught exceptions become 500s
|
||||||
try
|
try
|
||||||
@ -1077,7 +1077,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (req.method >= HTTPMethod::InternalMethodCount)
|
if (req.method >= HTTPMethod::InternalMethodCount)
|
||||||
return;
|
return;
|
||||||
auto& per_method = per_methods_[(int)req.method];
|
auto& per_method = per_methods_[static_cast<int>(req.method)];
|
||||||
auto& trie = per_method.trie;
|
auto& trie = per_method.trie;
|
||||||
auto& rules = per_method.rules;
|
auto& rules = per_method.rules;
|
||||||
|
|
||||||
@ -1125,7 +1125,7 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CROW_LOG_DEBUG << "Matched rule '" << rules[rule_index]->rule_ << "' " << (uint32_t)req.method << " / " << rules[rule_index]->get_methods();
|
CROW_LOG_DEBUG << "Matched rule '" << rules[rule_index]->rule_ << "' " << static_cast<uint32_t>(req.method) << " / " << rules[rule_index]->get_methods();
|
||||||
|
|
||||||
// any uncaught exceptions become 500s
|
// any uncaught exceptions become 500s
|
||||||
try
|
try
|
||||||
@ -1150,9 +1150,9 @@ public:
|
|||||||
|
|
||||||
void debug_print()
|
void debug_print()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < (int)HTTPMethod::InternalMethodCount; i ++)
|
for(int i = 0; i < static_cast<int>(HTTPMethod::InternalMethodCount); i ++)
|
||||||
{
|
{
|
||||||
CROW_LOG_DEBUG << method_name((HTTPMethod)i);
|
CROW_LOG_DEBUG << method_name(static_cast<HTTPMethod>(i));
|
||||||
per_methods_[i].trie.debug_print();
|
per_methods_[i].trie.debug_print();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1166,7 +1166,7 @@ public:
|
|||||||
// rule index 0, 1 has special meaning; preallocate it to avoid duplication.
|
// rule index 0, 1 has special meaning; preallocate it to avoid duplication.
|
||||||
PerMethod() : rules(2) {}
|
PerMethod() : rules(2) {}
|
||||||
};
|
};
|
||||||
std::array<PerMethod, (int)HTTPMethod::InternalMethodCount> per_methods_;
|
std::array<PerMethod, static_cast<int>(HTTPMethod::InternalMethodCount)> per_methods_;
|
||||||
std::vector<std::unique_ptr<BaseRule>> all_rules_;
|
std::vector<std::unique_ptr<BaseRule>> all_rules_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -510,29 +510,29 @@ template <typename F, typename Set>
|
|||||||
auto it = ret.begin();
|
auto it = ret.begin();
|
||||||
while(size >= 3)
|
while(size >= 3)
|
||||||
{
|
{
|
||||||
*it++ = key[(((unsigned char)*data)&0xFC)>>2];
|
*it++ = key[(static_cast<unsigned char>(*data)&0xFC)>>2];
|
||||||
unsigned char h = (((unsigned char)*data++) & 0x03) << 4;
|
unsigned char h = (static_cast<unsigned char>(*data++) & 0x03) << 4;
|
||||||
*it++ = key[h|((((unsigned char)*data)&0xF0)>>4)];
|
*it++ = key[h|((static_cast<unsigned char>(*data)&0xF0)>>4)];
|
||||||
h = (((unsigned char)*data++) & 0x0F) << 2;
|
h = (static_cast<unsigned char>(*data++) & 0x0F) << 2;
|
||||||
*it++ = key[h|((((unsigned char)*data)&0xC0)>>6)];
|
*it++ = key[h|((static_cast<unsigned char>(*data)&0xC0)>>6)];
|
||||||
*it++ = key[((unsigned char)*data++)&0x3F];
|
*it++ = key[static_cast<unsigned char>(*data++)&0x3F];
|
||||||
|
|
||||||
size -= 3;
|
size -= 3;
|
||||||
}
|
}
|
||||||
if (size == 1)
|
if (size == 1)
|
||||||
{
|
{
|
||||||
*it++ = key[(((unsigned char)*data)&0xFC)>>2];
|
*it++ = key[(static_cast<unsigned char>(*data)&0xFC)>>2];
|
||||||
unsigned char h = (((unsigned char)*data++) & 0x03) << 4;
|
unsigned char h = (static_cast<unsigned char>(*data++) & 0x03) << 4;
|
||||||
*it++ = key[h];
|
*it++ = key[h];
|
||||||
*it++ = '=';
|
*it++ = '=';
|
||||||
*it++ = '=';
|
*it++ = '=';
|
||||||
}
|
}
|
||||||
else if (size == 2)
|
else if (size == 2)
|
||||||
{
|
{
|
||||||
*it++ = key[(((unsigned char)*data)&0xFC)>>2];
|
*it++ = key[(static_cast<unsigned char>(*data)&0xFC)>>2];
|
||||||
unsigned char h = (((unsigned char)*data++) & 0x03) << 4;
|
unsigned char h = (static_cast<unsigned char>(*data++) & 0x03) << 4;
|
||||||
*it++ = key[h|((((unsigned char)*data)&0xF0)>>4)];
|
*it++ = key[h|((static_cast<unsigned char>(*data)&0xF0)>>4)];
|
||||||
h = (((unsigned char)*data++) & 0x0F) << 2;
|
h = (static_cast<unsigned char>(*data++) & 0x0F) << 2;
|
||||||
*it++ = key[h];
|
*it++ = key[h];
|
||||||
*it++ = '=';
|
*it++ = '=';
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ namespace crow
|
|||||||
else if (size < 0x10000)
|
else if (size < 0x10000)
|
||||||
{
|
{
|
||||||
buf[1] += 126;
|
buf[1] += 126;
|
||||||
*(uint16_t*)(buf+2) = htons((uint16_t)size);
|
*(uint16_t*)(buf+2) = htons(static_cast<uint16_t>(size));
|
||||||
return {buf, buf+4};
|
return {buf, buf+4};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -344,7 +344,7 @@ namespace crow
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
is_reading = false;
|
is_reading = false;
|
||||||
remaining_length_ = ((1==ntohl(1)) ? (remaining_length_) : ((uint64_t)ntohl((remaining_length_) & 0xFFFFFFFF) << 32) | ntohl((remaining_length_) >> 32));
|
remaining_length_ = ((1==ntohl(1)) ? (remaining_length_) : (static_cast<uint64_t>(ntohl((remaining_length_) & 0xFFFFFFFF)) << 32) | ntohl((remaining_length_) >> 32));
|
||||||
#ifdef CROW_ENABLE_DEBUG
|
#ifdef CROW_ENABLE_DEBUG
|
||||||
if (!ec && bytes_transferred != 8)
|
if (!ec && bytes_transferred != 8)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user