service/ManageSieveClient.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "ManageSieveClient.h" | ||
| 2 | |||
| 3 | #include "util/SecureUtil.h" | ||
| 4 | |||
| 5 | #include <QLoggingCategory> | ||
| 6 | #include <QSslConfiguration> | ||
| 7 | |||
| 8 |
4/7✓ Branch 2 → 3 taken 12 times.
✓ Branch 2 → 8 taken 5027 times.
✓ Branch 4 → 5 taken 12 times.
✗ Branch 4 → 8 not taken.
✓ Branch 5 → 6 taken 12 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
|
5039 | Q_LOGGING_CATEGORY(lcSieveProtocol, "mailjd.sieve.protocol") |
| 9 | |||
| 10 | using ManageSieve::Response; | ||
| 11 | using ManageSieve::Token; | ||
| 12 | |||
| 13 | namespace { | ||
| 14 | |||
| 15 | const ManageSieve::LineLimits kLimits; | ||
| 16 | |||
| 17 | 40 | const char *phaseName(int phase) { | |
| 18 | static const char *names[] = {"disconnected", "connecting", "greeting", "starttls", | ||
| 19 | "tls-handshake", "tls-capabilities", "authenticating", | ||
| 20 | "ready", "busy", "logging-out"}; | ||
| 21 |
2/4✓ Branch 2 → 3 taken 40 times.
✗ Branch 2 → 5 not taken.
✓ Branch 3 → 4 taken 40 times.
✗ Branch 3 → 5 not taken.
|
40 | return phase >= 0 && phase < 10 ? names[phase] : "?"; |
| 22 | } | ||
| 23 | |||
| 24 | } // namespace | ||
| 25 | |||
| 26 |
3/3✓ Branch 4 → 5 taken 364 times.
✓ Branch 11 → 12 taken 364 times.
✓ Branch 12 → 13 taken 364 times.
|
364 | ManageSieveClient::ManageSieveClient(QObject *parent) : QObject(parent) { |
| 27 |
1/1✓ Branch 13 → 14 taken 364 times.
|
364 | m_timeout.setSingleShot(true); |
| 28 |
1/1✓ Branch 14 → 15 taken 364 times.
|
364 | connect(&m_timeout, &QTimer::timeout, this, &ManageSieveClient::onTimeout); |
| 29 |
1/1✓ Branch 16 → 17 taken 364 times.
|
364 | m_idle.setSingleShot(true); |
| 30 |
1/1✓ Branch 17 → 18 taken 364 times.
|
364 | connect(&m_idle, &QTimer::timeout, this, &ManageSieveClient::logout); |
| 31 | 364 | } | |
| 32 | |||
| 33 | 704 | ManageSieveClient::~ManageSieveClient() { | |
| 34 | // Destruction drops queued callbacks: their owners are being destroyed too. | ||
| 35 | 364 | m_queue.clear(); | |
| 36 | 364 | clearCredentials(); | |
| 37 |
2/2✓ Branch 5 → 6 taken 320 times.
✓ Branch 5 → 10 taken 44 times.
|
364 | if (m_socket) { |
| 38 | 320 | m_socket->disconnect(this); | |
| 39 | 320 | m_socket->abort(); | |
| 40 | } | ||
| 41 | 704 | } | |
| 42 | |||
| 43 | 721 | void ManageSieveClient::setServer(const SieveServerConfig &config) { | |
| 44 |
2/4✓ Branch 4 → 5 taken 356 times.
✗ Branch 4 → 10 not taken.
✓ Branch 6 → 7 taken 356 times.
✗ Branch 6 → 10 not taken.
|
1433 | const bool sameServer = config.host == m_config.host && config.port == m_config.port && |
| 45 |
3/4✓ Branch 3 → 4 taken 356 times.
✓ Branch 3 → 10 taken 365 times.
✓ Branch 8 → 9 taken 356 times.
✗ Branch 8 → 10 not taken.
|
1433 | config.security == m_config.security && |
| 46 | 356 | config.username == m_config.username; | |
| 47 |
7/8✓ Branch 11 → 12 taken 365 times.
✓ Branch 11 → 16 taken 356 times.
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 16 taken 364 times.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 16 not taken.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 720 times.
|
721 | if (!sameServer && m_phase != Phase::Disconnected && m_queue.isEmpty()) |
| 48 | 1 | closeSocket(); | |
| 49 | // S106-098: capabilities describe one server; a different one starts empty. | ||
| 50 |
2/2✓ Branch 19 → 20 taken 365 times.
✓ Branch 19 → 23 taken 356 times.
|
721 | if (!sameServer) |
| 51 | 365 | m_capabilities = {}; | |
| 52 | 721 | clearCredentials(); | |
| 53 | 721 | m_config = config; | |
| 54 | 721 | } | |
| 55 | |||
| 56 | 361 | void ManageSieveClient::setCaCertificates(const QList<QSslCertificate> &certificates) { | |
| 57 | 361 | m_caCertificates = certificates; | |
| 58 | 361 | } | |
| 59 | |||
| 60 | 103 | void ManageSieveClient::probe(Callback callback) { | |
| 61 |
2/2✓ Branch 5 → 6 taken 103 times.
✓ Branch 6 → 7 taken 103 times.
|
103 | enqueue(Kind::Probe, "PROBE", {}, std::move(callback)); |
| 62 | 103 | } | |
| 63 | |||
| 64 | 332 | void ManageSieveClient::login(Callback callback) { | |
| 65 |
2/2✓ Branch 5 → 6 taken 332 times.
✓ Branch 6 → 7 taken 332 times.
|
332 | enqueue(Kind::Login, "LOGIN", {}, std::move(callback)); |
| 66 | 332 | } | |
| 67 | |||
| 68 | 347 | void ManageSieveClient::listScripts(Callback callback) { | |
| 69 |
4/4✓ Branch 5 → 6 taken 347 times.
✓ Branch 6 → 7 taken 347 times.
✓ Branch 7 → 8 taken 347 times.
✓ Branch 8 → 9 taken 347 times.
|
347 | enqueue(Kind::ListScripts, "LISTSCRIPTS", ManageSieve::command("LISTSCRIPTS"), |
| 70 | 347 | std::move(callback)); | |
| 71 | 347 | } | |
| 72 | |||
| 73 | 446 | void ManageSieveClient::getScript(const QString &name, Callback callback) { | |
| 74 |
2/2✓ Branch 9 → 10 taken 446 times.
✓ Branch 10 → 11 taken 446 times.
|
892 | enqueue(Kind::GetScript, "GETSCRIPT", |
| 75 |
4/6✓ Branch 7 → 8 taken 446 times.
✓ Branch 8 → 9 taken 446 times.
✓ Branch 16 → 17 taken 446 times.
✓ Branch 16 → 18 taken 446 times.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 34 not taken.
|
1338 | ManageSieve::command("GETSCRIPT", {ManageSieve::quotedOrLiteral(name.toUtf8())}), |
| 76 | 446 | std::move(callback)); | |
| 77 | 892 | } | |
| 78 | |||
| 79 | 332 | void ManageSieveClient::checkScript(const QByteArray &script, Callback callback) { | |
| 80 |
2/2✓ Branch 8 → 9 taken 332 times.
✓ Branch 9 → 10 taken 332 times.
|
664 | enqueue(Kind::CheckScript, "CHECKSCRIPT", |
| 81 |
4/6✓ Branch 6 → 7 taken 332 times.
✓ Branch 7 → 8 taken 332 times.
✓ Branch 15 → 16 taken 332 times.
✓ Branch 15 → 17 taken 332 times.
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
|
996 | ManageSieve::command("CHECKSCRIPT", {ManageSieve::literal(script)}), |
| 82 | 332 | std::move(callback), true); | |
| 83 | 664 | } | |
| 84 | |||
| 85 | 174 | void ManageSieveClient::putScript(const QString &name, const QByteArray &script, | |
| 86 | Callback callback) { | ||
| 87 |
2/2✓ Branch 10 → 11 taken 174 times.
✓ Branch 11 → 12 taken 174 times.
|
348 | enqueue(Kind::PutScript, "PUTSCRIPT", |
| 88 |
4/6✓ Branch 8 → 9 taken 174 times.
✓ Branch 9 → 10 taken 174 times.
✓ Branch 17 → 18 taken 348 times.
✓ Branch 17 → 19 taken 174 times.
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 35 not taken.
|
696 | ManageSieve::command("PUTSCRIPT", {ManageSieve::quotedOrLiteral(name.toUtf8()), |
| 89 | ManageSieve::literal(script)}), | ||
| 90 | 174 | std::move(callback), true); | |
| 91 | 348 | } | |
| 92 | |||
| 93 | 81 | void ManageSieveClient::setActive(const QString &name, Callback callback) { | |
| 94 |
2/2✓ Branch 9 → 10 taken 81 times.
✓ Branch 10 → 11 taken 81 times.
|
162 | enqueue(Kind::SetActive, "SETACTIVE", |
| 95 |
4/6✓ Branch 7 → 8 taken 81 times.
✓ Branch 8 → 9 taken 81 times.
✓ Branch 16 → 17 taken 81 times.
✓ Branch 16 → 18 taken 81 times.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 34 not taken.
|
243 | ManageSieve::command("SETACTIVE", {ManageSieve::quotedOrLiteral(name.toUtf8())}), |
| 96 | 81 | std::move(callback)); | |
| 97 | 162 | } | |
| 98 | |||
| 99 | 3 | void ManageSieveClient::renameScript(const QString &from, const QString &to, Callback callback) { | |
| 100 |
2/2✓ Branch 11 → 12 taken 3 times.
✓ Branch 12 → 13 taken 3 times.
|
6 | enqueue(Kind::RenameScript, "RENAMESCRIPT", |
| 101 |
4/6✓ Branch 9 → 10 taken 3 times.
✓ Branch 10 → 11 taken 3 times.
✓ Branch 18 → 19 taken 6 times.
✓ Branch 18 → 20 taken 3 times.
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 37 not taken.
|
15 | ManageSieve::command("RENAMESCRIPT", {ManageSieve::quotedOrLiteral(from.toUtf8()), |
| 102 | 3 | ManageSieve::quotedOrLiteral(to.toUtf8())}), | |
| 103 | 3 | std::move(callback)); | |
| 104 | 6 | } | |
| 105 | |||
| 106 | 5 | void ManageSieveClient::deleteScript(const QString &name, Callback callback) { | |
| 107 |
2/2✓ Branch 9 → 10 taken 5 times.
✓ Branch 10 → 11 taken 5 times.
|
10 | enqueue(Kind::DeleteScript, "DELETESCRIPT", |
| 108 |
4/6✓ Branch 7 → 8 taken 5 times.
✓ Branch 8 → 9 taken 5 times.
✓ Branch 16 → 17 taken 5 times.
✓ Branch 16 → 18 taken 5 times.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 34 not taken.
|
15 | ManageSieve::command("DELETESCRIPT", {ManageSieve::quotedOrLiteral(name.toUtf8())}), |
| 109 | 5 | std::move(callback)); | |
| 110 | 10 | } | |
| 111 | |||
| 112 | 173 | void ManageSieveClient::haveSpace(const QString &name, qint64 size, Callback callback) { | |
| 113 |
2/2✓ Branch 10 → 11 taken 173 times.
✓ Branch 11 → 12 taken 173 times.
|
346 | enqueue(Kind::HaveSpace, "HAVESPACE", |
| 114 |
4/6✓ Branch 8 → 9 taken 173 times.
✓ Branch 9 → 10 taken 173 times.
✓ Branch 17 → 18 taken 346 times.
✓ Branch 17 → 19 taken 173 times.
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 35 not taken.
|
692 | ManageSieve::command("HAVESPACE", {ManageSieve::quotedOrLiteral(name.toUtf8()), |
| 115 | QByteArray::number(size)}), | ||
| 116 | 173 | std::move(callback)); | |
| 117 | 346 | } | |
| 118 | |||
| 119 | 7 | void ManageSieveClient::noop(Callback callback) { | |
| 120 |
4/4✓ Branch 5 → 6 taken 7 times.
✓ Branch 6 → 7 taken 7 times.
✓ Branch 7 → 8 taken 7 times.
✓ Branch 8 → 9 taken 7 times.
|
7 | enqueue(Kind::Noop, "NOOP", ManageSieve::command("NOOP"), std::move(callback)); |
| 121 | 7 | } | |
| 122 | |||
| 123 | 2003 | void ManageSieveClient::enqueue(Kind kind, const QByteArray &name, const QByteArray &wire, | |
| 124 | Callback callback, bool upload) { | ||
| 125 | 2003 | Pending pending; | |
| 126 | 2003 | pending.kind = kind; | |
| 127 | 2003 | pending.name = name; | |
| 128 | 2003 | pending.wire = wire; | |
| 129 | 2003 | pending.callback = std::move(callback); | |
| 130 | 2003 | pending.upload = upload; | |
| 131 | 2003 | pending.timer.start(); | |
| 132 |
1/1✓ Branch 9 → 10 taken 2003 times.
|
2003 | m_queue.append(std::move(pending)); |
| 133 |
1/1✓ Branch 10 → 11 taken 2003 times.
|
2003 | m_idle.stop(); |
| 134 |
2/2✓ Branch 11 → 12 taken 1620 times.
✓ Branch 11 → 13 taken 383 times.
|
2003 | if (m_phase == Phase::Ready) |
| 135 |
1/1✓ Branch 12 → 15 taken 1620 times.
|
1620 | dispatchNext(); |
| 136 |
2/2✓ Branch 13 → 14 taken 365 times.
✓ Branch 13 → 15 taken 18 times.
|
383 | else if (m_phase == Phase::Disconnected) |
| 137 |
1/1✓ Branch 14 → 15 taken 365 times.
|
365 | ensureConnected(); |
| 138 | 2003 | } | |
| 139 | |||
| 140 | ✗ | bool ManageSieveClient::needsAuthentication(Kind kind) { return kind != Kind::Probe; } | |
| 141 | |||
| 142 | 366 | void ManageSieveClient::ensureConnected() { | |
| 143 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 12 taken 366 times.
|
366 | if (m_config.host.isEmpty()) { |
| 144 | ✗ | failAll(ErrorKind::Network, QStringLiteral("No ManageSieve server configured")); | |
| 145 | ✗ | return; | |
| 146 | } | ||
| 147 | 366 | createSocket(); | |
| 148 | // S106-098: every connection reads its capabilities afresh (implicit TLS | ||
| 149 | // never passes the STARTTLS reset in onEncrypted()). | ||
| 150 | 366 | m_capabilities = {}; | |
| 151 | 366 | m_listBytes = 0; | |
| 152 | 366 | m_phase = Phase::Connecting; | |
| 153 | 366 | armTimeout(m_timeouts.connectMs); | |
| 154 |
7/7✓ Branch 16 → 17 taken 366 times.
✓ Branch 20 → 21 taken 226 times.
✓ Branch 21 → 22 taken 226 times.
✓ Branch 22 → 23 taken 226 times.
✓ Branch 23 → 24 taken 226 times.
✓ Branch 28 → 18 taken 226 times.
✓ Branch 28 → 29 taken 366 times.
|
592 | qCInfo(lcSieveProtocol) << "Connecting, port" << m_config.port << "security" |
| 155 |
1/1✓ Branch 24 → 25 taken 226 times.
|
226 | << m_config.security; |
| 156 |
2/2✓ Branch 31 → 32 taken 3 times.
✓ Branch 31 → 36 taken 363 times.
|
366 | if (m_config.security == QLatin1String("ssl")) |
| 157 |
1/1✓ Branch 34 → 35 taken 3 times.
|
6 | m_socket->connectToHostEncrypted(m_config.host, m_config.port); |
| 158 | else | ||
| 159 |
1/1✓ Branch 38 → 39 taken 363 times.
|
363 | m_socket->connectToHost(m_config.host, m_config.port); |
| 160 | } | ||
| 161 | |||
| 162 | 366 | void ManageSieveClient::createSocket() { | |
| 163 |
1/1✓ Branch 2 → 3 taken 366 times.
|
366 | closeSocket(); |
| 164 |
3/6✓ Branch 3 → 4 taken 366 times.
✓ Branch 4 → 5 taken 366 times.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 366 times.
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 28 not taken.
|
366 | auto *socket = new QSslSocket(this); |
| 165 |
1/1✓ Branch 7 → 8 taken 366 times.
|
366 | QSslConfiguration configuration = QSslConfiguration::defaultConfiguration(); |
| 166 |
2/2✓ Branch 9 → 10 taken 352 times.
✓ Branch 9 → 11 taken 14 times.
|
366 | if (!m_caCertificates.isEmpty()) |
| 167 |
1/1✓ Branch 10 → 11 taken 352 times.
|
352 | configuration.addCaCertificates(m_caCertificates); |
| 168 |
1/1✓ Branch 11 → 12 taken 366 times.
|
366 | socket->setSslConfiguration(configuration); |
| 169 |
1/1✓ Branch 12 → 13 taken 366 times.
|
366 | socket->setPeerVerifyMode(QSslSocket::VerifyPeer); |
| 170 | 366 | const quint64 generation = ++m_generation; | |
| 171 |
1/1✓ Branch 13 → 14 taken 366 times.
|
366 | connect(socket, &QSslSocket::connected, this, [this, generation] { |
| 172 |
1/2✓ Branch 2 → 3 taken 350 times.
✗ Branch 2 → 4 not taken.
|
350 | if (generation == m_generation) |
| 173 | 350 | onConnected(); | |
| 174 | 350 | }); | |
| 175 |
1/1✓ Branch 15 → 16 taken 366 times.
|
366 | connect(socket, &QSslSocket::encrypted, this, [this, generation] { |
| 176 |
1/2✓ Branch 2 → 3 taken 342 times.
✗ Branch 2 → 4 not taken.
|
342 | if (generation == m_generation) |
| 177 | 342 | onEncrypted(); | |
| 178 | 342 | }); | |
| 179 |
1/1✓ Branch 17 → 18 taken 366 times.
|
366 | connect(socket, &QSslSocket::readyRead, this, [this, generation] { |
| 180 |
1/2✓ Branch 2 → 3 taken 3132 times.
✗ Branch 2 → 4 not taken.
|
3132 | if (generation == m_generation) |
| 181 | 3132 | onReadyRead(); | |
| 182 | 3132 | }); | |
| 183 | 366 | connect(socket, &QSslSocket::errorOccurred, this, | |
| 184 |
1/1✓ Branch 19 → 20 taken 366 times.
|
366 | [this, generation](QAbstractSocket::SocketError error) { |
| 185 |
1/2✓ Branch 2 → 3 taken 13 times.
✗ Branch 2 → 4 not taken.
|
13 | if (generation == m_generation) |
| 186 | 13 | onSocketError(error); | |
| 187 | 13 | }); | |
| 188 | 366 | connect(socket, &QSslSocket::sslErrors, this, | |
| 189 |
1/1✓ Branch 21 → 22 taken 366 times.
|
366 | [this, generation](const QList<QSslError> &errors) { |
| 190 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 3 times.
|
3 | if (generation != m_generation) |
| 191 | ✗ | return; | |
| 192 | 3 | QStringList messages; | |
| 193 |
2/2✓ Branch 12 → 6 taken 3 times.
✓ Branch 12 → 13 taken 3 times.
|
6 | for (const QSslError &error : errors) |
| 194 |
2/2✓ Branch 7 → 8 taken 3 times.
✓ Branch 8 → 9 taken 3 times.
|
3 | messages.append(error.errorString()); |
| 195 | // TLS stays fail-closed: ignoreSslErrors() is never called. | ||
| 196 |
2/2✓ Branch 16 → 17 taken 3 times.
✓ Branch 17 → 18 taken 3 times.
|
6 | failAll(ErrorKind::Certificate, messages.join(QStringLiteral("; "))); |
| 197 | 3 | }); | |
| 198 |
1/1✓ Branch 23 → 24 taken 366 times.
|
366 | m_socket = socket; |
| 199 | 366 | } | |
| 200 | |||
| 201 | 350 | void ManageSieveClient::onConnected() { | |
| 202 |
2/2✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 6 taken 347 times.
|
350 | if (m_config.security == QLatin1String("ssl")) |
| 203 | 3 | return; // greeting follows the handshake | |
| 204 | 347 | m_phase = Phase::Greeting; | |
| 205 | 347 | armTimeout(m_timeouts.commandMs); | |
| 206 | } | ||
| 207 | |||
| 208 | 342 | void ManageSieveClient::onEncrypted() { | |
| 209 |
7/7✓ Branch 2 → 3 taken 342 times.
✓ Branch 6 → 7 taken 202 times.
✓ Branch 7 → 8 taken 202 times.
✓ Branch 10 → 11 taken 202 times.
✓ Branch 11 → 12 taken 202 times.
✓ Branch 17 → 4 taken 202 times.
✓ Branch 17 → 18 taken 342 times.
|
544 | qCInfo(lcSieveProtocol) << "TLS established" << m_socket->sessionProtocol(); |
| 210 |
2/2✓ Branch 18 → 19 taken 339 times.
✓ Branch 18 → 22 taken 3 times.
|
342 | if (m_phase == Phase::TlsHandshake) { |
| 211 | // RFC 5804 §2.2: capabilities seen before TLS never authorize behaviour | ||
| 212 | // after TLS; the server re-issues them now. | ||
| 213 | 339 | m_capabilities = {}; | |
| 214 | 339 | m_phase = Phase::TlsCapabilities; | |
| 215 | } else { | ||
| 216 | 3 | m_phase = Phase::Greeting; | |
| 217 | } | ||
| 218 | 342 | armTimeout(m_timeouts.commandMs); | |
| 219 | 342 | } | |
| 220 | |||
| 221 | 3132 | void ManageSieveClient::onReadyRead() { | |
| 222 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 3132 times.
|
3132 | if (!m_socket) |
| 223 | ✗ | return; | |
| 224 |
2/2✓ Branch 6 → 7 taken 3132 times.
✓ Branch 7 → 8 taken 3132 times.
|
3132 | m_buffer += m_socket->readAll(); |
| 225 |
1/2✗ Branch 10 → 11 not taken.
✓ Branch 10 → 19 taken 3132 times.
|
3132 | if (m_buffer.size() > kLimits.maxLiteral + kLimits.maxLine) { |
| 226 | ✗ | failAll(ErrorKind::Protocol, QStringLiteral("Response too large")); | |
| 227 | ✗ | return; | |
| 228 | } | ||
| 229 | 3132 | const quint64 generation = m_generation; | |
| 230 |
6/6✓ Branch 41 → 42 taken 20142 times.
✓ Branch 41 → 45 taken 21 times.
✓ Branch 43 → 44 taken 17305 times.
✓ Branch 43 → 45 taken 2837 times.
✓ Branch 46 → 20 taken 17305 times.
✓ Branch 46 → 47 taken 2858 times.
|
20163 | while (generation == m_generation && !m_buffer.isEmpty()) { |
| 231 | 17305 | QList<Token> tokens; | |
| 232 | 17305 | int consumed = 0; | |
| 233 | 17305 | QString error; | |
| 234 | const ManageSieve::LineStatus status = | ||
| 235 |
1/1✓ Branch 20 → 21 taken 17305 times.
|
17305 | ManageSieve::readLine(m_buffer, kLimits, &tokens, &consumed, &error); |
| 236 |
2/2✓ Branch 21 → 22 taken 273 times.
✓ Branch 21 → 23 taken 17032 times.
|
17305 | if (status == ManageSieve::LineStatus::Incomplete) |
| 237 | 273 | return; | |
| 238 |
2/2✓ Branch 23 → 24 taken 1 time.
✓ Branch 23 → 27 taken 17031 times.
|
17032 | if (status == ManageSieve::LineStatus::Error) { |
| 239 |
1/1✓ Branch 24 → 25 taken 1 time.
|
1 | failAll(ErrorKind::Protocol, error); |
| 240 | 1 | return; | |
| 241 | } | ||
| 242 |
1/1✓ Branch 27 → 28 taken 17031 times.
|
17031 | m_buffer.remove(0, consumed); |
| 243 |
1/2✓ Branch 29 → 30 taken 17031 times.
✗ Branch 29 → 31 not taken.
|
17031 | if (!tokens.isEmpty()) |
| 244 |
1/1✓ Branch 30 → 31 taken 17031 times.
|
17031 | handleLine(tokens); |
| 245 | 17579 | } | |
| 246 | } | ||
| 247 | |||
| 248 | 17031 | void ManageSieveClient::handleLine(const QList<Token> &tokens) { | |
| 249 |
1/1✓ Branch 2 → 3 taken 17031 times.
|
17031 | const bool final = ManageSieve::isFinalResponse(tokens); |
| 250 |
3/3✓ Branch 3 → 4 taken 2837 times.
✓ Branch 3 → 5 taken 14194 times.
✓ Branch 4 → 6 taken 2837 times.
|
17031 | const Response response = final ? ManageSieve::parseResponse(tokens) : Response{}; |
| 251 |
5/6✓ Branch 6 → 7 taken 2837 times.
✓ Branch 6 → 22 taken 14194 times.
✓ Branch 7 → 8 taken 5 times.
✓ Branch 7 → 22 taken 2832 times.
✓ Branch 8 → 9 taken 5 times.
✗ Branch 8 → 22 not taken.
|
17031 | if (final && response.status == Response::Status::Bye && m_phase != Phase::LoggingOut) { |
| 252 |
6/6✓ Branch 9 → 10 taken 5 times.
✓ Branch 13 → 14 taken 5 times.
✓ Branch 14 → 15 taken 5 times.
✓ Branch 15 → 16 taken 5 times.
✓ Branch 19 → 11 taken 5 times.
✓ Branch 19 → 20 taken 5 times.
|
10 | qCInfo(lcSieveProtocol) << "Server closed the session, code" << response.code; |
| 253 |
1/1✓ Branch 20 → 21 taken 5 times.
|
5 | failAll(ErrorKind::Bye, response.text, response); |
| 254 | 5 | return; | |
| 255 | } | ||
| 256 |
5/6✓ Branch 22 → 23 taken 4126 times.
✓ Branch 22 → 27 taken 343 times.
✓ Branch 22 → 43 taken 258 times.
✓ Branch 22 → 45 taken 12290 times.
✓ Branch 22 → 47 taken 9 times.
✗ Branch 22 → 50 not taken.
|
17026 | switch (m_phase) { |
| 257 | 4126 | case Phase::Greeting: | |
| 258 | case Phase::TlsCapabilities: | ||
| 259 |
2/2✓ Branch 23 → 24 taken 686 times.
✓ Branch 23 → 25 taken 3440 times.
|
4126 | if (final) |
| 260 |
1/1✓ Branch 24 → 26 taken 686 times.
|
686 | handleCapabilitiesDone(response); |
| 261 | else | ||
| 262 |
1/1✓ Branch 25 → 26 taken 3440 times.
|
3440 | ManageSieve::applyCapabilityLine(tokens, &m_capabilities); |
| 263 | 4126 | return; | |
| 264 | 343 | case Phase::StartTls: | |
| 265 |
1/2✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 343 times.
|
343 | if (!final) |
| 266 | ✗ | return; | |
| 267 |
1/2✗ Branch 30 → 31 not taken.
✓ Branch 30 → 38 taken 343 times.
|
343 | if (!response.ok()) { |
| 268 | ✗ | failAll(ErrorKind::NoStartTls, QStringLiteral("STARTTLS refused"), response); | |
| 269 | ✗ | return; | |
| 270 | } | ||
| 271 | 343 | m_phase = Phase::TlsHandshake; | |
| 272 |
1/1✓ Branch 38 → 39 taken 343 times.
|
343 | m_buffer.clear(); |
| 273 |
1/1✓ Branch 39 → 40 taken 343 times.
|
343 | armTimeout(m_timeouts.connectMs); |
| 274 |
1/1✓ Branch 41 → 42 taken 343 times.
|
343 | m_socket->startClientEncryption(); |
| 275 | 343 | return; | |
| 276 | 258 | case Phase::Authenticating: | |
| 277 |
1/1✓ Branch 43 → 44 taken 258 times.
|
258 | handleAuthLine(tokens); |
| 278 | 258 | return; | |
| 279 | 12290 | case Phase::Busy: | |
| 280 |
1/1✓ Branch 45 → 46 taken 12290 times.
|
12290 | handleCommandLine(tokens); |
| 281 | 12290 | return; | |
| 282 | 9 | case Phase::LoggingOut: | |
| 283 |
1/2✓ Branch 47 → 48 taken 9 times.
✗ Branch 47 → 49 not taken.
|
9 | if (final) |
| 284 |
1/1✓ Branch 48 → 49 taken 9 times.
|
9 | finishLogout(); |
| 285 | 9 | return; | |
| 286 | ✗ | default: | |
| 287 | ✗ | qCDebug(lcSieveProtocol) << "Ignoring unsolicited line in phase" | |
| 288 | ✗ | << phaseName(static_cast<int>(m_phase)); | |
| 289 | ✗ | return; | |
| 290 | } | ||
| 291 | 17031 | } | |
| 292 | |||
| 293 | 686 | void ManageSieveClient::handleCapabilitiesDone(const Response &response) { | |
| 294 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 11 taken 686 times.
|
686 | if (!response.ok()) { |
| 295 | ✗ | failAll(ErrorKind::Protocol, QStringLiteral("Capability response was not OK"), response); | |
| 296 | ✗ | return; | |
| 297 | } | ||
| 298 |
6/6✓ Branch 11 → 12 taken 686 times.
✓ Branch 15 → 16 taken 406 times.
✓ Branch 16 → 17 taken 406 times.
✓ Branch 18 → 19 taken 406 times.
✓ Branch 28 → 13 taken 406 times.
✓ Branch 28 → 29 taken 686 times.
|
1092 | qCInfo(lcSieveProtocol) << "Capabilities:" << m_capabilities.sieveExtensions.size() |
| 299 |
3/3✓ Branch 19 → 20 taken 406 times.
✓ Branch 20 → 21 taken 406 times.
✓ Branch 21 → 22 taken 406 times.
|
406 | << "extensions, version" << m_capabilities.version << "encrypted" |
| 300 |
2/2✓ Branch 23 → 24 taken 406 times.
✓ Branch 24 → 25 taken 406 times.
|
406 | << m_socket->isEncrypted(); |
| 301 |
2/2✓ Branch 31 → 32 taken 344 times.
✓ Branch 31 → 50 taken 342 times.
|
686 | if (!m_socket->isEncrypted()) { |
| 302 |
2/2✓ Branch 32 → 33 taken 1 time.
✓ Branch 32 → 41 taken 343 times.
|
344 | if (!m_capabilities.startTls) { |
| 303 |
1/1✓ Branch 36 → 37 taken 1 time.
|
2 | failAll(ErrorKind::NoStartTls, QStringLiteral("Server offers no STARTTLS")); |
| 304 | 1 | return; | |
| 305 | } | ||
| 306 | 343 | m_phase = Phase::StartTls; | |
| 307 | 343 | armTimeout(m_timeouts.commandMs); | |
| 308 |
3/3✓ Branch 43 → 44 taken 343 times.
✓ Branch 44 → 45 taken 343 times.
✓ Branch 45 → 46 taken 343 times.
|
343 | writeRaw(ManageSieve::command("STARTTLS")); |
| 309 | 343 | return; | |
| 310 | } | ||
| 311 | 342 | m_timeout.stop(); | |
| 312 | 342 | completeLeadingProbes(); | |
| 313 |
1/2✗ Branch 52 → 53 not taken.
✓ Branch 52 → 54 taken 342 times.
|
342 | if (m_phase == Phase::Disconnected) |
| 314 | ✗ | return; | |
| 315 |
2/2✓ Branch 55 → 56 taken 87 times.
✓ Branch 55 → 58 taken 255 times.
|
342 | if (m_queue.isEmpty()) { |
| 316 | 87 | m_phase = Phase::Ready; // unauthenticated, only to send LOGOUT | |
| 317 | 87 | logout(); | |
| 318 | 87 | return; | |
| 319 | } | ||
| 320 | 255 | startAuthentication(); | |
| 321 | } | ||
| 322 | |||
| 323 | 342 | void ManageSieveClient::completeLeadingProbes() { | |
| 324 |
6/6✓ Branch 12 → 13 taken 342 times.
✓ Branch 12 → 16 taken 87 times.
✓ Branch 14 → 15 taken 87 times.
✓ Branch 14 → 16 taken 255 times.
✓ Branch 17 → 3 taken 87 times.
✓ Branch 17 → 18 taken 342 times.
|
429 | while (!m_queue.isEmpty() && m_queue.first().kind == Kind::Probe) { |
| 325 |
1/1✓ Branch 3 → 4 taken 87 times.
|
87 | Pending pending = m_queue.takeFirst(); |
| 326 | 87 | Result result; | |
| 327 | 87 | result.ok = true; | |
| 328 | 87 | result.elapsedMs = pending.timer.elapsed(); | |
| 329 |
1/2✓ Branch 6 → 7 taken 87 times.
✗ Branch 6 → 8 not taken.
|
87 | if (pending.callback) |
| 330 |
1/1✓ Branch 7 → 8 taken 87 times.
|
87 | pending.callback(result); |
| 331 | 87 | } | |
| 332 | 342 | } | |
| 333 | |||
| 334 | 255 | void ManageSieveClient::startAuthentication() { | |
| 335 |
3/6✓ Branch 3 → 4 taken 255 times.
✗ Branch 3 → 7 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 255 times.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 18 taken 255 times.
|
255 | if (!m_socket || !m_socket->isEncrypted()) { |
| 336 | ✗ | failAll(ErrorKind::Protocol, QStringLiteral("Refusing to authenticate without TLS")); | |
| 337 | ✗ | return; | |
| 338 | } | ||
| 339 |
5/6✓ Branch 19 → 20 taken 255 times.
✗ Branch 19 → 22 not taken.
✓ Branch 21 → 22 taken 1 time.
✓ Branch 21 → 23 taken 254 times.
✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 33 taken 254 times.
|
255 | if (m_config.username.isEmpty() || m_config.password.isEmpty()) { |
| 340 |
1/1✓ Branch 28 → 29 taken 1 time.
|
2 | failAll(ErrorKind::NoCredentials, QStringLiteral("No credentials")); |
| 341 | 1 | return; | |
| 342 | } | ||
| 343 | 254 | m_phase = Phase::Authenticating; | |
| 344 | 254 | armTimeout(m_timeouts.commandMs); | |
| 345 |
2/2✓ Branch 40 → 41 taken 252 times.
✓ Branch 40 → 58 taken 2 times.
|
508 | if (m_capabilities.saslMechanisms.contains(QStringLiteral("PLAIN"))) { |
| 346 |
5/5✓ Branch 41 → 42 taken 252 times.
✓ Branch 45 → 46 taken 112 times.
✓ Branch 46 → 47 taken 112 times.
✓ Branch 50 → 43 taken 112 times.
✓ Branch 50 → 51 taken 252 times.
|
364 | qCInfo(lcSieveProtocol) << "Authenticating with PLAIN"; |
| 347 |
3/3✓ Branch 51 → 52 taken 252 times.
✓ Branch 52 → 53 taken 252 times.
✓ Branch 53 → 54 taken 252 times.
|
252 | writeRaw(ManageSieve::authenticatePlain(m_config.username.toUtf8(), m_config.password)); |
| 348 | 252 | clearCredentials(); | |
| 349 | 252 | return; | |
| 350 | } | ||
| 351 |
1/2✓ Branch 64 → 65 taken 2 times.
✗ Branch 64 → 90 not taken.
|
4 | if (m_capabilities.saslMechanisms.contains(QStringLiteral("LOGIN"))) { |
| 352 |
5/5✓ Branch 65 → 66 taken 2 times.
✓ Branch 69 → 70 taken 2 times.
✓ Branch 70 → 71 taken 2 times.
✓ Branch 74 → 67 taken 2 times.
✓ Branch 74 → 75 taken 2 times.
|
4 | qCInfo(lcSieveProtocol) << "Authenticating with LOGIN"; |
| 353 |
1/1✓ Branch 75 → 76 taken 2 times.
|
2 | m_loginUser = m_config.username.toUtf8(); |
| 354 | 2 | m_loginStep = 0; | |
| 355 |
5/7✓ Branch 80 → 81 taken 2 times.
✓ Branch 81 → 82 taken 2 times.
✓ Branch 82 → 83 taken 2 times.
✓ Branch 87 → 88 taken 2 times.
✓ Branch 87 → 89 taken 2 times.
✗ Branch 142 → 143 not taken.
✗ Branch 142 → 144 not taken.
|
4 | writeRaw(ManageSieve::command("AUTHENTICATE", {"\"LOGIN\""})); |
| 356 | 2 | return; | |
| 357 | } | ||
| 358 | ✗ | failAll(ErrorKind::NoMechanism, QStringLiteral("No supported SASL mechanism")); | |
| 359 | 2 | } | |
| 360 | |||
| 361 | 258 | void ManageSieveClient::handleAuthLine(const QList<Token> &tokens) { | |
| 362 |
2/2✓ Branch 3 → 4 taken 254 times.
✓ Branch 3 → 36 taken 4 times.
|
258 | if (ManageSieve::isFinalResponse(tokens)) { |
| 363 |
1/1✓ Branch 4 → 5 taken 254 times.
|
254 | const Response response = ManageSieve::parseResponse(tokens); |
| 364 |
1/1✓ Branch 5 → 6 taken 254 times.
|
254 | clearCredentials(); |
| 365 |
2/2✓ Branch 7 → 8 taken 4 times.
✓ Branch 7 → 21 taken 250 times.
|
254 | if (!response.ok()) { |
| 366 |
6/6✓ Branch 8 → 9 taken 4 times.
✓ Branch 12 → 13 taken 4 times.
✓ Branch 13 → 14 taken 4 times.
✓ Branch 14 → 15 taken 4 times.
✓ Branch 18 → 10 taken 4 times.
✓ Branch 18 → 19 taken 4 times.
|
8 | qCInfo(lcSieveProtocol) << "Authentication refused, code" << response.code; |
| 367 |
1/1✓ Branch 19 → 20 taken 4 times.
|
4 | failAll(ErrorKind::AuthFailed, response.text, response); |
| 368 | 4 | return; | |
| 369 | } | ||
| 370 |
5/5✓ Branch 21 → 22 taken 250 times.
✓ Branch 25 → 26 taken 110 times.
✓ Branch 26 → 27 taken 110 times.
✓ Branch 30 → 23 taken 110 times.
✓ Branch 30 → 31 taken 250 times.
|
360 | qCInfo(lcSieveProtocol) << "Authenticated"; |
| 371 |
1/1✓ Branch 31 → 32 taken 250 times.
|
250 | m_timeout.stop(); |
| 372 | 250 | m_phase = Phase::Ready; | |
| 373 |
1/1✓ Branch 32 → 33 taken 250 times.
|
250 | dispatchNext(); |
| 374 | 250 | return; | |
| 375 | 254 | } | |
| 376 | // SASL LOGIN challenges: user name, then password, both base64. | ||
| 377 |
2/6✗ Branch 37 → 38 not taken.
✓ Branch 37 → 40 taken 4 times.
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 40 not taken.
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 50 taken 4 times.
|
4 | if (m_loginUser.isEmpty() && m_loginStep == 0) { |
| 378 | ✗ | failAll(ErrorKind::Protocol, QStringLiteral("Unexpected SASL challenge")); | |
| 379 | ✗ | return; | |
| 380 | } | ||
| 381 |
2/2✓ Branch 50 → 51 taken 2 times.
✓ Branch 50 → 60 taken 2 times.
|
4 | if (m_loginStep == 0) { |
| 382 |
4/4✓ Branch 52 → 53 taken 2 times.
✓ Branch 53 → 54 taken 2 times.
✓ Branch 54 → 55 taken 2 times.
✓ Branch 55 → 56 taken 2 times.
|
2 | writeRaw(ManageSieve::quotedOrLiteral(m_loginUser.toBase64()) + "\r\n"); |
| 383 | 2 | m_loginStep = 1; | |
| 384 |
1/2✓ Branch 60 → 61 taken 2 times.
✗ Branch 60 → 72 not taken.
|
2 | } else if (m_loginStep == 1) { |
| 385 |
1/1✓ Branch 62 → 63 taken 2 times.
|
2 | QByteArray encoded = m_config.password.toBase64(); |
| 386 |
3/3✓ Branch 63 → 64 taken 2 times.
✓ Branch 64 → 65 taken 2 times.
✓ Branch 65 → 66 taken 2 times.
|
2 | writeRaw(ManageSieve::quotedOrLiteral(encoded) + "\r\n"); |
| 387 |
1/1✓ Branch 68 → 69 taken 2 times.
|
2 | SecureUtil::zeroMemory(encoded); |
| 388 |
1/1✓ Branch 69 → 70 taken 2 times.
|
2 | clearCredentials(); |
| 389 | 2 | m_loginStep = 2; | |
| 390 | 2 | } else { | |
| 391 | ✗ | failAll(ErrorKind::Protocol, QStringLiteral("Unexpected SASL challenge")); | |
| 392 | } | ||
| 393 | } | ||
| 394 | |||
| 395 | 3410 | void ManageSieveClient::dispatchNext() { | |
| 396 |
2/2✓ Branch 2 → 3 taken 949 times.
✓ Branch 2 → 4 taken 2461 times.
|
3410 | if (m_phase != Phase::Ready) |
| 397 | 949 | return; | |
| 398 |
4/4✓ Branch 23 → 24 taken 1885 times.
✓ Branch 23 → 29 taken 580 times.
✓ Branch 30 → 5 taken 332 times.
✓ Branch 30 → 31 taken 2133 times.
|
4350 | while (!m_queue.isEmpty() && |
| 399 |
3/4✓ Branch 25 → 26 taken 1885 times.
✗ Branch 25 → 28 not taken.
✓ Branch 27 → 28 taken 332 times.
✓ Branch 27 → 29 taken 1553 times.
|
1885 | (m_queue.first().kind == Kind::Probe || m_queue.first().kind == Kind::Login)) { |
| 400 |
1/1✓ Branch 5 → 6 taken 332 times.
|
332 | Pending pending = m_queue.takeFirst(); |
| 401 | 332 | Result result; | |
| 402 | 332 | result.ok = true; | |
| 403 | 332 | result.elapsedMs = pending.timer.elapsed(); | |
| 404 |
1/2✓ Branch 8 → 9 taken 332 times.
✗ Branch 8 → 10 not taken.
|
332 | if (pending.callback) |
| 405 |
1/1✓ Branch 9 → 10 taken 332 times.
|
332 | pending.callback(result); |
| 406 |
2/2✓ Branch 10 → 11 taken 328 times.
✓ Branch 10 → 12 taken 4 times.
|
332 | if (m_phase != Phase::Ready) |
| 407 | 328 | return; | |
| 408 | 660 | } | |
| 409 |
2/2✓ Branch 32 → 33 taken 580 times.
✓ Branch 32 → 35 taken 1553 times.
|
2133 | if (m_queue.isEmpty()) { |
| 410 | 580 | m_idle.start(m_timeouts.idleMs); | |
| 411 | 580 | return; | |
| 412 | } | ||
| 413 | 1553 | Pending ¤t = m_queue.first(); | |
| 414 | 1553 | current.timer.restart(); | |
| 415 | 1553 | m_listBytes = 0; | |
| 416 | 1553 | m_phase = Phase::Busy; | |
| 417 |
2/2✓ Branch 37 → 38 taken 506 times.
✓ Branch 37 → 39 taken 1047 times.
|
1553 | armTimeout(current.upload ? m_timeouts.uploadMs : m_timeouts.commandMs); |
| 418 |
8/8✓ Branch 41 → 42 taken 1553 times.
✓ Branch 45 → 46 taken 746 times.
✓ Branch 46 → 47 taken 746 times.
✓ Branch 47 → 48 taken 746 times.
✓ Branch 49 → 50 taken 746 times.
✓ Branch 50 → 51 taken 746 times.
✓ Branch 54 → 43 taken 746 times.
✓ Branch 54 → 55 taken 1553 times.
|
2299 | qCDebug(lcSieveProtocol) << "Sending" << current.name << current.wire.size() << "bytes"; |
| 419 | 1553 | writeRaw(current.wire); | |
| 420 | } | ||
| 421 | |||
| 422 | 12290 | void ManageSieveClient::handleCommandLine(const QList<Token> &tokens) { | |
| 423 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 12290 times.
|
12290 | if (m_queue.isEmpty()) |
| 424 | 10750 | return; | |
| 425 |
1/1✓ Branch 5 → 6 taken 12290 times.
|
12290 | Pending ¤t = m_queue.first(); |
| 426 |
3/3✓ Branch 6 → 7 taken 12290 times.
✓ Branch 7 → 8 taken 10750 times.
✓ Branch 7 → 42 taken 1540 times.
|
12290 | if (!ManageSieve::isFinalResponse(tokens)) { |
| 427 |
2/2✓ Branch 8 → 9 taken 10309 times.
✓ Branch 8 → 33 taken 441 times.
|
10750 | if (current.kind == Kind::ListScripts) { |
| 428 | 10309 | ManageSieve::ScriptEntry entry; | |
| 429 |
2/3✓ Branch 9 → 10 taken 10309 times.
✓ Branch 10 → 11 taken 10309 times.
✗ Branch 10 → 27 not taken.
|
10309 | if (ManageSieve::parseScriptEntry(tokens, &entry)) { |
| 430 | 10309 | m_listBytes += entry.name.size(); | |
| 431 |
4/4✓ Branch 13 → 14 taken 10308 times.
✓ Branch 13 → 15 taken 1 time.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 26 taken 10308 times.
|
20617 | if (current.result.scripts.size() >= kLimits.maxListEntries || |
| 432 |
1/2✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 10308 times.
|
10308 | m_listBytes > kLimits.maxListBytes) { |
| 433 |
1/1✓ Branch 21 → 22 taken 1 time.
|
2 | failAll(ErrorKind::Protocol, QStringLiteral("Script list too long")); |
| 434 | 1 | return; | |
| 435 | } | ||
| 436 |
1/1✓ Branch 26 → 27 taken 10308 times.
|
10308 | current.result.scripts.append(entry); |
| 437 | } | ||
| 438 |
5/8✓ Branch 29 → 30 taken 10308 times.
✓ Branch 29 → 32 taken 1 time.
✓ Branch 33 → 34 taken 441 times.
✗ Branch 33 → 37 not taken.
✓ Branch 35 → 36 taken 441 times.
✗ Branch 35 → 37 not taken.
✓ Branch 38 → 39 taken 441 times.
✗ Branch 38 → 41 not taken.
|
10750 | } else if (current.kind == Kind::GetScript && tokens.first().kind == Token::Kind::String) { |
| 439 | 441 | current.result.script = tokens.first().text; | |
| 440 | } | ||
| 441 | 10749 | return; | |
| 442 | } | ||
| 443 | 1540 | Result result = current.result; | |
| 444 |
1/1✓ Branch 43 → 44 taken 1540 times.
|
1540 | result.response = ManageSieve::parseResponse(tokens); |
| 445 | 1540 | result.ok = result.response.ok(); | |
| 446 |
2/2✓ Branch 47 → 48 taken 17 times.
✓ Branch 47 → 57 taken 1523 times.
|
1540 | if (!result.ok) { |
| 447 | 17 | result.message = result.response.text; | |
| 448 |
1/2✗ Branch 51 → 52 not taken.
✓ Branch 51 → 56 taken 17 times.
|
17 | if (result.response.code == QLatin1String("REFERRAL")) { |
| 449 | ✗ | result.error = ErrorKind::Referral; | |
| 450 | ✗ | result.referral = result.response.codeArgs.value(0); | |
| 451 | } else { | ||
| 452 | 17 | result.error = ErrorKind::Server; | |
| 453 | } | ||
| 454 | } | ||
| 455 |
1/1✓ Branch 58 → 59 taken 1540 times.
|
1540 | finishCurrent(result); |
| 456 | 1540 | } | |
| 457 | |||
| 458 | 1540 | void ManageSieveClient::finishCurrent(Result result) { | |
| 459 |
1/1✓ Branch 2 → 3 taken 1540 times.
|
1540 | m_timeout.stop(); |
| 460 |
1/1✓ Branch 3 → 4 taken 1540 times.
|
1540 | Pending pending = m_queue.takeFirst(); |
| 461 | 1540 | result.elapsedMs = pending.timer.elapsed(); | |
| 462 |
9/9✓ Branch 5 → 6 taken 1540 times.
✓ Branch 9 → 10 taken 736 times.
✓ Branch 10 → 11 taken 736 times.
✓ Branch 11 → 12 taken 719 times.
✓ Branch 11 → 13 taken 17 times.
✓ Branch 14 → 15 taken 736 times.
✓ Branch 15 → 16 taken 736 times.
✓ Branch 28 → 7 taken 736 times.
✓ Branch 28 → 29 taken 1540 times.
|
2276 | qCInfo(lcSieveProtocol) << pending.name << (result.ok ? "OK" : "NO") << result.response.code |
| 463 |
4/4✓ Branch 16 → 17 taken 736 times.
✓ Branch 17 → 18 taken 736 times.
✓ Branch 18 → 19 taken 736 times.
✓ Branch 20 → 21 taken 736 times.
|
736 | << "in" << result.elapsedMs << "ms, sent" << pending.wire.size() |
| 464 |
3/3✓ Branch 21 → 22 taken 736 times.
✓ Branch 23 → 24 taken 736 times.
✓ Branch 24 → 25 taken 736 times.
|
736 | << "bytes, script" << result.script.size() << "bytes"; |
| 465 | 1540 | m_phase = Phase::Ready; | |
| 466 |
1/2✓ Branch 30 → 31 taken 1540 times.
✗ Branch 30 → 32 not taken.
|
1540 | if (pending.callback) |
| 467 |
1/1✓ Branch 31 → 32 taken 1540 times.
|
1540 | pending.callback(result); |
| 468 |
1/1✓ Branch 32 → 33 taken 1540 times.
|
1540 | dispatchNext(); |
| 469 | 1540 | } | |
| 470 | |||
| 471 | 36 | void ManageSieveClient::failAll(ErrorKind error, const QString &message, const Response &response) { | |
| 472 |
1/1✓ Branch 2 → 3 taken 36 times.
|
36 | m_timeout.stop(); |
| 473 |
1/1✓ Branch 3 → 4 taken 36 times.
|
36 | m_idle.stop(); |
| 474 |
1/1✓ Branch 4 → 5 taken 36 times.
|
36 | clearCredentials(); |
| 475 | 36 | QList<Pending> failed; | |
| 476 | 36 | failed.swap(m_queue); | |
| 477 |
7/7✓ Branch 6 → 7 taken 36 times.
✓ Branch 10 → 11 taken 36 times.
✓ Branch 11 → 12 taken 36 times.
✓ Branch 13 → 14 taken 36 times.
✓ Branch 14 → 15 taken 36 times.
✓ Branch 24 → 8 taken 36 times.
✓ Branch 24 → 25 taken 36 times.
|
72 | qCInfo(lcSieveProtocol) << "Failing" << failed.size() << "commands, error" |
| 478 |
2/2✓ Branch 15 → 16 taken 36 times.
✓ Branch 16 → 17 taken 36 times.
|
36 | << static_cast<int>(error) << "in phase" |
| 479 |
3/3✓ Branch 18 → 19 taken 36 times.
✓ Branch 19 → 20 taken 36 times.
✓ Branch 20 → 21 taken 36 times.
|
36 | << phaseName(static_cast<int>(m_phase)) << "code" << response.code; |
| 480 |
1/1✓ Branch 25 → 26 taken 36 times.
|
36 | closeSocket(); |
| 481 |
4/4✓ Branch 26 → 27 taken 36 times.
✓ Branch 27 → 28 taken 36 times.
✓ Branch 46 → 29 taken 34 times.
✓ Branch 46 → 47 taken 36 times.
|
70 | for (Pending &pending : failed) { |
| 482 | 34 | Result result; | |
| 483 | 34 | result.error = error; | |
| 484 | 34 | result.message = message; | |
| 485 | 34 | result.response = response; | |
| 486 |
2/2✓ Branch 34 → 35 taken 1 time.
✓ Branch 34 → 39 taken 33 times.
|
34 | if (response.code == QLatin1String("REFERRAL")) |
| 487 |
1/1✓ Branch 35 → 36 taken 1 time.
|
1 | result.referral = response.codeArgs.value(0); |
| 488 | 34 | result.elapsedMs = pending.timer.elapsed(); | |
| 489 |
1/2✓ Branch 41 → 42 taken 34 times.
✗ Branch 41 → 43 not taken.
|
34 | if (pending.callback) |
| 490 |
1/1✓ Branch 42 → 43 taken 34 times.
|
34 | pending.callback(result); |
| 491 | 34 | } | |
| 492 | 36 | } | |
| 493 | |||
| 494 | 95 | void ManageSieveClient::logout() { | |
| 495 | 95 | m_idle.stop(); | |
| 496 |
4/8✓ Branch 4 → 5 taken 95 times.
✗ Branch 4 → 8 not taken.
✓ Branch 5 → 6 taken 95 times.
✗ Branch 5 → 8 not taken.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 95 times.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 95 times.
|
95 | if (!m_socket || m_phase != Phase::Ready || !m_queue.isEmpty()) |
| 497 | ✗ | return; | |
| 498 | 95 | m_phase = Phase::LoggingOut; | |
| 499 | 95 | armTimeout(m_timeouts.commandMs); | |
| 500 |
3/3✓ Branch 14 → 15 taken 95 times.
✓ Branch 15 → 16 taken 95 times.
✓ Branch 16 → 17 taken 95 times.
|
95 | writeRaw(ManageSieve::command("LOGOUT")); |
| 501 | } | ||
| 502 | |||
| 503 | // S106-086: commands queued while LOGOUT was in flight run on a new | ||
| 504 | // connection; they are never left without a callback. | ||
| 505 | 9 | void ManageSieveClient::finishLogout() { | |
| 506 | 9 | closeSocket(); | |
| 507 |
2/2✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 19 taken 8 times.
|
9 | if (!m_queue.isEmpty()) { |
| 508 |
6/6✓ Branch 5 → 6 taken 1 time.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 10 → 11 taken 1 time.
✓ Branch 12 → 13 taken 1 time.
✓ Branch 17 → 7 taken 1 time.
✓ Branch 17 → 18 taken 1 time.
|
2 | qCInfo(lcSieveProtocol) << "Reconnecting for" << m_queue.size() |
| 509 |
1/1✓ Branch 13 → 14 taken 1 time.
|
1 | << "commands queued during LOGOUT"; |
| 510 | 1 | ensureConnected(); | |
| 511 | } | ||
| 512 | 9 | } | |
| 513 | |||
| 514 | 5 | void ManageSieveClient::cancelAll() { | |
| 515 |
1/1✓ Branch 5 → 6 taken 5 times.
|
10 | failAll(ErrorKind::Cancelled, QStringLiteral("Cancelled")); |
| 516 | 5 | } | |
| 517 | |||
| 518 | 412 | void ManageSieveClient::closeSocket() { | |
| 519 | 412 | ++m_generation; | |
| 520 | 412 | m_timeout.stop(); | |
| 521 | 412 | m_idle.stop(); | |
| 522 | 412 | m_buffer.clear(); | |
| 523 | 412 | const bool hadSocket = m_socket; | |
| 524 |
2/2✓ Branch 7 → 8 taken 46 times.
✓ Branch 7 → 15 taken 366 times.
|
412 | if (m_socket) { |
| 525 | 46 | m_socket->disconnect(this); | |
| 526 | 46 | m_socket->abort(); | |
| 527 | 46 | m_socket->deleteLater(); | |
| 528 | 46 | m_socket = nullptr; | |
| 529 | } | ||
| 530 | 412 | m_phase = Phase::Disconnected; | |
| 531 |
2/2✓ Branch 15 → 16 taken 46 times.
✓ Branch 15 → 17 taken 366 times.
|
412 | if (hadSocket) |
| 532 | 46 | emit connectionClosed(); | |
| 533 | 412 | } | |
| 534 | |||
| 535 | 13 | void ManageSieveClient::onSocketError(QAbstractSocket::SocketError error) { | |
| 536 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 13 times.
|
13 | if (m_phase == Phase::LoggingOut) { |
| 537 | ✗ | finishLogout(); | |
| 538 | ✗ | return; | |
| 539 | } | ||
| 540 |
2/4✓ Branch 5 → 6 taken 13 times.
✗ Branch 5 → 10 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 15 taken 13 times.
|
26 | if (m_phase == Phase::Disconnected || |
| 541 |
1/6✗ Branch 6 → 7 not taken.
✓ Branch 6 → 11 taken 13 times.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 11 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 11 not taken.
|
13 | (m_phase == Phase::Ready && m_queue.isEmpty() && |
| 542 | error == QAbstractSocket::RemoteHostClosedError)) { | ||
| 543 | ✗ | closeSocket(); | |
| 544 | ✗ | return; | |
| 545 | } | ||
| 546 |
3/7✓ Branch 16 → 17 taken 13 times.
✗ Branch 16 → 19 not taken.
✓ Branch 18 → 22 taken 13 times.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 13 times.
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 35 not taken.
|
13 | const QString message = m_socket ? m_socket->errorString() : QStringLiteral("Socket error"); |
| 547 |
2/3✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 13 times.
✓ Branch 27 → 28 taken 13 times.
|
13 | failAll(error == QAbstractSocket::SslHandshakeFailedError ? ErrorKind::Certificate |
| 548 | : ErrorKind::Network, | ||
| 549 | message); | ||
| 550 | 13 | } | |
| 551 | |||
| 552 | 2 | void ManageSieveClient::onTimeout() { | |
| 553 |
6/6✓ Branch 2 → 3 taken 2 times.
✓ Branch 6 → 7 taken 2 times.
✓ Branch 7 → 8 taken 2 times.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 13 → 4 taken 2 times.
✓ Branch 13 → 14 taken 2 times.
|
4 | qCInfo(lcSieveProtocol) << "Timeout in phase" << phaseName(static_cast<int>(m_phase)); |
| 554 |
1/2✗ Branch 14 → 15 not taken.
✓ Branch 14 → 17 taken 2 times.
|
2 | if (m_phase == Phase::LoggingOut) { |
| 555 | ✗ | finishLogout(); | |
| 556 | ✗ | return; | |
| 557 | } | ||
| 558 |
1/1✓ Branch 24 → 25 taken 2 times.
|
6 | failAll(ErrorKind::Timeout, |
| 559 |
1/1✓ Branch 23 → 24 taken 2 times.
|
6 | QStringLiteral("Timeout in phase %1").arg(QLatin1String(phaseName(static_cast<int>(m_phase))))); |
| 560 | } | ||
| 561 | |||
| 562 | 2249 | void ManageSieveClient::writeRaw(const QByteArray &bytes) { | |
| 563 |
1/2✓ Branch 3 → 4 taken 2249 times.
✗ Branch 3 → 6 not taken.
|
2249 | if (m_socket) |
| 564 | 2249 | m_socket->write(bytes); | |
| 565 | 2249 | } | |
| 566 | |||
| 567 | 3643 | void ManageSieveClient::armTimeout(int ms) { m_timeout.start(ms); } | |
| 568 | |||
| 569 | 1629 | void ManageSieveClient::clearCredentials() { | |
| 570 | 1629 | SecureUtil::zeroMemory(m_config.password); | |
| 571 | 1629 | m_config.password.clear(); | |
| 572 | 1629 | SecureUtil::zeroMemory(m_loginUser); | |
| 573 | 1629 | m_loginUser.clear(); | |
| 574 | 1629 | } | |
| 575 |