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

Method HandleCommand

daemon/HTTPServer.cpp:1387–1591  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1385 }
1386
1387 void HTTPConnection::HandleCommand (const HTTPReq& req, HTTPRes& res, std::stringstream& s)
1388 {
1389 std::map<std::string, std::string> params;
1390 URL url;
1391
1392 url.parse(req.uri);
1393 url.parse_query(params);
1394
1395 std::string webroot; i2p::config::GetOption("http.webroot", webroot);
1396 std::string redirect = std::to_string(COMMAND_REDIRECT_TIMEOUT) + "; url=" + webroot + "?page=commands";
1397 std::string token = params["token"];
1398
1399 if (token.empty () || m_Tokens.find (std::stoi (token)) == m_Tokens.end ())
1400 {
1401 ShowError(s, tr("Invalid token"));
1402 return;
1403 }
1404
1405 std::string cmd = params["cmd"];
1406 if (cmd == HTTP_COMMAND_RUN_PEER_TEST)
1407 i2p::transport::transports.PeerTest ();
1408 else if (cmd == HTTP_COMMAND_RELOAD_TUNNELS_CONFIG)
1409 i2p::client::context.ReloadConfig ();
1410 else if (cmd == HTTP_COMMAND_ENABLE_TRANSIT)
1411 i2p::context.SetAcceptsTunnels (true);
1412 else if (cmd == HTTP_COMMAND_DISABLE_TRANSIT)
1413 i2p::context.SetAcceptsTunnels (false);
1414 else if (cmd == HTTP_COMMAND_SHUTDOWN_START)
1415 {
1416 i2p::context.SetAcceptsTunnels (false);
1417#if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY))
1418 Daemon.gracefulShutdownInterval = 10*60;
1419#elif defined(WIN32_APP)
1420 i2p::win32::GracefulShutdown ();
1421#endif
1422 }
1423 else if (cmd == HTTP_COMMAND_SHUTDOWN_CANCEL)
1424 {
1425 i2p::context.SetAcceptsTunnels (true);
1426#if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY))
1427 Daemon.gracefulShutdownInterval = 0;
1428#elif defined(WIN32_APP)
1429 i2p::win32::StopGracefulShutdown ();
1430#endif
1431 }
1432 else if (cmd == HTTP_COMMAND_SHUTDOWN_NOW)
1433 {
1434#ifndef WIN32_APP
1435 Daemon.running = false;
1436#else
1437 i2p::win32::StopWin32App ();
1438#endif
1439 }
1440 else if (cmd == HTTP_COMMAND_LOGLEVEL)
1441 {
1442 std::string level = params["level"];
1443 SetLogLevel (level);
1444 }

Callers

nothing calls this directly

Calls 15

GetOptionFunction · 0.85
to_stringFunction · 0.85
stoiFunction · 0.85
ShowErrorFunction · 0.85
trFunction · 0.85
GracefulShutdownFunction · 0.85
StopGracefulShutdownFunction · 0.85
StopWin32AppFunction · 0.85
SetLogLevelFunction · 0.85
UrlDecodeFunction · 0.85
ByteStreamToBase64Function · 0.85
SetLanguageFunction · 0.85

Tested by

no test coverage detected