Debian Codegraph @

online-accounts-plugins/lib/LomiriOnlineAccountsPlugin/loopback-server.cpp

raw symbols SCIP
1 /*
2 * This file is part of libAuthentication
3 *
4 * Copyright (C) 2017-2020 Alberto Mardegan <[email protected]>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * version 2.1 as published by the Free Software Foundation.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 */
20
21 #include "loopback-server.h"cxx . . $ `<file>/online-accounts-plugins/lib/LomiriOnlineAccountsPlugin/loopback-server.h`/
22
23 #include <QCoreApplication>
24 #include <QDebug>
25 #include <QTcpServer>
26 #include <QTcpSocket>
27
28 using namespace OnlineAccountsPlugin;
29
30 namespace OnlineAccountsPlugincxx . . $ OnlineAccountsPlugin/ {
31
32 class LoopbackServerPrivatecxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#: public QTcpServercxx . . $ QTcpServer#
33 {
34 Q_OBJECTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:170:9`!
35 Q_DECLARE_PUBLICcxx . . $ `<external>/15045578679651060896/qglobal.h:1172:9`!(LoopbackServer)
36
37 public:
38 LoopbackServerPrivatecxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#LoopbackServerPrivate(f4b691f4ce16aa7f).(LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer# *q);
39 ~cxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#`~LoopbackServerPrivate`(ced63f7c635d850d).LoopbackServerPrivatecxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#();
40
41 bool listencxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#listen(3c978dac0e5ee2ad).(uint16_tcxx . . $ uint16_t# port);
42 void respondcxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#respond(214e24de1d575aa3).(QTcpSocketcxx . . $ QTcpSocket# *socket);
43
44 private Q_SLOTScxx . . $ `<external>/1208926524888476972/qobjectdefs.h:92:10`!:
45 void onNewConnectioncxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#onNewConnection(49f6e7a06ebc5aa8).();
46 void onReadyReadcxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#onReadyRead(49f6e7a06ebc5aa8).();
47
48 private:
49 int m_portIncrementAttemptscxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_portIncrementAttempts.;
50 QByteArraycxx . . $ QByteArray# m_datacxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_data.;
51 QByteArraycxx . . $ QByteArray# m_servedHtmlcxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_servedHtml.;
52 LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer# *q_ptrcxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#q_ptr.;
53 };
54
55 } // namespace
56
57 LoopbackServerPrivatecxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#::LoopbackServerPrivatecxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#LoopbackServerPrivate(f4b691f4ce16aa7f).(LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer# *q):
58 m_portIncrementAttemptscxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_portIncrementAttempts.(0),
59 q_ptrcxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#q_ptr.(q)
60 {
61 QObjectcxx . . $ QObject#::connectcxx . . $ QObject#connect(835f87066c895669).(this, &QTcpServercxx . . $ QTcpServer#::newConnectioncxx . . $ QTcpServer#newConnection(49f6e7a06ebc5aa8).,
62 this, &LoopbackServerPrivatecxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#::onNewConnectioncxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#onNewConnection(49f6e7a06ebc5aa8).);
63
64 m_servedHtmlcxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_servedHtml. =cxx . . $ QByteArray#`operator=`(acee8257ca81216f).
65 QByteArrayLiteralcxx . . $ `<external>/11057416899157294643/qbytearray.h:146:11`!("<html><head><title>") +cxx . . $ operator+(49e2485dc0bda598).
66 qAppcxx . . $ `<external>/3955209949423095026/qcoreapplication.h:70:9`!->applicationNamecxx . . $ QCoreApplication#applicationName(4365c3963150523e).().toUtf8cxx . . $ QString#toUtf8(7c2073558a834e49).() +cxx . . $ operator+(49e2485dc0bda598).
67 QByteArrayLiteralcxx . . $ `<external>/11057416899157294643/qbytearray.h:146:11`!("</title></head><body>") +cxx . . $ operator+(49e2485dc0bda598).
68 QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).("Authentication completed; you can close this page "
69 "and go back to the application.").
70 toUtf8cxx . . $ QString#toUtf8(7c2073558a834e49).() +cxx . . $ operator+(49e2485dc0bda598).
71 QByteArrayLiteralcxx . . $ `<external>/11057416899157294643/qbytearray.h:146:11`!("</body></html>");
72 }
73
74 LoopbackServerPrivatecxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#::~cxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#`~LoopbackServerPrivate`(ced63f7c635d850d).LoopbackServerPrivatecxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#()
75 {
76 }
77
78 bool LoopbackServerPrivatecxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#::listencxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#listen(3c978dac0e5ee2ad).(uint16_tcxx . . $ uint16_t# port)
79 {
80 uint16_tcxx . . $ uint16_t# attempts = 0;
81
82 do {
83 bool ok = QTcpServercxx . . $ QTcpServer#::listencxx . . $ QTcpServer#listen(6fdb1d868b5163ab).(QHostAddresscxx . . $ QHostAddress#QHostAddress(87181e547927ba53).::Anycxx . . $ QHostAddress#Any.,
84 quint16cxx . . $ quint16#(port + attempts));
85 if (ok) return true;
86 } while (attempts++ < m_portIncrementAttemptscxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_portIncrementAttempts.);
87
88 return false;
89 }
90
91 void LoopbackServerPrivatecxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#::respondcxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#respond(214e24de1d575aa3).(QTcpSocketcxx . . $ QTcpSocket# *socket)
92 {
93 QByteArraycxx . . $ QByteArray# htmlSize = QStringcxx . . $ QString#::numbercxx . . $ QString#number(f4fd9db251ca774b).(m_servedHtmlcxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_servedHtml..sizecxx . . $ QByteArray#size(455f465bc33b4cdf).()).toUtf8cxx . . $ QString#toUtf8(7c2073558a834e49).();
94 QByteArraycxx . . $ QByteArray# replyMessage =
95 QByteArrayLiteralcxx . . $ `<external>/11057416899157294643/qbytearray.h:146:11`!("HTTP/1.0 200 OK \r\n"
96 "Content-Type: text/html; charset=\"utf-8\"\r\n"
97 "Content-Length: ") +cxx . . $ operator+(49e2485dc0bda598). htmlSize +cxx . . $ operator+(49e2485dc0bda598).
98 QByteArrayLiteralcxx . . $ `<external>/11057416899157294643/qbytearray.h:146:11`!("\r\n\r\n") +cxx . . $ operator+(49e2485dc0bda598).
99 m_servedHtmlcxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_servedHtml.;
100
101 socket->writecxx . . $ QIODevice#write(4ee2750a0be83987).(replyMessage);
102 }
103
104 void LoopbackServerPrivatecxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#::onNewConnectioncxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#onNewConnection(49f6e7a06ebc5aa8).()
105 {
106 QTcpSocketcxx . . $ QTcpSocket# *socket = nextPendingConnectioncxx . . $ QTcpServer#nextPendingConnection(3b0f0a12ef6ae0dd).();
107 Q_ASSERTcxx . . $ `<external>/15045578679651060896/qglobal.h:859:13`!(socket);
108 QObjectcxx . . $ QObject#::connectcxx . . $ QObject#connect(835f87066c895669).(socket, &QTcpSocketcxx . . $ QTcpSocket#::disconnectedcxx . . $ QAbstractSocket#disconnected(49f6e7a06ebc5aa8).,
109 socket, &QTcpSocketcxx . . $ QTcpSocket#::deleteLatercxx . . $ QObject#deleteLater(49f6e7a06ebc5aa8).);
110 QObjectcxx . . $ QObject#::connectcxx . . $ QObject#connect(835f87066c895669).(socket, &QTcpSocketcxx . . $ QTcpSocket#::readyReadcxx . . $ QIODevice#readyRead(49f6e7a06ebc5aa8).,
111 this, &LoopbackServerPrivatecxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#::onReadyReadcxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#onReadyRead(49f6e7a06ebc5aa8).);
112 }
113
114 void LoopbackServerPrivatecxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#::onReadyReadcxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#onReadyRead(49f6e7a06ebc5aa8).()
115 {
116 Q_Qcxx . . $ `<external>/15045578679651060896/qglobal.h:1178:9`!(LoopbackServer);
117
118 QTcpSocketcxx . . $ QTcpSocket# *socket = qobject_castcxx . . $ qobject_cast(c988cfc0ca08742e).<QTcpSocketcxx . . $ QTcpSocket#*>(sendercxx . . $ QObject#sender(2dbb680a34285c44).());
119 Q_ASSERTcxx . . $ `<external>/15045578679651060896/qglobal.h:859:13`!(socket);
120
121 m_datacxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_data. +=cxx . . $ QByteArray#`operator+=`(85c7caed82076bbb). socket->readAllcxx . . $ QIODevice#readAll(b3c286cec66e09f4).();
122 int lineLength = m_datacxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_data..indexOfcxx . . $ QByteArray#indexOf(a8c99bbe05347276).('\r');
123 if (lineLength < 0) {
124 /* Not all data has been received; will get more later */
125 return;
126 }
127 QByteArraycxx . . $ QByteArray# firstLine = m_datacxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_data..leftcxx . . $ QByteArray#left(1e245adf2d5d15b2).(lineLength);
128 QListcxx . . $ QList#<QByteArraycxx . . $ QByteArray#> parts = firstLine.splitcxx . . $ QByteArray#split(7e7c4c9f9d7ac60e).(' ');
129 if (parts.countcxx . . $ QList#count(455f465bc33b4cdf).() >= 2) {
130 QStringcxx . . $ QString# path = QStringcxx . . $ QString#::fromUtf8cxx . . $ QString#fromUtf8(4e15edac36d215be).(parts[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).1]);
131 QUrlcxx . . $ QUrl# urlcxx . . $ QUrl#QUrl(ea1f3831e370f1cb).(QStringcxx . . $ QString#::fromLatin1cxx . . $ QString#fromLatin1(5ac70cc0fa2a874e).("http://localhost:%1%2").
132 argcxx . . $ QString#arg(ba69ea7f5cd360b4).(serverPortcxx . . $ QTcpServer#serverPort(72085aa11f4b6e09).()).argcxx . . $ QString#arg(bc823072288cbbb5).(path));
133 Q_EMITcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:95:10`! q->visitedcxx . . $ OnlineAccountsPlugin/LoopbackServer#visited(37355d2f77053a23).(url);
134 }
135
136 respondcxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#respond(214e24de1d575aa3).(socket);
137 socket->disconnectFromHostcxx . . $ QAbstractSocket#disconnectFromHost(49f6e7a06ebc5aa8).();
138 }
139
140 LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer#::LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer#LoopbackServer(749de1b6ae65bddd).(QObjectcxx . . $ QObject# *parent):
141 QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(parent),
142 d_ptrcxx . . $ OnlineAccountsPlugin/LoopbackServer#d_ptr.(new LoopbackServerPrivatecxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#LoopbackServerPrivate(f4b691f4ce16aa7f).(this))
143 {
144 }
145
146 LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer#::~cxx . . $ OnlineAccountsPlugin/LoopbackServer#`~LoopbackServer`(ced63f7c635d850d).LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer#()
147 {
148 }
149
150 bool LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer#::listencxx . . $ OnlineAccountsPlugin/LoopbackServer#listen(3c978dac0e5ee2ad).(uint16_tcxx . . $ uint16_t# port)
151 {
152 Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(LoopbackServer);
153
154 bool ok = d->listencxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#listen(3c978dac0e5ee2ad).(port);
155
156 Q_EMITcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:95:10`! callbackUrlChangedcxx . . $ OnlineAccountsPlugin/LoopbackServer#callbackUrlChanged(49f6e7a06ebc5aa8).();
157
158 return ok;
159 }
160
161 void LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer#::closecxx . . $ OnlineAccountsPlugin/LoopbackServer#close(49f6e7a06ebc5aa8).()
162 {
163 Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(LoopbackServer);
164 d->closecxx . . $ QTcpServer#close(49f6e7a06ebc5aa8).();
165
166 Q_EMITcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:95:10`! callbackUrlChangedcxx . . $ OnlineAccountsPlugin/LoopbackServer#callbackUrlChanged(49f6e7a06ebc5aa8).();
167 }
168
169 uint16_tcxx . . $ uint16_t# LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer#::portcxx . . $ OnlineAccountsPlugin/LoopbackServer#port(72085aa11f4b6e09).() const
170 {
171 Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const LoopbackServer);
172 return d->serverPortcxx . . $ QTcpServer#serverPort(72085aa11f4b6e09).();
173 }
174
175 void LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer#::setPortIncrementAttemptscxx . . $ OnlineAccountsPlugin/LoopbackServer#setPortIncrementAttempts(d4f767463ce0a6b3).(int maxAttempts)
176 {
177 Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(LoopbackServer);
178 if (d->m_portIncrementAttemptscxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_portIncrementAttempts. == maxAttempts) return;
179 d->m_portIncrementAttemptscxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_portIncrementAttempts. = maxAttempts;
180 Q_EMITcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:95:10`! portIncrementAttemptsChangedcxx . . $ OnlineAccountsPlugin/LoopbackServer#portIncrementAttemptsChanged(49f6e7a06ebc5aa8).();
181 }
182
183 int LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer#::portIncrementAttemptscxx . . $ OnlineAccountsPlugin/LoopbackServer#portIncrementAttempts(455f465bc33b4cdf).() const
184 {
185 Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const LoopbackServer);
186 return d->m_portIncrementAttemptscxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_portIncrementAttempts.;
187 }
188
189 void LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer#::setServedHtmlcxx . . $ OnlineAccountsPlugin/LoopbackServer#setServedHtml(45672f3c6961a244).(const QByteArraycxx . . $ QByteArray# &html)
190 {
191 Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(LoopbackServer);
192 d->m_servedHtmlcxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_servedHtml. =cxx . . $ QByteArray#`operator=`(acee8257ca81216f). html;
193 Q_EMITcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:95:10`! servedHtmlChangedcxx . . $ OnlineAccountsPlugin/LoopbackServer#servedHtmlChanged(49f6e7a06ebc5aa8).();
194 }
195
196 QByteArraycxx . . $ QByteArray# LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer#::servedHtmlcxx . . $ OnlineAccountsPlugin/LoopbackServer#servedHtml(a96750bfbcb1fbe9).() const
197 {
198 Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const LoopbackServer);
199 return dcxx . . $ QByteArray#QByteArray(6bfe0b9ef323589d).->m_servedHtmlcxx . . $ OnlineAccountsPlugin/LoopbackServerPrivate#m_servedHtml.;
200 }
201
202 QUrlcxx . . $ QUrl# LoopbackServercxx . . $ OnlineAccountsPlugin/LoopbackServer#::callbackUrlcxx . . $ OnlineAccountsPlugin/LoopbackServer#callbackUrl(36d9834fe7321282).() const
203 {
204 Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const LoopbackServer);
205 if (!d->isListeningcxx . . $ QTcpServer#isListening(50ce9a9e25b4a850).())
206 return QUrlcxx . . $ QUrl#QUrl(49f6e7a06ebc5aa8).();
207 return QUrlcxx . . $ QUrl#QUrl(ea1f3831e370f1cb).(QStringcxx . . $ QString#::fromLatin1cxx . . $ QString#fromLatin1(5ac70cc0fa2a874e).("http://localhost:%1/").
208 argcxx . . $ QString#arg(ba69ea7f5cd360b4).(d->serverPortcxx . . $ QTcpServer#serverPort(72085aa11f4b6e09).()));
209 }
210
211 #include "loopback-server.moc"cxx . . $ `<file>/build/online-accounts-plugins/lib/LomiriOnlineAccountsPlugin/lomiri-online-accounts-plugin_autogen/include/loopback-server.moc`/