| 206 | #endif |
| 207 | |
| 208 | void ServerPrivate::createSocket() |
| 209 | { |
| 210 | Q_Q(Server); |
| 211 | |
| 212 | if (socket) { |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | switch (connectionType) { |
| 217 | case Server::TcpConnection: |
| 218 | socket = new QTcpSocket(q); |
| 219 | break; |
| 220 | case Server::SslConnection: |
| 221 | case Server::TlsConnection: |
| 222 | #ifndef QT_NO_SSL |
| 223 | socket = new QSslSocket(q); |
| 224 | setPeerVerificationType(peerVerificationType); |
| 225 | q->connect( |
| 226 | static_cast<QSslSocket *>(socket), |
| 227 | static_cast<void (QSslSocket::*)(const QList<QSslError> &)>(&QSslSocket::sslErrors), |
| 228 | q, |
| 229 | &Server::sslErrors, |
| 230 | Qt::DirectConnection); |
| 231 | #else |
| 232 | qFatal("QT_NO_SSL defined, can't send emails"); |
| 233 | #endif |
| 234 | } |
| 235 | q->connect(socket, &QTcpSocket::stateChanged, q, [=](QAbstractSocket::SocketState sockState) { |
| 236 | qCDebug(SIMPLEMAIL_SERVER) << "stateChanged" << sockState << socket->readAll(); |
| 237 | if (sockState == QAbstractSocket::ClosingState) { |
| 238 | state = Closing; |
| 239 | } else if (sockState == QAbstractSocket::UnconnectedState) { |
| 240 | state = Disconnected; |
| 241 | if (!queue.isEmpty()) { |
| 242 | q->connectToServer(); |
| 243 | } |
| 244 | } |
| 245 | }); |
| 246 | |
| 247 | q->connect(socket, &QTcpSocket::connected, q, [=]() { |
| 248 | qCDebug(SIMPLEMAIL_SERVER) << "connected" << state << socket->readAll(); |
| 249 | state = WaitingForServiceReady220; |
| 250 | }); |
| 251 | |
| 252 | auto erroFn = [=](QAbstractSocket::SocketError error) { |
| 253 | qCDebug(SIMPLEMAIL_SERVER) << "SocketError" << error << socket->readAll(); |
| 254 | if (!queue.isEmpty()) { |
| 255 | ServerReplyContainer &cont = queue[0]; |
| 256 | if (!cont.reply.isNull()) { |
| 257 | ServerReply *reply = cont.reply; |
| 258 | queue.removeFirst(); |
| 259 | reply->finish(true, -1, socket->errorString()); |
| 260 | } else { |
| 261 | queue.removeFirst(); |
| 262 | } |
| 263 | } |
| 264 | }; |
| 265 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) |
no test coverage detected