3 Ревизии 6caf723e8c ... 0ec695da89

Автор SHA1 Съобщение Дата
  NanashiNoGombe 0ec695da89 do not remove DMDM, MDMD and sid cookies, used for be and uplift преди 5 месеца
  NanashiNoGombe 732d80baf8 concatenate cookie headers with ; for convenience преди 5 месеца
  NanashiNoGombe a782cc340c accpet session cookies преди 5 месеца
променени са 3 файла, в които са добавени 32 реда и са изтрити 5 реда
  1. 3 1
      BBS2chProxyHttpHeaders.cpp
  2. 2 2
      BBS2chProxyKeyManager.cpp
  3. 27 2
      BBS2chProxyPoster.cpp

+ 3 - 1
BBS2chProxyHttpHeaders.cpp

@@ -17,8 +17,10 @@ std::string BBS2chProxyHttpHeaderEntry::getLowercasedName(void)
 std::string BBS2chProxyHttpHeaderEntry::getValue(void)
 {
 	std::string ret;
+	std::string delimiter = ", ";
+	if (getLowercasedName() == "cookie") delimiter = "; ";
 	for (std::vector<std::string>::iterator it = _values.begin(); it != _values.end(); it++) {
-		if (!ret.empty()) ret += ", ";
+		if (!ret.empty()) ret += delimiter;
 		ret += *it;
  	}
  	return ret;

+ 2 - 2
BBS2chProxyKeyManager.cpp

@@ -427,7 +427,7 @@ std::string BBS2chProxyKeyManager::Cookie::valueInNetscapeFormat()
 
 bool BBS2chProxyKeyManager::Cookie::isExpired()
 {
-	return strtoull(expires.c_str(), NULL, 10) < time(NULL);
+	return expires != "0" && strtoull(expires.c_str(), NULL, 10) < time(NULL);
 }
 
 bool BBS2chProxyKeyManager::Cookie::isSameAs(Cookie &cookie)
@@ -437,7 +437,7 @@ bool BBS2chProxyKeyManager::Cookie::isSameAs(Cookie &cookie)
 
 void *BBS2chProxyKeyManager::Cookie::jsonValue()
 {
-	if (isExpired()) return NULL;
+	if (isExpired() || expires == "0") return NULL;
 #if defined(USE_YYJSON)
 	return NULL;
 #elif defined(USE_PICOJSON)

+ 27 - 2
BBS2chProxyPoster.cpp

@@ -513,10 +513,35 @@ curl_slist* IBBS2chProxyPoster::prepareCurlHandle(BBS2chProxyHttpHeaders &header
 {
 	CURL *curl = connectionDelegate->curl;
 	if (_manageCookies) {
-		log_printf(1, "Cookies are managed by proxy2ch, all existing \"Cookie: \" headers are ignored.\n");
+		log_printf(1, "Cookies are managed by proxy2ch, most of existing \"Cookie: \" headers are ignored.\n");
 		curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); //enable cookie engine explicitly
 		curl_easy_setopt(curl, CURLOPT_COOKIELIST, "ALL");  //erase all cookies explicitly
-		headers.remove("Cookie");
+		if (headers.has("Cookie")) {
+			const std::string &value = headers.getEntry("Cookie")->getValue();
+			std::vector<std::string> list;
+			size_t offset = 0;
+			while (1) {
+				size_t pos = value.find("; ", offset);
+				if (pos == std::string::npos) {
+					list.push_back(value.substr(offset));
+					break;
+				}
+				list.push_back(value.substr(offset, pos - offset));
+				offset = pos + 2;
+			}
+			std::string newCookie;
+			for (std::vector<std::string>::iterator it = list.begin(); it != list.end(); ++it) {
+				size_t pos = it->find('=');
+				if (pos == std::string::npos) continue;
+				std::string name = it->substr(0, pos);
+				if (name == "DMDM" || name == "MDMD" || name == "sid") {
+					if (newCookie.size()) newCookie += "; ";
+					newCookie += *it;
+				}
+			}
+			if (newCookie.size()) curl_easy_setopt(curl, CURLOPT_COOKIE, newCookie.c_str());
+			headers.remove("Cookie");
+		}
 		BBS2chProxyKeyManager::CookieJar &jar = BBS2chProxyConnection::keyManager.getCookieJar(_userAgentForRequest);
 		jar.lock();
 		std::vector<BBS2chProxyKeyManager::Cookie> &list = jar.getList();