Some work about adaptive color scheme for Web UI (PR #19901)
http://[316:c51a:62a3:8b9::4]/d4708/qBittorrent/src/branch/adaptive-webui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
4.0 KiB
149 lines
4.0 KiB
17 years ago
|
/*
|
||
16 years ago
|
* Bittorrent Client using Qt4 and libtorrent.
|
||
|
* Copyright (C) 2006 Ishan Arora and Christophe Dumez
|
||
17 years ago
|
*
|
||
16 years ago
|
* This program is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU General Public License
|
||
|
* as published by the Free Software Foundation; either version 2
|
||
|
* of the License, or (at your option) any later version.
|
||
17 years ago
|
*
|
||
16 years ago
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
17 years ago
|
*
|
||
16 years ago
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
*
|
||
|
* In addition, as a special exception, the copyright holders give permission to
|
||
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
||
|
* and distribute the linked executables. You must obey the GNU General Public
|
||
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
||
|
* modify file(s), you may extend this exception to your version of the file(s),
|
||
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||
|
* exception statement from your version.
|
||
|
*
|
||
|
* Contact : chris@qbittorrent.org
|
||
17 years ago
|
*/
|
||
|
|
||
|
|
||
|
#include "httprequestparser.h"
|
||
|
#include <QUrl>
|
||
|
#include <QDebug>
|
||
|
|
||
|
HttpRequestParser::HttpRequestParser()
|
||
|
{
|
||
|
headerDone = false;
|
||
|
messageDone = false;
|
||
|
error = false;
|
||
|
}
|
||
|
|
||
|
HttpRequestParser::~HttpRequestParser()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool HttpRequestParser::isParsable() const
|
||
|
{
|
||
|
return !error && headerDone && isValid() && (messageDone || !hasContentLength() || contentLength() == 0);
|
||
|
}
|
||
|
|
||
|
bool HttpRequestParser::isError() const
|
||
|
{
|
||
|
return error;
|
||
|
}
|
||
|
|
||
|
QString HttpRequestParser::url() const
|
||
|
{
|
||
|
return path;
|
||
|
}
|
||
|
|
||
17 years ago
|
QByteArray HttpRequestParser::message() const
|
||
17 years ago
|
{
|
||
|
if(isParsable())
|
||
|
return data;
|
||
17 years ago
|
return QByteArray();
|
||
17 years ago
|
}
|
||
|
|
||
|
QString HttpRequestParser::get(const QString key) const
|
||
|
{
|
||
|
return getMap[key];
|
||
|
}
|
||
|
|
||
|
QString HttpRequestParser::post(const QString key) const
|
||
|
{
|
||
|
return postMap[key];
|
||
|
}
|
||
|
|
||
17 years ago
|
QByteArray HttpRequestParser::torrent() const
|
||
|
{
|
||
|
return torrent_content;
|
||
|
}
|
||
|
|
||
|
void HttpRequestParser::write(QByteArray str)
|
||
17 years ago
|
{
|
||
|
while (!headerDone && str.size()>0)
|
||
|
{
|
||
|
int index = str.indexOf('\n') + 1;
|
||
|
if(index == 0)
|
||
|
{
|
||
|
data += str;
|
||
|
str.clear();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
data += str.left(index);
|
||
|
str.remove(0, index);
|
||
|
if(data.right(4) == "\r\n\r\n")
|
||
|
{
|
||
|
QHttpRequestHeader::operator=(QHttpRequestHeader(data));
|
||
|
headerDone = true;
|
||
|
data.clear();
|
||
|
QUrl url = QUrl::fromEncoded(QHttpRequestHeader::path().toAscii());
|
||
|
path = url.path();
|
||
16 years ago
|
//() << path;
|
||
17 years ago
|
QListIterator<QPair<QString, QString> > i(url.queryItems());
|
||
|
while (i.hasNext())
|
||
|
{
|
||
|
QPair<QString, QString> pair = i.next();
|
||
|
getMap[pair.first] = pair.second;
|
||
16 years ago
|
//qDebug() << pair.first << "=" << get(pair.first);
|
||
17 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if(!messageDone && str.size()>0)
|
||
|
{
|
||
|
if(hasContentLength())
|
||
|
{
|
||
|
data += str;
|
||
|
if(data.size() >= (int) contentLength())
|
||
|
{
|
||
|
data.resize(contentLength());
|
||
|
messageDone = true;
|
||
|
//parse POST data
|
||
|
if(contentType() == "application/x-www-form-urlencoded")
|
||
|
{
|
||
|
QUrl url;
|
||
17 years ago
|
url.setEncodedQuery(data);
|
||
17 years ago
|
QListIterator<QPair<QString, QString> > i(url.queryItems());
|
||
|
while (i.hasNext())
|
||
|
{
|
||
|
QPair<QString, QString> pair = i.next();
|
||
|
postMap[pair.first] = pair.second;
|
||
16 years ago
|
//qDebug() << pair.first << "=" << post(pair.first);
|
||
17 years ago
|
}
|
||
|
}
|
||
17 years ago
|
if(contentType() == "multipart/form-data")
|
||
|
{
|
||
|
//qDebug() << data.right(data.size()-data.indexOf("\r\n\r\n")-QByteArray("\r\n\r\n").size());
|
||
|
torrent_content = data.right(data.size()-data.indexOf("\r\n\r\n")-QByteArray("\r\n\r\n").size());
|
||
|
}
|
||
17 years ago
|
}
|
||
|
}
|
||
|
else
|
||
|
error = true;
|
||
16 years ago
|
}
|
||
17 years ago
|
}
|