@@ -657,6 +657,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
657
657
const QString URI_ASSIGNMENT = " /assignment" ;
658
658
const QString URI_NODES = " /nodes" ;
659
659
660
+ const QString UUID_REGEX_STRING = " [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" ;
661
+
660
662
if (connection->requestOperation () == QNetworkAccessManager::GetOperation) {
661
663
if (url.path () == " /assignments.json" ) {
662
664
// user is asking for json list of assignments
@@ -726,9 +728,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
726
728
727
729
return true ;
728
730
} else {
729
- const QString NODE_REGEX_STRING =
730
- QString (" \\ %1\\ /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}).json\\ /?$" ).arg (URI_NODES);
731
- QRegExp nodeShowRegex (NODE_REGEX_STRING);
731
+ const QString NODE_JSON_REGEX_STRING = QString (" \\ %1\\ /(%2).json\\ /?$" ).arg (URI_NODES).arg (UUID_REGEX_STRING);
732
+ QRegExp nodeShowRegex (NODE_JSON_REGEX_STRING);
732
733
733
734
if (nodeShowRegex.indexIn (url.path ()) != -1 ) {
734
735
QUuid matchingUUID = QUuid (nodeShowRegex.cap (1 ));
@@ -801,29 +802,35 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
801
802
return true ;
802
803
}
803
804
} else if (connection->requestOperation () == QNetworkAccessManager::DeleteOperation) {
804
- if (url.path ().startsWith (URI_NODES)) {
805
- // this is a request to DELETE a node by UUID
805
+ const QString ALL_NODE_DELETE_REGEX_STRING = QString (" \\ %1\\ /?$" ).arg (URI_NODES);
806
+ const QString NODE_DELETE_REGEX_STRING = QString (" \\ %1\\ /(%2)\\ /$" ).arg (URI_NODES).arg (UUID_REGEX_STRING);
807
+
808
+ QRegExp allNodesDeleteRegex (ALL_NODE_DELETE_REGEX_STRING);
809
+ QRegExp nodeDeleteRegex (NODE_DELETE_REGEX_STRING);
810
+
811
+ if (nodeDeleteRegex.indexIn (url.path ()) != -1 ) {
812
+ // this is a request to DELETE one node by UUID
813
+
814
+ // pull the captured string, if it exists
815
+ QUuid deleteUUID = QUuid (nodeDeleteRegex.cap (1 ));
806
816
807
- // pull the UUID from the url
808
- QUuid deleteUUID = QUuid (url.path ().mid (URI_NODES.size () + sizeof (' /' )));
817
+ SharedNodePointer nodeToKill = NodeList::getInstance ()->nodeWithUUID (deleteUUID);
809
818
810
- if (!deleteUUID.isNull ()) {
811
- SharedNodePointer nodeToKill = NodeList::getInstance ()->nodeWithUUID (deleteUUID);
819
+ if (nodeToKill) {
820
+ // start with a 200 response
821
+ connection->respond (HTTPConnection::StatusCode200);
812
822
813
- if (nodeToKill) {
814
- // start with a 200 response
815
- connection->respond (HTTPConnection::StatusCode200);
816
-
817
- // we have a valid UUID and node - kill the node that has this assignment
818
- QMetaObject::invokeMethod (NodeList::getInstance (), " killNodeWithUUID" , Q_ARG (const QUuid&, deleteUUID));
819
-
820
- // successfully processed request
821
- return true ;
822
- }
823
+ // we have a valid UUID and node - kill the node that has this assignment
824
+ QMetaObject::invokeMethod (NodeList::getInstance (), " killNodeWithUUID" , Q_ARG (const QUuid&, deleteUUID));
825
+
826
+ // successfully processed request
827
+ return true ;
823
828
}
824
829
825
- // bad request, couldn't pull a node ID
826
- connection->respond (HTTPConnection::StatusCode400);
830
+ return true ;
831
+ } else if (allNodesDeleteRegex.indexIn (url.path ()) != -1 ) {
832
+ qDebug () << " Received request to kill all nodes." ;
833
+ NodeList::getInstance ()->eraseAllNodes ();
827
834
828
835
return true ;
829
836
}
0 commit comments