From: Aki Tuomi Date: Wed, 25 Jun 2014 20:31:40 +0000 (+0300) Subject: Update YaHTTP from upstream (fixes several bugs) X-Git-Tag: auth-3.4.0-rc1~114^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F1490%2Fhead;p=thirdparty%2Fpdns.git Update YaHTTP from upstream (fixes several bugs) --- diff --git a/pdns/ext/yahttp/yahttp/cookie.hpp b/pdns/ext/yahttp/yahttp/cookie.hpp index 10070d1d5d..4b285aa760 100644 --- a/pdns/ext/yahttp/yahttp/cookie.hpp +++ b/pdns/ext/yahttp/yahttp/cookie.hpp @@ -43,14 +43,15 @@ namespace YaHTTP { }; //!< Stringify the cookie }; + /*! Implements a Cookie jar for storing multiple cookies */ class CookieJar { public: - std::map cookies; + std::map cookies; //cookies = rhs.cookies; - } + } // cookies; @@ -129,6 +130,6 @@ namespace YaHTTP { for(std::list::iterator i = cookies.begin(); i != cookies.end(); i++) { this->cookies[i->name] = *i; } - }; + }; // namespace YaHTTP { + /*! Generic error class */ class Error: public std::exception { public: Error() {}; @@ -14,8 +15,9 @@ namespace YaHTTP { { return reason.c_str(); } - const std::string reason; + const std::string reason; //first) << "=" << Utility::encodeURL(i->second) << "&"; + getparmbuf << Utility::encodeURL(i->first, false) << "=" << Utility::encodeURL(i->second, false) << "&"; } if (getparmbuf.str().length() > 0) getparms = "?" + std::string(getparmbuf.str().begin(), getparmbuf.str().end() - 1); diff --git a/pdns/ext/yahttp/yahttp/reqresp.hpp b/pdns/ext/yahttp/yahttp/reqresp.hpp index 91a83cb252..3c31e63138 100644 --- a/pdns/ext/yahttp/yahttp/reqresp.hpp +++ b/pdns/ext/yahttp/yahttp/reqresp.hpp @@ -30,17 +30,19 @@ namespace funcptr = boost; #define YAHTTP_TYPE_RESPONSE 2 namespace YaHTTP { - typedef std::map strstr_map_t; - typedef std::map strcookie_map_t; + typedef std::map strstr_map_t; // strcookie_map_t; //body; return doc->body.length(); - }; + }; //path = path; }; - size_t operator()(const HTTPBase *doc, std::ostream& os) const { + size_t operator()(const HTTPBase *doc __attribute__((unused)), std::ostream& os) const { char buf[4096]; size_t n,k; #ifdef HAVE_CXX11 @@ -73,12 +76,14 @@ namespace YaHTTP { } return n; - }; + }; // renderer; + funcptr::function renderer; //kind = YAHTTP_TYPE_RESPONSE; }; @@ -143,11 +155,12 @@ public: HTTPBase::operator=(rhs); this->kind = YAHTTP_TYPE_RESPONSE; return *this; - } + }; friend std::ostream& operator<<(std::ostream& os, const Response &resp); friend std::istream& operator>>(std::istream& is, Response &resp); }; + /* Request class, represents a HTTP Request document */ class Request: public HTTPBase { public: Request() { this->kind = YAHTTP_TYPE_REQUEST; }; @@ -158,7 +171,7 @@ public: HTTPBase::operator=(rhs); this->kind = YAHTTP_TYPE_REQUEST; return *this; - } + }; void setup(const std::string& method, const std::string& url) { this->url.parse(url); @@ -166,67 +179,70 @@ public: this->method = method; std::transform(this->method.begin(), this->method.end(), this->method.begin(), ::toupper); this->headers["user-agent"] = "YaHTTP v1.0"; - } + }; //first) << "=" << Utility::encodeURL(i->second) << "&"; + postbuf << Utility::encodeURL(i->first, false) << "=" << Utility::encodeURL(i->second, false) << "&"; } // remove last bit if (postbuf.str().length()>0) - body = std::string(postbuf.str().begin(), postbuf.str().end()-1); + body = postbuf.str().substr(0, postbuf.str().length()-1); else body = ""; headers["content-type"] = "application/x-www-form-urlencoded; charset=utf-8"; } else if (format == multipart) { headers["content-type"] = "multipart/form-data; boundary=YaHTTP-12ca543"; for(strstr_map_t::const_iterator i = POST().begin(); i != POST().end(); i++) { - postbuf << "--YaHTTP-12ca543\r\nContent-Disposition: form-data; name=\"" << Utility::encodeURL(i->first) << "; charset=UTF-8\r\n\r\n" - << Utility::encodeURL(i->second) << "\r\n"; + postbuf << "--YaHTTP-12ca543\r\nContent-Disposition: form-data; name=\"" << Utility::encodeURL(i->first, false) << "; charset=UTF-8\r\n\r\n" + << Utility::encodeURL(i->second, false) << "\r\n"; } } + postbuf.str(""); + postbuf << body.length(); // set method and change headers method = "POST"; - headers["content-length"] = body.length(); - }; + headers["content-length"] = postbuf.str(); + }; //>(std::istream& is, Request &resp); }; + /*! Asynchronous HTTP document loader */ template class AsyncLoader { public: - T* target; - int state; - size_t pos; + T* target; //target = target; hasBody = false; - }; - int feed(const std::string& somedata); + }; // 1 && (!hasBody || (bodybuf.str().size() <= maxbody && bodybuf.str().size() >= minbody) ); - }; + }; //target = NULL; - }; + }; // { }; + /*! Asynchronous HTTP request loader */ class AsyncRequestLoader: public AsyncLoader { }; diff --git a/pdns/ext/yahttp/yahttp/url.hpp b/pdns/ext/yahttp/yahttp/url.hpp index e649c59fb6..73b8d2342c 100644 --- a/pdns/ext/yahttp/yahttp/url.hpp +++ b/pdns/ext/yahttp/yahttp/url.hpp @@ -10,6 +10,7 @@ #endif namespace YaHTTP { + /*! URL parser and container */ class URL { private: bool parseSchema(const std::string& url, size_t &pos) { @@ -25,7 +26,7 @@ namespace YaHTTP { pos += 2; } return true; - } + }; //> port; + host = host.substr(0, pos1); + } return true; - } + }; //0 && *(parameters.end()-1) == '&') parameters.resize(parameters.size()-1); return true; - } + }; //= url.size()) return true; // no data if (url[pos] != '#') return false; // not anchor anchor = url.substr(pos+1); return true; - } + }; //tm_year + 1900; @@ -73,7 +74,7 @@ namespace YaHTTP { wday = tm->tm_wday; utc_offset = tm->tm_gmtoff; isSet = true; - }; + }; // 6) throw "Invalid date"; @@ -82,7 +83,7 @@ namespace YaHTTP { if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59 || seconds < 0 || seconds > 60) throw "Invalid date"; - } + }; //(&component[0]); @@ -207,9 +206,7 @@ namespace YaHTTP { } else result << (char)*iter; } return result.str(); - }; - - + }; // parseUrlParameters(std::string parameters) { std::string::size_type pos = 0; @@ -331,7 +328,7 @@ namespace YaHTTP { pos = nextpos+1; } return parameter_map; - }; + }; // Content-Type + }; }; #endif