Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change MythDownloadManager to allow for multiple headers

Seems we should be setting the Content-Type header for schedulesdirect calls,
and QT 4.8 might be putting in the wrong thing as a default if we don't
specify.  This makes it so we can send a hash of headers rather than just one
key/value pair.
  • Loading branch information...
commit 1850a253930da4b65d20588e534c3631079bf454 1 parent bdfcabc
@Beirdo Beirdo authored
View
43 mythtv/libs/libmythbase/mythdownloadmanager.cpp
@@ -49,8 +49,7 @@ class MythDownloadInfo
m_processReply(true), m_done(false), m_bytesReceived(0),
m_bytesTotal(0), m_lastStat(MythDate::current()),
m_authCallback(NULL), m_authArg(NULL),
- m_header(NULL), m_headerVal(NULL),
- m_errorCode(QNetworkReply::NoError)
+ m_headers(NULL), m_errorCode(QNetworkReply::NoError)
{
qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError");
}
@@ -88,8 +87,7 @@ class MythDownloadInfo
QDateTime m_lastStat;
AuthCallback m_authCallback;
void *m_authArg;
- const QByteArray *m_header;
- const QByteArray *m_headerVal;
+ const QHash<QByteArray, QByteArray> *m_headers;
QNetworkReply::NetworkError m_errorCode;
};
@@ -365,16 +363,14 @@ void MythDownloadManager::queueItem(const QString &url, QNetworkRequest *req,
* \param reload Force reloading of the URL
* \param authCallback AuthCallback function for authentication
* \param authArg Opaque argument for callback function
- * \param header Optional HTTP header to add to the request
- * \param headerVal Value for the optional HTTP header to add to the request
+ * \param headers Hash of optional HTTP header to add to the request
*/
bool MythDownloadManager::processItem(const QString &url, QNetworkRequest *req,
const QString &dest, QByteArray *data,
const MRequestType reqType,
const bool reload,
AuthCallback authCallback, void *authArg,
- const QByteArray *header,
- const QByteArray *headerVal)
+ const QHash<QByteArray, QByteArray> *headers)
{
MythDownloadInfo *dlInfo = new MythDownloadInfo;
@@ -387,8 +383,7 @@ bool MythDownloadManager::processItem(const QString &url, QNetworkRequest *req,
dlInfo->m_syncMode = true;
dlInfo->m_authCallback = authCallback;
dlInfo->m_authArg = authArg;
- dlInfo->m_header = header;
- dlInfo->m_headerVal = headerVal;
+ dlInfo->m_headers = headers;
return downloadNow(dlInfo);
}
@@ -509,16 +504,15 @@ bool MythDownloadManager::download(QNetworkRequest *req, QByteArray *data)
* \param reload Whether to force reloading of the URL or not
* \param authCallback AuthCallback function for use with authentication
* \param authArg Opaque argument for callback function
- * \param header Optional HTTP header to add to the request
- * \param headerVal Value for the optional HTTP header to add to the request
+ * \param headers Hash of optional HTTP header to add to the request
* \return true if download was successful, false otherwise.
*/
bool MythDownloadManager::downloadAuth(const QString &url, const QString &dest,
const bool reload, AuthCallback authCallback, void *authArg,
- const QByteArray *header, const QByteArray *headerVal)
+ const QHash<QByteArray, QByteArray> *headers)
{
return processItem(url, NULL, dest, NULL, kRequestGet, reload, authCallback,
- authArg, header, headerVal);
+ authArg, headers);
}
@@ -609,14 +603,12 @@ bool MythDownloadManager::post(QNetworkRequest *req, QByteArray *data)
* \param data Location holding post and response data
* \param authCallback AuthCallback function for authentication
* \param authArg Opaque argument for callback function
- * \param header Optional HTTP header to add to the request
- * \param headerVal Value for the optional HTTP header to add to the request
+ * \param headers Hash of optional HTTP headers to add to the request
* \return true if post was successful, false otherwise.
*/
bool MythDownloadManager::postAuth(const QString &url, QByteArray *data,
AuthCallback authCallback, void *authArg,
- const QByteArray *header,
- const QByteArray *headerVal)
+ const QHash<QByteArray, QByteArray> *headers)
{
LOG(VB_FILE, LOG_DEBUG, LOC + QString("postAuth('%1', '%2')")
.arg(url).arg((long long)data));
@@ -628,7 +620,7 @@ bool MythDownloadManager::postAuth(const QString &url, QByteArray *data,
}
return processItem(url, NULL, NULL, data, kRequestPost, false, authCallback,
- authArg, header, headerVal);
+ authArg, headers);
}
/** \brief Triggers a myth:// URI download in the background via RemoteFile
@@ -718,10 +710,17 @@ void MythDownloadManager::downloadQNetworkRequest(MythDownloadInfo *dlInfo)
request.setRawHeader("User-Agent",
"MythTV v" MYTH_BINARY_VERSION " MythDownloadManager");
- if (dlInfo->m_header && dlInfo->m_headerVal &&
- !dlInfo->m_header->isEmpty() && !dlInfo->m_headerVal->isEmpty())
+ if (dlInfo->m_headers)
{
- request.setRawHeader(*(dlInfo->m_header), *(dlInfo->m_headerVal));
+ QHash<QByteArray, QByteArray>::const_iterator it =
+ dlInfo->m_headers->constBegin();
+ for ( ; it != dlInfo->m_headers->constEnd(); ++it )
+ {
+ if (!it.key().isEmpty() && !it.value().isEmpty())
+ {
+ request.setRawHeader(it.key(), it.value());
+ }
+ }
}
switch (dlInfo->m_requestType)
View
12 mythtv/libs/libmythbase/mythdownloadmanager.h
@@ -10,6 +10,7 @@
#include <QNetworkProxy>
#include <QWaitCondition>
#include <QString>
+#include <QHash>
#include "mythbaseexp.h"
#include "mthread.h"
@@ -57,8 +58,8 @@ class MBASE_PUBLIC MythDownloadManager : public QObject, public MThread
bool downloadAuth(const QString &url, const QString &dest,
const bool reload = false,
AuthCallback authCallback = NULL,
- void *authArg = NULL, const QByteArray *header = NULL,
- const QByteArray *headerVal = NULL);
+ void *authArg = NULL,
+ const QHash<QByteArray, QByteArray> *headers = NULL);
// Methods to POST to a URL
void queuePost(const QString &url, QByteArray *data, QObject *caller);
@@ -67,8 +68,7 @@ class MBASE_PUBLIC MythDownloadManager : public QObject, public MThread
bool post(QNetworkRequest *req, QByteArray *data);
bool postAuth(const QString &url, QByteArray *data,
AuthCallback authCallback, void *authArg,
- const QByteArray *header = NULL,
- const QByteArray *headerVal = NULL);
+ const QHash<QByteArray, QByteArray> *headers = NULL);
// Cancel a download
void cancelDownload(const QString &url);
@@ -112,8 +112,8 @@ class MBASE_PUBLIC MythDownloadManager : public QObject, public MThread
const MRequestType reqType = kRequestGet,
const bool reload = false,
AuthCallback authCallback = NULL,
- void *authArg = NULL, const QByteArray *header = NULL,
- const QByteArray *headerVal = NULL);
+ void *authArg = NULL,
+ const QHash<QByteArray, QByteArray> *headers = NULL);
void downloadRemoteFile(MythDownloadInfo *dlInfo);
void downloadQNetworkRequest(MythDownloadInfo *dlInfo);
View
2  mythtv/libs/libmythbase/mythversion.h
@@ -12,7 +12,7 @@
/// Update this whenever the plug-in API changes.
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
/// libmythui class methods used by plug-ins.
-#define MYTH_BINARY_VERSION "0.26.20120724-1"
+#define MYTH_BINARY_VERSION "0.26.20120724-2"
/** \brief Increment this whenever the MythTV network protocol changes.
*
View
13 mythtv/libs/libmythtv/datadirect.cpp
@@ -1010,15 +1010,16 @@ bool DataDirectProcessor::DDPost(QString ddurl, QString &inputFile,
inputFile = QString("/tmp/mythtv_ddp_data");
}
- const QByteArray header = "Accept-Encoding";
- const QByteArray value = "gzip";
+ QHash<QByteArray, QByteArray> headers;
+ headers.insert("Accept-Encoding", "gzip");
+ headers.insert("Content-Type", "application/soap+xml; charset=utf-8");
LOG(VB_GENERAL, LOG_INFO, "Downloading DataDirect feed");
MythDownloadManager *manager = GetMythDownloadManager();
if (!manager->postAuth(ddurl, &postdata, &::authenticationCallback, this,
- &header, &value))
+ &headers))
{
err_txt = QString("Download error");
return false;
@@ -1078,9 +1079,13 @@ bool DataDirectProcessor::GrabNextSuggestedTime(void)
postdata += "</SOAP-ENV:Body>\n";
postdata += "</SOAP-ENV:Envelope>\n";
+ QHash<QByteArray, QByteArray> headers;
+ headers.insert("Content-Type", "application/soap+xml; charset=utf-8");
+
MythDownloadManager *manager = GetMythDownloadManager();
- if (!manager->postAuth(ddurl, &postdata, &::authenticationCallback, this))
+ if (!manager->postAuth(ddurl, &postdata, &::authenticationCallback, this,
+ &headers))
{
LOG(VB_GENERAL, LOG_ERR, LOC +
"GrabNextSuggestedTime: Could not download");
Please sign in to comment.
Something went wrong with that request. Please try again.