mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-25 06:40:58 -04:00
Merge pull request #230 from G10h4ck/ss_port_invalid_family
Check sockaddr_storage is not null before using it and call sockaddr_storage_port
This commit is contained in:
commit
a6ee7ccd0c
8 changed files with 385 additions and 336 deletions
|
@ -494,7 +494,8 @@ HEADERS += util/folderiterator.h \
|
||||||
util/rsmemcache.h \
|
util/rsmemcache.h \
|
||||||
util/rstickevent.h \
|
util/rstickevent.h \
|
||||||
util/rsrecogn.h \
|
util/rsrecogn.h \
|
||||||
util/rsscopetimer.h
|
util/rsscopetimer.h \
|
||||||
|
util/stacktrace.h
|
||||||
|
|
||||||
SOURCES += dbase/cachestrapper.cc \
|
SOURCES += dbase/cachestrapper.cc \
|
||||||
dbase/fimonitor.cc \
|
dbase/fimonitor.cc \
|
||||||
|
|
|
@ -1571,140 +1571,90 @@ bool p3LinkMgrIMPL::tryConnectUDP(const RsPeerId &id, const struct sockaddr_st
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* push all available addresses onto the connect addr stack...
|
||||||
|
* with the following exceptions:
|
||||||
|
* - id is our own
|
||||||
|
* - id is not our friend
|
||||||
|
* - id is already connected
|
||||||
|
* - id is hidden but of an unkown type
|
||||||
|
* - we are hidden but id is not
|
||||||
|
*/
|
||||||
bool p3LinkMgrIMPL::retryConnectTCP(const RsPeerId &id)
|
bool p3LinkMgrIMPL::retryConnectTCP(const RsPeerId &id)
|
||||||
{
|
{
|
||||||
/* Check if we should retry first */
|
|
||||||
{
|
|
||||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
|
|
||||||
/* push all available addresses onto the connect addr stack...
|
|
||||||
* with the following exceptions:
|
|
||||||
* - check local address, see if it is the same network as us
|
|
||||||
- check address age. don't add old ones
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef LINKMGR_DEBUG
|
#ifdef LINKMGR_DEBUG
|
||||||
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() id: " << id << std::endl;
|
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() id: " << id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (id == getOwnId())
|
if (id == getOwnId()) return false;
|
||||||
|
|
||||||
{
|
{
|
||||||
#ifdef LINKMGR_DEBUG
|
RS_STACK_MUTEX(mLinkMtx);
|
||||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgrIMPL::retryConnectTCP() Failed, connecting to own id: ");
|
std::map<RsPeerId, peerConnectState>::iterator it = mFriendList.find(id);
|
||||||
#endif
|
if ( it == mFriendList.end() ) return false;
|
||||||
return false;
|
if ( it->second.state & RS_PEER_S_CONNECTED ) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* look up the id */
|
// Extract the required info from p3PeerMgr
|
||||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
|
||||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
|
||||||
{
|
|
||||||
#ifdef LINKMGR_DEBUG
|
|
||||||
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() Peer is not Friend" << std::endl;
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if already connected -> done */
|
// first possibility - is it a hidden peer
|
||||||
if (it->second.state & RS_PEER_S_CONNECTED)
|
|
||||||
{
|
|
||||||
#ifdef LINKMGR_DEBUG
|
|
||||||
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() Peer Already Connected" << std::endl;
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} /****** END of LOCKED ******/
|
|
||||||
|
|
||||||
#ifdef LINKMGR_DEBUG
|
|
||||||
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() Getting Address from PeerMgr for : " << id;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
/* If we reach here, must retry .... extract the required info from p3PeerMgr */
|
|
||||||
|
|
||||||
/* first possibility - is it a hidden peer */
|
|
||||||
if (mPeerMgr->isHiddenPeer(id))
|
if (mPeerMgr->isHiddenPeer(id))
|
||||||
{
|
{
|
||||||
/* check for valid hidden type */
|
/* check for valid hidden type */
|
||||||
uint32_t type = mPeerMgr->getHiddenType(id);
|
uint32_t type = mPeerMgr->getHiddenType(id);
|
||||||
if (type & (~RS_HIDDEN_TYPE_MASK))
|
if ( type & (~RS_HIDDEN_TYPE_MASK) ) return false;
|
||||||
{
|
|
||||||
#ifdef LINKMGR_DEBUG
|
|
||||||
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() invalid hidden type (" << type << ") -> return false";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* then we just have one connect attempt via the Proxy */
|
||||||
struct sockaddr_storage proxy_addr;
|
struct sockaddr_storage proxy_addr;
|
||||||
std::string domain_addr;
|
std::string domain_addr;
|
||||||
uint16_t domain_port;
|
uint16_t domain_port;
|
||||||
|
if ( mPeerMgr->getProxyAddress(id, proxy_addr, domain_addr, domain_port) )
|
||||||
/* then we just have one connect attempt via the Proxy */
|
|
||||||
if (mPeerMgr->getProxyAddress(id, proxy_addr, domain_addr, domain_port))
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
RS_STACK_MUTEX(mLinkMtx);
|
||||||
|
std::map<RsPeerId, peerConnectState>::iterator it = mFriendList.find(id);
|
||||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
if (it != mFriendList.end())
|
||||||
if (mFriendList.end() != (it = mFriendList.find(id)))
|
|
||||||
{
|
{
|
||||||
locked_ConnectAttempt_ProxyAddress(&(it->second), type, proxy_addr, domain_addr, domain_port);
|
locked_ConnectAttempt_ProxyAddress(&(it->second), type, proxy_addr, domain_addr, domain_port);
|
||||||
return locked_ConnectAttempt_Complete(&(it->second));
|
return locked_ConnectAttempt_Complete(&(it->second));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mPeerMgr->isHidden())
|
if (mPeerMgr->isHidden()) return false;
|
||||||
{
|
|
||||||
#ifdef LINKMGR_DEBUG
|
|
||||||
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() isHidden(): no connection attempts for : " << id;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sockaddr_storage lAddr;
|
struct sockaddr_storage lAddr;
|
||||||
struct sockaddr_storage eAddr;
|
struct sockaddr_storage eAddr;
|
||||||
pqiIpAddrSet histAddrs;
|
pqiIpAddrSet histAddrs;
|
||||||
std::string dyndns;
|
std::string dyndns;
|
||||||
|
|
||||||
if (mPeerMgr->getConnectAddresses(id, lAddr, eAddr, histAddrs, dyndns))
|
if (mPeerMgr->getConnectAddresses(id, lAddr, eAddr, histAddrs, dyndns))
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
RS_STACK_MUTEX(mLinkMtx);
|
||||||
|
|
||||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
std::map<RsPeerId, peerConnectState>::iterator it = mFriendList.find(id);
|
||||||
if (mFriendList.end() != (it = mFriendList.find(id)))
|
if ( it != mFriendList.end() )
|
||||||
{
|
{
|
||||||
locked_ConnectAttempt_CurrentAddresses(&(it->second), lAddr, eAddr);
|
locked_ConnectAttempt_CurrentAddresses(&(it->second), lAddr, eAddr);
|
||||||
|
|
||||||
uint16_t dynPort = sockaddr_storage_port(eAddr);
|
uint16_t dynPort = 0;
|
||||||
if (!dynPort)
|
if (!sockaddr_storage_isnull(eAddr)) dynPort = sockaddr_storage_port(eAddr);
|
||||||
|
if (!dynPort && !sockaddr_storage_isnull(lAddr))
|
||||||
dynPort = sockaddr_storage_port(lAddr);
|
dynPort = sockaddr_storage_port(lAddr);
|
||||||
if (dynPort)
|
if (dynPort)
|
||||||
{
|
|
||||||
locked_ConnectAttempt_AddDynDNS(&(it->second), dyndns, dynPort);
|
locked_ConnectAttempt_AddDynDNS(&(it->second), dyndns, dynPort);
|
||||||
}
|
|
||||||
|
|
||||||
locked_ConnectAttempt_HistoricalAddresses(&(it->second), histAddrs);
|
locked_ConnectAttempt_HistoricalAddresses(&(it->second), histAddrs);
|
||||||
|
|
||||||
/* finish it off */
|
// finish it off
|
||||||
return locked_ConnectAttempt_Complete(&(it->second));
|
return locked_ConnectAttempt_Complete(&(it->second));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() ERROR failed to find friend data : " << id << std::endl;
|
||||||
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() ERROR failed to find friend data : " << id;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() ERROR failed to get addresses from PeerMgr for: " << id << std::endl;
|
||||||
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() ERROR failed to addresses from PeerMgr for: " << id;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -381,7 +381,7 @@ bool p3PeerMgrIMPL::getGpgId(const RsPeerId &ssl_id, RsPgpId &gpgId)
|
||||||
|
|
||||||
bool p3PeerMgrIMPL::isHidden()
|
bool p3PeerMgrIMPL::isHidden()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
RS_STACK_MUTEX(mPeerMtx);
|
||||||
return mOwnState.hiddenNode;
|
return mOwnState.hiddenNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,13 +35,17 @@
|
||||||
#include <retroshare/rsids.h>
|
#include <retroshare/rsids.h>
|
||||||
|
|
||||||
/* The Main Interface Class - for information about your Peers
|
/* The Main Interface Class - for information about your Peers
|
||||||
* A peer is another RS instance, means associated with an SSL certificate
|
* A peer is another RS instance, means associated with an SSL certificate
|
||||||
* A same GPG person can have multiple peer running with different SSL certs signed by the same GPG key
|
* A same GPG person can have multiple peer running with different SSL certs signed by the same GPG key
|
||||||
* Thus a peer have SSL cert details, and also the parent GPG details
|
* Thus a peer have SSL cert details, and also the parent GPG details
|
||||||
*/
|
*/
|
||||||
class RsPeers;
|
class RsPeers;
|
||||||
extern RsPeers *rsPeers;
|
extern RsPeers *rsPeers;
|
||||||
|
|
||||||
|
/* TODO: 2015/12/31 As for type safetyness all those constant must be declared as enum!
|
||||||
|
* C++ now supports typed enum so there is no ambiguity in serialization size
|
||||||
|
*/
|
||||||
|
|
||||||
/* Trust Levels. Should be the same values than what is declared in PGPHandler.h */
|
/* Trust Levels. Should be the same values than what is declared in PGPHandler.h */
|
||||||
|
|
||||||
const uint32_t RS_TRUST_LVL_UNDEFINED = 0;
|
const uint32_t RS_TRUST_LVL_UNDEFINED = 0;
|
||||||
|
@ -216,7 +220,7 @@ class RsPeerDetails
|
||||||
RsPgpId issuer;
|
RsPgpId issuer;
|
||||||
|
|
||||||
PGPFingerprintType fpr; /* pgp fingerprint */
|
PGPFingerprintType fpr; /* pgp fingerprint */
|
||||||
std::string authcode; // (cyril) what is this used for ?????
|
std::string authcode; // TODO: 2015/12/31 (cyril) what is this used for ?????
|
||||||
std::list<RsPgpId> gpgSigners;
|
std::list<RsPgpId> gpgSigners;
|
||||||
|
|
||||||
uint32_t trustLvl;
|
uint32_t trustLvl;
|
||||||
|
@ -234,6 +238,8 @@ class RsPeerDetails
|
||||||
uint32_t state;
|
uint32_t state;
|
||||||
bool actAsServer;
|
bool actAsServer;
|
||||||
|
|
||||||
|
// TODO: 2015/12/31 to take advantage of multiple connection this must be
|
||||||
|
// replaced by a set of addresses
|
||||||
std::string connectAddr ; // current address if connected.
|
std::string connectAddr ; // current address if connected.
|
||||||
uint16_t connectPort ;
|
uint16_t connectPort ;
|
||||||
|
|
||||||
|
@ -274,15 +280,14 @@ class RsPeerDetails
|
||||||
|
|
||||||
// This class is used to get info about crytographic algorithms used with a
|
// This class is used to get info about crytographic algorithms used with a
|
||||||
// particular peer.
|
// particular peer.
|
||||||
//
|
|
||||||
class RsPeerCryptoParams
|
class RsPeerCryptoParams
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int connexion_state ;
|
int connexion_state;
|
||||||
std::string cipher_name ;
|
std::string cipher_name;
|
||||||
int cipher_bits_1 ;
|
int cipher_bits_1;
|
||||||
int cipher_bits_2 ;
|
int cipher_bits_2;
|
||||||
std::string cipher_version ;
|
std::string cipher_version;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsGroupInfo
|
class RsGroupInfo
|
||||||
|
@ -299,13 +304,17 @@ public:
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail);
|
std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail);
|
||||||
|
|
||||||
|
/* TODO: 2015/12/31 this class seems foundamental for RetroShare code
|
||||||
|
* understanding must document it as soon as possible
|
||||||
|
*/
|
||||||
class RsPeers
|
class RsPeers
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RsPeers() { return; }
|
RsPeers() {}
|
||||||
virtual ~RsPeers() { return; }
|
virtual ~RsPeers() {}
|
||||||
|
|
||||||
|
// TODO: 2015/12/31 is this dead code?
|
||||||
/* Updates ... */
|
/* Updates ... */
|
||||||
// not implemented
|
// not implemented
|
||||||
//virtual bool FriendsChanged() = 0;
|
//virtual bool FriendsChanged() = 0;
|
||||||
|
@ -322,7 +331,7 @@ class RsPeers
|
||||||
|
|
||||||
virtual bool isOnline(const RsPeerId &ssl_id) = 0;
|
virtual bool isOnline(const RsPeerId &ssl_id) = 0;
|
||||||
virtual bool isFriend(const RsPeerId &ssl_id) = 0;
|
virtual bool isFriend(const RsPeerId &ssl_id) = 0;
|
||||||
virtual bool isGPGAccepted(const RsPgpId &gpg_id_is_friend) = 0; //
|
virtual bool isGPGAccepted(const RsPgpId &gpg_id_is_friend) = 0;
|
||||||
virtual std::string getPeerName(const RsPeerId &ssl_id) = 0;
|
virtual std::string getPeerName(const RsPeerId &ssl_id) = 0;
|
||||||
virtual std::string getGPGName(const RsPgpId& gpg_id) = 0;
|
virtual std::string getGPGName(const RsPgpId& gpg_id) = 0;
|
||||||
virtual bool getPeerDetails(const RsPeerId& ssl_id, RsPeerDetails &d) = 0;
|
virtual bool getPeerDetails(const RsPeerId& ssl_id, RsPeerDetails &d) = 0;
|
||||||
|
@ -345,11 +354,11 @@ class RsPeers
|
||||||
virtual bool removeFriendLocation(const RsPeerId& sslId) = 0;
|
virtual bool removeFriendLocation(const RsPeerId& sslId) = 0;
|
||||||
|
|
||||||
/* keyring management */
|
/* keyring management */
|
||||||
virtual bool removeKeysFromPGPKeyring(const std::set<RsPgpId>& pgp_ids,std::string& backup_file,uint32_t& error_code)=0 ;
|
virtual bool removeKeysFromPGPKeyring(const std::set<RsPgpId>& pgp_ids,std::string& backup_file,uint32_t& error_code) = 0;
|
||||||
|
|
||||||
/* Network Stuff */
|
/* Network Stuff */
|
||||||
virtual bool connectAttempt(const RsPeerId& ssl_id) = 0;
|
virtual bool connectAttempt(const RsPeerId& ssl_id) = 0;
|
||||||
virtual bool setLocation(const RsPeerId &ssl_id, const std::string &location) = 0;//location is shown in the gui to differentiate ssl certs
|
virtual bool setLocation(const RsPeerId &ssl_id, const std::string &location) = 0; // location is shown in the gui to differentiate ssl certs
|
||||||
|
|
||||||
virtual bool setHiddenNode(const RsPeerId &id, const std::string &hidden_node_address) = 0;
|
virtual bool setHiddenNode(const RsPeerId &id, const std::string &hidden_node_address) = 0;
|
||||||
virtual bool setHiddenNode(const RsPeerId &id, const std::string &address, uint16_t port) = 0;
|
virtual bool setHiddenNode(const RsPeerId &id, const std::string &address, uint16_t port) = 0;
|
||||||
|
@ -371,9 +380,9 @@ class RsPeers
|
||||||
/* Auth Stuff */
|
/* Auth Stuff */
|
||||||
virtual std::string GetRetroshareInvite(const RsPeerId& ssl_id,bool include_signatures) = 0;
|
virtual std::string GetRetroshareInvite(const RsPeerId& ssl_id,bool include_signatures) = 0;
|
||||||
virtual std::string getPGPKey(const RsPgpId& pgp_id,bool include_signatures) = 0;
|
virtual std::string getPGPKey(const RsPgpId& pgp_id,bool include_signatures) = 0;
|
||||||
virtual bool GetPGPBase64StringAndCheckSum(const RsPgpId& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) = 0 ;
|
virtual bool GetPGPBase64StringAndCheckSum(const RsPgpId& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) = 0;
|
||||||
virtual std::string GetRetroshareInvite(bool include_signatures) = 0;
|
virtual std::string GetRetroshareInvite(bool include_signatures) = 0;
|
||||||
virtual bool hasExportMinimal() = 0 ;
|
virtual bool hasExportMinimal() = 0;
|
||||||
|
|
||||||
// Add keys to the keyring
|
// Add keys to the keyring
|
||||||
virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string) = 0;
|
virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string) = 0;
|
||||||
|
@ -410,7 +419,9 @@ class RsPeers
|
||||||
// ... computes the sharing file permission hint flags set for this peer, that is a combination of
|
// ... computes the sharing file permission hint flags set for this peer, that is a combination of
|
||||||
// RS_FILE_HINTS_NETWORK_WIDE and RS_FILE_HINTS_BROWSABLE.
|
// RS_FILE_HINTS_NETWORK_WIDE and RS_FILE_HINTS_BROWSABLE.
|
||||||
//
|
//
|
||||||
virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id,FileStorageFlags file_sharing_flags,const std::list<std::string>& file_parent_groups) = 0;
|
virtual FileSearchFlags computePeerPermissionFlags(
|
||||||
|
const RsPeerId& peer_id, FileStorageFlags file_sharing_flags,
|
||||||
|
const std::list<std::string>& file_parent_groups) = 0;
|
||||||
|
|
||||||
/* Service permission flags */
|
/* Service permission flags */
|
||||||
|
|
||||||
|
|
|
@ -243,7 +243,7 @@ bool p3Peers::isFriend(const RsPeerId &ssl_id)
|
||||||
|
|
||||||
bool p3Peers::haveSecretKey(const RsPgpId& id)
|
bool p3Peers::haveSecretKey(const RsPgpId& id)
|
||||||
{
|
{
|
||||||
return AuthGPG::getAuthGPG()->haveSecretKey(id) ;
|
return AuthGPG::getAuthGPG()->haveSecretKey(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* There are too many dependancies of this function
|
/* There are too many dependancies of this function
|
||||||
|
@ -256,8 +256,6 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
|
||||||
std::cerr << "p3Peers::getPeerDetails() called for id : " << id << std::endl;
|
std::cerr << "p3Peers::getPeerDetails() called for id : " << id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// NOW Only for SSL Details.
|
|
||||||
|
|
||||||
RsPeerId sOwnId = AuthSSL::getAuthSSL()->OwnId();
|
RsPeerId sOwnId = AuthSSL::getAuthSSL()->OwnId();
|
||||||
peerState ps;
|
peerState ps;
|
||||||
|
|
||||||
|
@ -271,27 +269,11 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::getPeerDetails() ERROR not an SSL Id: " << id << std::endl;
|
std::cerr << "p3Peers::getPeerDetails() ERROR not an SSL Id: " << id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return false ;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool res = getGPGDetails(id, d);
|
|
||||||
//
|
|
||||||
// d.isOnlyGPGdetail = true;
|
|
||||||
//
|
|
||||||
// if(id.length() == 16)
|
|
||||||
// d.service_perm_flags = mPeerMgr->servicePermissionFlags(id) ;
|
|
||||||
// else if(id.length() == 32)
|
|
||||||
// d.service_perm_flags = mPeerMgr->servicePermissionFlags(id) ;
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// std::cerr << "p3Peers::getPeerDetails() ERROR not an correct Id: " << id << std::endl;
|
|
||||||
// d.service_perm_flags = RS_SERVICE_PERM_NONE ;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return res ;
|
|
||||||
|
|
||||||
/* get from gpg (first), to fill in the sign and trust details */
|
/* get from gpg (first), to fill in the sign and trust details */
|
||||||
/* don't retrun now, we've got fill in the ssl and connection info */
|
/* don't return now, we've got fill in the ssl and connection info */
|
||||||
getGPGDetails(ps.gpg_id, d);
|
getGPGDetails(ps.gpg_id, d);
|
||||||
d.isOnlyGPGdetail = false;
|
d.isOnlyGPGdetail = false;
|
||||||
|
|
||||||
|
@ -299,7 +281,7 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
|
||||||
d.id = id;
|
d.id = id;
|
||||||
d.location = ps.location;
|
d.location = ps.location;
|
||||||
|
|
||||||
d.service_perm_flags = mPeerMgr->servicePermissionFlags(ps.gpg_id) ;
|
d.service_perm_flags = mPeerMgr->servicePermissionFlags(ps.gpg_id);
|
||||||
|
|
||||||
/* generate */
|
/* generate */
|
||||||
d.authcode = "AUTHCODE";
|
d.authcode = "AUTHCODE";
|
||||||
|
@ -327,10 +309,28 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
|
||||||
d.hiddenNodePort = 0;
|
d.hiddenNodePort = 0;
|
||||||
d.hiddenType = RS_HIDDEN_TYPE_NONE;
|
d.hiddenType = RS_HIDDEN_TYPE_NONE;
|
||||||
|
|
||||||
|
if (sockaddr_storage_isnull(ps.localaddr))
|
||||||
|
{
|
||||||
|
d.localAddr = "INVALID_IP";
|
||||||
|
d.localPort = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
d.localAddr = sockaddr_storage_iptostring(ps.localaddr);
|
d.localAddr = sockaddr_storage_iptostring(ps.localaddr);
|
||||||
d.localPort = sockaddr_storage_port(ps.localaddr);
|
d.localPort = sockaddr_storage_port(ps.localaddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sockaddr_storage_isnull(ps.serveraddr))
|
||||||
|
{
|
||||||
|
d.extAddr = "INVALID_IP";
|
||||||
|
d.extPort = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
d.extAddr = sockaddr_storage_iptostring(ps.serveraddr);
|
d.extAddr = sockaddr_storage_iptostring(ps.serveraddr);
|
||||||
d.extPort = sockaddr_storage_port(ps.serveraddr);
|
d.extPort = sockaddr_storage_port(ps.serveraddr);
|
||||||
|
}
|
||||||
|
|
||||||
d.dyndns = ps.dyndns;
|
d.dyndns = ps.dyndns;
|
||||||
|
|
||||||
std::list<pqiIpAddress>::iterator it;
|
std::list<pqiIpAddress>::iterator it;
|
||||||
|
|
|
@ -35,118 +35,115 @@ struct sockaddr_storage;
|
||||||
|
|
||||||
class p3Peers: public RsPeers
|
class p3Peers: public RsPeers
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
p3Peers(p3LinkMgr *lm, p3PeerMgr *pm, p3NetMgr *nm);
|
p3Peers(p3LinkMgr *lm, p3PeerMgr *pm, p3NetMgr *nm);
|
||||||
virtual ~p3Peers() { return; }
|
virtual ~p3Peers() {}
|
||||||
|
|
||||||
/* Updates ... */
|
/* Updates ... */
|
||||||
virtual bool FriendsChanged();
|
virtual bool FriendsChanged();
|
||||||
virtual bool OthersChanged();
|
virtual bool OthersChanged();
|
||||||
|
|
||||||
/* Peer Details (Net & Auth) */
|
/* Peer Details (Net & Auth) */
|
||||||
virtual const RsPeerId& getOwnId();
|
virtual const RsPeerId& getOwnId();
|
||||||
|
|
||||||
virtual bool haveSecretKey(const RsPgpId& gpg_id) ;
|
virtual bool haveSecretKey(const RsPgpId& gpg_id) ;
|
||||||
|
|
||||||
|
virtual bool getOnlineList(std::list<RsPeerId> &ids);
|
||||||
|
virtual bool getFriendList(std::list<RsPeerId> &ids);
|
||||||
|
virtual bool getPeerCount (unsigned int *friendCount, unsigned int *onlineCount, bool ssl);
|
||||||
|
|
||||||
virtual bool getOnlineList(std::list<RsPeerId> &ids);
|
virtual bool isOnline(const RsPeerId &id);
|
||||||
virtual bool getFriendList(std::list<RsPeerId> &ids);
|
virtual bool isFriend(const RsPeerId &id);
|
||||||
//virtual bool getOthersList(std::list<std::string> &ids);
|
virtual bool isGPGAccepted(const RsPgpId &gpg_id_is_friend);
|
||||||
virtual bool getPeerCount (unsigned int *friendCount, unsigned int *onlineCount, bool ssl);
|
virtual std::string getGPGName(const RsPgpId &gpg_id);
|
||||||
|
virtual std::string getPeerName(const RsPeerId& ssl_or_gpg_id);
|
||||||
virtual bool isOnline(const RsPeerId &id);
|
virtual bool getPeerDetails(const RsPeerId& ssl_or_gpg_id, RsPeerDetails &d);
|
||||||
virtual bool isFriend(const RsPeerId &id);
|
|
||||||
virtual bool isGPGAccepted(const RsPgpId &gpg_id_is_friend); //
|
|
||||||
virtual std::string getGPGName(const RsPgpId &gpg_id);
|
|
||||||
virtual std::string getPeerName(const RsPeerId& ssl_or_gpg_id);
|
|
||||||
virtual bool getPeerDetails(const RsPeerId& ssl_or_gpg_id, RsPeerDetails &d);
|
|
||||||
|
|
||||||
/* Using PGP Ids */
|
/* Using PGP Ids */
|
||||||
virtual const RsPgpId& getGPGOwnId();
|
virtual const RsPgpId& getGPGOwnId();
|
||||||
virtual RsPgpId getGPGId(const RsPeerId &ssl_id);
|
virtual RsPgpId getGPGId(const RsPeerId &ssl_id);
|
||||||
virtual bool isKeySupported(const RsPgpId& ids);
|
virtual bool isKeySupported(const RsPgpId& ids);
|
||||||
virtual bool getGPGAcceptedList(std::list<RsPgpId> &ids);
|
virtual bool getGPGAcceptedList(std::list<RsPgpId> &ids);
|
||||||
virtual bool getGPGSignedList(std::list<RsPgpId> &ids);
|
virtual bool getGPGSignedList(std::list<RsPgpId> &ids);
|
||||||
virtual bool getGPGValidList(std::list<RsPgpId> &ids);
|
virtual bool getGPGValidList(std::list<RsPgpId> &ids);
|
||||||
virtual bool getGPGAllList(std::list<RsPgpId> &ids);
|
virtual bool getGPGAllList(std::list<RsPgpId> &ids);
|
||||||
virtual bool getGPGDetails(const RsPgpId &id, RsPeerDetails &d);
|
virtual bool getGPGDetails(const RsPgpId &id, RsPeerDetails &d);
|
||||||
virtual bool getAssociatedSSLIds(const RsPgpId& gpg_id, std::list<RsPeerId> &ids);
|
virtual bool getAssociatedSSLIds(const RsPgpId& gpg_id, std::list<RsPeerId> &ids);
|
||||||
virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen) ;
|
virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen) ;
|
||||||
|
|
||||||
/* Add/Remove Friends */
|
/* Add/Remove Friends */
|
||||||
virtual bool addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT);
|
virtual bool addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT);
|
||||||
virtual bool removeFriend(const RsPgpId& gpgid);
|
virtual bool removeFriend(const RsPgpId& gpgid);
|
||||||
virtual bool removeFriendLocation(const RsPeerId& sslId);
|
virtual bool removeFriendLocation(const RsPeerId& sslId);
|
||||||
|
|
||||||
/* keyring management */
|
/* keyring management */
|
||||||
virtual bool removeKeysFromPGPKeyring(const std::set<RsPgpId> &pgp_ids,std::string& backup_file,uint32_t& error_code);
|
virtual bool removeKeysFromPGPKeyring(const std::set<RsPgpId> &pgp_ids,std::string& backup_file,uint32_t& error_code);
|
||||||
|
|
||||||
/* Network Stuff */
|
/* Network Stuff */
|
||||||
virtual bool connectAttempt(const RsPeerId &id);
|
virtual bool connectAttempt(const RsPeerId &id);
|
||||||
virtual bool setLocation(const RsPeerId &ssl_id, const std::string &location);//location is shown in the gui to differentiate ssl certs
|
virtual bool setLocation(const RsPeerId &ssl_id, const std::string &location);//location is shown in the gui to differentiate ssl certs
|
||||||
virtual bool setHiddenNode(const RsPeerId &id, const std::string &hidden_node_address);
|
virtual bool setHiddenNode(const RsPeerId &id, const std::string &hidden_node_address);
|
||||||
virtual bool setHiddenNode(const RsPeerId &id, const std::string &address, uint16_t port);
|
virtual bool setHiddenNode(const RsPeerId &id, const std::string &address, uint16_t port);
|
||||||
|
|
||||||
virtual bool setLocalAddress(const RsPeerId &id, const std::string &addr, uint16_t port);
|
virtual bool setLocalAddress(const RsPeerId &id, const std::string &addr, uint16_t port);
|
||||||
virtual bool setExtAddress(const RsPeerId &id, const std::string &addr, uint16_t port);
|
virtual bool setExtAddress(const RsPeerId &id, const std::string &addr, uint16_t port);
|
||||||
virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns);
|
virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns);
|
||||||
virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode);
|
virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode);
|
||||||
virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht);
|
virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht);
|
||||||
|
|
||||||
virtual bool getProxyServer(const uint32_t type, std::string &addr, uint16_t &port,uint32_t& status);
|
virtual bool getProxyServer(const uint32_t type, std::string &addr, uint16_t &port,uint32_t& status);
|
||||||
virtual bool setProxyServer(const uint32_t type,const std::string &addr, const uint16_t port);
|
virtual bool setProxyServer(const uint32_t type, const std::string &addr, const uint16_t port);
|
||||||
virtual bool isProxyAddress(const uint32_t type,const sockaddr_storage&);
|
virtual bool isProxyAddress(const uint32_t type, const sockaddr_storage &addr);
|
||||||
|
|
||||||
virtual void getIPServersList(std::list<std::string>& ip_servers) ;
|
virtual void getIPServersList(std::list<std::string>& ip_servers);
|
||||||
virtual void allowServerIPDetermination(bool) ;
|
virtual void allowServerIPDetermination(bool);
|
||||||
virtual bool getAllowServerIPDetermination() ;
|
virtual bool getAllowServerIPDetermination();
|
||||||
virtual bool resetOwnExternalAddressList() ;
|
virtual bool resetOwnExternalAddressList();
|
||||||
|
|
||||||
/* Auth Stuff */
|
/* Auth Stuff */
|
||||||
// Get the invitation (GPG cert + local/ext address + SSL id for the given peer)
|
// Get the invitation (GPG cert + local/ext address + SSL id for the given peer)
|
||||||
virtual std::string GetRetroshareInvite(const RsPeerId& ssl_id,bool include_signatures);
|
virtual std::string GetRetroshareInvite(const RsPeerId& ssl_id,bool include_signatures);
|
||||||
virtual std::string getPGPKey(const RsPgpId& pgp_id,bool include_signatures) ;
|
virtual std::string getPGPKey(const RsPgpId& pgp_id,bool include_signatures) ;
|
||||||
|
|
||||||
// same but for own id
|
// same but for own id
|
||||||
virtual std::string GetRetroshareInvite(bool include_signatures);
|
virtual std::string GetRetroshareInvite(bool include_signatures);
|
||||||
virtual bool GetPGPBase64StringAndCheckSum(const RsPgpId& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) ;
|
virtual bool GetPGPBase64StringAndCheckSum(const RsPgpId& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum);
|
||||||
|
|
||||||
virtual bool hasExportMinimal() ;
|
virtual bool hasExportMinimal();
|
||||||
|
|
||||||
virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string);
|
virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string);
|
||||||
virtual bool loadDetailsFromStringCert(const std::string &cert, RsPeerDetails &pd, uint32_t& error_code);
|
virtual bool loadDetailsFromStringCert(const std::string &cert, RsPeerDetails &pd, uint32_t& error_code);
|
||||||
|
|
||||||
virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,int& error_code);
|
virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,int& error_code);
|
||||||
virtual bool saveCertificateToFile(const RsPeerId &id, const std::string &fname);
|
virtual bool saveCertificateToFile(const RsPeerId &id, const std::string &fname);
|
||||||
virtual std::string saveCertificateToString(const RsPeerId &id);
|
virtual std::string saveCertificateToString(const RsPeerId &id);
|
||||||
|
|
||||||
virtual bool signGPGCertificate(const RsPgpId &id);
|
virtual bool signGPGCertificate(const RsPgpId &id);
|
||||||
virtual bool trustGPGCertificate(const RsPgpId &id, uint32_t trustlvl);
|
virtual bool trustGPGCertificate(const RsPgpId &id, uint32_t trustlvl);
|
||||||
|
|
||||||
/* Group Stuff */
|
/* Group Stuff */
|
||||||
virtual bool addGroup(RsGroupInfo &groupInfo);
|
virtual bool addGroup(RsGroupInfo &groupInfo);
|
||||||
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo);
|
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo);
|
||||||
virtual bool removeGroup(const std::string &groupId);
|
virtual bool removeGroup(const std::string &groupId);
|
||||||
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo);
|
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo);
|
||||||
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
|
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
|
||||||
virtual bool assignPeerToGroup(const std::string &groupId, const RsPgpId &peerId, bool assign);
|
virtual bool assignPeerToGroup(const std::string &groupId, const RsPgpId &peerId, bool assign);
|
||||||
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId>& peerIds, bool assign);
|
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId>& peerIds, bool assign);
|
||||||
|
|
||||||
virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id,FileStorageFlags share_flags,const std::list<std::string>& parent_groups) ;
|
virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id,FileStorageFlags share_flags,const std::list<std::string>& parent_groups);
|
||||||
|
|
||||||
// service permission stuff
|
// service permission stuff
|
||||||
|
|
||||||
virtual ServicePermissionFlags servicePermissionFlags(const RsPgpId& gpg_id) ;
|
virtual ServicePermissionFlags servicePermissionFlags(const RsPgpId& gpg_id);
|
||||||
virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId & ssl_id) ;
|
virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId & ssl_id);
|
||||||
virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags) ;
|
virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
p3LinkMgr *mLinkMgr;
|
p3LinkMgr *mLinkMgr;
|
||||||
p3PeerMgr *mPeerMgr;
|
p3PeerMgr *mPeerMgr;
|
||||||
p3NetMgr *mNetMgr;
|
p3NetMgr *mNetMgr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "util/rsnet.h"
|
#include "util/rsnet.h"
|
||||||
#include "util/rsstring.h"
|
#include "util/rsstring.h"
|
||||||
#include "pqi/pqinetwork.h"
|
#include "pqi/pqinetwork.h"
|
||||||
|
#include "util/stacktrace.h"
|
||||||
|
|
||||||
/***************************** Internal Helper Fns ******************************/
|
/***************************** Internal Helper Fns ******************************/
|
||||||
|
|
||||||
|
@ -186,13 +187,12 @@ uint16_t sockaddr_storage_port(const struct sockaddr_storage &addr)
|
||||||
{
|
{
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
return sockaddr_storage_ipv4_port(addr);
|
return sockaddr_storage_ipv4_port(addr);
|
||||||
break;
|
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
return sockaddr_storage_ipv6_port(addr);
|
return sockaddr_storage_ipv6_port(addr);
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
std::cerr << "sockaddr_storage_port() invalid addr.ss_family" << std::endl;
|
std::cerr << "sockaddr_storage_port() invalid addr.ss_family" << std::endl;
|
||||||
sockaddr_storage_dump(addr);
|
sockaddr_storage_dump(addr);
|
||||||
|
print_stacktrace();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -508,22 +508,19 @@ bool sockaddr_storage_isnull(const struct sockaddr_storage &addr)
|
||||||
bool sockaddr_storage_isValidNet(const struct sockaddr_storage &addr)
|
bool sockaddr_storage_isValidNet(const struct sockaddr_storage &addr)
|
||||||
{
|
{
|
||||||
#ifdef SS_DEBUG
|
#ifdef SS_DEBUG
|
||||||
std::cerr << "sockaddr_storage_isValidNet()";
|
std::cerr << "sockaddr_storage_isValidNet()" << std::endl;
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch(addr.ss_family)
|
switch(addr.ss_family)
|
||||||
{
|
{
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
return sockaddr_storage_ipv4_isValidNet(addr);
|
return sockaddr_storage_ipv4_isValidNet(addr);
|
||||||
break;
|
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
return sockaddr_storage_ipv6_isValidNet(addr);
|
return sockaddr_storage_ipv6_isValidNet(addr);
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
#ifdef SS_DEBUG
|
#ifdef SS_DEBUG
|
||||||
std::cerr << "sockaddr_storage_isValidNet() INVALID Family - error: " << sockaddr_storage_iptostring(addr);
|
std::cerr << "sockaddr_storage_isValidNet() INVALID Family" << std::endl;
|
||||||
std::cerr << std::endl;
|
sockaddr_storage_dump(addr);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
93
libretroshare/src/util/stacktrace.h
Normal file
93
libretroshare/src/util/stacktrace.h
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
// stacktrace.h (c) 2008, Timo Bingmann from http://idlebox.net/
|
||||||
|
// published under the WTFPL v2.0
|
||||||
|
|
||||||
|
#ifndef _STACKTRACE_H_
|
||||||
|
#define _STACKTRACE_H_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <execinfo.h>
|
||||||
|
#include <cxxabi.h>
|
||||||
|
|
||||||
|
/** Print a demangled stack backtrace of the caller function to FILE* out. */
|
||||||
|
static inline void print_stacktrace(FILE *out = stderr, unsigned int max_frames = 63)
|
||||||
|
{
|
||||||
|
fprintf(out, "stack trace:\n");
|
||||||
|
|
||||||
|
// storage array for stack trace address data
|
||||||
|
void* addrlist[max_frames+1];
|
||||||
|
|
||||||
|
// retrieve current stack addresses
|
||||||
|
int addrlen = backtrace(addrlist, sizeof(addrlist) / sizeof(void*));
|
||||||
|
|
||||||
|
if (addrlen == 0) {
|
||||||
|
fprintf(out, " <empty, possibly corrupt>\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// resolve addresses into strings containing "filename(function+address)",
|
||||||
|
// this array must be free()-ed
|
||||||
|
char** symbollist = backtrace_symbols(addrlist, addrlen);
|
||||||
|
|
||||||
|
// allocate string which will be filled with the demangled function name
|
||||||
|
size_t funcnamesize = 256;
|
||||||
|
char* funcname = (char*)malloc(funcnamesize);
|
||||||
|
|
||||||
|
// iterate over the returned symbol lines. skip the first, it is the
|
||||||
|
// address of this function.
|
||||||
|
for (int i = 1; i < addrlen; i++)
|
||||||
|
{
|
||||||
|
char *begin_name = 0, *begin_offset = 0, *end_offset = 0;
|
||||||
|
|
||||||
|
// find parentheses and +address offset surrounding the mangled name:
|
||||||
|
// ./module(function+0x15c) [0x8048a6d]
|
||||||
|
for (char *p = symbollist[i]; *p; ++p)
|
||||||
|
{
|
||||||
|
if (*p == '(')
|
||||||
|
begin_name = p;
|
||||||
|
else if (*p == '+')
|
||||||
|
begin_offset = p;
|
||||||
|
else if (*p == ')' && begin_offset) {
|
||||||
|
end_offset = p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (begin_name && begin_offset && end_offset
|
||||||
|
&& begin_name < begin_offset)
|
||||||
|
{
|
||||||
|
*begin_name++ = '\0';
|
||||||
|
*begin_offset++ = '\0';
|
||||||
|
*end_offset = '\0';
|
||||||
|
|
||||||
|
// mangled name is now in [begin_name, begin_offset) and caller
|
||||||
|
// offset in [begin_offset, end_offset). now apply
|
||||||
|
// __cxa_demangle():
|
||||||
|
|
||||||
|
int status;
|
||||||
|
char* ret = abi::__cxa_demangle(begin_name,
|
||||||
|
funcname, &funcnamesize, &status);
|
||||||
|
if (status == 0) {
|
||||||
|
funcname = ret; // use possibly realloc()-ed string
|
||||||
|
fprintf(out, " %s : %s+%s\n",
|
||||||
|
symbollist[i], funcname, begin_offset);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// demangling failed. Output function name as a C function with
|
||||||
|
// no arguments.
|
||||||
|
fprintf(out, " %s : %s()+%s\n",
|
||||||
|
symbollist[i], begin_name, begin_offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// couldn't parse the line? print the whole line.
|
||||||
|
fprintf(out, " %s\n", symbollist[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(funcname);
|
||||||
|
free(symbollist);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _STACKTRACE_H_
|
Loading…
Add table
Add a link
Reference in a new issue