HTTP server logging migration (and other random small cleanups) (#106)

This commit is contained in:
penfold42 2016-07-12 21:47:30 +10:00 committed by brindosch
parent b7b17b36e8
commit 49f16ac2e6
8 changed files with 9 additions and 22 deletions

View File

@ -1,5 +1,4 @@
// QT includes // QT includes
#include <QDebug>
#include <QDateTime> #include <QDateTime>
// Hyperion includes // Hyperion includes

View File

@ -1,5 +1,4 @@
// QT includes // QT includes
#include <QDebug>
#include <QDateTime> #include <QDateTime>
// Hyperion includes // Hyperion includes

View File

@ -164,7 +164,7 @@ void ProtoConnection::sendMessage(const proto::HyperionRequest &message)
break; break;
default: default:
//std::cout << "Connecting to Hyperion: " << _host.toStdString() << ":" << _port << std::endl; Debug(_log, "Connecting to Hyperion: %s:%d", _host.toStdString().c_str(), _port);
break; break;
} }
_prevSocketState = _socket.state(); _prevSocketState = _socket.state();

View File

@ -23,8 +23,6 @@ void CgiHandler::exec(const QStringList & args, QtHttpRequest * request, QtHttpR
{ {
// QByteArray header = reply->getHeader(QtHttpHeader::Host); // QByteArray header = reply->getHeader(QtHttpHeader::Host);
// QtHttpRequest::ClientInfo info = request->getClientInfo(); // QtHttpRequest::ClientInfo info = request->getClientInfo();
// qDebug() << info.clientAddress.toString();
// qDebug() << info.serverAddress.toString();
cmd_cfg_jsonserver(args,reply); cmd_cfg_jsonserver(args,reply);
cmd_cfg_hyperion(args,reply); cmd_cfg_hyperion(args,reply);

View File

@ -50,10 +50,6 @@ void QtHttpClientWrapper::onClientDataReceived (void) {
QString url = parts.at (1); QString url = parts.at (1);
QString version = parts.at (2); QString version = parts.at (2);
if (version == QtHttpServer::HTTP_VERSION) { if (version == QtHttpServer::HTTP_VERSION) {
//qDebug () << "Debug : HTTP"
// << "command :" << command
// << "url :" << url
// << "version :" << version;
m_currentRequest = new QtHttpRequest (m_serverHandle); m_currentRequest = new QtHttpRequest (m_serverHandle);
m_currentRequest->setClientInfo(m_sockClient->localAddress(), m_sockClient->peerAddress()); m_currentRequest->setClientInfo(m_sockClient->localAddress(), m_sockClient->peerAddress());
m_currentRequest->setUrl (QUrl (url)); m_currentRequest->setUrl (QUrl (url));
@ -78,9 +74,6 @@ void QtHttpClientWrapper::onClientDataReceived (void) {
if (pos > 0) { if (pos > 0) {
QByteArray header = raw.left (pos).trimmed (); QByteArray header = raw.left (pos).trimmed ();
QByteArray value = raw.mid (pos +1).trimmed (); QByteArray value = raw.mid (pos +1).trimmed ();
//qDebug () << "Debug : HTTP"
// << "header :" << header
// << "value :" << value;
m_currentRequest->addHeader (header, value); m_currentRequest->addHeader (header, value);
if (header == QtHttpHeader::ContentLength) { if (header == QtHttpHeader::ContentLength) {
int len = -1; int len = -1;
@ -97,7 +90,6 @@ void QtHttpClientWrapper::onClientDataReceived (void) {
} }
} }
else { // end of headers else { // end of headers
//qDebug () << "Debug : HTTP end of headers";
if (m_currentRequest->getHeader (QtHttpHeader::ContentLength).toInt () > 0) { if (m_currentRequest->getHeader (QtHttpHeader::ContentLength).toInt () > 0) {
m_parsingStatus = AwaitingContent; m_parsingStatus = AwaitingContent;
} }
@ -109,11 +101,7 @@ void QtHttpClientWrapper::onClientDataReceived (void) {
} }
case AwaitingContent: { // raw data × N (until EOF ??) case AwaitingContent: { // raw data × N (until EOF ??)
m_currentRequest->appendRawData (line); 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 ()) { if (m_currentRequest->getRawDataSize () == m_currentRequest->getHeader (QtHttpHeader::ContentLength).toInt ()) {
//qDebug () << "Debug : HTTP end of content";
m_parsingStatus = RequestParsed; m_parsingStatus = RequestParsed;
} }
break; break;

View File

@ -7,7 +7,6 @@
#include <QTcpServer> #include <QTcpServer>
#include <QTcpSocket> #include <QTcpSocket>
#include <QHostAddress> #include <QHostAddress>
#include <QDebug>
const QString & QtHttpServer::HTTP_VERSION = QStringLiteral ("HTTP/1.1"); const QString & QtHttpServer::HTTP_VERSION = QStringLiteral ("HTTP/1.1");

View File

@ -3,7 +3,6 @@
#include <QStringBuilder> #include <QStringBuilder>
#include <QUrlQuery> #include <QUrlQuery>
#include <QDebug>
#include <QList> #include <QList>
#include <QPair> #include <QPair>
#include <QFile> #include <QFile>
@ -13,6 +12,7 @@ StaticFileServing::StaticFileServing (Hyperion *hyperion, QString baseUrl, quint
, _hyperion(hyperion) , _hyperion(hyperion)
, _baseUrl (baseUrl) , _baseUrl (baseUrl)
, _cgi(hyperion, this) , _cgi(hyperion, this)
, _log(Logger::getInstance("WEBSERVER"))
{ {
_mimeDb = new QMimeDatabase; _mimeDb = new QMimeDatabase;
@ -34,16 +34,16 @@ StaticFileServing::~StaticFileServing ()
void StaticFileServing::onServerStarted (quint16 port) 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 () { void StaticFileServing::onServerStopped () {
qDebug () << "QtHttpServer stopped" << _server->getServerName (); Info(_log, "stopped %s", _server->getServerName().toStdString().c_str());
} }
void StaticFileServing::onServerError (QString msg) void StaticFileServing::onServerError (QString msg)
{ {
qDebug () << "QtHttpServer error :" << msg; Error(_log, "%s", msg.toStdString().c_str());
} }
static inline void printErrorToReply (QtHttpReply * reply, QString errorMessage) static inline void printErrorToReply (QtHttpReply * reply, QString errorMessage)

View File

@ -11,6 +11,8 @@
#include "CgiHandler.h" #include "CgiHandler.h"
#include <hyperion/Hyperion.h> #include <hyperion/Hyperion.h>
#include <utils/Logger.h>
class StaticFileServing : public QObject { class StaticFileServing : public QObject {
Q_OBJECT Q_OBJECT
@ -31,6 +33,8 @@ private:
QtHttpServer * _server; QtHttpServer * _server;
QMimeDatabase * _mimeDb; QMimeDatabase * _mimeDb;
CgiHandler _cgi; CgiHandler _cgi;
Logger * _log;
}; };
#endif // STATICFILESERVING_H #endif // STATICFILESERVING_H