Skip to content

Commit 57dc682

Browse files
committed
code refactoring
1 parent 4028edd commit 57dc682

File tree

9 files changed

+72
-80
lines changed

9 files changed

+72
-80
lines changed

src/access-manager.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
#include "file-reader.h"
2929
#include "local-reply.h"
30-
#include "pseudo-domain.h"
3130
#include "script-handler.h"
3231

3332
// ==============================
@@ -51,7 +50,8 @@ class QAccessManager : public QNetworkAccessManager
5150
// Start page redirection:
5251
// ==============================
5352
if ((operation == GetOperation) and
54-
request.url().host() == PSEUDO_DOMAIN and
53+
request.url().host() ==
54+
qApp->property("pseudoDomain").toString() and
5555
request.url().fileName().length() == 0 and
5656
pageStatus == "trusted") {
5757
QNetworkRequest startPageRequest;
@@ -69,15 +69,16 @@ class QAccessManager : public QNetworkAccessManager
6969
// ==============================
7070
if ((operation == GetOperation or
7171
operation == PostOperation) and
72-
request.url().host() == PSEUDO_DOMAIN and
72+
request.url().host() ==
73+
qApp->property("pseudoDomain").toString() and
7374
request.url().userName() == "ajax" and
7475
pageStatus == "untrusted") {
7576

7677
QString errorMessage =
7778
"Calling local Perl scripts after "
7879
"untrusted content is loaded is prohibited.<br>"
7980
"Go to start page to unlock local Perl scripts.";
80-
qInfo() << "Local AJAX Perl script called after"
81+
qDebug() << "Local AJAX Perl script called after"
8182
<< "untrusted content is loaded:"
8283
<< request.url().toString();
8384

@@ -91,7 +92,8 @@ class QAccessManager : public QNetworkAccessManager
9192
// ==============================
9293
if ((operation == GetOperation or
9394
operation == PostOperation) and
94-
request.url().host() == PSEUDO_DOMAIN and
95+
request.url().host() ==
96+
qApp->property("pseudoDomain").toString() and
9597
request.url().userName() == "ajax" and
9698
pageStatus == "trusted") {
9799

@@ -155,7 +157,7 @@ class QAccessManager : public QNetworkAccessManager
155157
emptyString);
156158
return reply;
157159
} else {
158-
qInfo() << "File not found:" << ajaxScriptFullFilePath;
160+
qDebug() << "File not found:" << ajaxScriptFullFilePath;
159161

160162
QFileReader *resourceReader =
161163
new QFileReader(QString(":/html/error.html"));
@@ -180,7 +182,8 @@ class QAccessManager : public QNetworkAccessManager
180182
// local files and non-AJAX scripts:
181183
// ==============================
182184
if (operation == GetOperation and
183-
request.url().host() == PSEUDO_DOMAIN and
185+
request.url().host() ==
186+
qApp->property("pseudoDomain").toString() and
184187
(request.url().userName() != "ajax") and
185188
(!request.url().path().contains(".function"))) {
186189

@@ -225,7 +228,7 @@ class QAccessManager : public QNetworkAccessManager
225228
qApp->property("startPage").toString() +
226229
"'>start page</a> "
227230
"to unlock local Perl scripts.</p>";
228-
qInfo() << "Local Perl script called after"
231+
qDebug() << "Local Perl script called after"
229232
<< "untrusted content was loaded:"
230233
<< request.url().toString();
231234

@@ -261,7 +264,7 @@ class QAccessManager : public QNetworkAccessManager
261264
mimeType == "application/font-sfnt" or
262265
mimeType.contains("application/font-woff")) {
263266

264-
qInfo() << "Local link requested:"
267+
qDebug() << "Local link requested:"
265268
<< request.url().toString();
266269

267270
QFileReader *resourceReader =
@@ -273,7 +276,7 @@ class QAccessManager : public QNetworkAccessManager
273276
mimeType);
274277
return reply;
275278
} else {
276-
qInfo() << "File type not supported:" << fullFilePath;
279+
qDebug() << "File type not supported:" << fullFilePath;
277280

278281
QDesktopServices::openUrl(
279282
QUrl::fromLocalFile(fullFilePath));
@@ -284,7 +287,7 @@ class QAccessManager : public QNetworkAccessManager
284287
return reply;
285288
}
286289
} else {
287-
qInfo() << "File not found:" << fullFilePath;
290+
qDebug() << "File not found:" << fullFilePath;
288291

289292
QFileReader *resourceReader =
290293
new QFileReader(QString(":/html/error.html"));
@@ -308,7 +311,8 @@ class QAccessManager : public QNetworkAccessManager
308311
// non-AJAX scripts:
309312
// ==============================
310313
if (operation == PostOperation and
311-
request.url().host() == PSEUDO_DOMAIN and
314+
request.url().host() ==
315+
qApp->property("pseudoDomain").toString() and
312316
(request.url().userName() != "ajax")) {
313317

314318
if (outgoingData) {
@@ -336,7 +340,7 @@ class QAccessManager : public QNetworkAccessManager
336340
return reply;
337341
}
338342

339-
qInfo() << "Link requested:" << request.url().toString();
343+
qDebug() << "Link requested:" << request.url().toString();
340344

341345
return QNetworkAccessManager::createRequest
342346
(QNetworkAccessManager::GetOperation,

src/exit-handler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class QExitHandler : public QObject
3131
public slots:
3232
void qExitApplicationSlot()
3333
{
34-
qInfo() << qApp->applicationName().toLatin1().constData()
34+
qDebug() << qApp->applicationName().toLatin1().constData()
3535
<< qApp->applicationVersion().toLatin1().constData()
3636
<< "terminated normally.";
3737

src/main.cpp

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void customMessageHandler(QtMsgType type,
8181
switch (type) {
8282
#if QT_VERSION >= 0x050500
8383
case QtInfoMsg:
84-
text += QString("{Info} %1").arg(message);
84+
text += QString("{Log} %1").arg(message);
8585
break;
8686
#endif
8787
case QtDebugMsg:
@@ -127,6 +127,11 @@ int main(int argc, char **argv)
127127
application.setApplicationVersion("0.4.1");
128128
bool startedAsRoot = false;
129129

130+
// ==============================
131+
// PSEUDO-DOMAIN:
132+
// ==============================
133+
application.setProperty("pseudoDomain", QString("local-pseudodomain"));
134+
130135
// ==============================
131136
// UTF-8 ENCODING APPLICATION-WIDE:
132137
// ==============================
@@ -312,7 +317,7 @@ int main(int argc, char **argv)
312317
}
313318
}
314319

315-
trustedDomainsList.append(PSEUDO_DOMAIN);
320+
trustedDomainsList.append(application.property("pseudoDomain").toString());
316321
application.setProperty("trustedDomains", trustedDomainsList);
317322

318323
// ==============================
@@ -384,7 +389,7 @@ int main(int argc, char **argv)
384389

385390
mainWindow.webViewWidget->setHtml(htmlErrorContents);
386391

387-
qInfo() << "Using"
392+
qDebug() << "Using"
388393
<< application.applicationName().toLatin1().constData()
389394
<< application.applicationVersion().toLatin1().constData()
390395
<< "with administrative privileges is not allowed.";
@@ -406,47 +411,49 @@ int main(int argc, char **argv)
406411

407412
mainWindow.webViewWidget->setHtml(htmlErrorContents);
408413

409-
qInfo() << application.applicationName().toLatin1().constData()
414+
qDebug() << application.applicationName().toLatin1().constData()
410415
<< application.applicationVersion().toLatin1().constData()
411416
<< "started.";
412-
qInfo() << "Qt version:" << QT_VERSION_STR;
413-
qInfo() << "Executable:" << application.applicationFilePath();
414-
qInfo() << "No Perl interpreter is found.";
417+
qDebug() << "Qt version:" << QT_VERSION_STR;
418+
qDebug() << "Executable:" << application.applicationFilePath();
419+
qDebug() << "No Perl interpreter is found.";
415420
}
416421

417422
if (startedAsRoot == false and perlInterpreterFullPath.length() > 0) {
418423
// ==============================
419424
// LOG BASIC PROGRAM INFORMATION AND SETTINGS:
420425
// ==============================
421-
qInfo() << application.applicationName().toLatin1().constData()
426+
qDebug() << application.applicationName().toLatin1().constData()
422427
<< application.applicationVersion().toLatin1().constData()
423428
<< "started.";
424-
qInfo() << "Qt version:" << QT_VERSION_STR;
425-
qInfo() << "Executable:" << application.applicationFilePath();
426-
qInfo() << "PID:" << application.applicationPid();
429+
qDebug() << "Qt version:" << QT_VERSION_STR;
430+
qDebug() << "Executable:" << application.applicationFilePath();
431+
qDebug() << "PID:" << application.applicationPid();
427432

428433
#if ADMIN_PRIVILEGES_CHECK == 0
429-
qInfo() << "Administrative privileges check is disabled.";
434+
qDebug() << "Administrative privileges check is disabled.";
430435
#endif
431436

432437
#if ADMIN_PRIVILEGES_CHECK == 1
433-
qInfo() << "Administrative privileges check is enabled.";
438+
qDebug() << "Administrative privileges check is enabled.";
434439
#endif
435440

436441
#if PERL_DEBUGGER_GUI == 0
437-
qInfo() << "Perl debugger GUI is disabled.";
442+
qDebug() << "Perl debugger GUI is disabled.";
438443
#endif
439444

440445
#if PERL_DEBUGGER_GUI == 1
441-
qInfo() << "Perl debugger GUI is enabled.";
446+
qDebug() << "Perl debugger GUI is enabled.";
442447
#endif
443448

444-
qInfo() << "Perl interpreter:" << perlInterpreterFullPath;
445-
qInfo() <<"Local pseudo-domain:" << PSEUDO_DOMAIN;
449+
qDebug() << "Perl interpreter:" << perlInterpreterFullPath;
450+
qDebug() <<"Local pseudo-domain:"
451+
<< application.property("pseudoDomain").toString();
446452

447453
foreach (QString trustedDomain, trustedDomainsList) {
448-
if (trustedDomain != PSEUDO_DOMAIN) {
449-
qInfo() << "Trusted domain:" << trustedDomain;
454+
if (trustedDomain !=
455+
application.property("pseudoDomain").toString()) {
456+
qDebug() << "Trusted domain:" << trustedDomain;
450457
}
451458
}
452459

@@ -458,7 +465,10 @@ int main(int argc, char **argv)
458465
applicationDirName + QDir::separator() + "index.html");
459466

460467
if (staticStartPageFile.exists()) {
461-
startPage = "http://" + QString(PSEUDO_DOMAIN) + "/index.html";
468+
startPage =
469+
"http://" +
470+
QString(application.property("pseudoDomain").toString()) +
471+
"/index.html";
462472

463473
application.setProperty("startPage", startPage);
464474

@@ -467,7 +477,11 @@ int main(int argc, char **argv)
467477
QFile dynamicStartPageFile(
468478
applicationDirName + QDir::separator() + "index.pl");
469479
if (dynamicStartPageFile.exists()) {
470-
startPage = "http://" + QString(PSEUDO_DOMAIN) + "/index.pl";
480+
startPage =
481+
"http://" +
482+
QString(application.property("pseudoDomain")
483+
.toString()) +
484+
"/index.pl";
471485

472486
application.setProperty("startPage", startPage);
473487

@@ -481,7 +495,7 @@ int main(int argc, char **argv)
481495
htmlErrorContents.replace("ERROR_MESSAGE", errorMessage);
482496
mainWindow.webViewWidget->setHtml(htmlErrorContents);
483497

484-
qInfo() << "No start page is found.";
498+
qDebug() << "No start page is found.";
485499
}
486500
}
487501
}

src/page.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
#include "file-reader.h"
3535
#include "script-handler.h"
36-
#include "pseudo-domain.h"
3736

3837
// ==============================
3938
// WEB PAGE CLASS CONSTRUCTOR:
@@ -116,7 +115,9 @@ public slots:
116115
if (stdoutTarget.length() > 0) {
117116
qOutputInserter(output, stdoutTarget);
118117
} else {
119-
lastTargetFrame->setHtml(output, QUrl(PSEUDO_DOMAIN));
118+
lastTargetFrame->setHtml(output,
119+
QUrl(qApp->property("pseudoDomain")
120+
.toString()));
120121
}
121122
}
122123

@@ -502,7 +503,7 @@ public slots:
502503
debuggerHandler.close();
503504

504505
// Start the Perl debugger:
505-
qInfo() << QDateTime::currentMSecsSinceEpoch()
506+
qDebug() << QDateTime::currentMSecsSinceEpoch()
506507
<< "msecs from epoch: file passed to Perl debugger:"
507508
<< scriptToDebug;
508509
}
@@ -520,7 +521,7 @@ public slots:
520521

521522
if (debuggerHandler.isOpen()) {
522523
if (debuggerCommand.length() > 0) {
523-
qInfo() << QDateTime::currentMSecsSinceEpoch()
524+
qDebug() << QDateTime::currentMSecsSinceEpoch()
524525
<< "msecs from epoch: Perl debugger command:"
525526
<< debuggerCommand;
526527

@@ -623,7 +624,8 @@ public slots:
623624
return false;
624625
}
625626

626-
if (request.url().authority() == PSEUDO_DOMAIN) {
627+
if (request.url().authority() ==
628+
qApp->property("pseudoDomain").toString()) {
627629
lastTargetFrame = frame;
628630

629631
if (pageStatus == "trusted") {

src/peb.pro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ equals (QT_MAJOR_VERSION, 5) {
129129
local-reply.h \
130130
main-window.h \
131131
page.h \
132-
pseudo-domain.h \
133132
script-handler.h \
134133
view.h
135134

src/pseudo-domain.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/script-handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,6 @@ QScriptHandler::QScriptHandler(
186186
#endif
187187
#endif
188188

189-
qInfo() << QDateTime::currentMSecsSinceEpoch()
189+
qDebug() << QDateTime::currentMSecsSinceEpoch()
190190
<< "msecs from epoch: script started:" << scriptFullFilePath;
191191
}

src/script-handler.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public slots:
4444
QString output = scriptProcess.readAllStandardOutput();
4545
scriptAccumulatedOutput.append(output);
4646

47-
qInfo() << QDateTime::currentMSecsSinceEpoch()
47+
qDebug() << QDateTime::currentMSecsSinceEpoch()
4848
<< "msecs from epoch: output from" << scriptFullFilePath;
4949

5050
// Handling 'script closed' confirmation:
5151
if (output == scriptCloseConfirmation) {
52-
qInfo() << QDateTime::currentMSecsSinceEpoch()
52+
qDebug() << QDateTime::currentMSecsSinceEpoch()
5353
<< "msecs from epoch:"
5454
<< "interactive script terminated normally:"
5555
<< scriptFullFilePath;
@@ -66,7 +66,7 @@ public slots:
6666
scriptAccumulatedErrors.append(scriptErrors);
6767
scriptAccumulatedErrors.append("\n");
6868

69-
qInfo() << QDateTime::currentMSecsSinceEpoch()
69+
qDebug() << QDateTime::currentMSecsSinceEpoch()
7070
<< "msecs from epoch: errors from" << scriptFullFilePath;
7171
// qDebug() << "Script errors:" << scriptErrors;
7272
}
@@ -81,7 +81,7 @@ public slots:
8181

8282
scriptProcess.close();
8383

84-
qInfo() << QDateTime::currentMSecsSinceEpoch()
84+
qDebug() << QDateTime::currentMSecsSinceEpoch()
8585
<< "msecs from epoch: script finished:" << scriptFullFilePath;
8686
}
8787

0 commit comments

Comments
 (0)