Made a function for parameter parsing

This commit is contained in:
tastytea 2018-11-26 04:17:34 +01:00
parent c0c31f5093
commit b8ca3f6d13
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 24 additions and 6 deletions

View File

@ -41,17 +41,34 @@ const Request http::parse_request(const string &request)
if (pos_digest != std::string::npos)
{
digest = digest.substr(0, pos_digest);
std::size_t pos_size = request.find("s=", pos_digest);
if (pos_size != std::string::npos)
string answer;
answer = get_parameter(request, "s");
if (!answer.empty())
{
size = static_cast<uint16_t>(std::stoul(request.substr(pos_size + 2)));
size = static_cast<uint16_t>(std::stoul(answer));
}
pos_size = request.find("size=", pos_digest);
if (pos_size != std::string::npos)
else
{
size = static_cast<uint16_t>(std::stoul(request.substr(pos_size + 5)));
answer = get_parameter(request, "size");
if (!answer.empty())
{
size = static_cast<uint16_t>(std::stoul(answer));
}
}
}
return { digest, size };
}
const string http::get_parameter(const string &request, const string &parameter)
{
std::size_t pos = request.find(parameter + "=");
if (pos != std::string::npos)
{
pos += parameter.length();
return request.substr(pos, request.find('&', pos));
}
return "";
}

View File

@ -52,6 +52,7 @@ namespace http // http.cpp
};
const Request parse_request(const string &request);
const string get_parameter(const string &request, const string &parameter);
}
namespace hash // hash.cpp