Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/socket/qsocks5socketengine.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | static const int MaxWriteBufferSize = 128*1024; | - | ||||||||||||
8 | static inline QString s5StateToString(QSocks5SocketEnginePrivate::Socks5State) { return never executed: QString();return QString(); never executed: }return QString(); | 0 | ||||||||||||
9 | static inline QString dump(const QByteArray &) { return never executed: QString();return QString(); never executed: }return QString(); | 0 | ||||||||||||
10 | - | |||||||||||||
11 | - | |||||||||||||
12 | - | |||||||||||||
13 | - | |||||||||||||
14 | - | |||||||||||||
15 | - | |||||||||||||
16 | static bool qt_socks5_set_host_address_and_port(const QHostAddress &address, quint16 port, QByteArray *pBuf) | - | ||||||||||||
17 | { | - | ||||||||||||
18 | if (0) QMessageLogger(__FILE__, 150, __PRETTY_FUNCTION__).debug() << "setting [" << address << ':' << port << ']'; dead code: QMessageLogger(__FILE__, 150, __PRETTY_FUNCTION__).debug() << "setting [" << address << ':' << port << ']'; | - | ||||||||||||
19 | - | |||||||||||||
20 | union { | - | ||||||||||||
21 | quint16 port; | - | ||||||||||||
22 | quint32 ipv4; | - | ||||||||||||
23 | QIPv6Address ipv6; | - | ||||||||||||
24 | char ptr; | - | ||||||||||||
25 | } data; | - | ||||||||||||
26 | - | |||||||||||||
27 | - | |||||||||||||
28 | if (address.protocol() == QAbstractSocket::IPv4Protocol
| 1-246 | ||||||||||||
29 | data.ipv4 = qToBigEndian<quint32>(address.toIPv4Address()); | - | ||||||||||||
30 | pBuf->append(0x01); | - | ||||||||||||
31 | pBuf->append(QByteArray::fromRawData(&data.ptr, sizeof data.ipv4)); | - | ||||||||||||
32 | } executed 246 times by 4 tests: else if (address.protocol() == QAbstractSocket::IPv6Protocolend of block Executed by:
| 0-246 | ||||||||||||
33 | data.ipv6 = address.toIPv6Address(); | - | ||||||||||||
34 | pBuf->append(0x04); | - | ||||||||||||
35 | pBuf->append(QByteArray::fromRawData(&data.ptr, sizeof data.ipv6)); | - | ||||||||||||
36 | } executed 1 time by 1 test: else {end of block Executed by:
| 1 | ||||||||||||
37 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
38 | } | - | ||||||||||||
39 | - | |||||||||||||
40 | - | |||||||||||||
41 | data.port = qToBigEndian<quint16>(port); | - | ||||||||||||
42 | pBuf->append(QByteArray::fromRawData(&data.ptr, sizeof data.port)); | - | ||||||||||||
43 | return executed 247 times by 4 tests: true;return true; Executed by:
executed 247 times by 4 tests: return true; Executed by:
| 247 | ||||||||||||
44 | } | - | ||||||||||||
45 | - | |||||||||||||
46 | - | |||||||||||||
47 | - | |||||||||||||
48 | - | |||||||||||||
49 | static bool qt_socks5_set_host_name_and_port(const QString &hostname, quint16 port, QByteArray *pBuf) | - | ||||||||||||
50 | { | - | ||||||||||||
51 | if (0) QMessageLogger(__FILE__, 183, __PRETTY_FUNCTION__).debug() << "setting [" << hostname << ':' << port << ']'; dead code: QMessageLogger(__FILE__, 183, __PRETTY_FUNCTION__).debug() << "setting [" << hostname << ':' << port << ']'; | - | ||||||||||||
52 | - | |||||||||||||
53 | QByteArray encodedHostName = QUrl::toAce(hostname); | - | ||||||||||||
54 | QByteArray &buf = *pBuf; | - | ||||||||||||
55 | - | |||||||||||||
56 | if (encodedHostName.length() > 255
| 0-457 | ||||||||||||
57 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
58 | - | |||||||||||||
59 | buf.append(0x03); | - | ||||||||||||
60 | buf.append(uchar(encodedHostName.length())); | - | ||||||||||||
61 | buf.append(encodedHostName); | - | ||||||||||||
62 | - | |||||||||||||
63 | - | |||||||||||||
64 | union { | - | ||||||||||||
65 | quint16 port; | - | ||||||||||||
66 | char ptr; | - | ||||||||||||
67 | } data; | - | ||||||||||||
68 | data.port = qToBigEndian<quint16>(port); | - | ||||||||||||
69 | buf.append(QByteArray::fromRawData(&data.ptr, sizeof data.port)); | - | ||||||||||||
70 | - | |||||||||||||
71 | return executed 457 times by 7 tests: true;return true; Executed by:
executed 457 times by 7 tests: return true; Executed by:
| 457 | ||||||||||||
72 | } | - | ||||||||||||
73 | - | |||||||||||||
74 | - | |||||||||||||
75 | - | |||||||||||||
76 | - | |||||||||||||
77 | - | |||||||||||||
78 | - | |||||||||||||
79 | - | |||||||||||||
80 | static int qt_socks5_get_host_address_and_port(const QByteArray &buf, QHostAddress *pAddress, quint16 *pPort, int *pPos) | - | ||||||||||||
81 | { | - | ||||||||||||
82 | int ret = -1; | - | ||||||||||||
83 | int pos = *pPos; | - | ||||||||||||
84 | const unsigned char *pBuf = reinterpret_cast<const unsigned char*>(buf.constData()); | - | ||||||||||||
85 | QHostAddress address; | - | ||||||||||||
86 | quint16 port = 0; | - | ||||||||||||
87 | - | |||||||||||||
88 | if (buf.size() - pos < 1
| 4-693 | ||||||||||||
89 | if (0) QMessageLogger(__FILE__, 221, __PRETTY_FUNCTION__).debug() << "need more data address/port"; dead code: QMessageLogger(__FILE__, 221, __PRETTY_FUNCTION__).debug() << "need more data address/port"; | - | ||||||||||||
90 | return executed 4 times by 1 test: 0;return 0; Executed by:
executed 4 times by 1 test: return 0; Executed by:
| 4 | ||||||||||||
91 | } | - | ||||||||||||
92 | if (pBuf[pos] == 0x01
| 54-639 | ||||||||||||
93 | pos++; | - | ||||||||||||
94 | if (buf.size() - pos < 4
| 8-631 | ||||||||||||
95 | if (0) QMessageLogger(__FILE__, 227, __PRETTY_FUNCTION__).debug() << "need more data for ip4 address"; dead code: QMessageLogger(__FILE__, 227, __PRETTY_FUNCTION__).debug() << "need more data for ip4 address"; | - | ||||||||||||
96 | return executed 8 times by 1 test: 0;return 0; Executed by:
executed 8 times by 1 test: return 0; Executed by:
| 8 | ||||||||||||
97 | } | - | ||||||||||||
98 | address.setAddress(qFromBigEndian<quint32>(&pBuf[pos])); | - | ||||||||||||
99 | pos += 4; | - | ||||||||||||
100 | ret = 1; | - | ||||||||||||
101 | } executed 631 times by 7 tests: else if (pBuf[pos] == 0x04end of block Executed by:
| 0-631 | ||||||||||||
102 | pos++; | - | ||||||||||||
103 | if (buf.size() - pos < 16
| 22-32 | ||||||||||||
104 | if (0) QMessageLogger(__FILE__, 236, __PRETTY_FUNCTION__).debug() << "need more data for ip6 address"; dead code: QMessageLogger(__FILE__, 236, __PRETTY_FUNCTION__).debug() << "need more data for ip6 address"; | - | ||||||||||||
105 | return executed 32 times by 1 test: 0;return 0; Executed by:
executed 32 times by 1 test: return 0; Executed by:
| 32 | ||||||||||||
106 | } | - | ||||||||||||
107 | QIPv6Address add; | - | ||||||||||||
108 | for (int i = 0; i < 16
| 22-352 | ||||||||||||
109 | add[i] = buf[pos++]; executed 352 times by 1 test: add[i] = buf[pos++]; Executed by:
| 352 | ||||||||||||
110 | address.setAddress(add); | - | ||||||||||||
111 | ret = 1; | - | ||||||||||||
112 | } executed 22 times by 1 test: else if (pBuf[pos] == 0x03end of block Executed by:
| 0-22 | ||||||||||||
113 | - | |||||||||||||
114 | pos++; | - | ||||||||||||
115 | QMessageLogger(__FILE__, 247, __PRETTY_FUNCTION__).debug() << "skipping hostname of len" << uint(pBuf[pos]); | - | ||||||||||||
116 | pos += uchar(pBuf[pos]); | - | ||||||||||||
117 | } never executed: else {end of block | 0 | ||||||||||||
118 | if (0) QMessageLogger(__FILE__, 250, __PRETTY_FUNCTION__).debug() << "invalid address type" << (int)pBuf[pos]; dead code: QMessageLogger(__FILE__, 250, __PRETTY_FUNCTION__).debug() << "invalid address type" << (int)pBuf[pos]; | - | ||||||||||||
119 | ret = -1; | - | ||||||||||||
120 | } never executed: end of block | 0 | ||||||||||||
121 | - | |||||||||||||
122 | if (ret == 1
| 0-653 | ||||||||||||
123 | if (buf.size() - pos < 2
| 4-649 | ||||||||||||
124 | if (0) QMessageLogger(__FILE__, 256, __PRETTY_FUNCTION__).debug() << "need more data for port"; dead code: QMessageLogger(__FILE__, 256, __PRETTY_FUNCTION__).debug() << "need more data for port"; | - | ||||||||||||
125 | return executed 4 times by 1 test: 0;return 0; Executed by:
executed 4 times by 1 test: return 0; Executed by:
| 4 | ||||||||||||
126 | } | - | ||||||||||||
127 | port = qFromBigEndian<quint16>(&pBuf[pos]); | - | ||||||||||||
128 | pos += 2; | - | ||||||||||||
129 | } executed 649 times by 7 tests: end of block Executed by:
| 649 | ||||||||||||
130 | - | |||||||||||||
131 | if (ret == 1
| 0-649 | ||||||||||||
132 | if (0) QMessageLogger(__FILE__, 264, __PRETTY_FUNCTION__).debug() << "got [" << address << ':' << port << ']'; dead code: QMessageLogger(__FILE__, 264, __PRETTY_FUNCTION__).debug() << "got [" << address << ':' << port << ']'; | - | ||||||||||||
133 | *pAddress = address; | - | ||||||||||||
134 | *pPort = port; | - | ||||||||||||
135 | *pPos = pos; | - | ||||||||||||
136 | } executed 649 times by 7 tests: end of block Executed by:
| 649 | ||||||||||||
137 | - | |||||||||||||
138 | return executed 649 times by 7 tests: ret;return ret; Executed by:
executed 649 times by 7 tests: return ret; Executed by:
| 649 | ||||||||||||
139 | } | - | ||||||||||||
140 | - | |||||||||||||
141 | struct QSocks5Data | - | ||||||||||||
142 | { | - | ||||||||||||
143 | QTcpSocket *controlSocket; | - | ||||||||||||
144 | QSocks5Authenticator *authenticator; | - | ||||||||||||
145 | }; | - | ||||||||||||
146 | - | |||||||||||||
147 | struct QSocks5ConnectData : public QSocks5Data | - | ||||||||||||
148 | { | - | ||||||||||||
149 | QByteArray readBuffer; | - | ||||||||||||
150 | }; | - | ||||||||||||
151 | - | |||||||||||||
152 | struct QSocks5BindData : public QSocks5Data | - | ||||||||||||
153 | { | - | ||||||||||||
154 | QHostAddress localAddress; | - | ||||||||||||
155 | quint16 localPort; | - | ||||||||||||
156 | QHostAddress peerAddress; | - | ||||||||||||
157 | quint16 peerPort; | - | ||||||||||||
158 | QElapsedTimer timeStamp; | - | ||||||||||||
159 | }; | - | ||||||||||||
160 | - | |||||||||||||
161 | struct QSocks5RevivedDatagram | - | ||||||||||||
162 | { | - | ||||||||||||
163 | QByteArray data; | - | ||||||||||||
164 | QHostAddress address; | - | ||||||||||||
165 | quint16 port; | - | ||||||||||||
166 | }; | - | ||||||||||||
167 | - | |||||||||||||
168 | - | |||||||||||||
169 | struct QSocks5UdpAssociateData : public QSocks5Data | - | ||||||||||||
170 | { | - | ||||||||||||
171 | QUdpSocket *udpSocket; | - | ||||||||||||
172 | QHostAddress associateAddress; | - | ||||||||||||
173 | quint16 associatePort; | - | ||||||||||||
174 | QQueue<QSocks5RevivedDatagram> pendingDatagrams; | - | ||||||||||||
175 | }; | - | ||||||||||||
176 | - | |||||||||||||
177 | - | |||||||||||||
178 | - | |||||||||||||
179 | class QSocks5BindStore : public QObject | - | ||||||||||||
180 | { | - | ||||||||||||
181 | public: | - | ||||||||||||
182 | QSocks5BindStore(); | - | ||||||||||||
183 | ~QSocks5BindStore(); | - | ||||||||||||
184 | - | |||||||||||||
185 | void add(qintptr socketDescriptor, QSocks5BindData *bindData); | - | ||||||||||||
186 | bool contains(qintptr socketDescriptor); | - | ||||||||||||
187 | QSocks5BindData *retrieve(qintptr socketDescriptor); | - | ||||||||||||
188 | - | |||||||||||||
189 | protected: | - | ||||||||||||
190 | void timerEvent(QTimerEvent * event) override; | - | ||||||||||||
191 | - | |||||||||||||
192 | QMutex mutex; | - | ||||||||||||
193 | int sweepTimerId; | - | ||||||||||||
194 | - | |||||||||||||
195 | QHash<int, QSocks5BindData *> store; | - | ||||||||||||
196 | }; | - | ||||||||||||
197 | - | |||||||||||||
198 | namespace { namespace Q_QGS_socks5BindStore { typedef QSocks5BindStore Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
executed 17 times by 17 tests: }guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 17 times by 17 tests: }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; returnend of block Executed by:
executed 1005 times by 18 tests: &holder.value;return &holder.value; Executed by:
executed 1005 times by 18 tests: } } } static QGlobalStatic<QSocks5BindStore, Q_QGS_socks5BindStore::innerFunction, Q_QGS_socks5BindStore::guard> socks5BindStore;return &holder.value; Executed by:
| 0-1005 | ||||||||||||
199 | - | |||||||||||||
200 | QSocks5BindStore::QSocks5BindStore() | - | ||||||||||||
201 | : mutex(QMutex::Recursive) | - | ||||||||||||
202 | , sweepTimerId(-1) | - | ||||||||||||
203 | { | - | ||||||||||||
204 | QCoreApplication *app = QCoreApplication::instance(); | - | ||||||||||||
205 | if (app
| 0-18 | ||||||||||||
206 | moveToThread(app->thread()); executed 3 times by 3 tests: moveToThread(app->thread()); Executed by:
| 3 | ||||||||||||
207 | } executed 18 times by 18 tests: end of block Executed by:
| 18 | ||||||||||||
208 | - | |||||||||||||
209 | QSocks5BindStore::~QSocks5BindStore() | - | ||||||||||||
210 | { | - | ||||||||||||
211 | } | - | ||||||||||||
212 | - | |||||||||||||
213 | void QSocks5BindStore::add(qintptr socketDescriptor, QSocks5BindData *bindData) | - | ||||||||||||
214 | { | - | ||||||||||||
215 | QMutexLocker lock(&mutex); | - | ||||||||||||
216 | if (store.contains(socketDescriptor)
| 0-6 | ||||||||||||
217 | - | |||||||||||||
218 | } never executed: end of block | 0 | ||||||||||||
219 | bindData->timeStamp.start(); | - | ||||||||||||
220 | store.insert(socketDescriptor, bindData); | - | ||||||||||||
221 | - | |||||||||||||
222 | if (sweepTimerId == -1
| 0-6 | ||||||||||||
223 | sweepTimerId = startTimer(60000); executed 6 times by 3 tests: sweepTimerId = startTimer(60000); Executed by:
| 6 | ||||||||||||
224 | } executed 6 times by 3 tests: end of block Executed by:
| 6 | ||||||||||||
225 | - | |||||||||||||
226 | bool QSocks5BindStore::contains(qintptr socketDescriptor) | - | ||||||||||||
227 | { | - | ||||||||||||
228 | QMutexLocker lock(&mutex); | - | ||||||||||||
229 | return executed 993 times by 18 tests: store.contains(socketDescriptor);return store.contains(socketDescriptor); Executed by:
executed 993 times by 18 tests: return store.contains(socketDescriptor); Executed by:
| 993 | ||||||||||||
230 | } | - | ||||||||||||
231 | - | |||||||||||||
232 | QSocks5BindData *QSocks5BindStore::retrieve(qintptr socketDescriptor) | - | ||||||||||||
233 | { | - | ||||||||||||
234 | QMutexLocker lock(&mutex); | - | ||||||||||||
235 | if (!store.contains(socketDescriptor)
| 0-6 | ||||||||||||
236 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
237 | QSocks5BindData *bindData = store.take(socketDescriptor); | - | ||||||||||||
238 | if (bindData
| 0-6 | ||||||||||||
239 | if (bindData->controlSocket->thread() != QThread::currentThread()
| 0-6 | ||||||||||||
240 | QMessageLogger(__FILE__, 372, __PRETTY_FUNCTION__).warning("Can not access socks5 bind data from different thread"); | - | ||||||||||||
241 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
242 | } | - | ||||||||||||
243 | } executed 6 times by 3 tests: else {end of block Executed by:
| 6 | ||||||||||||
244 | if (0) QMessageLogger(__FILE__, 376, __PRETTY_FUNCTION__).debug() << "__ERROR__ binddata == 0"; dead code: QMessageLogger(__FILE__, 376, __PRETTY_FUNCTION__).debug() << "__ERROR__ binddata == 0"; | - | ||||||||||||
245 | } never executed: end of block | 0 | ||||||||||||
246 | - | |||||||||||||
247 | if (store.isEmpty()
| 0-6 | ||||||||||||
248 | killTimer(sweepTimerId); | - | ||||||||||||
249 | sweepTimerId = -1; | - | ||||||||||||
250 | } executed 6 times by 3 tests: end of block Executed by:
| 6 | ||||||||||||
251 | return executed 6 times by 3 tests: bindData;return bindData; Executed by:
executed 6 times by 3 tests: return bindData; Executed by:
| 6 | ||||||||||||
252 | } | - | ||||||||||||
253 | - | |||||||||||||
254 | void QSocks5BindStore::timerEvent(QTimerEvent * event) | - | ||||||||||||
255 | { | - | ||||||||||||
256 | QMutexLocker lock(&mutex); | - | ||||||||||||
257 | if (event->timerId() == sweepTimerId
| 0 | ||||||||||||
258 | if (0) QMessageLogger(__FILE__, 390, __PRETTY_FUNCTION__).debug() << "QSocks5BindStore performing sweep"; dead code: QMessageLogger(__FILE__, 390, __PRETTY_FUNCTION__).debug() << "QSocks5BindStore performing sweep"; | - | ||||||||||||
259 | QMutableHashIterator<int, QSocks5BindData *> it(store); | - | ||||||||||||
260 | while (it.hasNext()
| 0 | ||||||||||||
261 | it.next(); | - | ||||||||||||
262 | if (it.value()->timeStamp.hasExpired(350000)
| 0 | ||||||||||||
263 | if (0) QMessageLogger(__FILE__, 395, __PRETTY_FUNCTION__).debug() << "QSocks5BindStore removing JJJJ"; dead code: QMessageLogger(__FILE__, 395, __PRETTY_FUNCTION__).debug() << "QSocks5BindStore removing JJJJ"; | - | ||||||||||||
264 | it.remove(); | - | ||||||||||||
265 | } never executed: end of block | 0 | ||||||||||||
266 | } never executed: end of block | 0 | ||||||||||||
267 | } never executed: end of block | 0 | ||||||||||||
268 | } never executed: end of block | 0 | ||||||||||||
269 | - | |||||||||||||
270 | QSocks5Authenticator::QSocks5Authenticator() | - | ||||||||||||
271 | { | - | ||||||||||||
272 | } | - | ||||||||||||
273 | - | |||||||||||||
274 | QSocks5Authenticator::~QSocks5Authenticator() | - | ||||||||||||
275 | { | - | ||||||||||||
276 | } | - | ||||||||||||
277 | - | |||||||||||||
278 | char QSocks5Authenticator::methodId() | - | ||||||||||||
279 | { | - | ||||||||||||
280 | return executed 653 times by 9 tests: 0x00;return 0x00; Executed by:
executed 653 times by 9 tests: return 0x00; Executed by:
| 653 | ||||||||||||
281 | } | - | ||||||||||||
282 | - | |||||||||||||
283 | bool QSocks5Authenticator::beginAuthenticate(QTcpSocket *socket, bool *completed) | - | ||||||||||||
284 | { | - | ||||||||||||
285 | (void)socket;; | - | ||||||||||||
286 | *completed = true; | - | ||||||||||||
287 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||
288 | } | - | ||||||||||||
289 | - | |||||||||||||
290 | bool QSocks5Authenticator::continueAuthenticate(QTcpSocket *socket, bool *completed) | - | ||||||||||||
291 | { | - | ||||||||||||
292 | (void)socket;; | - | ||||||||||||
293 | *completed = true; | - | ||||||||||||
294 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||
295 | } | - | ||||||||||||
296 | - | |||||||||||||
297 | bool QSocks5Authenticator::seal(const QByteArray &buf, QByteArray *sealedBuf) | - | ||||||||||||
298 | { | - | ||||||||||||
299 | *sealedBuf = buf; | - | ||||||||||||
300 | return executed 2591 times by 9 tests: true;return true; Executed by:
executed 2591 times by 9 tests: return true; Executed by:
| 2591 | ||||||||||||
301 | } | - | ||||||||||||
302 | - | |||||||||||||
303 | bool QSocks5Authenticator::unSeal(const QByteArray &sealedBuf, QByteArray *buf) | - | ||||||||||||
304 | { | - | ||||||||||||
305 | *buf = sealedBuf; | - | ||||||||||||
306 | return executed 3662 times by 8 tests: true;return true; Executed by:
executed 3662 times by 8 tests: return true; Executed by:
| 3662 | ||||||||||||
307 | } | - | ||||||||||||
308 | - | |||||||||||||
309 | bool QSocks5Authenticator::unSeal(QTcpSocket *sealedSocket, QByteArray *buf) | - | ||||||||||||
310 | { | - | ||||||||||||
311 | return executed 3662 times by 8 tests: unSeal(sealedSocket->readAll(), buf);return unSeal(sealedSocket->readAll(), buf); Executed by:
executed 3662 times by 8 tests: return unSeal(sealedSocket->readAll(), buf); Executed by:
| 3662 | ||||||||||||
312 | } | - | ||||||||||||
313 | - | |||||||||||||
314 | QSocks5PasswordAuthenticator::QSocks5PasswordAuthenticator(const QString &userName, const QString &password) | - | ||||||||||||
315 | { | - | ||||||||||||
316 | this->userName = userName; | - | ||||||||||||
317 | this->password = password; | - | ||||||||||||
318 | } executed 147 times by 7 tests: end of block Executed by:
| 147 | ||||||||||||
319 | - | |||||||||||||
320 | char QSocks5PasswordAuthenticator::methodId() | - | ||||||||||||
321 | { | - | ||||||||||||
322 | return executed 236 times by 7 tests: 0x02;return 0x02; Executed by:
executed 236 times by 7 tests: return 0x02; Executed by:
| 236 | ||||||||||||
323 | } | - | ||||||||||||
324 | - | |||||||||||||
325 | bool QSocks5PasswordAuthenticator::beginAuthenticate(QTcpSocket *socket, bool *completed) | - | ||||||||||||
326 | { | - | ||||||||||||
327 | *completed = false; | - | ||||||||||||
328 | QByteArray uname = userName.toLatin1(); | - | ||||||||||||
329 | QByteArray passwd = password.toLatin1(); | - | ||||||||||||
330 | QByteArray dataBuf(3 + uname.size() + passwd.size(), 0); | - | ||||||||||||
331 | char *buf = dataBuf.data(); | - | ||||||||||||
332 | int pos = 0; | - | ||||||||||||
333 | buf[pos++] = 0x01; | - | ||||||||||||
334 | buf[pos++] = uname.size(); | - | ||||||||||||
335 | memcpy(&buf[pos], uname.data(), uname.size()); | - | ||||||||||||
336 | pos += uname.size(); | - | ||||||||||||
337 | buf[pos++] = passwd.size(); | - | ||||||||||||
338 | memcpy(&buf[pos], passwd.data(), passwd.size()); | - | ||||||||||||
339 | return executed 89 times by 7 tests: socket->write(dataBuf) == dataBuf.size();return socket->write(dataBuf) == dataBuf.size(); Executed by:
executed 89 times by 7 tests: return socket->write(dataBuf) == dataBuf.size(); Executed by:
| 89 | ||||||||||||
340 | } | - | ||||||||||||
341 | - | |||||||||||||
342 | bool QSocks5PasswordAuthenticator::continueAuthenticate(QTcpSocket *socket, bool *completed) | - | ||||||||||||
343 | { | - | ||||||||||||
344 | *completed = false; | - | ||||||||||||
345 | - | |||||||||||||
346 | if (socket->bytesAvailable() < 2
| 2-88 | ||||||||||||
347 | return executed 2 times by 1 test: true;return true; Executed by:
executed 2 times by 1 test: return true; Executed by:
| 2 | ||||||||||||
348 | - | |||||||||||||
349 | QByteArray buf = socket->read(2); | - | ||||||||||||
350 | if (buf.at(0) == 0x01
| 0-87 | ||||||||||||
351 | *completed = true; | - | ||||||||||||
352 | return executed 87 times by 7 tests: true;return true; Executed by:
executed 87 times by 7 tests: return true; Executed by:
| 87 | ||||||||||||
353 | } | - | ||||||||||||
354 | - | |||||||||||||
355 | - | |||||||||||||
356 | socket->close(); | - | ||||||||||||
357 | return executed 1 time by 1 test: false;return false; Executed by:
executed 1 time by 1 test: return false; Executed by:
| 1 | ||||||||||||
358 | } | - | ||||||||||||
359 | - | |||||||||||||
360 | QString QSocks5PasswordAuthenticator::errorString() | - | ||||||||||||
361 | { | - | ||||||||||||
362 | return never executed: QLatin1String("Socks5 user name or password incorrect");return QLatin1String("Socks5 user name or password incorrect"); never executed: return QLatin1String("Socks5 user name or password incorrect"); | 0 | ||||||||||||
363 | } | - | ||||||||||||
364 | - | |||||||||||||
365 | - | |||||||||||||
366 | - | |||||||||||||
367 | QSocks5SocketEnginePrivate::QSocks5SocketEnginePrivate() | - | ||||||||||||
368 | : socks5State(Uninitialized) | - | ||||||||||||
369 | , readNotificationEnabled(false) | - | ||||||||||||
370 | , writeNotificationEnabled(false) | - | ||||||||||||
371 | , exceptNotificationEnabled(false) | - | ||||||||||||
372 | , socketDescriptor(-1) | - | ||||||||||||
373 | , data(0) | - | ||||||||||||
374 | , connectData(0) | - | ||||||||||||
375 | - | |||||||||||||
376 | , udpData(0) | - | ||||||||||||
377 | - | |||||||||||||
378 | , bindData(0) | - | ||||||||||||
379 | , readNotificationActivated(false) | - | ||||||||||||
380 | , writeNotificationActivated(false) | - | ||||||||||||
381 | , readNotificationPending(false) | - | ||||||||||||
382 | , writeNotificationPending(false) | - | ||||||||||||
383 | , connectionNotificationPending(false) | - | ||||||||||||
384 | { | - | ||||||||||||
385 | mode = NoMode; | - | ||||||||||||
386 | } executed 726 times by 9 tests: end of block Executed by:
| 726 | ||||||||||||
387 | - | |||||||||||||
388 | QSocks5SocketEnginePrivate::~QSocks5SocketEnginePrivate() | - | ||||||||||||
389 | { | - | ||||||||||||
390 | } | - | ||||||||||||
391 | - | |||||||||||||
392 | void QSocks5SocketEnginePrivate::initialize(Socks5Mode socks5Mode) | - | ||||||||||||
393 | { | - | ||||||||||||
394 | QSocks5SocketEngine * const q = q_func(); | - | ||||||||||||
395 | - | |||||||||||||
396 | mode = socks5Mode; | - | ||||||||||||
397 | if (mode == ConnectMode
| 15-704 | ||||||||||||
398 | connectData = new QSocks5ConnectData; | - | ||||||||||||
399 | data = connectData; | - | ||||||||||||
400 | - | |||||||||||||
401 | } executed 704 times by 9 tests: else if (mode == UdpAssociateModeend of block Executed by:
| 2-704 | ||||||||||||
402 | udpData = new QSocks5UdpAssociateData; | - | ||||||||||||
403 | data = udpData; | - | ||||||||||||
404 | udpData->udpSocket = new QUdpSocket(q); | - | ||||||||||||
405 | - | |||||||||||||
406 | udpData->udpSocket->setProperty("_q_networksession", q->property("_q_networksession")); | - | ||||||||||||
407 | - | |||||||||||||
408 | udpData->udpSocket->setProxy(QNetworkProxy::NoProxy); | - | ||||||||||||
409 | QObject::connect(udpData->udpSocket, qFlagLocation("2""readyRead()" "\0" __FILE__ ":" "541"), | - | ||||||||||||
410 | q, qFlagLocation("1""_q_udpSocketReadNotification()" "\0" __FILE__ ":" "542"), | - | ||||||||||||
411 | Qt::DirectConnection); | - | ||||||||||||
412 | - | |||||||||||||
413 | } executed 2 times by 1 test: else if (mode == BindModeend of block Executed by:
| 0-13 | ||||||||||||
414 | bindData = new QSocks5BindData; | - | ||||||||||||
415 | data = bindData; | - | ||||||||||||
416 | } executed 13 times by 3 tests: end of block Executed by:
| 13 | ||||||||||||
417 | - | |||||||||||||
418 | data->controlSocket = new QTcpSocket(q); | - | ||||||||||||
419 | - | |||||||||||||
420 | data->controlSocket->setProperty("_q_networksession", q->property("_q_networksession")); | - | ||||||||||||
421 | - | |||||||||||||
422 | data->controlSocket->setProxy(QNetworkProxy::NoProxy); | - | ||||||||||||
423 | QObject::connect(data->controlSocket, qFlagLocation("2""connected()" "\0" __FILE__ ":" "555"), q, qFlagLocation("1""_q_controlSocketConnected()" "\0" __FILE__ ":" "555"), | - | ||||||||||||
424 | Qt::DirectConnection); | - | ||||||||||||
425 | QObject::connect(data->controlSocket, qFlagLocation("2""readyRead()" "\0" __FILE__ ":" "557"), q, qFlagLocation("1""_q_controlSocketReadNotification()" "\0" __FILE__ ":" "557"), | - | ||||||||||||
426 | Qt::DirectConnection); | - | ||||||||||||
427 | QObject::connect(data->controlSocket, qFlagLocation("2""bytesWritten(qint64)" "\0" __FILE__ ":" "559"), q, qFlagLocation("1""_q_controlSocketBytesWritten()" "\0" __FILE__ ":" "559"), | - | ||||||||||||
428 | Qt::DirectConnection); | - | ||||||||||||
429 | QObject::connect(data->controlSocket, qFlagLocation("2""error(QAbstractSocket::SocketError)" "\0" __FILE__ ":" "561"), | - | ||||||||||||
430 | q, qFlagLocation("1""_q_controlSocketError(QAbstractSocket::SocketError)" "\0" __FILE__ ":" "562"), | - | ||||||||||||
431 | Qt::DirectConnection); | - | ||||||||||||
432 | QObject::connect(data->controlSocket, qFlagLocation("2""disconnected()" "\0" __FILE__ ":" "564"), q, qFlagLocation("1""_q_controlSocketDisconnected()" "\0" __FILE__ ":" "564"), | - | ||||||||||||
433 | Qt::DirectConnection); | - | ||||||||||||
434 | QObject::connect(data->controlSocket, qFlagLocation("2""stateChanged(QAbstractSocket::SocketState)" "\0" __FILE__ ":" "566"), | - | ||||||||||||
435 | q, qFlagLocation("1""_q_controlSocketStateChanged(QAbstractSocket::SocketState)" "\0" __FILE__ ":" "567"), | - | ||||||||||||
436 | Qt::DirectConnection); | - | ||||||||||||
437 | - | |||||||||||||
438 | if (!proxyInfo.user().isEmpty()
| 0-657 | ||||||||||||
439 | if (0) QMessageLogger(__FILE__, 571, __PRETTY_FUNCTION__).debug() << "using username/password authentication; user =" << proxyInfo.user(); dead code: QMessageLogger(__FILE__, 571, __PRETTY_FUNCTION__).debug() << "using username/password authentication; user =" << proxyInfo.user(); | - | ||||||||||||
440 | data->authenticator = new QSocks5PasswordAuthenticator(proxyInfo.user(), proxyInfo.password()); | - | ||||||||||||
441 | } executed 62 times by 1 test: else {end of block Executed by:
| 62 | ||||||||||||
442 | if (0) QMessageLogger(__FILE__, 574, __PRETTY_FUNCTION__).debug() << "not using authentication"; dead code: QMessageLogger(__FILE__, 574, __PRETTY_FUNCTION__).debug() << "not using authentication"; | - | ||||||||||||
443 | data->authenticator = new QSocks5Authenticator(); | - | ||||||||||||
444 | } executed 657 times by 9 tests: end of block Executed by:
| 657 | ||||||||||||
445 | } | - | ||||||||||||
446 | - | |||||||||||||
447 | void QSocks5SocketEnginePrivate::setErrorState(Socks5State state, const QString &extraMessage) | - | ||||||||||||
448 | { | - | ||||||||||||
449 | QSocks5SocketEngine * const q = q_func(); | - | ||||||||||||
450 | - | |||||||||||||
451 | switch (state) { | - | ||||||||||||
452 | case never executed: Uninitialized:case Uninitialized: never executed: case Uninitialized: | 0 | ||||||||||||
453 | case never executed: Authenticating:case Authenticating: never executed: case Authenticating: | 0 | ||||||||||||
454 | case never executed: AuthenticationMethodsSent:case AuthenticationMethodsSent: never executed: case AuthenticationMethodsSent: | 0 | ||||||||||||
455 | case never executed: RequestMethodSent:case RequestMethodSent: never executed: case RequestMethodSent: | 0 | ||||||||||||
456 | case never executed: Connected:case Connected: never executed: case Connected: | 0 | ||||||||||||
457 | case never executed: UdpAssociateSuccess:case UdpAssociateSuccess: never executed: case UdpAssociateSuccess: | 0 | ||||||||||||
458 | case never executed: BindSuccess:case BindSuccess: never executed: case BindSuccess: | 0 | ||||||||||||
459 | - | |||||||||||||
460 | return; never executed: return; | 0 | ||||||||||||
461 | - | |||||||||||||
462 | case executed 6 times by 4 tests: ConnectError:case ConnectError: Executed by:
executed 6 times by 4 tests: case ConnectError: Executed by:
| 6 | ||||||||||||
463 | case executed 37 times by 4 tests: ControlSocketError:case ControlSocketError: Executed by:
executed 37 times by 4 tests: {case ControlSocketError: Executed by:
| 37 | ||||||||||||
464 | QAbstractSocket::SocketError controlSocketError = data->controlSocket->error(); | - | ||||||||||||
465 | if (socks5State != Connected
| 0-43 | ||||||||||||
466 | switch (controlSocketError) { | - | ||||||||||||
467 | case executed 2 times by 2 tests: QAbstractSocket::ConnectionRefusedError:case QAbstractSocket::ConnectionRefusedError: Executed by:
executed 2 times by 2 tests: case QAbstractSocket::ConnectionRefusedError: Executed by:
| 2 | ||||||||||||
468 | q->setError(QAbstractSocket::ProxyConnectionRefusedError, | - | ||||||||||||
469 | QSocks5SocketEngine::tr("Connection to proxy refused")); | - | ||||||||||||
470 | break; executed 2 times by 2 tests: break; Executed by:
| 2 | ||||||||||||
471 | case executed 30 times by 1 test: QAbstractSocket::RemoteHostClosedError:case QAbstractSocket::RemoteHostClosedError: Executed by:
executed 30 times by 1 test: case QAbstractSocket::RemoteHostClosedError: Executed by:
| 30 | ||||||||||||
472 | q->setError(QAbstractSocket::ProxyConnectionClosedError, | - | ||||||||||||
473 | QSocks5SocketEngine::tr("Connection to proxy closed prematurely")); | - | ||||||||||||
474 | break; executed 30 times by 1 test: break; Executed by:
| 30 | ||||||||||||
475 | case executed 4 times by 3 tests: QAbstractSocket::HostNotFoundError:case QAbstractSocket::HostNotFoundError: Executed by:
executed 4 times by 3 tests: case QAbstractSocket::HostNotFoundError: Executed by:
| 4 | ||||||||||||
476 | q->setError(QAbstractSocket::ProxyNotFoundError, | - | ||||||||||||
477 | QSocks5SocketEngine::tr("Proxy host not found")); | - | ||||||||||||
478 | break; executed 4 times by 3 tests: break; Executed by:
| 4 | ||||||||||||
479 | case executed 7 times by 3 tests: QAbstractSocket::SocketTimeoutError:case QAbstractSocket::SocketTimeoutError: Executed by:
executed 7 times by 3 tests: case QAbstractSocket::SocketTimeoutError: Executed by:
| 7 | ||||||||||||
480 | if (state == ConnectError
| 0-7 | ||||||||||||
481 | q->setError(QAbstractSocket::ProxyConnectionTimeoutError, | - | ||||||||||||
482 | QSocks5SocketEngine::tr("Connection to proxy timed out")); | - | ||||||||||||
483 | break; never executed: break; | 0 | ||||||||||||
484 | } | - | ||||||||||||
485 | - | |||||||||||||
486 | default never executed: default: code before this statement executed 7 times by 3 tests: default: Executed by:
never executed: :default: code before this statement executed 7 times by 3 tests: default: Executed by:
never executed: default: | 0-7 | ||||||||||||
487 | q->setError(controlSocketError, data->controlSocket->errorString()); | - | ||||||||||||
488 | break; executed 7 times by 3 tests: break; Executed by:
| 7 | ||||||||||||
489 | } | - | ||||||||||||
490 | } else { | - | ||||||||||||
491 | q->setError(controlSocketError, data->controlSocket->errorString()); | - | ||||||||||||
492 | } never executed: end of block | 0 | ||||||||||||
493 | break; executed 43 times by 5 tests: break; Executed by:
| 43 | ||||||||||||
494 | } | - | ||||||||||||
495 | - | |||||||||||||
496 | case executed 6 times by 2 tests: AuthenticatingError:case AuthenticatingError: Executed by:
executed 6 times by 2 tests: case AuthenticatingError: Executed by:
| 6 | ||||||||||||
497 | q->setError(QAbstractSocket::ProxyAuthenticationRequiredError, | - | ||||||||||||
498 | extraMessage.isEmpty() ? | - | ||||||||||||
499 | QSocks5SocketEngine::tr("Proxy authentication failed") : | - | ||||||||||||
500 | QSocks5SocketEngine::tr("Proxy authentication failed: %1").arg(extraMessage)); | - | ||||||||||||
501 | break; executed 6 times by 2 tests: break; Executed by:
| 6 | ||||||||||||
502 | - | |||||||||||||
503 | case executed 17 times by 3 tests: RequestError:case RequestError: Executed by:
executed 17 times by 3 tests: case RequestError: Executed by:
| 17 | ||||||||||||
504 | - | |||||||||||||
505 | break; executed 17 times by 3 tests: break; Executed by:
| 17 | ||||||||||||
506 | - | |||||||||||||
507 | case executed 2 times by 1 test: SocksError:case SocksError: Executed by:
executed 2 times by 1 test: case SocksError: Executed by:
| 2 | ||||||||||||
508 | q->setError(QAbstractSocket::ProxyProtocolError, | - | ||||||||||||
509 | QSocks5SocketEngine::tr("SOCKS version 5 protocol error")); | - | ||||||||||||
510 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||
511 | - | |||||||||||||
512 | case executed 4 times by 2 tests: HostNameLookupError:case HostNameLookupError: Executed by:
executed 4 times by 2 tests: case HostNameLookupError: Executed by:
| 4 | ||||||||||||
513 | q->setError(QAbstractSocket::HostNotFoundError, | - | ||||||||||||
514 | QAbstractSocket::tr("Host not found")); | - | ||||||||||||
515 | break; executed 4 times by 2 tests: break; Executed by:
| 4 | ||||||||||||
516 | } | - | ||||||||||||
517 | - | |||||||||||||
518 | q->setState(QAbstractSocket::UnconnectedState); | - | ||||||||||||
519 | socks5State = state; | - | ||||||||||||
520 | } executed 72 times by 7 tests: end of block Executed by:
| 72 | ||||||||||||
521 | - | |||||||||||||
522 | void QSocks5SocketEnginePrivate::setErrorState(Socks5State state, Socks5Error socks5error) | - | ||||||||||||
523 | { | - | ||||||||||||
524 | QSocks5SocketEngine * const q = q_func(); | - | ||||||||||||
525 | switch (socks5error) { | - | ||||||||||||
526 | case never executed: SocksFailure:case SocksFailure: never executed: case SocksFailure: | 0 | ||||||||||||
527 | q->setError(QAbstractSocket::NetworkError, | - | ||||||||||||
528 | QSocks5SocketEngine::tr("General SOCKSv5 server failure")); | - | ||||||||||||
529 | break; never executed: break; | 0 | ||||||||||||
530 | case executed 2 times by 1 test: ConnectionNotAllowed:case ConnectionNotAllowed: Executed by:
executed 2 times by 1 test: case ConnectionNotAllowed: Executed by:
| 2 | ||||||||||||
531 | q->setError(QAbstractSocket::SocketAccessError, | - | ||||||||||||
532 | QSocks5SocketEngine::tr("Connection not allowed by SOCKSv5 server")); | - | ||||||||||||
533 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||
534 | case executed 2 times by 1 test: NetworkUnreachable:case NetworkUnreachable: Executed by:
executed 2 times by 1 test: case NetworkUnreachable: Executed by:
| 2 | ||||||||||||
535 | q->setError(QAbstractSocket::NetworkError, | - | ||||||||||||
536 | QAbstractSocket::tr("Network unreachable")); | - | ||||||||||||
537 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||
538 | case executed 8 times by 3 tests: HostUnreachable:case HostUnreachable: Executed by:
executed 8 times by 3 tests: case HostUnreachable: Executed by:
| 8 | ||||||||||||
539 | q->setError(QAbstractSocket::HostNotFoundError, | - | ||||||||||||
540 | QAbstractSocket::tr("Host not found")); | - | ||||||||||||
541 | break; executed 8 times by 3 tests: break; Executed by:
| 8 | ||||||||||||
542 | case executed 5 times by 2 tests: ConnectionRefused:case ConnectionRefused: Executed by:
executed 5 times by 2 tests: case ConnectionRefused: Executed by:
| 5 | ||||||||||||
543 | q->setError(QAbstractSocket::ConnectionRefusedError, | - | ||||||||||||
544 | QAbstractSocket::tr("Connection refused")); | - | ||||||||||||
545 | break; executed 5 times by 2 tests: break; Executed by:
| 5 | ||||||||||||
546 | case never executed: TTLExpired:case TTLExpired: never executed: case TTLExpired: | 0 | ||||||||||||
547 | q->setError(QAbstractSocket::NetworkError, | - | ||||||||||||
548 | QSocks5SocketEngine::tr("TTL expired")); | - | ||||||||||||
549 | break; never executed: break; | 0 | ||||||||||||
550 | case never executed: CommandNotSupported:case CommandNotSupported: never executed: case CommandNotSupported: | 0 | ||||||||||||
551 | q->setError(QAbstractSocket::UnsupportedSocketOperationError, | - | ||||||||||||
552 | QSocks5SocketEngine::tr("SOCKSv5 command not supported")); | - | ||||||||||||
553 | break; never executed: break; | 0 | ||||||||||||
554 | case never executed: AddressTypeNotSupported:case AddressTypeNotSupported: never executed: case AddressTypeNotSupported: | 0 | ||||||||||||
555 | q->setError(QAbstractSocket::UnsupportedSocketOperationError, | - | ||||||||||||
556 | QSocks5SocketEngine::tr("Address type not supported")); | - | ||||||||||||
557 | break; never executed: break; | 0 | ||||||||||||
558 | - | |||||||||||||
559 | default never executed: :default: never executed: default: | 0 | ||||||||||||
560 | q->setError(QAbstractSocket::UnknownSocketError, | - | ||||||||||||
561 | QSocks5SocketEngine::tr("Unknown SOCKSv5 proxy error code 0x%1").arg(int(socks5error), 16)); | - | ||||||||||||
562 | break; never executed: break; | 0 | ||||||||||||
563 | } | - | ||||||||||||
564 | - | |||||||||||||
565 | setErrorState(state, QString()); | - | ||||||||||||
566 | } executed 17 times by 3 tests: end of block Executed by:
| 17 | ||||||||||||
567 | - | |||||||||||||
568 | void QSocks5SocketEnginePrivate::reauthenticate() | - | ||||||||||||
569 | { | - | ||||||||||||
570 | QSocks5SocketEngine * const q = q_func(); | - | ||||||||||||
571 | - | |||||||||||||
572 | - | |||||||||||||
573 | QAuthenticator auth; | - | ||||||||||||
574 | q->proxyAuthenticationRequired(proxyInfo, &auth); | - | ||||||||||||
575 | - | |||||||||||||
576 | if (!auth.user().isEmpty()
| 0-85 | ||||||||||||
577 | - | |||||||||||||
578 | if (0) QMessageLogger(__FILE__, 710, __PRETTY_FUNCTION__).debug() << "authentication failure: retrying connection"; dead code: QMessageLogger(__FILE__, 710, __PRETTY_FUNCTION__).debug() << "authentication failure: retrying connection"; | - | ||||||||||||
579 | socks5State = QSocks5SocketEnginePrivate::Uninitialized; | - | ||||||||||||
580 | - | |||||||||||||
581 | delete data->authenticator; | - | ||||||||||||
582 | proxyInfo.setUser(auth.user()); | - | ||||||||||||
583 | proxyInfo.setPassword(auth.password()); | - | ||||||||||||
584 | data->authenticator = new QSocks5PasswordAuthenticator(proxyInfo.user(), proxyInfo.password()); | - | ||||||||||||
585 | - | |||||||||||||
586 | { | - | ||||||||||||
587 | const QSignalBlocker blocker(data->controlSocket); | - | ||||||||||||
588 | data->controlSocket->abort(); | - | ||||||||||||
589 | } | - | ||||||||||||
590 | data->controlSocket->connectToHost(proxyInfo.hostName(), proxyInfo.port()); | - | ||||||||||||
591 | } executed 85 times by 7 tests: else {end of block Executed by:
| 85 | ||||||||||||
592 | - | |||||||||||||
593 | - | |||||||||||||
594 | setErrorState(AuthenticatingError); | - | ||||||||||||
595 | data->controlSocket->close(); | - | ||||||||||||
596 | emitConnectionNotification(); | - | ||||||||||||
597 | } executed 4 times by 2 tests: end of block Executed by:
| 4 | ||||||||||||
598 | } | - | ||||||||||||
599 | - | |||||||||||||
600 | void QSocks5SocketEnginePrivate::parseAuthenticationMethodReply() | - | ||||||||||||
601 | { | - | ||||||||||||
602 | - | |||||||||||||
603 | if (data->controlSocket->bytesAvailable() < 2
| 2-794 | ||||||||||||
604 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||
605 | - | |||||||||||||
606 | QByteArray buf = data->controlSocket->read(2); | - | ||||||||||||
607 | if (buf.at(0) != 0x05
| 1-793 | ||||||||||||
608 | if (0) QMessageLogger(__FILE__, 740, __PRETTY_FUNCTION__).debug() << "Socks5 version incorrect"; dead code: QMessageLogger(__FILE__, 740, __PRETTY_FUNCTION__).debug() << "Socks5 version incorrect"; | - | ||||||||||||
609 | setErrorState(SocksError); | - | ||||||||||||
610 | data->controlSocket->close(); | - | ||||||||||||
611 | emitConnectionNotification(); | - | ||||||||||||
612 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||
613 | } | - | ||||||||||||
614 | - | |||||||||||||
615 | bool authComplete = false; | - | ||||||||||||
616 | if (uchar(buf.at(1)) == 0x00
| 179-614 | ||||||||||||
617 | authComplete = true; | - | ||||||||||||
618 | } executed 614 times by 8 tests: else if (uchar(buf.at(1)) == 0xFFend of block Executed by:
| 88-614 | ||||||||||||
619 | reauthenticate(); | - | ||||||||||||
620 | return; executed 88 times by 7 tests: return; Executed by:
| 88 | ||||||||||||
621 | } else if (buf.at(1) != data->authenticator->methodId()
| 2-89 | ||||||||||||
622 | || !data->authenticator->beginAuthenticate(data->controlSocket, &authComplete)
| 0-89 | ||||||||||||
623 | setErrorState(AuthenticatingError, QLatin1String("Socks5 host did not support authentication method.")); | - | ||||||||||||
624 | socketError = QAbstractSocket::SocketAccessError; | - | ||||||||||||
625 | emitConnectionNotification(); | - | ||||||||||||
626 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||
627 | } | - | ||||||||||||
628 | - | |||||||||||||
629 | if (authComplete
| 89-614 | ||||||||||||
630 | sendRequestMethod(); executed 614 times by 8 tests: sendRequestMethod(); Executed by:
| 614 | ||||||||||||
631 | else | - | ||||||||||||
632 | socks5State = Authenticating; executed 89 times by 7 tests: socks5State = Authenticating; Executed by:
| 89 | ||||||||||||
633 | } | - | ||||||||||||
634 | - | |||||||||||||
635 | void QSocks5SocketEnginePrivate::parseAuthenticatingReply() | - | ||||||||||||
636 | { | - | ||||||||||||
637 | bool authComplete = false; | - | ||||||||||||
638 | if (!data->authenticator->continueAuthenticate(data->controlSocket, &authComplete)
| 1-89 | ||||||||||||
639 | reauthenticate(); | - | ||||||||||||
640 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||
641 | } | - | ||||||||||||
642 | if (authComplete
| 2-87 | ||||||||||||
643 | sendRequestMethod(); executed 87 times by 7 tests: sendRequestMethod(); Executed by:
| 87 | ||||||||||||
644 | } executed 89 times by 7 tests: end of block Executed by:
| 89 | ||||||||||||
645 | - | |||||||||||||
646 | void QSocks5SocketEnginePrivate::sendRequestMethod() | - | ||||||||||||
647 | { | - | ||||||||||||
648 | QHostAddress address; | - | ||||||||||||
649 | quint16 port = 0; | - | ||||||||||||
650 | char command = 0; | - | ||||||||||||
651 | if (mode == ConnectMode
| 13-688 | ||||||||||||
652 | command = 0x01; | - | ||||||||||||
653 | address = peerAddress; | - | ||||||||||||
654 | port = peerPort; | - | ||||||||||||
655 | } executed 688 times by 9 tests: else if (mode == BindModeend of block Executed by:
| 2-688 | ||||||||||||
656 | command = 0x02; | - | ||||||||||||
657 | address = localAddress; | - | ||||||||||||
658 | port = localPort; | - | ||||||||||||
659 | } executed 11 times by 3 tests: else {end of block Executed by:
| 11 | ||||||||||||
660 | - | |||||||||||||
661 | command = 0x03; | - | ||||||||||||
662 | address = localAddress; | - | ||||||||||||
663 | port = localPort; | - | ||||||||||||
664 | - | |||||||||||||
665 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
666 | - | |||||||||||||
667 | QByteArray buf; | - | ||||||||||||
668 | buf.reserve(270); | - | ||||||||||||
669 | buf[0] = 0x05; | - | ||||||||||||
670 | buf[1] = command; | - | ||||||||||||
671 | buf[2] = 0x00; | - | ||||||||||||
672 | if (peerName.isEmpty()
| 0-457 | ||||||||||||
673 | if (0) QMessageLogger(__FILE__, 805, __PRETTY_FUNCTION__).debug() << "error setting address" << address << " : " << port; dead code: QMessageLogger(__FILE__, 805, __PRETTY_FUNCTION__).debug() << "error setting address" << address << " : " << port; | - | ||||||||||||
674 | - | |||||||||||||
675 | return; never executed: return; | 0 | ||||||||||||
676 | } else if (!peerName.isEmpty()
| 0-457 | ||||||||||||
677 | if (0) QMessageLogger(__FILE__, 809, __PRETTY_FUNCTION__).debug() << "error setting peer name" << peerName << " : " << port; dead code: QMessageLogger(__FILE__, 809, __PRETTY_FUNCTION__).debug() << "error setting peer name" << peerName << " : " << port; | - | ||||||||||||
678 | - | |||||||||||||
679 | return; never executed: return; | 0 | ||||||||||||
680 | } | - | ||||||||||||
681 | if (0) QMessageLogger(__FILE__, 813, __PRETTY_FUNCTION__).debug() << "sending" << dump(buf); dead code: QMessageLogger(__FILE__, 813, __PRETTY_FUNCTION__).debug() << "sending" << dump(buf); | - | ||||||||||||
682 | QByteArray sealedBuf; | - | ||||||||||||
683 | if (!data->authenticator->seal(buf, &sealedBuf)
| 0-701 | ||||||||||||
684 | - | |||||||||||||
685 | } never executed: end of block | 0 | ||||||||||||
686 | data->controlSocket->write(sealedBuf); | - | ||||||||||||
687 | data->controlSocket->flush(); | - | ||||||||||||
688 | socks5State = RequestMethodSent; | - | ||||||||||||
689 | } executed 701 times by 9 tests: end of block Executed by:
| 701 | ||||||||||||
690 | - | |||||||||||||
691 | void QSocks5SocketEnginePrivate::parseRequestMethodReply() | - | ||||||||||||
692 | { | - | ||||||||||||
693 | QSocks5SocketEngine * const q = q_func(); | - | ||||||||||||
694 | if (0) QMessageLogger(__FILE__, 826, __PRETTY_FUNCTION__).debug() << "parseRequestMethodReply()"; dead code: QMessageLogger(__FILE__, 826, __PRETTY_FUNCTION__).debug() << "parseRequestMethodReply()"; | - | ||||||||||||
695 | - | |||||||||||||
696 | QByteArray inBuf; | - | ||||||||||||
697 | if (!data->authenticator->unSeal(data->controlSocket, &inBuf)
| 0-727 | ||||||||||||
698 | - | |||||||||||||
699 | if (0) QMessageLogger(__FILE__, 831, __PRETTY_FUNCTION__).debug() << "unSeal failed, needs more data"; dead code: QMessageLogger(__FILE__, 831, __PRETTY_FUNCTION__).debug() << "unSeal failed, needs more data"; | - | ||||||||||||
700 | return; never executed: return; | 0 | ||||||||||||
701 | } | - | ||||||||||||
702 | - | |||||||||||||
703 | inBuf.prepend(receivedHeaderFragment); | - | ||||||||||||
704 | receivedHeaderFragment.clear(); | - | ||||||||||||
705 | if (0) QMessageLogger(__FILE__, 837, __PRETTY_FUNCTION__).debug() << dump(inBuf); dead code: QMessageLogger(__FILE__, 837, __PRETTY_FUNCTION__).debug() << dump(inBuf); | - | ||||||||||||
706 | if (inBuf.size() < 3
| 8-719 | ||||||||||||
707 | if (0) QMessageLogger(__FILE__, 839, __PRETTY_FUNCTION__).debug() << "need more data for request reply header .. put this data somewhere"; dead code: QMessageLogger(__FILE__, 839, __PRETTY_FUNCTION__).debug() << "need more data for request reply header .. put this data somewhere"; | - | ||||||||||||
708 | receivedHeaderFragment = inBuf; | - | ||||||||||||
709 | return; executed 8 times by 1 test: return; Executed by:
| 8 | ||||||||||||
710 | } | - | ||||||||||||
711 | - | |||||||||||||
712 | QHostAddress address; | - | ||||||||||||
713 | quint16 port = 0; | - | ||||||||||||
714 | - | |||||||||||||
715 | if (inBuf.at(0) != 0x05
| 0-718 | ||||||||||||
716 | if (0) QMessageLogger(__FILE__, 848, __PRETTY_FUNCTION__).debug() << "socks protocol error"; dead code: QMessageLogger(__FILE__, 848, __PRETTY_FUNCTION__).debug() << "socks protocol error"; | - | ||||||||||||
717 | setErrorState(SocksError); | - | ||||||||||||
718 | } executed 1 time by 1 test: else if (inBuf.at(1) != 0x00end of block Executed by:
| 1-697 | ||||||||||||
719 | Socks5Error socks5Error = Socks5Error(inBuf.at(1)); | - | ||||||||||||
720 | if (0) QMessageLogger(__FILE__, 852, __PRETTY_FUNCTION__).debug() << "Request error :" << socks5Error; dead code: QMessageLogger(__FILE__, 852, __PRETTY_FUNCTION__).debug() << "Request error :" << socks5Error; | - | ||||||||||||
721 | if ((socks5Error == SocksFailure
| 2-19 | ||||||||||||
722 | && !peerName.isEmpty()
| 2-4 | ||||||||||||
723 | - | |||||||||||||
724 | setErrorState(HostNameLookupError); | - | ||||||||||||
725 | } executed 4 times by 2 tests: else {end of block Executed by:
| 4 | ||||||||||||
726 | setErrorState(RequestError, socks5Error); | - | ||||||||||||
727 | } executed 17 times by 3 tests: end of block Executed by:
| 17 | ||||||||||||
728 | } else { | - | ||||||||||||
729 | - | |||||||||||||
730 | int pos = 3; | - | ||||||||||||
731 | int err = qt_socks5_get_host_address_and_port(inBuf, &address, &port, &pos); | - | ||||||||||||
732 | if (err == -1
| 0-697 | ||||||||||||
733 | if (0) QMessageLogger(__FILE__, 865, __PRETTY_FUNCTION__).debug() << "error getting address"; dead code: QMessageLogger(__FILE__, 865, __PRETTY_FUNCTION__).debug() << "error getting address"; | - | ||||||||||||
734 | setErrorState(SocksError); | - | ||||||||||||
735 | } never executed: else if (err == 0end of block
| 0-649 | ||||||||||||
736 | - | |||||||||||||
737 | receivedHeaderFragment = inBuf; | - | ||||||||||||
738 | return; executed 48 times by 1 test: return; Executed by:
| 48 | ||||||||||||
739 | } else { | - | ||||||||||||
740 | inBuf.remove(0, pos); | - | ||||||||||||
741 | for (int i = inBuf.size() - 1; i >= 0
| 0-649 | ||||||||||||
742 | data->controlSocket->ungetChar(inBuf.at(i)); never executed: data->controlSocket->ungetChar(inBuf.at(i)); | 0 | ||||||||||||
743 | } executed 649 times by 7 tests: end of block Executed by:
| 649 | ||||||||||||
744 | } | - | ||||||||||||
745 | - | |||||||||||||
746 | if (socks5State == RequestMethodSent
| 24-647 | ||||||||||||
747 | - | |||||||||||||
748 | localAddress = address; | - | ||||||||||||
749 | localPort = port; | - | ||||||||||||
750 | - | |||||||||||||
751 | if (mode == ConnectMode
| 13-634 | ||||||||||||
752 | socks5State = Connected; | - | ||||||||||||
753 | - | |||||||||||||
754 | q->setState(QAbstractSocket::ConnectedState); | - | ||||||||||||
755 | emitConnectionNotification(); | - | ||||||||||||
756 | } executed 634 times by 7 tests: else if (mode == BindModeend of block Executed by:
| 2-634 | ||||||||||||
757 | socks5State = BindSuccess; | - | ||||||||||||
758 | q->setState(QAbstractSocket::ListeningState); | - | ||||||||||||
759 | } executed 11 times by 3 tests: else {end of block Executed by:
| 11 | ||||||||||||
760 | socks5State = UdpAssociateSuccess; | - | ||||||||||||
761 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
762 | } else if (socks5State == BindSuccess
| 2-22 | ||||||||||||
763 | - | |||||||||||||
764 | bindData->peerAddress = address; | - | ||||||||||||
765 | bindData->peerPort = port; | - | ||||||||||||
766 | - | |||||||||||||
767 | emitReadNotification(); | - | ||||||||||||
768 | } executed 2 times by 2 tests: else {end of block Executed by:
| 2 | ||||||||||||
769 | - | |||||||||||||
770 | data->controlSocket->close(); | - | ||||||||||||
771 | emitConnectionNotification(); | - | ||||||||||||
772 | } executed 22 times by 4 tests: end of block Executed by:
| 22 | ||||||||||||
773 | } | - | ||||||||||||
774 | - | |||||||||||||
775 | void QSocks5SocketEnginePrivate::_q_emitPendingReadNotification() | - | ||||||||||||
776 | { | - | ||||||||||||
777 | QSocks5SocketEngine * const q = q_func(); | - | ||||||||||||
778 | readNotificationPending = false; | - | ||||||||||||
779 | if (readNotificationEnabled
| 0-3112 | ||||||||||||
780 | if (0) QMessageLogger(__FILE__, 912, __PRETTY_FUNCTION__).debug() << "emitting readNotification"; dead code: QMessageLogger(__FILE__, 912, __PRETTY_FUNCTION__).debug() << "emitting readNotification"; | - | ||||||||||||
781 | QPointer<QSocks5SocketEngine> qq = q; | - | ||||||||||||
782 | q->readNotification(); | - | ||||||||||||
783 | if (!qq
| 356-2756 | ||||||||||||
784 | return; executed 356 times by 2 tests: return; Executed by:
| 356 | ||||||||||||
785 | - | |||||||||||||
786 | if (data
| 0-2752 | ||||||||||||
787 | && data->controlSocket->error() == QAbstractSocket::RemoteHostClosedError
| 0 | ||||||||||||
788 | connectData->readBuffer.clear(); | - | ||||||||||||
789 | emitReadNotification(); | - | ||||||||||||
790 | } never executed: end of block | 0 | ||||||||||||
791 | } executed 2756 times by 4 tests: end of block Executed by:
| 2756 | ||||||||||||
792 | } executed 2756 times by 4 tests: end of block Executed by:
| 2756 | ||||||||||||
793 | - | |||||||||||||
794 | void QSocks5SocketEnginePrivate::emitReadNotification() | - | ||||||||||||
795 | { | - | ||||||||||||
796 | QSocks5SocketEngine * const q = q_func(); | - | ||||||||||||
797 | readNotificationActivated = true; | - | ||||||||||||
798 | if (readNotificationEnabled
| 24-3289 | ||||||||||||
799 | if (0) QMessageLogger(__FILE__, 931, __PRETTY_FUNCTION__).debug() << "queueing readNotification"; dead code: QMessageLogger(__FILE__, 931, __PRETTY_FUNCTION__).debug() << "queueing readNotification"; | - | ||||||||||||
800 | readNotificationPending = true; | - | ||||||||||||
801 | QMetaObject::invokeMethod(q, "_q_emitPendingReadNotification", Qt::QueuedConnection); | - | ||||||||||||
802 | } executed 3200 times by 5 tests: end of block Executed by:
| 3200 | ||||||||||||
803 | } executed 3313 times by 6 tests: end of block Executed by:
| 3313 | ||||||||||||
804 | - | |||||||||||||
805 | void QSocks5SocketEnginePrivate::_q_emitPendingWriteNotification() | - | ||||||||||||
806 | { | - | ||||||||||||
807 | writeNotificationPending = false; | - | ||||||||||||
808 | QSocks5SocketEngine * const q = q_func(); | - | ||||||||||||
809 | if (writeNotificationEnabled
| 1637-2135 | ||||||||||||
810 | if (0) QMessageLogger(__FILE__, 942, __PRETTY_FUNCTION__).debug() << "emitting writeNotification"; dead code: QMessageLogger(__FILE__, 942, __PRETTY_FUNCTION__).debug() << "emitting writeNotification"; | - | ||||||||||||
811 | q->writeNotification(); | - | ||||||||||||
812 | } executed 2135 times by 4 tests: end of block Executed by:
| 2135 | ||||||||||||
813 | } executed 3772 times by 4 tests: end of block Executed by:
| 3772 | ||||||||||||
814 | - | |||||||||||||
815 | void QSocks5SocketEnginePrivate::emitWriteNotification() | - | ||||||||||||
816 | { | - | ||||||||||||
817 | QSocks5SocketEngine * const q = q_func(); | - | ||||||||||||
818 | writeNotificationActivated = true; | - | ||||||||||||
819 | if (writeNotificationEnabled
| 357-4401 | ||||||||||||
820 | if (0) QMessageLogger(__FILE__, 952, __PRETTY_FUNCTION__).debug() << "queueing writeNotification"; dead code: QMessageLogger(__FILE__, 952, __PRETTY_FUNCTION__).debug() << "queueing writeNotification"; | - | ||||||||||||
821 | writeNotificationPending = true; | - | ||||||||||||
822 | QMetaObject::invokeMethod(q, "_q_emitPendingWriteNotification", Qt::QueuedConnection); | - | ||||||||||||
823 | } executed 3904 times by 7 tests: end of block Executed by:
| 3904 | ||||||||||||
824 | } executed 4758 times by 7 tests: end of block Executed by:
| 4758 | ||||||||||||
825 | - | |||||||||||||
826 | void QSocks5SocketEnginePrivate::_q_emitPendingConnectionNotification() | - | ||||||||||||
827 | { | - | ||||||||||||
828 | connectionNotificationPending = false; | - | ||||||||||||
829 | QSocks5SocketEngine * const q = q_func(); | - | ||||||||||||
830 | if (0) QMessageLogger(__FILE__, 962, __PRETTY_FUNCTION__).debug() << "emitting connectionNotification"; dead code: QMessageLogger(__FILE__, 962, __PRETTY_FUNCTION__).debug() << "emitting connectionNotification"; | - | ||||||||||||
831 | q->connectionNotification(); | - | ||||||||||||
832 | } executed 598 times by 5 tests: end of block Executed by:
| 598 | ||||||||||||
833 | - | |||||||||||||
834 | void QSocks5SocketEnginePrivate::emitConnectionNotification() | - | ||||||||||||
835 | { | - | ||||||||||||
836 | QSocks5SocketEngine * const q = q_func(); | - | ||||||||||||
837 | if (0) QMessageLogger(__FILE__, 969, __PRETTY_FUNCTION__).debug() << "queueing connectionNotification"; dead code: QMessageLogger(__FILE__, 969, __PRETTY_FUNCTION__).debug() << "queueing connectionNotification"; | - | ||||||||||||
838 | connectionNotificationPending = true; | - | ||||||||||||
839 | QMetaObject::invokeMethod(q, "_q_emitPendingConnectionNotification", Qt::QueuedConnection); | - | ||||||||||||
840 | } executed 699 times by 8 tests: end of block Executed by:
| 699 | ||||||||||||
841 | - | |||||||||||||
842 | QSocks5SocketEngine::QSocks5SocketEngine(QObject *parent) | - | ||||||||||||
843 | :QAbstractSocketEngine(*new QSocks5SocketEnginePrivate(), parent) | - | ||||||||||||
844 | { | - | ||||||||||||
845 | } executed 726 times by 9 tests: end of block Executed by:
| 726 | ||||||||||||
846 | - | |||||||||||||
847 | QSocks5SocketEngine::~QSocks5SocketEngine() | - | ||||||||||||
848 | { | - | ||||||||||||
849 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
850 | - | |||||||||||||
851 | if (d->data
| 7-719 | ||||||||||||
852 | delete d->data->authenticator; | - | ||||||||||||
853 | delete d->data->controlSocket; | - | ||||||||||||
854 | } executed 719 times by 9 tests: end of block Executed by:
| 719 | ||||||||||||
855 | if (d->connectData
| 16-710 | ||||||||||||
856 | delete d->connectData; executed 710 times by 9 tests: delete d->connectData; Executed by:
| 710 | ||||||||||||
857 | - | |||||||||||||
858 | if (d->udpData
| 2-724 | ||||||||||||
859 | delete d->udpData->udpSocket; | - | ||||||||||||
860 | delete d->udpData; | - | ||||||||||||
861 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
862 | - | |||||||||||||
863 | if (d->bindData
| 7-719 | ||||||||||||
864 | delete d->bindData; executed 7 times by 1 test: delete d->bindData; Executed by:
| 7 | ||||||||||||
865 | } executed 726 times by 9 tests: end of block Executed by:
| 726 | ||||||||||||
866 | - | |||||||||||||
867 | static QBasicAtomicInt descriptorCounter = { 1 }; | - | ||||||||||||
868 | - | |||||||||||||
869 | bool QSocks5SocketEngine::initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol) | - | ||||||||||||
870 | { | - | ||||||||||||
871 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
872 | - | |||||||||||||
873 | d->socketDescriptor = descriptorCounter.fetchAndAddRelaxed(1); | - | ||||||||||||
874 | - | |||||||||||||
875 | d->socketType = type; | - | ||||||||||||
876 | d->socketProtocol = protocol; | - | ||||||||||||
877 | - | |||||||||||||
878 | return executed 720 times by 9 tests: true;return true; Executed by:
executed 720 times by 9 tests: return true; Executed by:
| 720 | ||||||||||||
879 | } | - | ||||||||||||
880 | - | |||||||||||||
881 | bool QSocks5SocketEngine::initialize(qintptr socketDescriptor, QAbstractSocket::SocketState socketState) | - | ||||||||||||
882 | { | - | ||||||||||||
883 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
884 | - | |||||||||||||
885 | if (0) QMessageLogger(__FILE__, 1017, __PRETTY_FUNCTION__).debug() << "initialize" << socketDescriptor; dead code: QMessageLogger(__FILE__, 1017, __PRETTY_FUNCTION__).debug() << "initialize" << socketDescriptor; | - | ||||||||||||
886 | - | |||||||||||||
887 | - | |||||||||||||
888 | - | |||||||||||||
889 | if (socketState != QAbstractSocket::ConnectedState
| 0-6 | ||||||||||||
890 | - | |||||||||||||
891 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
892 | } | - | ||||||||||||
893 | - | |||||||||||||
894 | QSocks5BindData *bindData = socks5BindStore()->retrieve(socketDescriptor); | - | ||||||||||||
895 | if (bindData
| 0-6 | ||||||||||||
896 | - | |||||||||||||
897 | d->socketState = QAbstractSocket::ConnectedState; | - | ||||||||||||
898 | d->socketType = QAbstractSocket::TcpSocket; | - | ||||||||||||
899 | d->connectData = new QSocks5ConnectData; | - | ||||||||||||
900 | d->data = d->connectData; | - | ||||||||||||
901 | d->mode = QSocks5SocketEnginePrivate::ConnectMode; | - | ||||||||||||
902 | d->data->controlSocket = bindData->controlSocket; | - | ||||||||||||
903 | bindData->controlSocket = 0; | - | ||||||||||||
904 | d->data->controlSocket->setParent(this); | - | ||||||||||||
905 | d->socketProtocol = d->data->controlSocket->localAddress().protocol(); | - | ||||||||||||
906 | d->data->authenticator = bindData->authenticator; | - | ||||||||||||
907 | bindData->authenticator = 0; | - | ||||||||||||
908 | d->localPort = bindData->localPort; | - | ||||||||||||
909 | d->localAddress = bindData->localAddress; | - | ||||||||||||
910 | d->peerPort = bindData->peerPort; | - | ||||||||||||
911 | d->peerAddress = bindData->peerAddress; | - | ||||||||||||
912 | delete bindData; | - | ||||||||||||
913 | - | |||||||||||||
914 | QObject::connect(d->data->controlSocket, qFlagLocation("2""connected()" "\0" __FILE__ ":" "1046"), this, qFlagLocation("1""_q_controlSocketConnected()" "\0" __FILE__ ":" "1046"), | - | ||||||||||||
915 | Qt::DirectConnection); | - | ||||||||||||
916 | QObject::connect(d->data->controlSocket, qFlagLocation("2""readyRead()" "\0" __FILE__ ":" "1048"), this, qFlagLocation("1""_q_controlSocketReadNotification()" "\0" __FILE__ ":" "1048"), | - | ||||||||||||
917 | Qt::DirectConnection); | - | ||||||||||||
918 | QObject::connect(d->data->controlSocket, qFlagLocation("2""bytesWritten(qint64)" "\0" __FILE__ ":" "1050"), this, qFlagLocation("1""_q_controlSocketBytesWritten()" "\0" __FILE__ ":" "1050"), | - | ||||||||||||
919 | Qt::DirectConnection); | - | ||||||||||||
920 | QObject::connect(d->data->controlSocket, qFlagLocation("2""error(QAbstractSocket::SocketError)" "\0" __FILE__ ":" "1052"), this, qFlagLocation("1""_q_controlSocketError(QAbstractSocket::SocketError)" "\0" __FILE__ ":" "1052"), | - | ||||||||||||
921 | Qt::DirectConnection); | - | ||||||||||||
922 | QObject::connect(d->data->controlSocket, qFlagLocation("2""disconnected()" "\0" __FILE__ ":" "1054"), this, qFlagLocation("1""_q_controlSocketDisconnected()" "\0" __FILE__ ":" "1054"), | - | ||||||||||||
923 | Qt::DirectConnection); | - | ||||||||||||
924 | QObject::connect(d->data->controlSocket, qFlagLocation("2""stateChanged(QAbstractSocket::SocketState)" "\0" __FILE__ ":" "1056"), | - | ||||||||||||
925 | this, qFlagLocation("1""_q_controlSocketStateChanged(QAbstractSocket::SocketState)" "\0" __FILE__ ":" "1057"), | - | ||||||||||||
926 | Qt::DirectConnection); | - | ||||||||||||
927 | - | |||||||||||||
928 | d->socks5State = QSocks5SocketEnginePrivate::Connected; | - | ||||||||||||
929 | - | |||||||||||||
930 | if (d->data->controlSocket->bytesAvailable() != 0
| 0-6 | ||||||||||||
931 | d->_q_controlSocketReadNotification(); never executed: d->_q_controlSocketReadNotification(); | 0 | ||||||||||||
932 | return executed 6 times by 3 tests: true;return true; Executed by:
executed 6 times by 3 tests: return true; Executed by:
| 6 | ||||||||||||
933 | } | - | ||||||||||||
934 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
935 | } | - | ||||||||||||
936 | - | |||||||||||||
937 | void QSocks5SocketEngine::setProxy(const QNetworkProxy &networkProxy) | - | ||||||||||||
938 | { | - | ||||||||||||
939 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
940 | d->proxyInfo = networkProxy; | - | ||||||||||||
941 | } executed 719 times by 9 tests: end of block Executed by:
| 719 | ||||||||||||
942 | - | |||||||||||||
943 | qintptr QSocks5SocketEngine::socketDescriptor() const | - | ||||||||||||
944 | { | - | ||||||||||||
945 | const QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
946 | return executed 1090 times by 9 tests: d->socketDescriptor;return d->socketDescriptor; Executed by:
executed 1090 times by 9 tests: return d->socketDescriptor; Executed by:
| 1090 | ||||||||||||
947 | } | - | ||||||||||||
948 | - | |||||||||||||
949 | bool QSocks5SocketEngine::isValid() const | - | ||||||||||||
950 | { | - | ||||||||||||
951 | const QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
952 | return executed 6842 times by 6 tests: d->socketType != QAbstractSocket::UnknownSocketTypereturn d->socketType != QAbstractSocket::UnknownSocketType && d->socks5State != QSocks5SocketEnginePrivate::SocksError && (d->socketError == QAbstractSocket::UnknownSocketError || d->socketError == QAbstractSocket::SocketTimeoutError || d->socketError == QAbstractSocket::UnfinishedSocketOperationError); Executed by:
executed 6842 times by 6 tests: return d->socketType != QAbstractSocket::UnknownSocketType && d->socks5State != QSocks5SocketEnginePrivate::SocksError && (d->socketError == QAbstractSocket::UnknownSocketError || d->socketError == QAbstractSocket::SocketTimeoutError || d->socketError == QAbstractSocket::UnfinishedSocketOperationError); Executed by:
| 1-6842 | ||||||||||||
953 | && d->socks5State != QSocks5SocketEnginePrivate::SocksError
executed 6842 times by 6 tests: return d->socketType != QAbstractSocket::UnknownSocketType && d->socks5State != QSocks5SocketEnginePrivate::SocksError && (d->socketError == QAbstractSocket::UnknownSocketError || d->socketError == QAbstractSocket::SocketTimeoutError || d->socketError == QAbstractSocket::UnfinishedSocketOperationError); Executed by:
| 0-6842 | ||||||||||||
954 | && (d->socketError == QAbstractSocket::UnknownSocketError
executed 6842 times by 6 tests: return d->socketType != QAbstractSocket::UnknownSocketType && d->socks5State != QSocks5SocketEnginePrivate::SocksError && (d->socketError == QAbstractSocket::UnknownSocketError || d->socketError == QAbstractSocket::SocketTimeoutError || d->socketError == QAbstractSocket::UnfinishedSocketOperationError); Executed by:
| 350-6842 | ||||||||||||
955 | || d->socketError == QAbstractSocket::SocketTimeoutError
executed 6842 times by 6 tests: return d->socketType != QAbstractSocket::UnknownSocketType && d->socks5State != QSocks5SocketEnginePrivate::SocksError && (d->socketError == QAbstractSocket::UnknownSocketError || d->socketError == QAbstractSocket::SocketTimeoutError || d->socketError == QAbstractSocket::UnfinishedSocketOperationError); Executed by:
| 0-6842 | ||||||||||||
956 | || d->socketError == QAbstractSocket::UnfinishedSocketOperationError
executed 6842 times by 6 tests: return d->socketType != QAbstractSocket::UnknownSocketType && d->socks5State != QSocks5SocketEnginePrivate::SocksError && (d->socketError == QAbstractSocket::UnknownSocketError || d->socketError == QAbstractSocket::SocketTimeoutError || d->socketError == QAbstractSocket::UnfinishedSocketOperationError); Executed by:
| 0-6842 | ||||||||||||
957 | } | - | ||||||||||||
958 | - | |||||||||||||
959 | bool QSocks5SocketEngine::connectInternal() | - | ||||||||||||
960 | { | - | ||||||||||||
961 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
962 | - | |||||||||||||
963 | if (!d->data
| 4-705 | ||||||||||||
964 | if (socketType() == QAbstractSocket::TcpSocket
| 1-704 | ||||||||||||
965 | d->initialize(QSocks5SocketEnginePrivate::ConnectMode); | - | ||||||||||||
966 | - | |||||||||||||
967 | } executed 704 times by 9 tests: else if (socketType() == QAbstractSocket::UdpSocketend of block Executed by:
| 0-704 | ||||||||||||
968 | d->initialize(QSocks5SocketEnginePrivate::UdpAssociateMode); | - | ||||||||||||
969 | - | |||||||||||||
970 | if (!bind(QHostAddress(QLatin1String("0.0.0.0")), 0)
| 0-1 | ||||||||||||
971 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
972 | - | |||||||||||||
973 | setState(QAbstractSocket::ConnectedState); | - | ||||||||||||
974 | return executed 1 time by 1 test: true;return true; Executed by:
executed 1 time by 1 test: return true; Executed by:
| 1 | ||||||||||||
975 | - | |||||||||||||
976 | } else { | - | ||||||||||||
977 | QMessageLogger(__FILE__, 1109, __PRETTY_FUNCTION__).fatal("QSocks5SocketEngine::connectToHost: in QTcpServer mode"); | - | ||||||||||||
978 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
979 | } | - | ||||||||||||
980 | } | - | ||||||||||||
981 | - | |||||||||||||
982 | if (d->socketState != QAbstractSocket::ConnectingState
| 0-708 | ||||||||||||
983 | if (d->socks5State == QSocks5SocketEnginePrivate::Uninitialized
| 4-704 | ||||||||||||
984 | - | |||||||||||||
985 | || d->socks5State == QSocks5SocketEnginePrivate::AuthenticatingError
| 2 | ||||||||||||
986 | setState(QAbstractSocket::ConnectingState); | - | ||||||||||||
987 | - | |||||||||||||
988 | d->data->controlSocket->setReadBufferSize(65536); | - | ||||||||||||
989 | } executed 706 times by 9 tests: end of block Executed by:
| 706 | ||||||||||||
990 | - | |||||||||||||
991 | d->data->controlSocket->connectToHost(d->proxyInfo.hostName(), d->proxyInfo.port()); | - | ||||||||||||
992 | } executed 708 times by 9 tests: end of block Executed by:
| 708 | ||||||||||||
993 | - | |||||||||||||
994 | return executed 708 times by 9 tests: false;return false; Executed by:
executed 708 times by 9 tests: return false; Executed by:
| 708 | ||||||||||||
995 | } | - | ||||||||||||
996 | - | |||||||||||||
997 | bool QSocks5SocketEngine::connectToHost(const QHostAddress &address, quint16 port) | - | ||||||||||||
998 | { | - | ||||||||||||
999 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1000 | if (0) QMessageLogger(__FILE__, 1132, __PRETTY_FUNCTION__).debug() << "connectToHost" << address << ':' << port; dead code: QMessageLogger(__FILE__, 1132, __PRETTY_FUNCTION__).debug() << "connectToHost" << address << ':' << port; | - | ||||||||||||
1001 | - | |||||||||||||
1002 | setPeerAddress(address); | - | ||||||||||||
1003 | setPeerPort(port); | - | ||||||||||||
1004 | d->peerName.clear(); | - | ||||||||||||
1005 | - | |||||||||||||
1006 | return executed 249 times by 5 tests: connectInternal();return connectInternal(); Executed by:
executed 249 times by 5 tests: return connectInternal(); Executed by:
| 249 | ||||||||||||
1007 | } | - | ||||||||||||
1008 | - | |||||||||||||
1009 | bool QSocks5SocketEngine::connectToHostByName(const QString &hostname, quint16 port) | - | ||||||||||||
1010 | { | - | ||||||||||||
1011 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1012 | - | |||||||||||||
1013 | setPeerAddress(QHostAddress()); | - | ||||||||||||
1014 | setPeerPort(port); | - | ||||||||||||
1015 | d->peerName = hostname; | - | ||||||||||||
1016 | - | |||||||||||||
1017 | return executed 460 times by 7 tests: connectInternal();return connectInternal(); Executed by:
executed 460 times by 7 tests: return connectInternal(); Executed by:
| 460 | ||||||||||||
1018 | } | - | ||||||||||||
1019 | - | |||||||||||||
1020 | void QSocks5SocketEnginePrivate::_q_controlSocketConnected() | - | ||||||||||||
1021 | { | - | ||||||||||||
1022 | if (0) QMessageLogger(__FILE__, 1154, __PRETTY_FUNCTION__).debug() << "_q_controlSocketConnected"; dead code: QMessageLogger(__FILE__, 1154, __PRETTY_FUNCTION__).debug() << "_q_controlSocketConnected"; | - | ||||||||||||
1023 | QByteArray buf(3, 0); | - | ||||||||||||
1024 | buf[0] = 0x05; | - | ||||||||||||
1025 | buf[1] = 0x01; | - | ||||||||||||
1026 | buf[2] = data->authenticator->methodId(); | - | ||||||||||||
1027 | data->controlSocket->write(buf); | - | ||||||||||||
1028 | socks5State = AuthenticationMethodsSent; | - | ||||||||||||
1029 | } executed 798 times by 9 tests: end of block Executed by:
| 798 | ||||||||||||
1030 | - | |||||||||||||
1031 | void QSocks5SocketEnginePrivate::_q_controlSocketReadNotification() | - | ||||||||||||
1032 | { | - | ||||||||||||
1033 | if (0) QMessageLogger(__FILE__, 1165, __PRETTY_FUNCTION__).debug() << "_q_controlSocketReadNotification socks5state" << s5StateToString(socks5State) dead code: QMessageLogger(__FILE__, 1165, __PRETTY_FUNCTION__).debug() << "_q_controlSocketReadNotification socks5state" << s5StateToString(socks5State) << "bytes available" << data->controlSocket->bytesAvailable(); | - | ||||||||||||
1034 | << "bytes available" << data->controlSocket->bytesAvailable(); dead code: QMessageLogger(__FILE__, 1165, __PRETTY_FUNCTION__).debug() << "_q_controlSocketReadNotification socks5state" << s5StateToString(socks5State) << "bytes available" << data->controlSocket->bytesAvailable(); | - | ||||||||||||
1035 | - | |||||||||||||
1036 | if (data->controlSocket->bytesAvailable() == 0
| 0-4548 | ||||||||||||
1037 | if (0) QMessageLogger(__FILE__, 1169, __PRETTY_FUNCTION__).debug() << "########## bogus read why do we get these ... on windows only"; dead code: QMessageLogger(__FILE__, 1169, __PRETTY_FUNCTION__).debug() << "########## bogus read why do we get these ... on windows only"; | - | ||||||||||||
1038 | return; never executed: return; | 0 | ||||||||||||
1039 | } | - | ||||||||||||
1040 | - | |||||||||||||
1041 | switch (socks5State) { | - | ||||||||||||
1042 | case executed 796 times by 9 tests: AuthenticationMethodsSent:case AuthenticationMethodsSent: Executed by:
executed 796 times by 9 tests: case AuthenticationMethodsSent: Executed by:
| 796 | ||||||||||||
1043 | parseAuthenticationMethodReply(); | - | ||||||||||||
1044 | break; executed 796 times by 9 tests: break; Executed by:
| 796 | ||||||||||||
1045 | case executed 90 times by 7 tests: Authenticating:case Authenticating: Executed by:
executed 90 times by 7 tests: case Authenticating: Executed by:
| 90 | ||||||||||||
1046 | parseAuthenticatingReply(); | - | ||||||||||||
1047 | break; executed 90 times by 7 tests: break; Executed by:
| 90 | ||||||||||||
1048 | case executed 725 times by 8 tests: RequestMethodSent:case RequestMethodSent: Executed by:
executed 725 times by 8 tests: case RequestMethodSent: Executed by:
| 725 | ||||||||||||
1049 | parseRequestMethodReply(); | - | ||||||||||||
1050 | break; executed 725 times by 8 tests: break; Executed by:
| 725 | ||||||||||||
1051 | case executed 2935 times by 6 tests: Connected:case Connected: Executed by:
executed 2935 times by 6 tests: {case Connected: Executed by:
| 2935 | ||||||||||||
1052 | QByteArray buf; | - | ||||||||||||
1053 | if (!data->authenticator->unSeal(data->controlSocket, &buf)
| 0-2935 | ||||||||||||
1054 | - | |||||||||||||
1055 | } never executed: end of block | 0 | ||||||||||||
1056 | if (buf.size()
| 0-2935 | ||||||||||||
1057 | if (0) QMessageLogger(__FILE__, 1189, __PRETTY_FUNCTION__).debug() << dump(buf); dead code: QMessageLogger(__FILE__, 1189, __PRETTY_FUNCTION__).debug() << dump(buf); | - | ||||||||||||
1058 | connectData->readBuffer += buf; | - | ||||||||||||
1059 | emitReadNotification(); | - | ||||||||||||
1060 | } executed 2935 times by 6 tests: end of block Executed by:
| 2935 | ||||||||||||
1061 | break; executed 2935 times by 6 tests: break; Executed by:
| 2935 | ||||||||||||
1062 | } | - | ||||||||||||
1063 | case executed 2 times by 2 tests: BindSuccess:case BindSuccess: Executed by:
executed 2 times by 2 tests: case BindSuccess: Executed by:
| 2 | ||||||||||||
1064 | - | |||||||||||||
1065 | if (mode == BindMode
| 0-2 | ||||||||||||
1066 | parseRequestMethodReply(); | - | ||||||||||||
1067 | break; executed 2 times by 2 tests: break; Executed by:
| 2 | ||||||||||||
1068 | } | - | ||||||||||||
1069 | - | |||||||||||||
1070 | - | |||||||||||||
1071 | default never executed: :default: never executed: default: code before this statement never executed: default: | 0 | ||||||||||||
1072 | QMessageLogger(__FILE__, 1204, __PRETTY_FUNCTION__).warning("QSocks5SocketEnginePrivate::_q_controlSocketReadNotification: " | - | ||||||||||||
1073 | "Unexpectedly received data while in state=%d and mode=%d", | - | ||||||||||||
1074 | socks5State, mode); | - | ||||||||||||
1075 | break; never executed: break; | 0 | ||||||||||||
1076 | }; | - | ||||||||||||
1077 | } | - | ||||||||||||
1078 | - | |||||||||||||
1079 | void QSocks5SocketEnginePrivate::_q_controlSocketBytesWritten() | - | ||||||||||||
1080 | { | - | ||||||||||||
1081 | if (0) QMessageLogger(__FILE__, 1213, __PRETTY_FUNCTION__).debug() << "_q_controlSocketBytesWritten"; dead code: QMessageLogger(__FILE__, 1213, __PRETTY_FUNCTION__).debug() << "_q_controlSocketBytesWritten"; | - | ||||||||||||
1082 | - | |||||||||||||
1083 | if (socks5State != Connected
| 1588-1887 | ||||||||||||
1084 | || (mode == ConnectMode
| 0-1887 | ||||||||||||
1085 | && data->controlSocket->bytesToWrite()
| 4-1883 | ||||||||||||
1086 | return; executed 1592 times by 9 tests: return; Executed by:
| 1592 | ||||||||||||
1087 | if (data->controlSocket->bytesToWrite() < MaxWriteBufferSize
| 0-1883 | ||||||||||||
1088 | emitWriteNotification(); | - | ||||||||||||
1089 | writeNotificationActivated = false; | - | ||||||||||||
1090 | } executed 1883 times by 6 tests: end of block Executed by:
| 1883 | ||||||||||||
1091 | } executed 1883 times by 6 tests: end of block Executed by:
| 1883 | ||||||||||||
1092 | - | |||||||||||||
1093 | void QSocks5SocketEnginePrivate::_q_controlSocketError(QAbstractSocket::SocketError error) | - | ||||||||||||
1094 | { | - | ||||||||||||
1095 | if (0) QMessageLogger(__FILE__, 1227, __PRETTY_FUNCTION__).debug() << "controlSocketError" << error << data->controlSocket->errorString(); dead code: QMessageLogger(__FILE__, 1227, __PRETTY_FUNCTION__).debug() << "controlSocketError" << error << data->controlSocket->errorString(); | - | ||||||||||||
1096 | - | |||||||||||||
1097 | if (error == QAbstractSocket::SocketTimeoutError
| 31-391 | ||||||||||||
1098 | return; executed 31 times by 5 tests: return; Executed by:
| 31 | ||||||||||||
1099 | - | |||||||||||||
1100 | if (error == QAbstractSocket::RemoteHostClosedError
| 8-383 | ||||||||||||
1101 | && socks5State == Connected
| 30-353 | ||||||||||||
1102 | - | |||||||||||||
1103 | - | |||||||||||||
1104 | if (!readNotificationPending
| 2-351 | ||||||||||||
1105 | connectData->readBuffer.clear(); executed 351 times by 2 tests: connectData->readBuffer.clear(); Executed by:
| 351 | ||||||||||||
1106 | emitReadNotification(); | - | ||||||||||||
1107 | data->controlSocket->close(); | - | ||||||||||||
1108 | - | |||||||||||||
1109 | emitWriteNotification(); | - | ||||||||||||
1110 | } executed 353 times by 3 tests: else if (socks5State == Uninitializedend of block Executed by:
| 6-353 | ||||||||||||
1111 | || socks5State == AuthenticationMethodsSent
| 1-31 | ||||||||||||
1112 | || socks5State == Authenticating
| 1-30 | ||||||||||||
1113 | || socks5State == RequestMethodSent
| 2-28 | ||||||||||||
1114 | setErrorState(socks5State == Uninitialized ? ConnectError : ControlSocketError); | - | ||||||||||||
1115 | data->controlSocket->close(); | - | ||||||||||||
1116 | emitConnectionNotification(); | - | ||||||||||||
1117 | } executed 36 times by 4 tests: else {end of block Executed by:
| 36 | ||||||||||||
1118 | q_func()->setError(data->controlSocket->error(), data->controlSocket->errorString()); | - | ||||||||||||
1119 | emitReadNotification(); | - | ||||||||||||
1120 | emitWriteNotification(); | - | ||||||||||||
1121 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
1122 | } | - | ||||||||||||
1123 | - | |||||||||||||
1124 | void QSocks5SocketEnginePrivate::_q_controlSocketDisconnected() | - | ||||||||||||
1125 | { | - | ||||||||||||
1126 | if (0) QMessageLogger(__FILE__, 1258, __PRETTY_FUNCTION__).debug() << "_q_controlSocketDisconnected"; dead code: QMessageLogger(__FILE__, 1258, __PRETTY_FUNCTION__).debug() << "_q_controlSocketDisconnected"; | - | ||||||||||||
1127 | } executed 713 times by 9 tests: end of block Executed by:
| 713 | ||||||||||||
1128 | - | |||||||||||||
1129 | void QSocks5SocketEnginePrivate::_q_controlSocketStateChanged(QAbstractSocket::SocketState state) | - | ||||||||||||
1130 | { | - | ||||||||||||
1131 | if (0) QMessageLogger(__FILE__, 1263, __PRETTY_FUNCTION__).debug() << "_q_controlSocketStateChanged" << state; dead code: QMessageLogger(__FILE__, 1263, __PRETTY_FUNCTION__).debug() << "_q_controlSocketStateChanged" << state; | - | ||||||||||||
1132 | } executed 3835 times by 9 tests: end of block Executed by:
| 3835 | ||||||||||||
1133 | - | |||||||||||||
1134 | - | |||||||||||||
1135 | void QSocks5SocketEnginePrivate::checkForDatagrams() const | - | ||||||||||||
1136 | { | - | ||||||||||||
1137 | - | |||||||||||||
1138 | if (udpData->udpSocket->hasPendingDatagrams()
| 0 | ||||||||||||
1139 | const_cast< never executed: QSocks5SocketEnginePrivate *>(this)->_q_udpSocketReadNotification();const_cast<QSocks5SocketEnginePrivate *>(this)->_q_udpSocketReadNotification(); never executed: const_cast<QSocks5SocketEnginePrivate *>(this)->_q_udpSocketReadNotification(); | 0 | ||||||||||||
1140 | } never executed: end of block | 0 | ||||||||||||
1141 | - | |||||||||||||
1142 | void QSocks5SocketEnginePrivate::_q_udpSocketReadNotification() | - | ||||||||||||
1143 | { | - | ||||||||||||
1144 | if (0) QMessageLogger(__FILE__, 1276, __PRETTY_FUNCTION__).debug() << "_q_udpSocketReadNotification()"; dead code: QMessageLogger(__FILE__, 1276, __PRETTY_FUNCTION__).debug() << "_q_udpSocketReadNotification()"; | - | ||||||||||||
1145 | - | |||||||||||||
1146 | - | |||||||||||||
1147 | if (!udpData->udpSocket->hasPendingDatagrams()
| 0 | ||||||||||||
1148 | if (0) QMessageLogger(__FILE__, 1280, __PRETTY_FUNCTION__).debug() << "false read ??"; dead code: QMessageLogger(__FILE__, 1280, __PRETTY_FUNCTION__).debug() << "false read ??"; | - | ||||||||||||
1149 | return; never executed: return; | 0 | ||||||||||||
1150 | } | - | ||||||||||||
1151 | - | |||||||||||||
1152 | while (udpData->udpSocket->hasPendingDatagrams()
| 0 | ||||||||||||
1153 | QByteArray sealedBuf(udpData->udpSocket->pendingDatagramSize(), 0); | - | ||||||||||||
1154 | if (0) QMessageLogger(__FILE__, 1286, __PRETTY_FUNCTION__).debug() << "new datagram"; dead code: QMessageLogger(__FILE__, 1286, __PRETTY_FUNCTION__).debug() << "new datagram"; | - | ||||||||||||
1155 | udpData->udpSocket->readDatagram(sealedBuf.data(), sealedBuf.size()); | - | ||||||||||||
1156 | QByteArray inBuf; | - | ||||||||||||
1157 | if (!data->authenticator->unSeal(sealedBuf, &inBuf)
| 0 | ||||||||||||
1158 | if (0) QMessageLogger(__FILE__, 1290, __PRETTY_FUNCTION__).debug() << "failed unsealing datagram discarding"; dead code: QMessageLogger(__FILE__, 1290, __PRETTY_FUNCTION__).debug() << "failed unsealing datagram discarding"; | - | ||||||||||||
1159 | return; never executed: return; | 0 | ||||||||||||
1160 | } | - | ||||||||||||
1161 | if (0) QMessageLogger(__FILE__, 1293, __PRETTY_FUNCTION__).debug() << dump(inBuf); dead code: QMessageLogger(__FILE__, 1293, __PRETTY_FUNCTION__).debug() << dump(inBuf); | - | ||||||||||||
1162 | int pos = 0; | - | ||||||||||||
1163 | const char *buf = inBuf.constData(); | - | ||||||||||||
1164 | if (inBuf.size() < 4
| 0 | ||||||||||||
1165 | if (0) QMessageLogger(__FILE__, 1297, __PRETTY_FUNCTION__).debug() << "bugus udp data, discarding"; dead code: QMessageLogger(__FILE__, 1297, __PRETTY_FUNCTION__).debug() << "bugus udp data, discarding"; | - | ||||||||||||
1166 | return; never executed: return; | 0 | ||||||||||||
1167 | } | - | ||||||||||||
1168 | QSocks5RevivedDatagram datagram; | - | ||||||||||||
1169 | if (buf[pos++] != 0
| 0 | ||||||||||||
1170 | if (0) QMessageLogger(__FILE__, 1302, __PRETTY_FUNCTION__).debug() << "invalid datagram discarding"; dead code: QMessageLogger(__FILE__, 1302, __PRETTY_FUNCTION__).debug() << "invalid datagram discarding"; | - | ||||||||||||
1171 | return; never executed: return; | 0 | ||||||||||||
1172 | } | - | ||||||||||||
1173 | if (buf[pos++] != 0
| 0 | ||||||||||||
1174 | if (0) QMessageLogger(__FILE__, 1306, __PRETTY_FUNCTION__).debug() << "don't support fragmentation yet disgarding"; dead code: QMessageLogger(__FILE__, 1306, __PRETTY_FUNCTION__).debug() << "don't support fragmentation yet disgarding"; | - | ||||||||||||
1175 | return; never executed: return; | 0 | ||||||||||||
1176 | } | - | ||||||||||||
1177 | if (qt_socks5_get_host_address_and_port(inBuf, &datagram.address, &datagram.port, &pos) != 1
| 0 | ||||||||||||
1178 | if (0) QMessageLogger(__FILE__, 1310, __PRETTY_FUNCTION__).debug() << "failed to get address from datagram disgarding"; dead code: QMessageLogger(__FILE__, 1310, __PRETTY_FUNCTION__).debug() << "failed to get address from datagram disgarding"; | - | ||||||||||||
1179 | return; never executed: return; | 0 | ||||||||||||
1180 | } | - | ||||||||||||
1181 | datagram.data = QByteArray(&buf[pos], inBuf.size() - pos); | - | ||||||||||||
1182 | udpData->pendingDatagrams.enqueue(datagram); | - | ||||||||||||
1183 | } never executed: end of block | 0 | ||||||||||||
1184 | emitReadNotification(); | - | ||||||||||||
1185 | } never executed: end of block | 0 | ||||||||||||
1186 | - | |||||||||||||
1187 | - | |||||||||||||
1188 | bool QSocks5SocketEngine::bind(const QHostAddress &addr, quint16 port) | - | ||||||||||||
1189 | { | - | ||||||||||||
1190 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1191 | - | |||||||||||||
1192 | - | |||||||||||||
1193 | - | |||||||||||||
1194 | QHostAddress address; | - | ||||||||||||
1195 | if (addr.protocol() == QAbstractSocket::AnyIPProtocol
| 7-8 | ||||||||||||
1196 | address = QHostAddress::AnyIPv4; executed 8 times by 1 test: address = QHostAddress::AnyIPv4; Executed by:
| 8 | ||||||||||||
1197 | else | - | ||||||||||||
1198 | address = addr; executed 7 times by 2 tests: address = addr; Executed by:
| 7 | ||||||||||||
1199 | - | |||||||||||||
1200 | if (!d->data
| 1-14 | ||||||||||||
1201 | if (socketType() == QAbstractSocket::TcpSocket
| 1-13 | ||||||||||||
1202 | d->initialize(QSocks5SocketEnginePrivate::BindMode); | - | ||||||||||||
1203 | - | |||||||||||||
1204 | } executed 13 times by 3 tests: else if (socketType() == QAbstractSocket::UdpSocketend of block Executed by:
| 0-13 | ||||||||||||
1205 | d->initialize(QSocks5SocketEnginePrivate::UdpAssociateMode); | - | ||||||||||||
1206 | - | |||||||||||||
1207 | } executed 1 time by 1 test: else {end of block Executed by:
| 1 | ||||||||||||
1208 | - | |||||||||||||
1209 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
1210 | } | - | ||||||||||||
1211 | } | - | ||||||||||||
1212 | - | |||||||||||||
1213 | - | |||||||||||||
1214 | if (d->mode == QSocks5SocketEnginePrivate::UdpAssociateMode
| 2-13 | ||||||||||||
1215 | if (!d->udpData->udpSocket->bind(address, port)
| 0-2 | ||||||||||||
1216 | if (0) QMessageLogger(__FILE__, 1348, __PRETTY_FUNCTION__).debug() << "local udp bind failed"; dead code: QMessageLogger(__FILE__, 1348, __PRETTY_FUNCTION__).debug() << "local udp bind failed"; | - | ||||||||||||
1217 | setError(d->udpData->udpSocket->error(), d->udpData->udpSocket->errorString()); | - | ||||||||||||
1218 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
1219 | } | - | ||||||||||||
1220 | d->localAddress = d->udpData->udpSocket->localAddress(); | - | ||||||||||||
1221 | d->localPort = d->udpData->udpSocket->localPort(); | - | ||||||||||||
1222 | } executed 2 times by 1 test: elseend of block Executed by:
| 2 | ||||||||||||
1223 | - | |||||||||||||
1224 | if (d->mode == QSocks5SocketEnginePrivate::BindMode
| 0-13 | ||||||||||||
1225 | d->localAddress = address; | - | ||||||||||||
1226 | d->localPort = port; | - | ||||||||||||
1227 | } executed 13 times by 3 tests: else {end of block Executed by:
| 13 | ||||||||||||
1228 | - | |||||||||||||
1229 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
1230 | } | - | ||||||||||||
1231 | - | |||||||||||||
1232 | int msecs = 5000; | - | ||||||||||||
1233 | QElapsedTimer stopWatch; | - | ||||||||||||
1234 | stopWatch.start(); | - | ||||||||||||
1235 | d->data->controlSocket->connectToHost(d->proxyInfo.hostName(), d->proxyInfo.port()); | - | ||||||||||||
1236 | if (!d->waitForConnected(msecs, 0)
| 1-14 | ||||||||||||
1237 | d->data->controlSocket->state() == QAbstractSocket::UnconnectedState
| 1-13 | ||||||||||||
1238 | - | |||||||||||||
1239 | if (0) QMessageLogger(__FILE__, 1371, __PRETTY_FUNCTION__).debug() << "waitForConnected to proxy server" << d->data->controlSocket->errorString(); dead code: QMessageLogger(__FILE__, 1371, __PRETTY_FUNCTION__).debug() << "waitForConnected to proxy server" << d->data->controlSocket->errorString(); | - | ||||||||||||
1240 | return executed 2 times by 1 test: false;return false; Executed by:
executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||
1241 | } | - | ||||||||||||
1242 | if (d->socks5State == QSocks5SocketEnginePrivate::BindSuccess
| 2-11 | ||||||||||||
1243 | setState(QAbstractSocket::BoundState); | - | ||||||||||||
1244 | return executed 11 times by 3 tests: true;return true; Executed by:
executed 11 times by 3 tests: return true; Executed by:
| 11 | ||||||||||||
1245 | - | |||||||||||||
1246 | } else if (d->socks5State == QSocks5SocketEnginePrivate::UdpAssociateSuccess
| 0-2 | ||||||||||||
1247 | setState(QAbstractSocket::BoundState); | - | ||||||||||||
1248 | d->udpData->associateAddress = d->localAddress; | - | ||||||||||||
1249 | d->localAddress = QHostAddress(); | - | ||||||||||||
1250 | d->udpData->associatePort = d->localPort; | - | ||||||||||||
1251 | d->localPort = 0; | - | ||||||||||||
1252 | QUdpSocket dummy; | - | ||||||||||||
1253 | - | |||||||||||||
1254 | dummy.setProperty("_q_networksession", property("_q_networksession")); | - | ||||||||||||
1255 | - | |||||||||||||
1256 | dummy.setProxy(QNetworkProxy::NoProxy); | - | ||||||||||||
1257 | if (!dummy.bind()
| 0-2 | ||||||||||||
1258 | || writeDatagram(0,0, QIpPacketHeader(d->data->controlSocket->localAddress(), dummy.localPort())) != 0
| 0-2 | ||||||||||||
1259 | || !dummy.waitForReadyRead(qt_subtract_from_timeout(msecs, stopWatch.elapsed()))
| 0-2 | ||||||||||||
1260 | || dummy.readDatagram(0,0, &d->localAddress, &d->localPort) != 0
| 0-2 | ||||||||||||
1261 | if (0) QMessageLogger(__FILE__, 1393, __PRETTY_FUNCTION__).debug() << "udp actual address and port lookup failed"; dead code: QMessageLogger(__FILE__, 1393, __PRETTY_FUNCTION__).debug() << "udp actual address and port lookup failed"; | - | ||||||||||||
1262 | setState(QAbstractSocket::UnconnectedState); | - | ||||||||||||
1263 | setError(dummy.error(), dummy.errorString()); | - | ||||||||||||
1264 | d->data->controlSocket->close(); | - | ||||||||||||
1265 | - | |||||||||||||
1266 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
1267 | } | - | ||||||||||||
1268 | if (0) QMessageLogger(__FILE__, 1400, __PRETTY_FUNCTION__).debug() << "udp actual address and port" << d->localAddress << ':' << d->localPort; dead code: QMessageLogger(__FILE__, 1400, __PRETTY_FUNCTION__).debug() << "udp actual address and port" << d->localAddress << ':' << d->localPort; | - | ||||||||||||
1269 | return executed 2 times by 1 test: true;return true; Executed by:
executed 2 times by 1 test: return true; Executed by:
| 2 | ||||||||||||
1270 | - | |||||||||||||
1271 | } | - | ||||||||||||
1272 | - | |||||||||||||
1273 | - | |||||||||||||
1274 | setError(QAbstractSocket::SocketTimeoutError, | - | ||||||||||||
1275 | QLatin1String("Network operation timed out")); | - | ||||||||||||
1276 | - | |||||||||||||
1277 | - | |||||||||||||
1278 | - | |||||||||||||
1279 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
1280 | } | - | ||||||||||||
1281 | - | |||||||||||||
1282 | - | |||||||||||||
1283 | bool QSocks5SocketEngine::listen() | - | ||||||||||||
1284 | { | - | ||||||||||||
1285 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1286 | - | |||||||||||||
1287 | if (0) QMessageLogger(__FILE__, 1419, __PRETTY_FUNCTION__).debug() << "listen()"; dead code: QMessageLogger(__FILE__, 1419, __PRETTY_FUNCTION__).debug() << "listen()"; | - | ||||||||||||
1288 | - | |||||||||||||
1289 | - | |||||||||||||
1290 | if (d->socketState == QAbstractSocket::BoundState
| 0-11 | ||||||||||||
1291 | d->socketState = QAbstractSocket::ListeningState; | - | ||||||||||||
1292 | - | |||||||||||||
1293 | - | |||||||||||||
1294 | if (d->socks5State == QSocks5SocketEnginePrivate::BindSuccess
| 0-11 | ||||||||||||
1295 | d->emitReadNotification(); executed 11 times by 3 tests: d->emitReadNotification(); Executed by:
| 11 | ||||||||||||
1296 | - | |||||||||||||
1297 | return executed 11 times by 3 tests: true;return true; Executed by:
executed 11 times by 3 tests: return true; Executed by:
| 11 | ||||||||||||
1298 | } | - | ||||||||||||
1299 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
1300 | } | - | ||||||||||||
1301 | - | |||||||||||||
1302 | int QSocks5SocketEngine::accept() | - | ||||||||||||
1303 | { | - | ||||||||||||
1304 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1305 | - | |||||||||||||
1306 | - | |||||||||||||
1307 | if (0) QMessageLogger(__FILE__, 1439, __PRETTY_FUNCTION__).debug() << "accept()"; dead code: QMessageLogger(__FILE__, 1439, __PRETTY_FUNCTION__).debug() << "accept()"; | - | ||||||||||||
1308 | - | |||||||||||||
1309 | qintptr sd = -1; | - | ||||||||||||
1310 | switch (d->socks5State) { | - | ||||||||||||
1311 | case executed 6 times by 3 tests: QSocks5SocketEnginePrivate::BindSuccess:case QSocks5SocketEnginePrivate::BindSuccess: Executed by:
executed 6 times by 3 tests: case QSocks5SocketEnginePrivate::BindSuccess: Executed by:
| 6 | ||||||||||||
1312 | if (0) QMessageLogger(__FILE__, 1444, __PRETTY_FUNCTION__).debug() << "BindSuccess adding" << d->socketDescriptor << "to the bind store"; dead code: QMessageLogger(__FILE__, 1444, __PRETTY_FUNCTION__).debug() << "BindSuccess adding" << d->socketDescriptor << "to the bind store"; | - | ||||||||||||
1313 | d->data->controlSocket->disconnect(); | - | ||||||||||||
1314 | d->data->controlSocket->setParent(0); | - | ||||||||||||
1315 | d->bindData->localAddress = d->localAddress; | - | ||||||||||||
1316 | d->bindData->localPort = d->localPort; | - | ||||||||||||
1317 | sd = d->socketDescriptor; | - | ||||||||||||
1318 | socks5BindStore()->add(sd, d->bindData); | - | ||||||||||||
1319 | d->data = 0; | - | ||||||||||||
1320 | d->bindData = 0; | - | ||||||||||||
1321 | d->socketDescriptor = 0; | - | ||||||||||||
1322 | - | |||||||||||||
1323 | - | |||||||||||||
1324 | d->socks5State = QSocks5SocketEnginePrivate::Uninitialized; | - | ||||||||||||
1325 | d->socketState = QAbstractSocket::UnconnectedState; | - | ||||||||||||
1326 | break; executed 6 times by 3 tests: break; Executed by:
| 6 | ||||||||||||
1327 | case never executed: QSocks5SocketEnginePrivate::ControlSocketError:case QSocks5SocketEnginePrivate::ControlSocketError: never executed: case QSocks5SocketEnginePrivate::ControlSocketError: | 0 | ||||||||||||
1328 | setError(QAbstractSocket::ProxyProtocolError, QLatin1String("Control socket error")); | - | ||||||||||||
1329 | break; never executed: break; | 0 | ||||||||||||
1330 | default never executed: :default: never executed: default: | 0 | ||||||||||||
1331 | setError(QAbstractSocket::ProxyProtocolError, QLatin1String("SOCKS5 proxy error")); | - | ||||||||||||
1332 | break; never executed: break; | 0 | ||||||||||||
1333 | } | - | ||||||||||||
1334 | return executed 6 times by 3 tests: sd;return sd; Executed by:
executed 6 times by 3 tests: return sd; Executed by:
| 6 | ||||||||||||
1335 | } | - | ||||||||||||
1336 | - | |||||||||||||
1337 | void QSocks5SocketEngine::close() | - | ||||||||||||
1338 | { | - | ||||||||||||
1339 | if (0) QMessageLogger(__FILE__, 1471, __PRETTY_FUNCTION__).debug() << "close()"; dead code: QMessageLogger(__FILE__, 1471, __PRETTY_FUNCTION__).debug() << "close()"; | - | ||||||||||||
1340 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1341 | if (d->data
| 0-1008 | ||||||||||||
1342 | if (d->data->controlSocket->state() == QAbstractSocket::ConnectedState
| 298-710 | ||||||||||||
1343 | int msecs = 100; | - | ||||||||||||
1344 | QElapsedTimer stopWatch; | - | ||||||||||||
1345 | stopWatch.start(); | - | ||||||||||||
1346 | while (!d->data->controlSocket->bytesToWrite()
| 2-296 | ||||||||||||
1347 | if (!d->data->controlSocket->waitForBytesWritten(qt_subtract_from_timeout(msecs, stopWatch.elapsed()))
| 0-296 | ||||||||||||
1348 | break; executed 296 times by 8 tests: break; Executed by:
| 296 | ||||||||||||
1349 | } never executed: end of block | 0 | ||||||||||||
1350 | } executed 298 times by 8 tests: end of block Executed by:
| 298 | ||||||||||||
1351 | d->data->controlSocket->close(); | - | ||||||||||||
1352 | } executed 1008 times by 8 tests: end of block Executed by:
| 1008 | ||||||||||||
1353 | - | |||||||||||||
1354 | if (d->udpData
| 0-1013 | ||||||||||||
1355 | d->udpData->udpSocket->close(); never executed: d->udpData->udpSocket->close(); | 0 | ||||||||||||
1356 | - | |||||||||||||
1357 | } executed 1013 times by 8 tests: end of block Executed by:
| 1013 | ||||||||||||
1358 | - | |||||||||||||
1359 | qint64 QSocks5SocketEngine::bytesAvailable() const | - | ||||||||||||
1360 | { | - | ||||||||||||
1361 | const QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1362 | if (d->mode == QSocks5SocketEnginePrivate::ConnectMode
| 1-3287 | ||||||||||||
1363 | return executed 3287 times by 6 tests: d->connectData->readBuffer.size();return d->connectData->readBuffer.size(); Executed by:
executed 3287 times by 6 tests: return d->connectData->readBuffer.size(); Executed by:
| 3287 | ||||||||||||
1364 | - | |||||||||||||
1365 | else if (d->mode == QSocks5SocketEnginePrivate::UdpAssociateMode
| 0-1 | ||||||||||||
1366 | && !d->udpData->pendingDatagrams.isEmpty()
| 0 | ||||||||||||
1367 | return never executed: d->udpData->pendingDatagrams.first().data.size();return d->udpData->pendingDatagrams.first().data.size(); never executed: return d->udpData->pendingDatagrams.first().data.size(); | 0 | ||||||||||||
1368 | - | |||||||||||||
1369 | return executed 1 time by 1 test: 0;return 0; Executed by:
executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||
1370 | } | - | ||||||||||||
1371 | - | |||||||||||||
1372 | qint64 QSocks5SocketEngine::read(char *data, qint64 maxlen) | - | ||||||||||||
1373 | { | - | ||||||||||||
1374 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1375 | if (0) QMessageLogger(__FILE__, 1507, __PRETTY_FUNCTION__).debug() << "read( , maxlen = " << maxlen << ')'; dead code: QMessageLogger(__FILE__, 1507, __PRETTY_FUNCTION__).debug() << "read( , maxlen = " << maxlen << ')'; | - | ||||||||||||
1376 | if (d->mode == QSocks5SocketEnginePrivate::ConnectMode
| 0-3290 | ||||||||||||
1377 | if (d->connectData->readBuffer.size() == 0
| 355-2935 | ||||||||||||
1378 | if (d->data->controlSocket->state() == QAbstractSocket::UnconnectedState
| 2-353 | ||||||||||||
1379 | - | |||||||||||||
1380 | close(); | - | ||||||||||||
1381 | setError(QAbstractSocket::RemoteHostClosedError, | - | ||||||||||||
1382 | QLatin1String("Remote host closed connection###")); | - | ||||||||||||
1383 | setState(QAbstractSocket::UnconnectedState); | - | ||||||||||||
1384 | return executed 353 times by 3 tests: -1;return -1; Executed by:
executed 353 times by 3 tests: return -1; Executed by:
| 353 | ||||||||||||
1385 | } else { | - | ||||||||||||
1386 | return executed 2 times by 1 test: 0;return 0; Executed by:
executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||
1387 | } | - | ||||||||||||
1388 | } | - | ||||||||||||
1389 | qint64 copy = qMin<qint64>(d->connectData->readBuffer.size(), maxlen); | - | ||||||||||||
1390 | memcpy(data, d->connectData->readBuffer.constData(), copy); | - | ||||||||||||
1391 | d->connectData->readBuffer.remove(0, copy); | - | ||||||||||||
1392 | if (0) QMessageLogger(__FILE__, 1524, __PRETTY_FUNCTION__).debug() << "read" << dump(QByteArray(data, copy)); dead code: QMessageLogger(__FILE__, 1524, __PRETTY_FUNCTION__).debug() << "read" << dump(QByteArray(data, copy)); | - | ||||||||||||
1393 | return executed 2935 times by 6 tests: copy;return copy; Executed by:
executed 2935 times by 6 tests: return copy; Executed by:
| 2935 | ||||||||||||
1394 | - | |||||||||||||
1395 | } else if (d->mode == QSocks5SocketEnginePrivate::UdpAssociateMode
| 0 | ||||||||||||
1396 | return never executed: readDatagram(data, maxlen);return readDatagram(data, maxlen); never executed: return readDatagram(data, maxlen); | 0 | ||||||||||||
1397 | - | |||||||||||||
1398 | } | - | ||||||||||||
1399 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
1400 | } | - | ||||||||||||
1401 | - | |||||||||||||
1402 | qint64 QSocks5SocketEngine::write(const char *data, qint64 len) | - | ||||||||||||
1403 | { | - | ||||||||||||
1404 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1405 | if (0) QMessageLogger(__FILE__, 1537, __PRETTY_FUNCTION__).debug() << "write" << dump(QByteArray(data, len)); dead code: QMessageLogger(__FILE__, 1537, __PRETTY_FUNCTION__).debug() << "write" << dump(QByteArray(data, len)); | - | ||||||||||||
1406 | - | |||||||||||||
1407 | if (d->mode == QSocks5SocketEnginePrivate::ConnectMode
| 1-1887 | ||||||||||||
1408 | - | |||||||||||||
1409 | len = qMin<qint64>(len, MaxWriteBufferSize) - d->data->controlSocket->bytesToWrite(); | - | ||||||||||||
1410 | if (len <= 0
| 0-1887 | ||||||||||||
1411 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
1412 | - | |||||||||||||
1413 | QByteArray buf = QByteArray::fromRawData(data, len); | - | ||||||||||||
1414 | QByteArray sealedBuf; | - | ||||||||||||
1415 | if (!d->data->authenticator->seal(buf, &sealedBuf)
| 0-1887 | ||||||||||||
1416 | - | |||||||||||||
1417 | } never executed: end of block | 0 | ||||||||||||
1418 | - | |||||||||||||
1419 | qint64 written = d->data->controlSocket->write(sealedBuf); | - | ||||||||||||
1420 | if (written <= 0
| 0-1887 | ||||||||||||
1421 | if (0) QMessageLogger(__FILE__, 1553, __PRETTY_FUNCTION__).debug() << "native write returned" << written; dead code: QMessageLogger(__FILE__, 1553, __PRETTY_FUNCTION__).debug() << "native write returned" << written; | - | ||||||||||||
1422 | return never executed: written;return written; never executed: return written; | 0 | ||||||||||||
1423 | } | - | ||||||||||||
1424 | d->data->controlSocket->waitForBytesWritten(0); | - | ||||||||||||
1425 | - | |||||||||||||
1426 | return executed 1887 times by 6 tests: len;return len; Executed by:
executed 1887 times by 6 tests: return len; Executed by:
| 1887 | ||||||||||||
1427 | - | |||||||||||||
1428 | } else if (d->mode == QSocks5SocketEnginePrivate::UdpAssociateMode
| 0-1 | ||||||||||||
1429 | - | |||||||||||||
1430 | return executed 1 time by 1 test: writeDatagram(data, len, QIpPacketHeader(d->peerAddress, d->peerPort));return writeDatagram(data, len, QIpPacketHeader(d->peerAddress, d->peerPort)); Executed by:
executed 1 time by 1 test: return writeDatagram(data, len, QIpPacketHeader(d->peerAddress, d->peerPort)); Executed by:
| 1 | ||||||||||||
1431 | - | |||||||||||||
1432 | } | - | ||||||||||||
1433 | - | |||||||||||||
1434 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||
1435 | } | - | ||||||||||||
1436 | - | |||||||||||||
1437 | - | |||||||||||||
1438 | - | |||||||||||||
1439 | bool QSocks5SocketEngine::joinMulticastGroup(const QHostAddress &, | - | ||||||||||||
1440 | const QNetworkInterface &) | - | ||||||||||||
1441 | { | - | ||||||||||||
1442 | setError(QAbstractSocket::UnsupportedSocketOperationError, | - | ||||||||||||
1443 | QLatin1String("Operation on socket is not supported")); | - | ||||||||||||
1444 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
1445 | } | - | ||||||||||||
1446 | - | |||||||||||||
1447 | bool QSocks5SocketEngine::leaveMulticastGroup(const QHostAddress &, | - | ||||||||||||
1448 | const QNetworkInterface &) | - | ||||||||||||
1449 | { | - | ||||||||||||
1450 | setError(QAbstractSocket::UnsupportedSocketOperationError, | - | ||||||||||||
1451 | QLatin1String("Operation on socket is not supported")); | - | ||||||||||||
1452 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
1453 | } | - | ||||||||||||
1454 | - | |||||||||||||
1455 | - | |||||||||||||
1456 | QNetworkInterface QSocks5SocketEngine::multicastInterface() const | - | ||||||||||||
1457 | { | - | ||||||||||||
1458 | return never executed: QNetworkInterface();return QNetworkInterface(); never executed: return QNetworkInterface(); | 0 | ||||||||||||
1459 | } | - | ||||||||||||
1460 | - | |||||||||||||
1461 | bool QSocks5SocketEngine::setMulticastInterface(const QNetworkInterface &) | - | ||||||||||||
1462 | { | - | ||||||||||||
1463 | setError(QAbstractSocket::UnsupportedSocketOperationError, | - | ||||||||||||
1464 | QLatin1String("Operation on socket is not supported")); | - | ||||||||||||
1465 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
1466 | } | - | ||||||||||||
1467 | - | |||||||||||||
1468 | - | |||||||||||||
1469 | qint64 QSocks5SocketEngine::readDatagram(char *data, qint64 maxlen, QIpPacketHeader *header, PacketHeaderOptions) | - | ||||||||||||
1470 | { | - | ||||||||||||
1471 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1472 | - | |||||||||||||
1473 | d->checkForDatagrams(); | - | ||||||||||||
1474 | - | |||||||||||||
1475 | if (d->udpData->pendingDatagrams.isEmpty()
| 0 | ||||||||||||
1476 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
1477 | - | |||||||||||||
1478 | QSocks5RevivedDatagram datagram = d->udpData->pendingDatagrams.dequeue(); | - | ||||||||||||
1479 | int copyLen = qMin<int>(maxlen, datagram.data.size()); | - | ||||||||||||
1480 | memcpy(data, datagram.data.constData(), copyLen); | - | ||||||||||||
1481 | header->senderAddress = datagram.address; | - | ||||||||||||
1482 | header->senderPort = datagram.port; | - | ||||||||||||
1483 | return never executed: copyLen;return copyLen; never executed: return copyLen; | 0 | ||||||||||||
1484 | } | - | ||||||||||||
1485 | - | |||||||||||||
1486 | qint64 QSocks5SocketEngine::writeDatagram(const char *data, qint64 len, const QIpPacketHeader &header) | - | ||||||||||||
1487 | { | - | ||||||||||||
1488 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1489 | - | |||||||||||||
1490 | - | |||||||||||||
1491 | if (!d->data
| 0-3 | ||||||||||||
1492 | d->initialize(QSocks5SocketEnginePrivate::UdpAssociateMode); | - | ||||||||||||
1493 | - | |||||||||||||
1494 | if (!bind(QHostAddress(QLatin1String("0.0.0.0")), 0)
| 0 | ||||||||||||
1495 | - | |||||||||||||
1496 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||
1497 | } | - | ||||||||||||
1498 | } never executed: end of block | 0 | ||||||||||||
1499 | - | |||||||||||||
1500 | QByteArray outBuf; | - | ||||||||||||
1501 | outBuf.reserve(270 + len); | - | ||||||||||||
1502 | outBuf[0] = 0x00; | - | ||||||||||||
1503 | outBuf[1] = 0x00; | - | ||||||||||||
1504 | outBuf[2] = 0x00; | - | ||||||||||||
1505 | if (!qt_socks5_set_host_address_and_port(header.destinationAddress, header.destinationPort, &outBuf)
| 0-3 | ||||||||||||
1506 | } never executed: end of block | 0 | ||||||||||||
1507 | outBuf += QByteArray(data, len); | - | ||||||||||||
1508 | if (0) QMessageLogger(__FILE__, 1640, __PRETTY_FUNCTION__).debug() << "sending" << dump(outBuf); dead code: QMessageLogger(__FILE__, 1640, __PRETTY_FUNCTION__).debug() << "sending" << dump(outBuf); | - | ||||||||||||
1509 | QByteArray sealedBuf; | - | ||||||||||||
1510 | if (!d->data->authenticator->seal(outBuf, &sealedBuf)
| 0-3 | ||||||||||||
1511 | if (0) QMessageLogger(__FILE__, 1643, __PRETTY_FUNCTION__).debug() << "sealing data failed"; dead code: QMessageLogger(__FILE__, 1643, __PRETTY_FUNCTION__).debug() << "sealing data failed"; | - | ||||||||||||
1512 | setError(QAbstractSocket::SocketAccessError, d->data->authenticator->errorString()); | - | ||||||||||||
1513 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||
1514 | } | - | ||||||||||||
1515 | if (d->udpData->udpSocket->writeDatagram(sealedBuf, d->udpData->associateAddress, d->udpData->associatePort) != sealedBuf.size()
| 0-3 | ||||||||||||
1516 | - | |||||||||||||
1517 | if (d->udpData->udpSocket->error() == QAbstractSocket::DatagramTooLargeError
| 0 | ||||||||||||
1518 | setError(d->udpData->udpSocket->error(), d->udpData->udpSocket->errorString()); never executed: setError(d->udpData->udpSocket->error(), d->udpData->udpSocket->errorString()); | 0 | ||||||||||||
1519 | - | |||||||||||||
1520 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||
1521 | } | - | ||||||||||||
1522 | - | |||||||||||||
1523 | return executed 3 times by 1 test: len;return len; Executed by:
executed 3 times by 1 test: return len; Executed by:
| 3 | ||||||||||||
1524 | } | - | ||||||||||||
1525 | - | |||||||||||||
1526 | bool QSocks5SocketEngine::hasPendingDatagrams() const | - | ||||||||||||
1527 | { | - | ||||||||||||
1528 | const QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1529 | do { if (!d->data
executed 1 time by 1 test: false;return false; Executed by:
executed 1 time by 1 test: } } while (0);return false; Executed by:
| 0-1 | ||||||||||||
1530 | - | |||||||||||||
1531 | d->checkForDatagrams(); | - | ||||||||||||
1532 | - | |||||||||||||
1533 | return never executed: !d->udpData->pendingDatagrams.isEmpty();return !d->udpData->pendingDatagrams.isEmpty(); never executed: return !d->udpData->pendingDatagrams.isEmpty(); | 0 | ||||||||||||
1534 | } | - | ||||||||||||
1535 | - | |||||||||||||
1536 | qint64 QSocks5SocketEngine::pendingDatagramSize() const | - | ||||||||||||
1537 | { | - | ||||||||||||
1538 | const QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1539 | - | |||||||||||||
1540 | d->checkForDatagrams(); | - | ||||||||||||
1541 | - | |||||||||||||
1542 | if (!d->udpData->pendingDatagrams.isEmpty()
| 0 | ||||||||||||
1543 | return never executed: d->udpData->pendingDatagrams.head().data.size();return d->udpData->pendingDatagrams.head().data.size(); never executed: return d->udpData->pendingDatagrams.head().data.size(); | 0 | ||||||||||||
1544 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
1545 | } | - | ||||||||||||
1546 | - | |||||||||||||
1547 | - | |||||||||||||
1548 | qint64 QSocks5SocketEngine::bytesToWrite() const | - | ||||||||||||
1549 | { | - | ||||||||||||
1550 | const QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1551 | if (d->data
| 0-4689 | ||||||||||||
1552 | return executed 4689 times by 5 tests: d->data->controlSocket->bytesToWrite();return d->data->controlSocket->bytesToWrite(); Executed by:
executed 4689 times by 5 tests: return d->data->controlSocket->bytesToWrite(); Executed by:
| 4689 | ||||||||||||
1553 | } else { | - | ||||||||||||
1554 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
1555 | } | - | ||||||||||||
1556 | } | - | ||||||||||||
1557 | - | |||||||||||||
1558 | int QSocks5SocketEngine::option(SocketOption option) const | - | ||||||||||||
1559 | { | - | ||||||||||||
1560 | const QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1561 | if (d->data
| 0 | ||||||||||||
1562 | - | |||||||||||||
1563 | if (option == QAbstractSocketEngine::LowDelayOption
| 0 | ||||||||||||
1564 | return never executed: d->data->controlSocket->socketOption(QAbstractSocket::LowDelayOption).toInt();return d->data->controlSocket->socketOption(QAbstractSocket::LowDelayOption).toInt(); never executed: return d->data->controlSocket->socketOption(QAbstractSocket::LowDelayOption).toInt(); | 0 | ||||||||||||
1565 | if (option == QAbstractSocketEngine::KeepAliveOption
| 0 | ||||||||||||
1566 | return never executed: d->data->controlSocket->socketOption(QAbstractSocket::KeepAliveOption).toInt();return d->data->controlSocket->socketOption(QAbstractSocket::KeepAliveOption).toInt(); never executed: return d->data->controlSocket->socketOption(QAbstractSocket::KeepAliveOption).toInt(); | 0 | ||||||||||||
1567 | } never executed: end of block | 0 | ||||||||||||
1568 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||
1569 | } | - | ||||||||||||
1570 | - | |||||||||||||
1571 | bool QSocks5SocketEngine::setOption(SocketOption option, int value) | - | ||||||||||||
1572 | { | - | ||||||||||||
1573 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1574 | if (d->data
| 0-345 | ||||||||||||
1575 | - | |||||||||||||
1576 | if (option == QAbstractSocketEngine::LowDelayOption
| 51-294 | ||||||||||||
1577 | d->data->controlSocket->setSocketOption(QAbstractSocket::LowDelayOption, value); executed 294 times by 1 test: d->data->controlSocket->setSocketOption(QAbstractSocket::LowDelayOption, value); Executed by:
| 294 | ||||||||||||
1578 | if (option == QAbstractSocketEngine::KeepAliveOption
| 51-294 | ||||||||||||
1579 | d->data->controlSocket->setSocketOption(QAbstractSocket::KeepAliveOption, value); executed 51 times by 2 tests: d->data->controlSocket->setSocketOption(QAbstractSocket::KeepAliveOption, value); Executed by:
| 51 | ||||||||||||
1580 | return executed 345 times by 3 tests: true;return true; Executed by:
executed 345 times by 3 tests: return true; Executed by:
| 345 | ||||||||||||
1581 | } | - | ||||||||||||
1582 | return executed 12 times by 2 tests: false;return false; Executed by:
executed 12 times by 2 tests: return false; Executed by:
| 12 | ||||||||||||
1583 | } | - | ||||||||||||
1584 | - | |||||||||||||
1585 | bool QSocks5SocketEnginePrivate::waitForConnected(int msecs, bool *timedOut) | - | ||||||||||||
1586 | { | - | ||||||||||||
1587 | if (data->controlSocket->state() == QAbstractSocket::UnconnectedState
| 0-494 | ||||||||||||
1588 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
1589 | - | |||||||||||||
1590 | const Socks5State wantedState = | - | ||||||||||||
1591 | mode == ConnectMode
| 18-476 | ||||||||||||
1592 | mode == BindMode
| 3-15 | ||||||||||||
1593 | UdpAssociateSuccess; | - | ||||||||||||
1594 | - | |||||||||||||
1595 | QElapsedTimer stopWatch; | - | ||||||||||||
1596 | stopWatch.start(); | - | ||||||||||||
1597 | - | |||||||||||||
1598 | while (socks5State != wantedState
| 352-479 | ||||||||||||
1599 | if (!data->controlSocket->waitForReadyRead(qt_subtract_from_timeout(msecs, stopWatch.elapsed()))
| 15-337 | ||||||||||||
1600 | if (data->controlSocket->state() == QAbstractSocket::UnconnectedState
| 7-8 | ||||||||||||
1601 | return executed 8 times by 4 tests: true;return true; Executed by:
executed 8 times by 4 tests: return true; Executed by:
| 8 | ||||||||||||
1602 | - | |||||||||||||
1603 | setErrorState(QSocks5SocketEnginePrivate::ControlSocketError); | - | ||||||||||||
1604 | if (timedOut
| 0-6 | ||||||||||||
1605 | * executed 6 times by 2 tests: timedOut = true;*timedOut = true; Executed by:
executed 6 times by 2 tests: *timedOut = true; Executed by:
| 6 | ||||||||||||
1606 | return executed 7 times by 3 tests: false;return false; Executed by:
executed 7 times by 3 tests: return false; Executed by:
| 7 | ||||||||||||
1607 | } | - | ||||||||||||
1608 | } executed 337 times by 7 tests: end of block Executed by:
| 337 | ||||||||||||
1609 | - | |||||||||||||
1610 | return executed 479 times by 5 tests: true;return true; Executed by:
executed 479 times by 5 tests: return true; Executed by:
| 479 | ||||||||||||
1611 | } | - | ||||||||||||
1612 | - | |||||||||||||
1613 | bool QSocks5SocketEngine::waitForRead(int msecs, bool *timedOut) | - | ||||||||||||
1614 | { | - | ||||||||||||
1615 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1616 | if (0) QMessageLogger(__FILE__, 1748, __PRETTY_FUNCTION__).debug() << "waitForRead" << msecs; dead code: QMessageLogger(__FILE__, 1748, __PRETTY_FUNCTION__).debug() << "waitForRead" << msecs; | - | ||||||||||||
1617 | - | |||||||||||||
1618 | d->readNotificationActivated = false; | - | ||||||||||||
1619 | - | |||||||||||||
1620 | QElapsedTimer stopWatch; | - | ||||||||||||
1621 | stopWatch.start(); | - | ||||||||||||
1622 | - | |||||||||||||
1623 | - | |||||||||||||
1624 | if (!d->waitForConnected(msecs, timedOut)
| 0-187 | ||||||||||||
1625 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
1626 | if (d->data->controlSocket->state() == QAbstractSocket::UnconnectedState
| 0-187 | ||||||||||||
1627 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||
1628 | - | |||||||||||||
1629 | - | |||||||||||||
1630 | if (d->mode == QSocks5SocketEnginePrivate::ConnectMode
| 3-184 | ||||||||||||
1631 | d->mode == QSocks5SocketEnginePrivate::BindMode
| 1-2 | ||||||||||||
1632 | while (!d->readNotificationActivated
| 179-186 | ||||||||||||
1633 | if (!d->data->controlSocket->waitForReadyRead(qt_subtract_from_timeout(msecs, stopWatch.elapsed()))
| 7-179 | ||||||||||||
1634 | if (d->data->controlSocket->state() == QAbstractSocket::UnconnectedState
| 2-5 | ||||||||||||
1635 | return executed 5 times by 2 tests: true;return true; Executed by:
executed 5 times by 2 tests: return true; Executed by:
| 5 | ||||||||||||
1636 | - | |||||||||||||
1637 | setError(d->data->controlSocket->error(), d->data->controlSocket->errorString()); | - | ||||||||||||
1638 | if (timedOut
| 0-2 | ||||||||||||
1639 | * never executed: timedOut = true;*timedOut = true; never executed: *timedOut = true; | 0 | ||||||||||||
1640 | return executed 2 times by 1 test: false;return false; Executed by:
executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||
1641 | } | - | ||||||||||||
1642 | } executed 179 times by 3 tests: end of block Executed by:
| 179 | ||||||||||||
1643 | - | |||||||||||||
1644 | } executed 179 times by 3 tests: else {end of block Executed by:
| 179 | ||||||||||||
1645 | while (!d->readNotificationActivated
| 0-1 | ||||||||||||
1646 | if (!d->udpData->udpSocket->waitForReadyRead(qt_subtract_from_timeout(msecs, stopWatch.elapsed()))
| 0-1 | ||||||||||||
1647 | setError(d->udpData->udpSocket->error(), d->udpData->udpSocket->errorString()); | - | ||||||||||||
1648 | if (timedOut
| 0-1 | ||||||||||||
1649 | * never executed: timedOut = true;*timedOut = true; never executed: *timedOut = true; | 0 | ||||||||||||
1650 | return executed 1 time by 1 test: false;return false; Executed by:
executed 1 time by 1 test: return false; Executed by:
| 1 | ||||||||||||
1651 | } | - | ||||||||||||
1652 | } never executed: end of block | 0 | ||||||||||||
1653 | - | |||||||||||||
1654 | } never executed: end of block | 0 | ||||||||||||
1655 | - | |||||||||||||
1656 | - | |||||||||||||
1657 | bool ret = d->readNotificationActivated; | - | ||||||||||||
1658 | d->readNotificationActivated = false; | - | ||||||||||||
1659 | - | |||||||||||||
1660 | if (0) QMessageLogger(__FILE__, 1792, __PRETTY_FUNCTION__).debug() << "waitForRead returned" << ret; dead code: QMessageLogger(__FILE__, 1792, __PRETTY_FUNCTION__).debug() << "waitForRead returned" << ret; | - | ||||||||||||
1661 | return executed 179 times by 3 tests: ret;return ret; Executed by:
executed 179 times by 3 tests: return ret; Executed by:
| 179 | ||||||||||||
1662 | } | - | ||||||||||||
1663 | - | |||||||||||||
1664 | - | |||||||||||||
1665 | bool QSocks5SocketEngine::waitForWrite(int msecs, bool *timedOut) | - | ||||||||||||
1666 | { | - | ||||||||||||
1667 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1668 | if (0) QMessageLogger(__FILE__, 1800, __PRETTY_FUNCTION__).debug() << "waitForWrite" << msecs; dead code: QMessageLogger(__FILE__, 1800, __PRETTY_FUNCTION__).debug() << "waitForWrite" << msecs; | - | ||||||||||||
1669 | - | |||||||||||||
1670 | QElapsedTimer stopWatch; | - | ||||||||||||
1671 | stopWatch.start(); | - | ||||||||||||
1672 | - | |||||||||||||
1673 | - | |||||||||||||
1674 | if (!d->waitForConnected(msecs, timedOut)
| 6-286 | ||||||||||||
1675 | return executed 6 times by 2 tests: false;return false; Executed by:
executed 6 times by 2 tests: return false; Executed by:
| 6 | ||||||||||||
1676 | if (d->data->controlSocket->state() == QAbstractSocket::UnconnectedState
| 7-279 | ||||||||||||
1677 | return executed 7 times by 3 tests: true;return true; Executed by:
executed 7 times by 3 tests: return true; Executed by:
| 7 | ||||||||||||
1678 | - | |||||||||||||
1679 | - | |||||||||||||
1680 | - | |||||||||||||
1681 | - | |||||||||||||
1682 | if (d->data->controlSocket->bytesToWrite()
| 0-279 | ||||||||||||
1683 | d->data->controlSocket->waitForBytesWritten(qt_subtract_from_timeout(msecs, stopWatch.elapsed())); never executed: d->data->controlSocket->waitForBytesWritten(qt_subtract_from_timeout(msecs, stopWatch.elapsed())); | 0 | ||||||||||||
1684 | while ((msecs == -1
| 0-273 | ||||||||||||
1685 | && d->data->controlSocket->state() == QAbstractSocket::ConnectedState
| 0-279 | ||||||||||||
1686 | && d->data->controlSocket->bytesToWrite() >= MaxWriteBufferSize
| 0-279 | ||||||||||||
1687 | d->data->controlSocket->waitForBytesWritten(qt_subtract_from_timeout(msecs, stopWatch.elapsed())); never executed: d->data->controlSocket->waitForBytesWritten(qt_subtract_from_timeout(msecs, stopWatch.elapsed())); | 0 | ||||||||||||
1688 | return executed 279 times by 4 tests: d->data->controlSocket->bytesToWrite() < MaxWriteBufferSize;return d->data->controlSocket->bytesToWrite() < MaxWriteBufferSize; Executed by:
executed 279 times by 4 tests: return d->data->controlSocket->bytesToWrite() < MaxWriteBufferSize; Executed by:
| 279 | ||||||||||||
1689 | } | - | ||||||||||||
1690 | - | |||||||||||||
1691 | bool QSocks5SocketEngine::waitForReadOrWrite(bool *readyToRead, bool *readyToWrite, | - | ||||||||||||
1692 | bool checkRead, bool checkWrite, | - | ||||||||||||
1693 | int msecs, bool *timedOut) | - | ||||||||||||
1694 | { | - | ||||||||||||
1695 | (void)checkRead;; | - | ||||||||||||
1696 | if (!checkWrite
| 174-184 | ||||||||||||
1697 | bool canRead = waitForRead(msecs, timedOut); | - | ||||||||||||
1698 | if (readyToRead
| 0-174 | ||||||||||||
1699 | * executed 174 times by 2 tests: readyToRead = canRead;*readyToRead = canRead; Executed by:
executed 174 times by 2 tests: *readyToRead = canRead; Executed by:
| 174 | ||||||||||||
1700 | return executed 174 times by 2 tests: canRead;return canRead; Executed by:
executed 174 times by 2 tests: return canRead; Executed by:
| 174 | ||||||||||||
1701 | } | - | ||||||||||||
1702 | - | |||||||||||||
1703 | bool canWrite = waitForWrite(msecs, timedOut); | - | ||||||||||||
1704 | if (readyToWrite
| 0-184 | ||||||||||||
1705 | * executed 184 times by 1 test: readyToWrite = canWrite;*readyToWrite = canWrite; Executed by:
executed 184 times by 1 test: *readyToWrite = canWrite; Executed by:
| 184 | ||||||||||||
1706 | return executed 184 times by 1 test: canWrite;return canWrite; Executed by:
executed 184 times by 1 test: return canWrite; Executed by:
| 184 | ||||||||||||
1707 | } | - | ||||||||||||
1708 | - | |||||||||||||
1709 | bool QSocks5SocketEngine::isReadNotificationEnabled() const | - | ||||||||||||
1710 | { | - | ||||||||||||
1711 | const QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1712 | return executed 3047 times by 5 tests: d->readNotificationEnabled;return d->readNotificationEnabled; Executed by:
executed 3047 times by 5 tests: return d->readNotificationEnabled; Executed by:
| 3047 | ||||||||||||
1713 | } | - | ||||||||||||
1714 | - | |||||||||||||
1715 | void QSocks5SocketEngine::setReadNotificationEnabled(bool enable) | - | ||||||||||||
1716 | { | - | ||||||||||||
1717 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1718 | - | |||||||||||||
1719 | if (0) QMessageLogger(__FILE__, 1851, __PRETTY_FUNCTION__).debug() << "setReadNotificationEnabled(" << enable << ')'; dead code: QMessageLogger(__FILE__, 1851, __PRETTY_FUNCTION__).debug() << "setReadNotificationEnabled(" << enable << ')'; | - | ||||||||||||
1720 | - | |||||||||||||
1721 | bool emitSignal = false; | - | ||||||||||||
1722 | if (!d->readNotificationEnabled
| 786-3238 | ||||||||||||
1723 | && enable
| 90-696 | ||||||||||||
1724 | if (d->mode == QSocks5SocketEnginePrivate::ConnectMode
| 10-686 | ||||||||||||
1725 | emitSignal = !d->connectData->readBuffer.isEmpty(); executed 686 times by 7 tests: emitSignal = !d->connectData->readBuffer.isEmpty(); Executed by:
| 686 | ||||||||||||
1726 | - | |||||||||||||
1727 | else if (d->mode == QSocks5SocketEnginePrivate::UdpAssociateMode
| 0-10 | ||||||||||||
1728 | emitSignal = !d->udpData->pendingDatagrams.isEmpty(); never executed: emitSignal = !d->udpData->pendingDatagrams.isEmpty(); | 0 | ||||||||||||
1729 | - | |||||||||||||
1730 | else if (d->mode == QSocks5SocketEnginePrivate::BindMode
| 0-10 | ||||||||||||
1731 | && d->socketState == QAbstractSocket::ListeningState
| 0-10 | ||||||||||||
1732 | && d->socks5State == QSocks5SocketEnginePrivate::BindSuccess
| 0-10 | ||||||||||||
1733 | emitSignal = true; executed 10 times by 2 tests: emitSignal = true; Executed by:
| 10 | ||||||||||||
1734 | } executed 696 times by 7 tests: end of block Executed by:
| 696 | ||||||||||||
1735 | - | |||||||||||||
1736 | d->readNotificationEnabled = enable; | - | ||||||||||||
1737 | - | |||||||||||||
1738 | if (emitSignal
| 10-4014 | ||||||||||||
1739 | d->emitReadNotification(); executed 10 times by 2 tests: d->emitReadNotification(); Executed by:
| 10 | ||||||||||||
1740 | } executed 4024 times by 7 tests: end of block Executed by:
| 4024 | ||||||||||||
1741 | - | |||||||||||||
1742 | bool QSocks5SocketEngine::isWriteNotificationEnabled() const | - | ||||||||||||
1743 | { | - | ||||||||||||
1744 | const QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1745 | return executed 1924 times by 5 tests: d->writeNotificationEnabled;return d->writeNotificationEnabled; Executed by:
executed 1924 times by 5 tests: return d->writeNotificationEnabled; Executed by:
| 1924 | ||||||||||||
1746 | } | - | ||||||||||||
1747 | - | |||||||||||||
1748 | void QSocks5SocketEngine::setWriteNotificationEnabled(bool enable) | - | ||||||||||||
1749 | { | - | ||||||||||||
1750 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1751 | d->writeNotificationEnabled = enable; | - | ||||||||||||
1752 | if (enable
| 241-4258 | ||||||||||||
1753 | if (d->mode == QSocks5SocketEnginePrivate::ConnectMode
| 0-2553 | ||||||||||||
1754 | return; executed 33 times by 2 tests: return; Executed by:
| 33 | ||||||||||||
1755 | d->emitWriteNotification(); | - | ||||||||||||
1756 | d->writeNotificationActivated = false; | - | ||||||||||||
1757 | } executed 2520 times by 7 tests: end of block Executed by:
| 2520 | ||||||||||||
1758 | } executed 7019 times by 7 tests: end of block Executed by:
| 7019 | ||||||||||||
1759 | - | |||||||||||||
1760 | bool QSocks5SocketEngine::isExceptionNotificationEnabled() const | - | ||||||||||||
1761 | { | - | ||||||||||||
1762 | const QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1763 | return executed 81 times by 3 tests: d->exceptNotificationEnabled;return d->exceptNotificationEnabled; Executed by:
executed 81 times by 3 tests: return d->exceptNotificationEnabled; Executed by:
| 81 | ||||||||||||
1764 | } | - | ||||||||||||
1765 | - | |||||||||||||
1766 | void QSocks5SocketEngine::setExceptionNotificationEnabled(bool enable) | - | ||||||||||||
1767 | { | - | ||||||||||||
1768 | QSocks5SocketEnginePrivate * const d = d_func(); | - | ||||||||||||
1769 | d->exceptNotificationEnabled = enable; | - | ||||||||||||
1770 | } executed 162 times by 3 tests: end of block Executed by:
| 162 | ||||||||||||
1771 | - | |||||||||||||
1772 | QAbstractSocketEngine * | - | ||||||||||||
1773 | QSocks5SocketEngineHandler::createSocketEngine(QAbstractSocket::SocketType socketType, | - | ||||||||||||
1774 | const QNetworkProxy &proxy, QObject *parent) | - | ||||||||||||
1775 | { | - | ||||||||||||
1776 | (void)socketType;; | - | ||||||||||||
1777 | - | |||||||||||||
1778 | - | |||||||||||||
1779 | if (proxy.type() != QNetworkProxy::Socks5Proxy
| 711-4949 | ||||||||||||
1780 | if (0) QMessageLogger(__FILE__, 1912, __PRETTY_FUNCTION__).debug() << "not proxying"; dead code: QMessageLogger(__FILE__, 1912, __PRETTY_FUNCTION__).debug() << "not proxying"; | - | ||||||||||||
1781 | return executed 4949 times by 29 tests: 0;return 0; Executed by:
executed 4949 times by 29 tests: return 0; Executed by:
| 4949 | ||||||||||||
1782 | } | - | ||||||||||||
1783 | QScopedPointer<QSocks5SocketEngine> engine(new QSocks5SocketEngine(parent)); | - | ||||||||||||
1784 | engine->setProxy(proxy); | - | ||||||||||||
1785 | return executed 711 times by 9 tests: engine.take();return engine.take(); Executed by:
executed 711 times by 9 tests: return engine.take(); Executed by:
| 711 | ||||||||||||
1786 | } | - | ||||||||||||
1787 | - | |||||||||||||
1788 | QAbstractSocketEngine *QSocks5SocketEngineHandler::createSocketEngine(qintptr socketDescriptor, QObject *parent) | - | ||||||||||||
1789 | { | - | ||||||||||||
1790 | if (0) QMessageLogger(__FILE__, 1922, __PRETTY_FUNCTION__).debug() << "createSocketEngine" << socketDescriptor; dead code: QMessageLogger(__FILE__, 1922, __PRETTY_FUNCTION__).debug() << "createSocketEngine" << socketDescriptor; | - | ||||||||||||
1791 | if (socks5BindStore()->contains(socketDescriptor)
| 5-988 | ||||||||||||
1792 | if (0) QMessageLogger(__FILE__, 1924, __PRETTY_FUNCTION__).debug() << "bind store contains" << socketDescriptor; dead code: QMessageLogger(__FILE__, 1924, __PRETTY_FUNCTION__).debug() << "bind store contains" << socketDescriptor; | - | ||||||||||||
1793 | return executed 5 times by 2 tests: new QSocks5SocketEngine(parent);return new QSocks5SocketEngine(parent); Executed by:
executed 5 times by 2 tests: return new QSocks5SocketEngine(parent); Executed by:
| 5 | ||||||||||||
1794 | } | - | ||||||||||||
1795 | return executed 988 times by 18 tests: 0;return 0; Executed by:
executed 988 times by 18 tests: return 0; Executed by:
| 988 | ||||||||||||
1796 | } | - | ||||||||||||
1797 | - | |||||||||||||
1798 | - | |||||||||||||
1799 | - | |||||||||||||
1800 | - | |||||||||||||
Switch to Source code | Preprocessed file |