modernize: Pass arguments by value and move in constructors
[quassel.git] / src / core / coreidentity.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #include "coreidentity.h"
22
23 #include "signalproxy.h"
24
25 CoreIdentity::CoreIdentity(IdentityId id, QObject *parent)
26     : Identity(id, parent)
27 #ifdef HAVE_SSL
28     , _certManager(*this)
29 #endif
30 {
31 #ifdef HAVE_SSL
32     connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId)));
33     connect(&_certManager, SIGNAL(updated()), this, SIGNAL(updated()));
34 #endif
35 }
36
37
38 CoreIdentity::CoreIdentity(const Identity &other, QObject *parent)
39     : Identity(other, parent)
40 #ifdef HAVE_SSL
41     , _certManager(*this)
42 #endif
43 {
44 #ifdef HAVE_SSL
45     connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId)));
46     connect(&_certManager, SIGNAL(updated()), this, SIGNAL(updated()));
47 #endif
48 }
49
50
51 CoreIdentity::CoreIdentity(const CoreIdentity &other, QObject *parent)
52     : Identity(other, parent)
53 #ifdef HAVE_SSL
54     , _sslKey(other._sslKey),
55     _sslCert(other._sslCert),
56     _certManager(*this)
57 #endif
58 {
59 #ifdef HAVE_SSL
60     connect(this, SIGNAL(idSet(IdentityId)), &_certManager, SLOT(setId(IdentityId)));
61     connect(&_certManager, SIGNAL(updated()), this, SIGNAL(updated()));
62 #endif
63 }
64
65
66 void CoreIdentity::synchronize(SignalProxy *proxy)
67 {
68     proxy->synchronize(this);
69 #ifdef HAVE_SSL
70     proxy->synchronize(&_certManager);
71 #endif
72 }
73
74
75 #ifdef HAVE_SSL
76 void CoreIdentity::setSslKey(const QByteArray &encoded)
77 {
78     QSslKey key(encoded, QSsl::Rsa);
79     if (key.isNull())
80         key = QSslKey(encoded, QSsl::Ec);
81     if (key.isNull())
82         key = QSslKey(encoded, QSsl::Dsa);
83     setSslKey(key);
84 }
85
86
87 void CoreIdentity::setSslCert(const QByteArray &encoded)
88 {
89     setSslCert(QSslCertificate(encoded));
90 }
91
92
93 #endif
94
95 CoreIdentity &CoreIdentity::operator=(const CoreIdentity &identity)
96 {
97     Identity::operator=(identity);
98 #ifdef HAVE_SSL
99     _sslKey = identity._sslKey;
100     _sslCert = identity._sslCert;
101 #endif
102     return *this;
103 }
104
105
106 #ifdef HAVE_SSL
107 // ========================================
108 //  CoreCertManager
109 // ========================================
110
111 CoreCertManager::CoreCertManager(CoreIdentity &identity)
112     : CertManager(identity.id()),
113     identity(identity)
114 {
115     setAllowClientUpdates(true);
116 }
117
118
119 void CoreCertManager::setId(IdentityId id)
120 {
121     renameObject(QString::number(id.toInt()));
122 }
123
124
125 void CoreCertManager::setSslKey(const QByteArray &encoded)
126 {
127     identity.setSslKey(encoded);
128     CertManager::setSslKey(encoded);
129 }
130
131
132 void CoreCertManager::setSslCert(const QByteArray &encoded)
133 {
134     identity.setSslCert(encoded);
135     CertManager::setSslCert(encoded);
136 }
137
138
139 #endif //HAVE_SSL