| 226 | } |
| 227 | |
| 228 | bool HTTPReqHandler::ExtractAddressHelper(i2p::http::URL& url, std::string& jump, bool& confirm) |
| 229 | { |
| 230 | confirm = false; |
| 231 | const char *param = "i2paddresshelper="; |
| 232 | std::size_t pos = url.query.find(param); |
| 233 | std::size_t len = std::strlen(param); |
| 234 | std::map<std::string, std::string> params; |
| 235 | |
| 236 | |
| 237 | if (pos == std::string::npos) |
| 238 | return false; /* not found */ |
| 239 | if (!url.parse_query(params)) |
| 240 | return false; |
| 241 | |
| 242 | std::string value = params["i2paddresshelper"]; |
| 243 | len += value.length(); |
| 244 | jump = i2p::http::UrlDecode(value); |
| 245 | if (!VerifyAddressHelper (jump)) |
| 246 | { |
| 247 | LogPrint (eLogError, "HTTPProxy: Malformed jump link ", jump); |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | // if we need update exists, request formed with update param |
| 252 | if (params["update"] == "true") |
| 253 | { |
| 254 | len += std::strlen("&update=true"); |
| 255 | confirm = true; |
| 256 | } |
| 257 | |
| 258 | // if helper is not only one query option and it placed after user's query |
| 259 | if (pos != 0 && url.query[pos-1] == '&') |
| 260 | { |
| 261 | pos--; |
| 262 | len++; |
| 263 | } |
| 264 | // if helper is not only one query option and it placed before user's query |
| 265 | else if (pos == 0 && url.query.length () > len && url.query[len] == '&') |
| 266 | { |
| 267 | // we don't touch the '?' but remove the trailing '&' |
| 268 | len++; |
| 269 | } |
| 270 | else |
| 271 | { |
| 272 | // there is no more query options, resetting hasquery flag |
| 273 | url.hasquery = false; |
| 274 | } |
| 275 | |
| 276 | // reset hasquery flag and remove addresshelper from URL |
| 277 | url.query.replace(pos, len, ""); |
| 278 | return true; |
| 279 | } |
| 280 | |
| 281 | bool HTTPReqHandler::VerifyAddressHelper (std::string_view jump) |
| 282 | { |
nothing calls this directly
no test coverage detected