|
|
|
@ -61,8 +61,8 @@ QString HttpRequestParser::post(const QString& key) const {
@@ -61,8 +61,8 @@ QString HttpRequestParser::post(const QString& key) const {
|
|
|
|
|
return m_postMap.value(key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const QByteArray& HttpRequestParser::torrent() const { |
|
|
|
|
return m_torrentContent; |
|
|
|
|
const QList<QByteArray>& HttpRequestParser::torrents() const { |
|
|
|
|
return m_torrents; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HttpRequestParser::writeHeader(const QByteArray& ba) { |
|
|
|
@ -79,6 +79,18 @@ void HttpRequestParser::writeHeader(const QByteArray& ba) {
@@ -79,6 +79,18 @@ void HttpRequestParser::writeHeader(const QByteArray& ba) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static QList<QByteArray> splitRawData(QByteArray rawData, const QByteArray& sep) |
|
|
|
|
{ |
|
|
|
|
QList<QByteArray> ret; |
|
|
|
|
const int sepLength = sep.size(); |
|
|
|
|
int index = 0; |
|
|
|
|
while ((index = rawData.indexOf(sep)) >= 0) { |
|
|
|
|
ret << rawData.left(index); |
|
|
|
|
rawData = rawData.mid(index + sepLength); |
|
|
|
|
} |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HttpRequestParser::writeMessage(const QByteArray& ba) { |
|
|
|
|
// Parse message content
|
|
|
|
|
Q_ASSERT (m_header.hasContentLength()); |
|
|
|
@ -119,21 +131,29 @@ Submit Query
@@ -119,21 +131,29 @@ Submit Query
|
|
|
|
|
**/ |
|
|
|
|
if (m_header.contentType().startsWith("multipart/form-data")) { |
|
|
|
|
qDebug() << Q_FUNC_INFO << "header is: " << m_header.toString(); |
|
|
|
|
|
|
|
|
|
int filename_index = m_data.indexOf("filename="); |
|
|
|
|
if (filename_index >= 0) { |
|
|
|
|
QByteArray boundary = m_data.left(m_data.indexOf("\r\n")); |
|
|
|
|
qDebug() << "Boundary is " << boundary << "\n\n"; |
|
|
|
|
qDebug() << "Before binary data: " << m_data.left(m_data.indexOf("\r\n\r\n", filename_index+9)) << "\n\n"; |
|
|
|
|
m_torrentContent = m_data.mid(m_data.indexOf("\r\n\r\n", filename_index+9) + 4); |
|
|
|
|
int binaryend_index = m_torrentContent.indexOf("\r\n"+boundary); |
|
|
|
|
if (binaryend_index >= 0) { |
|
|
|
|
qDebug() << "found end boundary :)"; |
|
|
|
|
m_torrentContent = m_torrentContent.left(binaryend_index); |
|
|
|
|
static QRegExp boundaryRegexQuoted("boundary=\"([ \\w'()+,-\\./:=\\?]+)\""); |
|
|
|
|
static QRegExp boundaryRegexNotQuoted("boundary=([\\w'()+,-\\./:=\\?]+)"); |
|
|
|
|
QByteArray boundary; |
|
|
|
|
if (boundaryRegexQuoted.indexIn(m_header.toString()) < 0) { |
|
|
|
|
if (boundaryRegexNotQuoted.indexIn(m_header.toString()) < 0) { |
|
|
|
|
qWarning() << "Could not find boundary in multipart/form-data header!"; |
|
|
|
|
m_error = true; |
|
|
|
|
return; |
|
|
|
|
} else { |
|
|
|
|
boundary = "--" + boundaryRegexNotQuoted.cap(1).toAscii(); |
|
|
|
|
} |
|
|
|
|
qDebug() << Q_FUNC_INFO << "m_torrentContent.size(): " << m_torrentContent.size()<< "\n\n"; |
|
|
|
|
} else { |
|
|
|
|
m_error = true; |
|
|
|
|
boundary = "--" + boundaryRegexQuoted.cap(1).toAscii(); |
|
|
|
|
} |
|
|
|
|
qDebug() << "Boundary is " << boundary; |
|
|
|
|
QList<QByteArray> parts = splitRawData(m_data, boundary); |
|
|
|
|
qDebug() << parts.size() << "parts in data"; |
|
|
|
|
foreach (const QByteArray& part, parts) { |
|
|
|
|
const int filenameIndex = part.indexOf("filename="); |
|
|
|
|
if (filenameIndex < 0) |
|
|
|
|
continue; |
|
|
|
|
qDebug() << "Found a torrent"; |
|
|
|
|
m_torrents << part.mid(part.indexOf("\r\n\r\n", filenameIndex + 9) + 4); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|