Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions src/details/http_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ http_endpoint::~http_endpoint()
{
if(reg_compiled)
{
regfree(&(this->re_url_normalized));
regfree(&re_url_normalized);
}
}

Expand All @@ -50,7 +50,7 @@ http_endpoint::http_endpoint
family_url(family),
reg_compiled(false)
{
this->url_normalized = use_regex ? "^/" : "/";
url_normalized = use_regex ? "^/" : "/";
vector<string> parts;

#ifdef CASE_INSENSITIVE
Expand All @@ -77,10 +77,10 @@ http_endpoint::http_endpoint
{
if(!registration)
{
this->url_normalized += (first ? "" : "/") + parts[i];
url_normalized += (first ? "" : "/") + parts[i];
first = false;

this->url_pieces.push_back(parts[i]);
url_pieces.push_back(parts[i]);

continue;
}
Expand All @@ -89,14 +89,14 @@ http_endpoint::http_endpoint
{
if(first)
{
this->url_normalized = (parts[i][0] == '^' ? "" : this->url_normalized) + parts[i];
url_normalized = (parts[i][0] == '^' ? "" : url_normalized) + parts[i];
first = false;
}
else
{
this->url_normalized += "/" + parts[i];
url_normalized += "/" + parts[i];
}
this->url_pieces.push_back(parts[i]);
url_pieces.push_back(parts[i]);

continue;
}
Expand All @@ -105,23 +105,23 @@ http_endpoint::http_endpoint
throw std::invalid_argument("Bad URL format");

std::string::size_type bar = parts[i].find_first_of('|');
this->url_pars.push_back(parts[i].substr(1, bar != string::npos ? bar - 1 : parts[i].size() - 2));
this->url_normalized += (first ? "" : "/") + (bar != string::npos ? parts[i].substr(bar + 1, parts[i].size() - bar - 2) : "([^\\/]+)");
url_pars.push_back(parts[i].substr(1, bar != string::npos ? bar - 1 : parts[i].size() - 2));
url_normalized += (first ? "" : "/") + (bar != string::npos ? parts[i].substr(bar + 1, parts[i].size() - bar - 2) : "([^\\/]+)");

first = false;

this->chunk_positions.push_back(i);
chunk_positions.push_back(i);

this->url_pieces.push_back(parts[i]);
url_pieces.push_back(parts[i]);
}

if(use_regex)
{
this->url_normalized += "$";
regcomp(&(this->re_url_normalized), url_normalized.c_str(),
url_normalized += "$";
regcomp(&re_url_normalized, url_normalized.c_str(),
REG_EXTENDED|REG_ICASE|REG_NOSUB
);
this->reg_compiled = true;
reg_compiled = true;
}
}

Expand All @@ -134,52 +134,52 @@ http_endpoint::http_endpoint(const http_endpoint& h):
family_url(h.family_url),
reg_compiled(h.reg_compiled)
{
if(this->reg_compiled)
regcomp(&(this->re_url_normalized), url_normalized.c_str(),
if(reg_compiled)
regcomp(&re_url_normalized, url_normalized.c_str(),
REG_EXTENDED|REG_ICASE|REG_NOSUB
);
}

http_endpoint& http_endpoint::operator =(const http_endpoint& h)
{
this->url_complete = h.url_complete;
this->url_normalized = h.url_normalized;
this->family_url = h.family_url;
this->reg_compiled = h.reg_compiled;
if(this->reg_compiled)
url_complete = h.url_complete;
url_normalized = h.url_normalized;
family_url = h.family_url;
reg_compiled = h.reg_compiled;
if(reg_compiled)
{
regfree(&(this->re_url_normalized));
regfree(&re_url_normalized);

regcomp(&(this->re_url_normalized), url_normalized.c_str(),
regcomp(&re_url_normalized, url_normalized.c_str(),
REG_EXTENDED|REG_ICASE|REG_NOSUB
);
}
this->url_pars = h.url_pars;
this->url_pieces = h.url_pieces;
this->chunk_positions = h.chunk_positions;
url_pars = h.url_pars;
url_pieces = h.url_pieces;
chunk_positions = h.chunk_positions;
return *this;
}

bool http_endpoint::operator <(const http_endpoint& b) const
{
COMPARATOR(this->url_normalized, b.url_normalized, std::toupper);
COMPARATOR(url_normalized, b.url_normalized, std::toupper);
}

bool http_endpoint::match(const http_endpoint& url) const
{
if (!this->reg_compiled) throw std::invalid_argument("Cannot run match. Regex suppressed.");
if (!reg_compiled) throw std::invalid_argument("Cannot run match. Regex suppressed.");

if(!this->family_url || url.url_pieces.size() < this->url_pieces.size())
return regexec(&(this->re_url_normalized), url.url_complete.c_str(), 0, NULL, 0) == 0;
if(!family_url || url.url_pieces.size() < url_pieces.size())
return regexec(&re_url_normalized, url.url_complete.c_str(), 0, NULL, 0) == 0;

string nn = "/";
bool first = true;
for(unsigned int i = 0; i < this->url_pieces.size(); i++)
for(unsigned int i = 0; i < url_pieces.size(); i++)
{
nn += (first ? "" : "/") + url.url_pieces[i];
first = false;
}
return regexec(&(this->re_url_normalized), nn.c_str(), 0, NULL, 0) == 0;
return regexec(&re_url_normalized, nn.c_str(), 0, NULL, 0) == 0;
}

};
Expand Down
16 changes: 8 additions & 8 deletions src/http_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool http_request::check_digest_auth(
const std::string http_request::get_connection_value(const std::string& key, enum MHD_ValueKind kind) const
{
const char* header_c = MHD_lookup_connection_value(
this->underlying_connection,
underlying_connection,
kind,
key.c_str()
);
Expand All @@ -103,7 +103,7 @@ const std::map<std::string, std::string, http::header_comparator> http_request::
std::map<std::string, std::string, http::header_comparator> headers;

MHD_get_connection_values(
this->underlying_connection,
underlying_connection,
kind,
&build_request_header,
(void*) &headers
Expand Down Expand Up @@ -144,9 +144,9 @@ const std::map<std::string, std::string, http::header_comparator> http_request::

const std::string http_request::get_arg(const std::string& key) const
{
std::map<std::string, std::string>::const_iterator it = this->args.find(key);
std::map<std::string, std::string>::const_iterator it = args.find(key);

if(it != this->args.end())
if(it != args.end())
{
return it->second;
}
Expand All @@ -157,14 +157,14 @@ const std::string http_request::get_arg(const std::string& key) const
const std::map<std::string, std::string, http::arg_comparator> http_request::get_args() const
{
std::map<std::string, std::string, http::arg_comparator> arguments;
arguments.insert(this->args.begin(), this->args.end());
arguments.insert(args.begin(), args.end());

arguments_accumulator aa;
aa.unescaper = this->unescaper;
aa.unescaper = unescaper;
aa.arguments = &arguments;

MHD_get_connection_values(
this->underlying_connection,
underlying_connection,
MHD_GET_ARGUMENT_KIND,
&build_request_args,
(void*) &aa
Expand All @@ -178,7 +178,7 @@ const std::string http_request::get_querystring() const
std::string querystring = "";

MHD_get_connection_values(
this->underlying_connection,
underlying_connection,
MHD_GET_ARGUMENT_KIND,
&build_request_querystring,
(void*) &querystring
Expand Down
2 changes: 1 addition & 1 deletion src/http_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int http_response::enqueue_response(MHD_Connection* connection, MHD_Response* re

void http_response::shoutCAST()
{
this->response_code |= http::http_utils::shoutcast_response;
response_code |= http::http_utils::shoutcast_response;
}

std::ostream &operator<< (std::ostream &os, const http_response &r)
Expand Down
12 changes: 6 additions & 6 deletions src/http_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,26 +517,26 @@ bool ip_representation::operator <(const ip_representation& b) const
{
if (i == 10 || i == 11) continue;

if (CHECK_BIT(this->mask, i) && CHECK_BIT(b.mask, i))
if (CHECK_BIT(mask, i) && CHECK_BIT(b.mask, i))
{
this_score += (16 - i) * this->pieces[i];
this_score += (16 - i) * pieces[i];
b_score += (16 - i) * b.pieces[i];
}
}

if (this_score == b_score &&
((this->pieces[10] == 0x00 || this->pieces[10] == 0xFF) && (b.pieces[10] == 0x00 || b.pieces[10] == 0xFF)) &&
((this->pieces[11] == 0x00 || this->pieces[11] == 0xFF) && (b.pieces[11] == 0x00 || b.pieces[11] == 0xFF))
((pieces[10] == 0x00 || pieces[10] == 0xFF) && (b.pieces[10] == 0x00 || b.pieces[10] == 0xFF)) &&
((pieces[11] == 0x00 || pieces[11] == 0xFF) && (b.pieces[11] == 0x00 || b.pieces[11] == 0xFF))
)
{
return false;
}

for (int i = 10; i < 12; i++)
{
if (CHECK_BIT(this->mask, i) && CHECK_BIT(b.mask, i))
if (CHECK_BIT(mask, i) && CHECK_BIT(b.mask, i))
{
this_score += (16 - i) * this->pieces[i];
this_score += (16 - i) * pieces[i];
b_score += (16 - i) * b.pieces[i];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/httpserver/deferred_response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class deferred_response : public string_response

MHD_Response* get_raw_response()
{
return details::get_raw_response_helper((void*) this, &(this->cb));
return details::get_raw_response_helper((void*) this, &cb);
}

private:
Expand Down
14 changes: 7 additions & 7 deletions src/httpserver/details/http_endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ class http_endpoint
**/
const std::string& get_url_complete() const
{
return this->url_complete;
return url_complete;
}

const std::string& get_url_normalized() const
{
return this->url_normalized;
return url_normalized;
}

/**
Expand All @@ -99,7 +99,7 @@ class http_endpoint
**/
const std::vector<std::string>& get_url_pars() const
{
return this->url_pars;
return url_pars;
}

/**
Expand All @@ -108,7 +108,7 @@ class http_endpoint
**/
const std::vector<std::string>& get_url_pieces() const
{
return this->url_pieces;
return url_pieces;
}

/**
Expand All @@ -117,17 +117,17 @@ class http_endpoint
**/
const std::vector<int>& get_chunk_positions() const
{
return this->chunk_positions;
return chunk_positions;
}

const bool is_family_url() const
{
return this->family_url;
return family_url;
}

const bool is_regex_compiled() const
{
return this->reg_compiled;
return reg_compiled;
}

/**
Expand Down
17 changes: 8 additions & 9 deletions src/httpserver/http_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class http_request
**/
const std::string& get_path() const
{
return this->path;
return path;
}

/**
Expand All @@ -85,7 +85,7 @@ class http_request
**/
const std::vector<std::string> get_path_pieces() const
{
return http::http_utils::tokenize_url(this->path);
return http::http_utils::tokenize_url(path);
}

/**
Expand All @@ -95,7 +95,7 @@ class http_request
**/
const std::string get_path_piece(int index) const
{
std::vector<std::string> post_path = this->get_path_pieces();
std::vector<std::string> post_path = get_path_pieces();
if(((int)(post_path.size())) > index)
return post_path[index];
return EMPTY;
Expand All @@ -107,7 +107,7 @@ class http_request
**/
const std::string& get_method() const
{
return this->method;
return method;
}

/**
Expand Down Expand Up @@ -167,7 +167,7 @@ class http_request
**/
const std::string& get_content() const
{
return this->content;
return content;
}

/**
Expand All @@ -190,7 +190,7 @@ class http_request
**/
const std::string& get_version() const
{
return this->version;
return version;
}

/**
Expand Down Expand Up @@ -264,7 +264,7 @@ class http_request
**/
void set_arg(const std::string& key, const std::string& value)
{
this->args[key] = value.substr(0,content_size_limit);
args[key] = value.substr(0,content_size_limit);
}

/**
Expand All @@ -275,8 +275,7 @@ class http_request
**/
void set_arg(const char* key, const char* value, size_t size)
{
this->args[key] = std::string(value,
std::min(size, content_size_limit));
args[key] = std::string(value, std::min(size, content_size_limit));
}

/**
Expand Down
Loading