Commit fed16f24 authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Sébastien Blin

uri: modify uri strip regex to be able to adapt more generalized format

Change-Id: I4072059caffc550c883c9678d3884b90e5d2c327
parent fcd3a347
......@@ -362,16 +362,14 @@ ContactModel::searchContact(const QString& query)
auto uri = URI(query);
auto uriScheme = uri.schemeType();
if (uri.schemeType() == URI::SchemeType::NONE) {
// uri has no scheme, default to current account scheme
if (owner.profileInfo.type == profile::Type::SIP) {
uriScheme = URI::SchemeType::SIP;
} else if (owner.profileInfo.type == profile::Type::RING) {
uriScheme = URI::SchemeType::RING;
}
if (static_cast<int>(uriScheme) > 2 && owner.profileInfo.type == profile::Type::SIP) {
// sip account do not care if schemeType is NONE, or UNRECOGNIZED (enum value > 2)
uriScheme = URI::SchemeType::SIP;
} else if (uriScheme == URI::SchemeType::NONE && owner.profileInfo.type == profile::Type::RING) {
uriScheme = URI::SchemeType::RING;
}
if (uriScheme == URI::SchemeType::SIP && owner.profileInfo.type == profile::Type::SIP) {
if ((uriScheme == URI::SchemeType::SIP || uriScheme == URI::SchemeType::SIPS) && owner.profileInfo.type == profile::Type::SIP) {
pimpl_->searchSipContact(uri);
} else if (uriScheme == URI::SchemeType::RING && owner.profileInfo.type == profile::Type::RING) {
pimpl_->searchRingContact(uri);
......
......@@ -159,8 +159,7 @@ QString URIPimpl::strip(const QString& uri, URI::SchemeType& schemeType, QString
{
if (uri.isEmpty())
return {};
std::regex uri_regex = std::regex("[a-zA-Z][a-zA-Z0-9+.-]*:");
std::regex uri_regex = std::regex("(^sip:)|(^sips:)|(^ring:)|(^jami:)");
std::string uri_to_match = uri.toStdString();
std::smatch match;
......@@ -172,11 +171,29 @@ QString URIPimpl::strip(const QString& uri, URI::SchemeType& schemeType, QString
schemeType = URI::SchemeType::UNRECOGNIZED;
auto it = std::find_if(schemeNames.begin(), schemeNames.end(), [&scheme] (auto& it) {
if (it.second == "ring:" && scheme == "jami:")
return true;
return it.second == scheme;
});
if (it != URIPimpl::schemeNames.end())
schemeType = it->first;
if (schemeType == URI::SchemeType::NONE) {
// no match, check if it includes x..x:..: format
std::regex uri_regex_unrecognized = std::regex("[a-zA-Z][a-zA-Z0-9+.-]*:");
std::string uri_to_match_unrecognized = uri_to_match;
std::smatch match_unrecognized;
if (std::regex_search(uri_to_match_unrecognized, match_unrecognized, uri_regex_unrecognized)) {
if (match_unrecognized.ready()) {
std::string scheme_unrecognized = match_unrecognized.str(0).c_str();
if (!scheme_unrecognized.empty()) {
// match x..x:..: format
schemeType = URI::SchemeType::UNRECOGNIZED;
}
}
}
}
return uri.mid(scheme.size(), uri.size());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment