Debian Codegraph @

src/librssguard/network-web/gemini/geminiclient.cpp

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.cxx . . $ `<file>/src/librssguard/network-web/gemini/geminiclient.cpp`/
2 //
3 // This file is heavily inspired by https://github.com/ikskuh/kristall.
4
5 #include "network-web/gemini/geminiclient.h"cxx . . $ `<file>/src/librssguard/network-web/gemini/geminiclient.h`/
6
7 #include "definitions/definitions.h"cxx . . $ `<file>/src/librssguard/definitions/definitions.h`/
8
9 #include <cassert>
10
11 #include <QDebug>
12 #include <QRegularExpression>
13 #include <QSslConfiguration>
14 #include <QUrl>
15
16 bool CryptoIdentitycxx . . $ CryptoIdentity#::isValidcxx . . $ CryptoIdentity#isValid(50ce9a9e25b4a850).() const {
17 return !certificatecxx . . $ CryptoIdentity#certificate..isNullcxx . . $ QSslCertificate#isNull(50ce9a9e25b4a850).() && !private_keycxx . . $ CryptoIdentity#private_key..isNullcxx . . $ QSslKey#isNull(50ce9a9e25b4a850).();
18 }
19
20 bool CryptoIdentitycxx . . $ CryptoIdentity#::isHostFilteredcxx . . $ CryptoIdentity#isHostFiltered(dd54f9efb9153ea5).(const QUrlcxx . . $ QUrl#& url) const {
21 if (host_filtercxx . . $ CryptoIdentity#host_filter..isEmptycxx . . $ QString#isEmpty(3482b152b9333168).()) {
22 return false;
23 }
24
25 QStringcxx . . $ QString# url_text = url.toStringcxx . . $ QUrl#toString(632475ebea3355f1).(QUrlcxx . . $ QUrlTwoFlags#QUrlTwoFlags(69eed69a60cddb2f).::FullyEncodedcxx . . $ QUrl#FullyEncoded.);
26 QRegularExpressioncxx . . $ QRegularExpression# patterncxx . . $ QRegularExpression#QRegularExpression(4279d2539df7cd4a).(QRegularExpressioncxx . . $ QRegularExpression#::wildcardToRegularExpressioncxx . . $ QRegularExpression#wildcardToRegularExpression(adef7e1bb3d059b7).(host_filtercxx . . $ CryptoIdentity#host_filter.),
27 QRegularExpressioncxx . . $ QFlags#QFlags(93d577a3e9528307).::PatternOptioncxx . . $ QRegularExpression#PatternOption#::CaseInsensitiveOptioncxx . . $ QRegularExpression#CaseInsensitiveOption.);
28
29 return !pattern.matchcxx . . $ QRegularExpression#match(d076266091fa4922).(url_text).hasMatchcxx . . $ QRegularExpressionMatch#hasMatch(50ce9a9e25b4a850).();
30 }
31
32 bool CryptoIdentitycxx . . $ CryptoIdentity#::isAutomaticallyEnabledOncxx . . $ CryptoIdentity#isAutomaticallyEnabledOn(dd54f9efb9153ea5).(const QUrlcxx . . $ QUrl#& url) const {
33 if (host_filtercxx . . $ CryptoIdentity#host_filter..isEmptycxx . . $ QString#isEmpty(3482b152b9333168).()) {
34 return false;
35 }
36
37 if (!auto_enablecxx . . $ CryptoIdentity#auto_enable.) {
38 return false;
39 }
40
41 QStringcxx . . $ QString# url_text = url.toStringcxx . . $ QUrl#toString(632475ebea3355f1).(QUrlcxx . . $ QUrlTwoFlags#QUrlTwoFlags(69eed69a60cddb2f).::FullyEncodedcxx . . $ QUrl#FullyEncoded.);
42 QRegularExpressioncxx . . $ QRegularExpression# patterncxx . . $ QRegularExpression#QRegularExpression(4279d2539df7cd4a).(QRegularExpressioncxx . . $ QRegularExpression#::wildcardToRegularExpressioncxx . . $ QRegularExpression#wildcardToRegularExpression(adef7e1bb3d059b7).(host_filtercxx . . $ CryptoIdentity#host_filter.),
43 QRegularExpressioncxx . . $ QFlags#QFlags(93d577a3e9528307).::PatternOptioncxx . . $ QRegularExpression#PatternOption#::CaseInsensitiveOptioncxx . . $ QRegularExpression#CaseInsensitiveOption.);
44
45 return pattern.matchcxx . . $ QRegularExpression#match(d076266091fa4922).(url_text).hasMatchcxx . . $ QRegularExpressionMatch#hasMatch(50ce9a9e25b4a850).();
46 }
47
48 GeminiClientcxx . . $ GeminiClient#::GeminiClientcxx . . $ GeminiClient#GeminiClient(749de1b6ae65bddd).(QObjectcxx . . $ QObject#* parent) : QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(parent) {
49 connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(&m_socketcxx . . $ GeminiClient#m_socket., &QSslSocketcxx . . $ QSslSocket#::encryptedcxx . . $ QSslSocket#encrypted(49f6e7a06ebc5aa8)., this, &GeminiClientcxx . . $ GeminiClient#::socketEncryptedcxx . . $ GeminiClient#socketEncrypted(49f6e7a06ebc5aa8).);
50 connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(&m_socketcxx . . $ GeminiClient#m_socket., &QSslSocketcxx . . $ QSslSocket#::readyReadcxx . . $ QIODevice#readyRead(49f6e7a06ebc5aa8)., this, &GeminiClientcxx . . $ GeminiClient#::socketReadyReadcxx . . $ GeminiClient#socketReadyRead(49f6e7a06ebc5aa8).);
51 connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(&m_socketcxx . . $ GeminiClient#m_socket., &QSslSocketcxx . . $ QSslSocket#::disconnectedcxx . . $ QAbstractSocket#disconnected(49f6e7a06ebc5aa8)., this, &GeminiClientcxx . . $ GeminiClient#::socketDisconnectedcxx . . $ GeminiClient#socketDisconnected(49f6e7a06ebc5aa8).);
52 connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(&m_socketcxx . . $ GeminiClient#m_socket., QOverloadcxx . . $ QOverload#<const QList<QSslError>&>::ofcxx . . $ QOverload#of(88aa2ca148e6aa42).(&QSslSocketcxx . . $ QSslSocket#::sslErrorscxx . . $ QSslSocket#sslErrors(a6189817b1df8092).), this, &GeminiClientcxx . . $ GeminiClient#::sslErrorscxx . . $ GeminiClient#sslErrors(a6189817b1df8092).);
53
54 // connect(&socket, &QSslSocket::stateChanged, [](QSslSocket::SocketState state) {
55 // qDebug() << "Socket state changed to " << state;
56 // });
57
58 #if (QT_VERSIONcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:17:9`! >= QT_VERSION_CHECKcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:21:9`!(5, 15, 0))
59 connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(&m_socketcxx . . $ GeminiClient#m_socket., &QTcpSocketcxx . . $ QTcpSocket#::errorOccurredcxx . . $ QAbstractSocket#errorOccurred(c866838463bd22b)., this, &GeminiClientcxx . . $ GeminiClient#::socketErrorcxx . . $ GeminiClient#socketError(c866838463bd22b).);
60 #else
61 connect(&m_socket, QOverload<QAbstractSocket::SocketError>::of(&QTcpSocket::error), this, &GeminiClient::socketError);
62 #endif
63
64 // States
65 connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(&m_socketcxx . . $ GeminiClient#m_socket., &QAbstractSocketcxx . . $ QAbstractSocket#::hostFoundcxx . . $ QAbstractSocket#hostFound(49f6e7a06ebc5aa8)., this, [this]() {
66 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! this->requestStateChangecxx . . $ GeminiClient#requestStateChange(75300df2abd8e70).(RequestStatecxx . . $ GeminiClient#RequestState#::HostFoundcxx . . $ GeminiClient#RequestState#HostFound.);
67 });
68
69 connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(&m_socketcxx . . $ GeminiClient#m_socket., &QAbstractSocketcxx . . $ QAbstractSocket#::connectedcxx . . $ QAbstractSocket#connected(49f6e7a06ebc5aa8)., this, [this]() {
70 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! this->requestStateChangecxx . . $ GeminiClient#requestStateChange(75300df2abd8e70).(RequestStatecxx . . $ GeminiClient#RequestState#::Connectedcxx . . $ GeminiClient#RequestState#Connected.);
71 });
72
73 connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(&m_socketcxx . . $ GeminiClient#m_socket., &QAbstractSocketcxx . . $ QAbstractSocket#::disconnectedcxx . . $ QAbstractSocket#disconnected(49f6e7a06ebc5aa8)., this, [this]() {
74 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! this->requestStateChangecxx . . $ GeminiClient#requestStateChange(75300df2abd8e70).(RequestStatecxx . . $ GeminiClient#RequestState#::Nonecxx . . $ GeminiClient#RequestState#None.);
75 });
76
77 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! requestStateChangecxx . . $ GeminiClient#requestStateChange(75300df2abd8e70).(RequestStatecxx . . $ GeminiClient#RequestState#::Nonecxx . . $ GeminiClient#RequestState#None.);
78 }
79
80 GeminiClientcxx . . $ GeminiClient#::~cxx . . $ GeminiClient#`~GeminiClient`(ced63f7c635d850d).GeminiClientcxx . . $ GeminiClient#() {
81 m_isReceivingBodycxx . . $ GeminiClient#m_isReceivingBody. = false;
82 }
83
84 bool GeminiClientcxx . . $ GeminiClient#::supportsUrlcxx . . $ GeminiClient#supportsUrl(f3b39adf77d9c36c).(const QStringcxx . . $ QString#& url) const {
85 return url.startsWithcxx . . $ QString#startsWith(9b0c247ef39438e0).(QL1Scxx . . $ `src/librssguard/definitions/definitions.h:449:9`!("gemini://"));
86 }
87
88 bool GeminiClientcxx . . $ GeminiClient#::supportsUrlcxx . . $ GeminiClient#supportsUrl(dd54f9efb9153ea5).(const QUrlcxx . . $ QUrl#& url) const {
89 return url.schemecxx . . $ QUrl#scheme(6ef7b6c27b00b43d).() ==cxx . . $ `operator==`(361382e1f96e31f0). QL1Scxx . . $ `src/librssguard/definitions/definitions.h:449:9`!("gemini");
90 }
91
92 bool GeminiClientcxx . . $ GeminiClient#::startRequestcxx . . $ GeminiClient#startRequest(cefe749ea8d0af37).(const QUrlcxx . . $ QUrl#& url, RequestOptionscxx . . $ GeminiClient#RequestOptions# options) {
93 if (!supportsUrlcxx . . $ GeminiClient#supportsUrl(dd54f9efb9153ea5).(url)) {
94 return false;
95 }
96
97 // qDebug() << "start request" << url;
98
99 if (m_socketcxx . . $ GeminiClient#m_socket..statecxx . . $ QAbstractSocket#state(626498656f2ff1ae).() != QTcpSocketcxx . . $ QTcpSocket#::UnconnectedStatecxx . . $ QAbstractSocket#UnconnectedState.) {
100 m_socketcxx . . $ GeminiClient#m_socket..disconnectFromHostcxx . . $ QSslSocket#disconnectFromHost(49f6e7a06ebc5aa8).();
101 m_socketcxx . . $ GeminiClient#m_socket..closecxx . . $ QSslSocket#close(49f6e7a06ebc5aa8).();
102
103 if (!m_socketcxx . . $ GeminiClient#m_socket..waitForDisconnectedcxx . . $ QSslSocket#waitForDisconnected(83c267b20bac841a).(1500)) {
104 return false;
105 }
106 }
107
108 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! requestStateChangecxx . . $ GeminiClient#requestStateChange(75300df2abd8e70).(RequestStatecxx . . $ GeminiClient#RequestState#::Startedcxx . . $ GeminiClient#RequestState#Started.);
109
110 m_inErrorStatecxx . . $ GeminiClient#m_inErrorState. = false;
111 options = options;
112
113 QSslConfigurationcxx . . $ QSslConfiguration# ssl_config = m_socketcxx . . $ GeminiClient#m_socket..sslConfigurationcxx . . $ QSslSocket#sslConfiguration(7f3939866bbdae83).();
114 ssl_config.setProtocolcxx . . $ QSslConfiguration#setProtocol(fa89e92ed34b18f9).(QSslcxx . . $ QSsl/::TlsV1_2OrLatercxx . . $ QSsl/TlsV1_2OrLater.);
115
116 /*
117 if (not kristall::globals().trust.gemini.enable_ca)
118 ssl_config.setCaCertificates(QList<QSslCertificate>{});
119 else
120 */
121
122 ssl_config.setCaCertificatescxx . . $ QSslConfiguration#setCaCertificates(69444c4d46b7c5bb).(QSslConfigurationcxx . . $ QSslConfiguration#::systemCaCertificatescxx . . $ QSslConfiguration#systemCaCertificates(94f8a904b649c236).());
123
124 /*
125 */
126
127 m_socketcxx . . $ GeminiClient#m_socket..setSslConfigurationcxx . . $ QSslSocket#setSslConfiguration(6a58e5fb2f85652c).(ssl_config);
128 m_socketcxx . . $ GeminiClient#m_socket..connectToHostEncryptedcxx . . $ QSslSocket#connectToHostEncrypted(b060889367adb1f4).(url.hostcxx . . $ QUrl#host(9d7420bec8bfe6c9).(), url.portcxx . . $ QUrl#port(7ccb52b1bfe01045).(1965));
129
130 m_buffercxx . . $ GeminiClient#m_buffer..clearcxx . . $ QByteArray#clear(49f6e7a06ebc5aa8).();
131 m_bodycxx . . $ GeminiClient#m_body..clearcxx . . $ QByteArray#clear(49f6e7a06ebc5aa8).();
132 m_isReceivingBodycxx . . $ GeminiClient#m_isReceivingBody. = false;
133 m_suppressSocketTlsErrorscxx . . $ GeminiClient#m_suppressSocketTlsErrors. = true;
134
135 if (!m_socketcxx . . $ GeminiClient#m_socket..isOpencxx . . $ QIODevice#isOpen(50ce9a9e25b4a850).()) {
136 return false;
137 }
138
139 m_targetUrlcxx . . $ GeminiClient#m_targetUrl. =cxx . . $ QUrl#`operator=`(5236b30dc3aa36dd). url;
140 m_mimeTypecxx . . $ GeminiClient#m_mimeType. =cxx . . $ QString#`operator=`(d02845eef0c33901). "<invalid>";
141
142 return true;
143 }
144
145 bool GeminiClientcxx . . $ GeminiClient#::inProgresscxx . . $ GeminiClient#inProgress(50ce9a9e25b4a850).() const {
146 return m_socketcxx . . $ GeminiClient#m_socket..statecxx . . $ QAbstractSocket#state(626498656f2ff1ae).() != QTcpSocketcxx . . $ QTcpSocket#::UnconnectedStatecxx . . $ QAbstractSocket#UnconnectedState.;
147 }
148
149 bool GeminiClientcxx . . $ GeminiClient#::cancelRequestcxx . . $ GeminiClient#cancelRequest(c9857a73d68e59ba).() {
150 // qDebug() << "cancel request" << isInProgress();
151 if (inProgresscxx . . $ GeminiClient#inProgress(50ce9a9e25b4a850).()) {
152 m_isReceivingBodycxx . . $ GeminiClient#m_isReceivingBody. = false;
153 m_socketcxx . . $ GeminiClient#m_socket..disconnectFromHostcxx . . $ QSslSocket#disconnectFromHost(49f6e7a06ebc5aa8).();
154 m_buffercxx . . $ GeminiClient#m_buffer..clearcxx . . $ QByteArray#clear(49f6e7a06ebc5aa8).();
155 m_bodycxx . . $ GeminiClient#m_body..clearcxx . . $ QByteArray#clear(49f6e7a06ebc5aa8).();
156
157 if (m_socketcxx . . $ GeminiClient#m_socket..statecxx . . $ QAbstractSocket#state(626498656f2ff1ae).() != QTcpSocketcxx . . $ QTcpSocket#::UnconnectedStatecxx . . $ QAbstractSocket#UnconnectedState.) {
158 m_socketcxx . . $ GeminiClient#m_socket..disconnectFromHostcxx . . $ QSslSocket#disconnectFromHost(49f6e7a06ebc5aa8).();
159 }
160
161 m_socketcxx . . $ GeminiClient#m_socket..waitForDisconnectedcxx . . $ QSslSocket#waitForDisconnected(83c267b20bac841a).(500);
162 m_socketcxx . . $ GeminiClient#m_socket..closecxx . . $ QSslSocket#close(49f6e7a06ebc5aa8).();
163
164 bool success = !inProgresscxx . . $ GeminiClient#inProgress(50ce9a9e25b4a850).();
165
166 // qDebug() << "cancel success" << success;
167
168 return success;
169 }
170 else {
171 return true;
172 }
173 }
174
175 bool GeminiClientcxx . . $ GeminiClient#::enableClientCertificatecxx . . $ GeminiClient#enableClientCertificate(1b1dd513197a4d59).(const CryptoIdentitycxx . . $ CryptoIdentity#& ident) {
176 m_socketcxx . . $ GeminiClient#m_socket..setLocalCertificatecxx . . $ QSslSocket#setLocalCertificate(78ac2807b13824e1).(ident.certificatecxx . . $ CryptoIdentity#certificate.);
177 m_socketcxx . . $ GeminiClient#m_socket..setPrivateKeycxx . . $ QSslSocket#setPrivateKey(82be7d26eb6bbb34).(ident.private_keycxx . . $ CryptoIdentity#private_key.);
178
179 return true;
180 }
181
182 void GeminiClientcxx . . $ GeminiClient#::disableClientCertificatecxx . . $ GeminiClient#disableClientCertificate(49f6e7a06ebc5aa8).() {
183 m_socketcxx . . $ GeminiClient#m_socket..setLocalCertificatecxx . . $ QSslSocket#setLocalCertificate(78ac2807b13824e1).(QSslCertificatecxx . . $ QSslCertificate#QSslCertificate(b83b1b90e5eda3d7).{});
184 m_socketcxx . . $ GeminiClient#m_socket..setPrivateKeycxx . . $ QSslSocket#setPrivateKey(82be7d26eb6bbb34).(QSslKeycxx . . $ QSslKey#QSslKey(49f6e7a06ebc5aa8).{});
185 }
186
187 void GeminiClientcxx . . $ GeminiClient#::emitNetworkErrorcxx . . $ GeminiClient#emitNetworkError(42ce75a38071931f).(QAbstractSocketcxx . . $ QAbstractSocket#::SocketErrorcxx . . $ QAbstractSocket#SocketError# error_code, const QStringcxx . . $ QString#& textual_description) {
188 NetworkErrorcxx . . $ GeminiClient#NetworkError# network_error = UnknownErrorcxx . . $ GeminiClient#UnknownError.;
189
190 switch (error_code) {
191 case QAbstractSocketcxx . . $ QAbstractSocket#::ConnectionRefusedErrorcxx . . $ QAbstractSocket#ConnectionRefusedError.:
192 network_error = ConnectionRefusedcxx . . $ GeminiClient#ConnectionRefused.;
193 break;
194
195 case QAbstractSocketcxx . . $ QAbstractSocket#::HostNotFoundErrorcxx . . $ QAbstractSocket#HostNotFoundError.:
196 network_error = HostNotFoundcxx . . $ GeminiClient#HostNotFound.;
197 break;
198
199 case QAbstractSocketcxx . . $ QAbstractSocket#::SocketTimeoutErrorcxx . . $ QAbstractSocket#SocketTimeoutError.:
200 network_error = Timeoutcxx . . $ GeminiClient#Timeout.;
201 break;
202
203 case QAbstractSocketcxx . . $ QAbstractSocket#::SslHandshakeFailedErrorcxx . . $ QAbstractSocket#SslHandshakeFailedError.:
204 network_error = TlsFailurecxx . . $ GeminiClient#TlsFailure.;
205 break;
206
207 case QAbstractSocketcxx . . $ QAbstractSocket#::SslInternalErrorcxx . . $ QAbstractSocket#SslInternalError.:
208 network_error = TlsFailurecxx . . $ GeminiClient#TlsFailure.;
209 break;
210
211 case QAbstractSocketcxx . . $ QAbstractSocket#::SslInvalidUserDataErrorcxx . . $ QAbstractSocket#SslInvalidUserDataError.:
212 network_error = TlsFailurecxx . . $ GeminiClient#TlsFailure.;
213 break;
214
215 default:
216 qDebugcxx . . $ `<external>/7280663963939302026/qlogging.h:168:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "unhandled network error:" <<cxx . . $ `operator<<`(614cb1c17b4b6104). error_code;
217 break;
218 }
219
220 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(network_error, textual_description);
221 }
222
223 void GeminiClientcxx . . $ GeminiClient#::socketEncryptedcxx . . $ GeminiClient#socketEncrypted(49f6e7a06ebc5aa8).() {
224 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! hostCertificateLoadedcxx . . $ GeminiClient#hostCertificateLoaded(78ac2807b13824e1).(m_socketcxx . . $ GeminiClient#m_socket..peerCertificatecxx . . $ QSslSocket#peerCertificate(e568f5a5e352bf3c).());
225
226 QStringcxx . . $ QString# request = m_targetUrlcxx . . $ GeminiClient#m_targetUrl..toStringcxx . . $ QUrl#toString(632475ebea3355f1).(QUrlcxx . . $ QUrlTwoFlags#QUrlTwoFlags(69eed69a60cddb2f).::FormattingOptionscxx . . $ QUrl#FormattingOptions#(QUrlcxx . . $ QUrl#::FullyEncodedcxx . . $ QUrl#FullyEncoded.)) +cxx . . $ operator+(adfbdceb504720ce). QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("\r\n");
227
228 QByteArraycxx . . $ QByteArray# request_bytes = request.toUtf8cxx . . $ QString#toUtf8(ef52b713090bc85a).();
229
230 qint64cxx . . $ qint64# offset = 0;
231
232 while (offset < request_bytes.sizecxx . . $ QByteArray#size(6b0412d51016192f).()) {
233 const auto len = m_socketcxx . . $ GeminiClient#m_socket..writecxx . . $ QIODevice#write(93d4069f65218ea4).(request_bytes.constDatacxx . . $ QByteArray#constData(ba32b354807b2b81).() + offset, request_bytes.sizecxx . . $ QByteArray#size(6b0412d51016192f).() - offset);
234
235 if (len <= 0) {
236 m_socketcxx . . $ GeminiClient#m_socket..closecxx . . $ QSslSocket#close(49f6e7a06ebc5aa8).();
237 return;
238 }
239
240 offset += len;
241 }
242 }
243
244 void GeminiClientcxx . . $ GeminiClient#::socketReadyReadcxx . . $ GeminiClient#socketReadyRead(49f6e7a06ebc5aa8).() {
245 if (m_inErrorStatecxx . . $ GeminiClient#m_inErrorState.) {
246 return;
247 }
248
249 QByteArraycxx . . $ QByteArray# response = m_socketcxx . . $ GeminiClient#m_socket..readAllcxx . . $ QIODevice#readAll(b3c286cec66e09f4).();
250
251 if (m_isReceivingBodycxx . . $ GeminiClient#m_isReceivingBody.) {
252 m_bodycxx . . $ GeminiClient#m_body..appendcxx . . $ QByteArray#append(85c7caed82076bbb).(response);
253
254 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! requestProgresscxx . . $ GeminiClient#requestProgress(35cb52607f6af42f).(m_bodycxx . . $ GeminiClient#m_body..sizecxx . . $ QByteArray#size(6b0412d51016192f).());
255 }
256 else {
257 for (int i = 0; i < response.sizecxx . . $ QByteArray#size(6b0412d51016192f).(); i++) {
258 if (response[cxx . . $ QByteArray#`operator[]`(78168207d1016c17).i] == '\n') {
259 m_buffercxx . . $ GeminiClient#m_buffer..appendcxx . . $ QByteArray#append(e241a888293f0e7a).(response.datacxx . . $ QByteArray#data(41208ce6ca65dd58).(), i);
260 m_bodycxx . . $ GeminiClient#m_body..appendcxx . . $ QByteArray#append(e241a888293f0e7a).(response.datacxx . . $ QByteArray#data(41208ce6ca65dd58).() + i + 1, response.sizecxx . . $ QByteArray#size(6b0412d51016192f).() - i - 1);
261
262 // "XY " <META> <CR> <LF>
263 if (m_buffercxx . . $ GeminiClient#m_buffer..sizecxx . . $ QByteArray#size(6b0412d51016192f).() < 4) { // we allow an empty <META>
264 m_socketcxx . . $ GeminiClient#m_socket..closecxx . . $ QSslSocket#close(49f6e7a06ebc5aa8).();
265
266 qDebugcxx . . $ `<external>/7280663963939302026/qlogging.h:168:9`!() <<cxx . . $ QDebug#`operator<<`(1387ba1672043913). m_buffercxx . . $ GeminiClient#m_buffer.;
267
268 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(ProtocolViolationcxx . . $ GeminiClient#ProtocolViolation., trcxx . . $ GeminiClient#tr(75d9f1c324b4579d).("Line is too short for valid protocol"));
269
270 return;
271 }
272 if (m_buffercxx . . $ GeminiClient#m_buffer..sizecxx . . $ QByteArray#size(6b0412d51016192f).() >= 1200) {
273 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(ProtocolViolationcxx . . $ GeminiClient#ProtocolViolation., trcxx . . $ GeminiClient#tr(75d9f1c324b4579d).("response too large!"));
274
275 m_socketcxx . . $ GeminiClient#m_socket..closecxx . . $ QSslSocket#close(49f6e7a06ebc5aa8).();
276 }
277 if (m_buffercxx . . $ GeminiClient#m_buffer.[cxx . . $ QByteArray#`operator[]`(78168207d1016c17).m_buffercxx . . $ GeminiClient#m_buffer..sizecxx . . $ QByteArray#size(6b0412d51016192f).() - 1] != '\r') {
278 m_socketcxx . . $ GeminiClient#m_socket..closecxx . . $ QSslSocket#close(49f6e7a06ebc5aa8).();
279
280 qDebugcxx . . $ `<external>/7280663963939302026/qlogging.h:168:9`!() <<cxx . . $ QDebug#`operator<<`(1387ba1672043913). m_buffercxx . . $ GeminiClient#m_buffer.;
281
282 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(ProtocolViolationcxx . . $ GeminiClient#ProtocolViolation., trcxx . . $ GeminiClient#tr(75d9f1c324b4579d).("Line does not end with <CR> <LF>"));
283
284 return;
285 }
286 if (!stdcxx . . $ std/::isdigitcxx . . $ std/isdigit(a1851578aea3f541).(m_buffercxx . . $ GeminiClient#m_buffer.[cxx . . $ QByteArray#`operator[]`(78168207d1016c17).0])) {
287 m_socketcxx . . $ GeminiClient#m_socket..closecxx . . $ QSslSocket#close(49f6e7a06ebc5aa8).();
288
289 qDebugcxx . . $ `<external>/7280663963939302026/qlogging.h:168:9`!() <<cxx . . $ QDebug#`operator<<`(1387ba1672043913). m_buffercxx . . $ GeminiClient#m_buffer.;
290
291 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(ProtocolViolationcxx . . $ GeminiClient#ProtocolViolation., trcxx . . $ GeminiClient#tr(75d9f1c324b4579d).("First character is not a digit."));
292
293 return;
294 }
295 if (!stdcxx . . $ std/::isdigitcxx . . $ std/isdigit(a1851578aea3f541).(m_buffercxx . . $ GeminiClient#m_buffer.[cxx . . $ QByteArray#`operator[]`(78168207d1016c17).1])) {
296 m_socketcxx . . $ GeminiClient#m_socket..closecxx . . $ QSslSocket#close(49f6e7a06ebc5aa8).();
297
298 qDebugcxx . . $ `<external>/7280663963939302026/qlogging.h:168:9`!() <<cxx . . $ QDebug#`operator<<`(1387ba1672043913). m_buffercxx . . $ GeminiClient#m_buffer.;
299
300 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(ProtocolViolationcxx . . $ GeminiClient#ProtocolViolation., trcxx . . $ GeminiClient#tr(75d9f1c324b4579d).("Second character is not a digit."));
301
302 return;
303 }
304
305 // TODO: Implement stricter version
306 // if(buffer[2] != ' ') {
307 if (!stdcxx . . $ std/::isspacecxx . . $ std/isspace(a1851578aea3f541).(m_buffercxx . . $ GeminiClient#m_buffer.[cxx . . $ QByteArray#`operator[]`(78168207d1016c17).2])) {
308 m_socketcxx . . $ GeminiClient#m_socket..closecxx . . $ QSslSocket#close(49f6e7a06ebc5aa8).();
309
310 qDebugcxx . . $ `<external>/7280663963939302026/qlogging.h:168:9`!() <<cxx . . $ QDebug#`operator<<`(1387ba1672043913). m_buffercxx . . $ GeminiClient#m_buffer.;
311
312 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(ProtocolViolationcxx . . $ GeminiClient#ProtocolViolation., trcxx . . $ GeminiClient#tr(75d9f1c324b4579d).("Third character is not a space."));
313
314 return;
315 }
316
317 QStringcxx . . $ QString# meta = QStringcxx . . $ QString#::fromUtf8cxx . . $ QString#fromUtf8(c6a27c21e014c0ef).(m_buffercxx . . $ GeminiClient#m_buffer..datacxx . . $ QByteArray#data(41208ce6ca65dd58).() + 3, m_buffercxx . . $ GeminiClient#m_buffer..sizecxx . . $ QByteArray#size(6b0412d51016192f).() - 4);
318
319 int primary_code = m_buffercxx . . $ GeminiClient#m_buffer.[cxx . . $ QByteArray#`operator[]`(78168207d1016c17).0] - '0';
320 int secondary_code = m_buffercxx . . $ GeminiClient#m_buffer.[cxx . . $ QByteArray#`operator[]`(78168207d1016c17).1] - '0';
321
322 qDebugcxx . . $ `<external>/7280663963939302026/qlogging.h:168:9`!() <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). primary_code <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). secondary_code <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). meta;
323
324 // We don't need to receive any data after that.
325 if (primary_code != 2) {
326 m_socketcxx . . $ GeminiClient#m_socket..closecxx . . $ QSslSocket#close(49f6e7a06ebc5aa8).();
327 }
328
329 switch (primary_code) {
330 case 1: // requesting input
331 switch (secondary_code) {
332 case 1:
333 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! inputRequiredcxx . . $ GeminiClient#inputRequired(37c160c81b6367f7).(meta, true);
334 break;
335
336 case 0:
337 default:
338 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! inputRequiredcxx . . $ GeminiClient#inputRequired(37c160c81b6367f7).(meta, false);
339 }
340
341 return;
342
343 case 2: // success
344 m_isReceivingBodycxx . . $ GeminiClient#m_isReceivingBody. = true;
345 m_mimeTypecxx . . $ GeminiClient#m_mimeType. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). meta;
346
347 return;
348
349 case 3: { // redirect
350 QUrlcxx . . $ QUrl# new_urlcxx . . $ QUrl#QUrl(ea1f3831e370f1cb).(meta);
351 if (new_url.isValidcxx . . $ QUrl#isValid(50ce9a9e25b4a850).()) {
352 if (new_url.isRelativecxx . . $ QUrl#isRelative(50ce9a9e25b4a850).()) {
353 new_url =cxx . . $ QUrl#`operator=`(590d023fc9cd4b2d). m_targetUrlcxx . . $ GeminiClient#m_targetUrl..resolvedcxx . . $ QUrl#resolved(12b57030d3a86ba7).(new_url);
354 }
355
356 assertcxx . . $ `/usr/include/assert.h:50:10`!(not new_url.isRelative());
357
358 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! redirectedcxx . . $ GeminiClient#redirected(61e5b15e0cd21ddb).(new_url, (secondary_code == 1));
359 }
360 else {
361 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(ProtocolViolationcxx . . $ GeminiClient#ProtocolViolation., trcxx . . $ GeminiClient#tr(75d9f1c324b4579d).("Invalid URL for redirection!"));
362 }
363
364 return;
365 }
366
367 case 4: { // temporary failure
368 NetworkErrorcxx . . $ GeminiClient#NetworkError# type = UnknownErrorcxx . . $ GeminiClient#UnknownError.;
369
370 switch (secondary_code) {
371 case 1:
372 type = InternalServerErrorcxx . . $ GeminiClient#InternalServerError.;
373 break;
374
375 case 2:
376 type = InternalServerErrorcxx . . $ GeminiClient#InternalServerError.;
377 break;
378
379 case 3:
380 type = InternalServerErrorcxx . . $ GeminiClient#InternalServerError.;
381 break;
382
383 case 4:
384 type = UnknownErrorcxx . . $ GeminiClient#UnknownError.;
385 break;
386 }
387
388 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(type, meta);
389
390 return;
391 }
392
393 case 5: { // permanent failure
394 NetworkErrorcxx . . $ GeminiClient#NetworkError# type = UnknownErrorcxx . . $ GeminiClient#UnknownError.;
395
396 switch (secondary_code) {
397 case 1:
398 type = ResourceNotFoundcxx . . $ GeminiClient#ResourceNotFound.;
399 break;
400
401 case 2:
402 type = ResourceNotFoundcxx . . $ GeminiClient#ResourceNotFound.;
403 break;
404
405 case 3:
406 type = ProxyRequestcxx . . $ GeminiClient#ProxyRequest.;
407 break;
408
409 case 9:
410 type = BadRequestcxx . . $ GeminiClient#BadRequest.;
411 break;
412 }
413
414 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(type, meta);
415
416 return;
417 }
418
419 case 6: // client certificate required
420 switch (secondary_code) {
421 case 0:
422 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! certificateRequiredcxx . . $ GeminiClient#certificateRequired(3520e46b33348bf6).(meta);
423 return;
424
425 case 1:
426 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(Unauthorizedcxx . . $ GeminiClient#Unauthorized., meta);
427 return;
428
429 default:
430 case 2:
431 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(InvalidClientCertificatecxx . . $ GeminiClient#InvalidClientCertificate., meta);
432 return;
433 }
434
435 return;
436
437 default:
438 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(ProtocolViolationcxx . . $ GeminiClient#ProtocolViolation., trcxx . . $ GeminiClient#tr(75d9f1c324b4579d).("Unspecified status code used!"));
439
440 return;
441 }
442
443 assertcxx . . $ `/usr/include/assert.h:50:10`!(false && "unreachable");
444 }
445 }
446 if ((m_buffercxx . . $ GeminiClient#m_buffer..sizecxx . . $ QByteArray#size(6b0412d51016192f).() + response.sizecxx . . $ QByteArray#size(6b0412d51016192f).()) >= 1200) {
447 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(ProtocolViolationcxx . . $ GeminiClient#ProtocolViolation., trcxx . . $ GeminiClient#tr(75d9f1c324b4579d).("META too large!"));
448
449 m_socketcxx . . $ GeminiClient#m_socket..closecxx . . $ QSslSocket#close(49f6e7a06ebc5aa8).();
450 }
451
452 m_buffercxx . . $ GeminiClient#m_buffer..appendcxx . . $ QByteArray#append(85c7caed82076bbb).(response);
453 }
454 }
455
456 void GeminiClientcxx . . $ GeminiClient#::socketDisconnectedcxx . . $ GeminiClient#socketDisconnected(49f6e7a06ebc5aa8).() {
457 if (m_isReceivingBodycxx . . $ GeminiClient#m_isReceivingBody. && !m_inErrorStatecxx . . $ GeminiClient#m_inErrorState.) {
458 m_bodycxx . . $ GeminiClient#m_body..appendcxx . . $ QByteArray#append(85c7caed82076bbb).(m_socketcxx . . $ GeminiClient#m_socket..readAllcxx . . $ QIODevice#readAll(b3c286cec66e09f4).());
459 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! requestCompletecxx . . $ GeminiClient#requestComplete(84d6cb2703da46aa).(m_bodycxx . . $ GeminiClient#m_body., m_mimeTypecxx . . $ GeminiClient#m_mimeType.);
460 }
461 }
462
463 void GeminiClientcxx . . $ GeminiClient#::sslErrorscxx . . $ GeminiClient#sslErrors(a6189817b1df8092).(const QListcxx . . $ QList#<QSslErrorcxx . . $ QSslError#>& errors) {
464 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! hostCertificateLoadedcxx . . $ GeminiClient#hostCertificateLoaded(78ac2807b13824e1).(m_socketcxx . . $ GeminiClient#m_socket..peerCertificatecxx . . $ QSslSocket#peerCertificate(e568f5a5e352bf3c).());
465
466 if (m_optionscxx . . $ GeminiClient#m_options. & IgnoreTlsErrorscxx . . $ GeminiClient#IgnoreTlsErrors.) {
467 m_socketcxx . . $ GeminiClient#m_socket..ignoreSslErrorscxx . . $ QSslSocket#ignoreSslErrors(a6189817b1df8092).(errors);
468 return;
469 }
470
471 QListcxx . . $ QList#<QSslErrorcxx . . $ QSslError#> remaining_errors = errors;
472 QListcxx . . $ QList#<QSslErrorcxx . . $ QSslError#> ignored_errorscxx . . $ QList#QList(ced63f7c635d850d).;
473
474 int i = 0;
475 while (i < remaining_errors.sizecxx . . $ QList#size(6b0412d51016192f).()) {
476 const auto& err = remaining_errors.atcxx . . $ QList#at(c7965f769b39929).(i);
477
478 bool ignore = false;
479
480 /*
481 */
482 ignore = true;
483 /*
484 if (SslTrust::isTrustRelated(err.error())) {
485 switch (kristall::globals().trust.gemini.getTrust(target_url, socket.peerCertificate())) {
486 case SslTrust::Trusted:
487 ignore = true;
488 break;
489 case SslTrust::Untrusted:
490 this->is_error_state = true;
491 this->suppress_socket_tls_error = true;
492 emit this->networkError(UntrustedHost, toFingerprintString(socket.peerCertificate()));
493 return;
494 case SslTrust::Mistrusted:
495 this->is_error_state = true;
496 this->suppress_socket_tls_error = true;
497 emit this->networkError(MistrustedHost, toFingerprintString(socket.peerCertificate()));
498 return;
499 }
500 }
501
502 else */
503 if (err.errorcxx . . $ QSslError#error(128c2c7378ec24e1).() == QSslErrorcxx . . $ QSslError#::UnableToVerifyFirstCertificatecxx . . $ QSslError#UnableToVerifyFirstCertificate.) {
504 ignore = true;
505 }
506
507 if (ignore) {
508 ignored_errors.appendcxx . . $ QList#append(200d2dc08238a4ed).(err);
509 remaining_errors.removeAtcxx . . $ QList#removeAt(35cb52607f6af42f).(0);
510 }
511 else {
512 i += 1;
513 }
514 }
515
516 m_socketcxx . . $ GeminiClient#m_socket..ignoreSslErrorscxx . . $ QSslSocket#ignoreSslErrors(a6189817b1df8092).(ignored_errors);
517
518 qDebugcxx . . $ `<external>/7280663963939302026/qlogging.h:168:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "ignoring" <<cxx . . $ QDebug#`operator<<`(f416a4561cb9723d). ignored_errors.sizecxx . . $ QList#size(6b0412d51016192f).() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "out of" <<cxx . . $ QDebug#`operator<<`(f416a4561cb9723d). errors.sizecxx . . $ QList#size(6b0412d51016192f).();
519
520 for (const auto& error : remaining_errors) {
521 qWarningcxx . . $ `<external>/7280663963939302026/qlogging.h:170:9`!() <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). int(error.errorcxx . . $ QSslError#error(128c2c7378ec24e1).()) <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). error.errorStringcxx . . $ QSslError#errorString(6ef7b6c27b00b43d).();
522 }
523
524 if (remaining_errors.sizecxx . . $ QList#size(6b0412d51016192f).() > 0) {
525 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! networkErrorcxx . . $ GeminiClient#networkError(bf7ef9a2ade9db5c).(TlsFailurecxx . . $ GeminiClient#TlsFailure., remaining_errors.firstcxx . . $ QList#first(19b2b6f17af048b).().errorStringcxx . . $ QSslError#errorString(6ef7b6c27b00b43d).());
526 }
527 }
528
529 void GeminiClientcxx . . $ GeminiClient#::socketErrorcxx . . $ GeminiClient#socketError(c866838463bd22b).(QAbstractSocketcxx . . $ QAbstractSocket#::SocketErrorcxx . . $ QAbstractSocket#SocketError# socketError) {
530 // When remote host closes TLS session, the client closes the socket.
531 // This is more sane then erroring out here as it's a perfectly legal
532 // state and we know the TLS connection has ended.
533 if (socketError == QAbstractSocketcxx . . $ QAbstractSocket#::RemoteHostClosedErrorcxx . . $ QAbstractSocket#RemoteHostClosedError.) {
534 m_socketcxx . . $ GeminiClient#m_socket..closecxx . . $ QSslSocket#close(49f6e7a06ebc5aa8).();
535 return;
536 }
537
538 m_inErrorStatecxx . . $ GeminiClient#m_inErrorState. = true;
539
540 if (!m_suppressSocketTlsErrorscxx . . $ GeminiClient#m_suppressSocketTlsErrors.) {
541 emitNetworkErrorcxx . . $ GeminiClient#emitNetworkError(42ce75a38071931f).(socketError, m_socketcxx . . $ GeminiClient#m_socket..errorStringcxx . . $ QIODevice#errorString(6ef7b6c27b00b43d).());
542 }
543 }
544
545 QUrlcxx . . $ QUrl# GeminiClientcxx . . $ GeminiClient#::targetUrlcxx . . $ GeminiClient#targetUrl(36d9834fe7321282).() const {
546 return m_targetUrlcxx . . $ QUrl#QUrl(9a9d0cfaabb61200).;
547 }