source: ntrip/trunk/BNC/src/bncsslconfig.cpp@ 9739

Last change on this file since 9739 was 9739, checked in by stuerze, 23 months ago

minor changes

File size: 2.1 KB
RevLine 
[3347]1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncSslConfig
6 *
[3348]7 * Purpose: Singleton Class that inherits QSslConfiguration class
[3347]8 *
9 * Author: L. Mervart
10 *
11 * Created: 22-Aug-2011
12 *
[9739]13 * Changes:
[3347]14 *
15 * -----------------------------------------------------------------------*/
16
17#include <iostream>
18
[8252]19#include <QApplication>
20#include <QDir>
21#include <QStringList>
22
[3347]23#include "bncsslconfig.h"
[3358]24#include "bncsettings.h"
[3347]25
[9739]26
27// Singleton
28////////////////////////////////////////////////////////////////////////////
29bncSslConfig bncSslConfig::instance() {
30 static bncSslConfig _sslConfig;
31 return _sslConfig;
32}
33
[3347]34// Constructor
35////////////////////////////////////////////////////////////////////////////
[9739]36bncSslConfig::bncSslConfig() :
37 QSslConfiguration(QSslConfiguration::defaultConfiguration())
[3350]38{
[9739]39
[3358]40 bncSettings settings;
41 QString dirName = settings.value("sslCaCertPath").toString();
42 if (dirName.isEmpty()) {
43 dirName = defaultPath();
44 }
[3350]45
46 QList<QSslCertificate> caCerts = this->caCertificates();
47
48 // Bug in Qt: the wildcard does not work here:
49 // -------------------------------------------
50 // caCerts += QSslCertificate::fromPath(dirName + QDir::separator() + "*crt",
51 // QSsl::Pem, QRegExp::Wildcard);
52 QDir dir(dirName);
53 QStringList nameFilters; nameFilters << "*.crt";
54 QStringList fileNames = dir.entryList(nameFilters, QDir::Files);
55 QStringListIterator it(fileNames);
56 while (it.hasNext()) {
57 QString fileName = it.next();
58 caCerts += QSslCertificate::fromPath(dirName+QDir::separator()+fileName);
59 }
[9739]60
[3348]61 this->setCaCertificates(caCerts);
[3347]62}
63
64// Destructor
65////////////////////////////////////////////////////////////////////////////
66bncSslConfig::~bncSslConfig() {
67}
68
[3357]69// Destructor
70////////////////////////////////////////////////////////////////////////////
71QString bncSslConfig::defaultPath() {
[9739]72 return QDir::homePath() + QDir::separator()
[3357]73 + ".config" + QDir::separator() + qApp->organizationName();
74}
75
Note: See TracBrowser for help on using the repository browser.