forked from Skarsnik/QUsb2snes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwsserver.cpp
More file actions
654 lines (605 loc) · 22.2 KB
/
wsserver.cpp
File metadata and controls
654 lines (605 loc) · 22.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
/*
* Copyright (c) 2018 Sylvain "Skarsnik" Colinet.
*
* This file is part of the QUsb2Snes project.
* (see https://github.com/Skarsnik/QUsb2snes).
*
* QUsb2Snes is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QUsb2Snes is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QUsb2Snes. If not, see <https://www.gnu.org/licenses/>.
*/
#include "wsserver.h"
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QLoggingCategory>
#include <QSettings>
Q_LOGGING_CATEGORY(log_wsserver, "WSServer")
#define sDebug() qCDebug(log_wsserver)
#define sInfo() qCInfo(log_wsserver)
extern QSettings* globalSettings;
quint64 WSServer::MRequest::gId = 0;
WSServer::WSServer(QObject *parent) : QObject(parent)
{
//wsServer = new QWebSocketServer(QStringLiteral("USB2SNES Server"), QWebSocketServer::NonSecureMode, this);
const QMetaObject &mo = USB2SnesWS::staticMetaObject;
const QMetaObject &mo2 = SD2Snes::staticMetaObject;
int i = mo.indexOfEnumerator("opcode");
cmdMetaEnum = mo.enumerator(i);
i = mo2.indexOfEnumerator("space");
spaceMetaEnum = mo2.enumerator(i);
i = mo2.indexOfEnumerator("server_flags");
flagsMetaEnum = mo2.enumerator(i);
trustedOrigin.append("http://localhost");
trustedOrigin.append("");
numberOfAsyncFactory = 0;
}
QString WSServer::start(QHostAddress lAddress, quint16 port)
{
QWebSocketServer* newServer = new QWebSocketServer(QStringLiteral("USB2SNES Server"), QWebSocketServer::NonSecureMode, this);
if (newServer->listen(lAddress, port))
{
sInfo() << "WebSocket server started : listenning " << lAddress << "port : " << port;
connect(newServer, &QWebSocketServer::newConnection, this, &WSServer::onNewConnection);
connect(newServer, &QWebSocketServer::closed, this, &WSServer::onWSClosed);
connect(newServer, &QWebSocketServer::serverError, this, &WSServer::onWSError);
wsServers.append(newServer);
return QString();
}
return newServer->errorString();
}
void WSServer::onNewConnection()
{
QWebSocketServer* server = qobject_cast<QWebSocketServer*>(sender());
QWebSocket* newSocket = server->nextPendingConnection();
sInfo() << "New connection from " << newSocket->origin();
if (!trustedOrigin.contains(newSocket->origin()))
{
sInfo() << "Connection from untrusted origin";
emit untrustedConnection(newSocket->origin());
sInfo() << "Closing Connection";
newSocket->close(QWebSocketProtocol::CloseCodePolicyViolated, "Not in trusted origin");
return ;
}
connect(newSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(onTextMessageReceived(QString)));
connect(newSocket, SIGNAL(binaryMessageReceived(QByteArray)), this, SLOT(onBinaryMessageReceived(QByteArray)));
connect(newSocket, SIGNAL(disconnected()), this, SLOT(onClientDisconnected()));
connect(newSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onClientError(QAbstractSocket::SocketError)));
WSInfos wi;
wi.name = "Websocket " + QString::number((size_t)newSocket, 16);
wi.attached = false;
wi.attachedTo = nullptr;
wi.commandState = NOCOMMAND;
wi.byteReceived = 0;
wi.pendingAttach = false;
wi.recvData.clear();
wi.ipsSize = 0;
wi.legacy = server->serverPort() == USB2SnesWS::legacyPort;
wsInfos[newSocket] = wi;
sInfo() << "New connection accepted " << wi.name << newSocket->origin() << newSocket->peerAddress();
}
void WSServer::onWSError(QWebSocketProtocol::CloseCode code)
{
sDebug() << "Websocket error" << code;
}
void WSServer::onWSClosed()
{
qDebug() << "Websocket closed";
}
void WSServer::addDevice(ADevice *device)
{
sDebug() << "Adding device" << device->name();
devices.append(device);
devicesInfos[device] = DeviceInfos();
connect(device, &ADevice::commandFinished, this, &WSServer::onDeviceCommandFinished);
connect(device, &ADevice::protocolError, this, &WSServer::onDeviceProtocolError);
connect(device, &ADevice::closed, this, &WSServer::onDeviceClosed);
sDebug() << "Added device : " << device->name();
}
void WSServer::removeDevice(ADevice *device)
{
setError(DeviceError, "Manualy removed the device (probably from the UI");
cleanUpDevice(device);
devices.removeAt(devices.indexOf(device));
devicesInfos.remove(device);
// TODO remove and disconnect WS
}
void WSServer::addDeviceFactory(DeviceFactory *devFact)
{
sDebug() << "Adding Device Factory " << devFact->name();
if (devFact->hasAsyncListDevices())
{
numberOfAsyncFactory++;
connect(devFact, &DeviceFactory::newDeviceName, this, &WSServer::onNewDeviceName);
connect(devFact, &DeviceFactory::devicesListDone, this, &WSServer::onDeviceListDone);
}
deviceFactories.append(devFact);
}
// TODO: this is bad if you do it during a devicelist request x)
void WSServer::removeDeviceFactory(DeviceFactory *devFact)
{
sDebug() << "Removing Device Factory" << devFact->name();
if (devFact->hasAsyncListDevices())
{
numberOfAsyncFactory--;
}
disconnect(devFact, nullptr, this, nullptr);
deviceFactories.removeAll(devFact);
}
QStringList WSServer::getClientsName(ADevice *dev)
{
QStringList toret;
QMapIterator<QWebSocket*, WSInfos> wsIit(wsInfos);
while (wsIit.hasNext())
{
auto p = wsIit.next();
if (p.value().attachedTo == dev)
{
toret << p.value().name;
}
}
return toret;
}
QList<WSServer::MiniDeviceInfos> WSServer::getDevicesInfo()
{
QList<MiniDeviceInfos> toret;
QListIterator<ADevice*> it(devices);
QStringList canAttachDev = getDevicesList();
while (it.hasNext())
{
MiniDeviceInfos mInfo;
mInfo.usable = true;
ADevice *dev = it.next();
sDebug() << dev->name();
mInfo.name = dev->name();
if (!canAttachDev.contains(dev->name()))
{
mInfo.usable = false;
mInfo.error = dev->attachError();
} else {
QMapIterator<QWebSocket*, WSInfos> wsIit(wsInfos);
while (wsIit.hasNext())
{
auto p = wsIit.next();
if (p.value().attachedTo == dev)
{
mInfo.clients << p.value().name;
}
}
}
toret.append(mInfo);
}
/* SD2SNES devices are created only when attached */
foreach (QString devName, canAttachDev)
{
bool pass = false;
foreach(MiniDeviceInfos mDev, toret)
{
if (devName == mDev.name)
pass = true;
}
if (pass)
continue;
MiniDeviceInfos mInfo;
mInfo.name = devName;
mInfo.usable = true;
toret.append(mInfo);
}
return toret;
}
void WSServer::addTrusted(QString origin)
{
trustedOrigin.append(origin);
}
void WSServer::onTextMessageReceived(QString message)
{
QWebSocket* ws = qobject_cast<QWebSocket*>(sender());
const WSInfos &wsInfo = wsInfos.value(ws);
sDebug() << wsInfo.name << "received " << message;
MRequest* req = requestFromJSON(message);
sDebug() << "Request is " << req->opcode;
if ((intptr_t)req->owner == 42)
goto LError;
req->owner = ws;
if (wsInfo.attached == false && !isValidUnAttached(req->opcode))
{
if (wsInfo.pendingAttach)
{
sDebug() << wsInfo.attachedTo->name() << "Adding request in queue (size:" << pendingRequests[wsInfo.attachedTo].size() << ")" << *req;
addToPendingRequest(wsInfo.attachedTo, req);
return ;
} else {
setError(ErrorType::ProtocolError, "Invalid command while unattached");
goto LError;
}
}
if (wsInfo.attached && !isValidUnAttached(req->opcode))
{
ADevice* dev = wsInfo.attachedTo;
sDebug() << "Device is " << dev->state();
if (dev->state() == ADevice::READY && pendingRequests[dev].isEmpty())
{
if ((isControlCommand(req->opcode) && !dev->hasControlCommands()) ||
(isFileCommand(req->opcode) && !dev->hasFileCommands()))
{
setError(ErrorType::DeviceError, QString("The device does not support the command %1").arg(cmdMetaEnum.valueToKey(static_cast<int>(req->opcode))));
goto LError;
}
currentRequests[dev] = req;
devicesInfos[dev].currentCommand = req->opcode;
devicesInfos[dev].currentWS = ws;
executeRequest(req);
} else { // add to queue
sDebug() << wsInfo.attachedTo->name() << "Adding request in queue " << *req << "(" << pendingRequests[wsInfo.attachedTo].size() << ")";
addToPendingRequest(wsInfo.attachedTo, req);
}
}
if (isValidUnAttached(req->opcode))
executeServerRequest(req);
return ;
LError:
clientError(ws);
}
void WSServer::addToPendingRequest(ADevice* device, MRequest *req)
{
pendingRequests[device].append(req);
if (req->opcode == USB2SnesWS::PutAddress || req->opcode == USB2SnesWS::PutIPS || req->opcode == USB2SnesWS::PutFile)
{
bool ok;
unsigned putSize = req->arguments.at(1).toUInt(&ok, 16);
if (req->opcode == USB2SnesWS::PutAddress && req->arguments.size() > 3)
{
putSize = 0;
for (int i = 0; i < req->arguments.size(); i += 2)
putSize += req->arguments.at(i + 1).toUShort(&ok, 16);
}
wsInfos[req->owner].pendingPutSizes.append(putSize);
sDebug() << "Adding a Put command in queue, adding size" << wsInfos[req->owner].pendingPutSizes.last();
}
}
void WSServer::onBinaryMessageReceived(QByteArray data)
{
QWebSocket* ws = qobject_cast<QWebSocket*>(sender());
WSInfos& infos = wsInfos[ws];
infos.recvData.append(data);
infos.byteReceived += data.size();
ADevice* dev = wsInfos.value(ws).attachedTo;
sDebug() << infos.name << "Received binary data" << data.size() << "Pending size: " << infos.pendingPutSizes;
if (infos.commandState != ClientCommandState::WAITINGBDATAREPLY && infos.pendingPutSizes.empty())
{
setError(ErrorType::ProtocolError, "Sending binary data when nothing waiting for it");
clientError(ws);
} else {
if (infos.ipsSize != 0)
{
sDebug() << "Data sent are IPS data";
infos.ipsData.append(data);
if (infos.ipsData.size() == infos.ipsSize)
{
infos.recvData.clear();
infos.byteReceived = 0;
infos.ipsSize = 0;
processIpsData(ws);
}
return ;
}
QList<unsigned int>& pend = infos.pendingPutSizes;
sDebug() << "Pend empty : " << pend.isEmpty() << "Current PUT" << infos.currentPutSize;
if (pend.isEmpty() || infos.currentPutSize != 0) {
infos.byteReceived = 0;
infos.recvData.clear();
if (data.size() == infos.currentPutSize)
{
infos.currentPutSize = 0; // the call to write data can trigger other signal.
dev->writeData(data);
return ;
}
if (data.size() < infos.currentPutSize) // We need two case since the previous one can
// trigger the finish signal and mess up currentPutSize
{
dev->writeData(data);
infos.currentPutSize -= data.size();
return ;
} else {
QByteArray toWrite = data.left(infos.currentPutSize);
data = data.mid(infos.currentPutSize);
infos.currentPutSize = 0;
dev->writeData(toWrite);
if (!data.isEmpty()) // This is probably data for the next cmd
{
if (infos.pendingPutSizes.isEmpty() && infos.currentPutSize == 0)
{
sDebug() << "Sending too much data to Websocket";
ws->close();
cleanUpSocket(ws);
return ;
}
while (infos.currentPutSize != 0 && !data.isEmpty()) // the previous writeData triggered a request in queue
{
toWrite = data.left(infos.currentPutSize);
data = data.mid(infos.currentPutSize);
infos.currentPutSize = 0;
dev->writeData(toWrite);
}
if (!data.isEmpty()) // we should probably move that highter
{
QByteArray nextData = data.left(infos.pendingPutSizes.first());
qDebug() << "Next data : "<< nextData.size();
while (!nextData.isEmpty() && !infos.pendingPutSizes.isEmpty() &&
nextData.size() == infos.pendingPutSizes.first())
{
infos.pendingPutDatas.append(nextData);
nextData = data.left(infos.pendingPutSizes.first());
}
}
}
//sDebug() << "Wriging before cps :" << __func__ << infos.currentPutSize;
infos.currentPutSize = 0;
//sDebug() << "Wriging after cps :" << __func__ << infos.currentPutSize;
}
}
sDebug() << "Data for pending request" << infos.byteReceived << pend.first();
sDebug() << infos.name << "Putting data in queue";
//infos.pendingPutDatas.append(data);
if (pend.first() == infos.byteReceived)
{
sDebug() << infos.name << "Putting data in queue";
infos.pendingPutDatas.append(infos.recvData);
pend.removeFirst();
//infos.pendingPutReqWithNoData.removeFirst();
infos.byteReceived = 0;
infos.recvData.clear();
}
}
}
void WSServer::onClientDisconnected()
{
QWebSocket* ws = qobject_cast<QWebSocket*>(sender());
sInfo() << "Websocket disconnected" << wsInfos.value(ws).name;
cleanUpSocket(ws);
}
void WSServer::onClientError(QAbstractSocket::SocketError)
{
QWebSocket* ws = qobject_cast<QWebSocket*>(sender());
sInfo() << "Client error : " << wsInfos.value(ws).name << ws->errorString();
}
void WSServer::onDeviceCommandFinished()
{
ADevice* device = qobject_cast<ADevice*>(sender());
if (devicesInfos[device].currentWS != nullptr)
{
processDeviceCommandFinished(device);
processCommandQueue(device);
}
else
sDebug() << "Received finished command while no socket to receive it";
}
void WSServer::onDeviceProtocolError()
{
ADevice* device = qobject_cast<ADevice*>(sender());
sInfo() << "Device Error" << device->name();
setError(ProtocolError, "Error in device protocol");
disconnect(device, &ADevice::closed, this, &WSServer::onDeviceClosed);
cleanUpDevice(device);
}
void WSServer::onDeviceClosed()
{
ADevice* dev = qobject_cast<ADevice*>(sender());
sInfo() << "Device closed" << dev->name();
disconnect(dev, &ADevice::closed, this, &WSServer::onDeviceClosed);
cleanUpDevice(dev);
}
void WSServer::onDeviceGetDataReceived(QByteArray data)
{
ADevice* device = qobject_cast<ADevice*>(sender());
if (devicesInfos.value(device).currentWS == nullptr)
{
sDebug() << "NOOP Sending get data to nothing" << device->name();
return ;
}
sDebug() << "Sending " << data.size() << "to" << wsInfos.value(devicesInfos[device].currentWS).name;
devicesInfos[device].currentWS->sendBinaryMessage(data);
}
// Used for Get File
void WSServer::onDeviceSizeGet(unsigned int size)
{
ADevice* device = qobject_cast<ADevice*>(sender());
sendReply(devicesInfos[device].currentWS, QString::number(size, 16));
}
void WSServer::processCommandQueue(ADevice* device)
{
QList<MRequest*>& cmdQueue = pendingRequests[device];
if (!cmdQueue.isEmpty())
{
sDebug() << cmdQueue.size() << " requests in queue, processing the first";
MRequest* req = cmdQueue.takeFirst();
currentRequests[device] = req;
devicesInfos[device].currentCommand = req->opcode;
devicesInfos[device].currentWS = req->owner;
req->wasPending = true;
// Request is no longer in queue, so expected data need to not go in queue
// if not already here.
/*if (req->opcode == USB2SnesWS::PutAddress)
{
WSInfos& wInfos = wsInfos[req->owner];
if (wInfos.pendingPutReqWithNoData.contains(req))
{
wInfos.pendingPutReqWithNoData.removeFirst();
wInfos.pendingPutSizes.removeFirst();
}
}*/
executeRequest(req);
}
}
void WSServer::setError(const WSServer::ErrorType type, const QString reason)
{
m_errorType = type;
m_errorString = reason;
}
WSServer::MRequest* WSServer::requestFromJSON(const QString &str)
{
MRequest *req = new MRequest();
req->state = RequestState::NEW;
req->owner = nullptr;
QJsonDocument jdoc = QJsonDocument::fromJson(str.toLatin1());
QJsonObject job = jdoc.object();
QString opcode = job["Opcode"].toString();
if (cmdMetaEnum.keyToValue(qPrintable(opcode)) == -1)
{
req->owner = (QWebSocket*)(42);
setError(ErrorType::ProtocolError, "Invalid OPcode send" + opcode);
return req;
}
if (job.contains("Space"))
{
QString space = job["Space"].toString();
if (spaceMetaEnum.keyToValue(qPrintable(space)) == -1)
{
req->owner = (QWebSocket*)(42);
setError(ErrorType::ProtocolError, "Invalid Space send" + space);
return req;
}
req->space = (SD2Snes::space) spaceMetaEnum.keyToValue(qPrintable(space));
}
req->opcode = (USB2SnesWS::opcode) cmdMetaEnum.keyToValue(qPrintable(opcode));
if (job.contains("Operands"))
{
QJsonArray jarray = job["Operands"].toArray();
foreach(QVariant entry, jarray.toVariantList())
{
req->arguments << entry.toString();
}
}
if (job.contains("Flags"))
{
QJsonArray jarray = job["Flags"].toArray();
foreach(QVariant entry, jarray.toVariantList())
{
req->flags << entry.toString();
}
}
req->timeCreated = QTime::currentTime();
return req;
}
void WSServer::clientError(QWebSocket *ws)
{
sInfo() << "Error with a ws client " << wsInfos[ws].name << m_errorType << m_errorString;
ws->close();
emit error();
}
void WSServer::cleanUpDevice(ADevice* device)
{
sDebug() << "Cleaning up device " << device->name();
DeviceInfos& devInfo = devicesInfos[device];
QMapIterator<QWebSocket*, WSInfos> it(wsInfos);
QList<QWebSocket*> toDiscard;
while (it.hasNext())
{
it.next();
if (it.value().attachedTo == device)
toDiscard.append(it.key());
}
foreach (QWebSocket* ws, toDiscard)
{
setError(WSServer::DeviceError, "Device closed");
clientError(ws);
}
if (devInfo.currentWS != nullptr)
devInfo.currentWS = nullptr;
DeviceFactory* devFact = mapDevFact[device];
mapDevFact.remove(device);
disconnect(device, nullptr, this, nullptr);
devices.removeAll(device);
devFact->deleteDevice(device);
}
void WSServer::cleanUpSocket(QWebSocket *ws)
{
WSInfos wInfo = wsInfos.value(ws);
sDebug() << "Cleaning up wsocket" << wInfo.name;
if (pendingDeviceListWebsocket.contains(ws))
{
pendingDeviceListQuery -= pendingDeviceListWebsocket.count(ws);
pendingDeviceListWebsocket.removeAll(ws);
QMutableListIterator<MRequest*> it(pendingDeviceListRequests);
while (it.hasNext())
{
it.next();
if (it.value()->owner == ws)
{
it.value()->owner = nullptr;
it.value()->state = RequestState::CANCELLED;
it.remove();
}
}
}
if (wInfo.attached)
{
ADevice* dev = wInfo.attachedTo;
MRequest* req = currentRequests[dev];
if (devicesInfos.value(dev).currentWS == ws)
devicesInfos[dev].currentWS = nullptr;
if (req != nullptr && req->owner == ws)
{
req->owner = nullptr;
req->state = RequestState::CANCELLED;
}
// Removing pending request that are tied to this ws
QMutableListIterator<MRequest*> it(pendingRequests[dev]);
while(it.hasNext())
{
MRequest* mReq = it.next();
if (mReq->owner == ws)
{
it.remove();
delete mReq;
}
}
}
wsInfos.remove(ws);
ws->deleteLater();
}
bool WSServer::isValidUnAttached(const USB2SnesWS::opcode opcode)
{
if (opcode == USB2SnesWS::Attach ||
opcode == USB2SnesWS::AppVersion ||
opcode == USB2SnesWS::Name ||
opcode == USB2SnesWS::DeviceList ||
opcode == USB2SnesWS::Close)
return true;
return false;
}
void WSServer::sendReply(QWebSocket* ws, const QStringList& args)
{
if (ws == nullptr)
{
sDebug() << "NOOP: Sending reply to a non existing client";
return ;
}
QJsonObject jObj;
QJsonArray ja;
foreach(QString s, args)
{
ja.append(QJsonValue(s));
}
jObj["Results"] = ja;
sDebug() << wsInfos.value(ws).name << ">>" << QJsonDocument(jObj).toJson();
ws->sendTextMessage(QJsonDocument(jObj).toJson());
}
void WSServer::sendReply(QWebSocket *ws, QString args)
{
sendReply(ws, QStringList() << args);
}
QDebug operator<<(QDebug debug, const WSServer::MRequest &req)
{
debug << req.id << "Created at" << req.timeCreated << "-" << req.opcode << req.space << req.flags << req.arguments << req.state;
return debug;
}