| 266 | } |
| 267 | |
| 268 | void ApiServer::clientProcessCommands() |
| 269 | { |
| 270 | API_DEBUG_OUT << Q_FUNC_INFO << "ApiServer thread id:" << this->thread()->currentThreadId(); |
| 271 | |
| 272 | QTcpSocket *client = dynamic_cast<QTcpSocket*>(sender()); |
| 273 | |
| 274 | while (m_clients.contains(client) && client->canReadLine()) |
| 275 | { |
| 276 | QString sessionKey = m_clients[client].sessionKey; |
| 277 | int m_lockedClient = lightpack->CheckLock(sessionKey); |
| 278 | |
| 279 | QByteArray cmdBuffer = client->readLine().trimmed(); |
| 280 | API_DEBUG_OUT << cmdBuffer; |
| 281 | |
| 282 | QString result = CmdUnknown; |
| 283 | |
| 284 | if (cmdBuffer.isEmpty()) |
| 285 | { |
| 286 | // Ignore empty lines |
| 287 | return; |
| 288 | } |
| 289 | else if (cmdBuffer == CmdExit) |
| 290 | { |
| 291 | writeData(client, "Goodbye!\r\n"); |
| 292 | if (m_clients.contains(client)) |
| 293 | client->close(); |
| 294 | return; |
| 295 | } |
| 296 | else if (cmdBuffer == CmdHelp) |
| 297 | { |
| 298 | writeData(client, m_helpMessage); |
| 299 | return; |
| 300 | } |
| 301 | else if (cmdBuffer == CmdHelpShort) |
| 302 | { |
| 303 | writeData(client, m_shortHelpMessage); |
| 304 | return; |
| 305 | } |
| 306 | else if (cmdBuffer.startsWith(CmdApiKey)) |
| 307 | { |
| 308 | API_DEBUG_OUT << CmdApiKey; |
| 309 | |
| 310 | if (m_isAuthEnabled) |
| 311 | { |
| 312 | cmdBuffer.remove(0, cmdBuffer.indexOf(':') + 1); |
| 313 | API_DEBUG_OUT << QString(cmdBuffer); |
| 314 | |
| 315 | if (cmdBuffer == m_apiAuthKey) |
| 316 | { |
| 317 | API_DEBUG_OUT << CmdApiKey << "OK"; |
| 318 | |
| 319 | m_clients[client].isAuthorized = true; |
| 320 | |
| 321 | result = CmdApiKeyResult_Ok; |
| 322 | } else { |
| 323 | API_DEBUG_OUT << CmdApiKey << "Api key is not valid:" << QString(cmdBuffer); |
| 324 | |
| 325 | m_clients[client].isAuthorized = false; |
nothing calls this directly
no test coverage detected