Prepare for merging

This commit is contained in:
Gioacchino Mazzurco 2019-11-27 18:44:10 +01:00
parent b1860d8682
commit 1d4ca64dee
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
27 changed files with 1442 additions and 992 deletions

View file

@ -5,9 +5,8 @@
* Copyright (C) 2019-2019 Cyril Soler <csoler@users.sourceforge.net> *
* *
* 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. *
* it under the terms of the GNU Affero General Public License version 3 as *
* published by the Free Software Foundation. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
@ -16,7 +15,7 @@
* *
* 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/>. *
*
* *
*******************************************************************************/
#pragma once
@ -25,113 +24,139 @@
class p3ConfigMgr;
class JsonApiResourceProvider;
class RsJsonApi;
class RsJsonAPI
/**
* Pointer to global instance of RsJsonApi service implementation
* @jsonapi{development}
*/
extern RsJsonApi* rsJsonApi;
class RsJsonApi
{
public:
static const uint16_t DEFAULT_PORT = 9092 ;
static const std::string DEFAULT_BINDING_ADDRESS ; // 127.0.0.1
static const uint16_t DEFAULT_PORT = 9092;
static const std::string DEFAULT_BINDING_ADDRESS; // 127.0.0.1
/**
* @brief Restart RsJsonApi server
* @jsonapi{development}
*/
virtual bool restart() = 0;
/**
* @brief Request RsJsonApi to stop and wait until ti has stopped.
* Be expecially carefull to call this from JSON API because you will loose
* access to the API.
* @jsonapi{development}
*/
virtual bool fullstop() = 0;
virtual bool restart() =0;
virtual bool stop() =0;
/**
* @brief Get status of the json api server
* @jsonapi{development}
* @return Returns true if the server is running
*/
virtual bool isRunning() =0;
virtual bool isRunning() = 0;
/*!
* \brief setBindingAddress
* Sets the binding address of the jsonapi server. Will only take effect after the server is restarted
* \param address
* Address in IPv4 or IPv6 format.
*/
/**
* Sets the binding address of the JSON API server. Will only take effect
* after the server is restarted.
* @jsonapi{development}
* @param[in] address Binding address in IPv4 or IPv6 format.
*/
virtual void setBindingAddress(const std::string& address) = 0;
virtual void setBindingAddress(const std::string& address) =0;
/**
* Get the binding address of the JSON API server.
* @jsonapi{development}
* @return string representing binding address
*/
virtual std::string getBindingAddress() const = 0;
/*!
* \brief setListeningPort
* Port to use when talking to the jsonAPI server.
* \param port
* Should be a non system-reserved 16 bits port number (1024 to 65535)
*/
virtual void setListeningPort(uint16_t port) =0;
virtual uint16_t listeningPort() const =0;
/*!
* Set port on which JSON API server will listen. Will only take effect
* after the server is restarted.
* @jsonapi{development}
* @param[in] port Must be available otherwise the binding will fail
*/
virtual void setListeningPort(uint16_t port) = 0;
/*!
* \brief connectToConfigManager
* Should be called after creating the JsonAPI object so that it publishes itself with the proper config file.
* Since JsonAPI is created *before* login, the config manager does not exist at this time.
* \param cfgmgr
*/
virtual void connectToConfigManager(p3ConfigMgr *cfgmgr)=0;
/*!
* Get port on which JSON API server will listen.
* @jsonapi{development}
*/
virtual uint16_t listeningPort() const = 0;
/*!
* \brief registerResourceProvider
* This is used to add/remove new web services to JsonAPI. The client should take care of not using a path range already
* used by the jsonAPI server.
*/
virtual void registerResourceProvider(const JsonApiResourceProvider *)=0;
virtual void unregisterResourceProvider(const JsonApiResourceProvider *)=0;
virtual bool hasResourceProvider(const JsonApiResourceProvider *)=0;
/*!
* Should be called after creating the JsonAPI object so that it publishes
* itself with the proper config file.
* Since JsonAPI is created *before* login, the config manager does not
* exist at that time.
* @param cfgmgr
*/
virtual void connectToConfigManager(p3ConfigMgr& cfgmgr) = 0;
/**
* This is used to add/remove new web services to JsonAPI. The client
* should take care of not using a path range already used by the jsonAPI
* server
*/
virtual void registerResourceProvider(const JsonApiResourceProvider&) = 0;
virtual void unregisterResourceProvider(const JsonApiResourceProvider&) = 0;
virtual bool hasResourceProvider(const JsonApiResourceProvider&) = 0;
//=============================================================================================//
// API methods that are also accessible through http //
//=============================================================================================//
/**
* @brief This function should be used by JSON API clients that aren't
* authenticated yet, to ask their token to be authorized, the success or
* failure will depend on mNewAccessRequestCallback return value, and it
* will likely need human user interaction in the process.
* @jsonapi{development,unauthenticated}
* @param[in] token token to autorize
* @param[in] user user name to authorize
* @param[in] password password for the new user
* @return true if authorization succeded, false otherwise.
*/
virtual bool requestNewTokenAutorization(const std::string& token)=0;
virtual bool requestNewTokenAutorization(
const std::string& user, const std::string& password) = 0;
//=============================================================================================//
// Utility methods //
//=============================================================================================//
/** Split a token in USER:PASSWORD format into user and password */
static bool parseToken(
const std::string& clear_token,
std::string& user, std::string& passwd );
static bool parseToken(const std::string& clear_token,std::string& user,std::string& passwd);
//=============================================================================================//
// API methods that SHOULD NOT be accessible through http //
//=============================================================================================//
//////////////// @Gio: The methods below should not be accessible from the API server !
///
/**
* @brief Add new auth (user,passwd) token to the authorized set, creating the token user:passwd internally.
* @param[in] alphanumeric_user username to autorize decoded
* @param[in] alphanumeric_passwd passwd to autorize decoded
* @return true if the token has been added to authorized, false if error occurred
* Add new auth (user,passwd) token to the authorized set, creating the
* token user:passwd internally.
* @jsonapi{development}
* @param[in] user user name to autorize, must be alphanumerinc
* @param[in] password password for the user, must be alphanumerinc
* @return true if the token has been added to authorized, false if error
* occurred
*/
virtual bool authorizeUser(const std::string& alphanumeric_user,const std::string& alphanumeric_passwd)=0;
virtual bool authorizeUser(
const std::string& user, const std::string& password ) = 0;
/**
* @brief Revoke given auth token
* @param[in] user par of the decoded token
* @jsonapi{development}
* @param[in] user user name of which to revoke authorization
* @return true if the token has been revoked, false otherwise
*/
virtual bool revokeAuthToken(const std::string& user)=0;
/**
* @brief Get authorized tokens
* @jsonapi{development}
* @return the set of authorized encoded tokens
*/
virtual std::map<std::string,std::string> getAuthorizedTokens() =0;
virtual std::map<std::string,std::string> getAuthorizedTokens() = 0;
/**
* @brief Check if given JSON API auth token is authorized
* @jsonapi{development,unauthenticated}
* @param[in] token decoded
* @return tru if authorized, false otherwise
*/
virtual bool isAuthTokenValid(const std::string& token)=0;
virtual bool isAuthTokenValid(const std::string& token) = 0;
virtual ~RsJsonApi() = default;
};
extern RsJsonAPI *rsJsonAPI;

View file

@ -3,7 +3,8 @@
* *
* libretroshare: retroshare core library *
* *
* Copyright 2012-2018 by Retroshare Team <retroshare.project@gmail.com> *
* Copyright (C) 2012-2018 Retroshare Team <contact@retroshare.cc> *
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -21,7 +22,6 @@
*******************************************************************************/
#pragma once
/**
* @def RS_MINI_VERSION
* First number of RetroShare versioning scheme
@ -69,13 +69,45 @@
(RS_MINOR_VERSION == (B) && RS_MINI_VERSION >= (C)))))
#define __RS_PRIVATE_STRINGIFY2(X) #X
#define __RS_PRIVATE_STRINGIFY(X) __RS_PRIVATE_STRINGIFY2(X)
#define RS_PRIVATE_STRINGIFY2(X) #X
#define RS_PRIVATE_STRINGIFY(X) RS_PRIVATE_STRINGIFY2(X)
/**
* Human readable string describing RetroShare version
*/
constexpr auto RS_HUMAN_READABLE_VERSION =
__RS_PRIVATE_STRINGIFY(RS_MAJOR_VERSION) "." \
__RS_PRIVATE_STRINGIFY(RS_MINOR_VERSION) "." \
__RS_PRIVATE_STRINGIFY(RS_MINI_VERSION) RS_EXTRA_VERSION;
RS_PRIVATE_STRINGIFY(RS_MAJOR_VERSION) "." \
RS_PRIVATE_STRINGIFY(RS_MINOR_VERSION) "." \
RS_PRIVATE_STRINGIFY(RS_MINI_VERSION) RS_EXTRA_VERSION;
#include <cstdint>
#include <string>
/**
* Helper to expose version information to JSON API.
* From C++ you should use directly the macro and constants defined upstair
* @jsonapi{development}
*/
class RsVersion
{
public:
/**
* @brief Write version information to given paramethers
* @jsonapi{development,unauthenticated}
* @param[out] major storage
* @param[out] minor storage
* @param[out] mini storage
* @param[out] extra storage
* @param[out] human storage
*/
static void version( uint32_t& major, uint32_t& minor, uint32_t& mini,
std::string& extra, std::string& human );
};
/**
* Pointer to global instance of RsVersion, for the sake of JSON API, from C++
* you can use directly the macro and constants defined upstair
* @jsonapi{development}
*/
extern RsVersion* rsVersion;

View file

@ -6,39 +6,67 @@
* Copyright 2019-2019 Cyril Soler <csoler@users.sourceforge.net> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* it under the terms of the GNU Affero General Public License version 3 as *
* published by the Free Software Foundation. *
* *
* 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* 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/>. *
* *
*******************************************************************************/
#pragma once
class RsWebUI
#include <string>
class RsWebUi;
/**
* Pointer to global instance of RsWebUi service implementation
* @jsonapi{development}
*/
extern RsWebUi* rsWebUI;
class RsWebUi
{
public:
enum {
WEBUI_STATUS_UNKNOWN = 0x00,
WEBUI_STATUS_NOT_RUNNING = 0x01,
WEBUI_STATUS_RUNNING = 0x02
};
static const std::string DEFAULT_BASE_DIRECTORY ;
static const std::string DEFAULT_BASE_DIRECTORY;
virtual bool restart() =0;
virtual bool stop() =0;
/**
* @brief Restart WebUI
* @jsonapi{development}
*/
virtual bool restart() = 0;
virtual void setHtmlFilesDirectory(const std::string& html_dir) =0;
virtual void setUserPassword(const std::string& passwd) =0;
/**
* @brief Stop WebUI
* @jsonapi{development}
*/
virtual bool stop() = 0;
virtual int status() const=0;
/**
* @brief Set WebUI static files directory, need restart to apply
* @param[in] htmlDir directory path
* @jsonapi{development}
*/
virtual void setHtmlFilesDirectory(const std::string& htmlDir) = 0;
/**
* @brief Set WebUI user password
* @param[in] password new password for WebUI
* @jsonapi{development}
*/
virtual void setUserPassword(const std::string& password) =0;
/**
* @brief check if WebUI is running
* @jsonapi{development}
* @return true if running, false otherwise
*/
virtual bool isRunning() const = 0;
virtual ~RsWebUi() = default;
};
extern RsWebUI *rsWebUI;