| 335 | } |
| 336 | |
| 337 | BrowserCookie CookieManager::ParseSingleCookie(const std::string& cookie) { |
| 338 | LOG(TRACE) << "Entering CookieManager::ParsePersistentCookieInfo"; |
| 339 | // Cookies represented by a structured string record type. |
| 340 | // This structure is modeled after how some versions of IE |
| 341 | // stored perisitent cookeis as files on disk. Each cookie |
| 342 | // is represented by 8 lines in the file separated by line |
| 343 | // feed (0xA) characters, with the following format: |
| 344 | // |
| 345 | // cookie_name |
| 346 | // cookie_value |
| 347 | // cookie.domain.value/cookie/path/value/ |
| 348 | // <integer representing cookie flags> |
| 349 | // <unsigned long representing the low 32 bits of expiration time> |
| 350 | // <unsigned long representing the high 32 bits of expiration time> |
| 351 | // <unsigned long representing the low 32 bits of last-modified time> |
| 352 | // <unsigned long representing the high 32 bits of last-modified time> |
| 353 | // |
| 354 | // Read each of these lines and set the appropriate values |
| 355 | // in the resulting cookie object. |
| 356 | std::vector<std::string> cookie_parts; |
| 357 | StringUtilities::Split(cookie, "\n", &cookie_parts); |
| 358 | |
| 359 | BrowserCookie cookie_to_return; |
| 360 | cookie_to_return.set_name(cookie_parts[0]); |
| 361 | cookie_to_return.set_value(cookie_parts[1]); |
| 362 | |
| 363 | size_t position = cookie_parts[2].find_first_of("/"); |
| 364 | cookie_to_return.set_domain(cookie_parts[2].substr(0, position)); |
| 365 | cookie_to_return.set_path(cookie_parts[2].substr(position)); |
| 366 | |
| 367 | int flags = atoi(cookie_parts[3].c_str()); |
| 368 | cookie_to_return.set_is_secure(INTERNET_COOKIE_IS_SECURE == (INTERNET_COOKIE_IS_SECURE & flags)); |
| 369 | cookie_to_return.set_is_httponly(INTERNET_COOKIE_HTTPONLY == (INTERNET_COOKIE_HTTPONLY & flags)); |
| 370 | |
| 371 | if (cookie_parts[4].size() > 0 && cookie_parts[5].size() > 0) { |
| 372 | unsigned long expiry_time_low = strtoul(cookie_parts[4].c_str(), NULL, 10); |
| 373 | unsigned long expiry_time_high = strtoul(cookie_parts[5].c_str(), NULL, 10); |
| 374 | unsigned long long expiration_time = (expiry_time_high * static_cast<long long>(pow(2.0, 32))) + expiry_time_low; |
| 375 | |
| 376 | // Cookie expiration time is stored in the file as the number |
| 377 | // of 100-nanosecond ticks since 1 January 1601 12:00:00 AM GMT. |
| 378 | // We need the number of seconds since 1 January 1970 12:00:00 AM GMT. |
| 379 | // This is the conversion. |
| 380 | unsigned long cookie_expiration_time = static_cast<unsigned long>((expiration_time / TICKS_PER_SECOND) - UNIX_TIME_OFFSET_SECONDS); |
| 381 | cookie_to_return.set_expiration_time(cookie_expiration_time); |
| 382 | } |
| 383 | return cookie_to_return; |
| 384 | } |
| 385 | |
| 386 | void CookieManager::ParseCookieString(const std::wstring& cookie_string, |
| 387 | std::map<std::string, std::string>* cookies) { |
no test coverage detected