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