This repository was archived by the owner on May 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Expand file tree
/
Copy pathconfig.cpp
More file actions
797 lines (660 loc) · 22.5 KB
/
config.cpp
File metadata and controls
797 lines (660 loc) · 22.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
/*
This file is part of the PhantomJS project from Ofi Labs.
Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
Copyright (C) 2011 execjosh, http://execjosh.blogspot.com
Copyright (C) 2013 James M. Greene <james.m.greene@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include <QDir>
#include <QFileInfo>
#include <QNetworkProxy>
#include <QtWebKitWidgets/QWebFrame>
#include <QtWebKitWidgets/QWebPage>
#include "consts.h"
#include "qcommandline.h"
#include "terminal.h"
#include "utils.h"
#include <iostream>
static const struct QCommandLineConfigEntry flags[] = {
{ QCommandLine::Option, '\0', "cookies-file", "Sets the file name to store the persistent cookies", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "config", "Specifies JSON-formatted configuration file", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "debug", "Prints additional warning and debug message: 'true' or 'false' (default)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "disk-cache", "Enables disk cache: 'true' or 'false' (default)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "disk-cache-path", "Specifies the location for the disk cache", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "ignore-ssl-errors", "Ignores SSL errors (expired/self-signed certificate errors): 'true' or 'false' (default)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "load-images", "Loads all inlined images: 'true' (default) or 'false'", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "local-url-access", "Allows use of 'file:///' URLs: 'true' (default) or 'false'", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "local-storage-path", "Specifies the location for local storage", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "local-storage-quota", "Sets the maximum size of the local storage (in KB)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "offline-storage-path", "Specifies the location for offline storage", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "offline-storage-quota", "Sets the maximum size of the offline storage (in KB)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "local-to-remote-url-access", "Allows local content to access remote URL: 'true' or 'false' (default)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "max-disk-cache-size", "Limits the size of the disk cache (in KB)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "output-encoding", "Sets the encoding for the terminal output, default is 'utf8'", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "remote-debugger-port", "Starts the script in a debug harness and listens on the specified port", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "remote-debugger-autorun", "Runs the script in the debugger immediately: 'true' or 'false' (default)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "proxy", "Sets the proxy server, e.g. '--proxy=http://proxy.company.com:8080'", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "proxy-auth", "Provides authentication information for the proxy, e.g. ''-proxy-auth=username:password'", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "proxy-type", "Specifies the proxy type, 'http' (default), 'none' (disable completely), or 'socks5'", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "script-encoding", "Sets the encoding used for the starting script, default is 'utf8'", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "script-language", "Sets the script language instead of detecting it: 'javascript'", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "web-security", "Enables web security, 'true' (default) or 'false'", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "ssl-protocol", "Selects a specific SSL protocol version to offer. Values (case insensitive): TLSv1.2, TLSv1.1, TLSv1.0, TLSv1 (same as v1.0), SSLv3, or ANY. Default is to offer all that Qt thinks are secure (SSLv3 and up). Not all values may be supported, depending on the system OpenSSL library.", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "ssl-ciphers", "Sets supported TLS/SSL ciphers. Argument is a colon-separated list of OpenSSL cipher names (macros like ALL, kRSA, etc. may not be used). Default matches modern browsers.", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "ssl-certificates-path", "Sets the location for custom CA certificates (if none set, uses environment variable SSL_CERT_DIR. If none set too, uses system default)", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "ssl-client-certificate-file", "Sets the location of a client certificate", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "ssl-client-key-file", "Sets the location of a clients' private key", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "ssl-client-key-passphrase", "Sets the passphrase for the clients' private key", QCommandLine::Optional },
{ QCommandLine::Param, '\0', "script", "Script", QCommandLine::Flags(QCommandLine::Optional | QCommandLine::ParameterFence) },
{ QCommandLine::Param, '\0', "argument", "Script argument", QCommandLine::OptionalMultiple },
{ QCommandLine::Switch, 'h', "help", "Shows this message and quits", QCommandLine::Optional },
{ QCommandLine::Switch, 'v', "version", "Prints out PhantomJS version", QCommandLine::Optional },
QCOMMANDLINE_CONFIG_ENTRY_END
};
Config::Config(QObject* parent)
: QObject(parent)
{
m_cmdLine = new QCommandLine(this);
// We will handle --help and --version ourselves in phantom.cpp
m_cmdLine->enableHelp(false);
m_cmdLine->enableVersion(false);
resetToDefaults();
}
void Config::init(const QStringList* const args)
{
resetToDefaults();
QByteArray envSslCertDir = qgetenv("SSL_CERT_DIR");
if (!envSslCertDir.isEmpty()) {
setSslCertificatesPath(envSslCertDir);
}
processArgs(*args);
}
void Config::processArgs(const QStringList& args)
{
connect(m_cmdLine, SIGNAL(switchFound(const QString&)), this, SLOT(handleSwitch(const QString&)));
connect(m_cmdLine, SIGNAL(optionFound(const QString&, const QVariant&)), this, SLOT(handleOption(const QString&, const QVariant&)));
connect(m_cmdLine, SIGNAL(paramFound(const QString&, const QVariant&)), this, SLOT(handleParam(const QString&, const QVariant&)));
connect(m_cmdLine, SIGNAL(parseError(const QString&)), this, SLOT(handleError(const QString&)));
m_cmdLine->setArguments(args);
m_cmdLine->setConfig(flags);
m_cmdLine->parse();
}
void Config::loadJsonFile(const QString& filePath)
{
QString jsonConfig;
QFile f(filePath);
// Check file exists and is readable
if (!f.exists() || !f.open(QFile::ReadOnly | QFile::Text)) {
Terminal::instance()->cerr("Unable to open config: \"" + filePath + "\"");
return;
}
// Read content
jsonConfig = QString::fromUtf8(f.readAll().trimmed());
f.close();
// Check it's a valid JSON format
if (jsonConfig.isEmpty() || !jsonConfig.startsWith('{') || !jsonConfig.endsWith('}')) {
Terminal::instance()->cerr("Config file MUST be in JSON format!");
return;
}
// Load configurator
QString configurator = Utils::readResourceFileUtf8(":/configurator.js");
// Use a temporary QWebPage to load the JSON configuration in this Object using the 'configurator' above
QWebPage webPage;
// Add this object to the global scope
webPage.mainFrame()->addToJavaScriptWindowObject("config", this);
// Apply the JSON config settings to this very object
webPage.mainFrame()->evaluateJavaScript(configurator.arg(jsonConfig));
}
QString Config::helpText() const
{
return m_cmdLine->help();
}
bool Config::autoLoadImages() const
{
return m_autoLoadImages;
}
void Config::setAutoLoadImages(const bool value)
{
m_autoLoadImages = value;
}
QString Config::cookiesFile() const
{
return m_cookiesFile;
}
void Config::setCookiesFile(const QString& value)
{
m_cookiesFile = value;
}
QString Config::offlineStoragePath() const
{
return m_offlineStoragePath;
}
void Config::setOfflineStoragePath(const QString& value)
{
QDir dir(value);
m_offlineStoragePath = dir.absolutePath();
}
int Config::offlineStorageDefaultQuota() const
{
return m_offlineStorageDefaultQuota;
}
void Config::setOfflineStorageDefaultQuota(int offlineStorageDefaultQuota)
{
m_offlineStorageDefaultQuota = offlineStorageDefaultQuota * 1024;
}
QString Config::localStoragePath() const
{
return m_localStoragePath;
}
void Config::setLocalStoragePath(const QString& value)
{
QDir dir(value);
m_localStoragePath = dir.absolutePath();
}
int Config::localStorageDefaultQuota() const
{
return m_localStorageDefaultQuota;
}
void Config::setLocalStorageDefaultQuota(int localStorageDefaultQuota)
{
m_localStorageDefaultQuota = localStorageDefaultQuota * 1024;
}
bool Config::diskCacheEnabled() const
{
return m_diskCacheEnabled;
}
void Config::setDiskCacheEnabled(const bool value)
{
m_diskCacheEnabled = value;
}
int Config::maxDiskCacheSize() const
{
return m_maxDiskCacheSize;
}
void Config::setMaxDiskCacheSize(int maxDiskCacheSize)
{
m_maxDiskCacheSize = maxDiskCacheSize;
}
QString Config::diskCachePath() const
{
return m_diskCachePath;
}
void Config::setDiskCachePath(const QString& value)
{
QDir dir(value);
m_diskCachePath = dir.absolutePath();
}
bool Config::ignoreSslErrors() const
{
return m_ignoreSslErrors;
}
void Config::setIgnoreSslErrors(const bool value)
{
m_ignoreSslErrors = value;
}
bool Config::localUrlAccessEnabled() const
{
return m_localUrlAccessEnabled;
}
void Config::setLocalUrlAccessEnabled(const bool value)
{
m_localUrlAccessEnabled = value;
}
bool Config::localToRemoteUrlAccessEnabled() const
{
return m_localToRemoteUrlAccessEnabled;
}
void Config::setLocalToRemoteUrlAccessEnabled(const bool value)
{
m_localToRemoteUrlAccessEnabled = value;
}
QString Config::outputEncoding() const
{
return m_outputEncoding;
}
void Config::setOutputEncoding(const QString& value)
{
if (value.isEmpty()) {
return;
}
m_outputEncoding = value;
}
QString Config::proxyType() const
{
return m_proxyType;
}
void Config::setProxyType(const QString& value)
{
m_proxyType = value;
}
QString Config::proxy() const
{
return m_proxyHost + ":" + QString::number(m_proxyPort);
}
void Config::setProxy(const QString& value)
{
QUrl proxyUrl = QUrl::fromUserInput(value);
if (proxyUrl.isValid()) {
setProxyHost(proxyUrl.host());
setProxyPort(proxyUrl.port(1080));
}
}
void Config::setProxyAuth(const QString& value)
{
QString proxyUser = value;
QString proxyPass = "";
if (proxyUser.lastIndexOf(':') > 0) {
proxyPass = proxyUser.mid(proxyUser.lastIndexOf(':') + 1).trimmed();
proxyUser = proxyUser.left(proxyUser.lastIndexOf(':')).trimmed();
setProxyAuthUser(proxyUser);
setProxyAuthPass(proxyPass);
}
}
QString Config::proxyAuth() const
{
return proxyAuthUser() + ":" + proxyAuthPass();
}
QString Config::proxyAuthUser() const
{
return m_proxyAuthUser;
}
QString Config::proxyAuthPass() const
{
return m_proxyAuthPass;
}
QString Config::proxyHost() const
{
return m_proxyHost;
}
int Config::proxyPort() const
{
return m_proxyPort;
}
QStringList Config::scriptArgs() const
{
return m_scriptArgs;
}
void Config::setScriptArgs(const QStringList& value)
{
m_scriptArgs.clear();
QStringListIterator it(value);
while (it.hasNext()) {
m_scriptArgs.append(it.next());
}
}
QString Config::scriptEncoding() const
{
return m_scriptEncoding;
}
void Config::setScriptEncoding(const QString& value)
{
if (value.isEmpty()) {
return;
}
m_scriptEncoding = value;
}
QString Config::scriptFile() const
{
return m_scriptFile;
}
void Config::setScriptFile(const QString& value)
{
m_scriptFile = value;
}
QString Config::unknownOption() const
{
return m_unknownOption;
}
void Config::setUnknownOption(const QString& value)
{
m_unknownOption = value;
}
bool Config::versionFlag() const
{
return m_versionFlag;
}
void Config::setVersionFlag(const bool value)
{
m_versionFlag = value;
}
bool Config::debug() const
{
return m_debug;
}
void Config::setDebug(const bool value)
{
m_debug = value;
}
int Config::remoteDebugPort() const
{
return m_remoteDebugPort;
}
void Config::setRemoteDebugPort(const int port)
{
m_remoteDebugPort = port;
}
bool Config::remoteDebugAutorun() const
{
return m_remoteDebugAutorun;
}
void Config::setRemoteDebugAutorun(const bool value)
{
m_remoteDebugAutorun = value;
}
bool Config::webSecurityEnabled() const
{
return m_webSecurityEnabled;
}
void Config::setWebSecurityEnabled(const bool value)
{
m_webSecurityEnabled = value;
}
void Config::setJavascriptCanOpenWindows(const bool value)
{
m_javascriptCanOpenWindows = value;
}
bool Config::javascriptCanOpenWindows() const
{
return m_javascriptCanOpenWindows;
}
void Config::setJavascriptCanCloseWindows(const bool value)
{
m_javascriptCanCloseWindows = value;
}
bool Config::javascriptCanCloseWindows() const
{
return m_javascriptCanCloseWindows;
}
// private:
void Config::resetToDefaults()
{
m_autoLoadImages = true;
m_cookiesFile = QString();
m_offlineStoragePath = QString();
m_offlineStorageDefaultQuota = -1;
m_localStoragePath = QString();
m_localStorageDefaultQuota = -1;
m_diskCacheEnabled = false;
m_maxDiskCacheSize = -1;
m_diskCachePath = QString();
m_ignoreSslErrors = false;
m_localUrlAccessEnabled = true;
m_localToRemoteUrlAccessEnabled = false;
m_outputEncoding = "UTF-8";
m_proxyType = "http";
m_proxyHost.clear();
m_proxyPort = 1080;
m_proxyAuthUser.clear();
m_proxyAuthPass.clear();
m_scriptArgs.clear();
m_scriptEncoding = "UTF-8";
m_scriptFile.clear();
m_unknownOption.clear();
m_versionFlag = false;
m_debug = false;
m_remoteDebugPort = -1;
m_remoteDebugAutorun = false;
m_webSecurityEnabled = true;
m_javascriptCanOpenWindows = true;
m_javascriptCanCloseWindows = true;
m_helpFlag = false;
m_printDebugMessages = false;
m_sslProtocol = "default";
// Default taken from Chromium 35.0.1916.153
m_sslCiphers = ("ECDHE-ECDSA-AES128-GCM-SHA256"
":ECDHE-RSA-AES128-GCM-SHA256"
":DHE-RSA-AES128-GCM-SHA256"
":ECDHE-ECDSA-AES256-SHA"
":ECDHE-ECDSA-AES128-SHA"
":ECDHE-RSA-AES128-SHA"
":ECDHE-RSA-AES256-SHA"
":ECDHE-ECDSA-RC4-SHA"
":ECDHE-RSA-RC4-SHA"
":DHE-RSA-AES128-SHA"
":DHE-DSS-AES128-SHA"
":DHE-RSA-AES256-SHA"
":AES128-GCM-SHA256"
":AES128-SHA"
":AES256-SHA"
":DES-CBC3-SHA"
":RC4-SHA"
":RC4-MD5");
m_sslCertificatesPath.clear();
m_sslClientCertificateFile.clear();
m_sslClientKeyFile.clear();
m_sslClientKeyPassphrase.clear();
}
void Config::setProxyAuthPass(const QString& value)
{
m_proxyAuthPass = value;
}
void Config::setProxyAuthUser(const QString& value)
{
m_proxyAuthUser = value;
}
void Config::setProxyHost(const QString& value)
{
m_proxyHost = value;
}
void Config::setProxyPort(const int value)
{
m_proxyPort = value;
}
bool Config::helpFlag() const
{
return m_helpFlag;
}
void Config::setHelpFlag(const bool value)
{
m_helpFlag = value;
}
bool Config::printDebugMessages() const
{
return m_printDebugMessages;
}
void Config::setPrintDebugMessages(const bool value)
{
m_printDebugMessages = value;
}
void Config::handleSwitch(const QString& sw)
{
setHelpFlag(sw == "help");
setVersionFlag(sw == "version");
}
void Config::handleOption(const QString& option, const QVariant& value)
{
bool boolValue = false;
QStringList booleanFlags;
booleanFlags << "debug";
booleanFlags << "disk-cache";
booleanFlags << "ignore-ssl-errors";
booleanFlags << "load-images";
booleanFlags << "local-url-access";
booleanFlags << "local-to-remote-url-access";
booleanFlags << "remote-debugger-autorun";
booleanFlags << "web-security";
if (booleanFlags.contains(option)) {
if ((value != "true") && (value != "yes") && (value != "false") && (value != "no")) {
setUnknownOption(QString("Invalid values for '%1' option.").arg(option));
return;
}
boolValue = (value == "true") || (value == "yes");
}
if (option == "cookies-file") {
setCookiesFile(value.toString());
}
if (option == "config") {
loadJsonFile(value.toString());
}
if (option == "debug") {
setPrintDebugMessages(boolValue);
}
if (option == "disk-cache") {
setDiskCacheEnabled(boolValue);
}
if (option == "disk-cache-path") {
setDiskCachePath(value.toString());
}
if (option == "ignore-ssl-errors") {
setIgnoreSslErrors(boolValue);
}
if (option == "load-images") {
setAutoLoadImages(boolValue);
}
if (option == "local-storage-path") {
setLocalStoragePath(value.toString());
}
if (option == "local-storage-quota") {
setLocalStorageDefaultQuota(value.toInt());
}
if (option == "offline-storage-path") {
setOfflineStoragePath(value.toString());
}
if (option == "offline-storage-quota") {
setOfflineStorageDefaultQuota(value.toInt());
}
if (option == "local-url-access") {
setLocalUrlAccessEnabled(boolValue);
}
if (option == "local-to-remote-url-access") {
setLocalToRemoteUrlAccessEnabled(boolValue);
}
if (option == "max-disk-cache-size") {
setMaxDiskCacheSize(value.toInt());
}
if (option == "output-encoding") {
setOutputEncoding(value.toString());
}
if (option == "remote-debugger-autorun") {
setRemoteDebugAutorun(boolValue);
}
if (option == "remote-debugger-port") {
setDebug(true);
setRemoteDebugPort(value.toInt());
}
if (option == "proxy") {
setProxy(value.toString());
}
if (option == "proxy-type") {
setProxyType(value.toString());
}
if (option == "proxy-auth") {
setProxyAuth(value.toString());
}
if (option == "script-encoding") {
setScriptEncoding(value.toString());
}
if (option == "web-security") {
setWebSecurityEnabled(boolValue);
}
if (option == "ssl-protocol") {
setSslProtocol(value.toString());
}
if (option == "ssl-ciphers") {
setSslCiphers(value.toString());
}
if (option == "ssl-certificates-path") {
setSslCertificatesPath(value.toString());
}
if (option == "ssl-client-certificate-file") {
setSslClientCertificateFile(value.toString());
}
if (option == "ssl-client-key-file") {
setSslClientKeyFile(value.toString());
}
if (option == "ssl-client-key-passphrase") {
setSslClientKeyPassphrase(value.toByteArray());
}
}
void Config::handleParam(const QString& param, const QVariant& value)
{
Q_UNUSED(param);
if (m_scriptFile.isEmpty()) {
m_scriptFile = value.toString();
} else {
m_scriptArgs += value.toString();
}
}
void Config::handleError(const QString& error)
{
setUnknownOption(QString("Error: %1").arg(error));
}
QString Config::sslProtocol() const
{
return m_sslProtocol;
}
void Config::setSslProtocol(const QString& sslProtocolName)
{
m_sslProtocol = sslProtocolName.toLower();
}
QString Config::sslCiphers() const
{
return m_sslCiphers;
}
void Config::setSslCiphers(const QString& sslCiphersName)
{
// OpenSSL cipher strings are case sensitive.
m_sslCiphers = sslCiphersName;
}
QString Config::sslCertificatesPath() const
{
return m_sslCertificatesPath;
}
void Config::setSslCertificatesPath(const QString& sslCertificatesPath)
{
QFileInfo sslPathInfo = QFileInfo(sslCertificatesPath);
if (sslPathInfo.isDir()) {
if (sslCertificatesPath.endsWith('/')) {
m_sslCertificatesPath = sslCertificatesPath + "*";
} else {
m_sslCertificatesPath = sslCertificatesPath + "/*";
}
} else {
m_sslCertificatesPath = sslCertificatesPath;
}
}
QString Config::sslClientCertificateFile() const
{
return m_sslClientCertificateFile;
}
void Config::setSslClientCertificateFile(const QString& sslClientCertificateFile)
{
m_sslClientCertificateFile = sslClientCertificateFile;
}
QString Config::sslClientKeyFile() const
{
return m_sslClientKeyFile;
}
void Config::setSslClientKeyFile(const QString& sslClientKeyFile)
{
m_sslClientKeyFile = sslClientKeyFile;
}
QByteArray Config::sslClientKeyPassphrase() const
{
return m_sslClientKeyPassphrase;
}
void Config::setSslClientKeyPassphrase(const QByteArray& sslClientKeyPassphrase)
{
m_sslClientKeyPassphrase = sslClientKeyPassphrase;
}