MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / HandleRequest

Method HandleRequest

libi2pd_client/HTTPProxy.cpp:362–545  ·  view source on GitHub ↗

* @brief Try to parse request from @a m_recv_buf * If parsing success, rebuild request and store to @a m_send_buf * with remaining data tail * @return true on processed request or false if more data needed */

Source from the content-addressed store, hash-verified

360 * @return true on processed request or false if more data needed
361 */
362 bool HTTPReqHandler::HandleRequest()
363 {
364 m_req_len = m_ClientRequest.parse(m_recv_buf);
365
366 if (m_req_len == 0)
367 return false; /* need more data */
368
369 if (m_req_len < 0) {
370 LogPrint(eLogError, "HTTPProxy: Unable to parse request");
371 GenericProxyError(tr("Invalid request"), tr("Proxy unable to parse your request"));
372 return true; /* parse error */
373 }
374
375 /* parsing success, now let's look inside request */
376 LogPrint(eLogDebug, "HTTPProxy: Requested: ", m_ClientRequest.uri);
377 m_RequestURL.parse(m_ClientRequest.uri);
378 bool m_Confirm;
379
380 std::string jump;
381 if (ExtractAddressHelper(m_RequestURL, jump, m_Confirm))
382 {
383 if (!m_Addresshelper || !i2p::client::context.GetAddressBook ().IsEnabled ())
384 {
385 LogPrint(eLogWarning, "HTTPProxy: Addresshelper request rejected");
386 GenericProxyError(tr("Invalid request"), tr("Addresshelper is not supported"));
387 return true;
388 }
389
390 if (i2p::client::context.GetAddressBook ().RecordExists (m_RequestURL.host, jump))
391 {
392 std::string full_url = m_RequestURL.to_string();
393 SendRedirect(full_url);
394 return true;
395 }
396 else if (!i2p::client::context.GetAddressBook ().FindAddress (m_RequestURL.host) || m_Confirm)
397 {
398 const std::string referer_raw = m_ClientRequest.GetHeader("Referer");
399 i2p::http::URL referer_url;
400 if (!referer_raw.empty ())
401 {
402 referer_url.parse (referer_raw);
403 }
404 if (m_RequestURL.host != referer_url.host)
405 {
406 if (m_Confirm) // Attempt to forced overwriting by link with "&update=true" from harmful URL
407 {
408 LogPrint (eLogWarning, "HTTPProxy: Address update from addresshelper rejected for ", m_RequestURL.host, " (referer is ", m_RequestURL.host.empty() ? "empty" : "harmful", ")");
409 std::string full_url = m_RequestURL.to_string();
410 std::stringstream ss;
411 ss << tr("Host %s is <font color=red>already in router's addressbook</font>. <b>Be careful: source of this URL may be harmful!</b> Click here to update record: <a href=\"%s%s%s&update=true\">Continue</a>.",
412 m_RequestURL.host.c_str(), full_url.c_str(), (full_url.find('?') != std::string::npos ? "&i2paddresshelper=" : "?i2paddresshelper="), jump.c_str());
413 GenericProxyInfo(tr("Addresshelper forced update rejected"), ss.str());
414 }
415 else // Preventing unauthorized additions to the address book
416 {
417 LogPrint (eLogDebug, "HTTPProxy: Adding address from addresshelper for ", m_RequestURL.host, " (generate refer-base page)");
418 std::string full_url = m_RequestURL.to_string();
419 std::stringstream ss;

Callers

nothing calls this directly

Calls 15

LogPrintFunction · 0.85
trFunction · 0.85
stoiFunction · 0.85
to_stringFunction · 0.85
str_rmatchFunction · 0.85
parseMethod · 0.80
IsEnabledMethod · 0.80
RecordExistsMethod · 0.80
to_stringMethod · 0.80
FindAddressMethod · 0.80
InsertAddressMethod · 0.80
UpdateHeaderMethod · 0.80

Tested by

no test coverage detected