Browse Source

Use the new Http classes.

adaptive-webui-19844
sledgehammer999 11 years ago
parent
commit
e8c14f3507
  1. 9
      src/tracker/qtracker.cpp
  2. 1
      src/tracker/qtracker.h
  3. 4
      src/webui/httpconnection.cpp
  4. 2
      src/webui/httprequestparser.cpp
  5. 6
      src/webui/httprequestparser.h
  6. 2
      src/webui/httpresponsegenerator.cpp
  7. 4
      src/webui/httpresponsegenerator.h

9
src/tracker/qtracker.cpp

@ -28,7 +28,6 @@
* Contact : chris@qbittorrent.org * Contact : chris@qbittorrent.org
*/ */
#include <QHttpRequestHeader>
#include <QTcpSocket> #include <QTcpSocket>
#include <QUrl> #include <QUrl>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
@ -38,6 +37,8 @@
#include <libtorrent/bencode.hpp> #include <libtorrent/bencode.hpp>
#include <libtorrent/entry.hpp> #include <libtorrent/entry.hpp>
#include "httprequestheader.h"
#include "httpresponseheader.h"
#include "qtracker.h" #include "qtracker.h"
#include "preferences.h" #include "preferences.h"
@ -90,7 +91,7 @@ void QTracker::readRequest()
QTcpSocket *socket = static_cast<QTcpSocket*>(sender()); QTcpSocket *socket = static_cast<QTcpSocket*>(sender());
QByteArray input = socket->readAll(); QByteArray input = socket->readAll();
//qDebug("QTracker: Raw request:\n%s", input.data()); //qDebug("QTracker: Raw request:\n%s", input.data());
QHttpRequestHeader http_request(input); HttpRequestHeader http_request(input);
if (!http_request.isValid()) { if (!http_request.isValid()) {
qDebug("QTracker: Invalid HTTP Request:\n %s", qPrintable(http_request.toString())); qDebug("QTracker: Invalid HTTP Request:\n %s", qPrintable(http_request.toString()));
respondInvalidRequest(socket, 100, "Invalid request type"); respondInvalidRequest(socket, 100, "Invalid request type");
@ -129,7 +130,7 @@ void QTracker::readRequest()
void QTracker::respondInvalidRequest(QTcpSocket *socket, int code, QString msg) void QTracker::respondInvalidRequest(QTcpSocket *socket, int code, QString msg)
{ {
QHttpResponseHeader response; HttpResponseHeader response;
response.setStatusLine(code, msg); response.setStatusLine(code, msg);
socket->write(response.toString().toLocal8Bit()); socket->write(response.toString().toLocal8Bit());
socket->disconnectFromHost(); socket->disconnectFromHost();
@ -246,7 +247,7 @@ void QTracker::ReplyWithPeerList(QTcpSocket *socket, const TrackerAnnounceReques
QByteArray reply(&buf[0], buf.size()); QByteArray reply(&buf[0], buf.size());
qDebug("QTracker: reply with the following bencoded data:\n %s", reply.constData()); qDebug("QTracker: reply with the following bencoded data:\n %s", reply.constData());
// HTTP reply // HTTP reply
QHttpResponseHeader response; HttpResponseHeader response;
response.setStatusLine(200, "OK"); response.setStatusLine(200, "OK");
socket->write(response.toString().toLocal8Bit() + reply); socket->write(response.toString().toLocal8Bit() + reply);
socket->disconnectFromHost(); socket->disconnectFromHost();

1
src/tracker/qtracker.h

@ -32,7 +32,6 @@
#define QTRACKER_H #define QTRACKER_H
#include <QTcpServer> #include <QTcpServer>
#include <QHttpResponseHeader>
#include <QHash> #include <QHash>
#include "trackerannouncerequest.h" #include "trackerannouncerequest.h"

4
src/webui/httpconnection.cpp

@ -31,6 +31,8 @@
#include "httpconnection.h" #include "httpconnection.h"
#include "httpserver.h" #include "httpserver.h"
#include "httprequestheader.h"
#include "httpresponseheader.h"
#include "preferences.h" #include "preferences.h"
#include "btjson.h" #include "btjson.h"
#include "prefjson.h" #include "prefjson.h"
@ -42,8 +44,6 @@
#include <QTcpSocket> #include <QTcpSocket>
#include <QDateTime> #include <QDateTime>
#include <QStringList> #include <QStringList>
#include <QHttpRequestHeader>
#include <QHttpResponseHeader>
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
#include <QRegExp> #include <QRegExp>

2
src/webui/httprequestparser.cpp

@ -71,7 +71,7 @@ const QList<QByteArray>& HttpRequestParser::torrents() const {
void HttpRequestParser::writeHeader(const QByteArray& ba) { void HttpRequestParser::writeHeader(const QByteArray& ba) {
m_error = false; m_error = false;
// Parse header // Parse header
m_header = QHttpRequestHeader(ba); m_header = HttpRequestHeader(ba);
QUrl url = QUrl::fromEncoded(m_header.path().toLatin1()); QUrl url = QUrl::fromEncoded(m_header.path().toLatin1());
m_path = url.path(); m_path = url.path();

6
src/webui/httprequestparser.h

@ -32,8 +32,8 @@
#ifndef HTTPREQUESTPARSER_H #ifndef HTTPREQUESTPARSER_H
#define HTTPREQUESTPARSER_H #define HTTPREQUESTPARSER_H
#include <QHttpRequestHeader>
#include <QHash> #include <QHash>
#include "httprequestheader.h"
class HttpRequestParser { class HttpRequestParser {
@ -49,10 +49,10 @@ public:
void writeHeader(const QByteArray& ba); void writeHeader(const QByteArray& ba);
void writeMessage(const QByteArray& ba); void writeMessage(const QByteArray& ba);
bool acceptsEncoding(); bool acceptsEncoding();
inline const QHttpRequestHeader& header() const { return m_header; } inline const HttpRequestHeader& header() const { return m_header; }
private: private:
QHttpRequestHeader m_header; HttpRequestHeader m_header;
bool m_error; bool m_error;
QByteArray m_data; QByteArray m_data;
QString m_path; QString m_path;

2
src/webui/httpresponsegenerator.cpp

@ -136,5 +136,5 @@ QByteArray HttpResponseGenerator::toByteArray() {
} }
setContentLength(m_message.size()); setContentLength(m_message.size());
return QHttpResponseHeader::toString().toUtf8() + m_message; return HttpResponseHeader::toString().toUtf8() + m_message;
} }

4
src/webui/httpresponsegenerator.h

@ -32,9 +32,9 @@
#ifndef HTTPRESPONSEGENERATOR_H #ifndef HTTPRESPONSEGENERATOR_H
#define HTTPRESPONSEGENERATOR_H #define HTTPRESPONSEGENERATOR_H
#include<QHttpResponseHeader> #include "httpresponseheader.h"
class HttpResponseGenerator : public QHttpResponseHeader class HttpResponseGenerator : public HttpResponseHeader
{ {
public: public:

Loading…
Cancel
Save