diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 4d15a98b33..c1be563672 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include #include @@ -34,7 +34,7 @@ const quint16 DOMAIN_SERVER_HTTP_PORT = 8080; DomainServer::DomainServer(int argc, char* argv[]) : QCoreApplication(argc, argv), - _httpManager(DOMAIN_SERVER_HTTP_PORT, QString("%1/resources/web/").arg(QCoreApplication::applicationDirPath()), this), + _HTTPManager(DOMAIN_SERVER_HTTP_PORT, QString("%1/resources/web/").arg(QCoreApplication::applicationDirPath()), this), _assignmentQueueMutex(), _assignmentQueue(), _staticAssignmentFile(QString("%1/config.ds").arg(QCoreApplication::applicationDirPath())), @@ -294,7 +294,7 @@ QJsonObject jsonObjectForNode(Node* node) { return nodeJson; } -bool DomainServer::handleHTTPRequest(HttpConnection* connection, const QString& path) { +bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QString& path) { const QString JSON_MIME_TYPE = "application/json"; const QString URI_ASSIGNMENT = "/assignment"; @@ -346,7 +346,7 @@ bool DomainServer::handleHTTPRequest(HttpConnection* connection, const QString& // print out the created JSON QJsonDocument assignmentDocument(assignmentJSON); - connection->respond(HttpConnection::StatusCode200, assignmentDocument.toJson(), qPrintable(JSON_MIME_TYPE)); + connection->respond(HTTPConnection::StatusCode200, assignmentDocument.toJson(), qPrintable(JSON_MIME_TYPE)); // we've processed this request return true; @@ -370,11 +370,11 @@ bool DomainServer::handleHTTPRequest(HttpConnection* connection, const QString& QJsonDocument nodesDocument(rootJSON); // send the response - connection->respond(HttpConnection::StatusCode200, nodesDocument.toJson(), qPrintable(JSON_MIME_TYPE)); + connection->respond(HTTPConnection::StatusCode200, nodesDocument.toJson(), qPrintable(JSON_MIME_TYPE)); } } else if (connection->requestOperation() == QNetworkAccessManager::PostOperation) { if (path == URI_ASSIGNMENT) { - // this is a script upload - ask the HttpConnection to parse the form data + // this is a script upload - ask the HTTPConnection to parse the form data QList formData = connection->parseFormData(); qDebug() << formData; } @@ -390,7 +390,7 @@ bool DomainServer::handleHTTPRequest(HttpConnection* connection, const QString& if (nodeToKill) { // start with a 200 response - connection->respond(HttpConnection::StatusCode200); + connection->respond(HTTPConnection::StatusCode200); // we have a valid UUID and node - kill the node that has this assignment QMetaObject::invokeMethod(NodeList::getInstance(), "killNodeWithUUID", Q_ARG(const QUuid&, deleteUUID)); @@ -401,7 +401,7 @@ bool DomainServer::handleHTTPRequest(HttpConnection* connection, const QString& } // bad request, couldn't pull a node ID - connection->respond(HttpConnection::StatusCode400); + connection->respond(HTTPConnection::StatusCode400); return true; } diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 96a33eb267..17f0904e21 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -16,7 +16,7 @@ #include #include -#include +#include #include const int MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS = 1000; @@ -26,7 +26,7 @@ class DomainServer : public QCoreApplication, public HttpRequestHandler { public: DomainServer(int argc, char* argv[]); - bool handleHTTPRequest(HttpConnection* connection, const QString& path); + bool handleHTTPRequest(HTTPConnection* connection, const QString& path); void exit(int retCode = 0); @@ -50,7 +50,7 @@ private: unsigned char* addNodeToBroadcastPacket(unsigned char* currentPosition, Node* nodeToAdd); - HttpManager _httpManager; + HTTPManager _HTTPManager; QMutex _assignmentQueueMutex; std::deque _assignmentQueue; diff --git a/libraries/embedded-webserver/src/HttpConnection.cpp b/libraries/embedded-webserver/src/HTTPConnection.cpp similarity index 91% rename from libraries/embedded-webserver/src/HttpConnection.cpp rename to libraries/embedded-webserver/src/HTTPConnection.cpp index 0ea14ea82b..3ffc96c9f4 100755 --- a/libraries/embedded-webserver/src/HttpConnection.cpp +++ b/libraries/embedded-webserver/src/HTTPConnection.cpp @@ -1,5 +1,5 @@ // -// HttpConnection.cpp +// HTTPConnection.cpp // hifi // // Created by Stephen Birarda on 1/16/14. @@ -11,14 +11,14 @@ #include #include -#include "HttpConnection.h" -#include "HttpManager.h" +#include "HTTPConnection.h" +#include "HTTPManager.h" -const char* HttpConnection::StatusCode200 = "200 OK"; -const char* HttpConnection::StatusCode400 = "400 Bad Request"; -const char* HttpConnection::StatusCode404 = "404 Not Found"; +const char* HTTPConnection::StatusCode200 = "200 OK"; +const char* HTTPConnection::StatusCode400 = "400 Bad Request"; +const char* HTTPConnection::StatusCode404 = "404 Not Found"; -HttpConnection::HttpConnection (QTcpSocket* socket, HttpManager* parentManager) : +HTTPConnection::HTTPConnection (QTcpSocket* socket, HTTPManager* parentManager) : QObject(parentManager), _parentManager(parentManager), _socket(socket), @@ -34,14 +34,14 @@ HttpConnection::HttpConnection (QTcpSocket* socket, HttpManager* parentManager) connect(socket, SIGNAL(disconnected()), SLOT(deleteLater())); } -HttpConnection::~HttpConnection() { +HTTPConnection::~HTTPConnection() { // log the destruction if (_socket->error() != QAbstractSocket::UnknownSocketError) { qDebug() << _socket->errorString(); } } -QList HttpConnection::parseFormData() const { +QList HTTPConnection::parseFormData() const { // make sure we have the correct MIME type QList elements = _requestHeaders.value("Content-Type").split(';'); if (elements.at(0).trimmed() != "multipart/form-data") { @@ -97,7 +97,7 @@ QList HttpConnection::parseFormData() const { return data; } -void HttpConnection::respond(const char* code, const QByteArray& content, const char* contentType, const Headers& headers) { +void HTTPConnection::respond(const char* code, const QByteArray& content, const char* contentType, const Headers& headers) { _socket->write("HTTP/1.1 "); _socket->write(code); _socket->write("\r\n"); @@ -132,7 +132,7 @@ void HttpConnection::respond(const char* code, const QByteArray& content, const _socket->disconnectFromHost(); } -void HttpConnection::readRequest() { +void HTTPConnection::readRequest() { if (!_socket->canReadLine()) { return; } @@ -169,7 +169,7 @@ void HttpConnection::readRequest() { readHeaders(); } -void HttpConnection::readHeaders() { +void HTTPConnection::readHeaders() { while (_socket->canReadLine()) { QByteArray line = _socket->readLine(); QByteArray trimmed = line.trimmed(); @@ -209,7 +209,7 @@ void HttpConnection::readHeaders() { } } -void HttpConnection::readContent() { +void HTTPConnection::readContent() { int size = _requestContent.size(); if (_socket->bytesAvailable() < size) { return; diff --git a/libraries/embedded-webserver/src/HttpConnection.h b/libraries/embedded-webserver/src/HTTPConnection.h old mode 100755 new mode 100644 similarity index 87% rename from libraries/embedded-webserver/src/HttpConnection.h rename to libraries/embedded-webserver/src/HTTPConnection.h index 23f210218f..80e470ece1 --- a/libraries/embedded-webserver/src/HttpConnection.h +++ b/libraries/embedded-webserver/src/HTTPConnection.h @@ -1,17 +1,17 @@ // -// HttpConnection.h +// HTTPConnection.h // hifi // // Created by Stephen Birarda on 1/16/14. // Copyright (c) 2014 HighFidelity, Inc. All rights reserved. // -// Heavily based on Andrzej Kapolka's original HttpConnection class +// Heavily based on Andrzej Kapolka's original HTTPConnection class // found from another one of his projects. // https://github.com/ey6es/witgap/tree/master/src/cpp/server/http // -#ifndef __hifi__HttpConnection__ -#define __hifi__HttpConnection__ +#ifndef __hifi__HTTPConnection__ +#define __hifi__HTTPConnection__ #include #include @@ -23,7 +23,7 @@ #include class QTcpSocket; -class HttpManager; +class HTTPManager; class MaskFilter; class ServerApp; @@ -34,7 +34,7 @@ typedef QHash Headers; typedef QPair FormData; /// Handles a single HTTP connection. -class HttpConnection : public QObject { +class HTTPConnection : public QObject { Q_OBJECT public: @@ -46,10 +46,10 @@ public: enum ReasonCode { NoReason = 0, NormalClosure = 1000, GoingAway = 1001 }; /// Initializes the connection. - HttpConnection (QTcpSocket* socket, HttpManager* parentManager); + HTTPConnection (QTcpSocket* socket, HTTPManager* parentManager); /// Destroys the connection. - virtual ~HttpConnection (); + virtual ~HTTPConnection (); /// Returns a pointer to the underlying socket, to which WebSocket message bodies should be written. QTcpSocket* socket () const { return _socket; } @@ -88,7 +88,7 @@ protected slots: protected: /// The parent HTTP manager - HttpManager* _parentManager; + HTTPManager* _parentManager; /// The underlying socket. QTcpSocket* _socket; @@ -115,4 +115,4 @@ protected: QByteArray _requestContent; }; -#endif /* defined(__hifi__HttpConnection__) */ +#endif /* defined(__hifi__HTTPConnection__) */ diff --git a/libraries/embedded-webserver/src/HttpManager.cpp b/libraries/embedded-webserver/src/HTTPManager.cpp similarity index 91% rename from libraries/embedded-webserver/src/HttpManager.cpp rename to libraries/embedded-webserver/src/HTTPManager.cpp index 58c6574db9..89712d825c 100755 --- a/libraries/embedded-webserver/src/HttpManager.cpp +++ b/libraries/embedded-webserver/src/HTTPManager.cpp @@ -1,5 +1,5 @@ // -// HttpManager.cpp +// HTTPManager.cpp // hifi // // Created by Stephen Birarda on 1/16/14. @@ -12,10 +12,10 @@ #include #include -#include "HttpConnection.h" -#include "HttpManager.h" +#include "HTTPConnection.h" +#include "HTTPManager.h" -bool HttpManager::handleHTTPRequest(HttpConnection* connection, const QString& path) { +bool HTTPManager::handleHTTPRequest(HTTPConnection* connection, const QString& path) { if (_requestHandler && _requestHandler->handleHTTPRequest(connection, path)) { // this request was handled by our _requestHandler object // so we don't need to attempt to do so in the document root @@ -99,16 +99,16 @@ bool HttpManager::handleHTTPRequest(HttpConnection* connection, const QString& p } } - connection->respond(HttpConnection::StatusCode200, localFileString.toLocal8Bit(), qPrintable(mimeDatabase.mimeTypeForFile(filePath).name())); + connection->respond(HTTPConnection::StatusCode200, localFileString.toLocal8Bit(), qPrintable(mimeDatabase.mimeTypeForFile(filePath).name())); } else { // respond with a 404 - connection->respond(HttpConnection::StatusCode404, "Resource not found."); + connection->respond(HTTPConnection::StatusCode404, "Resource not found."); } return true; } -HttpManager::HttpManager(quint16 port, const QString& documentRoot, HttpRequestHandler* requestHandler, QObject* parent) : +HTTPManager::HTTPManager(quint16 port, const QString& documentRoot, HttpRequestHandler* requestHandler, QObject* parent) : QTcpServer(parent), _documentRoot(documentRoot), _requestHandler(requestHandler) @@ -123,9 +123,9 @@ HttpManager::HttpManager(quint16 port, const QString& documentRoot, HttpRequestH connect(this, SIGNAL(newConnection()), SLOT(acceptConnections())); } -void HttpManager::acceptConnections() { +void HTTPManager::acceptConnections() { QTcpSocket* socket; while ((socket = nextPendingConnection()) != 0) { - new HttpConnection(socket, this); + new HTTPConnection(socket, this); } } diff --git a/libraries/embedded-webserver/src/HttpManager.h b/libraries/embedded-webserver/src/HTTPManager.h similarity index 60% rename from libraries/embedded-webserver/src/HttpManager.h rename to libraries/embedded-webserver/src/HTTPManager.h index 80a2c5ba2c..fdb7e1e915 100755 --- a/libraries/embedded-webserver/src/HttpManager.h +++ b/libraries/embedded-webserver/src/HTTPManager.h @@ -1,36 +1,36 @@ // -// HttpManager.h +// HTTPManager.h // hifi // // Created by Stephen Birarda on 1/16/14. // Copyright (c) 2014 HighFidelity, Inc. All rights reserved. // -// Heavily based on Andrzej Kapolka's original HttpManager class +// Heavily based on Andrzej Kapolka's original HTTPManager class // found from another one of his projects. // https://github.com/ey6es/witgap/tree/master/src/cpp/server/http // -#ifndef __hifi__HttpManager__ -#define __hifi__HttpManager__ +#ifndef __hifi__HTTPManager__ +#define __hifi__HTTPManager__ #include -class HttpConnection; +class HTTPConnection; class HttpRequestHandler { public: /// Handles an HTTP request. - virtual bool handleHTTPRequest(HttpConnection* connection, const QString& path) = 0; + virtual bool handleHTTPRequest(HTTPConnection* connection, const QString& path) = 0; }; /// Handles HTTP connections -class HttpManager : public QTcpServer, public HttpRequestHandler { +class HTTPManager : public QTcpServer, public HttpRequestHandler { Q_OBJECT public: /// Initializes the manager. - HttpManager(quint16 port, const QString& documentRoot, HttpRequestHandler* requestHandler = NULL, QObject* parent = 0); + HTTPManager(quint16 port, const QString& documentRoot, HttpRequestHandler* requestHandler = NULL, QObject* parent = 0); - bool handleHTTPRequest(HttpConnection* connection, const QString& path); + bool handleHTTPRequest(HTTPConnection* connection, const QString& path); protected slots: /// Accepts all pending connections @@ -40,4 +40,4 @@ protected: HttpRequestHandler* _requestHandler; }; -#endif /* defined(__hifi__HttpManager__) */ +#endif /* defined(__hifi__HTTPManager__) */