|
21 | 21 |
|
22 | 22 | #include "xmpp_client.h"
|
23 | 23 | #include "xmpp_serverinfomanager.h"
|
24 |
| -#include "xmpp_tasks.h" |
25 | 24 | #include "xmpp_xmlcommon.h"
|
26 | 25 |
|
27 | 26 | #include <QList>
|
28 | 27 | #include <QNetworkAccessManager>
|
29 | 28 | #include <QNetworkReply>
|
30 | 29 | #include <QNetworkRequest>
|
| 30 | +#include <QPointer> |
31 | 31 |
|
32 | 32 | using namespace XMPP;
|
33 | 33 |
|
@@ -99,70 +99,69 @@ void HttpFileUpload::start()
|
99 | 99 | if (featureOptions.isEmpty()) {
|
100 | 100 | featureOptions << (QSet<QString>() << xmlns_v0_2_5) << (QSet<QString>() << xmlns_v0_3_1);
|
101 | 101 | }
|
102 |
| - d->client->serverInfoManager()->queryServiceInfo( |
| 102 | + auto query = d->client->serverInfoManager()->queryServiceInfo( |
103 | 103 | QLatin1String("store"), QLatin1String("file"), featureOptions,
|
104 |
| - QRegularExpression("^(upload|http|stor|file|dis|drive).*"), ServerInfoManager::SQ_CheckAllOnNoMatch, |
105 |
| - [this](const QList<DiscoItem> &items) { |
106 |
| - d->httpHosts.clear(); |
107 |
| - for (const auto &item : items) { |
108 |
| - const QStringList &l = item.features().list(); |
109 |
| - XEP0363::version ver = XEP0363::vUnknown; |
110 |
| - QString xmlns; |
111 |
| - quint64 sizeLimit = 0; |
112 |
| - if (l.contains(xmlns_v0_3_1)) { |
113 |
| - ver = XEP0363::v0_3_1; |
114 |
| - xmlns = xmlns_v0_3_1; |
115 |
| - } else if (l.contains(xmlns_v0_2_5)) { |
116 |
| - ver = XEP0363::v0_2_5; |
117 |
| - xmlns = xmlns_v0_2_5; |
| 104 | + QRegularExpression("^(upload|http|stor|file|dis|drive).*"), ServiceInfoQuery::CheckAllOnNoMatch); |
| 105 | + connect(query, &ServiceInfoQuery::finished, this, [this](const QList<DiscoItem> &items) { |
| 106 | + d->httpHosts.clear(); |
| 107 | + for (const auto &item : items) { |
| 108 | + const QStringList &l = item.features().list(); |
| 109 | + XEP0363::version ver = XEP0363::vUnknown; |
| 110 | + QString xmlns; |
| 111 | + quint64 sizeLimit = 0; |
| 112 | + if (l.contains(xmlns_v0_3_1)) { |
| 113 | + ver = XEP0363::v0_3_1; |
| 114 | + xmlns = xmlns_v0_3_1; |
| 115 | + } else if (l.contains(xmlns_v0_2_5)) { |
| 116 | + ver = XEP0363::v0_2_5; |
| 117 | + xmlns = xmlns_v0_2_5; |
| 118 | + } |
| 119 | + if (ver != XEP0363::vUnknown) { |
| 120 | + QVector<std::pair<HttpHost, int>> hosts; |
| 121 | + const XData::Field field = item.registeredExtension(xmlns).getField(QLatin1String("max-file-size")); |
| 122 | + if (field.isValid() && field.type() == XData::Field::Field_TextSingle) |
| 123 | + sizeLimit = field.value().at(0).toULongLong(); |
| 124 | + HttpHost host; |
| 125 | + host.ver = ver; |
| 126 | + host.jid = item.jid(); |
| 127 | + host.sizeLimit = sizeLimit; |
| 128 | + QVariant metaProps(d->client->serverInfoManager()->serviceMeta(host.jid, "httpprops")); |
| 129 | + if (metaProps.isValid()) { |
| 130 | + host.props = HostProps(metaProps.value<int>()); |
| 131 | + } else { |
| 132 | + host.props = SecureGet | SecurePut; |
| 133 | + if (ver == XEP0363::v0_3_1) |
| 134 | + host.props |= NewestVer; |
118 | 135 | }
|
119 |
| - if (ver != XEP0363::vUnknown) { |
120 |
| - QVector<std::pair<HttpHost, int>> hosts; |
121 |
| - const XData::Field field = item.registeredExtension(xmlns).getField(QLatin1String("max-file-size")); |
122 |
| - if (field.isValid() && field.type() == XData::Field::Field_TextSingle) |
123 |
| - sizeLimit = field.value().at(0).toULongLong(); |
124 |
| - HttpHost host; |
125 |
| - host.ver = ver; |
126 |
| - host.jid = item.jid(); |
127 |
| - host.sizeLimit = sizeLimit; |
128 |
| - QVariant metaProps(d->client->serverInfoManager()->serviceMeta(host.jid, "httpprops")); |
129 |
| - if (metaProps.isValid()) { |
130 |
| - host.props = HostProps(metaProps.value<int>()); |
131 |
| - } else { |
132 |
| - host.props = SecureGet | SecurePut; |
133 |
| - if (ver == XEP0363::v0_3_1) |
134 |
| - host.props |= NewestVer; |
135 |
| - } |
136 |
| - int value = 0; |
137 |
| - if (host.props & SecureGet) |
138 |
| - value += 5; |
139 |
| - if (host.props & SecurePut) |
140 |
| - value += 5; |
141 |
| - if (host.props & NewestVer) |
142 |
| - value += 3; |
143 |
| - if (host.props & Failure) |
144 |
| - value -= 15; |
145 |
| - if (!sizeLimit || d->fileSize < sizeLimit) |
146 |
| - hosts.append({ host, value }); |
147 |
| - |
148 |
| - // no sorting in preference order. most preferred go first |
149 |
| - std::sort(hosts.begin(), hosts.end(), |
150 |
| - [](const auto &a, const auto &b) { return a.second > b.second; }); |
151 |
| - for (auto &hp : hosts) { |
152 |
| - d->httpHosts.append(hp.first); |
153 |
| - } |
| 136 | + int value = 0; |
| 137 | + if (host.props & SecureGet) |
| 138 | + value += 5; |
| 139 | + if (host.props & SecurePut) |
| 140 | + value += 5; |
| 141 | + if (host.props & NewestVer) |
| 142 | + value += 3; |
| 143 | + if (host.props & Failure) |
| 144 | + value -= 15; |
| 145 | + if (!sizeLimit || d->fileSize < sizeLimit) |
| 146 | + hosts.append({ host, value }); |
| 147 | + |
| 148 | + // no sorting in preference order. most preferred go first |
| 149 | + std::sort(hosts.begin(), hosts.end(), [](const auto &a, const auto &b) { return a.second > b.second; }); |
| 150 | + for (auto &hp : hosts) { |
| 151 | + d->httpHosts.append(hp.first); |
154 | 152 | }
|
155 | 153 | }
|
156 |
| - // d->currentHost = d->httpHosts.begin(); |
157 |
| - d->client->httpFileUploadManager()->setDiscoHosts(d->httpHosts); |
158 |
| - if (d->httpHosts.isEmpty()) { // if empty as the last resort check all services |
159 |
| - d->result.statusCode = HttpFileUpload::ErrorCode::NoUploadService; |
160 |
| - d->result.statusString = "No suitable http upload services were found"; |
161 |
| - done(State::Error); |
162 |
| - } else { |
163 |
| - tryNextServer(); |
164 |
| - } |
165 |
| - }); |
| 154 | + } |
| 155 | + // d->currentHost = d->httpHosts.begin(); |
| 156 | + d->client->httpFileUploadManager()->setDiscoHosts(d->httpHosts); |
| 157 | + if (d->httpHosts.isEmpty()) { // if empty as the last resort check all services |
| 158 | + d->result.statusCode = HttpFileUpload::ErrorCode::NoUploadService; |
| 159 | + d->result.statusString = "No suitable http upload services were found"; |
| 160 | + done(State::Error); |
| 161 | + } else { |
| 162 | + tryNextServer(); |
| 163 | + } |
| 164 | + }); |
166 | 165 | }
|
167 | 166 |
|
168 | 167 | void HttpFileUpload::tryNextServer()
|
|
0 commit comments