mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
fixed start/stop of jsonapi in GUI
This commit is contained in:
parent
a304ec20ef
commit
6878a7773d
6 changed files with 89 additions and 71 deletions
|
@ -117,6 +117,39 @@ JsonApiServer::corsOptionsHeaders =
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool is_alphanumeric(char c) { return (c>='0' && c<'9') || (c>='a' && c<='z') || (c>='A' && c<='Z') ;}
|
||||
static bool is_alphanumeric(const std::string& s)
|
||||
{
|
||||
for(uint32_t i=0;i<s.size();++i)
|
||||
if(!is_alphanumeric(s[i]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsJsonAPI::parseToken(const std::string& clear_token,std::string& user,std::string& passwd)
|
||||
{
|
||||
uint32_t last_index=0;
|
||||
uint32_t nb_colons=0;
|
||||
|
||||
for(uint32_t i=0;i<clear_token.length();++i)
|
||||
if(clear_token[i]==':')
|
||||
{
|
||||
++nb_colons;
|
||||
last_index = i;
|
||||
}
|
||||
else if(!is_alphanumeric(clear_token[i]))
|
||||
return false;
|
||||
|
||||
if(nb_colons != 1)
|
||||
return false;
|
||||
|
||||
user = clear_token.substr(0,last_index);
|
||||
passwd = clear_token.substr(last_index+1,(int)clear_token.size()-(int)last_index-2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
JsonApiServer::JsonApiServer(): configMutex("JsonApiServer config")
|
||||
{
|
||||
registerHandler("/rsLoginHelper/createLocation",
|
||||
|
@ -436,38 +469,6 @@ bool JsonApiServer::requestNewTokenAutorization(const std::string& user)
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool is_alphanumeric(char c) { return (c>='0' && c<'9') || (c>='a' && c<='z') || (c>='A' && c<='Z') ;}
|
||||
static bool is_alphanumeric(const std::string& s)
|
||||
{
|
||||
for(uint32_t i=0;i<s.size();++i)
|
||||
if(!is_alphanumeric(s[i]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parseToken(const std::string& clear_token,std::string& user,std::string& passwd)
|
||||
{
|
||||
uint32_t last_index=0;
|
||||
uint32_t nb_colons=0;
|
||||
|
||||
for(uint32_t i=0;i<clear_token.length();++i)
|
||||
if(clear_token[i]==':')
|
||||
{
|
||||
++nb_colons;
|
||||
last_index = i;
|
||||
}
|
||||
else if(!is_alphanumeric(clear_token[i]))
|
||||
return false;
|
||||
|
||||
if(nb_colons != 1)
|
||||
return false;
|
||||
|
||||
user = clear_token.substr(0,last_index);
|
||||
passwd = clear_token.substr(last_index+1,(int)clear_token.size()-(int)last_index-2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool JsonApiServer::isAuthTokenValid(const std::string& token)
|
||||
{
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
bool isAuthTokenValid(const std::string& token) override;
|
||||
bool requestNewTokenAutorization(const std::string& user) override;
|
||||
|
||||
// private API
|
||||
// private API. These methods may be moved to RsJsonAPI so as to be visible in http mode, if needed.
|
||||
|
||||
/**
|
||||
* @brief Get decoded version of the given encoded token
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
|
||||
try
|
||||
{
|
||||
std::cerr << "(II) Starting web service on port " << std::dec << _listening_port << std::endl;
|
||||
std::cerr << "(II) Starting restbed service on port " << std::dec << _listening_port << std::endl;
|
||||
_service->start( settings );
|
||||
}
|
||||
catch(std::exception& e)
|
||||
|
@ -67,7 +67,7 @@ public:
|
|||
return;
|
||||
}
|
||||
|
||||
std::cerr << "(II) webui service stopped." << std::endl;
|
||||
std::cerr << "(II) restbed service stopped." << std::endl;
|
||||
}
|
||||
void stop()
|
||||
{
|
||||
|
@ -77,7 +77,7 @@ public:
|
|||
|
||||
while(isRunning())
|
||||
{
|
||||
std::cerr << "(II) shutting down webui service." << std::endl;
|
||||
std::cerr << "(II) shutting down restbed service." << std::endl;
|
||||
rstime::rs_usleep(1000*1000);
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ RestbedService::~RestbedService()
|
|||
|
||||
bool RestbedService::restart()
|
||||
{
|
||||
RsDbg() << "Restarting web interface listening on port " << _restbed_thread->listeningPort() << std::endl;
|
||||
RsDbg() << "Restarting restbed service listening on port " << _restbed_thread->listeningPort() << std::endl;
|
||||
|
||||
if(_restbed_thread->isRunning())
|
||||
_restbed_thread->stop();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue