2008-01-25 01:36:40 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/pqi: p3cfgmgr.h
|
|
|
|
*
|
|
|
|
* 3P/PQI network interface for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2007-2008 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef P3_CONFIG_MGR_HEADER
|
|
|
|
#define P3_CONFIG_MGR_HEADER
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "pqi/pqi_base.h"
|
|
|
|
#include "pqi/pqiindic.h"
|
|
|
|
#include "pqi/pqinetwork.h"
|
2008-02-07 11:18:34 -05:00
|
|
|
#include "util/rsthreads.h"
|
2010-03-03 13:20:24 -05:00
|
|
|
#include "pqi/pqibin.h"
|
2008-01-25 01:36:40 -05:00
|
|
|
|
|
|
|
/***** Configuration Management *****
|
|
|
|
*
|
|
|
|
* we need to store:
|
|
|
|
* (1) Certificates.
|
|
|
|
* (2) List of Friends / Net Configuration
|
|
|
|
* (3) Stun List. / DHT peers.
|
|
|
|
* (4) general config.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* At top level we need:
|
|
|
|
*
|
2009-08-10 15:01:27 -04:00
|
|
|
* - type / filename / size / hash -
|
2008-01-25 01:36:40 -05:00
|
|
|
* and the file signed...
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
/**** THESE are STORED in CONFIGURATION FILES....
|
|
|
|
* Cannot be changed
|
|
|
|
*
|
|
|
|
*********************/
|
|
|
|
|
2009-03-20 16:41:31 -04:00
|
|
|
const uint32_t CONFIG_TYPE_GENERAL = 0x0001;
|
|
|
|
const uint32_t CONFIG_TYPE_PEERS = 0x0002;
|
|
|
|
const uint32_t CONFIG_TYPE_FSERVER = 0x0003;
|
|
|
|
const uint32_t CONFIG_TYPE_MSGS = 0x0004;
|
|
|
|
const uint32_t CONFIG_TYPE_CACHE_OLDID = 0x0005;
|
2010-01-13 16:26:30 -05:00
|
|
|
const uint32_t CONFIG_TYPE_AUTHGPG = 0x006;
|
|
|
|
|
2010-01-15 16:09:25 -05:00
|
|
|
const uint32_t CONFIG_TYPE_P3DISC = 0x00B;
|
2010-02-25 17:42:42 -05:00
|
|
|
const uint32_t CONFIG_TYPE_AUTHSSL = 0x00C;
|
2010-01-15 16:09:25 -05:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2008-11-13 18:03:46 -05:00
|
|
|
/* new FileTransfer */
|
2009-03-20 16:41:31 -04:00
|
|
|
const uint32_t CONFIG_TYPE_FT_SHARED = 0x0007;
|
2008-11-15 15:00:29 -05:00
|
|
|
const uint32_t CONFIG_TYPE_FT_EXTRA_LIST= 0x0008;
|
2009-03-20 16:41:31 -04:00
|
|
|
const uint32_t CONFIG_TYPE_FT_CONTROL = 0x0009;
|
2009-08-10 15:01:27 -04:00
|
|
|
const uint32_t CONFIG_TYPE_FT_DWLQUEUE = 0x000A;
|
2008-06-13 11:42:08 -04:00
|
|
|
|
2010-04-15 07:26:44 -04:00
|
|
|
/// turtle router
|
2009-06-03 14:47:14 -04:00
|
|
|
const uint32_t CONFIG_TYPE_TURTLE = 0x0020;
|
|
|
|
|
2008-11-13 18:03:46 -05:00
|
|
|
/* wish these ids where higher...
|
|
|
|
* may move when switch to v0.5
|
|
|
|
*/
|
2009-03-20 16:41:31 -04:00
|
|
|
const uint32_t CONFIG_TYPE_RANK_LINK = 0x0011;
|
|
|
|
const uint32_t CONFIG_TYPE_CHAT = 0x0012;
|
2010-04-15 07:26:44 -04:00
|
|
|
const uint32_t CONFIG_TYPE_STATUS = 0x0013;
|
2008-04-15 12:35:46 -04:00
|
|
|
|
2008-11-13 18:03:46 -05:00
|
|
|
/* standard services */
|
|
|
|
const uint32_t CONFIG_TYPE_QBLOG = 0x0101;
|
|
|
|
const uint32_t CONFIG_TYPE_FORUMS = 0x0102;
|
|
|
|
const uint32_t CONFIG_TYPE_CHANNELS = 0x0103;
|
2008-06-24 00:22:42 -04:00
|
|
|
|
2008-06-16 16:37:48 -04:00
|
|
|
/* CACHE ID Must be at the END so that other configurations
|
|
|
|
* are loaded First (Cache Config --> Cache Loading)
|
|
|
|
*/
|
|
|
|
const uint32_t CONFIG_TYPE_CACHE = 0xff01;
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
class p3ConfigMgr;
|
2008-01-25 01:36:40 -05:00
|
|
|
|
2010-03-10 09:08:52 -05:00
|
|
|
|
2010-04-15 07:26:44 -04:00
|
|
|
|
|
|
|
//! abstract class for configuration saving
|
2010-03-10 09:08:52 -05:00
|
|
|
/*!
|
|
|
|
* Aim is that active objects in retroshare can dervie from this class
|
|
|
|
* and implement their method of saving and loading their configuration
|
|
|
|
*/
|
2008-01-25 01:36:40 -05:00
|
|
|
class pqiConfig
|
|
|
|
{
|
2009-08-10 15:01:27 -04:00
|
|
|
public:
|
2008-02-07 11:18:34 -05:00
|
|
|
pqiConfig(uint32_t t);
|
|
|
|
virtual ~pqiConfig();
|
2008-01-25 01:36:40 -05:00
|
|
|
|
2010-03-03 13:20:24 -05:00
|
|
|
/**
|
2010-04-15 07:26:44 -04:00
|
|
|
* loads configuration of object
|
|
|
|
* @param loadHash This is the hash that will be compared to confirm saved configuration has not
|
2010-03-10 09:08:52 -05:00
|
|
|
* been tampered with
|
2010-03-03 13:20:24 -05:00
|
|
|
*/
|
2008-02-07 11:18:34 -05:00
|
|
|
virtual bool loadConfiguration(std::string &loadHash) = 0;
|
2010-03-03 13:20:24 -05:00
|
|
|
|
2010-04-15 07:26:44 -04:00
|
|
|
/**
|
|
|
|
* save configuration of object
|
|
|
|
*/
|
2008-02-07 11:18:34 -05:00
|
|
|
virtual bool saveConfiguration() = 0;
|
2008-01-25 01:36:40 -05:00
|
|
|
|
2010-03-03 13:20:24 -05:00
|
|
|
/**
|
|
|
|
* The type of configuration, see ids where this class is declared
|
2010-03-10 09:08:52 -05:00
|
|
|
* @see p3cfgmgr.h
|
2010-03-03 13:20:24 -05:00
|
|
|
*/
|
2008-02-07 11:18:34 -05:00
|
|
|
uint32_t Type();
|
2010-03-03 13:20:24 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The name of the configuration file
|
|
|
|
*/
|
2008-02-07 11:18:34 -05:00
|
|
|
std::string Filename();
|
2010-03-03 13:20:24 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The hash computed for this configuration, can use this to compare to externally stored hash
|
|
|
|
* for validation checking
|
|
|
|
*/
|
2008-02-07 11:18:34 -05:00
|
|
|
std::string Hash();
|
2008-01-25 01:36:40 -05:00
|
|
|
|
|
|
|
protected:
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2010-03-10 09:08:52 -05:00
|
|
|
/**
|
|
|
|
* Checks if configuration has changed
|
|
|
|
*/
|
2008-02-07 11:18:34 -05:00
|
|
|
void IndicateConfigChanged();
|
2009-08-10 15:01:27 -04:00
|
|
|
void setHash(std::string h);
|
2008-02-07 11:18:34 -05:00
|
|
|
|
|
|
|
RsMutex cfgMtx;
|
2008-01-25 01:36:40 -05:00
|
|
|
|
|
|
|
private:
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2010-03-03 13:20:24 -05:00
|
|
|
/**
|
|
|
|
* This sets the name of the pqi configuation file
|
|
|
|
*/
|
|
|
|
void setFilename(std::string name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param an index for the Confind which contains list of configuarations that can be tracked
|
|
|
|
*/
|
|
|
|
bool HasConfigChanged(uint16_t idx);
|
2008-02-07 11:18:34 -05:00
|
|
|
|
|
|
|
Indicator ConfInd;
|
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
uint32_t type;
|
|
|
|
std::string filename;
|
|
|
|
std::string hash;
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2009-08-10 15:01:27 -04:00
|
|
|
friend class p3ConfigMgr;
|
2008-02-07 11:18:34 -05:00
|
|
|
/* so it can access:
|
|
|
|
* setFilename() and HasConfigChanged()
|
|
|
|
*/
|
2008-01-25 01:36:40 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2010-03-10 09:08:52 -05:00
|
|
|
/***********************************************************************************************/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* MUTEX NOTE
|
2010-06-25 17:52:21 -04:00
|
|
|
* Class data is protected by mutex's so that anyone can call these
|
|
|
|
* functions, at any time.
|
2010-03-10 09:08:52 -05:00
|
|
|
*/
|
2010-06-25 17:52:21 -04:00
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
class p3ConfigMgr
|
|
|
|
{
|
|
|
|
public:
|
2010-04-15 07:26:44 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bdir base directory: where config files will be saved
|
|
|
|
* @param fname file name for global configuration
|
|
|
|
* @param signame file name for global signature
|
|
|
|
*/
|
2010-01-13 15:56:55 -05:00
|
|
|
p3ConfigMgr(std::string bdir, std::string fname, std::string signame);
|
2008-01-25 01:36:40 -05:00
|
|
|
|
2010-03-03 13:20:24 -05:00
|
|
|
/**
|
2010-03-10 09:08:52 -05:00
|
|
|
* checks and update all added configurations
|
|
|
|
* @see rsserver
|
2010-03-03 13:20:24 -05:00
|
|
|
*/
|
|
|
|
void tick();
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2010-03-03 13:20:24 -05:00
|
|
|
/**
|
|
|
|
* save all added configuation including configuration files
|
2010-04-15 07:26:44 -04:00
|
|
|
* creates global signature file
|
2010-03-03 13:20:24 -05:00
|
|
|
*/
|
|
|
|
void saveConfiguration();
|
|
|
|
|
|
|
|
/**
|
2010-04-15 07:26:44 -04:00
|
|
|
* loads all configurations
|
2010-03-03 13:20:24 -05:00
|
|
|
*/
|
|
|
|
void loadConfiguration();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param file The name for new configuration
|
|
|
|
* @param conf to the configuration to use
|
|
|
|
*/
|
|
|
|
void addConfiguration(std::string file, pqiConfig *conf);
|
|
|
|
|
|
|
|
/* saves config, and disables further saving
|
|
|
|
* used for exiting the system
|
|
|
|
*/
|
|
|
|
void completeConfiguration();
|
2008-01-25 01:36:40 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2010-03-03 13:20:24 -05:00
|
|
|
/**
|
2010-03-10 09:08:52 -05:00
|
|
|
* checks if signature and configuration file's signature matches
|
|
|
|
* @return false if signature file does not match configuration file's signature
|
2010-03-03 13:20:24 -05:00
|
|
|
*/
|
|
|
|
bool getSignAttempt(std::string& metaConfigFname, std::string& metaSignFname, BinMemInterface* membio);
|
|
|
|
|
2010-03-10 09:08:52 -05:00
|
|
|
/**
|
|
|
|
* takes current configuration which is stored in back-up file, and moves it to actual config file
|
|
|
|
* then stores data that was in actual config file into back-up, Corresponding signatures and handled
|
|
|
|
* simlarly in parallel
|
|
|
|
*@param fname the name of the first configuration file checked
|
|
|
|
*@param fname_backup the seconf file, backup, checked if first file does not exist or is corrupted
|
|
|
|
*@param sign file name in which signature is kept
|
|
|
|
*@param sign_backup file name in which signature which correspond to backup config is kept
|
|
|
|
*@param configbio to write config to file
|
|
|
|
*@param signbio to write signature config to file
|
|
|
|
*/
|
|
|
|
bool backedUpFileSave(const std::string& fname, const std::string& fname_backup,const std::string& sign,
|
|
|
|
const std::string& sign_backup, BinMemInterface* configbio, BinMemInterface* signbio);
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
const std::string basedir;
|
|
|
|
const std::string metafname;
|
|
|
|
const std::string metasigfname;
|
|
|
|
|
|
|
|
RsMutex cfgMtx; /* below is protected */
|
2008-01-25 01:36:40 -05:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
bool mConfigSaveActive;
|
|
|
|
std::map<uint32_t, pqiConfig *> configs;
|
2008-01-25 01:36:40 -05:00
|
|
|
};
|
|
|
|
|
2010-03-10 09:08:52 -05:00
|
|
|
/***************************************************************************************************/
|
2008-01-25 01:36:40 -05:00
|
|
|
|
2010-04-15 07:26:44 -04:00
|
|
|
|
|
|
|
//! abstract class for configuration saving, aimed at rs services that uses RsItem config data
|
|
|
|
/*!
|
|
|
|
* The aim of this class is to provide a way for rs services and object to save particular
|
|
|
|
* configurations an items (and load them up as well).
|
|
|
|
*/
|
2008-01-25 01:36:40 -05:00
|
|
|
class p3Config: public pqiConfig
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
p3Config(uint32_t t);
|
2008-01-25 01:36:40 -05:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
virtual bool loadConfiguration(std::string &loadHash);
|
|
|
|
virtual bool saveConfiguration();
|
2008-01-25 01:36:40 -05:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/* Key Functions to be overloaded for Full Configuration */
|
|
|
|
virtual RsSerialiser *setupSerialiser() = 0;
|
2010-04-15 07:26:44 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* saves list of derived object
|
|
|
|
* @return list of config items derived object wants to saves
|
|
|
|
*/
|
2008-01-25 01:36:40 -05:00
|
|
|
virtual std::list<RsItem *> saveList(bool &cleanup) = 0;
|
2010-04-15 07:26:44 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* loads up list of configs items for derived object
|
|
|
|
* @param load list of config items to load up
|
|
|
|
*/
|
2008-01-25 01:36:40 -05:00
|
|
|
virtual bool loadList(std::list<RsItem *> load) = 0;
|
2010-04-15 07:26:44 -04:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
/**
|
|
|
|
* callback for mutex unlocking
|
|
|
|
* in derived classes (should only be needed if cleanup = false)
|
|
|
|
*/
|
2009-08-10 15:01:27 -04:00
|
|
|
virtual void saveDone() { return; }
|
2008-01-25 01:36:40 -05:00
|
|
|
|
2010-03-03 13:20:24 -05:00
|
|
|
private:
|
|
|
|
|
2010-03-10 09:08:52 -05:00
|
|
|
/**
|
|
|
|
* takes current configuration which is stored in back-up file, and moves it to actual config file
|
|
|
|
* then stores data that was in actual config file into back-up, This is an rs specific solution
|
|
|
|
* @param fname the name of the first configuration file checked
|
|
|
|
* @param fname_backup the seconf file, backup, checked if first file does not exist or is corrupted
|
|
|
|
*/
|
|
|
|
bool backedUpFileSave(const std::string& fname, const std::string& fname_backup, std::list<RsItem* >& toSave,
|
|
|
|
bool cleanup);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* for retrieving hash files
|
|
|
|
*/
|
|
|
|
bool getHashAttempt(const std::string& loadHash, std::string& hashstr, const std::string& fname, std::list<RsItem *>& load);
|
2010-03-03 13:20:24 -05:00
|
|
|
|
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
}; /* end of p3Config */
|
|
|
|
|
|
|
|
|
|
|
|
class p3GeneralConfig: public p3Config
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
p3GeneralConfig();
|
|
|
|
|
|
|
|
// General Configuration System
|
|
|
|
std::string getSetting(std::string opt);
|
|
|
|
void setSetting(std::string opt, std::string val);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/* Key Functions to be overloaded for Full Configuration */
|
|
|
|
virtual RsSerialiser *setupSerialiser();
|
|
|
|
virtual std::list<RsItem *> saveList(bool &cleanup);
|
|
|
|
virtual bool loadList(std::list<RsItem *> load);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
/* protected by pqiConfig mutex as well! */
|
2008-01-25 01:36:40 -05:00
|
|
|
std::map<std::string, std::string> settings;
|
2010-03-03 13:20:24 -05:00
|
|
|
|
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-10 15:01:27 -04:00
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // P3_CONFIG_MGR_HEADER
|