2014-01-17 21:32:55 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/rsserver/rsaccounts.h
|
|
|
|
*
|
|
|
|
* RetroShare C++ Interface.
|
|
|
|
*
|
|
|
|
* Copyright 2013-2014 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.1 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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Header providing interface for libretroshare access to RsAccounts stuff.
|
|
|
|
* External access must be through rsinit.g where a RsAccounts namespace + fns
|
|
|
|
* are available.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
2014-03-17 16:56:06 -04:00
|
|
|
#include "retroshare/rstypes.h"
|
2014-01-17 21:32:55 -05:00
|
|
|
|
|
|
|
class AccountDetails
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AccountDetails();
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
RsPeerId mSslId;
|
2014-01-17 21:32:55 -05:00
|
|
|
std::string mAccountDir;
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
RsPgpId mPgpId;
|
2014-01-17 21:32:55 -05:00
|
|
|
std::string mPgpName;
|
|
|
|
std::string mPgpEmail;
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
std::string mLocation;
|
2014-01-17 21:32:55 -05:00
|
|
|
bool mIsHiddenLoc;
|
|
|
|
bool mFirstRun;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class RsAccountsDetail
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsAccountsDetail();
|
|
|
|
|
|
|
|
// These functions are externally accessible via RsAccounts namespace.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// These functions are accessible from inside libretroshare.
|
|
|
|
|
|
|
|
bool setupBaseDirectory(std::string alt_basedir);
|
|
|
|
bool loadAccounts();
|
|
|
|
bool lockPreferredAccount();
|
2014-11-08 14:31:16 -05:00
|
|
|
void unlockPreferredAccount();
|
2014-01-17 21:32:55 -05:00
|
|
|
|
|
|
|
// Paths.
|
|
|
|
std::string PathDataDirectory();
|
|
|
|
std::string PathBaseDirectory();
|
|
|
|
|
|
|
|
// PGP Path is only dependent on BaseDirectory.
|
|
|
|
std::string PathPGPDirectory();
|
|
|
|
|
|
|
|
// Below are dependent on mPreferredId.
|
|
|
|
std::string PathAccountDirectory();
|
|
|
|
std::string PathAccountKeysDirectory();
|
|
|
|
std::string PathKeyFile();
|
|
|
|
std::string PathCertFile();
|
|
|
|
|
|
|
|
// PGP Accounts.
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
int GetPGPLogins(std::list<RsPgpId> &pgpIds);
|
|
|
|
int GetPGPLoginDetails(const RsPgpId& id, std::string &name, std::string &email);
|
|
|
|
bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, RsPgpId &pgpId, std::string &errString);
|
2014-01-17 21:32:55 -05:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
bool SelectPGPAccount(const RsPgpId& pgpId);
|
2014-01-17 21:32:55 -05:00
|
|
|
|
|
|
|
// PGP Support Functions.
|
2014-03-17 16:56:06 -04:00
|
|
|
bool exportIdentity(const std::string& fname,const RsPgpId& pgp_id) ;
|
|
|
|
bool importIdentity(const std::string& fname,RsPgpId& imported_pgp_id,std::string& import_error) ;
|
2014-01-17 21:32:55 -05:00
|
|
|
void getUnsupportedKeys(std::map<std::string,std::vector<std::string> > &unsupported_keys);
|
|
|
|
bool copyGnuPGKeyrings() ;
|
|
|
|
|
|
|
|
|
|
|
|
// Selecting Rs Account.
|
|
|
|
bool selectAccountByString(const std::string &prefUserString);
|
2014-03-17 16:56:06 -04:00
|
|
|
bool selectId(const RsPeerId& preferredId);
|
2014-01-17 21:32:55 -05:00
|
|
|
|
|
|
|
// Details of Rs Account.
|
2014-03-17 16:56:06 -04:00
|
|
|
bool getPreferredAccountId(RsPeerId &id);
|
|
|
|
bool getAccountDetails(const RsPeerId &id, RsPgpId& gpgId, std::string &gpgName, std::string &gpgEmail, std::string &location);
|
2014-01-17 21:32:55 -05:00
|
|
|
|
|
|
|
bool getAccountOptions(bool &ishidden, bool isFirstTimeRun);
|
|
|
|
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
bool getAccountIds(std::list<RsPeerId> &ids);
|
2014-01-17 21:32:55 -05:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
bool GenerateSSLCertificate(const RsPgpId& gpg_id,
|
2014-01-17 21:32:55 -05:00
|
|
|
const std::string& org, const std::string& loc,
|
|
|
|
const std::string& country, const bool ishiddenloc,
|
2014-03-17 16:56:06 -04:00
|
|
|
const std::string& passwd, RsPeerId &sslId,
|
2014-01-17 21:32:55 -05:00
|
|
|
std::string &errString);
|
|
|
|
|
|
|
|
// From init file.
|
|
|
|
bool storePreferredAccount();
|
|
|
|
bool loadPreferredAccount();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool checkPreferredId();
|
|
|
|
|
|
|
|
bool defaultBaseDirectory();
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
bool getAvailableAccounts(std::map<RsPeerId, AccountDetails> &accounts,
|
2014-01-17 21:32:55 -05:00
|
|
|
int& failing_accounts,
|
|
|
|
std::map<std::string,std::vector<std::string> >& unsupported_keys);
|
|
|
|
|
|
|
|
bool setupAccount(const std::string& accountdir);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
bool mAccountsLocked;
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
std::map<RsPeerId, AccountDetails> mAccounts;
|
|
|
|
RsPeerId mPreferredId;
|
2014-01-17 21:32:55 -05:00
|
|
|
std::string mBaseDirectory;
|
|
|
|
|
|
|
|
std::map<std::string,std::vector<std::string> > mUnsupportedKeys ;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Global singleton declaration of data.
|
2014-08-25 17:07:07 -04:00
|
|
|
extern RsAccountsDetail *rsAccounts;
|
2014-01-17 21:32:55 -05:00
|
|
|
|