mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
Share additional addresses via RsCertificate
This commit is contained in:
parent
8542abd4f0
commit
bed856425f
13 changed files with 267 additions and 149 deletions
|
@ -192,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)
|
||||
{
|
||||
|
@ -203,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;
|
||||
|
@ -504,7 +505,7 @@ std::string sockaddr_storage_tostring(const struct sockaddr_storage &addr)
|
|||
url.setScheme("ipv6");
|
||||
break;
|
||||
default:
|
||||
return "INVALID_IP";
|
||||
return "AF_INVALID";
|
||||
}
|
||||
|
||||
url.setHost(sockaddr_storage_iptostring(addr))
|
||||
|
@ -613,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;
|
||||
|
|
|
@ -34,10 +34,10 @@ RsUrl::RsUrl(const std::string& urlStr) : mPort(0), mHasPort(false)
|
|||
|
||||
RsUrl& RsUrl::fromString(const std::string& urlStr)
|
||||
{
|
||||
size_t urlSize = urlStr.size();
|
||||
size_t endI = urlStr.size()-1;
|
||||
|
||||
size_t schemeEndI = urlStr.find(schemeSeparator);
|
||||
if(schemeEndI == string::npos)
|
||||
if(schemeEndI >= endI)
|
||||
{
|
||||
mScheme = urlStr;
|
||||
return *this;
|
||||
|
@ -46,15 +46,16 @@ RsUrl& RsUrl::fromString(const std::string& urlStr)
|
|||
mScheme = urlStr.substr(0, schemeEndI);
|
||||
|
||||
size_t hostBeginI = schemeEndI + 3;
|
||||
if(hostBeginI >= urlSize) return *this;
|
||||
if(hostBeginI >= endI) return *this;
|
||||
|
||||
bool hasSquareBr = (urlStr[hostBeginI] == ipv6WrapOpen[0]);
|
||||
size_t hostEndI;
|
||||
if(hasSquareBr)
|
||||
{
|
||||
if(++hostBeginI >= urlSize) return *this;
|
||||
if(++hostBeginI >= endI) return *this;
|
||||
hostEndI = urlStr.find(ipv6WrapClose, hostBeginI);
|
||||
mHost = urlStr.substr(hostBeginI, hostEndI - hostBeginI - 1);
|
||||
++hostEndI;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -64,24 +65,25 @@ RsUrl& RsUrl::fromString(const std::string& urlStr)
|
|||
hostEndI = min(hostEndI, urlStr.find(fragmentSeparator, hostBeginI));
|
||||
|
||||
mHost = urlStr.substr(hostBeginI, hostEndI - hostBeginI);
|
||||
if(hostEndI == string::npos) return *this;
|
||||
}
|
||||
|
||||
if( hostEndI >= endI ) return *this;
|
||||
|
||||
mHasPort = (sscanf(&urlStr[hostEndI], ":%hu", &mPort) == 1);
|
||||
|
||||
size_t pathBeginI = urlStr.find(pathSeparator, hostEndI);
|
||||
size_t pathBeginI = urlStr.find(pathSeparator, hostBeginI);
|
||||
size_t pathEndI = string::npos;
|
||||
if(pathBeginI != 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 == string::npos) return *this;
|
||||
if(pathEndI >= endI) return *this;
|
||||
}
|
||||
|
||||
size_t queryBeginI = urlStr.find(querySeparator, schemeEndI);
|
||||
size_t queryEndI = urlStr.find(fragmentSeparator, schemeEndI);
|
||||
if(queryBeginI != string::npos)
|
||||
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);
|
||||
|
||||
|
@ -96,14 +98,16 @@ RsUrl& RsUrl::fromString(const std::string& urlStr)
|
|||
kPos = vEndPos+1;
|
||||
assPos = qStr.find(queryAssign, vEndPos);
|
||||
}
|
||||
while(assPos != string::npos);
|
||||
while(assPos < endI);
|
||||
|
||||
if(queryEndI == string::npos) return *this;
|
||||
if(queryEndI >= endI) return *this;
|
||||
}
|
||||
|
||||
size_t fragmentBeginI = urlStr.find(fragmentSeparator, schemeEndI);
|
||||
if(fragmentBeginI != string::npos)
|
||||
size_t fragmentBeginI = urlStr.find(fragmentSeparator, hostBeginI);
|
||||
if(fragmentBeginI < endI)
|
||||
mFragment = UrlDecode(urlStr.substr(++fragmentBeginI));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string RsUrl::toString() const
|
||||
|
|
|
@ -65,17 +65,17 @@ struct RsUrl
|
|||
const std::string& ignoreChars = "");
|
||||
static std::string UrlDecode(const std::string& str);
|
||||
|
||||
inline bool operator<(const RsUrl& rhs)
|
||||
inline bool operator<(const RsUrl& rhs) const
|
||||
{ return toString() < rhs.toString(); }
|
||||
inline bool operator>(const RsUrl& rhs)
|
||||
inline bool operator>(const RsUrl& rhs) const
|
||||
{ return toString() > rhs.toString(); }
|
||||
inline bool operator<=(const RsUrl& rhs)
|
||||
inline bool operator<=(const RsUrl& rhs) const
|
||||
{ return toString() <= rhs.toString(); }
|
||||
inline bool operator>=(const RsUrl& rhs)
|
||||
inline bool operator>=(const RsUrl& rhs) const
|
||||
{ return toString() >= rhs.toString(); }
|
||||
inline bool operator==(const RsUrl& rhs)
|
||||
inline bool operator==(const RsUrl& rhs) const
|
||||
{ return toString() == rhs.toString(); }
|
||||
inline bool operator!=(const RsUrl& rhs)
|
||||
inline bool operator!=(const RsUrl& rhs) const
|
||||
{ return toString() != rhs.toString(); }
|
||||
|
||||
static const std::string schemeSeparator;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue