| 786 | } |
| 787 | |
| 788 | void HTTPConnection::fillRequest(HTTPRequest& req) { |
| 789 | req.request = request; |
| 790 | req.vdir = url_decode(vdir); |
| 791 | req.resource = url_decode(resource); |
| 792 | req.headers = header; |
| 793 | req.cookies.clear(); |
| 794 | |
| 795 | req.ip = bz_getNonPlayerConnectionIP(connectionID); |
| 796 | const char* hostmask = bz_getNonPlayerConnectionHost(connectionID); |
| 797 | req.hostmask = hostmask ? hostmask : ""; |
| 798 | |
| 799 | // parse the headers here for cookies |
| 800 | std::map<std::string, std::string>::iterator itr = req.headers.begin(); |
| 801 | |
| 802 | while (itr != req.headers.end()) { |
| 803 | const std::string& key = itr->first; |
| 804 | if (compare_nocase(key, "cookie") == 0) { |
| 805 | std::vector<std::string> cookie = tokenize(itr->second, "=", 2, false); |
| 806 | |
| 807 | if (cookie.size() > 1) { |
| 808 | req.cookies[cookie[0]] = cookie[1]; |
| 809 | |
| 810 | // check for the magic sessionID cookie |
| 811 | if (compare_nocase(cookie[0], "sessionid") == 0) { |
| 812 | sessionID = atoi(cookie[1].c_str()); |
| 813 | } |
| 814 | } |
| 815 | } |
| 816 | else if (compare_nocase(key, "authorization") == 0) { |
| 817 | std::vector<std::string> auth = tokenize(itr->second, " ", 2, false); |
| 818 | |
| 819 | if (auth.size() > 1) { |
| 820 | req.authType = auth[0]; |
| 821 | req.authCredentials = auth[1]; |
| 822 | |
| 823 | if (compare_nocase(auth[0], "basic") == 0 && auth[1].size()) { |
| 824 | std::string b64 = base64_decode(auth[1]); |
| 825 | std::vector<std::string> uandp = tokenize(b64, ":", 2, false); |
| 826 | if (uandp.size() == 2) { |
| 827 | req.username = uandp[0]; |
| 828 | req.password = uandp[1]; |
| 829 | } |
| 830 | } |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | itr++; |
| 835 | } |
| 836 | |
| 837 | if (req.request != ePost) { |
| 838 | // parse out the parameters from the resource |
| 839 | size_t q = req.resource.find_first_of('?'); |
| 840 | if (q != std::string::npos) { |
| 841 | parseParams(req.parameters, req.resource, q + 1); |
| 842 | req.resource.erase(req.resource.begin() + q, req.resource.end()); |
| 843 | } |
| 844 | } |
| 845 |
no test coverage detected