Warning: That file was not part of the compilation database. It may have many parsing errors.

1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "tools.h"
43
44#include <QDir>
45#include <QFile>
46#include <QByteArray>
47
48
49// std stuff ------------------------------------
50#include <iostream>
51#include <windows.h>
52#include <conio.h>
53#define NUMBER_OF_PARTS 7
54
55std::ostream &operator<<(std::ostream &s, const QString &val); // defined in configureapp.cpp
56using namespace std;
57
58void Tools::checkLicense(QMap<QString,QString> &dictionary, QMap<QString,QString> &licenseInfo,
59 const QString &path)
60{
61 if (dictionary[ "BUILDNOKIA" ] == "yes") {
62 dictionary["EDITION"] = "DigiaInternalBuild";
63 dictionary["LICENSE_FILE"] = ""; // No License for nokia developers
64 dictionary["QT_EDITION"] = "QT_EDITION_OPENSOURCE";
65 return; // No license key checking in internal builds
66 }
67
68 QString tpLicense = dictionary["QT_SOURCE_TREE"] + "/LICENSE.PREVIEW.OPENSOURCE";
69 if (QFile::exists(tpLicense)) {
70 dictionary["EDITION"] = "Preview";
71 dictionary["LICENSE FILE"] = tpLicense;
72 dictionary["QT_EDITION"] = "QT_EDITION_OPENSOURCE";
73 return; // No license key checking in Tech Preview
74 }
75 tpLicense = dictionary["QT_SOURCE_TREE"] + "/LICENSE.PREVIEW.COMMERCIAL";
76 if (QFile::exists(tpLicense)) {
77 dictionary["EDITION"] = "Preview";
78 dictionary["LICENSE FILE"] = tpLicense;
79 dictionary["QT_EDITION"] = "QT_EDITION_DESKTOP";
80 return; // No license key checking in Tech Preview
81 }
82
83 // Read in the license file
84 QFile licenseFile(path);
85 if( !path.isEmpty() && licenseFile.open( QFile::ReadOnly ) ) {
86 cout << "Reading license file in....." << qPrintable(path) << endl;
87
88 QString buffer = licenseFile.readLine(1024);
89 while (!buffer.isEmpty()) {
90 if( buffer[ 0 ] != '#' ) {
91 QStringList components = buffer.split( '=' );
92 if ( components.size() >= 2 ) {
93 QStringList::Iterator it = components.begin();
94 QString key = (*it++).trimmed().remove('"').toUpper();
95 QString value = (*it++).trimmed().remove('"');
96 licenseInfo[ key ] = value;
97 }
98 }
99 // read next line
100 buffer = licenseFile.readLine(1024);
101 }
102 licenseFile.close();
103 } else {
104 cout << "License file not found in " << QDir::homePath() << endl;
105 cout << "Please put the Qt license file, '.qt-license' in your home "
106 << "directory and run configure again.";
107 dictionary["DONE"] = "error";
108 return;
109 }
110
111 // Verify license info...
112 QString licenseKey = licenseInfo["LICENSEKEYEXT"];
113 QByteArray clicenseKey = licenseKey.toLatin1();
114 //We check the license
115 static const char * const SEP = "-";
116 char *licenseParts[NUMBER_OF_PARTS];
117 int partNumber = 0;
118 for (char *part = strtok(clicenseKey.data(), SEP); part != 0; part = strtok(0, SEP))
119 licenseParts[partNumber++] = part;
120 if (partNumber < (NUMBER_OF_PARTS-1)) {
121 dictionary["DONE"] = "error";
122 cout << "License file does not contain proper license key." <<partNumber<< endl;
123 return;
124 }
125
126 char products = licenseParts[0][0];
127 char* platforms = licenseParts[1];
128 char* licenseSchema = licenseParts[2];
129 char licenseFeatures = licenseParts[3][0];
130
131 // Determine edition ---------------------------------------------------------------------------
132 QString licenseType;
133 if (strcmp(licenseSchema,"F4M") == 0) {
134 licenseType = "Commercial";
135 if (products == 'F') {
136 dictionary["EDITION"] = "Universal";
137 dictionary["QT_EDITION"] = "QT_EDITION_UNIVERSAL";
138 } else if (products == 'B') {
139 dictionary["EDITION"] = "FullFramework";
140 dictionary["QT_EDITION"] = "QT_EDITION_DESKTOP";
141 } else {
142 dictionary["EDITION"] = "GUIFramework";
143 dictionary["QT_EDITION"] = "QT_EDITION_DESKTOPLIGHT";
144 }
145 } else if (strcmp(licenseSchema,"Z4M") == 0 || strcmp(licenseSchema,"R4M") == 0 || strcmp(licenseSchema,"Q4M") == 0) {
146 if (products == 'B') {
147 dictionary["EDITION"] = "Evaluation";
148 dictionary["QT_EDITION"] = "QT_EDITION_EVALUATION";
149 licenseType = "Evaluation";
150 }
151 }
152
153 if (platforms[2] == 'L') {
154 static const char src[] = "8NPQRTZ";
155 static const char dst[] = "UCWX9M7";
156 const char *p = strchr(src, platforms[1]);
157 platforms[1] = dst[p - src];
158 }
159
160#define PL(a,b) (int(a)+int(b)*256)
161 int platformCode = PL(platforms[0],platforms[1]);
162 switch (platformCode) {
163 case PL('X','9'):
164 case PL('X','C'):
165 case PL('X','U'):
166 case PL('X','W'):
167 case PL('X','M'): // old license key
168 dictionary["LICENSE_EXTENSION"] = "-ALLOS";
169 break;
170
171 case PL('6', 'M'):
172 case PL('8', 'M'):
173 case PL('K', 'M'): // old license key
174 case PL('N', '7'):
175 case PL('N', '9'):
176 case PL('N', 'X'):
177 case PL('S', '9'):
178 case PL('S', 'C'):
179 case PL('S', 'U'):
180 case PL('S', 'W'):
181 dictionary["LICENSE_EXTENSION"] = "-EMBEDDED";
182 if (dictionary["PLATFORM NAME"].contains("Windows CE")
183 && platformCode != PL('6', 'M') && platformCode != PL('S', '9')
184 && platformCode != PL('S', 'C') && platformCode != PL('S', 'U')
185 && platformCode != PL('S', 'W') && platformCode != PL('K', 'M')) {
186 dictionary["DONE"] = "error";
187 } else if (dictionary["PLATFORM NAME"].contains("Symbian")
188 && platformCode != PL('N', '9') && platformCode != PL('S', '9')
189 && platformCode != PL('S', 'C') && platformCode != PL('S', 'U')
190 && platformCode != PL('S', 'W')) {
191 dictionary["DONE"] = "error";
192 }
193 break;
194 case PL('R', 'M'):
195 case PL('F', 'M'):
196 dictionary["LICENSE_EXTENSION"] = "-DESKTOP";
197 if (!dictionary["PLATFORM NAME"].endsWith("Windows")) {
198 dictionary["DONE"] = "error";
199 }
200 break;
201 default:
202 dictionary["DONE"] = "error";
203 break;
204 }
205#undef PL
206
207 if (dictionary.value("DONE") == "error") {
208 cout << "You are not licensed for the " << dictionary["PLATFORM NAME"] << " platform." << endl << endl;
209 cout << "Please contact http://qt.digia.com/contact-us to upgrade your license" << endl;
210 cout << "to include the " << dictionary["PLATFORM NAME"] << " platform." << endl;
211 return;
212 }
213
214 // Override for evaluation licenses
215 if (dictionary["EDITION"] == "Evaluation")
216 dictionary["LICENSE_EXTENSION"] = "-EVALUATION";
217
218 if (QFile::exists(dictionary["QT_SOURCE_TREE"] + "/.LICENSE")) {
219 // Generic, no-suffix license
220 dictionary["LICENSE_EXTENSION"].clear();
221 } else if (dictionary["LICENSE_EXTENSION"].isEmpty()) {
222 cout << "License file does not contain proper license key." << endl;
223 dictionary["DONE"] = "error";
224 }
225 if (licenseType.isEmpty()
226 || dictionary["EDITION"].isEmpty()
227 || dictionary["QT_EDITION"].isEmpty()) {
228 cout << "License file does not contain proper license key." << endl;
229 dictionary["DONE"] = "error";
230 return;
231 }
232
233 // copy one of .LICENSE-*(-US) to LICENSE
234 QString toLicenseFile = dictionary["QT_SOURCE_TREE"] + "/LICENSE";
235 QString fromLicenseFile = dictionary["QT_SOURCE_TREE"] + "/.LICENSE" + dictionary["LICENSE_EXTENSION"];
236 if (licenseFeatures == 'B' || licenseFeatures == 'G'
237 || licenseFeatures == 'L' || licenseFeatures == 'Y')
238 fromLicenseFile += "-US";
239
240 if (!CopyFile((wchar_t*)QDir::toNativeSeparators(fromLicenseFile).utf16(),
241 (wchar_t*)QDir::toNativeSeparators(toLicenseFile).utf16(), false)) {
242 cout << "Failed to copy license file (" << fromLicenseFile << ")";
243 dictionary["DONE"] = "error";
244 return;
245 }
246 dictionary["LICENSE FILE"] = toLicenseFile;
247}
248
249

Warning: That file was not part of the compilation database. It may have many parsing errors.