mirror of
				https://github.com/hyperion-project/hyperion.ng.git
				synced 2025-03-01 10:33:28 +00:00 
			
		
		
		
	HTTP server logging migration (and other random small cleanups) (#106)
This commit is contained in:
		| @@ -1,5 +1,4 @@ | ||||
| // QT includes | ||||
| #include <QDebug> | ||||
| #include <QDateTime> | ||||
|  | ||||
| // Hyperion includes | ||||
|   | ||||
| @@ -1,5 +1,4 @@ | ||||
| // QT includes | ||||
| #include <QDebug> | ||||
| #include <QDateTime> | ||||
|  | ||||
| // Hyperion includes | ||||
|   | ||||
| @@ -164,7 +164,7 @@ void ProtoConnection::sendMessage(const proto::HyperionRequest &message) | ||||
| 		  break; | ||||
|  | ||||
| 		default: | ||||
| 		  //std::cout << "Connecting to Hyperion: " << _host.toStdString() << ":" << _port << std::endl; | ||||
| 		  Debug(_log, "Connecting to Hyperion: %s:%d", _host.toStdString().c_str(), _port); | ||||
| 		  break; | ||||
| 	  } | ||||
| 	  _prevSocketState = _socket.state(); | ||||
|   | ||||
| @@ -23,8 +23,6 @@ void CgiHandler::exec(const QStringList & args, QtHttpRequest * request, QtHttpR | ||||
| 	{ | ||||
| // 		QByteArray header = reply->getHeader(QtHttpHeader::Host); | ||||
| // 		QtHttpRequest::ClientInfo info = request->getClientInfo(); | ||||
| // 		qDebug() << info.clientAddress.toString(); | ||||
| // 		qDebug() << info.serverAddress.toString(); | ||||
| 		 | ||||
| 		cmd_cfg_jsonserver(args,reply); | ||||
| 		cmd_cfg_hyperion(args,reply); | ||||
|   | ||||
| @@ -50,10 +50,6 @@ void QtHttpClientWrapper::onClientDataReceived (void) { | ||||
|                         QString url     = parts.at (1); | ||||
|                         QString version = parts.at (2); | ||||
|                         if (version == QtHttpServer::HTTP_VERSION) { | ||||
|                             //qDebug () << "Debug : HTTP" | ||||
|                             //          << "command :" << command | ||||
|                             //          << "url :"     << url | ||||
|                             //          << "version :" << version; | ||||
|                             m_currentRequest = new QtHttpRequest (m_serverHandle); | ||||
|                             m_currentRequest->setClientInfo(m_sockClient->localAddress(), m_sockClient->peerAddress()); | ||||
|                             m_currentRequest->setUrl     (QUrl (url)); | ||||
| @@ -78,9 +74,6 @@ void QtHttpClientWrapper::onClientDataReceived (void) { | ||||
|                         if (pos > 0) { | ||||
|                             QByteArray header = raw.left (pos).trimmed (); | ||||
|                             QByteArray value  = raw.mid  (pos +1).trimmed (); | ||||
|                             //qDebug () << "Debug : HTTP" | ||||
|                             //          << "header :" << header | ||||
|                             //          << "value :"  << value; | ||||
|                             m_currentRequest->addHeader (header, value); | ||||
|                             if (header == QtHttpHeader::ContentLength) { | ||||
|                                 int  len = -1; | ||||
| @@ -97,7 +90,6 @@ void QtHttpClientWrapper::onClientDataReceived (void) { | ||||
|                         } | ||||
|                     } | ||||
|                     else { // end of headers | ||||
|                         //qDebug () << "Debug : HTTP end of headers"; | ||||
|                         if (m_currentRequest->getHeader (QtHttpHeader::ContentLength).toInt () > 0) { | ||||
|                             m_parsingStatus = AwaitingContent; | ||||
|                         } | ||||
| @@ -109,11 +101,7 @@ void QtHttpClientWrapper::onClientDataReceived (void) { | ||||
|                 } | ||||
|                 case AwaitingContent: { // raw data × N (until EOF ??) | ||||
|                     m_currentRequest->appendRawData (line); | ||||
|                     //qDebug () << "Debug : HTTP" | ||||
|                     //          << "content :" << m_currentRequest->getRawData ().toHex () | ||||
|                     //          << "size :"    << m_currentRequest->getRawData ().size  (); | ||||
|                     if (m_currentRequest->getRawDataSize () == m_currentRequest->getHeader (QtHttpHeader::ContentLength).toInt ()) { | ||||
|                         //qDebug () << "Debug : HTTP end of content"; | ||||
|                         m_parsingStatus = RequestParsed; | ||||
|                     } | ||||
|                     break; | ||||
|   | ||||
| @@ -7,7 +7,6 @@ | ||||
| #include <QTcpServer> | ||||
| #include <QTcpSocket> | ||||
| #include <QHostAddress> | ||||
| #include <QDebug> | ||||
|  | ||||
| const QString & QtHttpServer::HTTP_VERSION = QStringLiteral ("HTTP/1.1"); | ||||
|  | ||||
|   | ||||
| @@ -3,7 +3,6 @@ | ||||
|  | ||||
| #include <QStringBuilder> | ||||
| #include <QUrlQuery> | ||||
| #include <QDebug> | ||||
| #include <QList> | ||||
| #include <QPair> | ||||
| #include <QFile> | ||||
| @@ -13,6 +12,7 @@ StaticFileServing::StaticFileServing (Hyperion *hyperion, QString baseUrl, quint | ||||
| 		, _hyperion(hyperion) | ||||
| 		, _baseUrl (baseUrl) | ||||
| 		, _cgi(hyperion, this) | ||||
| 		, _log(Logger::getInstance("WEBSERVER")) | ||||
| { | ||||
| 	_mimeDb = new QMimeDatabase; | ||||
|  | ||||
| @@ -34,16 +34,16 @@ StaticFileServing::~StaticFileServing () | ||||
|  | ||||
| void StaticFileServing::onServerStarted (quint16 port) | ||||
| { | ||||
| 	qDebug () << "QtHttpServer started on port" << port << _server->getServerName (); | ||||
| 	Info(_log, "started on port %d name \"%s\"", port ,_server->getServerName().toStdString().c_str()); | ||||
| } | ||||
|  | ||||
| void StaticFileServing::onServerStopped () { | ||||
| 	qDebug () << "QtHttpServer stopped" << _server->getServerName (); | ||||
| 	Info(_log, "stopped %s", _server->getServerName().toStdString().c_str()); | ||||
| } | ||||
|  | ||||
| void StaticFileServing::onServerError (QString msg) | ||||
| { | ||||
| 	qDebug () << "QtHttpServer error :" << msg; | ||||
| 	Error(_log, "%s", msg.toStdString().c_str()); | ||||
| } | ||||
|  | ||||
| static inline void printErrorToReply (QtHttpReply * reply, QString errorMessage) | ||||
|   | ||||
| @@ -11,6 +11,8 @@ | ||||
| #include "CgiHandler.h" | ||||
|  | ||||
| #include <hyperion/Hyperion.h> | ||||
| #include <utils/Logger.h> | ||||
|  | ||||
|  | ||||
| class StaticFileServing : public QObject { | ||||
|     Q_OBJECT | ||||
| @@ -31,6 +33,8 @@ private: | ||||
| 	QtHttpServer  * _server; | ||||
| 	QMimeDatabase * _mimeDb; | ||||
| 	CgiHandler      _cgi; | ||||
|         Logger * _log; | ||||
|  | ||||
| }; | ||||
|  | ||||
| #endif // STATICFILESERVING_H | ||||
|   | ||||
		Reference in New Issue
	
	Block a user