Use single url setting instead for subsonic, check http code
This commit is contained in:
@@ -72,12 +72,7 @@ QUrl SubsonicBaseRequest::CreateUrl(const QString &ressource_name, const QList<P
|
||||
url_query.addQueryItem(encoded_param.first, encoded_param.second);
|
||||
}
|
||||
|
||||
QUrl url;
|
||||
if (scheme().isEmpty()) url.setScheme("https");
|
||||
else url.setScheme(scheme());
|
||||
url.setHost(hostname());
|
||||
if (port() > 0 && port() != 443)
|
||||
url.setPort(port());
|
||||
QUrl url(server_url());
|
||||
url.setPath(QString("/rest/") + ressource_name);
|
||||
url.setQuery(url_query);
|
||||
|
||||
@@ -90,7 +85,7 @@ QNetworkReply *SubsonicBaseRequest::CreateGetRequest(const QString &ressource_na
|
||||
QUrl url = CreateUrl(ressource_name, params_provided);
|
||||
QNetworkRequest req(url);
|
||||
|
||||
if (!verify_certificate()) {
|
||||
if (url.scheme() == "https" && !verify_certificate()) {
|
||||
QSslConfiguration sslconfig = QSslConfiguration::defaultConfiguration();
|
||||
sslconfig.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||
req.setSslConfiguration(sslconfig);
|
||||
@@ -117,7 +112,13 @@ QByteArray SubsonicBaseRequest::GetReplyData(QNetworkReply *reply, QString &erro
|
||||
QByteArray data;
|
||||
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
data = reply->readAll();
|
||||
int http_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if (http_code == 200) {
|
||||
data = reply->readAll();
|
||||
}
|
||||
else {
|
||||
error = Error(QString("Received HTTP code %1").arg(http_code));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (reply->error() < 200) {
|
||||
@@ -149,7 +150,6 @@ QByteArray SubsonicBaseRequest::GetReplyData(QNetworkReply *reply, QString &erro
|
||||
}
|
||||
error = Error(failure_reason);
|
||||
}
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
@@ -68,9 +68,7 @@ class SubsonicBaseRequest : public QObject {
|
||||
|
||||
QString client_name() { return service_->client_name(); }
|
||||
QString api_version() { return service_->api_version(); }
|
||||
QString scheme() { return service_->scheme(); }
|
||||
QString hostname() { return service_->hostname(); }
|
||||
int port() { return service_->port(); }
|
||||
QUrl server_url() { return service_->server_url(); }
|
||||
QString username() { return service_->username(); }
|
||||
QString password() { return service_->password(); }
|
||||
bool verify_certificate() { return service_->verify_certificate(); }
|
||||
|
||||
@@ -105,9 +105,7 @@ void SubsonicService::ReloadSettings() {
|
||||
QSettings s;
|
||||
s.beginGroup(SubsonicSettingsPage::kSettingsGroup);
|
||||
|
||||
scheme_ = s.value("scheme", "https").toString();
|
||||
hostname_ = s.value("hostname").toString();
|
||||
port_ = s.value("port", 443).toInt();
|
||||
server_url_ = s.value("url").toUrl();
|
||||
username_ = s.value("username").toString();
|
||||
QByteArray password = s.value("password").toByteArray();
|
||||
if (password.isEmpty()) password_.clear();
|
||||
@@ -125,10 +123,10 @@ QString SubsonicService::CoverCacheDir() {
|
||||
}
|
||||
|
||||
void SubsonicService::SendPing() {
|
||||
SendPing(hostname_, port_, username_, password_);
|
||||
SendPing(server_url_, username_, password_);
|
||||
}
|
||||
|
||||
void SubsonicService::SendPing(const QString &hostname, const int port, const QString &username, const QString &password) {
|
||||
void SubsonicService::SendPing(QUrl url, const QString &username, const QString &password) {
|
||||
|
||||
const ParamList params = ParamList() << Param("c", kClientName)
|
||||
<< Param("v", kApiVersion)
|
||||
@@ -142,17 +140,12 @@ void SubsonicService::SendPing(const QString &hostname, const int port, const QS
|
||||
url_query.addQueryItem(encoded_param.first, encoded_param.second);
|
||||
}
|
||||
|
||||
QUrl url;
|
||||
if (scheme_.isEmpty()) url.setScheme("https");
|
||||
else url.setScheme(scheme_);
|
||||
url.setHost(hostname);
|
||||
url.setPort(port);
|
||||
url.setPath("/rest/ping.view");
|
||||
url.setQuery(url_query);
|
||||
|
||||
QNetworkRequest req(url);
|
||||
|
||||
if (!verify_certificate_) {
|
||||
if (url.scheme() == "https" && !verify_certificate_) {
|
||||
QSslConfiguration sslconfig = QSslConfiguration::defaultConfiguration();
|
||||
sslconfig.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||
req.setSslConfiguration(sslconfig);
|
||||
@@ -205,6 +198,12 @@ void SubsonicService::HandlePingReply(QNetworkReply *reply) {
|
||||
}
|
||||
}
|
||||
|
||||
int http_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if (http_code != 200) {
|
||||
PingError(QString("Received HTTP code %1").arg(http_code));
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray data(reply->readAll());
|
||||
|
||||
QJsonParseError json_error;
|
||||
@@ -288,8 +287,8 @@ void SubsonicService::HandlePingReply(QNetworkReply *reply) {
|
||||
|
||||
void SubsonicService::CheckConfiguration() {
|
||||
|
||||
if (hostname_.isEmpty()) {
|
||||
emit TestComplete(false, "Missing Subsonic hostname.");
|
||||
if (server_url_.isEmpty()) {
|
||||
emit TestComplete(false, "Missing Subsonic server url.");
|
||||
return;
|
||||
}
|
||||
if (username_.isEmpty()) {
|
||||
|
||||
@@ -63,9 +63,7 @@ class SubsonicService : public InternetService {
|
||||
|
||||
QString client_name() { return kClientName; }
|
||||
QString api_version() { return kApiVersion; }
|
||||
QString scheme() { return scheme_; }
|
||||
QString hostname() { return hostname_; }
|
||||
int port() { return port_; }
|
||||
QUrl server_url() { return server_url_; }
|
||||
QString username() { return username_; }
|
||||
QString password() { return password_; }
|
||||
bool verify_certificate() { return verify_certificate_; }
|
||||
@@ -86,7 +84,7 @@ class SubsonicService : public InternetService {
|
||||
public slots:
|
||||
void ShowConfig();
|
||||
void SendPing();
|
||||
void SendPing(const QString &hostname, const int port, const QString &username, const QString &password);
|
||||
void SendPing(QUrl url, const QString &username, const QString &password);
|
||||
void GetSongs();
|
||||
void ResetSongsRequest();
|
||||
|
||||
@@ -119,9 +117,7 @@ class SubsonicService : public InternetService {
|
||||
|
||||
std::shared_ptr<SubsonicRequest> songs_request_;
|
||||
|
||||
QString scheme_;
|
||||
QString hostname_;
|
||||
int port_;
|
||||
QUrl server_url_;
|
||||
QString username_;
|
||||
QString password_;
|
||||
bool verify_certificate_;
|
||||
|
||||
@@ -44,12 +44,7 @@ UrlHandler::LoadResult SubsonicUrlHandler::StartLoading(const QUrl &url) {
|
||||
url_query.addQueryItem(encoded_param.first, encoded_param.second);
|
||||
}
|
||||
|
||||
QUrl media_url;
|
||||
if (server_scheme().isEmpty()) media_url.setScheme("https");
|
||||
else media_url.setScheme(server_scheme());
|
||||
media_url.setHost(service_->hostname());
|
||||
if (service_->port() > 0 && service_->port() != 443)
|
||||
media_url.setPort(service_->port());
|
||||
QUrl media_url(server_url());
|
||||
media_url.setPath("/rest/stream");
|
||||
media_url.setQuery(url_query);
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class SubsonicUrlHandler : public UrlHandler {
|
||||
SubsonicUrlHandler(Application *app, SubsonicService *service);
|
||||
|
||||
QString scheme() const { return service_->url_scheme(); }
|
||||
QString server_scheme() const { return service_->scheme(); }
|
||||
QUrl server_url() const { return service_->server_url(); }
|
||||
LoadResult StartLoading(const QUrl &url);
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user