Permalink
Browse files

Merge pull request #1465 from zeha/update-yahttp

Update yahttp
  • Loading branch information...
2 parents 8be531f + 583ea80 commit 0897e94e84e76110380fa329f136564e3336a114 @Habbie Habbie committed Jun 24, 2014
View
@@ -320,6 +320,8 @@ AC_CONFIG_FILES([
pdns/Makefile
codedocs/Makefile
pdns/pdns
+ pdns/ext/yahttp/Makefile
+ pdns/ext/yahttp/yahttp/Makefile
modules/bindbackend/Makefile
modules/db2backend/Makefile
modules/geobackend/Makefile
View
@@ -23,7 +23,7 @@ rec_channel.o rec_channel_rec.o selectmplexer.o sillyrecords.o \
dns_random.o ext/polarssl-1.3.2/library/aes.o ext/polarssl-1.3.2/library/padlock.o dnslabeltext.o \
lua-pdns.o lua-recursor.o randomhelper.o recpacketcache.o dns.o \
reczones.o base32.o nsecrecords.o json.o ws-recursor.o ws-api.o \
-version.o responsestats.o webserver.o ext/yahttp/yahttp/reqresp.o \
+version.o responsestats.o webserver.o ext/yahttp/yahttp/reqresp.o ext/yahttp/yahttp/router.o \
rec-carbon.o
REC_CONTROL_OBJECTS=rec_channel.o rec_control.o arguments.o misc.o \
@@ -1,2 +1,4 @@
yahttp/libyahttp.a
*.o
+Makefile
+Makefile.in
View
@@ -1,22 +0,0 @@
-.SILENT:
-
-all:
- $(MAKE) -C yahttp all
-
-install:
-
-uninstall:
-
-distclean: clean
-
-clean:
- $(MAKE) -C yahttp clean
-
-check:
-
-distdir:
- mkdir -p $(distdir)
- cp LICENSE Makefile $(distdir)
- mkdir $(distdir)/yahttp
- cp yahttp/Makefile yahttp/*.cpp yahttp/*.hpp $(distdir)/yahttp
-
@@ -0,0 +1 @@
+SUBDIRS=yahttp
@@ -1,14 +0,0 @@
-
-all: libyahttp.a
-
-
-clean:
- -rm -f *.o *.a
-
-
-reqresp.o: *.cpp *.hpp
-
-
-libyahttp.a: reqresp.o
- echo AR $@
- $(AR) rcs $@ $<
@@ -0,0 +1,3 @@
+noinst_LTLIBRARIES=libyahttp.la
+
+libyahttp_la_SOURCES=cookie.hpp exception.hpp reqresp.cpp reqresp.hpp router.cpp router.hpp url.hpp utility.hpp yahttp-config.h yahttp.hpp
@@ -0,0 +1,134 @@
+namespace YaHTTP {
+ /*! Implements a single cookie */
+ class Cookie {
+ public:
+ Cookie() {
+ secure = false;
+ httponly = false;
+ name = value = "";
+ }; //!< Set the cookie to empty value
+
+ Cookie(const Cookie &rhs) {
+ domain = rhs.domain;
+ path = rhs.path;
+ secure = rhs.secure;
+ httponly = rhs.httponly;
+ name = rhs.name;
+ value = rhs.value;
+ }; //<! Copy cookie values
+
+ DateTime expires; /*!< Expiration date */
+ std::string domain; /*!< Domain where cookie is valid */
+ std::string path; /*!< Path where the cookie is valid */
+ bool httponly; /*!< Whether the cookie is for server use only */
+ bool secure; /*!< Whether the cookie is for HTTPS only */
+
+ std::string name; /*!< Cookie name */
+ std::string value; /*!< Cookie value */
+
+ std::string str() const {
+ std::ostringstream oss;
+ oss << YaHTTP::Utility::encodeURL(name) << "=" << YaHTTP::Utility::encodeURL(value);
+ if (expires.isSet)
+ oss << "; expires=" << expires.cookie_str();
+ if (domain.size()>0)
+ oss << "; domain=" << domain;
+ if (path.size()>0)
+ oss << "; path=" << path;
+ if (secure)
+ oss << "; secure";
+ if (httponly)
+ oss << "; httpOnly";
+ return oss.str();
+ }; //!< Stringify the cookie
+ };
+
+ class CookieJar {
+ public:
+ std::map<std::string, Cookie> cookies;
+
+ CookieJar() {};
+ CookieJar(const CookieJar & rhs) {
+ this->cookies = rhs.cookies;
+ }
+
+ void keyValuePair(const std::string &keyvalue, std::string &key, std::string &value) {
+ size_t pos;
+ pos = keyvalue.find("=");
+ if (pos == std::string::npos) throw "Not a Key-Value pair (cookie)";
+ key = std::string(keyvalue.begin(), keyvalue.begin()+pos);
+ value = std::string(keyvalue.begin()+pos+1, keyvalue.end());
+ }
+
+ void parseCookieHeader(const std::string &cookiestr) {
+ std::list<Cookie> cookies;
+ int cstate = 0; //cookiestate
+ size_t pos,npos;
+ pos = 0;
+ cstate = 0;
+ while(pos < cookiestr.size()) {
+ if (cookiestr.compare(pos, 7, "expires") ==0 ||
+ cookiestr.compare(pos, 6, "domain") ==0 ||
+ cookiestr.compare(pos, 4, "path") ==0) {
+ cstate = 1;
+ // get the date
+ std::string key, value, s;
+ npos = cookiestr.find("; ", pos);
+ if (npos == std::string::npos) {
+ // last value
+ s = std::string(cookiestr.begin() + pos + 1, cookiestr.end());
+ pos = cookiestr.size();
+ } else {
+ s = std::string(cookiestr.begin() + pos + 1, cookiestr.begin() + npos - 1);
+ pos = npos+2;
+ }
+ keyValuePair(s, key, value);
+ if (s == "expires") {
+ DateTime dt;
+ dt.parseCookie(value);
+ for(std::list<Cookie>::iterator i = cookies.begin(); i != cookies.end(); i++)
+ i->expires = dt;
+ } else if (s == "domain") {
+ for(std::list<Cookie>::iterator i = cookies.begin(); i != cookies.end(); i++)
+ i->domain = value;
+ } else if (s == "path") {
+ for(std::list<Cookie>::iterator i = cookies.begin(); i != cookies.end(); i++)
+ i->path = value;
+ }
+ } else if (cookiestr.compare(pos, 8, "httpOnly")==0) {
+ cstate = 1;
+ for(std::list<Cookie>::iterator i = cookies.begin(); i != cookies.end(); i++)
+ i->httponly = true;
+ } else if (cookiestr.compare(pos, 6, "secure") ==0) {
+ cstate = 1;
+ for(std::list<Cookie>::iterator i = cookies.begin(); i != cookies.end(); i++)
+ i->secure = true;
+ } else if (cstate == 0) { // expect cookie
+ Cookie c;
+ std::string s;
+ npos = cookiestr.find("; ", pos);
+ if (npos == std::string::npos) {
+ // last value
+ s = std::string(cookiestr.begin() + pos, cookiestr.end());
+ pos = cookiestr.size();
+ } else {
+ s = std::string(cookiestr.begin() + pos, cookiestr.begin() + npos);
+ pos = npos+2;
+ }
+ keyValuePair(s, c.name, c.value);
+ c.name = YaHTTP::Utility::decodeURL(c.name);
+ c.value = YaHTTP::Utility::decodeURL(c.value);
+ cookies.push_back(c);
+ } else if (cstate == 1) {
+ // ignore crap
+ break;
+ }
+ }
+
+ // store cookies
+ for(std::list<Cookie>::iterator i = cookies.begin(); i != cookies.end(); i++) {
+ this->cookies[i->name] = *i;
+ }
+ };
+ };
+};
@@ -4,18 +4,23 @@
#include <exception>
namespace YaHTTP {
- class ParseError: public std::exception {
+ class Error: public std::exception {
public:
- ParseError() {};
- ParseError(const std::string& reason): reason(reason) {};
- virtual ~ParseError() throw() {};
+ Error() {};
+ Error(const std::string& reason): reason(reason) {};
+ virtual ~Error() throw() {};
virtual const char* what() const throw()
{
return reason.c_str();
}
const std::string reason;
};
+ class ParseError: public YaHTTP::Error {
+ public:
+ ParseError() {};
+ ParseError(const std::string& reason): Error(reason) {};
+ };
};
#endif
Oops, something went wrong.

0 comments on commit 0897e94

Please sign in to comment.