MCPcopy Create free account
hub / github.com/Atarity/Lightpack / clientProcessCommands

Method clientProcessCommands

Software/src/ApiServer.cpp:268–1057  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266}
267
268void 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;

Callers

nothing calls this directly

Calls 15

canReadLineMethod · 0.80
CheckLockMethod · 0.80
removeMethod · 0.80
GetStatusAPIMethod · 0.80
countMethod · 0.80
GetFPSMethod · 0.80
GetScreenSizeMethod · 0.80
VerifySessionKeyMethod · 0.80
SetLockAliveMethod · 0.80
SetGammaMethod · 0.80
SetBrightnessMethod · 0.80
SetSmoothMethod · 0.80

Tested by

no test coverage detected