2018-11-11 06:11:54 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* retroshare-nogui/src/TerminalApiClient.h *
|
|
|
|
* *
|
|
|
|
* retroshare-nogui: headless version of retroshare *
|
|
|
|
* *
|
2018-11-11 14:42:48 -05:00
|
|
|
* Copyright 2004-2006 by Robert Fernie <retroshare.project@gmail.com> *
|
2018-11-11 06:11:54 -05:00
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2015-03-31 14:00:40 -04:00
|
|
|
#pragma once
|
|
|
|
#include <api/ApiServer.h>
|
|
|
|
#include <util/rsthreads.h>
|
|
|
|
|
|
|
|
namespace resource_api {
|
|
|
|
|
|
|
|
// allows basic control from stdin/stdout
|
|
|
|
// - account selection
|
|
|
|
// - login
|
|
|
|
// - shutdown
|
2017-07-08 11:38:09 -04:00
|
|
|
class TerminalApiClient: public RsTickingThread{
|
2015-03-31 14:00:40 -04:00
|
|
|
public:
|
|
|
|
// zero setup: create an instance of this class and destroy it when not needed anymore
|
|
|
|
// no need to call start or stop or something
|
|
|
|
// parameter api must not be null
|
|
|
|
TerminalApiClient(ApiServer* api);
|
|
|
|
~TerminalApiClient();
|
|
|
|
protected:
|
|
|
|
// from RsThread
|
2015-06-16 08:35:07 -04:00
|
|
|
virtual void data_tick(); /* called once the thread is started. Should be overloaded by subclasses. */
|
2015-03-31 14:00:40 -04:00
|
|
|
private:
|
2017-07-08 11:38:09 -04:00
|
|
|
struct AccountInfo
|
|
|
|
{
|
|
|
|
std::string name ;
|
|
|
|
std::string location ;
|
|
|
|
RsPeerId ssl_id ;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void waitForResponse(ApiServer::RequestId id) const;
|
2017-07-09 15:16:41 -04:00
|
|
|
bool isTokenValid(StateToken st) const;
|
2015-03-31 14:00:40 -04:00
|
|
|
ApiServer* mApiServer;
|
2017-07-08 11:38:09 -04:00
|
|
|
|
|
|
|
// Methods to talk to the ApiServer
|
|
|
|
|
|
|
|
void sendPassword(const std::string& passwd) const;
|
|
|
|
void sendSelectedAccount(const std::string& ssl_id) const;
|
|
|
|
void readAvailableAccounts(std::vector<AccountInfo>& accounts) const;
|
|
|
|
void getRunningState() const ;
|
2017-07-09 15:16:41 -04:00
|
|
|
void readPasswordState(StateToken& password_state_token,bool& ask_for_password,std::string& key_name,bool& prev_is_bad) const;
|
2017-07-11 17:47:51 -04:00
|
|
|
void readRunState(StateToken& runstate_state_token, std::string& runstate) const;
|
2015-03-31 14:00:40 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace resource_api
|