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"
|
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:
|
|
|
|
*
|
|
|
|
* - type / filename / size / hash -
|
|
|
|
* and the file signed...
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
/**** THESE are STORED in CONFIGURATION FILES....
|
|
|
|
* Cannot be changed
|
|
|
|
*
|
|
|
|
*********************/
|
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
const uint32_t CONFIG_TYPE_GENERAL = 0x0001;
|
2008-02-07 11:18:34 -05:00
|
|
|
const uint32_t CONFIG_TYPE_PEERS = 0x0002;
|
2008-01-25 01:36:40 -05:00
|
|
|
const uint32_t CONFIG_TYPE_FSERVER = 0x0003;
|
2008-02-07 11:18:34 -05:00
|
|
|
const uint32_t CONFIG_TYPE_MSGS = 0x0004;
|
2008-06-16 16:37:48 -04:00
|
|
|
const uint32_t CONFIG_TYPE_CACHE_OLDID = 0x0005;
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2008-04-15 12:35:46 -04:00
|
|
|
const uint32_t CONFIG_TYPE_RANK_LINK = 0x0011;
|
2008-06-13 11:42:08 -04:00
|
|
|
|
|
|
|
const uint32_t CONFIG_TYPE_QBLOG = 0x0012;
|
|
|
|
|
|
|
|
const uint32_t CONFIG_TYPE_FORUMS = 0x0013;
|
2008-04-15 12:35:46 -04:00
|
|
|
|
2008-06-24 00:22:42 -04:00
|
|
|
const uint32_t CONFIG_TYPE_CHANNELS = 0x0014;
|
|
|
|
|
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-02-08 07:39:40 -05:00
|
|
|
class p3AuthMgr;
|
2008-01-25 01:36:40 -05:00
|
|
|
|
|
|
|
class pqiConfig
|
|
|
|
{
|
|
|
|
public:
|
2008-02-07 11:18:34 -05:00
|
|
|
pqiConfig(uint32_t t);
|
|
|
|
virtual ~pqiConfig();
|
2008-01-25 01:36:40 -05:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
virtual bool loadConfiguration(std::string &loadHash) = 0;
|
|
|
|
virtual bool saveConfiguration() = 0;
|
2008-01-25 01:36:40 -05:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
uint32_t Type();
|
|
|
|
std::string Filename();
|
|
|
|
std::string Hash();
|
2008-01-25 01:36:40 -05:00
|
|
|
|
|
|
|
protected:
|
2008-02-07 11:18:34 -05:00
|
|
|
|
|
|
|
void IndicateConfigChanged();
|
|
|
|
void setHash(std::string h);
|
|
|
|
|
|
|
|
RsMutex cfgMtx;
|
2008-01-25 01:36:40 -05:00
|
|
|
|
|
|
|
private:
|
2008-02-07 11:18:34 -05:00
|
|
|
|
|
|
|
void setFilename(std::string name);
|
|
|
|
bool HasConfigChanged(uint16_t idx);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
friend class p3ConfigMgr;
|
|
|
|
/* so it can access:
|
|
|
|
* setFilename() and HasConfigChanged()
|
|
|
|
*/
|
2008-01-25 01:36:40 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
/**** MUTEX NOTE
|
|
|
|
* None - because no-one calls any functions
|
|
|
|
* besides tick() when the system is running.
|
|
|
|
*/
|
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
class p3ConfigMgr
|
|
|
|
{
|
|
|
|
public:
|
2008-02-08 07:39:40 -05:00
|
|
|
p3ConfigMgr(p3AuthMgr *am, std::string bdir, std::string fname, std::string signame);
|
2008-01-25 01:36:40 -05:00
|
|
|
|
|
|
|
void tick();
|
|
|
|
void saveConfiguration();
|
|
|
|
void loadConfiguration();
|
2008-02-07 11:18:34 -05:00
|
|
|
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:
|
|
|
|
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
/* these are constants - so shouldn't need mutex */
|
2008-02-08 07:39:40 -05:00
|
|
|
p3AuthMgr *mAuthMgr;
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
virtual std::list<RsItem *> saveList(bool &cleanup) = 0;
|
|
|
|
virtual bool loadList(std::list<RsItem *> load) = 0;
|
2008-02-07 11:18:34 -05:00
|
|
|
/**
|
|
|
|
* callback for mutex unlocking
|
|
|
|
* in derived classes (should only be needed if cleanup = false)
|
|
|
|
*/
|
|
|
|
virtual void saveDone() { return; }
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // P3_CONFIG_MGR_HEADER
|