mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 23:49:35 -05:00
merged upstream/master
This commit is contained in:
commit
0c45217fc0
@ -727,6 +727,11 @@ void PeersHandler::handleWildcard(Request &req, Response &resp)
|
||||
peerDetails.localPort );
|
||||
if (!peerDetails.dyndns.empty())
|
||||
mRsPeers->setDynDNS(peerDetails.id, peerDetails.dyndns);
|
||||
for(auto&& ipr : peerDetails.ipAddressList)
|
||||
mRsPeers->addPeerLocator(
|
||||
peerDetails.id,
|
||||
RsUrl(ipr.substr(0, ipr.find(' '))) );
|
||||
|
||||
}
|
||||
}
|
||||
while(false);
|
||||
|
@ -9,10 +9,6 @@ DESTDIR = lib
|
||||
|
||||
!include(use_libresapi.pri):error("Including")
|
||||
|
||||
# when rapidjson is mainstream on all distribs, we will not need the sources anymore
|
||||
# in the meantime, they are part of the RS directory so that it is always possible to find them
|
||||
|
||||
INCLUDEPATH += ../../rapidjson-1.1.0
|
||||
INCLUDEPATH += ../../libretroshare/src
|
||||
|
||||
libresapilocalserver {
|
||||
|
@ -17,11 +17,6 @@ DESTDIR = lib
|
||||
#QMAKE_CFLAGS += -Werror
|
||||
#QMAKE_CXXFLAGS += -Werror
|
||||
|
||||
# when rapidjson is mainstream on all distribs, we will not need the sources anymore
|
||||
# in the meantime, they are part of the RS directory so that it is always possible to find them
|
||||
|
||||
INCLUDEPATH += ../../rapidjson-1.1.0
|
||||
|
||||
debug {
|
||||
# DEFINES *= DEBUG
|
||||
# DEFINES *= OPENDHT_DEBUG DHT_DEBUG CONN_DEBUG DEBUG_UDP_SORTER P3DISC_DEBUG DEBUG_UDP_LAYER FT_DEBUG EXTADDRSEARCH_DEBUG
|
||||
@ -510,7 +505,8 @@ HEADERS += util/folderiterator.h \
|
||||
util/rstime.h \
|
||||
util/stacktrace.h \
|
||||
util/rsdeprecate.h \
|
||||
util/cxx11retrocompat.h
|
||||
util/cxx11retrocompat.h \
|
||||
util/rsurl.h
|
||||
|
||||
SOURCES += ft/ftchunkmap.cc \
|
||||
ft/ftcontroller.cc \
|
||||
@ -657,7 +653,8 @@ SOURCES += util/folderiterator.cc \
|
||||
util/rsrandom.cc \
|
||||
util/rstickevent.cc \
|
||||
util/rsrecogn.cc \
|
||||
util/rstime.cc
|
||||
util/rstime.cc \
|
||||
util/rsurl.cc
|
||||
|
||||
## Added for retrocompatibility remove ASAP
|
||||
isEmpty(RS_UPNP_LIB) {
|
||||
|
@ -1,3 +1,23 @@
|
||||
/*
|
||||
* RetroShare
|
||||
*
|
||||
* Copyright (C) 2012-2014 Cyril Soler <csoler@users.sourceforge.net>
|
||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
@ -11,25 +31,21 @@
|
||||
|
||||
//#define DEBUG_RSCERTIFICATE
|
||||
|
||||
static const std::string PGP_CERTIFICATE_START ( "-----BEGIN PGP PUBLIC KEY BLOCK-----" );
|
||||
static const std::string PGP_CERTIFICATE_END ( "-----END PGP PUBLIC KEY BLOCK-----" );
|
||||
static const std::string EXTERNAL_IP_BEGIN_SECTION ( "--EXT--" );
|
||||
static const std::string LOCAL_IP_BEGIN_SECTION ( "--LOCAL--" );
|
||||
static const std::string SSLID_BEGIN_SECTION ( "--SSLID--" );
|
||||
static const std::string LOCATION_BEGIN_SECTION ( "--LOCATION--" );
|
||||
static const std::string HIDDEN_NODE_BEGIN_SECTION ( "--HIDDEN--" );
|
||||
static const uint8_t CERTIFICATE_VERSION_06 = 0x06;
|
||||
|
||||
static const uint8_t CERTIFICATE_PTAG_PGP_SECTION = 0x01 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_EXTIPANDPORT_SECTION = 0x02 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_LOCIPANDPORT_SECTION = 0x03 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_DNS_SECTION = 0x04 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_SSLID_SECTION = 0x05 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_NAME_SECTION = 0x06 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_CHECKSUM_SECTION = 0x07 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_HIDDENNODE_SECTION = 0x08 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_VERSION_SECTION = 0x09 ;
|
||||
|
||||
static const uint8_t CERTIFICATE_VERSION_06 = 0x06 ;
|
||||
enum CertificatePtag : uint8_t
|
||||
{
|
||||
CERTIFICATE_PTAG_PGP_SECTION = 0x01,
|
||||
CERTIFICATE_PTAG_EXTIPANDPORT_SECTION = 0x02,
|
||||
CERTIFICATE_PTAG_LOCIPANDPORT_SECTION = 0x03,
|
||||
CERTIFICATE_PTAG_DNS_SECTION = 0x04,
|
||||
CERTIFICATE_PTAG_SSLID_SECTION = 0x05,
|
||||
CERTIFICATE_PTAG_NAME_SECTION = 0x06,
|
||||
CERTIFICATE_PTAG_CHECKSUM_SECTION = 0x07,
|
||||
CERTIFICATE_PTAG_HIDDENNODE_SECTION = 0x08,
|
||||
CERTIFICATE_PTAG_VERSION_SECTION = 0x09,
|
||||
CERTIFICATE_PTAG_EXTRA_LOCATOR = 10
|
||||
};
|
||||
|
||||
static bool is_acceptable_radix64Char(char c)
|
||||
{
|
||||
@ -95,6 +111,14 @@ std::string RsCertificate::toStdString() const
|
||||
|
||||
addPacket( CERTIFICATE_PTAG_NAME_SECTION , (unsigned char *)location_name.c_str() ,location_name.length() , buf, p, BS ) ;
|
||||
addPacket( CERTIFICATE_PTAG_SSLID_SECTION , location_id.toByteArray() ,location_id.SIZE_IN_BYTES, buf, p, BS ) ;
|
||||
|
||||
for (const RsUrl& locator : mLocators)
|
||||
{
|
||||
std::string urlStr(locator.toString());
|
||||
addPacket( CERTIFICATE_PTAG_EXTRA_LOCATOR,
|
||||
(unsigned char *) urlStr.c_str(), urlStr.size(),
|
||||
buf, p, BS );
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC(buf,p) ;
|
||||
@ -195,7 +219,10 @@ RsCertificate::RsCertificate(const RsPeerDetails& Detail, const unsigned char *b
|
||||
memset(ipv4_external_ip_and_port,0,6) ;
|
||||
}
|
||||
|
||||
dns_name = Detail.dyndns ;
|
||||
dns_name = Detail.dyndns;
|
||||
|
||||
for(auto&& ipr : Detail.ipAddressList)
|
||||
mLocators.insert(RsUrl(ipr.substr(0, ipr.find(' '))));
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -254,19 +281,19 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code)
|
||||
std::vector<uint8_t> bf = Radix64::decode(str) ;
|
||||
size_t size = bf.size();
|
||||
|
||||
bool checksum_check_passed = false ;
|
||||
unsigned char *buf = bf.data() ;
|
||||
size_t total_s = 0 ;
|
||||
only_pgp = true ;
|
||||
uint8_t certificate_version = 0x00 ;
|
||||
bool checksum_check_passed = false;
|
||||
unsigned char *buf = bf.data();
|
||||
size_t total_s = 0;
|
||||
only_pgp = true;
|
||||
uint8_t certificate_version = 0x00;
|
||||
|
||||
while(total_s < size)
|
||||
{
|
||||
uint8_t ptag = buf[0];
|
||||
buf = &buf[1] ;
|
||||
buf = &buf[1];
|
||||
|
||||
unsigned char *buf2 = buf ;
|
||||
uint32_t s = PGPKeyParser::read_125Size(buf) ;
|
||||
unsigned char *buf2 = buf;
|
||||
uint32_t s = PGPKeyParser::read_125Size(buf);
|
||||
|
||||
total_s += 1 + ((unsigned long)buf-(unsigned long)buf2) ;
|
||||
|
||||
@ -281,90 +308,80 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code)
|
||||
#endif
|
||||
switch(ptag)
|
||||
{
|
||||
case CERTIFICATE_PTAG_VERSION_SECTION: certificate_version = buf[0] ;
|
||||
buf = &buf[s] ;
|
||||
break ;
|
||||
|
||||
|
||||
case CERTIFICATE_PTAG_PGP_SECTION: binary_pgp_key = new unsigned char[s] ;
|
||||
memcpy(binary_pgp_key,buf,s) ;
|
||||
binary_pgp_key_size = s ;
|
||||
buf = &buf[s] ;
|
||||
break ;
|
||||
|
||||
case CERTIFICATE_PTAG_NAME_SECTION: location_name = std::string((char *)buf,s) ;
|
||||
buf = &buf[s] ;
|
||||
break ;
|
||||
|
||||
case CERTIFICATE_PTAG_SSLID_SECTION:
|
||||
if(s != location_id.SIZE_IN_BYTES)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_LOCATION_ID ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
location_id = RsPeerId(buf) ;
|
||||
buf = &buf[s] ;
|
||||
only_pgp = false ;
|
||||
break ;
|
||||
|
||||
case CERTIFICATE_PTAG_DNS_SECTION: dns_name = std::string((char *)buf,s) ;
|
||||
buf = &buf[s] ;
|
||||
break ;
|
||||
|
||||
case CERTIFICATE_PTAG_HIDDENNODE_SECTION:
|
||||
hidden_node_address = std::string((char *)buf,s);
|
||||
hidden_node = true;
|
||||
buf = &buf[s];
|
||||
|
||||
break ;
|
||||
|
||||
case CERTIFICATE_PTAG_LOCIPANDPORT_SECTION:
|
||||
if(s != 6)
|
||||
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_LOCAL_IP;
|
||||
return false ;
|
||||
}
|
||||
|
||||
memcpy(ipv4_internal_ip_and_port,buf,s) ;
|
||||
buf = &buf[s] ;
|
||||
break ;
|
||||
case CERTIFICATE_PTAG_EXTIPANDPORT_SECTION:
|
||||
if(s != 6)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_EXTERNAL_IP;
|
||||
return false ;
|
||||
}
|
||||
|
||||
memcpy(ipv4_external_ip_and_port,buf,s) ;
|
||||
buf = &buf[s] ;
|
||||
break ;
|
||||
case CERTIFICATE_PTAG_CHECKSUM_SECTION:
|
||||
{
|
||||
if(s != 3 || total_s+3 != size)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_CHECKSUM_SECTION ;
|
||||
return false ;
|
||||
}
|
||||
uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC(bf.data(),size-5) ;
|
||||
uint32_t certificate_crc = buf[0] + (buf[1] << 8) + (buf[2] << 16) ;
|
||||
|
||||
if(computed_crc != certificate_crc)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_CHECKSUM_ERROR ;
|
||||
return false ;
|
||||
}
|
||||
else
|
||||
checksum_check_passed = true ;
|
||||
}
|
||||
break ;
|
||||
default:
|
||||
std::cerr << "(WW) unknwown PTAG 0x" << std::hex << ptag << std::dec << " in certificate! Ignoring it." << std::endl;
|
||||
buf = &buf[s] ;
|
||||
break ;
|
||||
case CERTIFICATE_PTAG_VERSION_SECTION:
|
||||
certificate_version = buf[0];
|
||||
break;
|
||||
case CERTIFICATE_PTAG_PGP_SECTION:
|
||||
binary_pgp_key = new unsigned char[s];
|
||||
memcpy(binary_pgp_key,buf,s);
|
||||
binary_pgp_key_size = s;
|
||||
break;
|
||||
case CERTIFICATE_PTAG_NAME_SECTION:
|
||||
location_name = std::string((char *)buf,s);
|
||||
break;
|
||||
case CERTIFICATE_PTAG_SSLID_SECTION:
|
||||
if(s != location_id.SIZE_IN_BYTES)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_LOCATION_ID;
|
||||
return false;
|
||||
}
|
||||
location_id = RsPeerId(buf);
|
||||
only_pgp = false;
|
||||
break;
|
||||
case CERTIFICATE_PTAG_DNS_SECTION:
|
||||
dns_name = std::string((char *)buf,s);
|
||||
break;
|
||||
case CERTIFICATE_PTAG_HIDDENNODE_SECTION:
|
||||
hidden_node_address = std::string((char *)buf,s);
|
||||
hidden_node = true;
|
||||
break;
|
||||
case CERTIFICATE_PTAG_LOCIPANDPORT_SECTION:
|
||||
if(s != 6)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_LOCAL_IP;
|
||||
return false;
|
||||
}
|
||||
memcpy(ipv4_internal_ip_and_port,buf,s);
|
||||
break;
|
||||
case CERTIFICATE_PTAG_EXTIPANDPORT_SECTION:
|
||||
if(s != 6)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_EXTERNAL_IP;
|
||||
return false;
|
||||
}
|
||||
memcpy(ipv4_external_ip_and_port,buf,s);
|
||||
break;
|
||||
case CERTIFICATE_PTAG_CHECKSUM_SECTION:
|
||||
{
|
||||
if(s != 3 || total_s+3 != size)
|
||||
{
|
||||
err_code =
|
||||
CERTIFICATE_PARSING_ERROR_INVALID_CHECKSUM_SECTION;
|
||||
return false;
|
||||
}
|
||||
uint32_t computed_crc =
|
||||
PGPKeyManagement::compute24bitsCRC(bf.data(),size-5);
|
||||
uint32_t certificate_crc =
|
||||
buf[0] + (buf[1] << 8) + (buf[2] << 16);
|
||||
if(computed_crc != certificate_crc)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_CHECKSUM_ERROR;
|
||||
return false;
|
||||
}
|
||||
else checksum_check_passed = true;
|
||||
break;
|
||||
}
|
||||
case CERTIFICATE_PTAG_EXTRA_LOCATOR:
|
||||
mLocators.insert(RsUrl(std::string((char *)buf, s)));
|
||||
break;
|
||||
default:
|
||||
std::cerr << "(WW) unknwown PTAG 0x" << std::hex << ptag
|
||||
<< std::dec << " in certificate! Ignoring it."
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
buf = &buf[s];
|
||||
total_s += s ;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,28 @@
|
||||
#pragma once
|
||||
/*
|
||||
* RetroShare
|
||||
*
|
||||
* Copyright (C) 2012-2014 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.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "util/rsurl.h"
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <retroshare/rstypes.h>
|
||||
|
||||
class RsPeerDetails ;
|
||||
|
||||
@ -42,6 +63,7 @@ class RsCertificate
|
||||
size_t pgp_key_size() const { return binary_pgp_key_size ; }
|
||||
|
||||
static bool cleanCertificate(const std::string& input, std::string& output, RsCertificate::Format& format, int& error_code, bool check_content) ;
|
||||
const std::set<RsUrl>& locators() const { return mLocators; }
|
||||
|
||||
private:
|
||||
static bool cleanCertificate(const std::string& input,std::string& output,int&) ; // new radix format
|
||||
@ -69,6 +91,7 @@ class RsCertificate
|
||||
std::string pgp_version ;
|
||||
std::string dns_name ;
|
||||
std::string hidden_node_address;
|
||||
std::set<RsUrl> mLocators;
|
||||
|
||||
bool only_pgp ; // does the cert contain only pgp info?
|
||||
bool hidden_node; // IP or hidden Node Address.
|
||||
|
@ -1119,12 +1119,7 @@ bool p3NetMgrIMPL::checkNetAddress()
|
||||
#ifdef NETMGR_DEBUG
|
||||
std::cerr << "p3NetMgrIMPL::checkNetAddress() Correcting Port to DEFAULT" << std::endl;
|
||||
#endif
|
||||
// Generate a default port from SSL id. The port will always be the
|
||||
// same, but appear random from peer to peer.
|
||||
// Random port avoids clashes, improves anonymity.
|
||||
//
|
||||
|
||||
int new_port = htons(PQI_MIN_PORT_RNG + (RSRandom::random_u32() % (PQI_MAX_PORT - PQI_MIN_PORT_RNG)));
|
||||
uint16_t new_port = htons(PQI_MIN_PORT_RNG + (RSRandom::random_u32() % (PQI_MAX_PORT - PQI_MIN_PORT_RNG)));
|
||||
sockaddr_storage_setport(mLocalAddr, new_port);
|
||||
|
||||
addrChanged = true;
|
||||
|
@ -1365,16 +1365,63 @@ bool p3PeerMgrIMPL::UpdateOwnAddress( const sockaddr_storage& pLocalAddr,
|
||||
}
|
||||
|
||||
|
||||
bool p3PeerMgrIMPL::addPeerLocator(const RsPeerId &sslId, const RsUrl& locator)
|
||||
{
|
||||
std::string host(locator.host());
|
||||
pqiIpAddress ip;
|
||||
if(!locator.hasPort() || host.empty() ||
|
||||
!sockaddr_storage_inet_pton(ip.mAddr, host) ||
|
||||
!sockaddr_storage_setport(ip.mAddr, locator.port())) return false;
|
||||
ip.mSeenTime = time(NULL);
|
||||
|
||||
bool changed = false;
|
||||
|
||||
bool p3PeerMgrIMPL::setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr)
|
||||
if (sslId == AuthSSL::getAuthSSL()->OwnId())
|
||||
{
|
||||
RS_STACK_MUTEX(mPeerMtx);
|
||||
changed = mOwnState.ipAddrs.updateLocalAddrs(ip);
|
||||
}
|
||||
else
|
||||
{
|
||||
RS_STACK_MUTEX(mPeerMtx);
|
||||
auto it = mFriendList.find(sslId);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
it = mOthersList.find(sslId);
|
||||
if (it == mOthersList.end())
|
||||
{
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << __PRETTY_FUNCTION__ << "cannot add address "
|
||||
<< "info, peer id: " << sslId << " not found in list"
|
||||
<< std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
changed = it->second.ipAddrs.updateLocalAddrs(ip);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Added locator: "
|
||||
<< locator.toString() << std::endl;
|
||||
#endif
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::setLocalAddress( const RsPeerId &id,
|
||||
const sockaddr_storage &addr )
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
RS_STACK_MUTEX(mPeerMtx);
|
||||
if (!sockaddr_storage_same(mOwnState.localaddr, addr))
|
||||
{
|
||||
mOwnState.localaddr = addr;
|
||||
@ -1392,7 +1439,7 @@ bool p3PeerMgrIMPL::setLocalAddress(const RsPeerId &id, const struct sockaddr
|
||||
return changed;
|
||||
}
|
||||
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
RS_STACK_MUTEX(mPeerMtx);
|
||||
/* check if it is a friend */
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
@ -1400,7 +1447,9 @@ bool p3PeerMgrIMPL::setLocalAddress(const RsPeerId &id, const struct sockaddr
|
||||
if (mOthersList.end() == (it = mOthersList.find(id)))
|
||||
{
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres info : peer id not found in friend list id: " << id << std::endl;
|
||||
std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres "
|
||||
<< "info : peer id not found in friend list id: "
|
||||
<< id << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@ -1421,10 +1470,7 @@ bool p3PeerMgrIMPL::setLocalAddress(const RsPeerId &id, const struct sockaddr
|
||||
it->second.updateIpAddressList(ipAddressTimed);
|
||||
#endif
|
||||
|
||||
if (changed) {
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
}
|
||||
|
||||
if (changed) IndicateConfigChanged();
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
@ -163,6 +163,7 @@ virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list
|
||||
* 3) p3disc - reasonable
|
||||
*/
|
||||
|
||||
virtual bool addPeerLocator(const RsPeerId &ssl_id, const RsUrl& locator) = 0;
|
||||
virtual bool setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr) = 0;
|
||||
virtual bool setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr) = 0;
|
||||
virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns) = 0;
|
||||
@ -277,6 +278,7 @@ public:
|
||||
* 3) p3disc - reasonable
|
||||
*/
|
||||
|
||||
virtual bool addPeerLocator(const RsPeerId &ssl_id, const RsUrl& locator);
|
||||
virtual bool setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr);
|
||||
virtual bool setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr);
|
||||
virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns);
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <retroshare/rstypes.h>
|
||||
#include <retroshare/rsfiles.h>
|
||||
#include <retroshare/rsids.h>
|
||||
#include "util/rsurl.h"
|
||||
|
||||
/* The Main Interface Class - for information about your Peers
|
||||
* A peer is another RS instance, means associated with an SSL certificate
|
||||
@ -370,6 +371,7 @@ public:
|
||||
virtual bool setHiddenNode(const RsPeerId &id, const std::string &address, uint16_t port) = 0;
|
||||
virtual bool isHiddenNode(const RsPeerId &id) = 0;
|
||||
|
||||
virtual bool addPeerLocator(const RsPeerId &ssl_id, const RsUrl& locator) = 0;
|
||||
virtual bool setLocalAddress(const RsPeerId &ssl_id, const std::string &addr, uint16_t port) = 0;
|
||||
virtual bool setExtAddress( const RsPeerId &ssl_id, const std::string &addr, uint16_t port) = 0;
|
||||
virtual bool setDynDNS(const RsPeerId &id, const std::string &addr) = 0;
|
||||
@ -384,11 +386,30 @@ public:
|
||||
virtual bool resetOwnExternalAddressList() = 0;
|
||||
virtual bool getAllowServerIPDetermination() = 0 ;
|
||||
|
||||
/**
|
||||
* @brief Get RetroShare invite of the given peer
|
||||
* @param[in] sslId Id of the peer of which we want to generate an invite
|
||||
* @param[in] includeSignatures true to add key signatures to the invite
|
||||
* @param[in] includeExtraLocators false to avoid to add extra locators
|
||||
* @return invite string
|
||||
*/
|
||||
virtual std::string GetRetroshareInvite(
|
||||
const RsPeerId& sslId, bool includeSignatures = false,
|
||||
bool includeExtraLocators = true ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get RetroShare invite of our own peer
|
||||
* @param[in] includeSignatures true to add key signatures to the invite
|
||||
* @param[in] includeExtraLocators false to avoid to add extra locators
|
||||
* @return invite string
|
||||
*/
|
||||
virtual std::string GetRetroshareInvite(
|
||||
bool includeSignatures = false,
|
||||
bool includeExtraLocators = true ) = 0;
|
||||
|
||||
/* Auth Stuff */
|
||||
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 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 bool hasExportMinimal() = 0;
|
||||
|
||||
// Add keys to the keyring
|
||||
|
@ -904,6 +904,9 @@ bool p3Peers::setHiddenNode(const RsPeerId &id, const std::string &address, uin
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Peers::addPeerLocator(const RsPeerId &ssl_id, const RsUrl& locator)
|
||||
{ return mPeerMgr->addPeerLocator(ssl_id, locator); }
|
||||
|
||||
bool p3Peers::setLocalAddress(const RsPeerId &id,
|
||||
const std::string &addr_str, uint16_t port)
|
||||
{
|
||||
@ -1045,9 +1048,11 @@ bool p3Peers::setProxyServer(const uint32_t type, const std::string &addr_str, c
|
||||
|
||||
//===========================================================================
|
||||
/* Auth Stuff */
|
||||
std::string p3Peers::GetRetroshareInvite(bool include_signatures)
|
||||
std::string p3Peers::GetRetroshareInvite(
|
||||
bool include_signatures, bool includeExtraLocators )
|
||||
{
|
||||
return GetRetroshareInvite(getOwnId(),include_signatures);
|
||||
return GetRetroshareInvite(
|
||||
getOwnId(), include_signatures, includeExtraLocators );
|
||||
}
|
||||
std::string p3Peers::getPGPKey(const RsPgpId& pgp_id,bool include_signatures)
|
||||
{
|
||||
@ -1098,37 +1103,42 @@ bool p3Peers::GetPGPBase64StringAndCheckSum( const RsPgpId& gpg_id,
|
||||
return true ;
|
||||
}
|
||||
|
||||
std::string p3Peers::GetRetroshareInvite(const RsPeerId& ssl_id,bool include_signatures)
|
||||
std::string p3Peers::GetRetroshareInvite(
|
||||
const RsPeerId& ssl_id, bool include_signatures,
|
||||
bool includeExtraLocators )
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::GetRetroshareInvite()" << std::endl;
|
||||
std::cerr << __PRETTY_FUNCTION__ << std::endl;
|
||||
#endif
|
||||
|
||||
//add the sslid, location, ip local and external address after the signature
|
||||
RsPeerDetails Detail;
|
||||
std::string invite ;
|
||||
RsPeerDetails detail;
|
||||
std::string invite;
|
||||
|
||||
if (getPeerDetails(ssl_id, Detail))
|
||||
if (getPeerDetails(ssl_id, detail))
|
||||
{
|
||||
unsigned char *mem_block = NULL;
|
||||
if(!includeExtraLocators) detail.ipAddressList.clear();
|
||||
|
||||
unsigned char *mem_block = nullptr;
|
||||
size_t mem_block_size = 0;
|
||||
|
||||
if(!AuthGPG::getAuthGPG()->exportPublicKey(RsPgpId(Detail.gpg_id),mem_block,mem_block_size,false,include_signatures))
|
||||
if(!AuthGPG::getAuthGPG()->exportPublicKey(
|
||||
RsPgpId(detail.gpg_id), mem_block, mem_block_size, false,
|
||||
include_signatures ))
|
||||
{
|
||||
std::cerr << "Cannot output certificate for id \"" << Detail.gpg_id << "\". Sorry." << std::endl;
|
||||
return "" ;
|
||||
std::cerr << "Cannot output certificate for id \"" << detail.gpg_id
|
||||
<< "\". Sorry." << std::endl;
|
||||
return "";
|
||||
}
|
||||
|
||||
RsCertificate cert( Detail,mem_block,mem_block_size ) ;
|
||||
|
||||
delete[] mem_block ;
|
||||
|
||||
return cert.toStdString() ;
|
||||
RsCertificate cert(detail, mem_block, mem_block_size);
|
||||
delete[] mem_block;
|
||||
|
||||
return cert.toStdString();
|
||||
}
|
||||
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::GetRetroshareInvite() returns : \n" << invite << std::endl;
|
||||
std::cerr << __PRETTY_FUNCTION__ << " returns : \n" << invite << std::endl;
|
||||
#endif
|
||||
return invite;
|
||||
}
|
||||
@ -1148,11 +1158,12 @@ bool p3Peers::loadCertificateFromString(const std::string& cert, RsPeerId& ssl_
|
||||
return res ;
|
||||
}
|
||||
|
||||
bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetails &pd,uint32_t& error_code)
|
||||
bool p3Peers::loadDetailsFromStringCert( const std::string &certstr,
|
||||
RsPeerDetails &pd,
|
||||
uint32_t& error_code )
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::LoadCertificateFromString() ";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3Peers::LoadCertificateFromString() " << std::endl;
|
||||
#endif
|
||||
//parse the text to get ip address
|
||||
try
|
||||
@ -1192,9 +1203,11 @@ bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetai
|
||||
pd.localPort = cert.loc_port_us();
|
||||
pd.extAddr = cert.ext_ip_string();
|
||||
pd.extPort = cert.ext_port_us();
|
||||
pd.dyndns = cert.dns_string() ;
|
||||
pd.dyndns = cert.dns_string();
|
||||
for(const RsUrl& locator : cert.locators())
|
||||
pd.ipAddressList.push_back(locator.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(uint32_t e)
|
||||
{
|
||||
std::cerr << "ConnectFriendWizard : Parse ip address error :" << e << std::endl;
|
||||
|
@ -36,6 +36,7 @@
|
||||
#endif
|
||||
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "util/rsurl.h"
|
||||
|
||||
class p3LinkMgr;
|
||||
class p3PeerMgr;
|
||||
@ -96,7 +97,8 @@ public:
|
||||
virtual bool setHiddenNode(const RsPeerId &id, const std::string &address, uint16_t port);
|
||||
virtual bool isHiddenNode(const RsPeerId &id);
|
||||
|
||||
virtual bool setLocalAddress(const RsPeerId &id, const std::string &addr, uint16_t port);
|
||||
virtual bool addPeerLocator(const RsPeerId &ssl_id, const RsUrl& locator);
|
||||
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 setDynDNS(const RsPeerId &id, const std::string &dyndns);
|
||||
virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode);
|
||||
@ -113,11 +115,15 @@ public:
|
||||
|
||||
/* Auth Stuff */
|
||||
// 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 getPGPKey(const RsPgpId& pgp_id,bool include_signatures) ;
|
||||
virtual std::string GetRetroshareInvite(
|
||||
const RsPeerId& ssl_id, bool include_signatures = false,
|
||||
bool includeExtraLocators = true );
|
||||
virtual std::string getPGPKey(const RsPgpId& pgp_id,bool include_signatures);
|
||||
|
||||
// same but for own id
|
||||
virtual std::string GetRetroshareInvite(bool include_signatures);
|
||||
virtual std::string GetRetroshareInvite(
|
||||
bool include_signatures = false,
|
||||
bool includeExtraLocators = true );
|
||||
virtual bool GetPGPBase64StringAndCheckSum(const RsPgpId& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum);
|
||||
|
||||
virtual bool hasExportMinimal();
|
||||
|
@ -291,8 +291,8 @@ bool RsTypeSerializer::from_JSON( const std::string& memberName,
|
||||
uint64_t& member, RsJson& jDoc )
|
||||
{
|
||||
SAFE_GET_JSON_V();
|
||||
ret = ret && v.IsUint();
|
||||
if(ret) member = v.GetUint();
|
||||
ret = ret && v.IsUint64();
|
||||
if(ret) member = v.GetUint64();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,11 @@ bitdht {
|
||||
!include("../../libbitdht/src/use_libbitdht.pri"):error("Including")
|
||||
}
|
||||
|
||||
# when rapidjson is mainstream on all distribs, we will not need the sources
|
||||
# anymore in the meantime, they are part of the RS directory so that it is
|
||||
# always possible to find them
|
||||
INCLUDEPATH *= $$system_path($$clean_path($${PWD}/../../rapidjson-1.1.0))
|
||||
|
||||
sLibs =
|
||||
mLibs = $$RS_SQL_LIB ssl crypto $$RS_THREAD_LIB $$RS_UPNP_LIB
|
||||
dLibs =
|
||||
|
@ -142,6 +142,7 @@ bool sockaddr_storage_sameip(const struct sockaddr_storage &addr, const struct s
|
||||
|
||||
// string,
|
||||
std::string sockaddr_storage_tostring(const struct sockaddr_storage &addr);
|
||||
bool sockaddr_storage_fromString(const std::string& str, sockaddr_storage &addr);
|
||||
std::string sockaddr_storage_familytostring(const struct sockaddr_storage &addr);
|
||||
std::string sockaddr_storage_iptostring(const struct sockaddr_storage &addr);
|
||||
std::string sockaddr_storage_porttostring(const struct sockaddr_storage &addr);
|
||||
|
@ -24,6 +24,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "util/rsurl.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <cstdlib>
|
||||
@ -190,8 +192,7 @@ bool sockaddr_storage_copyip(struct sockaddr_storage &dst, const struct sockaddr
|
||||
uint16_t sockaddr_storage_port(const struct sockaddr_storage &addr)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_port()";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "sockaddr_storage_port()" << std::endl;
|
||||
#endif
|
||||
switch(addr.ss_family)
|
||||
{
|
||||
@ -201,8 +202,10 @@ uint16_t sockaddr_storage_port(const struct sockaddr_storage &addr)
|
||||
return sockaddr_storage_ipv6_port(addr);
|
||||
default:
|
||||
std::cerr << "sockaddr_storage_port() invalid addr.ss_family" << std::endl;
|
||||
#ifdef SS_DEBUG
|
||||
sockaddr_storage_dump(addr);
|
||||
print_stacktrace();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
@ -491,27 +494,32 @@ bool sockaddr_storage_sameip(const struct sockaddr_storage &addr, const struct s
|
||||
|
||||
std::string sockaddr_storage_tostring(const struct sockaddr_storage &addr)
|
||||
{
|
||||
std::string output;
|
||||
output += sockaddr_storage_familytostring(addr);
|
||||
RsUrl url;
|
||||
|
||||
switch(addr.ss_family)
|
||||
{
|
||||
case AF_INET:
|
||||
output += "=";
|
||||
output += sockaddr_storage_iptostring(addr);
|
||||
output += ":";
|
||||
output += sockaddr_storage_porttostring(addr);
|
||||
url.setScheme("ipv4");
|
||||
break;
|
||||
case AF_INET6:
|
||||
output += "=[";
|
||||
output += sockaddr_storage_iptostring(addr);
|
||||
output += "]:";
|
||||
output += sockaddr_storage_porttostring(addr);
|
||||
url.setScheme("ipv6");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
return "AF_INVALID";
|
||||
}
|
||||
return output;
|
||||
|
||||
url.setHost(sockaddr_storage_iptostring(addr))
|
||||
.setPort(sockaddr_storage_port(addr));
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
bool sockaddr_storage_fromString(const std::string& str, sockaddr_storage &addr)
|
||||
{
|
||||
RsUrl url(str);
|
||||
bool valid = sockaddr_storage_inet_pton(addr, url.host());
|
||||
if(url.hasPort()) sockaddr_storage_setport(addr, url.port());
|
||||
return valid;
|
||||
}
|
||||
|
||||
void sockaddr_storage_dump(const sockaddr_storage & addr, std::string * outputString)
|
||||
@ -606,9 +614,11 @@ std::string sockaddr_storage_iptostring(const struct sockaddr_storage &addr)
|
||||
break;
|
||||
default:
|
||||
output = "INVALID_IP";
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Got invalid IP:" << std::endl;
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Got invalid IP!" << std::endl;
|
||||
#ifdef SS_DEBUG
|
||||
sockaddr_storage_dump(addr);
|
||||
print_stacktrace();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return output;
|
||||
|
267
libretroshare/src/util/rsurl.cc
Normal file
267
libretroshare/src/util/rsurl.cc
Normal file
@ -0,0 +1,267 @@
|
||||
/*
|
||||
* RetroShare
|
||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//#include "util/rsurl.h"
|
||||
#include "rsurl.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
RsUrl::RsUrl() : mPort(0), mHasPort(false) {}
|
||||
|
||||
RsUrl::RsUrl(const std::string& urlStr) : mPort(0), mHasPort(false)
|
||||
{ fromString(urlStr); }
|
||||
|
||||
RsUrl& RsUrl::fromString(const std::string& urlStr)
|
||||
{
|
||||
size_t endI = urlStr.size()-1;
|
||||
|
||||
size_t schemeEndI = urlStr.find(schemeSeparator);
|
||||
if(schemeEndI >= endI)
|
||||
{
|
||||
mScheme = urlStr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
mScheme = urlStr.substr(0, schemeEndI);
|
||||
|
||||
size_t hostBeginI = schemeEndI + 3;
|
||||
if(hostBeginI >= endI) return *this;
|
||||
|
||||
bool hasSquareBr = (urlStr[hostBeginI] == ipv6WrapOpen[0]);
|
||||
size_t hostEndI;
|
||||
if(hasSquareBr)
|
||||
{
|
||||
if(++hostBeginI >= endI) return *this;
|
||||
hostEndI = urlStr.find(ipv6WrapClose, hostBeginI);
|
||||
mHost = urlStr.substr(hostBeginI, hostEndI - hostBeginI - 1);
|
||||
++hostEndI;
|
||||
}
|
||||
else
|
||||
{
|
||||
hostEndI = urlStr.find(pathSeparator, hostBeginI);
|
||||
hostEndI = min(hostEndI, urlStr.find(portSeparator, hostBeginI));
|
||||
hostEndI = min(hostEndI, urlStr.find(querySeparator, hostBeginI));
|
||||
hostEndI = min(hostEndI, urlStr.find(fragmentSeparator, hostBeginI));
|
||||
|
||||
mHost = urlStr.substr(hostBeginI, hostEndI - hostBeginI);
|
||||
}
|
||||
|
||||
if( hostEndI >= endI ) return *this;
|
||||
|
||||
mHasPort = (sscanf(&urlStr[hostEndI], ":%hu", &mPort) == 1);
|
||||
|
||||
size_t pathBeginI = urlStr.find(pathSeparator, hostBeginI);
|
||||
size_t pathEndI = string::npos;
|
||||
if(pathBeginI < endI)
|
||||
{
|
||||
pathEndI = urlStr.find(querySeparator, pathBeginI);
|
||||
pathEndI = min(pathEndI, urlStr.find(fragmentSeparator, pathBeginI));
|
||||
mPath = UrlDecode(urlStr.substr(pathBeginI, pathEndI - pathBeginI));
|
||||
if(pathEndI >= endI) return *this;
|
||||
}
|
||||
|
||||
size_t queryBeginI = urlStr.find(querySeparator, hostBeginI);
|
||||
size_t queryEndI = urlStr.find(fragmentSeparator, hostBeginI);
|
||||
if(queryBeginI < endI)
|
||||
{
|
||||
string qStr = urlStr.substr(queryBeginI+1, queryEndI-queryBeginI-1);
|
||||
|
||||
size_t kPos = 0;
|
||||
size_t assPos = qStr.find(queryAssign);
|
||||
do
|
||||
{
|
||||
size_t vEndPos = qStr.find(queryFieldSep, assPos);
|
||||
mQuery.insert( std::make_pair( qStr.substr(kPos, assPos-kPos),
|
||||
UrlDecode(qStr.substr(assPos+1, vEndPos-assPos-1))
|
||||
) );
|
||||
kPos = vEndPos+1;
|
||||
assPos = qStr.find(queryAssign, vEndPos);
|
||||
}
|
||||
while(assPos < endI);
|
||||
|
||||
if(queryEndI >= endI) return *this;
|
||||
}
|
||||
|
||||
size_t fragmentBeginI = urlStr.find(fragmentSeparator, hostBeginI);
|
||||
if(fragmentBeginI < endI)
|
||||
mFragment = UrlDecode(urlStr.substr(++fragmentBeginI));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string RsUrl::toString() const
|
||||
{
|
||||
std::string urlStr(mScheme);
|
||||
urlStr += schemeSeparator;
|
||||
|
||||
if(!mHost.empty())
|
||||
{
|
||||
if(mHost.find(ipv6Separator) != string::npos &&
|
||||
mHost[0] != ipv6WrapOpen[0] )
|
||||
urlStr += ipv6WrapOpen + mHost + ipv6WrapClose;
|
||||
else urlStr += mHost;
|
||||
}
|
||||
|
||||
if(mHasPort) urlStr += portSeparator + std::to_string(mPort);
|
||||
|
||||
urlStr += UrlEncode(mPath, pathSeparator);
|
||||
|
||||
bool hasQuery = !mQuery.empty();
|
||||
if(hasQuery) urlStr += querySeparator;
|
||||
for(auto&& kv : mQuery)
|
||||
{
|
||||
urlStr += kv.first;
|
||||
urlStr += queryAssign;
|
||||
urlStr += UrlEncode(kv.second);
|
||||
urlStr += queryFieldSep;
|
||||
}
|
||||
if(hasQuery) urlStr.pop_back();
|
||||
|
||||
if(!mFragment.empty()) urlStr += fragmentSeparator + UrlEncode(mFragment);
|
||||
|
||||
return urlStr;
|
||||
}
|
||||
|
||||
const std::string& RsUrl::scheme() const { return mScheme; }
|
||||
RsUrl& RsUrl::setScheme(const std::string& scheme)
|
||||
{
|
||||
mScheme = scheme;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::string& RsUrl::host() const { return mHost; }
|
||||
RsUrl& RsUrl::setHost(const std::string& host)
|
||||
{
|
||||
mHost = host;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool RsUrl::hasPort() const { return mHasPort; }
|
||||
uint16_t RsUrl::port(uint16_t def) const
|
||||
{
|
||||
if(mHasPort) return mPort;
|
||||
return def;
|
||||
}
|
||||
RsUrl& RsUrl::setPort(uint16_t port)
|
||||
{
|
||||
mPort = port;
|
||||
mHasPort = true;
|
||||
return *this;
|
||||
}
|
||||
RsUrl& RsUrl::unsetPort()
|
||||
{
|
||||
mPort = 0;
|
||||
mHasPort = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::string& RsUrl::path() const { return mPath; }
|
||||
RsUrl& RsUrl::setPath(const std::string& path)
|
||||
{
|
||||
mPath = path;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::map<std::string, std::string>& RsUrl::query() const
|
||||
{ return mQuery; }
|
||||
RsUrl& RsUrl::setQuery(const std::map<std::string, std::string>& query)
|
||||
{
|
||||
mQuery = query;
|
||||
return *this;
|
||||
}
|
||||
RsUrl& RsUrl::setQueryKV(const std::string& key, const std::string& value)
|
||||
{
|
||||
mQuery.insert(std::make_pair(key, value));
|
||||
return *this;
|
||||
}
|
||||
RsUrl& RsUrl::delQueryK(const std::string& key)
|
||||
{
|
||||
mQuery.erase(key);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::string& RsUrl::fragment() const { return mFragment; }
|
||||
RsUrl& RsUrl::setFragment(const std::string& fragment)
|
||||
{
|
||||
mFragment = fragment;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*static*/ std::string RsUrl::UrlEncode( const std::string& str,
|
||||
const std::string& ignore )
|
||||
{
|
||||
ostringstream escaped;
|
||||
escaped.fill('0');
|
||||
escaped << hex;
|
||||
|
||||
for (string::value_type c : str)
|
||||
{
|
||||
// Keep alphanumeric and other accepted characters intact
|
||||
if ( isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~'
|
||||
|| ignore.find(c) != string::npos )
|
||||
{
|
||||
escaped << c;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Any other characters are percent-encoded
|
||||
escaped << uppercase;
|
||||
escaped << '%' << setw(2) << int((unsigned char) c);
|
||||
escaped << nouppercase;
|
||||
}
|
||||
|
||||
return escaped.str();
|
||||
}
|
||||
|
||||
/*static*/ std::string RsUrl::UrlDecode(const std::string& str)
|
||||
{
|
||||
ostringstream decoded;
|
||||
|
||||
size_t len = str.size();
|
||||
size_t boundary = len-2; // % Encoded char must be at least 2 hex char
|
||||
for (size_t i = 0; i < len; ++i)
|
||||
{
|
||||
|
||||
if(str[i] == '%' && i < boundary)
|
||||
{
|
||||
decoded << static_cast<char>(stoi(str.substr(++i, 2), 0, 16));
|
||||
++i;
|
||||
}
|
||||
else decoded << str[i];
|
||||
}
|
||||
|
||||
return decoded.str();
|
||||
}
|
||||
|
||||
/*static*/ const std::string RsUrl::schemeSeparator("://");
|
||||
/*static*/ const std::string RsUrl::ipv6WrapOpen("[");
|
||||
/*static*/ const std::string RsUrl::ipv6Separator(":");
|
||||
/*static*/ const std::string RsUrl::ipv6WrapClose("]");
|
||||
/*static*/ const std::string RsUrl::portSeparator(":");
|
||||
/*static*/ const std::string RsUrl::pathSeparator("/");
|
||||
/*static*/ const std::string RsUrl::querySeparator("?");
|
||||
/*static*/ const std::string RsUrl::queryAssign("=");
|
||||
/*static*/ const std::string RsUrl::queryFieldSep("&");
|
||||
/*static*/ const std::string RsUrl::fragmentSeparator("#");
|
||||
|
102
libretroshare/src/util/rsurl.h
Normal file
102
libretroshare/src/util/rsurl.h
Normal file
@ -0,0 +1,102 @@
|
||||
#pragma once
|
||||
/*
|
||||
* RetroShare
|
||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
/**
|
||||
* Very simplistic and minimal URL helper class for RetroShare, after looking
|
||||
* for a small and self-contained C/C++ URL parsing and manipulation library,
|
||||
* haven't found nothing satisfactory except for implementation like QUrl that
|
||||
* rely on bigger library.
|
||||
* ATM this implementation is not standard compliant and doesn't aim to be.
|
||||
* Improvements to this are welcome.
|
||||
*
|
||||
* Anyway this should support most common URLs of the form
|
||||
* scheme://host[:port][/path][?query][#fragment]
|
||||
*/
|
||||
struct RsUrl
|
||||
{
|
||||
RsUrl();
|
||||
RsUrl(const std::string& urlStr);
|
||||
|
||||
RsUrl& fromString(const std::string& urlStr);
|
||||
std::string toString() const;
|
||||
|
||||
const std::string& scheme() const;
|
||||
RsUrl& setScheme(const std::string& scheme);
|
||||
|
||||
const std::string& host() const;
|
||||
RsUrl& setHost(const std::string& host);
|
||||
|
||||
bool hasPort() const;
|
||||
uint16_t port(uint16_t def = 0) const;
|
||||
RsUrl& setPort(uint16_t port);
|
||||
RsUrl& unsetPort();
|
||||
|
||||
const std::string& path() const;
|
||||
RsUrl& setPath(const std::string& path);
|
||||
|
||||
const std::map<std::string, std::string>& query() const;
|
||||
RsUrl& setQuery(const std::map<std::string, std::string>& query);
|
||||
RsUrl& setQueryKV(const std::string& key, const std::string& value);
|
||||
RsUrl& delQueryK(const std::string& key);
|
||||
|
||||
const std::string& fragment() const;
|
||||
RsUrl& setFragment(const std::string& fragment);
|
||||
|
||||
static std::string UrlEncode(const std::string& str,
|
||||
const std::string& ignoreChars = "");
|
||||
static std::string UrlDecode(const std::string& str);
|
||||
|
||||
inline bool operator<(const RsUrl& rhs) const
|
||||
{ return toString() < rhs.toString(); }
|
||||
inline bool operator>(const RsUrl& rhs) const
|
||||
{ return toString() > rhs.toString(); }
|
||||
inline bool operator<=(const RsUrl& rhs) const
|
||||
{ return toString() <= rhs.toString(); }
|
||||
inline bool operator>=(const RsUrl& rhs) const
|
||||
{ return toString() >= rhs.toString(); }
|
||||
inline bool operator==(const RsUrl& rhs) const
|
||||
{ return toString() == rhs.toString(); }
|
||||
inline bool operator!=(const RsUrl& rhs) const
|
||||
{ return toString() != rhs.toString(); }
|
||||
|
||||
static const std::string schemeSeparator;
|
||||
static const std::string ipv6WrapOpen;
|
||||
static const std::string ipv6Separator;
|
||||
static const std::string ipv6WrapClose;
|
||||
static const std::string portSeparator;
|
||||
static const std::string pathSeparator;
|
||||
static const std::string querySeparator;
|
||||
static const std::string queryAssign;
|
||||
static const std::string queryFieldSep;
|
||||
static const std::string fragmentSeparator;
|
||||
|
||||
private:
|
||||
|
||||
std::string mScheme;
|
||||
std::string mHost;
|
||||
uint16_t mPort;
|
||||
bool mHasPort;
|
||||
std::string mPath;
|
||||
std::map<std::string, std::string> mQuery;
|
||||
std::string mFragment;
|
||||
};
|
||||
|
@ -2066,6 +2066,10 @@ bool FriendList::importFriendlist(QString &fileName, bool &errorPeers, bool &err
|
||||
rsPeers->setDynDNS(rsPeerDetails.id, rsPeerDetails.dyndns);
|
||||
if (!rsPeerDetails.location.empty())
|
||||
rsPeers->setLocation(rsPeerDetails.id, rsPeerDetails.location);
|
||||
for(auto&& ipr : rsPeerDetails.ipAddressList)
|
||||
rsPeers->addPeerLocator(
|
||||
rsPeerDetails.id,
|
||||
RsUrl(ipr.substr(0, ipr.find(' '))) );
|
||||
}
|
||||
} else if (!rsPeerDetails.gpg_id.isNull()) {
|
||||
// only pgp id is avaiable
|
||||
|
@ -974,6 +974,10 @@ void ConnectFriendWizard::accept()
|
||||
std::cerr << "ConnectFriendWizard::accept() : setting DynDNS." << std::endl;
|
||||
rsPeers->setDynDNS(peerDetails.id, peerDetails.dyndns);
|
||||
}
|
||||
for(auto&& ipr : peerDetails.ipAddressList)
|
||||
rsPeers->addPeerLocator(
|
||||
peerDetails.id,
|
||||
RsUrl(ipr.substr(0, ipr.find(' '))) );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,12 +2,12 @@
|
||||
#include "RsGxsUpdateBroadcastBase.h"
|
||||
|
||||
RsGxsUpdateBroadcastWidget::RsGxsUpdateBroadcastWidget(RsGxsIfaceHelper *ifaceImpl, QWidget *parent, Qt::WindowFlags flags)
|
||||
: QWidget(parent, flags)
|
||||
: QWidget(parent, flags)
|
||||
{
|
||||
mBase = new RsGxsUpdateBroadcastBase(ifaceImpl, this);
|
||||
connect(mBase, SIGNAL(fillDisplay(bool)), this, SLOT(fillDisplay(bool)));
|
||||
mBase = new RsGxsUpdateBroadcastBase(ifaceImpl, this);
|
||||
connect(mBase, SIGNAL(fillDisplay(bool)), this, SLOT(fillDisplay(bool)));
|
||||
|
||||
mInterfaceHelper = ifaceImpl;
|
||||
mInterfaceHelper = ifaceImpl;
|
||||
}
|
||||
|
||||
RsGxsUpdateBroadcastWidget::~RsGxsUpdateBroadcastWidget()
|
||||
@ -16,17 +16,17 @@ RsGxsUpdateBroadcastWidget::~RsGxsUpdateBroadcastWidget()
|
||||
|
||||
void RsGxsUpdateBroadcastWidget::fillComplete()
|
||||
{
|
||||
mBase->fillComplete();
|
||||
mBase->fillComplete();
|
||||
}
|
||||
|
||||
void RsGxsUpdateBroadcastWidget::setUpdateWhenInvisible(bool update)
|
||||
{
|
||||
mBase->setUpdateWhenInvisible(update);
|
||||
mBase->setUpdateWhenInvisible(update);
|
||||
}
|
||||
|
||||
const std::set<RsGxsGroupId> &RsGxsUpdateBroadcastWidget::getGrpIds()
|
||||
{
|
||||
return mBase->getGrpIds();
|
||||
return mBase->getGrpIds();
|
||||
}
|
||||
|
||||
const std::set<TurtleRequestId>& RsGxsUpdateBroadcastWidget::getSearchResults()
|
||||
@ -35,37 +35,37 @@ const std::set<TurtleRequestId>& RsGxsUpdateBroadcastWidget::getSearchResults()
|
||||
}
|
||||
const std::set<RsGxsGroupId> &RsGxsUpdateBroadcastWidget::getGrpIdsMeta()
|
||||
{
|
||||
return mBase->getGrpIdsMeta();
|
||||
return mBase->getGrpIdsMeta();
|
||||
}
|
||||
|
||||
void RsGxsUpdateBroadcastWidget::getAllGrpIds(std::set<RsGxsGroupId> &grpIds)
|
||||
{
|
||||
mBase->getAllGrpIds(grpIds);
|
||||
mBase->getAllGrpIds(grpIds);
|
||||
}
|
||||
|
||||
const std::map<RsGxsGroupId, std::set<RsGxsMessageId> > &RsGxsUpdateBroadcastWidget::getMsgIds()
|
||||
{
|
||||
return mBase->getMsgIds();
|
||||
return mBase->getMsgIds();
|
||||
}
|
||||
|
||||
const std::map<RsGxsGroupId, std::set<RsGxsMessageId> > &RsGxsUpdateBroadcastWidget::getMsgIdsMeta()
|
||||
{
|
||||
return mBase->getMsgIdsMeta();
|
||||
return mBase->getMsgIdsMeta();
|
||||
}
|
||||
|
||||
void RsGxsUpdateBroadcastWidget::getAllMsgIds(std::map<RsGxsGroupId, std::set<RsGxsMessageId> > &msgIds)
|
||||
{
|
||||
mBase->getAllMsgIds(msgIds);
|
||||
mBase->getAllMsgIds(msgIds);
|
||||
}
|
||||
|
||||
void RsGxsUpdateBroadcastWidget::fillDisplay(bool complete)
|
||||
{
|
||||
updateDisplay(complete);
|
||||
update(); // Qt flush
|
||||
updateDisplay(complete);
|
||||
update(); // Qt flush
|
||||
}
|
||||
|
||||
void RsGxsUpdateBroadcastWidget::showEvent(QShowEvent *event)
|
||||
{
|
||||
mBase->showEvent(event);
|
||||
QWidget::showEvent(event);
|
||||
mBase->showEvent(event);
|
||||
QWidget::showEvent(event);
|
||||
}
|
||||
|
@ -10,11 +10,6 @@ DEFINES += TARGET=\\\"$${TARGET}\\\"
|
||||
DEPENDPATH *= $${PWD} $${RS_INCLUDE_DIR} retroshare-gui
|
||||
INCLUDEPATH *= $${PWD} retroshare-gui
|
||||
|
||||
# when rapidjson is mainstream on all distribs, we will not need the sources anymore
|
||||
# in the meantime, they are part of the RS directory so that it is always possible to find them
|
||||
|
||||
INCLUDEPATH += ../../rapidjson-1.1.0
|
||||
|
||||
libresapihttpserver {
|
||||
!include("../../libresapi/src/use_libresapi.pri"):error("Including")
|
||||
HEADERS *= gui/settings/WebuiPage.h
|
||||
|
@ -16,10 +16,6 @@ libresapihttpserver {
|
||||
|
||||
!include("../../libretroshare/src/use_libretroshare.pri"):error("Including")
|
||||
|
||||
# when rapidjson is mainstream on all distribs, we will not need the sources anymore
|
||||
# in the meantime, they are part of the RS directory so that it is always possible to find them
|
||||
|
||||
INCLUDEPATH += ../../rapidjson-1.1.0
|
||||
|
||||
################################# Linux ##########################################
|
||||
linux-* {
|
||||
|
Loading…
Reference in New Issue
Block a user