Parses a param string. params_to_check: map from the name of params that should be parsed to pointers where the value should be written original: the full http path (used only in error message) params_string: & delimited param string to parse err_msg: write detailed message here in case of error
| 959 | // params_string: & delimited param string to parse |
| 960 | // err_msg: write detailed message here in case of error |
| 961 | bool ParseParams(std::map<string, string*>& params_to_check, |
| 962 | const string& original, const string& params_string, string* err_msg) { |
| 963 | for (auto pair : Split(params_string, "&")) { |
| 964 | vector<string> key_value = Split(pair, delimiter::Limit("=", 1)); |
| 965 | if (key_value.size() == 2) { |
| 966 | auto it = params_to_check.find(key_value[0]); |
| 967 | if (it == params_to_check.end()) continue; |
| 968 | string decoded; |
| 969 | if (!UrlDecode(key_value[1], &decoded)) { |
| 970 | *err_msg = Substitute( |
| 971 | "Could not decode '$0' parameter from HTTP request with path: $1", |
| 972 | key_value[0], original); |
| 973 | return false; |
| 974 | } else { |
| 975 | *it->second = decoded; |
| 976 | } |
| 977 | } |
| 978 | } |
| 979 | return true; |
| 980 | } |
| 981 | |
| 982 | // Takes the path component of an HTTP request and parses it. |
| 983 | // The followings are inspected in the path: |