]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Sync with upstream
authorAki Tuomi <cmouse@desteem.org>
Thu, 10 Jul 2014 20:31:03 +0000 (23:31 +0300)
committerAki Tuomi <cmouse@desteem.org>
Thu, 10 Jul 2014 20:33:31 +0000 (23:33 +0300)
pdns/ext/yahttp/yahttp/Makefile.am
pdns/ext/yahttp/yahttp/reqresp.cpp
pdns/ext/yahttp/yahttp/reqresp.hpp
pdns/ext/yahttp/yahttp/utility.hpp

index a2866513aad3429ddef77c86f9ea536fea36e901..b5c6ee0f22fa8f6f400a5b4b47ed1aa40b0cf0d6 100644 (file)
@@ -1,5 +1,7 @@
-AM_CPPFLAGS=$(BOOST_CPPFLAGS)
-
+AM_CPPFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@
 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
+
+yahttp-config.h:
+       cat ../../../../config.h > yahttp-config.h
index 9b94a2720a0d2e04ac3ce9ce6f0e0515a935752d..9f12c54773a6ead6d9604c1c7dcf6356c3fa7fca 100644 (file)
@@ -75,8 +75,8 @@ namespace YaHTTP {
 
     minbody = 0;
     // check for expected body size
-    if (target->kind == YAHTTP_TYPE_REQUEST) maxbody = YAHTTP_MAX_REQUEST_SIZE;
-    else if (target->kind == YAHTTP_TYPE_RESPONSE) maxbody = YAHTTP_MAX_RESPONSE_SIZE
+    if (target->kind == YAHTTP_TYPE_REQUEST) maxbody = target->max_request_size;
+    else if (target->kind == YAHTTP_TYPE_RESPONSE) maxbody = target->max_response_size
     else maxbody = 0;
    
     if (!chunked) {
@@ -86,8 +86,8 @@ namespace YaHTTP {
         maxbody = minbody;
       }
       if (minbody < 1) return true; // guess there isn't anything left.
-      if (target->kind == YAHTTP_TYPE_REQUEST && minbody > YAHTTP_MAX_REQUEST_SIZE) throw ParseError("Max request body size exceeded");
-      else if (target->kind == YAHTTP_TYPE_RESPONSE && minbody > YAHTTP_MAX_RESPONSE_SIZE) throw ParseError("Max response body size exceeded");
+      if (target->kind == YAHTTP_TYPE_REQUEST && minbody > target->max_request_size) throw ParseError("Max request body size exceeded");
+      else if (target->kind == YAHTTP_TYPE_RESPONSE && minbody > target->max_response_size) throw ParseError("Max response body size exceeded");
     }
 
     if (maxbody == 0) hasBody = false;
index 44be27a563c30de948af9c1f5b7c1b1169845359..a66dcb622f3874587729975a19ef7ab72fdb65a6 100644 (file)
@@ -87,6 +87,8 @@ namespace YaHTTP {
 #ifdef HAVE_CPP_FUNC_PTR
       renderer = SendBodyRender();
 #endif
+      max_request_size = YAHTTP_MAX_REQUEST_SIZE;
+      max_response_size = YAHTTP_MAX_RESPONSE_SIZE;
     };
 protected:
     HTTPBase(const HTTPBase& rhs) {
@@ -127,6 +129,9 @@ public:
     std::string routeName; //<! name of the current route (only if you use YaHTTP::Router)
 
     std::string body; //<! the actual content
+
+    ssize_t max_request_size; //<! maximum size of request
+    ssize_t max_response_size;  //<! maximum size of response
  
 #ifdef HAVE_CPP_FUNC_PTR
     funcptr::function<size_t(const HTTPBase*,std::ostream&)> renderer; //<! rendering function
index e2d8c62e5af7cf8b74826c4f3c5ebab93c8f5c85..5a42e65ff9db5a04ff92e16babdbde5cc2f91a19 100644 (file)
@@ -45,10 +45,19 @@ namespace YaHTTP {
        struct tm tm;
        localtime_r(&t, &tm);
        fromTm(&tm);
+#ifndef HAVE_TM_GMTOFF
+       time_t t2 = timegm(&tm);
+#endif
 #else
        struct tm *tm;
        tm = localtime(&t);
        fromTm(tm);
+#ifndef HAVE_TM_GMTOFF
+       time_t t2 = timegm(tm);
+#endif
+#endif
+#ifndef HAVE_TM_GMTOFF
+       this->utc_offset = ((t2-t)/10)*10; // removes any possible differences. 
 #endif
      }; //<! uses localtime for time
 
@@ -61,6 +70,9 @@ namespace YaHTTP {
        struct tm *tm;
        tm = gmtime(&t);
        fromTm(tm);
+#endif
+#ifndef HAVE_TM_GMTOFF
+       this->utc_offset = 0;
 #endif
      }; //<! uses gmtime for time
 
@@ -74,8 +86,6 @@ namespace YaHTTP {
        wday = tm->tm_wday;
 #ifdef HAVE_TM_GMTOFF
        utc_offset = tm->tm_gmtoff;
-#else
-       utc_offset = 0;
 #endif
        isSet = true;
      }; //<! parses date from struct tm 
@@ -118,7 +128,23 @@ namespace YaHTTP {
  
      void parse822(const std::string &rfc822_date) {
        struct tm tm;
-       if ( (strptime(rfc822_date.c_str(), "%a, %d %b %Y %T %z", &tm)) != NULL) {
+       const char *ptr;
+#ifdef HAVE_TM_GMTOFF
+       if ( (ptr = strptime(rfc822_date.c_str(), "%a, %d %b %Y %T %z", &tm)) != NULL) {
+#else
+       if ( (ptr = strptime(rfc822_date.c_str(), "%a, %d %b %Y %T", &tm)) != NULL) {
+          int sign;
+         // parse the timezone parameter
+          while(*ptr && ::isspace(*ptr)) ptr++;
+          if (*ptr == '+') sign = 0;
+          else if (*ptr == '-') sign = -1;
+          else throw "Unparseable date";
+          ptr++;
+          utc_offset = ::atoi(ptr) * sign;
+          while(*ptr && ::isdigit(*ptr)) ptr++;
+#endif
+          while(*ptr && ::isspace(*ptr)) ptr++;
+          if (*ptr) throw "Unparseable date"; // must be final.
           fromTm(&tm);
        } else {
           throw "Unparseable date";
@@ -134,7 +160,7 @@ namespace YaHTTP {
        }
      }; //<! parses HTTP Cookie date
 
-     int unixtime() const {
+     time_t unixtime() const {
        struct tm tm;
        tm.tm_year = year-1900;
        tm.tm_mon = month-1;
@@ -145,7 +171,7 @@ namespace YaHTTP {
 #ifdef HAVE_TM_GMTOFF
        tm.tm_gmtoff = utc_offset;
 #endif
-       return mktime(&tm);
+       return timelocal(&tm);
      }; //<! returns this datetime as unixtime. will not work for dates before 1970/1/1 00:00:00 GMT
   };