Skip to content
Snippets Groups Projects
Commit a10fb62a authored by Hugo Lefeuvre's avatar Hugo Lefeuvre Committed by Sébastien Blin
Browse files

uri: take ProtocolHint in account in format()


20e8d7b3 unintentionally dropped ProtocolHint support in format().
ProtocolHint is meant to improve format() output when no scheme was
provided in the original uri. This commit addresses this issue.

20e8d7b3 intentionally dropped "active defaulting" in the URI class,
meaning that if no URI scheme was provided in the original URI and if
the scheme couldn't be guessed by ProtocolHint then no scheme will be
present in format()'s output. However this breaks quite a few things
in the old LRC. This commit reintroduces active defaulting to
URI::SchemeType::RING.

Also, finish to cleanup strip() scheme detection.

Change-Id: Ibc9decfb9d9f72d070302702de46d376eecf5c48
Gitlab: #390
Reviewed-by: default avatarSebastien Blin <sebastien.blin@savoirfairelinux.com>
parent 85f03e35
No related branches found
No related tags found
No related merge requests found
...@@ -86,6 +86,7 @@ const std::map<URI::Transport, const char*> URIPimpl::transportNames = { ...@@ -86,6 +86,7 @@ const std::map<URI::Transport, const char*> URIPimpl::transportNames = {
}; };
const std::map<URI::SchemeType, const char*> URIPimpl::schemeNames = { const std::map<URI::SchemeType, const char*> URIPimpl::schemeNames = {
{ URI::SchemeType::NONE, "" },
{ URI::SchemeType::SIP, "sip:" }, { URI::SchemeType::SIP, "sip:" },
{ URI::SchemeType::SIPS, "sips:" }, { URI::SchemeType::SIPS, "sips:" },
{ URI::SchemeType::RING, "ring:" } { URI::SchemeType::RING, "ring:" }
...@@ -169,17 +170,13 @@ QString URIPimpl::strip(const QString& uri, URI::SchemeType& schemeType, QString ...@@ -169,17 +170,13 @@ QString URIPimpl::strip(const QString& uri, URI::SchemeType& schemeType, QString
} }
} }
if (scheme == URIPimpl::schemeNames.at(URI::SchemeType::SIP)) {
schemeType = URI::SchemeType::SIP;
} else if (scheme == URIPimpl::schemeNames.at(URI::SchemeType::RING)) {
schemeType = URI::SchemeType::RING;
} else if (scheme == URIPimpl::schemeNames.at(URI::SchemeType::SIPS)) {
schemeType = URI::SchemeType::SIPS;
} else if (!scheme.isEmpty()) {
schemeType = URI::SchemeType::UNRECOGNIZED; schemeType = URI::SchemeType::UNRECOGNIZED;
} else { auto it = std::find_if(schemeNames.begin(), schemeNames.end(), [&scheme] (auto& it) {
schemeType = URI::SchemeType::NONE; return it.second == scheme;
} });
if (it != URIPimpl::schemeNames.end())
schemeType = it->first;
return uri.mid(scheme.size(), uri.size()); return uri.mid(scheme.size(), uri.size());
} }
...@@ -468,13 +465,36 @@ QString URI::format(FlagPack<URI::Section> sections) const ...@@ -468,13 +465,36 @@ QString URI::format(FlagPack<URI::Section> sections) const
pimpl_->parseHostname(); pimpl_->parseHostname();
} }
auto header_type = pimpl_->m_HeaderType;
if (header_type == SchemeType::NONE) {
switch (protocolHint()) {
case ProtocolHint::RING:
case ProtocolHint::RING_USERNAME:
header_type = SchemeType::RING;
break;
case ProtocolHint::SIP_HOST:
case ProtocolHint::SIP_OTHER:
case ProtocolHint::IP:
header_type = SchemeType::SIP;
break;
default:
header_type = SchemeType::RING;
break;
}
}
QString ret; QString ret;
if (sections & URI::Section::CHEVRONS) if (sections & URI::Section::CHEVRONS)
ret += '<'; ret += '<';
if (sections & URI::Section::SCHEME) if (sections & URI::Section::SCHEME) {
if (header_type == SchemeType::UNRECOGNIZED) {
ret += pimpl_->m_Scheme; ret += pimpl_->m_Scheme;
} else {
ret += URIPimpl::schemeNames.at(header_type);
}
}
if (sections & URI::Section::USER_INFO) if (sections & URI::Section::USER_INFO)
ret += pimpl_->m_Userinfo; ret += pimpl_->m_Userinfo;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment