| 30 | #include "platform/FileUtils.h" |
| 31 | |
| 32 | void HttpCookie::readFile() { |
| 33 | ccstd::string inString = cc::FileUtils::getInstance()->getStringFromFile(_cookieFileName); |
| 34 | if (!inString.empty()) { |
| 35 | ccstd::vector<ccstd::string> cookiesVec; |
| 36 | cookiesVec.clear(); |
| 37 | |
| 38 | std::stringstream stream(inString); |
| 39 | ccstd::string item; |
| 40 | while (std::getline(stream, item, '\n')) { |
| 41 | cookiesVec.push_back(item); |
| 42 | } |
| 43 | |
| 44 | if (cookiesVec.empty()) { |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | _cookies.clear(); |
| 49 | |
| 50 | for (auto &cookie : cookiesVec) { |
| 51 | if (cookie.length() == 0) { |
| 52 | continue; |
| 53 | } |
| 54 | |
| 55 | if (cookie.find("#HttpOnly_") != ccstd::string::npos) { |
| 56 | cookie = cookie.substr(10); |
| 57 | } |
| 58 | |
| 59 | if (cookie.at(0) == '#') { |
| 60 | continue; |
| 61 | } |
| 62 | |
| 63 | CookiesInfo co; |
| 64 | std::stringstream streamInfo(cookie); |
| 65 | ccstd::vector<ccstd::string> elems; |
| 66 | ccstd::string elemsItem; |
| 67 | |
| 68 | while (std::getline(streamInfo, elemsItem, '\t')) { |
| 69 | elems.push_back(elemsItem); |
| 70 | } |
| 71 | |
| 72 | co.domain = elems[0]; |
| 73 | if (co.domain.at(0) == '.') { |
| 74 | co.domain = co.domain.substr(1); |
| 75 | } |
| 76 | co.tailmatch = (strcmp("TRUE", elems[1].c_str()) != 0); |
| 77 | co.path = elems[2]; |
| 78 | co.secure = (strcmp("TRUE", elems[3].c_str()) != 0); |
| 79 | co.expires = elems[4]; |
| 80 | co.name = elems[5]; |
| 81 | co.value = elems[6]; |
| 82 | _cookies.push_back(co); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | const ccstd::vector<CookiesInfo> *HttpCookie::getCookies() const { |
| 88 | return &_cookies; |
no test coverage detected