Debian Codegraph @

src/search/scanner.cpp

raw symbols SCIP
1 // Copyright (C) 2014 Sacha Refshauge
2
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 3.0.
6
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 3.0 for more details.
11
12 // A copy of the GPL 3.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
14
15 // Official GIT repository and contact information can be found at
16 // http://github.com/xsacha/Sachesi
17
18 #include <QXmlStreamReader>
19 #include "scanner.h"
20 #include "../ports.h"
21
22 void Scanner::clearHistory() {
23 foreach(DiscoveredRelease* rel, _history) {
24 rel->deleteLater();
25 }
26 _history.clear();
27 emit historyChanged();
28 }
29
30 void Scanner::exportHistory() {
31 QString historyText;
32 foreach(DiscoveredRelease* rel, _history) {
33 historyText.append(tr("SR: ") + " " + rel->srVersion() + " | " + tr("OS: ") + rel->osVersion() + " [");
34 if (rel->activeServers() & 1)
35 historyText.append(tr("Production") + ", ");
36 if (rel->activeServers() & 2)
37 historyText.append(tr("Beta") + ", ");
38 if (rel->activeServers() & 4)
39 historyText.append(tr("Alpha") + ", ");
40 historyText.chop(2);
41 historyText.append("]\n");
42 }
43
44 writeDisplayFile(tr("History"), historyText);
45 }
46
47 void Scanner::reverseLookup(QString OSver) {
48 // If we only want real links, we're only going to want the server we can download from
49 _isActive = true; emit isActiveChanged();
50 _curRelease = new DiscoveredRelease();
51 _curRelease->setOsVersion(OSver);
52 emit curReleaseChanged();
53 QString query = QString("<srVersionLookupRequest version=\"2.0.0\" authEchoTS=\"%1\">"
54 "<clientProperties>"
55 "<hardware><pin>0x2FFFFFB3</pin><bsn>1140011878</bsn><id>0x85002c0a</id></hardware>"
56 "<software><osVersion>%2</osVersion></software>"
57 "</clientProperties>"
58 "</srVersionLookupRequest>")
59 .arg(QDateTime::currentMSecsSinceEpoch())
60 .arg(OSver);
61 QNetworkRequest request;
62 request.setRawHeader("Content-Type", "text/xml;charset=UTF-8");
63 QStringList serverList = QStringList("cs.sl");
64 if (_findExisting != 1) {
65 serverList << "beta2.sl.eval" << "alpha.sl.eval";
66 }
67 _scansActive = serverList.count();
68 foreach(QString server, serverList) {
69 request.setUrl(QUrl(QString("https://%1.blackberry.com/%2cse/srVersionLookup/2.0/").arg(server).arg(server == "cs.sl" ? "" : "sls")));
70 QNetworkReply* reply = _manager->post(request, query.toUtf8());
71 connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
72 this, SLOT(serverError(QNetworkReply::NetworkError)));
73 connect(reply, SIGNAL(finished()), this, SLOT(newSRVersion()));
74 }
75 }
76
77 void Scanner::newSRVersion() {
78 QNetworkReply* reply = (QNetworkReply*)sender();
79 QString swRelease;
80 QByteArray data = reply->readAll();
81 //for (int i = 0; i < data.size(); i += 3000) qDebug() << data.mid(i, 3000);
82 QXmlStreamReader xml(data);
83 while(!xml.atEnd() && !xml.hasError()) {
84 if(xml.tokenType() == QXmlStreamReader::StartElement) {
85 if (xml.name() == "softwareReleaseVersion") {
86 swRelease = xml.readElementText();
87 }
88 }
89 xml.readNext();
90 }
91
92 // Software release has a version
93 if (swRelease.startsWith('1')) {
94 QString replyHost = reply->url().host();
95 if (replyHost.startsWith("cs")) {
96 _curRelease->setActiveServers(1);
97 } else if (replyHost.startsWith("beta")) {
98 _curRelease->setActiveServers(2);
99 } else if (replyHost.startsWith("alpha")) {
100 _curRelease->setActiveServers(4);
101 }
102 // Software release is new so we should check if it has a release
103 if (swRelease != _curRelease->srVersion()) {
104 _curRelease->setSrVersion(swRelease);
105 // Don't care about Links?
106 if (_findExisting == 2) {
107 completeScan();
108 } else {
109 QCryptographicHash hash(QCryptographicHash::Sha1);
110 hash.addData(swRelease.toLatin1());
111 QString url = "http://cdn.fs.sl.blackberry.com/fs/qnx/production/" + QString(hash.result().toHex());
112 QNetworkRequest request;
113 request.setRawHeader("Content-Type", "text/xml;charset=UTF-8");
114 request.setUrl(QUrl(url));
115 QNetworkReply* replyTmp = _manager->head(request);
116 connect(replyTmp, SIGNAL(finished()), this, SLOT(validateDownload()));
117 }
118 reply->deleteLater();
119 return;
120 }
121 }
122 completeScan();
123 reply->deleteLater();
124 }
125
126 void Scanner::validateDownload()
127 {
128 QNetworkReply* reply = (QNetworkReply*)sender();
129 uint status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toUInt();
130 // Seems to give 301 redirect if it's real
131 if (status == 200 || (status > 300 && status <= 308)) {
132 _curRelease->setBaseUrl(reply->url().toString());
133 }
134 emit softwareReleaseChanged();
135 completeScan();
136 reply->deleteLater();
137 }
138
139 void appendNewHeader(QString *potentialText, QString name, QString devices) {
140 potentialText->append("\n" + name + ": " + devices + " (Debrick + Core OS)\n");
141 }
142
143 void Scanner::appendNewLink(QString *potentialText, QString linkType, QString hwType, QString version) {
144 bool os = (linkType == "Core" || linkType == "Debrick");
145 if (!os) {
146 potentialText->append(linkType + " Radio\n");
147 }
148 potentialText->append(_curRelease->baseUrl() + "/" + hwType + "-" + version + "-nto+armle-v7+signed.bar\n");
149 }
150
151
152 void Scanner::generatePotentialLinks() {
153 QStringList parts = _curRelease->osVersion().split('.');
154 // Just a guess that the Radio is +1. In some builds this isn't true.
155 int build = parts.last().toInt() + 1;
156 QString radioVersion = "";
157 for (int i = 0; i < 3; i++)
158 radioVersion += parts.at(i) + ".";
159 radioVersion += QString::number(build);
160
161 QString potentialText = QString("Potential OS and Radio links for SR " + _curRelease->srVersion() + " (OS " + _curRelease->osVersion() + " + Radio " + radioVersion + ")\n\n"
162 "* Operating Systems *\n");
163 appendNewHeader(&potentialText, "QC8974", "Blackberry Passport");
164 appendNewLink(&potentialText, "Debrick", "qc8960.factory_sfi_hybrid_qc8974.desktop", _curRelease->osVersion());
165 appendNewLink(&potentialText, "Core", "qc8960.factory_sfi_hybrid_qc8974", _curRelease->osVersion());
166
167 appendNewHeader(&potentialText, "QC8960", "Blackberry Z10/Z30/Q5/Q10");
168 appendNewLink(&potentialText, "Debrick", "qc8960.factory_sfi.desktop", _curRelease->osVersion());
169 appendNewLink(&potentialText, "Core", "qc8960.factory_sfi", _curRelease->osVersion());
170
171 appendNewHeader(&potentialText, "QC8x30", "Blackberry Z3");
172 appendNewLink(&potentialText, "Debrick", "qc8960.factory_sfi_hybrid_qc8x30.desktop", _curRelease->osVersion());
173 appendNewLink(&potentialText, "Core", "qc8960.factory_sfi_hybrid_qc8x30", _curRelease->osVersion());
174
175 appendNewHeader(&potentialText, "OMAP", "Blackberry Z10 STL 100-1");
176 appendNewLink(&potentialText, "Debrick", "winchester.factory_sfi.desktop", _curRelease->osVersion());
177 appendNewLink(&potentialText, "Core", "winchester.factory_sfi", _curRelease->osVersion());
178
179 potentialText.append("\n\n* Radios *\n");
180 // Touch
181 appendNewLink(&potentialText, "Z30 + Classic + Leap", "qc8960.wtr5", radioVersion);
182 appendNewLink(&potentialText, "Z10 (STL 100-1)", "m5730", radioVersion);
183 appendNewLink(&potentialText, "Z10 (STL 100-2/3/4) + P9982", "qc8960", radioVersion);
184 appendNewLink(&potentialText, "Z3", "qc8930.wtr5", radioVersion);
185 // QWERTY
186 appendNewLink(&potentialText, "Passport + Ontario", "qc8974.wtr2", radioVersion);
187 appendNewLink(&potentialText, "Q5 + Q10 + P9983", "qc8960.wtr", radioVersion);
188 writeDisplayFile(tr("VersionLookup"), potentialText);
189 }
190
191 void Scanner::serverError(QNetworkReply::NetworkError err) {
192 Q_UNUSED(err);
193 completeScan();
194 sender()->deleteLater();
195 }
196