aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/connection.cpp28
-rw-r--r--lib/connection.h4
-rw-r--r--lib/util.cpp14
-rw-r--r--lib/util.h8
4 files changed, 26 insertions, 28 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index ff066def..6d06c603 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -162,33 +162,11 @@ Connection::~Connection()
stopSync();
}
-static const auto ServerPartRegEx = QStringLiteral(
- "(\\[[^]]+\\]|[^:@]+)" // Either IPv6 address or hostname/IPv4 address
- "(?::(\\d{1,5}))?" // Optional port
-);
-
-QString serverPart(const QString& mxId)
+void Connection::resolveServer(const QString& mxid)
{
- static QString re = "^[@!#$+].+?:(" // Localpart and colon
- % ServerPartRegEx % ")$";
- static QRegularExpression parser(re,
- QRegularExpression::UseUnicodePropertiesOption); // Because Asian digits
- return parser.match(mxId).captured(1);
-}
-
-void Connection::resolveServer(const QString& mxidOrDomain)
-{
- // mxIdOrDomain may be something as complex as
- // @username:[IPv6:address]:port, or as simple as a plain serverpart.
- static QRegularExpression parser(
- "^(@.+?:)?" // Optional username (allow everything for compatibility)
- % ServerPartRegEx % '$',
- QRegularExpression::UseUnicodePropertiesOption); // Because Asian digits
- auto match = parser.match(mxidOrDomain);
-
- auto maybeBaseUrl = QUrl::fromUserInput(match.captured(2));
+ auto maybeBaseUrl = QUrl::fromUserInput(serverPart(mxid));
maybeBaseUrl.setScheme("https"); // Instead of the Qt-default "http"
- if (!match.hasMatch() || !maybeBaseUrl.isValid())
+ if (maybeBaseUrl.isEmpty() || !maybeBaseUrl.isValid())
{
emit resolveError(
tr("%1 is not a valid homeserver address")
diff --git a/lib/connection.h b/lib/connection.h
index 4ab8d5ba..11499a6e 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -408,8 +408,8 @@ namespace QMatrixClient
/** Set the homeserver base URL */
void setHomeserver(const QUrl& baseUrl);
- /** Determine and set the homeserver from domain or MXID */
- void resolveServer(const QString& mxidOrDomain);
+ /** Determine and set the homeserver from MXID */
+ void resolveServer(const QString& mxid);
void connectToServer(const QString& user, const QString& password,
const QString& initialDeviceName,
diff --git a/lib/util.cpp b/lib/util.cpp
index 88cba959..b9639843 100644
--- a/lib/util.cpp
+++ b/lib/util.cpp
@@ -112,6 +112,20 @@ qreal QMatrixClient::stringToHueF(const QString &string)
return hueF;
}
+static const auto ServerPartRegEx = QStringLiteral(
+ "(\\[[^]]+\\]|[^:@]+)" // Either IPv6 address or hostname/IPv4 address
+ "(?::(\\d{1,5}))?" // Optional port
+);
+
+QString QMatrixClient::serverPart(const QString& mxId)
+{
+ static QString re = "^[@!#$+].+?:(" // Localpart and colon
+ % ServerPartRegEx % ")$";
+ static QRegularExpression parser(re,
+ QRegularExpression::UseUnicodePropertiesOption); // Because Asian digits
+ return parser.match(mxId).captured(1);
+}
+
// Tests for function_traits<>
#ifdef Q_CC_CLANG
diff --git a/lib/util.h b/lib/util.h
index eda817a1..1106e774 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -300,27 +300,33 @@ namespace QMatrixClient
void linkifyUrls(QString& htmlEscapedText);
/** Sanitize the text before showing in HTML
+ *
* This does toHtmlEscaped() and removes Unicode BiDi marks.
*/
QString sanitized(const QString& plainText);
/** Pretty-print plain text into HTML
+ *
* This includes HTML escaping of <,>,",& and calling linkifyUrls()
*/
QString prettyPrint(const QString& plainText);
/** Return a path to cache directory after making sure that it exists
+ *
* The returned path has a trailing slash, clients don't need to append it.
* \param dir path to cache directory relative to the standard cache path
*/
QString cacheLocation(const QString& dirName);
/** Hue color component of based of the hash of the string.
+ *
* The implementation is based on XEP-0392:
* https://xmpp.org/extensions/xep-0392.html
* Naming and range are the same as QColor's hueF method:
* https://doc.qt.io/qt-5/qcolor.html#integer-vs-floating-point-precision
*/
qreal stringToHueF(const QString& string);
-} // namespace QMatrixClient
+ /** Extract the serverpart from MXID */
+ QString serverPart(const QString& mxId);
+} // namespace QMatrixClient