From b77ba4c739d25768dc56b47a929d800266c3230b Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 28 Dec 2010 04:08:35 +0100 Subject: Added a shady url decoder for paths. --- http.cpp | 24 ++++++++++++++++++++++++ http.h | 1 + 2 files changed, 25 insertions(+) diff --git a/http.cpp b/http.cpp index dbe8145..46f8e40 100644 --- a/http.cpp +++ b/http.cpp @@ -15,6 +15,7 @@ HTTPRequest::HTTPRequest(std::istream& is) { type = splitvec[0]; path = splitvec[1]; + url_decode(path); httpver = splitvec[2]; std::cout << boost::format("%s %s %s\n") % type % path % httpver; @@ -29,6 +30,29 @@ HTTPRequest::HTTPRequest(std::istream& is) { } } +void HTTPRequest::url_decode(std::string& str) { + std::string::const_iterator start, end, prev; + start = str.begin(); + end = str.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + boost::regex re("%([0-9a-fA-F]{2})"); + prev = start; + std::string out; + while(boost::regex_search(start, end, what, re, flags)) { + std::istringstream hs(what[1]); + char c; + int hi; + hs >> std::hex >> hi; + c = hi; + out += std::string(prev, what[1].first - 1) + c; + start = what[1].second; + prev = start; + } + out += std::string(prev, end); + str = out; +} + HTTPResponse::HTTPResponse(boost::asio::ip::tcp::socket& socket_) : socket(socket_){ httpver = "1.1"; headers_written = false; diff --git a/http.h b/http.h index 3ab66dc..ef6e43c 100644 --- a/http.h +++ b/http.h @@ -14,6 +14,7 @@ class HTTPRequest { std::string type, path, httpver; HTTPHeaders headers; HTTPRequest(std::istream& is); + static void url_decode(std::string& str); }; class HTTPResponse { -- cgit v1.2.3