Merge lp:~libqtelegram-team/telegram-app/dev-lib-file-management-refactor into lp:telegram-app/dev
- dev-lib-file-management-refactor
- Merge into libqtelegram-dev
Status: | Merged |
---|---|
Approved by: | Michał Karnicki |
Approved revision: | 182 |
Merged at revision: | 180 |
Proposed branch: | lp:~libqtelegram-team/telegram-app/dev-lib-file-management-refactor |
Merge into: | lp:telegram-app/dev |
Diff against target: |
7687 lines (+2967/-2864) 68 files modified
lib/CMakeLists.txt (+12/-11) lib/core/CMakeLists.txt (+12/-13) lib/core/api.cpp (+1/-2) lib/core/asserter.cpp (+0/-28) lib/core/asserter.h (+0/-37) lib/core/connection.cpp (+4/-5) lib/core/connection.h (+3/-3) lib/core/constants.h (+0/-79) lib/core/cryptoutils.cpp (+0/-334) lib/core/cryptoutils.h (+0/-69) lib/core/dc.h (+1/-1) lib/core/dcauth.cpp (+22/-22) lib/core/dcauth.h (+2/-2) lib/core/dcprovider.cpp (+13/-13) lib/core/dcprovider.h (+1/-1) lib/core/inboundpkt.cpp (+7/-7) lib/core/inboundpkt.h (+1/-1) lib/core/outboundpkt.cpp (+8/-8) lib/core/outboundpkt.h (+2/-2) lib/core/query.h (+1/-1) lib/core/session.cpp (+44/-44) lib/core/session.h (+1/-1) lib/core/sessionmanager.cpp (+7/-5) lib/core/sessionmanager.h (+3/-0) lib/core/settings.cpp (+24/-24) lib/core/settings.h (+1/-1) lib/core/tlvalues.h (+0/-444) lib/core/utils.cpp (+0/-377) lib/core/utils.h (+0/-88) lib/file/CMakeLists.txt (+11/-0) lib/file/downloadfile.cpp (+85/-0) lib/file/downloadfile.h (+66/-0) lib/file/file.h (+84/-0) lib/file/filehandler.cpp (+422/-0) lib/file/filehandler.h (+79/-0) lib/file/fileoperation.h (+107/-0) lib/file/uploadfile.cpp (+131/-0) lib/file/uploadfile.h (+80/-0) lib/logic/CMakeLists.txt (+0/-10) lib/logic/downloadfile.cpp (+0/-85) lib/logic/downloadfile.h (+0/-63) lib/logic/file.h (+0/-88) lib/logic/fileoperation.h (+0/-104) lib/logic/uploadfile.cpp (+0/-130) lib/logic/uploadfile.h (+0/-76) lib/secret/CMakeLists.txt (+2/-0) lib/secret/decryptedmessagebuilder.cpp (+1/-1) lib/secret/decrypter.cpp (+26/-24) lib/secret/decrypter.h (+2/-2) lib/secret/encrypter.cpp (+3/-3) lib/secret/encrypter.h (+1/-1) lib/secret/secretchat.cpp (+5/-3) lib/secret/secretchat.h (+2/-2) lib/secret/secretstate.h (+1/-1) lib/telegram.cpp (+214/-607) lib/telegram.h (+5/-38) lib/types/CMakeLists.txt (+0/-1) lib/util/CMakeLists.txt (+12/-0) lib/util/asserter.cpp (+28/-0) lib/util/asserter.h (+37/-0) lib/util/constants.h (+79/-0) lib/util/cryptoutils.cpp (+334/-0) lib/util/cryptoutils.h (+69/-0) lib/util/tlvalues.h (+444/-0) lib/util/utils.cpp (+377/-0) lib/util/utils.h (+88/-0) qmlplugin/config.cpp (+1/-1) qmlplugin/tools.cpp (+1/-1) |
To merge this branch: | bzr merge lp:~libqtelegram-team/telegram-app/dev-lib-file-management-refactor |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michał Karnicki (community) | Approve | ||
Review via email:
|
Commit message
Description of the change
CHANGES:
- Created FileHandler class to hold all the file upload and download operations
- Moved to FileHandler all the Telegram class existent operations, taking care of not missing signal-slot connections
- Improved upload/download progress bar steps
- file management related raw pointers to QSharedPointer
- Created those QSharedPointer by defining a new type into the pointed class
- QLogging categories to have this name TG_<folder>_<class>
- m_foo to mFoo
TESTED
Send photo:
- regular chat, gallery
- regular chat, camera
- secret chat, gallery
- secret chat, camera
Send video:
- regular chat, gallery
- regular chat, camera
- secret chat, gallery
- secret chat, camera
Receive photo:
- regular chat, gallery
- secret chat, gallery
Receive video:
- regular chat, gallery
- secret chat, gallery
Sent a photo while a video is been downloaded:
Note: the progress bar does not update unless you exit and enter again in chat, but the download procress does not stop
Removed .cache/
Pressed cancel in a downloading file and check the file download is cancelled
NOTES: not all pointer have been moved to QSharedPointer. Only those related with file handler.
This hardening should be completed by creating in a later step a SecretHandler to manage all secret chats operations
Preview Diff
1 | === modified file 'lib/CMakeLists.txt' |
2 | --- lib/CMakeLists.txt 2015-02-06 10:19:34 +0000 |
3 | +++ lib/CMakeLists.txt 2015-02-24 14:12:31 +0000 |
4 | @@ -6,10 +6,9 @@ |
5 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}) |
6 | add_definitions(-DLIBQTELEGRAM_LIBRARY) |
7 | add_library(${LIB_NAME} SHARED |
8 | + telegram.cpp |
9 | core/connection.cpp |
10 | - core/cryptoutils.cpp |
11 | core/settings.cpp |
12 | - core/utils.cpp |
13 | core/inboundpkt.cpp |
14 | core/outboundpkt.cpp |
15 | core/dcprovider.cpp |
16 | @@ -17,29 +16,30 @@ |
17 | core/api.cpp |
18 | core/query.cpp |
19 | core/eventtimer.cpp |
20 | - logic/downloadfile.cpp |
21 | - logic/file.h |
22 | - logic/uploadfile.cpp |
23 | - telegram.cpp |
24 | core/abstractapi.cpp |
25 | core/session.cpp |
26 | core/dcauth.cpp |
27 | core/sessionmanager.cpp |
28 | - core/asserter.cpp |
29 | + util/asserter.cpp |
30 | + util/cryptoutils.cpp |
31 | + util/utils.cpp |
32 | secret/decrypter.cpp |
33 | secret/encrypter.cpp |
34 | secret/secretstate.cpp |
35 | secret/secretchat.cpp |
36 | - secret/decryptedmessagebuilder.cpp) |
37 | + secret/decryptedmessagebuilder.cpp |
38 | + file/filehandler.cpp |
39 | + file/downloadfile.cpp |
40 | + file/uploadfile.cpp |
41 | + file/fileoperation.h |
42 | + file/file.h) |
43 | set_property(TARGET ${LIB_NAME} PROPERTY COMPILE_FLAGS "${COMPILE_FLAGS} -fpermissive") |
44 | set_target_properties(${LIB_NAME} PROPERTIES VERSION ${VERSION} SOVERSION 1) |
45 | qt5_use_modules(${LIB_NAME} Network Multimedia) |
46 | target_link_libraries(${LIB_NAME} ${OPENSSL_LDFLAGS}) |
47 | |
48 | -if (IS_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) |
49 | INSTALL(TARGETS ${LIB_NAME} |
50 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
51 | -endif() |
52 | |
53 | set(HEADERS |
54 | telegram.h |
55 | @@ -64,8 +64,9 @@ |
56 | |
57 | add_subdirectory(types) |
58 | add_subdirectory(core) |
59 | -add_subdirectory(logic) |
60 | +add_subdirectory(file) |
61 | add_subdirectory(secret) |
62 | +add_subdirectory(util) |
63 | |
64 | # make the .h files visible on qtcreator |
65 | file(GLOB H_FILES *.h **/*.h) |
66 | |
67 | === modified file 'lib/core/CMakeLists.txt' |
68 | --- lib/core/CMakeLists.txt 2014-12-09 17:28:59 +0000 |
69 | +++ lib/core/CMakeLists.txt 2015-02-24 14:12:31 +0000 |
70 | @@ -1,25 +1,24 @@ |
71 | set (CORE_HEADERS |
72 | + abstractapi.h |
73 | + api.h |
74 | + asserter.h |
75 | connection.h |
76 | + constants.h |
77 | cryptoutils.h |
78 | - settings.h |
79 | - utils.h |
80 | - constants.h |
81 | + dc.h |
82 | + dcauth.h |
83 | + dcprovider.h |
84 | + endpoint.h |
85 | + eventtimer.h |
86 | inboundpkt.h |
87 | outboundpkt.h |
88 | - dcprovider.h |
89 | - eventtimer.h |
90 | - dc.h |
91 | - api.h |
92 | - tlvalues.h |
93 | query.h |
94 | querymethods.h |
95 | - abstractapi.h |
96 | session.h |
97 | - dcauth.h |
98 | - endpoint.h |
99 | sessionmanager.h |
100 | - asserter.h |
101 | - eventtimer.h) |
102 | + settings.h |
103 | + tlvalues.h |
104 | + utils.h) |
105 | |
106 | if(NOT CLICK_MODE) |
107 | INSTALL(FILES ${CORE_HEADERS} |
108 | |
109 | === modified file 'lib/core/api.cpp' |
110 | --- lib/core/api.cpp 2015-02-22 20:57:58 +0000 |
111 | +++ lib/core/api.cpp 2015-02-24 14:12:31 +0000 |
112 | @@ -21,9 +21,8 @@ |
113 | |
114 | #include "api.h" |
115 | |
116 | -#include "tlvalues.h" |
117 | +#include "util/tlvalues.h" |
118 | #include "dcprovider.h" |
119 | - |
120 | #include "secret/encrypter.h" |
121 | |
122 | Api::Api(Session *session, QObject *parent) : |
123 | |
124 | === removed file 'lib/core/asserter.cpp' |
125 | --- lib/core/asserter.cpp 2014-11-03 13:58:03 +0000 |
126 | +++ lib/core/asserter.cpp 1970-01-01 00:00:00 +0000 |
127 | @@ -1,28 +0,0 @@ |
128 | -/* |
129 | - * Copyright 2014 Canonical Ltd. |
130 | - * |
131 | - * This program is free software; you can redistribute it and/or modify |
132 | - * it under the terms of the GNU General Public License as published by |
133 | - * the Free Software Foundation; version 3. |
134 | - * |
135 | - * This program is distributed in the hope that it will be useful, |
136 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
137 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
138 | - * GNU General Public License for more details. |
139 | - * |
140 | - * You should have received a copy of the GNU General Public License |
141 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
142 | - * |
143 | - * Authors: |
144 | - * Roberto Mier |
145 | - * Tiago Herrmann |
146 | - */ |
147 | -#include "asserter.h" |
148 | - |
149 | -Asserter::Asserter(QObject *parent) : |
150 | - QObject(parent) { |
151 | -} |
152 | - |
153 | -void Asserter::check(bool condition) { |
154 | - if (!condition) Q_EMIT fatalError(); |
155 | -} |
156 | |
157 | === removed file 'lib/core/asserter.h' |
158 | --- lib/core/asserter.h 2014-11-03 13:58:03 +0000 |
159 | +++ lib/core/asserter.h 1970-01-01 00:00:00 +0000 |
160 | @@ -1,37 +0,0 @@ |
161 | -/* |
162 | - * Copyright 2014 Canonical Ltd. |
163 | - * |
164 | - * This program is free software; you can redistribute it and/or modify |
165 | - * it under the terms of the GNU General Public License as published by |
166 | - * the Free Software Foundation; version 3. |
167 | - * |
168 | - * This program is distributed in the hope that it will be useful, |
169 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
170 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
171 | - * GNU General Public License for more details. |
172 | - * |
173 | - * You should have received a copy of the GNU General Public License |
174 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
175 | - * |
176 | - * Authors: |
177 | - * Roberto Mier |
178 | - * Tiago Herrmann |
179 | - */ |
180 | -#ifndef ASSERTER_H |
181 | -#define ASSERTER_H |
182 | - |
183 | -#include <QObject> |
184 | - |
185 | -class Asserter : public QObject |
186 | -{ |
187 | - Q_OBJECT |
188 | -public: |
189 | - explicit Asserter(QObject *parent = 0); |
190 | - |
191 | - void check(bool condition); |
192 | - |
193 | -Q_SIGNALS: |
194 | - void fatalError(); |
195 | -}; |
196 | - |
197 | -#endif // ASSERTER_H |
198 | |
199 | === modified file 'lib/core/connection.cpp' |
200 | --- lib/core/connection.cpp 2014-09-29 12:33:11 +0000 |
201 | +++ lib/core/connection.cpp 2015-02-24 14:12:31 +0000 |
202 | @@ -20,13 +20,12 @@ |
203 | */ |
204 | |
205 | #include "connection.h" |
206 | -#include "constants.h" |
207 | +#include "util/constants.h" |
208 | #include <sys/socket.h> |
209 | #include <netinet/tcp.h> |
210 | #include <netinet/in.h> |
211 | |
212 | -Q_LOGGING_CATEGORY(TG_NET_SOCKET, "tg.net.socket") |
213 | - |
214 | +Q_LOGGING_CATEGORY(TG_CORE_CONNECTION, "tg.core.connection") |
215 | |
216 | Connection::Connection(const QString &host, qint32 port, QObject *parent) : |
217 | QTcpSocket(parent), |
218 | @@ -118,7 +117,7 @@ |
219 | QAbstractSocket::UnknownSocketError -1 An unidentified error occurred. |
220 | */ |
221 | void Connection::onError(QAbstractSocket::SocketError error) { |
222 | - qCWarning(TG_NET_SOCKET) << "SocketError:" << QString::number(error) << ",Description:" << errorString(); |
223 | + qCWarning(TG_CORE_CONNECTION) << "SocketError:" << QString::number(error) << ",Description:" << errorString(); |
224 | |
225 | if (!mReconnectTimerId) { |
226 | mReconnectTimerId = startTimer(RECONNECT_TIMEOUT); |
227 | @@ -127,7 +126,7 @@ |
228 | |
229 | void Connection::timerEvent(QTimerEvent *) { |
230 | if (state() != QAbstractSocket::ConnectingState && state() != QAbstractSocket::ConnectedState) { |
231 | - qCWarning(TG_NET_SOCKET) << "Trying to reconect to host"; |
232 | + qCWarning(TG_CORE_CONNECTION) << "Trying to reconect to host"; |
233 | connectToServer(); |
234 | } else { |
235 | stopReconnecting(); |
236 | |
237 | === modified file 'lib/core/connection.h' |
238 | --- lib/core/connection.h 2014-09-29 12:33:11 +0000 |
239 | +++ lib/core/connection.h 2015-02-24 14:12:31 +0000 |
240 | @@ -28,10 +28,10 @@ |
241 | #include <QtNetwork/QTcpSocket> |
242 | #include "endpoint.h" |
243 | #include <QLoggingCategory> |
244 | -#include "constants.h" |
245 | -#include "asserter.h" |
246 | +#include "util/constants.h" |
247 | +#include "util/asserter.h" |
248 | |
249 | -Q_DECLARE_LOGGING_CATEGORY(TG_NET_SOCKET) |
250 | +Q_DECLARE_LOGGING_CATEGORY(TG_CORE_CONNECTION) |
251 | |
252 | class Connection : public QTcpSocket, public Endpoint |
253 | { |
254 | |
255 | === removed file 'lib/core/constants.h' |
256 | --- lib/core/constants.h 2015-01-28 08:01:23 +0000 |
257 | +++ lib/core/constants.h 1970-01-01 00:00:00 +0000 |
258 | @@ -1,79 +0,0 @@ |
259 | -/* |
260 | - * Copyright 2014 Canonical Ltd. |
261 | - * Authors: |
262 | - * Roberto Mier |
263 | - * Tiago Herrmann |
264 | - * |
265 | - * This program is free software; you can redistribute it and/or modify |
266 | - * it under the terms of the GNU General Public License as published by |
267 | - * the Free Software Foundation; version 3. |
268 | - * |
269 | - * This program is distributed in the hope that it will be useful, |
270 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
271 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
272 | - * GNU General Public License for more details. |
273 | - * |
274 | - * You should have received a copy of the GNU General Public License |
275 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
276 | - * |
277 | - */ |
278 | - |
279 | -#ifndef CONSTANTS_H |
280 | -#define CONSTANTS_H |
281 | - |
282 | -// macro to assert conditions as in debug as in release mode |
283 | -#define ASSERT(cond) ((!(cond)) ? qt_assert(#cond,__FILE__,__LINE__) : qt_noop()) |
284 | - |
285 | -#define PACKET_BUFFER_SIZE (16384 * 100 + 16) |
286 | -#define ENCRYPT_BUFFER_INTS 16384 |
287 | -#define DECRYPT_BUFFER_INTS 16384 |
288 | - |
289 | -// These are the the original |
290 | -#define LIBQTELEGRAM_APP_HASH "c68fd5e560aa84dd4b6ad6f489164790" |
291 | -#define LIBQTELEGRAM_APP_ID 12433 |
292 | -// These are the telegram-cli credentials |
293 | -//#define LIBQTELEGRAM_APP_HASH "36722c72256a24c1225de00eb6a1ca74" |
294 | -//#define LIBQTELEGRAM_APP_ID 2899 |
295 | -// These are my second phone ones |
296 | -//#define LIBQTELEGRAM_APP_HASH "4b7f87d44de5e0a22248597939c848ae" |
297 | -//#define LIBQTELEGRAM_APP_ID 11986 |
298 | - |
299 | -#define PRODUCTION_DEFAULT_DC_ID 4 |
300 | -#define PRODUCTION_DEFAULT_DC_HOST "149.154.167.91" |
301 | -#define PRODUCTION_DEFAULT_DC_PORT 443 |
302 | -#define TEST_DEFAULT_DC_ID 1 |
303 | -#define TEST_DEFAULT_DC_HOST "173.240.5.253" |
304 | -#define TEST_DEFAULT_DC_PORT 80 |
305 | - |
306 | -#define LIBQTELEGRAM_BUILD "001" |
307 | -#define LIBQTELEGRAM_VERSION "1.0.0-SNAPSHOT" |
308 | - |
309 | -#define MAX_RESPONSE_SIZE (1L << 24) |
310 | - |
311 | -#define MAX_MESSAGE_INTS 1048576 |
312 | - |
313 | -#define MAX_PENDING_ACKS 16 |
314 | - |
315 | -#define MAX_PACKED_SIZE (1 << 24) |
316 | - |
317 | -#define ACK_TIMEOUT 120000 //120 secs |
318 | -#define QUERY_TIMEOUT 60000 // 60 secs |
319 | - |
320 | -#define MAX_QUERY_RESENDS 10 |
321 | - |
322 | -#define LANG_CODE "en" |
323 | - |
324 | -// divide file bytes into parts >= 128 kbytes. This is the minimum block size to ensurance receiving complete the users |
325 | -// profile and chat "photoBig" files. |
326 | -#define BLOCK (512 * 1024) |
327 | - |
328 | -#define RECONNECT_TIMEOUT 5000 // in case session hasn't connection, try to reconnect every 5 seconds |
329 | - |
330 | -#define UBUNTU_PHONE_TOKEN_TYPE 5 // used as token type when register and unregister device in telegram servers for push notifications |
331 | - |
332 | -#define DH_CONFIG_SERVER_RANDOM_LENGTH 256 // length we want to be a server generated random number |
333 | -#define SHARED_KEY_LENGTH 256 // length for the secret chat generated shared keys |
334 | - |
335 | -#define LAYER 17 // this value must be consistent with the TL_InvokeWithLayerX header in OutboundPkt.initConnection(). |
336 | - |
337 | -#endif // CONSTANTS_H |
338 | |
339 | === removed file 'lib/core/cryptoutils.cpp' |
340 | --- lib/core/cryptoutils.cpp 2015-01-27 09:39:53 +0000 |
341 | +++ lib/core/cryptoutils.cpp 1970-01-01 00:00:00 +0000 |
342 | @@ -1,334 +0,0 @@ |
343 | -/* |
344 | - * Copyright 2013 Vitaly Valtman |
345 | - * Copyright 2014 Canonical Ltd. |
346 | - * Authors: |
347 | - * Roberto Mier |
348 | - * Tiago Herrmann |
349 | - * |
350 | - * This program is free software; you can redistribute it and/or modify |
351 | - * it under the terms of the GNU General Public License as published by |
352 | - * the Free Software Foundation; version 3. |
353 | - * |
354 | - * This program is distributed in the hope that it will be useful, |
355 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
356 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
357 | - * GNU General Public License for more details. |
358 | - * |
359 | - * You should have received a copy of the GNU General Public License |
360 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
361 | - * |
362 | - */ |
363 | - |
364 | -#include "cryptoutils.h" |
365 | - |
366 | -#include "settings.h" |
367 | -#include "utils.h" |
368 | -#include <openssl/rand.h> |
369 | -#include <openssl/sha.h> |
370 | -#include <openssl/md5.h> |
371 | - |
372 | -CryptoUtils::CryptoUtils() { |
373 | - BN_ctx = BN_CTX_new (); |
374 | - Utils::ensurePtr(BN_ctx); |
375 | -} |
376 | - |
377 | -CryptoUtils::~CryptoUtils() { |
378 | - if (BN_ctx) free(BN_ctx); //do this with a tfree method from Utils |
379 | -} |
380 | - |
381 | -CryptoUtils* CryptoUtils::getInstance() { |
382 | - static CryptoUtils *instance = new CryptoUtils; |
383 | - return instance; |
384 | -} |
385 | - |
386 | -qint32 CryptoUtils::encryptPacketBuffer(OutboundPkt &p, void *encryptBuffer) { |
387 | - RSA *pubKey = Settings::getInstance()->pubKey(); |
388 | - return padRsaEncrypt((char *) p.buffer(), p.length() * 4, (char *) encryptBuffer, ENCRYPT_BUFFER_INTS * 4, pubKey->n, pubKey->e); |
389 | -} |
390 | - |
391 | -qint32 CryptoUtils::encryptPacketBufferAESUnAuth(const char serverNonce[16], const char hiddenClientNonce[32], OutboundPkt &p, void *encryptBuffer) { |
392 | - initAESUnAuth (serverNonce, hiddenClientNonce, AES_ENCRYPT); |
393 | - return padAESEncrypt ((char *) p.buffer(), p.length() * 4, (char *) encryptBuffer, ENCRYPT_BUFFER_INTS * 4); |
394 | -} |
395 | - |
396 | -qint32 CryptoUtils::padRsaEncrypt (char *from, qint32 from_len, char *to, qint32 size, BIGNUM *N, BIGNUM *E) { |
397 | - qint32 pad = (255000 - from_len - 32) % 255 + 32; |
398 | - qint32 chunks = (from_len + pad) / 255; |
399 | - qint32 bits = BN_num_bits (N); |
400 | - qint32 isSupported = RAND_pseudo_bytes ((uchar *) from + from_len, pad); // returns -1 if not supported |
401 | - Q_UNUSED(bits); |
402 | - Q_ASSERT(bits >= 2041 && bits <= 2048); |
403 | - Q_ASSERT(from_len > 0 && from_len <= 2550); |
404 | - Q_UNUSED(size); |
405 | - Q_ASSERT(size >= chunks * 256); |
406 | - Q_UNUSED(isSupported); |
407 | - Q_ASSERT(isSupported >= 0); |
408 | - qint32 i; |
409 | - BIGNUM x, y; |
410 | - BN_init (&x); |
411 | - BN_init (&y); |
412 | - for (i = 0; i < chunks; i++) { |
413 | - BN_bin2bn ((uchar *) from, 255, &x); |
414 | - qint32 success = BN_mod_exp (&y, &x, E, N, BN_ctx); |
415 | - Q_UNUSED(success); |
416 | - Q_ASSERT(success == 1); |
417 | - unsigned l = 256 - BN_num_bytes (&y); |
418 | - Q_ASSERT(l <= 256); |
419 | - memset (to, 0, l); |
420 | - BN_bn2bin (&y, (uchar *) to + l); |
421 | - to += 256; |
422 | - } |
423 | - BN_free (&x); |
424 | - BN_free (&y); |
425 | - return chunks * 256; |
426 | -} |
427 | - |
428 | -void CryptoUtils::initAESUnAuth (const char serverNonce[16], const char hiddenClientNonce[32], qint32 encrypt) { |
429 | - static uchar buffer[64], hash[20]; |
430 | - memcpy (buffer, hiddenClientNonce, 32); |
431 | - memcpy (buffer + 32, serverNonce, 16); |
432 | - SHA1 (buffer, 48, aes_key_raw); |
433 | - memcpy (buffer + 32, hiddenClientNonce, 32); |
434 | - SHA1 (buffer, 64, aes_iv + 8); |
435 | - memcpy (buffer, serverNonce, 16); |
436 | - memcpy (buffer + 16, hiddenClientNonce, 32); |
437 | - SHA1 (buffer, 48, hash); |
438 | - memcpy (aes_key_raw + 20, hash, 12); |
439 | - memcpy (aes_iv, hash + 12, 8); |
440 | - memcpy (aes_iv + 28, hiddenClientNonce, 4); |
441 | - if (encrypt == AES_ENCRYPT) { |
442 | - AES_set_encrypt_key (aes_key_raw, 32*8, &aes_key); |
443 | - } else { |
444 | - AES_set_decrypt_key (aes_key_raw, 32*8, &aes_key); |
445 | - } |
446 | - memset (aes_key_raw, 0, sizeof (aes_key_raw)); |
447 | -} |
448 | - |
449 | -void CryptoUtils::initAESAuth (char authKey[192], char msgKey[16], qint32 encrypt) { |
450 | - static uchar buffer[48], hash[20]; |
451 | - /* |
452 | - Steps: |
453 | - 1) sha1_a = SHA1 (msg_key + substr (auth_key, 0, 32)); |
454 | - 2) sha1_b = SHA1 (substr (auth_key, 32, 16) + msg_key + substr (auth_key, 48, 16)); |
455 | - 3) sha1_с = SHA1 (substr (auth_key, 64, 32) + msg_key); |
456 | - 4) sha1_d = SHA1 (msg_key + substr (auth_key, 96, 32)); |
457 | - 5) aes_key = substr (sha1_a, 0, 8) + substr (sha1_b, 8, 12) + substr (sha1_c, 4, 12); |
458 | - 6) aes_iv = substr (sha1_a, 8, 12) + substr (sha1_b, 0, 8) + substr (sha1_c, 16, 4) + substr (sha1_d, 0, 8); |
459 | - */ |
460 | - memcpy (buffer, msgKey, 16); |
461 | - memcpy (buffer + 16, authKey, 32); |
462 | - SHA1 (buffer, 48, hash); |
463 | - memcpy (aes_key_raw, hash, 8); |
464 | - memcpy (aes_iv, hash + 8, 12); |
465 | - |
466 | - memcpy (buffer, authKey + 32, 16); |
467 | - memcpy (buffer + 16, msgKey, 16); |
468 | - memcpy (buffer + 32, authKey + 48, 16); |
469 | - SHA1 (buffer, 48, hash); |
470 | - memcpy (aes_key_raw + 8, hash + 8, 12); |
471 | - memcpy (aes_iv + 12, hash, 8); |
472 | - |
473 | - memcpy (buffer, authKey + 64, 32); |
474 | - memcpy (buffer + 32, msgKey, 16); |
475 | - SHA1 (buffer, 48, hash); |
476 | - memcpy (aes_key_raw + 20, hash + 4, 12); |
477 | - memcpy (aes_iv + 20, hash + 16, 4); |
478 | - |
479 | - memcpy (buffer, msgKey, 16); |
480 | - memcpy (buffer + 16, authKey + 96, 32); |
481 | - SHA1 (buffer, 48, hash); |
482 | - memcpy (aes_iv + 24, hash, 8); |
483 | - |
484 | - if (encrypt == AES_ENCRYPT) { |
485 | - AES_set_encrypt_key (aes_key_raw, 32*8, &aes_key); |
486 | - } else { |
487 | - AES_set_decrypt_key (aes_key_raw, 32*8, &aes_key); |
488 | - } |
489 | - memset (aes_key_raw, 0, sizeof (aes_key_raw)); |
490 | -} |
491 | - |
492 | -qint32 CryptoUtils::padAESEncrypt (const char *from, qint32 fromLen, char *to, qint32 size) { |
493 | - qint32 paddedSize = (fromLen + 15) & -16; |
494 | - Q_UNUSED(size); |
495 | - Q_ASSERT(fromLen > 0 && paddedSize <= size); |
496 | - if (fromLen < paddedSize) { |
497 | - qint32 isRandSupported = RAND_pseudo_bytes ((uchar *) from + fromLen, paddedSize - fromLen); |
498 | - Q_UNUSED(isRandSupported); |
499 | - Q_ASSERT(isRandSupported >= 0); |
500 | - } |
501 | - AES_ige_encrypt ((uchar *) from, (uchar *) to, paddedSize, &aes_key, aes_iv, AES_ENCRYPT); |
502 | - return paddedSize; |
503 | -} |
504 | - |
505 | -qint32 CryptoUtils::padAESDecrypt (const char *from, qint32 fromLen, char *to, qint32 size) { |
506 | - if (fromLen <= 0 || fromLen > size || (fromLen & 15)) { |
507 | - return -1; |
508 | - } |
509 | - AES_ige_encrypt ((const uchar *) from, (uchar *) to, fromLen, &aes_key, aes_iv, AES_DECRYPT); |
510 | - return fromLen; |
511 | -} |
512 | - |
513 | -qint32 CryptoUtils::checkPrime (BIGNUM *p) { |
514 | - qint32 r = BN_is_prime (p, BN_prime_checks, 0, BN_ctx, 0); |
515 | - Utils::ensure (r >= 0); |
516 | - return r; |
517 | -} |
518 | - |
519 | -qint32 CryptoUtils::checkDHParams (BIGNUM *p, qint32 g) { |
520 | - if (g < 2 || g > 7) { return -1; } |
521 | - BIGNUM t; |
522 | - BN_init (&t); |
523 | - |
524 | - BIGNUM dh_g; |
525 | - BN_init (&dh_g); |
526 | - Utils::ensure (BN_set_word (&dh_g, 4 * g)); |
527 | - |
528 | - Utils::ensure (BN_mod (&t, p, &dh_g, BN_ctx)); |
529 | - qint32 x = BN_get_word (&t); |
530 | - Q_ASSERT(x >= 0 && x < 4 * g); |
531 | - |
532 | - BN_free (&dh_g); |
533 | - |
534 | - switch (g) { |
535 | - case 2: |
536 | - if (x != 7) { return -1; } |
537 | - break; |
538 | - case 3: |
539 | - if (x % 3 != 2 ) { return -1; } |
540 | - break; |
541 | - case 4: |
542 | - break; |
543 | - case 5: |
544 | - if (x % 5 != 1 && x % 5 != 4) { return -1; } |
545 | - break; |
546 | - case 6: |
547 | - if (x != 19 && x != 23) { return -1; } |
548 | - break; |
549 | - case 7: |
550 | - if (x % 7 != 3 && x % 7 != 5 && x % 7 != 6) { return -1; } |
551 | - break; |
552 | - } |
553 | - |
554 | - if (!checkPrime (p)) { return -1; } |
555 | - |
556 | - BIGNUM b; |
557 | - BN_init (&b); |
558 | - Utils::ensure (BN_set_word (&b, 2)); |
559 | - Utils::ensure (BN_div (&t, 0, p, &b, BN_ctx)); |
560 | - if (!checkPrime (&t)) { return -1; } |
561 | - BN_free (&b); |
562 | - BN_free (&t); |
563 | - return 0; |
564 | -} |
565 | - |
566 | -/** |
567 | - https://core.telegram.org/api/end-to-end says: |
568 | - "Both clients in a secret chat creation are to check that g, g_a and g_b are greater than one and smaller than p-1. |
569 | - Recommented checking that g_a and g_b are between 2^{2048-64} and p - 2^{2048-64} as well." |
570 | -*/ |
571 | -qint32 CryptoUtils::checkCalculatedParams(const BIGNUM *gAOrB, const BIGNUM *g, const BIGNUM *p) { |
572 | - ASSERT(gAOrB); |
573 | - ASSERT(g); |
574 | - ASSERT(p); |
575 | - |
576 | - // 1) gAOrB and g greater than one and smaller than p-1 |
577 | - BIGNUM one; |
578 | - BN_init(&one); |
579 | - Utils::ensure(BN_one(&one)); |
580 | - |
581 | - BIGNUM *pMinusOne = BN_dup(p); |
582 | - Utils::ensure(BN_sub_word(pMinusOne, 1)); |
583 | - |
584 | - // check params greater than one |
585 | - if (BN_cmp(gAOrB, &one) <= 0) return -1; |
586 | - if (BN_cmp(g, &one) <= 0) return -1; |
587 | - |
588 | - // check params <= p-1 |
589 | - if (BN_cmp(gAOrB, pMinusOne) >= 0) return -1; |
590 | - if (BN_cmp(g, pMinusOne) >= 0) return -1; |
591 | - |
592 | - // 2) gAOrB between 2^{2048-64} and p - 2^{2048-64} |
593 | - quint64 expWord = 2048 - 64; |
594 | - BIGNUM exp; |
595 | - BN_init(&exp); |
596 | - Utils::ensure(BN_set_word(&exp, expWord)); |
597 | - |
598 | - BIGNUM base; |
599 | - BN_init(&base); |
600 | - Utils::ensure(BN_set_word(&base, 2)); |
601 | - |
602 | - // lowLimit = base ^ exp |
603 | - BIGNUM lowLimit; |
604 | - BN_init(&lowLimit); |
605 | - Utils::ensure(BN_exp(&lowLimit, &base, &exp, BN_ctx)); |
606 | - |
607 | - // highLimit = p - lowLimit |
608 | - BIGNUM highLimit; |
609 | - BN_init(&highLimit); |
610 | - BN_sub(&highLimit, p, &lowLimit); |
611 | - |
612 | - if (BN_cmp(gAOrB, &lowLimit) < 0) return -1; |
613 | - if (BN_cmp(gAOrB, &highLimit) > 0) return -1; |
614 | - |
615 | - BN_free(&one); |
616 | - BN_free(pMinusOne); |
617 | - BN_free(&exp); |
618 | - BN_free(&lowLimit); |
619 | - BN_free(&highLimit); |
620 | - |
621 | - return 0; |
622 | -} |
623 | - |
624 | -qint32 CryptoUtils::BNModExp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m) { |
625 | - return BN_mod_exp (r, a, p, m, BN_ctx); |
626 | -} |
627 | - |
628 | -QByteArray CryptoUtils::encryptFilePart(const QByteArray &partBytes, uchar *key, uchar *iv) { |
629 | - qint32 length = partBytes.length(); |
630 | - uchar *buffer = (uchar *)partBytes.constData(); |
631 | - // Use an output buffer for not to modify original one. |
632 | - // Max size of the output buffer, included padding, will be length + 15 |
633 | - uchar out[length + 15]; |
634 | - memcpy(out, buffer, length); |
635 | - |
636 | - // in case this part length % 0xF != 0, it means is the last part and we must pad the size to match AES block size (16) |
637 | - qint32 paddedSize = length; |
638 | - if (length & 15) { |
639 | - paddedSize = (length + 15) & -16; |
640 | - if (length < paddedSize) { |
641 | - RAND_pseudo_bytes(out + length, paddedSize - length); |
642 | - } |
643 | - } |
644 | - |
645 | - AES_KEY aesKey; |
646 | - AES_set_encrypt_key(key, 256, &aesKey); |
647 | - AES_ige_encrypt(out, out, paddedSize, &aesKey, iv, AES_ENCRYPT); |
648 | - memset(&aesKey, 0, sizeof(aesKey)); |
649 | - |
650 | - return QByteArray((char *)out, paddedSize); |
651 | -} |
652 | - |
653 | -QByteArray CryptoUtils::decryptFilePart(const QByteArray &partBytes, uchar *key, uchar *iv) { |
654 | - qint32 length = partBytes.length(); |
655 | - uchar *buffer = (uchar *)partBytes.constData(); |
656 | - |
657 | - ASSERT(!(length & 15)); |
658 | - AES_KEY aesKey; |
659 | - AES_set_decrypt_key(key, 256, &aesKey); |
660 | - AES_ige_encrypt(buffer, buffer, length, &aesKey, iv, AES_DECRYPT); |
661 | - memset(&aesKey, 0, sizeof(aesKey)); |
662 | - |
663 | - return QByteArray::fromRawData((char *)buffer, length); |
664 | -} |
665 | - |
666 | -qint32 CryptoUtils::computeKeyFingerprint(const QByteArray &keyBytes, const QByteArray &ivBytes) { |
667 | - uchar *key = (uchar *)keyBytes.data(); |
668 | - uchar *iv = (uchar *)ivBytes.data(); |
669 | - uchar md5[16]; |
670 | - uchar str[64]; |
671 | - memcpy(str, key, 32); |
672 | - memcpy(str + 32, iv, 32); |
673 | - MD5(str, 64, md5); |
674 | - qint32 keyFingerprint = (*(int *)md5) ^ (*(int *)(md5 + 4)); |
675 | - return keyFingerprint; |
676 | -} |
677 | |
678 | === removed file 'lib/core/cryptoutils.h' |
679 | --- lib/core/cryptoutils.h 2014-11-28 18:46:13 +0000 |
680 | +++ lib/core/cryptoutils.h 1970-01-01 00:00:00 +0000 |
681 | @@ -1,69 +0,0 @@ |
682 | -/* |
683 | - * Copyright 2013 Vitaly Valtman |
684 | - * Copyright 2014 Canonical Ltd. |
685 | - * Authors: |
686 | - * Roberto Mier |
687 | - * Tiago Herrmann |
688 | - * |
689 | - * This program is free software; you can redistribute it and/or modify |
690 | - * it under the terms of the GNU General Public License as published by |
691 | - * the Free Software Foundation; version 3. |
692 | - * |
693 | - * This program is distributed in the hope that it will be useful, |
694 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
695 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
696 | - * GNU General Public License for more details. |
697 | - * |
698 | - * You should have received a copy of the GNU General Public License |
699 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
700 | - * |
701 | - */ |
702 | - |
703 | -#ifndef CRYPTOUTILS_H |
704 | -#define CRYPTOUTILS_H |
705 | - |
706 | -#include <QObject> |
707 | -#include "outboundpkt.h" |
708 | - |
709 | -#include <openssl/bn.h> |
710 | -#include <openssl/aes.h> |
711 | - |
712 | -class CryptoUtils : public QObject |
713 | -{ |
714 | - Q_OBJECT |
715 | -public: |
716 | - static CryptoUtils *getInstance(); |
717 | - |
718 | - qint32 encryptPacketBuffer(OutboundPkt &p, void *encryptBuffer); |
719 | - qint32 encryptPacketBufferAESUnAuth(const char serverNonce[16], const char hiddenClientNonce[32], OutboundPkt &p, void *encryptBuffer); |
720 | - qint32 padRsaEncrypt(char *from, qint32 from_len, char *to, qint32 size, BIGNUM *N, BIGNUM *E); |
721 | - |
722 | - void initAESAuth (char authKey[192], char msgKey[16], qint32 encrypt); |
723 | - void initAESUnAuth(const char serverNonce[16], const char hiddenClientNonce[32], qint32 encrypt); |
724 | - qint32 padAESDecrypt(const char *from, qint32 fromLen, char *to, qint32 size); |
725 | - qint32 padAESEncrypt(const char *from, qint32 fromLen, char *to, qint32 size); |
726 | - |
727 | - qint32 checkPrime(BIGNUM *p); |
728 | - qint32 checkDHParams(BIGNUM *p, qint32 g); |
729 | - qint32 checkCalculatedParams(const BIGNUM *gAOrB, const BIGNUM *g, const BIGNUM *p); |
730 | - |
731 | - qint32 BNModExp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m); |
732 | - |
733 | - QByteArray encryptFilePart(const QByteArray &partBytes, uchar *key, uchar *iv); |
734 | - QByteArray decryptFilePart(const QByteArray &partBytes, uchar *key, uchar *iv); |
735 | - qint32 computeKeyFingerprint(const QByteArray &key, const QByteArray &iv); |
736 | - |
737 | -private: |
738 | - CryptoUtils(); |
739 | - ~CryptoUtils(); |
740 | - CryptoUtils(const CryptoUtils &); |
741 | - CryptoUtils &operator=(const CryptoUtils &); |
742 | - |
743 | - static CryptoUtils *m_instance; |
744 | - |
745 | - BN_CTX *BN_ctx; |
746 | - uchar aes_key_raw[32], aes_iv[32]; |
747 | - AES_KEY aes_key; |
748 | -}; |
749 | - |
750 | -#endif // CRYPTOUTILS_H |
751 | |
752 | === modified file 'lib/core/dc.h' |
753 | --- lib/core/dc.h 2014-12-02 13:01:22 +0000 |
754 | +++ lib/core/dc.h 2015-02-24 14:12:31 +0000 |
755 | @@ -27,7 +27,7 @@ |
756 | #include "inboundpkt.h" |
757 | #include "connection.h" |
758 | #include "settings.h" |
759 | -#include "cryptoutils.h" |
760 | +#include "util/cryptoutils.h" |
761 | |
762 | class DC : public Endpoint |
763 | { |
764 | |
765 | === modified file 'lib/core/dcauth.cpp' |
766 | --- lib/core/dcauth.cpp 2014-12-22 22:01:28 +0000 |
767 | +++ lib/core/dcauth.cpp 2015-02-24 14:12:31 +0000 |
768 | @@ -22,12 +22,12 @@ |
769 | #include "dcauth.h" |
770 | |
771 | #include "openssl/sha.h" |
772 | -#include "utils.h" |
773 | -#include "tlvalues.h" |
774 | -#include "asserter.h" |
775 | +#include "util/utils.h" |
776 | +#include "util/tlvalues.h" |
777 | +#include "util/asserter.h" |
778 | #include <QDateTime> |
779 | |
780 | -Q_LOGGING_CATEGORY(TG_AUTH_DCAUTH, "tg.auth.dcauth") |
781 | +Q_LOGGING_CATEGORY(TG_CORE_DCAUTH, "tg.core.dcauth") |
782 | |
783 | DCAuth::DCAuth(DC *dc, QObject *parent) : Connection(dc->host(), dc->port(), parent) , m_dc(dc) { |
784 | } |
785 | @@ -48,7 +48,7 @@ |
786 | Q_EMIT dcReady(m_dc); |
787 | } |
788 | } else { |
789 | - qCWarning(TG_AUTH_DCAUTH) << "Error! provided DC for creating auth key is null"; |
790 | + qCWarning(TG_CORE_DCAUTH) << "Error! provided DC for creating auth key is null"; |
791 | } |
792 | } |
793 | |
794 | @@ -63,13 +63,13 @@ |
795 | Q_EMIT dcReady(m_dc); |
796 | break; |
797 | default: |
798 | - qCCritical(TG_AUTH_DCAUTH) << "Invalid state:" << m_dc->state(); |
799 | + qCCritical(TG_CORE_DCAUTH) << "Invalid state:" << m_dc->state(); |
800 | Q_EMIT fatalError(); |
801 | } |
802 | } |
803 | |
804 | void DCAuth::sendReqPQPacket() { |
805 | - qCDebug(TG_AUTH_DCAUTH) << "sendReqPQPacket()"; |
806 | + qCDebug(TG_CORE_DCAUTH) << "sendReqPQPacket()"; |
807 | mAsserter.check(m_dc->state() == DC::init); |
808 | Utils::randomBytes(m_nonce, 16); |
809 | OutboundPkt outboundPkt; |
810 | @@ -77,7 +77,7 @@ |
811 | outboundPkt.appendInts((qint32 *)m_nonce, 4); |
812 | rpcSendPacket(outboundPkt); |
813 | m_dc->setState(DC::reqPQSent); |
814 | - qCDebug(TG_AUTH_DCAUTH) << "changed state to reqPQSent"; |
815 | + qCDebug(TG_CORE_DCAUTH) << "changed state to reqPQSent"; |
816 | } |
817 | |
818 | void DCAuth::processResPQAnswer(const InboundPkt &inboundPkt) { |
819 | @@ -86,7 +86,7 @@ |
820 | const char* buffer = inboundPkt.buffer(); |
821 | qint32 i; |
822 | |
823 | - qCDebug(TG_AUTH_DCAUTH) << "processResPQAnswer(), len=" << len; |
824 | + qCDebug(TG_CORE_DCAUTH) << "processResPQAnswer(), len=" << len; |
825 | |
826 | mAsserter.check(len >= 76); |
827 | mAsserter.check(!*(qint64 *) buffer); |
828 | @@ -107,7 +107,7 @@ |
829 | |
830 | uint p1 = 0, p2 = 0; |
831 | |
832 | - qCDebug(TG_AUTH_DCAUTH) << "received pq =" << what; |
833 | + qCDebug(TG_CORE_DCAUTH) << "received pq =" << what; |
834 | |
835 | qint64 g = Utils::findDivider(what); |
836 | mAsserter.check(g > 1 && g < what); |
837 | @@ -117,7 +117,7 @@ |
838 | uint t = p1; p1 = p2; p2 = t; |
839 | } |
840 | |
841 | - qCDebug(TG_AUTH_DCAUTH) << "p1 =" << p1 << ", p2 =" << p2; |
842 | + qCDebug(TG_CORE_DCAUTH) << "p1 =" << p1 << ", p2 =" << p2; |
843 | |
844 | mAsserter.check(*(qint32 *) (from) == TL_Vector); |
845 | qint32 fingerprints_num = *(qint32 *)(from + 4); |
846 | @@ -125,13 +125,13 @@ |
847 | qint64 *fingerprints = (qint64 *) (from + 8); |
848 | for (i = 0; i < fingerprints_num; i++) { |
849 | if (fingerprints[i] == Settings::getInstance()->pkFingerprint()) { |
850 | - qCDebug(TG_AUTH_DCAUTH) << "found our public key at position" << i; |
851 | + qCDebug(TG_CORE_DCAUTH) << "found our public key at position" << i; |
852 | break; |
853 | } |
854 | } |
855 | if (i == fingerprints_num) { |
856 | - qCWarning(TG_AUTH_DCAUTH) << "fatal: don't have any matching keys (" << QString::number(Settings::getInstance()->pkFingerprint(), 16) << "expected)"; |
857 | - exit (2); |
858 | + qCWarning(TG_CORE_DCAUTH) << "fatal: don't have any matching keys (" << QString::number(Settings::getInstance()->pkFingerprint(), 16) << "expected)"; |
859 | + Q_EMIT fatalError(); |
860 | } |
861 | |
862 | // create inner part (P_Q_inner_data) |
863 | @@ -173,7 +173,7 @@ |
864 | void DCAuth::processDHAnswer(InboundPkt &inboundPkt) { |
865 | const char *buffer = inboundPkt.buffer(); |
866 | qint32 len = inboundPkt.length(); |
867 | - qCDebug(TG_AUTH_DCAUTH) << "processDHAnswer(), len=" << len; |
868 | + qCDebug(TG_CORE_DCAUTH) << "processDHAnswer(), len=" << len; |
869 | |
870 | mAsserter.check(len >= 116); |
871 | mAsserter.check(!*(qint64 *) buffer); |
872 | @@ -277,7 +277,7 @@ |
873 | void DCAuth::processAuthComplete(InboundPkt &inboundPkt) { |
874 | const char *buffer = inboundPkt.buffer(); |
875 | qint32 len = inboundPkt.length(); |
876 | - qCDebug(TG_AUTH_DCAUTH) << "processAuthComplete(), len=" << len; |
877 | + qCDebug(TG_CORE_DCAUTH) << "processAuthComplete(), len=" << len; |
878 | |
879 | mAsserter.check(len == 72); |
880 | mAsserter.check(!*(qint64 *) buffer); |
881 | @@ -300,8 +300,8 @@ |
882 | m_dc->setServerSalt(*(qint64 *)m_serverNonce ^ *(qint64 *)m_newNonce); |
883 | m_dc->setState(DC::authKeyCreated); |
884 | |
885 | - qCDebug(TG_AUTH_DCAUTH) << "created auth shared key for DC" << m_dc->id(); |
886 | - qCDebug(TG_AUTH_DCAUTH) << "auth_key_id =" << m_dc->authKeyId(); |
887 | + qCDebug(TG_CORE_DCAUTH) << "created auth shared key for DC" << m_dc->id(); |
888 | + qCDebug(TG_CORE_DCAUTH) << "auth_key_id =" << m_dc->authKeyId(); |
889 | |
890 | Q_EMIT dcReady(m_dc); |
891 | } |
892 | @@ -312,7 +312,7 @@ |
893 | peekIn(&op, 4); |
894 | qint32 len = response.length(); |
895 | |
896 | - qCDebug(TG_AUTH_DCAUTH) << "connection #" << socketDescriptor() << "received rpc answer" << op << "with" << len << "content bytes"; |
897 | + qCDebug(TG_CORE_DCAUTH) << "connection #" << socketDescriptor() << "received rpc answer" << op << "with" << len << "content bytes"; |
898 | |
899 | InboundPkt p(response.data(), len); |
900 | |
901 | @@ -330,8 +330,8 @@ |
902 | case DC::userSignedIn: |
903 | break; |
904 | default: |
905 | - qCWarning(TG_AUTH_DCAUTH) << "fatal: cannot receive answer in state" << m_dc->state(); |
906 | - exit (2); |
907 | + qCWarning(TG_CORE_DCAUTH) << "fatal: cannot receive answer in state" << m_dc->state(); |
908 | + Q_EMIT fatalError(); |
909 | } |
910 | } |
911 | |
912 | @@ -362,5 +362,5 @@ |
913 | } |
914 | writeOut(&unencMsgHeader, 20); |
915 | writeOut(packet.buffer(), len); |
916 | - qCDebug(TG_AUTH_DCAUTH) << "packet sent"; |
917 | + qCDebug(TG_CORE_DCAUTH) << "packet sent"; |
918 | } |
919 | |
920 | === modified file 'lib/core/dcauth.h' |
921 | --- lib/core/dcauth.h 2014-09-29 12:33:11 +0000 |
922 | +++ lib/core/dcauth.h 2015-02-24 14:12:31 +0000 |
923 | @@ -24,10 +24,10 @@ |
924 | |
925 | #include "dc.h" |
926 | #include "connection.h" |
927 | -#include "asserter.h" |
928 | +#include "util/asserter.h" |
929 | #include <QLoggingCategory> |
930 | |
931 | -Q_DECLARE_LOGGING_CATEGORY(TG_AUTH_DCAUTH) |
932 | +Q_DECLARE_LOGGING_CATEGORY(TG_CORE_DCAUTH) |
933 | |
934 | class DCAuth : public Connection |
935 | { |
936 | |
937 | === modified file 'lib/core/dcprovider.cpp' |
938 | --- lib/core/dcprovider.cpp 2014-12-22 22:01:28 +0000 |
939 | +++ lib/core/dcprovider.cpp 2015-02-24 14:12:31 +0000 |
940 | @@ -16,10 +16,10 @@ |
941 | */ |
942 | |
943 | #include "dcprovider.h" |
944 | -#include "constants.h" |
945 | +#include "util/constants.h" |
946 | #include "session.h" |
947 | |
948 | -Q_LOGGING_CATEGORY(TG_INIT_DCPROVIDER, "tg.init.dcprovider") |
949 | +Q_LOGGING_CATEGORY(TG_CORE_DCPROVIDER, "tg.core.dcprovider") |
950 | |
951 | DcProvider::DcProvider() : mApi(0), mPendingDcs(0), mPendingTransferSessions(0), mWorkingDcSession(0) { |
952 | } |
953 | @@ -137,7 +137,7 @@ |
954 | } |
955 | |
956 | void DcProvider::onDcReady(DC *dc) { |
957 | - qCDebug(TG_INIT_DCPROVIDER) << "DC" << dc->id() << "ready"; |
958 | + qCDebug(TG_CORE_DCPROVIDER) << "DC" << dc->id() << "ready"; |
959 | // disconnect dcAuth to avoid consuming bandwidth with unnecessary connections |
960 | DCAuth *dcAuth = mDcAuths.value(dc->id()); |
961 | if (dcAuth) { |
962 | @@ -172,7 +172,7 @@ |
963 | Settings::getInstance()->setDcsList(mDcs.values()); |
964 | Settings::getInstance()->writeAuthFile(); |
965 | |
966 | - qCDebug(TG_INIT_DCPROVIDER) << "DcProvider ready"; |
967 | + qCDebug(TG_CORE_DCPROVIDER) << "DcProvider ready"; |
968 | Q_EMIT dcProviderReady(); |
969 | |
970 | // if current dc is in "authKeyCreated" state, authNeeded signal must be emitted for user to sign in. |
971 | @@ -196,7 +196,7 @@ |
972 | void DcProvider::onApiError() { |
973 | |
974 | Session *session = qobject_cast<Session *>(sender()); |
975 | - qCWarning(TG_INIT_DCPROVIDER) << "Api init error when connecting session to server:" << session->errorString(); |
976 | + qCWarning(TG_CORE_DCPROVIDER) << "Api init error when connecting session to server:" << session->errorString(); |
977 | |
978 | // after emitting these startup offline signals, we don't want to do it again when session gets connected, so disconnect signal-slot |
979 | disconnect(session, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onApiError())); |
980 | @@ -230,7 +230,7 @@ |
981 | |
982 | void DcProvider::onApiReady(DC*) { |
983 | Session *session = qobject_cast<Session *>(sender()); |
984 | - qCDebug(TG_INIT_DCPROVIDER) << "Api connected to server and ready"; |
985 | + qCDebug(TG_CORE_DCPROVIDER) << "Api connected to server and ready"; |
986 | |
987 | // after emitting the api startup signals, we don't want to do it again when session gets connected, so disconnect signal-slot |
988 | disconnect(session, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onApiError())); |
989 | @@ -244,15 +244,15 @@ |
990 | |
991 | void DcProvider::onConfigReceived(qint64 msgId, qint32 date, bool testMode, qint32 thisDc, const QList<DcOption> &dcOptions, qint32 chatMaxSize, qint32 broadcastMaxSize) { |
992 | |
993 | - qCDebug(TG_INIT_DCPROVIDER) << "onConfigReceived(), msgId =" << QString::number(msgId, 16); |
994 | - qCDebug(TG_INIT_DCPROVIDER) << "date =" << date; |
995 | - qCDebug(TG_INIT_DCPROVIDER) << "testMode =" << testMode; |
996 | - qCDebug(TG_INIT_DCPROVIDER) << "thisDc =" << thisDc; |
997 | + qCDebug(TG_CORE_DCPROVIDER) << "onConfigReceived(), msgId =" << QString::number(msgId, 16); |
998 | + qCDebug(TG_CORE_DCPROVIDER) << "date =" << date; |
999 | + qCDebug(TG_CORE_DCPROVIDER) << "testMode =" << testMode; |
1000 | + qCDebug(TG_CORE_DCPROVIDER) << "thisDc =" << thisDc; |
1001 | |
1002 | mPendingDcs = dcOptions.length() -1; //all the received options but the default one, yet used |
1003 | |
1004 | Q_FOREACH (DcOption dcOption, dcOptions) { |
1005 | - qCDebug(TG_INIT_DCPROVIDER) << "dcOption | id =" << dcOption.id() << ", ipAddress =" << dcOption.ipAddress() << |
1006 | + qCDebug(TG_CORE_DCPROVIDER) << "dcOption | id =" << dcOption.id() << ", ipAddress =" << dcOption.ipAddress() << |
1007 | ", port =" << dcOption.port() << ", hostname =" << dcOption.hostname(); |
1008 | |
1009 | // for every new DC or not authenticated DC, insert into m_dcs and authenticate |
1010 | @@ -283,8 +283,8 @@ |
1011 | } |
1012 | } |
1013 | |
1014 | - qCDebug(TG_INIT_DCPROVIDER) << "chatMaxSize =" << chatMaxSize; |
1015 | - qCDebug(TG_INIT_DCPROVIDER) << "broadcastMaxSize =" << broadcastMaxSize; |
1016 | + qCDebug(TG_CORE_DCPROVIDER) << "chatMaxSize =" << chatMaxSize; |
1017 | + qCDebug(TG_CORE_DCPROVIDER) << "broadcastMaxSize =" << broadcastMaxSize; |
1018 | } |
1019 | |
1020 | Api *DcProvider::getApi() const { |
1021 | |
1022 | === modified file 'lib/core/dcprovider.h' |
1023 | --- lib/core/dcprovider.h 2014-09-29 16:27:49 +0000 |
1024 | +++ lib/core/dcprovider.h 2015-02-24 14:12:31 +0000 |
1025 | @@ -27,7 +27,7 @@ |
1026 | #include "dcauth.h" |
1027 | #include "api.h" |
1028 | |
1029 | -Q_DECLARE_LOGGING_CATEGORY(TG_INIT_DCPROVIDER) |
1030 | +Q_DECLARE_LOGGING_CATEGORY(TG_CORE_DCPROVIDER) |
1031 | |
1032 | class DcProvider : public QObject |
1033 | { |
1034 | |
1035 | === modified file 'lib/core/inboundpkt.cpp' |
1036 | --- lib/core/inboundpkt.cpp 2015-01-28 17:06:39 +0000 |
1037 | +++ lib/core/inboundpkt.cpp 2015-02-24 14:12:31 +0000 |
1038 | @@ -22,11 +22,11 @@ |
1039 | #include "inboundpkt.h" |
1040 | |
1041 | #include <QDebug> |
1042 | -#include "utils.h" |
1043 | -#include "tlvalues.h" |
1044 | +#include "util/utils.h" |
1045 | +#include "util/tlvalues.h" |
1046 | #include "telegram.h" |
1047 | |
1048 | -Q_LOGGING_CATEGORY(TG_NET_FETCH, "tg.net.fetch") |
1049 | +Q_LOGGING_CATEGORY(TG_CORE_INBOUNDPKT, "tg.core.inboundpkt") |
1050 | |
1051 | InboundPkt::InboundPkt(char *buffer, qint32 length) : |
1052 | m_buffer(buffer), |
1053 | @@ -86,21 +86,21 @@ |
1054 | |
1055 | qint32 InboundPkt::fetchInt() { |
1056 | Q_ASSERT(m_inPtr + 1 <= m_inEnd); |
1057 | - qCDebug(TG_NET_FETCH) << "fetchInt()" << *m_inPtr << " (" << Utils::toHex(*m_inPtr) << ")"; |
1058 | + qCDebug(TG_CORE_INBOUNDPKT) << "fetchInt()" << *m_inPtr << " (" << Utils::toHex(*m_inPtr) << ")"; |
1059 | return *(m_inPtr ++); |
1060 | } |
1061 | |
1062 | bool InboundPkt::fetchBool() { |
1063 | Q_ASSERT(m_inPtr + 1 <= m_inEnd); |
1064 | ASSERT(*(m_inPtr) == (qint32)TL_BoolTrue || *(m_inPtr) == (qint32)TL_BoolFalse); |
1065 | - qCDebug(TG_NET_FETCH) << "fetchBool()" << (*(m_inPtr) == (qint32)TL_BoolTrue) << " (" << Utils::toHex(*m_inPtr) << ")"; |
1066 | + qCDebug(TG_CORE_INBOUNDPKT) << "fetchBool()" << (*(m_inPtr) == (qint32)TL_BoolTrue) << " (" << Utils::toHex(*m_inPtr) << ")"; |
1067 | return *(m_inPtr++) == (qint32)TL_BoolTrue; |
1068 | } |
1069 | |
1070 | qint64 InboundPkt::fetchLong() { |
1071 | Q_ASSERT(m_inPtr + 2 <= m_inEnd); |
1072 | qint64 r = *(qint64 *)m_inPtr; |
1073 | - qCDebug(TG_NET_FETCH) << "fetchLong()" << r ; |
1074 | + qCDebug(TG_CORE_INBOUNDPKT) << "fetchLong()" << r ; |
1075 | m_inPtr += 2; |
1076 | return r; |
1077 | } |
1078 | @@ -122,7 +122,7 @@ |
1079 | |
1080 | char *InboundPkt::fetchStr(qint32 len) { |
1081 | Q_ASSERT(len >= 0); |
1082 | - qCDebug(TG_NET_FETCH) << "fetchStr(), len =" << len; |
1083 | + qCDebug(TG_CORE_INBOUNDPKT) << "fetchStr(), len =" << len; |
1084 | char *str; |
1085 | if (len < 254) { |
1086 | str = (char *)m_inPtr + 1; |
1087 | |
1088 | === modified file 'lib/core/inboundpkt.h' |
1089 | --- lib/core/inboundpkt.h 2015-01-28 17:06:39 +0000 |
1090 | +++ lib/core/inboundpkt.h 2015-02-24 14:12:31 +0000 |
1091 | @@ -62,7 +62,7 @@ |
1092 | |
1093 | #include "secret/secretchat.h" |
1094 | |
1095 | -Q_DECLARE_LOGGING_CATEGORY(TG_NET_FETCH) |
1096 | +Q_DECLARE_LOGGING_CATEGORY(TG_CORE_INBOUNDPKT) |
1097 | |
1098 | class InboundPkt |
1099 | { |
1100 | |
1101 | === modified file 'lib/core/outboundpkt.cpp' |
1102 | --- lib/core/outboundpkt.cpp 2015-01-28 17:06:39 +0000 |
1103 | +++ lib/core/outboundpkt.cpp 2015-02-24 14:12:31 +0000 |
1104 | @@ -23,10 +23,10 @@ |
1105 | |
1106 | #include <sys/utsname.h> |
1107 | |
1108 | -#include "utils.h" |
1109 | -#include "tlvalues.h" |
1110 | +#include "util/utils.h" |
1111 | +#include "util/tlvalues.h" |
1112 | |
1113 | -Q_LOGGING_CATEGORY(TG_NET_APPEND, "tg.net.append") |
1114 | +Q_LOGGING_CATEGORY(TG_CORE_OUTBOUNDPKT, "tg.core.outboundpkt") |
1115 | |
1116 | template <typename T_> |
1117 | void do_delete(T_ buf[]) { |
1118 | @@ -67,7 +67,7 @@ |
1119 | |
1120 | void OutboundPkt::appendLong(qint64 x) { |
1121 | Q_ASSERT(m_packetPtr + 2 <= m_packetBuffer + PACKET_BUFFER_SIZE); |
1122 | - qCDebug(TG_NET_APPEND) << "appendLong()" << QString::number(x) << " (" << "0x" + QString::number(x,16) << ")";; |
1123 | + qCDebug(TG_CORE_OUTBOUNDPKT) << "appendLong()" << QString::number(x) << " (" << "0x" + QString::number(x,16) << ")";; |
1124 | *(qint64 *)m_packetPtr = x; |
1125 | m_packetPtr += 2; |
1126 | } |
1127 | @@ -91,13 +91,13 @@ |
1128 | |
1129 | void OutboundPkt::appendInt (qint32 x) { |
1130 | Q_ASSERT(m_packetPtr + 1 <= m_packetBuffer + PACKET_BUFFER_SIZE); |
1131 | - qCDebug(TG_NET_APPEND) << "appendInt()" << QString::number(x) << " (" << "0x" + QString::number(x,16) << ")";; |
1132 | + qCDebug(TG_CORE_OUTBOUNDPKT) << "appendInt()" << QString::number(x) << " (" << "0x" + QString::number(x,16) << ")";; |
1133 | *m_packetPtr++ = x; |
1134 | } |
1135 | |
1136 | void OutboundPkt::appendDouble(double d) { |
1137 | Q_ASSERT(m_packetPtr + 2 <= m_packetBuffer + PACKET_BUFFER_SIZE); |
1138 | - qCDebug(TG_NET_APPEND) << "appendInt()" << QString::number(d); |
1139 | + qCDebug(TG_CORE_OUTBOUNDPKT) << "appendInt()" << QString::number(d); |
1140 | *(double *)m_packetPtr = d; |
1141 | m_packetPtr += 2; |
1142 | } |
1143 | @@ -125,7 +125,7 @@ |
1144 | } |
1145 | |
1146 | void OutboundPkt::appendQString (const QString &string) { |
1147 | -// qCDebug(TG_NET_APPEND) << "appendQString()" << string; |
1148 | +// qCDebug(TG_CORE_OUTBOUNDPKT) << "appendQString()" << string; |
1149 | QByteArray bytes = string.toUtf8(); |
1150 | appendCString(bytes.data(), bytes.length()); |
1151 | } |
1152 | @@ -138,7 +138,7 @@ |
1153 | } |
1154 | |
1155 | void OutboundPkt::appendBool(bool b) { |
1156 | - qCDebug(TG_NET_APPEND) << "appendBool()" << b; |
1157 | + qCDebug(TG_CORE_OUTBOUNDPKT) << "appendBool()" << b; |
1158 | b ? appendInt(TL_BoolTrue) : appendInt(TL_BoolFalse); |
1159 | } |
1160 | |
1161 | |
1162 | === modified file 'lib/core/outboundpkt.h' |
1163 | --- lib/core/outboundpkt.h 2015-01-28 17:06:39 +0000 |
1164 | +++ lib/core/outboundpkt.h 2015-02-24 14:12:31 +0000 |
1165 | @@ -26,7 +26,7 @@ |
1166 | #include <QByteArray> |
1167 | #include <QLoggingCategory> |
1168 | #include <openssl/bn.h> |
1169 | -#include "constants.h" |
1170 | +#include "util/constants.h" |
1171 | #include "settings.h" |
1172 | #include "types/inputpeer.h" |
1173 | #include "types/inputuser.h" |
1174 | @@ -50,7 +50,7 @@ |
1175 | |
1176 | #include <QSharedPointer> |
1177 | |
1178 | -Q_DECLARE_LOGGING_CATEGORY(TG_NET_APPEND) |
1179 | +Q_DECLARE_LOGGING_CATEGORY(TG_CORE_OUTBOUNDPKT) |
1180 | |
1181 | class OutboundPkt |
1182 | { |
1183 | |
1184 | === modified file 'lib/core/query.h' |
1185 | --- lib/core/query.h 2014-09-12 22:00:16 +0000 |
1186 | +++ lib/core/query.h 2015-02-24 14:12:31 +0000 |
1187 | @@ -22,7 +22,7 @@ |
1188 | #ifndef QUERY_H |
1189 | #define QUERY_H |
1190 | |
1191 | -#include "utils.h" |
1192 | +#include "util/utils.h" |
1193 | #include "inboundpkt.h" |
1194 | #include "querymethods.h" |
1195 | #include "dc.h" |
1196 | |
1197 | === modified file 'lib/core/session.cpp' |
1198 | --- lib/core/session.cpp 2014-12-09 18:01:27 +0000 |
1199 | +++ lib/core/session.cpp 2015-02-24 14:12:31 +0000 |
1200 | @@ -23,9 +23,9 @@ |
1201 | #include "openssl/rand.h" |
1202 | #include "openssl/sha.h" |
1203 | #include <QDateTime> |
1204 | -#include "tlvalues.h" |
1205 | +#include "util/tlvalues.h" |
1206 | |
1207 | -Q_LOGGING_CATEGORY(TG_NET_SESSION, "tg.net.session") |
1208 | +Q_LOGGING_CATEGORY(TG_CORE_SESSION, "tg.core.session") |
1209 | |
1210 | qint64 Session::m_clientLastMsgId = 0; |
1211 | |
1212 | @@ -45,11 +45,11 @@ |
1213 | m_serverSalt = m_dc->serverSalt(); |
1214 | // create session id |
1215 | RAND_pseudo_bytes((uchar *) &m_sessionId, 8); |
1216 | - qCDebug(TG_NET_SESSION) << "created session with id" << QString::number(m_sessionId, 16); |
1217 | + qCDebug(TG_CORE_SESSION) << "created session with id" << QString::number(m_sessionId, 16); |
1218 | } |
1219 | |
1220 | Session::~Session() { |
1221 | - qCDebug(TG_NET_SESSION) << "destroyed session with id" << QString::number(m_sessionId, 16); |
1222 | + qCDebug(TG_CORE_SESSION) << "destroyed session with id" << QString::number(m_sessionId, 16); |
1223 | } |
1224 | |
1225 | void Session::close() { |
1226 | @@ -93,12 +93,12 @@ |
1227 | peekIn(&op, 4); |
1228 | qint32 len = response.length(); |
1229 | |
1230 | - qCDebug(TG_NET_SESSION) << "connection #" << socketDescriptor() << "received rpc answer" << op << "with" << len << "content bytes by session" << QString::number(m_sessionId, 16); |
1231 | + qCDebug(TG_CORE_SESSION) << "connection #" << socketDescriptor() << "received rpc answer" << op << "with" << len << "content bytes by session" << QString::number(m_sessionId, 16); |
1232 | |
1233 | InboundPkt p(response.data(), len); |
1234 | |
1235 | if (op < 0 && op >= -999) { |
1236 | - qCDebug(TG_NET_SESSION) << "server error" << op; |
1237 | + qCDebug(TG_CORE_SESSION) << "server error" << op; |
1238 | } else { |
1239 | processRpcMessage(p); |
1240 | } |
1241 | @@ -111,7 +111,7 @@ |
1242 | |
1243 | const qint32 MINSZ = offsetof (EncryptedMsg, message); |
1244 | const qint32 UNENCSZ = offsetof (EncryptedMsg, serverSalt); |
1245 | - qCDebug(TG_NET_SESSION) << "processRpcMessage(), len=" << len; |
1246 | + qCDebug(TG_CORE_SESSION) << "processRpcMessage(), len=" << len; |
1247 | |
1248 | Q_ASSERT(len >= MINSZ && (len & 15) == (UNENCSZ & 15)); |
1249 | Q_ASSERT(m_dc->authKeyId()); |
1250 | @@ -136,20 +136,20 @@ |
1251 | qint32 serverTime = enc->msgId >> 32LL; |
1252 | qint32 clientTime = QDateTime::currentDateTime().toTime_t() - mTimeDifference; |
1253 | if (clientTime <= serverTime - 30 || clientTime >= serverTime + 300) { |
1254 | - qCDebug(TG_NET_SESSION) << "salt =" << enc->serverSalt << ", sessionId =" << QString::number(enc->sessionId, 16) << ", msgId =" << QString::number(enc->msgId, 16) << ", seqNo =" << enc->seqNo << ", serverTime =" << serverTime << ", clientTime =" << clientTime; |
1255 | + qCDebug(TG_CORE_SESSION) << "salt =" << enc->serverSalt << ", sessionId =" << QString::number(enc->sessionId, 16) << ", msgId =" << QString::number(enc->msgId, 16) << ", seqNo =" << enc->seqNo << ", serverTime =" << serverTime << ", clientTime =" << clientTime; |
1256 | QString alert("Received message has too large difference between client and server dates - "); |
1257 | if (clientTime <= serverTime -30) { |
1258 | alert.append("the message has a date at least 30 seconds later in time than current date"); |
1259 | } else { |
1260 | alert.append("the message was sent at least 300 seconds ago"); |
1261 | } |
1262 | - qCWarning(TG_NET_SESSION) << alert; |
1263 | + qCWarning(TG_CORE_SESSION) << alert; |
1264 | } |
1265 | |
1266 | inboundPkt.setInPtr(enc->message); |
1267 | inboundPkt.setInEnd(inboundPkt.inPtr() + (enc->msgLen / 4)); |
1268 | |
1269 | - qCDebug(TG_NET_SESSION) << "received message id" << QString::number(enc->msgId, 16); |
1270 | + qCDebug(TG_CORE_SESSION) << "received message id" << QString::number(enc->msgId, 16); |
1271 | |
1272 | Q_ASSERT(l >= (MINSZ - UNENCSZ) + 8); |
1273 | |
1274 | @@ -164,7 +164,7 @@ |
1275 | |
1276 | void Session::rpcExecuteAnswer(InboundPkt &inboundPkt, qint64 msgId) { |
1277 | qint32 op = inboundPkt.prefetchInt(); |
1278 | - qCDebug(TG_NET_SESSION) << "rpcExecuteAnswer(), op =" << QString::number(op, 16); |
1279 | + qCDebug(TG_CORE_SESSION) << "rpcExecuteAnswer(), op =" << QString::number(op, 16); |
1280 | switch (op) { |
1281 | case TL_MsgContainer: |
1282 | workContainer(inboundPkt, msgId); |
1283 | @@ -214,12 +214,12 @@ |
1284 | workBadMsgNotification(inboundPkt, msgId); |
1285 | return; |
1286 | } |
1287 | - qCWarning(TG_NET_SESSION) << "Unknown rpc response message"; |
1288 | + qCWarning(TG_CORE_SESSION) << "Unknown rpc response message"; |
1289 | inboundPkt.setInPtr(inboundPkt.inEnd()); |
1290 | } |
1291 | |
1292 | void Session::workContainer (InboundPkt &inboundPkt, qint64 msgId) { |
1293 | - qCDebug(TG_NET_SESSION) << "workContainer: msgId =" << QString::number(msgId, 16); |
1294 | + qCDebug(TG_CORE_SESSION) << "workContainer: msgId =" << QString::number(msgId, 16); |
1295 | mAsserter.check(inboundPkt.fetchInt() == TL_MsgContainer); |
1296 | qint32 n = inboundPkt.fetchInt(); |
1297 | for (qint32 i = 0; i < n; i++) { // message |
1298 | @@ -238,7 +238,7 @@ |
1299 | } |
1300 | |
1301 | void Session::workNewSessionCreated(InboundPkt &inboundPkt, qint64 msgId) { |
1302 | - qCDebug(TG_NET_SESSION) << "workNewSessionCreated: msgId =" << QString::number(msgId, 16); |
1303 | + qCDebug(TG_CORE_SESSION) << "workNewSessionCreated: msgId =" << QString::number(msgId, 16); |
1304 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_NewSessionCreated); |
1305 | inboundPkt.fetchLong(); // first_msg_id; //XXX set is as m_clientLastMsgId?? |
1306 | inboundPkt.fetchLong (); // unique_id |
1307 | @@ -246,7 +246,7 @@ |
1308 | } |
1309 | |
1310 | void Session::workMsgsAck(InboundPkt &inboundPkt, qint64 msgId) { |
1311 | - qCDebug(TG_NET_SESSION) << "workMsgsAck: msgId =" << QString::number(msgId, 16); |
1312 | + qCDebug(TG_CORE_SESSION) << "workMsgsAck: msgId =" << QString::number(msgId, 16); |
1313 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_MsgsAck); |
1314 | mAsserter.check(inboundPkt.fetchInt () == (qint32)TL_Vector); |
1315 | qint32 n = inboundPkt.fetchInt(); |
1316 | @@ -259,7 +259,7 @@ |
1317 | } |
1318 | |
1319 | void Session::workRpcResult(InboundPkt &inboundPkt, qint64 msgId) { |
1320 | - qCDebug(TG_NET_SESSION) << "workRpcResult: msgId =" << QString::number(msgId, 16); |
1321 | + qCDebug(TG_CORE_SESSION) << "workRpcResult: msgId =" << QString::number(msgId, 16); |
1322 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_RpcResult); |
1323 | qint64 id = inboundPkt.fetchLong(); |
1324 | qint32 op = inboundPkt.prefetchInt(); |
1325 | @@ -271,7 +271,7 @@ |
1326 | } |
1327 | |
1328 | void Session::workUpdateShort(InboundPkt &inboundPkt, qint64 msgId) { |
1329 | - qCDebug(TG_NET_SESSION) << "workUpdateShort: msgId =" << QString::number(msgId, 16); |
1330 | + qCDebug(TG_CORE_SESSION) << "workUpdateShort: msgId =" << QString::number(msgId, 16); |
1331 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_UpdateShort); |
1332 | Update update = inboundPkt.fetchUpdate(); |
1333 | qint32 date = inboundPkt.fetchInt(); |
1334 | @@ -279,7 +279,7 @@ |
1335 | } |
1336 | |
1337 | void Session::workUpdatesCombined(InboundPkt &inboundPkt, qint64 msgId) { |
1338 | - qCDebug(TG_NET_SESSION) << "workUpdatesCombined: msgId =" << QString::number(msgId, 16); |
1339 | + qCDebug(TG_CORE_SESSION) << "workUpdatesCombined: msgId =" << QString::number(msgId, 16); |
1340 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_UpdatesCombined); |
1341 | //updates |
1342 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_Vector); |
1343 | @@ -309,7 +309,7 @@ |
1344 | } |
1345 | |
1346 | void Session::workUpdates(InboundPkt &inboundPkt, qint64 msgId) { |
1347 | - qCDebug(TG_NET_SESSION) << "workUpdates: msgId =" << QString::number(msgId, 16); |
1348 | + qCDebug(TG_CORE_SESSION) << "workUpdates: msgId =" << QString::number(msgId, 16); |
1349 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_Updates); |
1350 | //updates |
1351 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_Vector); |
1352 | @@ -338,7 +338,7 @@ |
1353 | } |
1354 | |
1355 | void Session::workUpdateShortMessage(InboundPkt &inboundPkt, qint64 msgId) { |
1356 | - qCDebug(TG_NET_SESSION) << "workUpdateShortMessage: msgId =" << QString::number(msgId, 16); |
1357 | + qCDebug(TG_CORE_SESSION) << "workUpdateShortMessage: msgId =" << QString::number(msgId, 16); |
1358 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_UpdateShortMessage); |
1359 | qint32 id = inboundPkt.fetchInt(); |
1360 | qint32 fromId = inboundPkt.fetchInt(); |
1361 | @@ -350,7 +350,7 @@ |
1362 | } |
1363 | |
1364 | void Session::workUpdateShortChatMessage(InboundPkt &inboundPkt, qint64 msgId) { |
1365 | - qCDebug(TG_NET_SESSION) << "workUpdateShortChatMessage: msgId =" << QString::number(msgId, 16); |
1366 | + qCDebug(TG_CORE_SESSION) << "workUpdateShortChatMessage: msgId =" << QString::number(msgId, 16); |
1367 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_UpdateShortChatMessage); |
1368 | qint32 id = inboundPkt.fetchInt(); |
1369 | qint32 fromId = inboundPkt.fetchInt(); |
1370 | @@ -363,7 +363,7 @@ |
1371 | } |
1372 | |
1373 | void Session::workPacked(InboundPkt &inboundPkt, qint64 msgId) { |
1374 | - qCDebug(TG_NET_SESSION) << "workPacked: msgId =" << QString::number(msgId, 16); |
1375 | + qCDebug(TG_CORE_SESSION) << "workPacked: msgId =" << QString::number(msgId, 16); |
1376 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_GZipPacked); |
1377 | static qint32 buf[MAX_PACKED_SIZE >> 2]; |
1378 | qint32 l = inboundPkt.prefetchStrlen(); |
1379 | @@ -374,14 +374,14 @@ |
1380 | qint32 *inEnd = inboundPkt.inEnd(); |
1381 | inboundPkt.setInPtr(buf); |
1382 | inboundPkt.setInEnd(inboundPkt.inPtr() + totalOut / 4); |
1383 | - qCDebug(TG_NET_SESSION) << "Unzipped data"; |
1384 | + qCDebug(TG_CORE_SESSION) << "Unzipped data"; |
1385 | rpcExecuteAnswer(inboundPkt, msgId); |
1386 | inboundPkt.setInPtr(inPtr); //TODO Not sure about this operations of setting inPtr and inEnd after execute answer completion |
1387 | inboundPkt.setInEnd(inEnd); |
1388 | } |
1389 | |
1390 | void Session::workBadServerSalt(InboundPkt &inboundPkt, qint64 msgId) { |
1391 | - qCDebug(TG_NET_SESSION) << "workBadServerSalt: msgId =" << QString::number(msgId, 16); |
1392 | + qCDebug(TG_CORE_SESSION) << "workBadServerSalt: msgId =" << QString::number(msgId, 16); |
1393 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_BadServerSalt); |
1394 | qint64 badMsgId = inboundPkt.fetchLong(); |
1395 | inboundPkt.fetchInt(); // badMsgSeqNo |
1396 | @@ -393,14 +393,14 @@ |
1397 | } |
1398 | |
1399 | void Session::workPong(InboundPkt &inboundPkt, qint64 msgId) { |
1400 | - qCDebug(TG_NET_SESSION) << "workPong: msgId =" << QString::number(msgId, 16); |
1401 | + qCDebug(TG_CORE_SESSION) << "workPong: msgId =" << QString::number(msgId, 16); |
1402 | mAsserter.check (inboundPkt.fetchInt() == (qint32)TL_Pong); |
1403 | inboundPkt.fetchLong(); // msg_id |
1404 | inboundPkt.fetchLong(); // ping_id |
1405 | } |
1406 | |
1407 | void Session::workDetailedInfo(InboundPkt &inboundPkt, qint64 msgId) { |
1408 | - qCDebug(TG_NET_SESSION) << "workDetailedInfo: msgId =" << QString::number(msgId, 16); |
1409 | + qCDebug(TG_CORE_SESSION) << "workDetailedInfo: msgId =" << QString::number(msgId, 16); |
1410 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_MsgDetailedInfo); |
1411 | inboundPkt.fetchLong(); // msg_id |
1412 | inboundPkt.fetchLong(); // answer_msg_id |
1413 | @@ -409,7 +409,7 @@ |
1414 | } |
1415 | |
1416 | void Session::workNewDetailedInfo(InboundPkt &inboundPkt, qint64 msgId) { |
1417 | - qCDebug(TG_NET_SESSION) << "workNewDetailedInfo: msgId =" << QString::number(msgId, 16); |
1418 | + qCDebug(TG_CORE_SESSION) << "workNewDetailedInfo: msgId =" << QString::number(msgId, 16); |
1419 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_MsgNewDetailedInfo); |
1420 | inboundPkt.fetchLong(); // answer_msg_id |
1421 | inboundPkt.fetchInt(); // bytes |
1422 | @@ -417,7 +417,7 @@ |
1423 | } |
1424 | |
1425 | void Session::workUpdatesTooLong(InboundPkt &inboundPkt, qint64 msgId) { |
1426 | - qCDebug(TG_NET_SESSION) << "workUpdatesTooLong: msgId =" << QString::number(msgId, 16); |
1427 | + qCDebug(TG_CORE_SESSION) << "workUpdatesTooLong: msgId =" << QString::number(msgId, 16); |
1428 | mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_UpdatesTooLong); |
1429 | Q_EMIT updatesTooLong(); |
1430 | } |
1431 | @@ -427,7 +427,7 @@ |
1432 | qint64 badMsgId = inboundPkt.fetchLong(); |
1433 | qint32 badMsgSeqNo = inboundPkt.fetchInt(); |
1434 | qint32 errorCode = inboundPkt.fetchInt(); |
1435 | - qCWarning(TG_NET_SESSION) << "workBadMsgNotification: msgId =" << badMsgId << |
1436 | + qCWarning(TG_CORE_SESSION) << "workBadMsgNotification: msgId =" << badMsgId << |
1437 | ", seqNo =" << badMsgSeqNo << ", errorCode =" << errorCode; |
1438 | switch (errorCode) { |
1439 | case 16: |
1440 | @@ -467,7 +467,7 @@ |
1441 | qint32 encLen = (MINSZ - UNENCSZ) + encMsg->msgLen; |
1442 | Q_ASSERT (encMsg->msgLen >= 0 && encMsg->msgLen <= MAX_MESSAGE_INTS * 4 - 16 && !(encMsg->msgLen & 3)); |
1443 | SHA1 ((uchar *) &encMsg->serverSalt, encLen, sha1Buffer); |
1444 | - qCDebug(TG_NET_SESSION) << "sending message with sha1" << QString::number(*(qint32 *)sha1Buffer, 8); |
1445 | + qCDebug(TG_CORE_SESSION) << "sending message with sha1" << QString::number(*(qint32 *)sha1Buffer, 8); |
1446 | |
1447 | memcpy (encMsg->msgKey, sha1Buffer + 4, 16); |
1448 | CryptoUtils::getInstance()->initAESAuth(m_dc->authKey(), encMsg->msgKey, AES_ENCRYPT); |
1449 | @@ -524,13 +524,13 @@ |
1450 | qint32 *data = outboundPkt.buffer(); |
1451 | qint32 ints = outboundPkt.length(); |
1452 | |
1453 | - qCDebug(TG_NET_SESSION) << "Sending query of size" << 4 * ints << "to DC" << m_dc->id() << "at" << peerName() << ":" << peerPort() << "by session" << QString::number(m_sessionId, 16); |
1454 | + qCDebug(TG_CORE_SESSION) << "Sending query of size" << 4 * ints << "to DC" << m_dc->id() << "at" << peerName() << ":" << peerPort() << "by session" << QString::number(m_sessionId, 16); |
1455 | |
1456 | Query *q = new Query(this); |
1457 | q->setData(data, ints); |
1458 | q->setMsgId(encryptSendMessage(data, ints, 1)); |
1459 | q->setSeqNo(m_seqNo - 1); |
1460 | - qCDebug(TG_NET_SESSION) << "msgId is" << QString::number(q->msgId(), 16); |
1461 | + qCDebug(TG_CORE_SESSION) << "msgId is" << QString::number(q->msgId(), 16); |
1462 | q->setMethods(methods); |
1463 | q->setAcked(false); |
1464 | q->setExtra(extra); |
1465 | @@ -547,10 +547,10 @@ |
1466 | |
1467 | void Session::recomposeAndSendQuery(Query *q) { |
1468 | Q_ASSERT(q); |
1469 | - qCDebug(TG_NET_SESSION) << "Resending query with previous msgId" << QString::number(q->msgId(), 16); |
1470 | + qCDebug(TG_CORE_SESSION) << "Resending query with previous msgId" << QString::number(q->msgId(), 16); |
1471 | q->setMsgId(encryptSendMessage((qint32 *)q->data(), q->dataLength(), 1)); |
1472 | q->setSeqNo(m_seqNo - 1); |
1473 | - qCDebug(TG_NET_SESSION) << "new msgId is" << QString::number(q->msgId(), 16); |
1474 | + qCDebug(TG_CORE_SESSION) << "new msgId is" << QString::number(q->msgId(), 16); |
1475 | q->setAcked(false); |
1476 | m_pendingQueries.insert(q->msgId(), q); |
1477 | } |
1478 | @@ -559,11 +559,11 @@ |
1479 | Q_ASSERT(q); |
1480 | //avoid resending if resend numbers is less than zero |
1481 | if (q->decreaseResends() < 0) { |
1482 | - qCDebug(TG_NET_SESSION) << "Max resend numbers reached for query with msgId" << QString::number(q->msgId(), 16) << ",query discarded"; |
1483 | + qCDebug(TG_CORE_SESSION) << "Max resend numbers reached for query with msgId" << QString::number(q->msgId(), 16) << ",query discarded"; |
1484 | m_pendingQueries.remove(q->msgId()); |
1485 | delete q; |
1486 | } else { |
1487 | - qCDebug(TG_NET_SESSION) << "Resending query with msgId" << QString::number(q->msgId(), 16); |
1488 | + qCDebug(TG_CORE_SESSION) << "Resending query with msgId" << QString::number(q->msgId(), 16); |
1489 | OutboundPkt p; |
1490 | p.appendInt(TL_MsgContainer); |
1491 | p.appendInt(1); |
1492 | @@ -576,7 +576,7 @@ |
1493 | } |
1494 | |
1495 | void Session::queryOnResult(InboundPkt &inboundPkt, qint64 msgId) { |
1496 | - qCDebug(TG_NET_SESSION) << "result for query" << QString::number(msgId, 16); |
1497 | + qCDebug(TG_CORE_SESSION) << "result for query" << QString::number(msgId, 16); |
1498 | qint32 op = inboundPkt.prefetchInt(); |
1499 | qint32 *inPtr = 0; |
1500 | qint32 *inEnd = 0; |
1501 | @@ -590,15 +590,15 @@ |
1502 | inEnd = inboundPkt.inEnd(); |
1503 | inboundPkt.setInPtr(packedBuffer); |
1504 | inboundPkt.setInEnd(inboundPkt.inPtr() + totalOut / 4); |
1505 | - qCDebug(TG_NET_SESSION) << "unzipped data"; |
1506 | + qCDebug(TG_CORE_SESSION) << "unzipped data"; |
1507 | } |
1508 | |
1509 | Query *q = m_pendingQueries.take(msgId); |
1510 | if (!q) { |
1511 | - qCWarning(TG_NET_SESSION) << "No such query"; |
1512 | + qCWarning(TG_CORE_SESSION) << "No such query"; |
1513 | inboundPkt.setInPtr(inboundPkt.inEnd()); |
1514 | } else { |
1515 | - qCDebug(TG_NET_SESSION) << "acked query with msgId" << QString::number(msgId, 16) << ",pendingQueries:" << m_pendingQueries.size(); |
1516 | + qCDebug(TG_CORE_SESSION) << "acked query with msgId" << QString::number(msgId, 16) << ",pendingQueries:" << m_pendingQueries.size(); |
1517 | q->setAcked(true); |
1518 | Q_EMIT resultReceived(q, inboundPkt); |
1519 | } |
1520 | @@ -613,11 +613,11 @@ |
1521 | mAsserter.check(inboundPkt.fetchInt() == TL_RpcError); |
1522 | qint32 errorCode = inboundPkt.fetchInt(); |
1523 | QString errorText = inboundPkt.fetchQString(); |
1524 | - qCDebug(TG_NET_SESSION) << "error for query" << QString::number(msgId, 16) << " :" << errorCode << " :" << errorText; |
1525 | + qCDebug(TG_CORE_SESSION) << "error for query" << QString::number(msgId, 16) << " :" << errorCode << " :" << errorText; |
1526 | |
1527 | Query *q = m_pendingQueries.take(msgId); |
1528 | if (!q) { |
1529 | - qCWarning(TG_NET_SESSION) << "No such query"; |
1530 | + qCWarning(TG_CORE_SESSION) << "No such query"; |
1531 | } else { |
1532 | q->setAcked(true); |
1533 | Q_EMIT errorReceived(q, errorCode, errorText); |
1534 | @@ -653,7 +653,7 @@ |
1535 | p.appendInt(n); |
1536 | Q_FOREACH (qint64 msgId, msgIds) { |
1537 | p.appendLong(msgId); |
1538 | - qCDebug(TG_NET_SESSION) << "Ack for msgId" << msgId; |
1539 | + qCDebug(TG_CORE_SESSION) << "Ack for msgId" << msgId; |
1540 | EventTimer* t = m_pendingAcks.take(msgId); |
1541 | if (t) { |
1542 | t->stop(); |
1543 | @@ -661,5 +661,5 @@ |
1544 | } |
1545 | } |
1546 | qint64 sentAcksId = encryptSendMessage(p.buffer(), p.length(), 0); |
1547 | - qCDebug(TG_NET_SESSION) << "Sent Acks with id:" << QString::number(sentAcksId, 16); |
1548 | + qCDebug(TG_CORE_SESSION) << "Sent Acks with id:" << QString::number(sentAcksId, 16); |
1549 | } |
1550 | |
1551 | === modified file 'lib/core/session.h' |
1552 | --- lib/core/session.h 2014-12-09 18:01:27 +0000 |
1553 | +++ lib/core/session.h 2015-02-24 14:12:31 +0000 |
1554 | @@ -30,7 +30,7 @@ |
1555 | |
1556 | #include "eventtimer.h" |
1557 | |
1558 | -Q_DECLARE_LOGGING_CATEGORY(TG_NET_SESSION) |
1559 | +Q_DECLARE_LOGGING_CATEGORY(TG_CORE_SESSION) |
1560 | |
1561 | class Session : public Connection |
1562 | { |
1563 | |
1564 | === modified file 'lib/core/sessionmanager.cpp' |
1565 | --- lib/core/sessionmanager.cpp 2014-12-17 11:12:11 +0000 |
1566 | +++ lib/core/sessionmanager.cpp 2015-02-24 14:12:31 +0000 |
1567 | @@ -20,6 +20,8 @@ |
1568 | |
1569 | #include "sessionmanager.h" |
1570 | |
1571 | +Q_LOGGING_CATEGORY(TG_CORE_SESSIONMANAGER, "tg.core.sessionmanager") |
1572 | + |
1573 | SessionManager::SessionManager(Session *session, QObject *parent) : |
1574 | QObject(parent), mMainSession(session) { |
1575 | connect(mMainSession, SIGNAL(sessionReady(DC*)), this, SIGNAL(mainSessionReady()), Qt::UniqueConnection); |
1576 | @@ -49,7 +51,7 @@ |
1577 | } |
1578 | |
1579 | resourcesAtDc++; |
1580 | - qCDebug(TG_NET_SESSION) << "file session resources at DC" << dc->id() << resourcesAtDc; |
1581 | + qCDebug(TG_CORE_SESSIONMANAGER) << "file session resources at DC" << dc->id() << resourcesAtDc; |
1582 | |
1583 | return session; |
1584 | } |
1585 | @@ -58,7 +60,7 @@ |
1586 | Session *session = createSession(dc); |
1587 | mFileSessions.insert(session->sessionId(), session); |
1588 | mDcSessionIds.insert(dc->id(), session->sessionId()); |
1589 | - qCDebug(TG_NET_SESSION) << "created file session at DC" << dc->id(); |
1590 | + qCDebug(TG_CORE_SESSIONMANAGER) << "created file session at DC" << dc->id(); |
1591 | return session; |
1592 | } |
1593 | |
1594 | @@ -80,10 +82,10 @@ |
1595 | if (!resourcesAtDc) { |
1596 | session->close(); |
1597 | mDcSessionIds.remove(dcId); |
1598 | - qCDebug(TG_NET_SESSION) << "closed file session at DC" << dcId; |
1599 | - qCDebug(TG_NET_SESSION) << "remaining" << mFileSessions.count() << "file sessions, counting all DCs"; |
1600 | + qCDebug(TG_CORE_SESSIONMANAGER) << "closed file session at DC" << dcId; |
1601 | + qCDebug(TG_CORE_SESSIONMANAGER) << "remaining" << mFileSessions.count() << "file sessions, counting all DCs"; |
1602 | } else { |
1603 | - qCDebug(TG_NET_SESSION) << "released file session at DC" << dcId << ", remaining" << resourcesAtDc << "resources"; |
1604 | + qCDebug(TG_CORE_SESSIONMANAGER) << "released file session at DC" << dcId << ", remaining" << resourcesAtDc << "resources"; |
1605 | } |
1606 | } else if (mMainSession && mMainSession->sessionId() == sessionId) { |
1607 | mMainSession->close(); |
1608 | |
1609 | === modified file 'lib/core/sessionmanager.h' |
1610 | --- lib/core/sessionmanager.h 2014-11-20 13:44:13 +0000 |
1611 | +++ lib/core/sessionmanager.h 2015-02-24 14:12:31 +0000 |
1612 | @@ -23,9 +23,12 @@ |
1613 | |
1614 | #include <QObject> |
1615 | #include <QMap> |
1616 | +#include <QLoggingCategory> |
1617 | #include "session.h" |
1618 | #include "dc.h" |
1619 | |
1620 | +Q_DECLARE_LOGGING_CATEGORY(TG_CORE_SESSIONMANAGER) |
1621 | + |
1622 | class SessionManager : public QObject |
1623 | { |
1624 | Q_OBJECT |
1625 | |
1626 | === modified file 'lib/core/settings.cpp' |
1627 | --- lib/core/settings.cpp 2015-02-11 18:35:01 +0000 |
1628 | +++ lib/core/settings.cpp 2015-02-24 14:12:31 +0000 |
1629 | @@ -19,8 +19,8 @@ |
1630 | */ |
1631 | |
1632 | #include "settings.h" |
1633 | -#include "utils.h" |
1634 | -#include "constants.h" |
1635 | +#include "util/utils.h" |
1636 | +#include "util/constants.h" |
1637 | #include "dc.h" |
1638 | |
1639 | #include <QDir> |
1640 | @@ -31,7 +31,7 @@ |
1641 | |
1642 | #include <openssl/bn.h> |
1643 | |
1644 | -Q_LOGGING_CATEGORY(TG_INIT_SETTINGS, "tg.init.settings") |
1645 | +Q_LOGGING_CATEGORY(TG_CORE_SETTINGS, "tg.core.settings") |
1646 | |
1647 | Settings::Settings() : |
1648 | m_phoneNumber(""), |
1649 | @@ -64,16 +64,16 @@ |
1650 | if (!m_pubKey) { |
1651 | m_pubKey = Utils::rsaLoadPublicKey(publicKeyFile); |
1652 | m_pkFingerprint = Utils::computeRSAFingerprint(m_pubKey); |
1653 | - qCDebug(TG_INIT_SETTINGS) << "loaded Telegram public key from file:" << publicKeyFile; |
1654 | + qCDebug(TG_CORE_SETTINGS) << "loaded Telegram public key from file:" << publicKeyFile; |
1655 | } |
1656 | |
1657 | - qCDebug(TG_INIT_SETTINGS) << "loading configuration from path:" << configPath; |
1658 | + qCDebug(TG_CORE_SETTINGS) << "loading configuration from path:" << configPath; |
1659 | QDir configDir = QDir(configPath); |
1660 | if (!configDir.exists()) { |
1661 | if (QDir::root().mkpath(configPath)) { |
1662 | - qCDebug(TG_INIT_SETTINGS) << configPath << "config directory created"; |
1663 | + qCDebug(TG_CORE_SETTINGS) << configPath << "config directory created"; |
1664 | } else { |
1665 | - qCWarning(TG_INIT_SETTINGS) << "error creating config directory: " << configPath; |
1666 | + qCWarning(TG_CORE_SETTINGS) << "error creating config directory: " << configPath; |
1667 | return false; |
1668 | } |
1669 | } |
1670 | @@ -88,13 +88,13 @@ |
1671 | out << DEFAULT_CONFIG_CONTENTS; |
1672 | configFile.close(); |
1673 | } else { |
1674 | - qCWarning(TG_INIT_SETTINGS) << "Impossible to open file " << configFilename << " for writting default configuration"; |
1675 | + qCWarning(TG_CORE_SETTINGS) << "Impossible to open file " << configFilename << " for writting default configuration"; |
1676 | return false; |
1677 | } |
1678 | } |
1679 | |
1680 | //read settings |
1681 | - qCDebug(TG_INIT_SETTINGS) << "loading settings file" << configFilename; |
1682 | + qCDebug(TG_CORE_SETTINGS) << "loading settings file" << configFilename; |
1683 | QSettings settings(configFilename, QSettings::IniFormat); |
1684 | m_testMode = settings.value(ST_TEST_MODE, false).toBool(); |
1685 | m_managedDownloads = settings.value(ST_MANAGED_DOWNLOADS, false).toBool(); |
1686 | @@ -105,12 +105,12 @@ |
1687 | m_stateFilename = settings.value(ST_STATE_FILE, configPath + '/' + STATE_FILE).toString(); |
1688 | |
1689 | // log readed data |
1690 | - qCDebug(TG_INIT_SETTINGS) << "testMode:" << m_testMode; |
1691 | - qCDebug(TG_INIT_SETTINGS) << "managedDownloads:" << m_managedDownloads; |
1692 | - qCDebug(TG_INIT_SETTINGS) << "lang:" << m_langCode; |
1693 | - qCDebug(TG_INIT_SETTINGS) << "authFile:" << m_authFilename; |
1694 | - qCDebug(TG_INIT_SETTINGS) << "secretChatFile:" << m_secretChatFilename; |
1695 | - qCDebug(TG_INIT_SETTINGS) << "stateFile:" << m_stateFilename; |
1696 | + qCDebug(TG_CORE_SETTINGS) << "testMode:" << m_testMode; |
1697 | + qCDebug(TG_CORE_SETTINGS) << "managedDownloads:" << m_managedDownloads; |
1698 | + qCDebug(TG_CORE_SETTINGS) << "lang:" << m_langCode; |
1699 | + qCDebug(TG_CORE_SETTINGS) << "authFile:" << m_authFilename; |
1700 | + qCDebug(TG_CORE_SETTINGS) << "secretChatFile:" << m_secretChatFilename; |
1701 | + qCDebug(TG_CORE_SETTINGS) << "stateFile:" << m_stateFilename; |
1702 | |
1703 | readAuthFile(); |
1704 | readSecretFile(); |
1705 | @@ -150,8 +150,8 @@ |
1706 | m_workingDcNum = settings.value(ST_WORKING_DC_NUM, defaultDcId).toInt(); |
1707 | m_ourId = settings.value(ST_OUR_ID).toInt(); |
1708 | |
1709 | - qCDebug(TG_INIT_SETTINGS) << "workingDcNum:" << m_workingDcNum; |
1710 | - qCDebug(TG_INIT_SETTINGS) << "ourId:" << m_ourId; |
1711 | + qCDebug(TG_CORE_SETTINGS) << "workingDcNum:" << m_workingDcNum; |
1712 | + qCDebug(TG_CORE_SETTINGS) << "ourId:" << m_ourId; |
1713 | |
1714 | // read all dcs |
1715 | m_dcsList.clear(); |
1716 | @@ -171,7 +171,7 @@ |
1717 | dc->setServerSalt(settings.value(ST_SERVER_SALT, 0).toLongLong()); |
1718 | dc->setExpires(settings.value(ST_EXPIRES).toInt()); |
1719 | |
1720 | - qCDebug(TG_INIT_SETTINGS) << "DC | id:" << dc->id() << ", state:" << dc->state() << |
1721 | + qCDebug(TG_CORE_SETTINGS) << "DC | id:" << dc->id() << ", state:" << dc->state() << |
1722 | ", host:" << dc->host() << ", port:" << dc->port() << |
1723 | ", expires:" << dc->expires() << ", authKeyId:" << dc->authKeyId() << |
1724 | ", serverSalt:" << dc->serverSalt(); |
1725 | @@ -186,10 +186,10 @@ |
1726 | QFile authFile(m_authFilename); |
1727 | if (authFile.exists()) { |
1728 | if (authFile.remove()) { |
1729 | - qCDebug(TG_INIT_SETTINGS) << "Auth file has been reset"; |
1730 | + qCDebug(TG_CORE_SETTINGS) << "Auth file has been reset"; |
1731 | return true; |
1732 | } else { |
1733 | - qCDebug(TG_INIT_SETTINGS) << "An error has happened when trying to remove auth file"; |
1734 | + qCDebug(TG_CORE_SETTINGS) << "An error has happened when trying to remove auth file"; |
1735 | } |
1736 | } |
1737 | return false; |
1738 | @@ -201,9 +201,9 @@ |
1739 | mG = settings.value(ST_G, 0).toInt(); |
1740 | mP = QByteArray::fromBase64(settings.value(ST_P).toByteArray()); |
1741 | |
1742 | - qCDebug(TG_INIT_SETTINGS) << "secret chats dh version:" << mVersion; |
1743 | - qCDebug(TG_INIT_SETTINGS) << "secret chats g:" << mG; |
1744 | - qCDebug(TG_INIT_SETTINGS) << "secret chats p:" << mP.toBase64(); |
1745 | + qCDebug(TG_CORE_SETTINGS) << "secret chats dh version:" << mVersion; |
1746 | + qCDebug(TG_CORE_SETTINGS) << "secret chats g:" << mG; |
1747 | + qCDebug(TG_CORE_SETTINGS) << "secret chats p:" << mP.toBase64(); |
1748 | |
1749 | mSecretChats.clear(); |
1750 | qint32 n = settings.beginReadArray(ST_SECRET_CHATS_ARRAY); |
1751 | @@ -236,7 +236,7 @@ |
1752 | secretChat->setOutSeqNo(settings.value(ST_OUT_SEQ_NO, 0).toInt()); |
1753 | mSecretChats.append(secretChat); |
1754 | |
1755 | - qCDebug(TG_INIT_SETTINGS) << "SecretChat:\nid:" << secretChat->chatId() |
1756 | + qCDebug(TG_CORE_SETTINGS) << "SecretChat:\nid:" << secretChat->chatId() |
1757 | << "\nadminId:" << secretChat->adminId() |
1758 | << "\nparticipantId:" << secretChat->participantId() |
1759 | << "\ndate:" << secretChat->date() |
1760 | |
1761 | === modified file 'lib/core/settings.h' |
1762 | --- lib/core/settings.h 2015-02-04 15:46:54 +0000 |
1763 | +++ lib/core/settings.h 2015-02-24 14:12:31 +0000 |
1764 | @@ -78,7 +78,7 @@ |
1765 | #include <openssl/rsa.h> |
1766 | #include "secret/secretchat.h" |
1767 | |
1768 | -Q_DECLARE_LOGGING_CATEGORY(TG_INIT_SETTINGS) |
1769 | +Q_DECLARE_LOGGING_CATEGORY(TG_CORE_SETTINGS) |
1770 | |
1771 | class DC; |
1772 | |
1773 | |
1774 | === removed file 'lib/core/tlvalues.h' |
1775 | --- lib/core/tlvalues.h 2015-02-17 11:35:00 +0000 |
1776 | +++ lib/core/tlvalues.h 1970-01-01 00:00:00 +0000 |
1777 | @@ -1,444 +0,0 @@ |
1778 | -/* |
1779 | - * Copyright 2014 Canonical Ltd. |
1780 | - * Authors: |
1781 | - * Roberto Mier |
1782 | - * Tiago Herrmann |
1783 | - * |
1784 | - * This program is free software; you can redistribute it and/or modify |
1785 | - * it under the terms of the GNU General Public License as published by |
1786 | - * the Free Software Foundation; version 3. |
1787 | - * |
1788 | - * This program is distributed in the hope that it will be useful, |
1789 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1790 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1791 | - * GNU General Public License for more details. |
1792 | - * |
1793 | - * You should have received a copy of the GNU General Public License |
1794 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1795 | - * |
1796 | - */ |
1797 | - |
1798 | -#ifndef TLVALUES_H |
1799 | -#define TLVALUES_H |
1800 | - |
1801 | -enum TLValues { |
1802 | - // https://core.telegram.org/mtproto/auth_key |
1803 | - TL_ReqPQ = 0x60469778, |
1804 | - TL_ResPQ = 0x05162463, |
1805 | - TL_ReqDHParams = 0xd712e4be, |
1806 | - TL_PQInnerData = 0x83c95aec, |
1807 | - TL_PQInnerDataTemp = 0x3c6a84d4, |
1808 | - TL_ServerDHParamsOK = 0xd0e8075c, |
1809 | - TL_ServerDHParamsFail = 0x79cb045d, |
1810 | - TL_ServerDHInnerData = 0xb5890dba, |
1811 | - TL_ClientDHInnerData = 0x6643b654, |
1812 | - TL_SetClientDHParams = 0xf5045f1f, |
1813 | - TL_DHGenOK = 0x3bcbf734, |
1814 | - |
1815 | - // https://core.telegram.org/mtproto/service_messages |
1816 | - TL_RpcResult = 0xf35c6d01, |
1817 | - TL_RpcError = 0x2144ca19, |
1818 | - TL_RpcDropAnswer = 0x58e4a740, |
1819 | - TL_RpcAnswerUnknown = 0x5e2ad36e, |
1820 | - TL_RpcAnswerDroppedRunning = 0xcd78e586, |
1821 | - TL_RpcAnswerDropped = 0xa43ad8b7, |
1822 | - TL_GetFutureSalts = 0xb921bd04, |
1823 | - TL_FutureSalt = 0x0949d9dc, |
1824 | - TL_FutureSalts = 0xae500895, |
1825 | - TL_Ping = 0x7abe77ec, |
1826 | - TL_Pong = 0x347773c5, |
1827 | - TL_PingDelayDisconnect = 0xf3427b8c, |
1828 | - TL_DestroySession = 0xe7512126, |
1829 | - TL_DestroySessionOk = 0xe22045fc, |
1830 | - TL_DestroySessionNone = 0x62d350c9, |
1831 | - TL_NewSessionCreated = 0x9ec20908, |
1832 | - TL_MsgContainer = 0x73f1f8dc, |
1833 | - TL_MsgCopy = 0xe06046b2, |
1834 | - TL_GZipPacked = 0x3072cfa1, |
1835 | - TL_HttpWait = 0x9299359f, |
1836 | - |
1837 | - // https://core.telegram.org/mtproto/service_messages_about_messages |
1838 | - TL_MsgsAck = 0x62d6b459, |
1839 | - TL_BadMsgNotification = 0xa7eff811, |
1840 | - TL_BadServerSalt = 0xedab447b, |
1841 | - TL_MsgsStateReq = 0xda69fb52, |
1842 | - TL_MsgsStateInfo = 0x04deb57d, |
1843 | - TL_MsgsAllInfo = 0x8cc0d131, |
1844 | - TL_MsgDetailedInfo = 0x276d3ec6, |
1845 | - TL_MsgNewDetailedInfo = 0x809db6df, |
1846 | - TL_MsgResendReq = 0x7d861a08, |
1847 | - |
1848 | - // https://core.telegram.org/schema by generator |
1849 | - TL_BoolFalse = 0xbc799737, |
1850 | - TL_BoolTrue = 0x997275b5, |
1851 | - TL_Vector = 0x1cb5c415, |
1852 | - TL_Error = 0xc4b9f9bb, |
1853 | - TL_Null = 0x56730bcc, |
1854 | - TL_InputPeerEmpty = 0x7f3b18ea, |
1855 | - TL_InputPeerSelf = 0x7da07ec9, |
1856 | - TL_InputPeerContact = 0x1023dbe8, |
1857 | - TL_InputPeerForeign = 0x9b447325, |
1858 | - TL_InputPeerChat = 0x179be863, |
1859 | - TL_InputUserEmpty = 0xb98886cf, |
1860 | - TL_InputUserSelf = 0xf7c1b13f, |
1861 | - TL_InputUserContact = 0x86e94f65, |
1862 | - TL_InputUserForeign = 0x655e74ff, |
1863 | - TL_InputPhoneContact = 0xf392b7f4, |
1864 | - TL_InputFile = 0xf52ff27f, |
1865 | - TL_InputMediaEmpty = 0x9664f57f, |
1866 | - TL_InputMediaUploadedPhoto = 0x2dc53a7d, |
1867 | - TL_InputMediaPhoto = 0x8f2ab2ec, |
1868 | - TL_InputMediaGeoPoint = 0xf9c44144, |
1869 | - TL_InputMediaContact = 0xa6e45987, |
1870 | - TL_InputMediaUploadedVideo = 0x133ad6f6, |
1871 | - TL_InputMediaUploadedThumbVideo = 0x9912dabf, |
1872 | - TL_InputMediaVideo = 0x7f023ae6, |
1873 | - TL_InputChatPhotoEmpty = 0x1ca48f57, |
1874 | - TL_InputChatUploadedPhoto = 0x94254732, |
1875 | - TL_InputChatPhoto = 0xb2e1bf08, |
1876 | - TL_InputGeoPointEmpty = 0xe4c123d6, |
1877 | - TL_InputGeoPoint = 0xf3b7acc9, |
1878 | - TL_InputPhotoEmpty = 0x1cd7bf0d, |
1879 | - TL_InputPhoto = 0xfb95c6c4, |
1880 | - TL_InputVideoEmpty = 0x5508ec75, |
1881 | - TL_InputVideo = 0xee579652, |
1882 | - TL_InputFileLocation = 0x14637196, |
1883 | - TL_InputVideoFileLocation = 0x3d0364ec, |
1884 | - TL_InputPhotoCropAuto = 0xade6b004, |
1885 | - TL_InputPhotoCrop = 0xd9915325, |
1886 | - TL_InputAppEvent = 0x770656a8, |
1887 | - TL_PeerUser = 0x9db1bc6d, |
1888 | - TL_PeerChat = 0xbad0e5bb, |
1889 | - TL_StorageFileUnknown = 0xaa963b05, |
1890 | - TL_StorageFileJpeg = 0x7efe0e, |
1891 | - TL_StorageFileGif = 0xcae1aadf, |
1892 | - TL_StorageFilePng = 0xa4f63c0, |
1893 | - TL_StorageFilePdf = 0xae1e508d, |
1894 | - TL_StorageFileMp3 = 0x528a0677, |
1895 | - TL_StorageFileMov = 0x4b09ebbc, |
1896 | - TL_StorageFilePartial = 0x40bc6f52, |
1897 | - TL_StorageFileMp4 = 0xb3cea0e4, |
1898 | - TL_StorageFileWebp = 0x1081464c, |
1899 | - TL_FileLocationUnavailable = 0x7c596b46, |
1900 | - TL_FileLocation = 0x53d69076, |
1901 | - TL_UserEmpty = 0x200250ba, |
1902 | - TL_UserSelf = 0x720535ec, |
1903 | - TL_UserContact = 0xf2fb8319, |
1904 | - TL_UserRequest = 0x22e8ceb0, |
1905 | - TL_UserForeign = 0x5214c89d, |
1906 | - TL_UserDeleted = 0xb29ad7cc, |
1907 | - TL_UserProfilePhotoEmpty = 0x4f11bae1, |
1908 | - TL_UserProfilePhoto = 0xd559d8c8, |
1909 | - TL_UserStatusEmpty = 0x9d05049, |
1910 | - TL_UserStatusOnline = 0xedb93949, |
1911 | - TL_UserStatusOffline = 0x8c703f, |
1912 | - TL_ChatEmpty = 0x9ba2d800, |
1913 | - TL_Chat = 0x6e9c9bc7, |
1914 | - TL_ChatForbidden = 0xfb0ccc41, |
1915 | - TL_ChatFull = 0x630e61be, |
1916 | - TL_ChatParticipant = 0xc8d7493e, |
1917 | - TL_ChatParticipantsForbidden = 0xfd2bb8a, |
1918 | - TL_ChatParticipants = 0x7841b415, |
1919 | - TL_ChatPhotoEmpty = 0x37c1011c, |
1920 | - TL_ChatPhoto = 0x6153276a, |
1921 | - TL_MessageEmpty = 0x83e5de54, |
1922 | - TL_Message = 0x22eb6aba, |
1923 | - TL_MessageForwarded = 0x5f46804, |
1924 | - TL_MessageService = 0x9f8d60bb, |
1925 | - TL_MessageMediaEmpty = 0x3ded6320, |
1926 | - TL_MessageMediaPhoto = 0xc8c45a2a, |
1927 | - TL_MessageMediaVideo = 0xa2d24290, |
1928 | - TL_MessageMediaGeo = 0x56e0d474, |
1929 | - TL_MessageMediaContact = 0x5e7d2f39, |
1930 | - TL_MessageMediaUnsupported = 0x29632a36, |
1931 | - TL_MessageActionEmpty = 0xb6aef7b0, |
1932 | - TL_MessageActionChatCreate = 0xa6638b9a, |
1933 | - TL_MessageActionChatEditTitle = 0xb5a1ce5a, |
1934 | - TL_MessageActionChatEditPhoto = 0x7fcb13a8, |
1935 | - TL_MessageActionChatDeletePhoto = 0x95e3fbef, |
1936 | - TL_MessageActionChatAddUser = 0x5e3cfc4b, |
1937 | - TL_MessageActionChatDeleteUser = 0xb2ae9b0c, |
1938 | - TL_Dialog = 0x214a8cdf, |
1939 | - TL_PhotoEmpty = 0x2331b22d, |
1940 | - TL_Photo = 0x22b56751, |
1941 | - TL_PhotoSizeEmpty = 0xe17e23c, |
1942 | - TL_PhotoSize = 0x77bfb61b, |
1943 | - TL_PhotoCachedSize = 0xe9a734fa, |
1944 | - TL_VideoEmpty = 0xc10658a8, |
1945 | - TL_Video = 0x388fa391, |
1946 | - TL_GeoPointEmpty = 0x1117dd5f, |
1947 | - TL_GeoPoint = 0x2049d70c, |
1948 | - TL_AuthCheckedPhone = 0xe300cc3b, |
1949 | - TL_AuthSentCode = 0xefed51d9, |
1950 | - TL_AuthSentAppCode = 0xe325edcf, |
1951 | - TL_AuthAuthorization = 0xf6b673a4, |
1952 | - TL_AuthExportedAuthorization = 0xdf969c2d, |
1953 | - TL_InputNotifyPeer = 0xb8bc5b0c, |
1954 | - TL_InputNotifyUsers = 0x193b4417, |
1955 | - TL_InputNotifyChats = 0x4a95e84e, |
1956 | - TL_InputNotifyAll = 0xa429b886, |
1957 | - TL_InputPeerNotifyEventsEmpty = 0xf03064d8, |
1958 | - TL_InputPeerNotifyEventsAll = 0xe86a2c74, |
1959 | - TL_InputPeerNotifySettings = 0x46a2ce98, |
1960 | - TL_PeerNotifyEventsEmpty = 0xadd53cb3, |
1961 | - TL_PeerNotifyEventsAll = 0x6d1ded88, |
1962 | - TL_PeerNotifySettingsEmpty = 0x70a68512, |
1963 | - TL_PeerNotifySettings = 0x8d5e11ee, |
1964 | - TL_WallPaper = 0xccb03657, |
1965 | - TL_UserFull = 0x771095da, |
1966 | - TL_Contact = 0xf911c994, |
1967 | - TL_ImportedContact = 0xd0028438, |
1968 | - TL_ContactBlocked = 0x561bc879, |
1969 | - TL_ContactFound = 0xea879f95, |
1970 | - TL_ContactSuggested = 0x3de191a1, |
1971 | - TL_ContactStatus = 0xaa77b873, |
1972 | - TL_ChatLocated = 0x3631cf4c, |
1973 | - TL_ContactsForeignLinkUnknown = 0x133421f8, |
1974 | - TL_ContactsForeignLinkRequested = 0xa7801f47, |
1975 | - TL_ContactsForeignLinkMutual = 0x1bea8ce1, |
1976 | - TL_ContactsMyLinkEmpty = 0xd22a1c60, |
1977 | - TL_ContactsMyLinkRequested = 0x6c69efee, |
1978 | - TL_ContactsMyLinkContact = 0xc240ebd9, |
1979 | - TL_ContactsLink = 0xeccea3f5, |
1980 | - TL_ContactsContacts = 0x6f8b8cb2, |
1981 | - TL_ContactsContactsNotModified = 0xb74ba9d2, |
1982 | - TL_ContactsImportedContacts = 0xad524315, |
1983 | - TL_ContactsBlocked = 0x1c138d15, |
1984 | - TL_ContactsBlockedSlice = 0x900802a1, |
1985 | - TL_ContactsFound = 0x566000e, |
1986 | - TL_ContactsSuggested = 0x5649dcc5, |
1987 | - TL_MessagesDialogs = 0x15ba6c40, |
1988 | - TL_MessagesDialogsSlice = 0x71e094f3, |
1989 | - TL_MessagesMessages = 0x8c718e87, |
1990 | - TL_MessagesMessagesSlice = 0xb446ae3, |
1991 | - TL_MessagesMessageEmpty = 0x3f4e0648, |
1992 | - TL_MessagesMessage = 0xff90c417, |
1993 | - TL_MessagesStatedMessages = 0x969478bb, |
1994 | - TL_MessagesStatedMessage = 0xd07ae726, |
1995 | - TL_MessagesSentMessage = 0xd1f4d35c, |
1996 | - TL_MessagesChat = 0x40e9002a, |
1997 | - TL_MessagesChats = 0x8150cbd8, |
1998 | - TL_MessagesChatFull = 0xe5d7d19c, |
1999 | - TL_MessagesAffectedHistory = 0xb7de36f2, |
2000 | - TL_InputMessagesFilterEmpty = 0x57e2f66c, |
2001 | - TL_InputMessagesFilterPhotos = 0x9609a51c, |
2002 | - TL_InputMessagesFilterVideo = 0x9fc00e65, |
2003 | - TL_InputMessagesFilterPhotoVideo = 0x56e9f0e4, |
2004 | - TL_InputMessagesFilterDocument = 0x9eddf188, |
2005 | - TL_UpdateNewMessage = 0x13abdb3, |
2006 | - TL_UpdateMessageID = 0x4e90bfd6, |
2007 | - TL_UpdateReadMessages = 0xc6649e31, |
2008 | - TL_UpdateDeleteMessages = 0xa92bfe26, |
2009 | - TL_UpdateRestoreMessages = 0xd15de04d, |
2010 | - TL_UpdateUserTyping = 0x6baa8508, |
2011 | - TL_UpdateChatUserTyping = 0x3c46cfe6, |
2012 | - TL_UpdateChatParticipants = 0x7761198, |
2013 | - TL_UpdateUserStatus = 0x1bfbd823, |
2014 | - TL_UpdateUserName = 0xda22d9ad, |
2015 | - TL_UpdateUserPhoto = 0x95313b0c, |
2016 | - TL_UpdateContactRegistered = 0x2575bbb9, |
2017 | - TL_UpdateContactLink = 0x51a48a9a, |
2018 | - TL_UpdateActivation = 0x6f690963, |
2019 | - TL_UpdateNewAuthorization = 0x8f06529a, |
2020 | - TL_UpdatesState = 0xa56c2a3e, |
2021 | - TL_UpdatesDifferenceEmpty = 0x5d75a138, |
2022 | - TL_UpdatesDifference = 0xf49ca0, |
2023 | - TL_UpdatesDifferenceSlice = 0xa8fb1981, |
2024 | - TL_UpdatesTooLong = 0xe317af7e, |
2025 | - TL_UpdateShortMessage = 0xd3f45784, |
2026 | - TL_UpdateShortChatMessage = 0x2b2fbd4e, |
2027 | - TL_UpdateShort = 0x78d4dec1, |
2028 | - TL_UpdatesCombined = 0x725b04c3, |
2029 | - TL_Updates = 0x74ae4240, |
2030 | - TL_PhotosPhotos = 0x8dca6aa5, |
2031 | - TL_PhotosPhotosSlice = 0x15051f54, |
2032 | - TL_PhotosPhoto = 0x20212ca8, |
2033 | - TL_UploadFile = 0x96a18d5, |
2034 | - TL_DcOption = 0x2ec2a43c, |
2035 | - TL_Config = 0x2e54dd74, |
2036 | - TL_NearestDc = 0x8e1a1775, |
2037 | - TL_HelpAppUpdate = 0x8987f311, |
2038 | - TL_HelpNoAppUpdate = 0xc45a6536, |
2039 | - TL_HelpInviteText = 0x18cb9f78, |
2040 | - TL_MessagesStatedMessagesLinks = 0x3e74f5c6, |
2041 | - TL_MessagesStatedMessageLink = 0xa9af2881, |
2042 | - TL_MessagesSentMessageLink = 0xe9db4a3f, |
2043 | - TL_InputGeoChat = 0x74d456fa, |
2044 | - TL_InputNotifyGeoChatPeer = 0x4d8ddec8, |
2045 | - TL_GeoChat = 0x75eaea5a, |
2046 | - TL_GeoChatMessageEmpty = 0x60311a9b, |
2047 | - TL_GeoChatMessage = 0x4505f8e1, |
2048 | - TL_GeoChatMessageService = 0xd34fa24e, |
2049 | - TL_GeochatsStatedMessage = 0x17b1578b, |
2050 | - TL_GeochatsLocated = 0x48feb267, |
2051 | - TL_GeochatsMessages = 0xd1526db1, |
2052 | - TL_GeochatsMessagesSlice = 0xbc5863e8, |
2053 | - TL_MessageActionGeoChatCreate = 0x6f038ebc, |
2054 | - TL_MessageActionGeoChatCheckin = 0xc7d53de, |
2055 | - TL_UpdateNewGeoChatMessage = 0x5a68e3f7, |
2056 | - TL_WallPaperSolid = 0x63117f24, |
2057 | - TL_UpdateNewEncryptedMessage = 0x12bcbd9a, |
2058 | - TL_UpdateEncryptedChatTyping = 0x1710f156, |
2059 | - TL_UpdateEncryption = 0xb4a2e88d, |
2060 | - TL_UpdateEncryptedMessagesRead = 0x38fe25b7, |
2061 | - TL_EncryptedChatEmpty = 0xab7ec0a0, |
2062 | - TL_EncryptedChatWaiting = 0x3bf703dc, |
2063 | - TL_EncryptedChatRequested = 0xc878527e, |
2064 | - TL_EncryptedChat = 0xfa56ce36, |
2065 | - TL_EncryptedChatDiscarded = 0x13d6dd27, |
2066 | - TL_InputEncryptedChat = 0xf141b5e1, |
2067 | - TL_EncryptedFileEmpty = 0xc21f497e, |
2068 | - TL_EncryptedFile = 0x4a70994c, |
2069 | - TL_InputEncryptedFileEmpty = 0x1837c364, |
2070 | - TL_InputEncryptedFileUploaded = 0x64bd0306, |
2071 | - TL_InputEncryptedFile = 0x5a17b5e5, |
2072 | - TL_InputEncryptedFileLocation = 0xf5235d55, |
2073 | - TL_EncryptedMessage = 0xed18c118, |
2074 | - TL_EncryptedMessageService = 0x23734b06, |
2075 | - TL_DecryptedMessageLayer = 0x1be31789, |
2076 | - TL_DecryptedMessage_layer8 = 0x1f814f1f, |
2077 | - TL_DecryptedMessage = 0x204d3878, |
2078 | - TL_DecryptedMessageService_layer8 = 0xaa48327d, |
2079 | - TL_DecryptedMessageService = 0x73164160, |
2080 | - TL_DecryptedMessageMediaEmpty = 0x89f5c4a, |
2081 | - TL_DecryptedMessageMediaPhoto = 0x32798a8c, |
2082 | - TL_DecryptedMessageMediaVideo_layer8 = 0x4cee6ef3, |
2083 | - TL_DecryptedMessageMediaVideo = 0x524a415d, |
2084 | - TL_DecryptedMessageMediaGeoPoint = 0x35480a59, |
2085 | - TL_DecryptedMessageMediaContact = 0x588a0a97, |
2086 | - TL_DecryptedMessageMediaAudio_layer8 = 0x6080758f, |
2087 | - TL_DecryptedMessageMediaAudio = 0x57e0a9cb, |
2088 | - TL_DecryptedMessageActionSetMessageTTL = 0xa1733aec, |
2089 | - TL_DecryptedMessageActionReadMessages = 0xc4f40be, |
2090 | - TL_DecryptedMessageActionDeleteMessages = 0x65614304, |
2091 | - TL_DecryptedMessageActionScreenshotMessages = 0x8ac1f475, |
2092 | - TL_DecryptedMessageActionFlushHistory = 0x6719e45c, |
2093 | - TL_DecryptedMessageActionResend = 0x511110b0, |
2094 | - TL_DecryptedMessageActionNotifyLayer = 0xf3048883, |
2095 | - TL_DecryptedMessageActionTyping = 0xccb27641, |
2096 | - TL_MessagesDhConfigNotModified = 0xc0e24635, |
2097 | - TL_MessagesDhConfig = 0x2c221edd, |
2098 | - TL_MessagesSentEncryptedMessage = 0x560f8935, |
2099 | - TL_MessagesSentEncryptedFile = 0x9493ff32, |
2100 | - TL_InputFileBig = 0xfa4f0bb5, |
2101 | - TL_InputEncryptedFileBigUploaded = 0x2dc173c8, |
2102 | - TL_UpdateChatParticipantAdd = 0x3a0eeb22, |
2103 | - TL_UpdateChatParticipantDelete = 0x6e5f8c22, |
2104 | - TL_UpdateDcOptions = 0x8e5e9873, |
2105 | - TL_InputMediaUploadedAudio = 0x4e498cab, |
2106 | - TL_InputMediaAudio = 0x89938781, |
2107 | - TL_InputMediaUploadedDocument = 0x34e794bd, |
2108 | - TL_InputMediaUploadedThumbDocument = 0x3e46de5d, |
2109 | - TL_InputMediaDocument = 0xd184e841, |
2110 | - TL_MessageMediaDocument = 0x2fda2204, |
2111 | - TL_MessageMediaAudio = 0xc6b68300, |
2112 | - TL_InputAudioEmpty = 0xd95adc84, |
2113 | - TL_InputAudio = 0x77d440ff, |
2114 | - TL_InputDocumentEmpty = 0x72f0eaae, |
2115 | - TL_InputDocument = 0x18798952, |
2116 | - TL_InputAudioFileLocation = 0x74dc404d, |
2117 | - TL_InputDocumentFileLocation = 0x4e45abe9, |
2118 | - TL_DecryptedMessageMediaDocument = 0xb095434b, |
2119 | - TL_AudioEmpty = 0x586988d8, |
2120 | - TL_Audio = 0xc7ac6496, |
2121 | - TL_DocumentEmpty = 0x36f8c871, |
2122 | - TL_Document = 0x9efc6326, |
2123 | - TL_HelpSupport = 0x17c6b5f6, |
2124 | - TL_InvokeAfterMsg = 0xcb9f372d, |
2125 | - TL_InvokeAfterMsgs = 0x3dc4b4f0, |
2126 | - TL_AuthCheckPhone = 0x6fe51dfb, |
2127 | - TL_AuthSendCode = 0x768d5f4d, |
2128 | - TL_AuthSendSms = 0xda9f3e8, |
2129 | - TL_AuthSendCall = 0x3c51564, |
2130 | - TL_AuthSignUp = 0x1b067634, |
2131 | - TL_AuthSignIn = 0xbcd51581, |
2132 | - TL_AuthLogOut = 0x5717da40, |
2133 | - TL_AuthResetAuthorizations = 0x9fab0d1a, |
2134 | - TL_AuthSendInvites = 0x771c1d97, |
2135 | - TL_AuthExportAuthorization = 0xe5bfffcd, |
2136 | - TL_AuthImportAuthorization = 0xe3ef9613, |
2137 | - TL_AccountRegisterDevice = 0x446c712c, |
2138 | - TL_AccountUnregisterDevice = 0x65c55b40, |
2139 | - TL_AccountUpdateNotifySettings = 0x84be5b93, |
2140 | - TL_AccountGetNotifySettings = 0x12b3ad31, |
2141 | - TL_AccountResetNotifySettings = 0xdb7e1747, |
2142 | - TL_AccountUpdateProfile = 0xf0888d68, |
2143 | - TL_AccountUpdateStatus = 0x6628562c, |
2144 | - TL_AccountGetWallPapers = 0xc04cfac2, |
2145 | - TL_UsersGetUsers = 0xd91a548, |
2146 | - TL_UsersGetFullUser = 0xca30a5b1, |
2147 | - TL_ContactsGetStatuses = 0xc4a353ee, |
2148 | - TL_ContactsGetContacts = 0x22c6aa08, |
2149 | - TL_ContactsImportContacts = 0xda30b32d, |
2150 | - TL_ContactsSearch = 0x11f812d8, |
2151 | - TL_ContactsGetSuggested = 0xcd773428, |
2152 | - TL_ContactsDeleteContact = 0x8e953744, |
2153 | - TL_ContactsDeleteContacts = 0x59ab389e, |
2154 | - TL_ContactsBlock = 0x332b49fc, |
2155 | - TL_ContactsUnblock = 0xe54100bd, |
2156 | - TL_ContactsGetBlocked = 0xf57c350f, |
2157 | - TL_MessagesGetMessages = 0x4222fa74, |
2158 | - TL_MessagesGetDialogs = 0xeccf1df6, |
2159 | - TL_MessagesGetHistory = 0x92a1df2f, |
2160 | - TL_MessagesSearch = 0x7e9f2ab, |
2161 | - TL_MessagesReadHistory = 0xeed884c6, |
2162 | - TL_MessagesReadMessageContents = 0x354b5bc2, |
2163 | - TL_MessagesDeleteHistory = 0xf4f8fb61, |
2164 | - TL_MessagesDeleteMessages = 0x14f2dd0a, |
2165 | - TL_MessagesRestoreMessages = 0x395f9d7e, |
2166 | - TL_MessagesReceivedMessages = 0x28abcb68, |
2167 | - TL_MessagesSetTyping = 0xa3825e50, |
2168 | - TL_MessagesSendMessage = 0x4cde0aab, |
2169 | - TL_MessagesSendMedia = 0xa3c85d76, |
2170 | - TL_MessagesForwardMessages = 0x514cd10f, |
2171 | - TL_MessagesGetChats = 0x3c6aa187, |
2172 | - TL_MessagesGetFullChat = 0x3b831c66, |
2173 | - TL_MessagesEditChatTitle = 0xb4bc68b5, |
2174 | - TL_MessagesEditChatPhoto = 0xd881821d, |
2175 | - TL_MessagesAddChatUser = 0x2ee9ee9e, |
2176 | - TL_MessagesDeleteChatUser = 0xc3c5cd23, |
2177 | - TL_MessagesCreateChat = 0x419d9aee, |
2178 | - TL_UpdatesGetState = 0xedd4882a, |
2179 | - TL_UpdatesGetDifference = 0xa041495, |
2180 | - TL_PhotosUpdateProfilePhoto = 0xeef579a0, |
2181 | - TL_PhotosUploadProfilePhoto = 0xd50f9c88, |
2182 | - TL_UploadSaveFilePart = 0xb304a621, |
2183 | - TL_UploadGetFile = 0xe3a6cfb5, |
2184 | - TL_HelpGetConfig = 0xc4f9186b, |
2185 | - TL_HelpGetNearestDc = 0x1fb33026, |
2186 | - TL_HelpGetAppUpdate = 0xc812ac7e, |
2187 | - TL_HelpSaveAppLog = 0x6f02f748, |
2188 | - TL_HelpGetInviteText = 0xa4a95186, |
2189 | - TL_PhotosGetUserPhotos = 0xb7ee553c, |
2190 | - TL_MessagesForwardMessage = 0x3f3f4f2, |
2191 | - TL_MessagesSendBroadcast = 0x41bb0972, |
2192 | - TL_GeochatsGetLocated = 0x7f192d8f, |
2193 | - TL_GeochatsGetRecents = 0xe1427e6f, |
2194 | - TL_GeochatsCheckin = 0x55b3e8fb, |
2195 | - TL_GeochatsGetFullChat = 0x6722dd6f, |
2196 | - TL_GeochatsEditChatTitle = 0x4c8e2273, |
2197 | - TL_GeochatsEditChatPhoto = 0x35d81a95, |
2198 | - TL_GeochatsSearch = 0xcfcdc44d, |
2199 | - TL_GeochatsGetHistory = 0xb53f7a68, |
2200 | - TL_GeochatsSetTyping = 0x8b8a729, |
2201 | - TL_GeochatsSendMessage = 0x61b0044, |
2202 | - TL_GeochatsSendMedia = 0xb8f0deff, |
2203 | - TL_GeochatsCreateGeoChat = 0xe092e16, |
2204 | - TL_MessagesGetDhConfig = 0x26cf8950, |
2205 | - TL_MessagesRequestEncryption = 0xf64daf43, |
2206 | - TL_MessagesAcceptEncryption = 0x3dbc0415, |
2207 | - TL_MessagesDiscardEncryption = 0xedd923c5, |
2208 | - TL_MessagesSetEncryptedTyping = 0x791451ed, |
2209 | - TL_MessagesReadEncryptedHistory = 0x7f4b690a, |
2210 | - TL_MessagesSendEncrypted = 0xa9776773, |
2211 | - TL_MessagesSendEncryptedFile = 0x9a901b66, |
2212 | - TL_MessagesSendEncryptedService = 0x32d439a4, |
2213 | - TL_MessagesReceivedQueue = 0x55a5bb66, |
2214 | - TL_UploadSaveBigFilePart = 0xde7b673d, |
2215 | - TL_InitConnection = 0x69796de9, |
2216 | - TL_HelpGetSupport = 0x9cdf08cd, |
2217 | - //TL_InvokeWithLayer14 = 0x2b9b08fa |
2218 | - TL_InvokeWithLayer17 = 0x50858a19 |
2219 | -}; |
2220 | - |
2221 | -#endif // TLVALUES_H |
2222 | |
2223 | === removed file 'lib/core/utils.cpp' |
2224 | --- lib/core/utils.cpp 2015-01-07 15:59:33 +0000 |
2225 | +++ lib/core/utils.cpp 1970-01-01 00:00:00 +0000 |
2226 | @@ -1,377 +0,0 @@ |
2227 | -/* |
2228 | - * Copyright 2013 Vitaly Valtman |
2229 | - * Copyright 2014 Canonical Ltd. |
2230 | - * Authors: |
2231 | - * Roberto Mier |
2232 | - * Tiago Herrmann |
2233 | - * |
2234 | - * This program is free software; you can redistribute it and/or modify |
2235 | - * it under the terms of the GNU General Public License as published by |
2236 | - * the Free Software Foundation; version 3. |
2237 | - * |
2238 | - * This program is distributed in the hope that it will be useful, |
2239 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2240 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2241 | - * GNU General Public License for more details. |
2242 | - * |
2243 | - * You should have received a copy of the GNU General Public License |
2244 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2245 | - * |
2246 | - */ |
2247 | - |
2248 | -#include "utils.h" |
2249 | -#include <openssl/rand.h> |
2250 | -#include <openssl/pem.h> |
2251 | -#include <openssl/err.h> |
2252 | -#include <sys/utsname.h> |
2253 | -#include <zlib.h> |
2254 | - |
2255 | -#include <QDebug> |
2256 | -#include <QEventLoop> |
2257 | -#include <QtMultimedia/QMediaPlayer> |
2258 | -#include <QtMultimedia/QMediaContent> |
2259 | -#include <QtMultimedia/QMediaResource> |
2260 | -#include <QProcess> |
2261 | -#include <QStringList> |
2262 | -#include <QtCore> |
2263 | - |
2264 | - |
2265 | -Q_LOGGING_CATEGORY(TG_UTILS, "tg.utils") |
2266 | - |
2267 | - |
2268 | -Utils::Utils(QObject *parent) : |
2269 | - QObject(parent) |
2270 | -{ |
2271 | -} |
2272 | - |
2273 | -qint32 Utils::randomBytes(void *buffer, qint32 count) { |
2274 | - qint32 returnValue = RAND_bytes ((uchar *)buffer, count); |
2275 | - if (returnValue < 0) { |
2276 | - returnValue = RAND_pseudo_bytes ((uchar *)buffer, count); |
2277 | - } |
2278 | - return returnValue; |
2279 | -} |
2280 | - |
2281 | -qint32 Utils::serializeBignum(BIGNUM *b, char *buffer, qint32 maxlen) { |
2282 | - qint32 itslen = BN_num_bytes (b); |
2283 | - qint32 reqlen; |
2284 | - if (itslen < 254) { |
2285 | - reqlen = itslen + 1; |
2286 | - } else { |
2287 | - reqlen = itslen + 4; |
2288 | - } |
2289 | - qint32 newlen = (reqlen + 3) & -4; |
2290 | - qint32 pad = newlen - reqlen; |
2291 | - reqlen = newlen; |
2292 | - if (reqlen > maxlen) { |
2293 | - return -reqlen; |
2294 | - } |
2295 | - if (itslen < 254) { |
2296 | - *buffer++ = itslen; |
2297 | - } else { |
2298 | - *(qint32 *)buffer = (itslen << 8) + 0xfe; |
2299 | - buffer += 4; |
2300 | - } |
2301 | - qint32 l = BN_bn2bin (b, (uchar *)buffer); |
2302 | - Q_ASSERT (l == itslen); |
2303 | - buffer += l; |
2304 | - while (pad --> 0) { |
2305 | - *buffer++ = 0; |
2306 | - } |
2307 | - return reqlen; |
2308 | -} |
2309 | - |
2310 | -double Utils::getUTime(qint32 clockId) { |
2311 | - struct timespec T; |
2312 | - qint32 success = clock_gettime(clockId, &T); |
2313 | - Q_UNUSED(success); |
2314 | - Q_ASSERT(success == 0); |
2315 | - double res = T.tv_sec + (double) T.tv_nsec * 1e-9; |
2316 | - return res; |
2317 | -} |
2318 | - |
2319 | -quint64 Utils::gcd(quint64 a, quint64 b) { |
2320 | - return b ? gcd (b, a % b) : a; |
2321 | -} |
2322 | - |
2323 | -qint32 Utils::check_g (uchar p[256], BIGNUM *g) { |
2324 | - static uchar s[256]; |
2325 | - memset (s, 0, 256); |
2326 | - Q_ASSERT(BN_num_bytes (g) <= 256); |
2327 | - BN_bn2bin (g, s); |
2328 | - qint32 ok = 0; |
2329 | - qint32 i; |
2330 | - for (i = 0; i < 64; i++) { |
2331 | - if (s[i]) { |
2332 | - ok = 1; |
2333 | - break; |
2334 | - } |
2335 | - } |
2336 | - if (!ok) { return -1; } |
2337 | - ok = 0; |
2338 | - for (i = 0; i < 64; i++) { |
2339 | - if (s[255 - i]) { |
2340 | - ok = 1; |
2341 | - break; |
2342 | - } |
2343 | - } |
2344 | - if (!ok) { return -1; } |
2345 | - ok = 0; |
2346 | - for (i = 0; i < 64; i++) { |
2347 | - if (s[i] < p[i]) { |
2348 | - ok = 1; |
2349 | - break; |
2350 | - } else if (s[i] > p[i]) { |
2351 | - qDebug() << i << "=" << (qint32)s[i] << (qint32)p[i]; |
2352 | - return -1; |
2353 | - } |
2354 | - } |
2355 | - if (!ok) { return -1; } |
2356 | - return 0; |
2357 | -} |
2358 | - |
2359 | -qint32 Utils::check_g_bn (BIGNUM *p, BIGNUM *g) { |
2360 | - static uchar s[256]; |
2361 | - memset (s, 0, 256); |
2362 | - Q_ASSERT(BN_num_bytes (p) <= 256); |
2363 | - BN_bn2bin (p, s); |
2364 | - return check_g (s, g); |
2365 | -} |
2366 | - |
2367 | -void Utils::ensurePtr(void *p) { |
2368 | - if (p == NULL) { |
2369 | - qFatal("Out of memory"); |
2370 | - exit (1); |
2371 | - } |
2372 | -} |
2373 | - |
2374 | -void Utils::ensure (qint32 r) { |
2375 | - if (!r) { |
2376 | - ERR_print_errors_fp (stderr); |
2377 | - Q_ASSERT(0); |
2378 | - } |
2379 | -} |
2380 | - |
2381 | -void Utils::freeSecure(void *ptr, qint32 size) { |
2382 | - if (!ptr) return; |
2383 | - memset (ptr, 0, size); |
2384 | - free (ptr); |
2385 | -} |
2386 | - |
2387 | -RSA *Utils::rsaLoadPublicKey(const QString &publicKeyName) { |
2388 | - RSA *pubKey = NULL; |
2389 | - FILE *f = fopen (publicKeyName.toLocal8Bit().data(), "r"); |
2390 | - if (f == NULL) { |
2391 | - qCWarning(TG_UTILS) << "Couldn't open public key file" << publicKeyName; |
2392 | - return NULL; |
2393 | - } |
2394 | - pubKey = PEM_read_RSAPublicKey (f, NULL, NULL, NULL); |
2395 | - fclose (f); |
2396 | - if (pubKey == NULL) { |
2397 | - qCWarning(TG_UTILS) << "PEM_read_RSAPublicKey returns NULL"; |
2398 | - return NULL; |
2399 | - } |
2400 | - qCDebug(TG_UTILS) << "public key" << publicKeyName << "loaded successfully"; |
2401 | - return pubKey; |
2402 | -} |
2403 | - |
2404 | -qint64 Utils::computeRSAFingerprint(RSA *key) { |
2405 | - static char tempbuff[4096]; |
2406 | - static uchar sha[20]; |
2407 | - Q_ASSERT(key->n && key->e); |
2408 | - qint32 l1 = serializeBignum (key->n, tempbuff, 4096); |
2409 | - Q_ASSERT(l1 > 0); |
2410 | - qint32 l2 = serializeBignum (key->e, tempbuff + l1, 4096 - l1); |
2411 | - Q_ASSERT(l2 > 0 && l1 + l2 <= 4096); |
2412 | - SHA1 ((uchar *)tempbuff, l1 + l2, sha); |
2413 | - return *(qint64 *)(sha + 12); |
2414 | -} |
2415 | - |
2416 | -void *Utils::talloc(size_t size) { |
2417 | -#ifdef DEBUG |
2418 | - total_allocated_bytes += size; |
2419 | - void *p = malloc (size + RES_PRE + RES_AFTER); |
2420 | - ensurePtr (p); |
2421 | - *(qint32 *)p = size ^ 0xbedabeda; |
2422 | - *(qint32 *)(p + 4) = size; |
2423 | - *(qint32 *)(p + RES_PRE + size) = size ^ 0x7bed7bed; |
2424 | - *(qint32 *)(p + RES_AFTER + 4 + size) = usedBlocks; |
2425 | - blocks[usedBlocks ++] = p; |
2426 | - return p + 8; |
2427 | -#else |
2428 | - void *p = malloc (size); |
2429 | - ensurePtr (p); |
2430 | - return p; |
2431 | -#endif |
2432 | -} |
2433 | - |
2434 | -qint32 Utils::tinflate(void *input, qint32 ilen, void *output, qint32 olen) { |
2435 | - z_stream strm; |
2436 | - memset(&strm, 0, sizeof (strm)); |
2437 | - qint32 inflateResult = inflateInit2(&strm, 16 + MAX_WBITS); |
2438 | - Q_UNUSED(inflateResult); |
2439 | - Q_ASSERT(inflateResult == Z_OK); |
2440 | - strm.avail_in = ilen; |
2441 | - strm.next_in = (Bytef *)input; |
2442 | - strm.avail_out = olen ; |
2443 | - strm.next_out = (Bytef *)output; |
2444 | - qint32 err = inflate (&strm, Z_FINISH), totalOut = 0; |
2445 | - if (err == Z_OK || err == Z_STREAM_END) { |
2446 | - totalOut = (qint32) strm.total_out; |
2447 | - } |
2448 | - inflateEnd (&strm); |
2449 | - return totalOut; |
2450 | -} |
2451 | - |
2452 | -QString Utils::toHex(qint32 x) { |
2453 | - return "0x" + QString::number(static_cast<quint32>(x), 16); |
2454 | -} |
2455 | - |
2456 | -QString Utils::toHex(void *buffer, qint32 size) { |
2457 | - QByteArray array((char *)buffer, size); |
2458 | - QByteArray hexArray = array.toHex(); |
2459 | - QString sb; |
2460 | - qint32 count = 0; |
2461 | - for (qint32 i = 0; i < hexArray.length(); i += 2) { |
2462 | - count++; |
2463 | - sb.append(QString(hexArray.at(i)).toUpper()); |
2464 | - sb.append(QString(hexArray.at(i+1)).toUpper()); |
2465 | - if (count == 8) { |
2466 | - sb.append("\n"); |
2467 | - count = 0; |
2468 | - } else if (count == 4) { |
2469 | - sb.append("\t"); |
2470 | - } else { |
2471 | - sb.append(" "); |
2472 | - } |
2473 | - } |
2474 | - return sb; |
2475 | -} |
2476 | - |
2477 | -BIGNUM *Utils::padBytesAndGetBignum(const QByteArray &gAOrB) { |
2478 | - // padding of B (gAOrB) to have exactly 256 bytes |
2479 | - uchar paddedGAOrB[256]; |
2480 | - qint32 length = gAOrB.length(); |
2481 | - // check that size of |
2482 | - uchar *rawGAOrB = (uchar *)gAOrB.data(); |
2483 | - if (length < 256) { |
2484 | - memcpy (paddedGAOrB + 256 - length, rawGAOrB, length); |
2485 | - } else { |
2486 | - memcpy (paddedGAOrB, rawGAOrB + (length - 256), 256); |
2487 | - } |
2488 | - |
2489 | - BIGNUM *bigNumGAOrB = BN_bin2bn(paddedGAOrB, 256, 0); |
2490 | - return bigNumGAOrB; |
2491 | -} |
2492 | - |
2493 | -BIGNUM *Utils::bytesToBignum(const QByteArray &bytes) { |
2494 | - uchar *data = (uchar *)bytes.data(); |
2495 | - qint32 length = bytes.length(); |
2496 | - BIGNUM *bignum = BN_bin2bn(data, length, 0); |
2497 | - return bignum; |
2498 | -} |
2499 | - |
2500 | -QByteArray Utils::bignumToBytes(BIGNUM *bignum) { |
2501 | - qint32 length = BN_num_bytes(bignum); |
2502 | - uchar data[length]; |
2503 | - BN_bn2bin(bignum, data); |
2504 | - return QByteArray((char *)data, length); |
2505 | -} |
2506 | - |
2507 | -qint64 Utils::getKeyFingerprint(uchar *sharedKey) { |
2508 | - uchar shaBuffer[20]; |
2509 | - SHA1(sharedKey, 256, shaBuffer); |
2510 | - qint64 keyFingerprint = *(qint64 *)(shaBuffer + 12); |
2511 | - return keyFingerprint; |
2512 | -} |
2513 | - |
2514 | -QString Utils::getDeviceModel() { |
2515 | - struct utsname st; |
2516 | - uname(&st); |
2517 | - return QString(st.machine); |
2518 | -} |
2519 | - |
2520 | -QString Utils::getSystemVersion() { |
2521 | - struct utsname st; |
2522 | - uname(&st); |
2523 | - return QString(QString(st.sysname) + " " + QString(st.release) + " " + QString(st.version)); |
2524 | -} |
2525 | - |
2526 | -QString Utils::getAppVersion() { |
2527 | - return LIBQTELEGRAM_VERSION " (build " LIBQTELEGRAM_BUILD ")"; |
2528 | -} |
2529 | - |
2530 | -QString Utils::parsePhoneNumberDigits(const QString &phoneNumber) { |
2531 | - // Only allowing + and [0..9] chars |
2532 | - QString filteredChars; |
2533 | - |
2534 | - if (phoneNumber.length() > 0) { |
2535 | - |
2536 | - for (int i = 0; i < phoneNumber.length(); i++) { |
2537 | - const QChar c = phoneNumber.at(i); |
2538 | - if (c.isDigit() || c == '+') { |
2539 | - filteredChars.append(c); |
2540 | - } |
2541 | - } |
2542 | - } |
2543 | - |
2544 | - return filteredChars; |
2545 | -} |
2546 | - |
2547 | -QByteArray Utils::pToBigEndian(quint32 p) {; |
2548 | - qint32 pLength; |
2549 | - if (p < (1 << 8)) { |
2550 | - pLength = 1; |
2551 | - } else if (p < (1 << 16)) { |
2552 | - pLength = 2; |
2553 | - } else if (p < (1 << 24)) { |
2554 | - pLength = 3; |
2555 | - } else { |
2556 | - pLength = 4; |
2557 | - } |
2558 | - |
2559 | - uchar beP[4]; |
2560 | - qToBigEndian(p, beP); |
2561 | - |
2562 | - return QByteArray((const char *)beP, pLength); |
2563 | -} |
2564 | - |
2565 | -qint64 Utils::findDivider(qint64 pq) { |
2566 | - qint32 it = 0; |
2567 | - quint64 g = 0; |
2568 | - for (int i = 0; i < 3 || it < 1000; i++) { |
2569 | - qint32 q = ((lrand48() & 15) + 17) % pq; |
2570 | - quint64 x = (qint64)lrand48 () % (pq - 1) + 1, y = x; |
2571 | - qint32 lim = 1 << (i + 18); |
2572 | - qint32 j; |
2573 | - for (j = 1; j < lim; j++) { |
2574 | - ++it; |
2575 | - quint64 a = x, b = x, c = q; |
2576 | - while (b) { |
2577 | - if (b & 1) { |
2578 | - c += a; |
2579 | - if (c >= pq) { |
2580 | - c -= pq; |
2581 | - } |
2582 | - } |
2583 | - a += a; |
2584 | - if (a >= pq) { |
2585 | - a -= pq; |
2586 | - } |
2587 | - b >>= 1; |
2588 | - } |
2589 | - x = c; |
2590 | - quint64 z = x < y ? pq + x - y : x - y; |
2591 | - g = Utils::gcd(z, pq); |
2592 | - if (g != 1) { |
2593 | - break; |
2594 | - } |
2595 | - if (!(j & (j - 1))) { |
2596 | - y = x; |
2597 | - } |
2598 | - } |
2599 | - if (g > 1 && g < pq) break; |
2600 | - } |
2601 | - qCDebug(TG_UTILS) << "got" << g << "divider after" << it << "iterations"; |
2602 | - return g; |
2603 | -} |
2604 | |
2605 | === removed file 'lib/core/utils.h' |
2606 | --- lib/core/utils.h 2014-12-22 22:01:28 +0000 |
2607 | +++ lib/core/utils.h 1970-01-01 00:00:00 +0000 |
2608 | @@ -1,88 +0,0 @@ |
2609 | -/* |
2610 | - * Copyright 2013 Vitaly Valtman |
2611 | - * Copyright 2014 Canonical Ltd. |
2612 | - * Authors: |
2613 | - * Roberto Mier |
2614 | - * Tiago Herrmann |
2615 | - * |
2616 | - * This program is free software; you can redistribute it and/or modify |
2617 | - * it under the terms of the GNU General Public License as published by |
2618 | - * the Free Software Foundation; version 3. |
2619 | - * |
2620 | - * This program is distributed in the hope that it will be useful, |
2621 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2622 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2623 | - * GNU General Public License for more details. |
2624 | - * |
2625 | - * You should have received a copy of the GNU General Public License |
2626 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2627 | - * |
2628 | - */ |
2629 | - |
2630 | -#ifndef UTILS_H |
2631 | -#define UTILS_H |
2632 | - |
2633 | -#ifdef DEBUG |
2634 | -#define RES_PRE 8 |
2635 | -#define RES_AFTER 8 |
2636 | -#define MAX_BLOCKS 1000000 |
2637 | -void *blocks[MAX_BLOCKS]; |
2638 | -void *free_blocks[MAX_BLOCKS]; |
2639 | -qint32 usedBlocks; |
2640 | -qint32 freeBlocksCnt; |
2641 | -#endif |
2642 | - |
2643 | -#include <QObject> |
2644 | -#include <openssl/bn.h> |
2645 | -#include "constants.h" |
2646 | -#include <QLoggingCategory> |
2647 | - |
2648 | -Q_DECLARE_LOGGING_CATEGORY(TG_UTILS) |
2649 | - |
2650 | - |
2651 | -class Utils : public QObject |
2652 | -{ |
2653 | - Q_OBJECT |
2654 | -public: |
2655 | - explicit Utils(QObject *parent = 0); |
2656 | - |
2657 | - static qint32 randomBytes(void *buffer, qint32 count); |
2658 | - static qint32 serializeBignum(BIGNUM *b, char *buffer, qint32 maxlen); |
2659 | - static double getUTime(qint32 clockId); |
2660 | - static quint64 gcd (quint64 a, quint64 b); |
2661 | - |
2662 | - static RSA *rsaLoadPublicKey (const QString &publicKeyName); |
2663 | - static qint64 computeRSAFingerprint(RSA *key); |
2664 | - |
2665 | - static qint32 check_g (uchar p[256], BIGNUM *g); |
2666 | - static qint32 check_g_bn (BIGNUM *p, BIGNUM *g); |
2667 | - |
2668 | - static void ensure(qint32 r); |
2669 | - static void ensurePtr(void *p); |
2670 | - static void freeSecure (void *ptr, qint32 size); |
2671 | - |
2672 | - static void *talloc(size_t size); |
2673 | - static qint32 tinflate (void *input, qint32 ilen, void *output, qint32 olen); |
2674 | - |
2675 | - static QString toHex(qint32 x); |
2676 | - static QString toHex(void *buffer, qint32 size); |
2677 | - |
2678 | - static BIGNUM *padBytesAndGetBignum(const QByteArray &bytes); |
2679 | - static BIGNUM *bytesToBignum(const QByteArray &bytes); |
2680 | - static QByteArray bignumToBytes(BIGNUM *bignum); |
2681 | - static qint64 getKeyFingerprint(uchar *sharedKey); |
2682 | - |
2683 | - static QString getDeviceModel(); |
2684 | - static QString getSystemVersion(); |
2685 | - static QString getAppVersion(); |
2686 | - |
2687 | - static qint64 getMediaDuration(const QString &resource, const QString &type); |
2688 | - static QString createThumbnail(const QString &resource); |
2689 | - |
2690 | - static QString parsePhoneNumberDigits(const QString &phoneNumber); |
2691 | - |
2692 | - static QByteArray pToBigEndian(quint32 p); |
2693 | - static qint64 findDivider(qint64 pq); |
2694 | -}; |
2695 | - |
2696 | -#endif // UTILS_H |
2697 | |
2698 | === added directory 'lib/file' |
2699 | === added file 'lib/file/CMakeLists.txt' |
2700 | --- lib/file/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
2701 | +++ lib/file/CMakeLists.txt 2015-02-24 14:12:31 +0000 |
2702 | @@ -0,0 +1,11 @@ |
2703 | +set(FILE_HEADERS |
2704 | + file.h |
2705 | + downloadfile.h |
2706 | + filehandler.h |
2707 | + fileoperation.h |
2708 | + uploadfile.h) |
2709 | + |
2710 | +if(NOT CLICK_MODE) |
2711 | +INSTALL(FILES ${FILE_HEADERS} |
2712 | + DESTINATION ${CMAKE_INSTALL_PREFIX}/include/libqtelegram/file) |
2713 | +endif(NOT CLICK_MODE) |
2714 | |
2715 | === added file 'lib/file/downloadfile.cpp' |
2716 | --- lib/file/downloadfile.cpp 1970-01-01 00:00:00 +0000 |
2717 | +++ lib/file/downloadfile.cpp 2015-02-24 14:12:31 +0000 |
2718 | @@ -0,0 +1,85 @@ |
2719 | +/* |
2720 | + * Copyright 2014 Canonical Ltd. |
2721 | + * |
2722 | + * This program is free software; you can redistribute it and/or modify |
2723 | + * it under the terms of the GNU General Public License as published by |
2724 | + * the Free Software Foundation; version 3. |
2725 | + * |
2726 | + * This program is distributed in the hope that it will be useful, |
2727 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2728 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2729 | + * GNU General Public License for more details. |
2730 | + * |
2731 | + * You should have received a copy of the GNU General Public License |
2732 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2733 | + * |
2734 | + * Authors: |
2735 | + * Roberto Mier |
2736 | + * Tiago Herrmann |
2737 | + */ |
2738 | + |
2739 | +#include "downloadfile.h" |
2740 | + |
2741 | +DownloadFile::DownloadFile(Session *session, InputFileLocation fileLocation, qint32 expectedSize, QObject *parent) : |
2742 | + File(session, 0, parent), |
2743 | + mFileLocation(fileLocation), |
2744 | + mOffset(0), |
2745 | + mMtime(0), |
2746 | + mExpectedSize(expectedSize), |
2747 | + mPartId(0) { |
2748 | +} |
2749 | + |
2750 | +DownloadFile::~DownloadFile() { |
2751 | +} |
2752 | + |
2753 | +QByteArray DownloadFile::bytes() const { |
2754 | + return mBytes; |
2755 | +} |
2756 | + |
2757 | +void DownloadFile::appendBytes(const QByteArray &bytes) { |
2758 | + mBytes.append(bytes); |
2759 | + mOffset += bytes.length(); |
2760 | +} |
2761 | + |
2762 | +qint32 DownloadFile::offset() const { |
2763 | + return mOffset; |
2764 | +} |
2765 | + |
2766 | +void DownloadFile::setOffset(qint32 offset) { |
2767 | + mOffset = offset; |
2768 | +} |
2769 | + |
2770 | +qint32 DownloadFile::mtime() const { |
2771 | + return mMtime; |
2772 | +} |
2773 | +void DownloadFile::setMtime(qint32 mtime) { |
2774 | + mMtime = mtime; |
2775 | +} |
2776 | + |
2777 | +InputFileLocation DownloadFile::fileLocation() const { |
2778 | + return mFileLocation; |
2779 | +} |
2780 | + |
2781 | +qint32 DownloadFile::expectedSize() const { |
2782 | + return mExpectedSize; |
2783 | +} |
2784 | + |
2785 | +qint32 DownloadFile::partId() const { |
2786 | + return mPartId; |
2787 | +} |
2788 | + |
2789 | +void DownloadFile::incrementPartId() { |
2790 | + mPartId++; |
2791 | +} |
2792 | + |
2793 | +bool DownloadFile::encrypted() const { |
2794 | + return mEncrypted; |
2795 | +} |
2796 | + |
2797 | +uchar *DownloadFile::key() { |
2798 | + return mKey; |
2799 | +} |
2800 | + |
2801 | +uchar *DownloadFile::iv() { |
2802 | + return mIv; |
2803 | +} |
2804 | |
2805 | === added file 'lib/file/downloadfile.h' |
2806 | --- lib/file/downloadfile.h 1970-01-01 00:00:00 +0000 |
2807 | +++ lib/file/downloadfile.h 2015-02-24 14:12:31 +0000 |
2808 | @@ -0,0 +1,66 @@ |
2809 | +/* |
2810 | + * Copyright 2014 Canonical Ltd. |
2811 | + * |
2812 | + * This program is free software; you can redistribute it and/or modify |
2813 | + * it under the terms of the GNU General Public License as published by |
2814 | + * the Free Software Foundation; version 3. |
2815 | + * |
2816 | + * This program is distributed in the hope that it will be useful, |
2817 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2818 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2819 | + * GNU General Public License for more details. |
2820 | + * |
2821 | + * You should have received a copy of the GNU General Public License |
2822 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2823 | + * |
2824 | + * Authors: |
2825 | + * Roberto Mier |
2826 | + * Tiago Herrmann |
2827 | + */ |
2828 | + |
2829 | +#ifndef DOWNLOADFILE_H |
2830 | +#define DOWNLOADFILE_H |
2831 | + |
2832 | +#include <QString> |
2833 | +#include <QByteArray> |
2834 | +#include <QSharedPointer> |
2835 | +#include "util/constants.h" |
2836 | +#include "types/inputfilelocation.h" |
2837 | +#include "file.h" |
2838 | +#include "core/session.h" |
2839 | + |
2840 | +class DownloadFile : public File |
2841 | +{ |
2842 | + Q_OBJECT |
2843 | +public: |
2844 | + |
2845 | + typedef QSharedPointer<DownloadFile> Ptr; |
2846 | + |
2847 | + DownloadFile(Session *session, InputFileLocation fileLocation, qint32 expectedSize, QObject *parent = 0); |
2848 | + ~DownloadFile(); |
2849 | + |
2850 | + void appendBytes(const QByteArray &bytes); |
2851 | + QByteArray bytes() const; |
2852 | + qint32 offset() const; |
2853 | + void setOffset(qint32 offset); |
2854 | + void setMtime(qint32 mtime); |
2855 | + qint32 mtime() const; |
2856 | + InputFileLocation fileLocation() const; |
2857 | + qint32 expectedSize() const ; |
2858 | + qint32 partId() const; |
2859 | + void incrementPartId(); |
2860 | + bool encrypted() const; |
2861 | + uchar *key(); |
2862 | + uchar *iv(); |
2863 | + |
2864 | +private: |
2865 | + InputFileLocation mFileLocation; |
2866 | + QString mName; |
2867 | + QByteArray mBytes; |
2868 | + qint32 mOffset; |
2869 | + qint32 mMtime; |
2870 | + qint32 mExpectedSize; |
2871 | + qint32 mPartId; |
2872 | +}; |
2873 | + |
2874 | +#endif // DOWNLOADFILE_H |
2875 | |
2876 | === added file 'lib/file/file.h' |
2877 | --- lib/file/file.h 1970-01-01 00:00:00 +0000 |
2878 | +++ lib/file/file.h 2015-02-24 14:12:31 +0000 |
2879 | @@ -0,0 +1,84 @@ |
2880 | +/* |
2881 | + * Copyright 2014 Canonical Ltd. |
2882 | + * |
2883 | + * This program is free software; you can redistribute it and/or modify |
2884 | + * it under the terms of the GNU General Public License as published by |
2885 | + * the Free Software Foundation; version 3. |
2886 | + * |
2887 | + * This program is distributed in the hope that it will be useful, |
2888 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2889 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2890 | + * GNU General Public License for more details. |
2891 | + * |
2892 | + * You should have received a copy of the GNU General Public License |
2893 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2894 | + * |
2895 | + * Authors: |
2896 | + * Roberto Mier |
2897 | + * Tiago Herrmann |
2898 | + */ |
2899 | + |
2900 | +#ifndef FILE_H |
2901 | +#define FILE_H |
2902 | + |
2903 | +#include <QObject> |
2904 | +#include <QLoggingCategory> |
2905 | +#include "util/constants.h" |
2906 | +#include "util/utils.h" |
2907 | +#include "core/session.h" |
2908 | + |
2909 | +Q_DECLARE_LOGGING_CATEGORY(TG_FILE_FILEHANDLER) |
2910 | + |
2911 | +class File : public QObject |
2912 | +{ |
2913 | + Q_OBJECT |
2914 | +public: |
2915 | + explicit File(Session *session, qint64 length, QObject *parent = 0) : |
2916 | + QObject(parent), |
2917 | + mSession(session), |
2918 | + mLength(length), |
2919 | + mPartLength(BLOCK), |
2920 | + mEncrypted(false) { |
2921 | + |
2922 | + // generate random file id |
2923 | + Utils::randomBytes(&mId, 8); |
2924 | + |
2925 | + // calculate part length |
2926 | + qint32 tmp = ((mLength + 2999) / 3000); |
2927 | + while (mPartLength < tmp) { |
2928 | + mPartLength *= 2; |
2929 | + } |
2930 | + if (mPartLength > (512 << 10)) { |
2931 | + qCCritical(TG_FILE_FILEHANDLER) << "Too big file. Max supported part size is" << ((512 << 10) + 1000); |
2932 | + return; |
2933 | + } |
2934 | + } |
2935 | + virtual ~File() { |
2936 | + if (mSession) { |
2937 | + mSession->release(); |
2938 | + } |
2939 | + } |
2940 | + |
2941 | + void setSession(Session *session) { mSession = session; } |
2942 | + Session *session() { return mSession; } |
2943 | + qint64 id() const { return mId; } |
2944 | + qint64 length() const { return mLength; } |
2945 | + qint64 partLength() const { return mPartLength; } |
2946 | + |
2947 | + void setEncrypted(bool encrypted) { mEncrypted = encrypted; } |
2948 | + void setKey(const QByteArray &key) { memcpy(mKey, key.data(), 32); } |
2949 | + void setIv(const QByteArray &iv) { memcpy(mIv, iv.data(), 32); } |
2950 | + |
2951 | +protected: |
2952 | + Session *mSession; |
2953 | + qint64 mId; |
2954 | + qint64 mLength; |
2955 | + qint64 mPartLength; |
2956 | + |
2957 | + bool mEncrypted; // if true, this file upload belongs to a secret chat |
2958 | + //key and initialization vector for encrypted files |
2959 | + uchar mKey[32]; // 32 bytes |
2960 | + uchar mIv[32]; // 32 bytes |
2961 | +}; |
2962 | + |
2963 | +#endif // FILE_H |
2964 | |
2965 | === added file 'lib/file/filehandler.cpp' |
2966 | --- lib/file/filehandler.cpp 1970-01-01 00:00:00 +0000 |
2967 | +++ lib/file/filehandler.cpp 2015-02-24 14:12:31 +0000 |
2968 | @@ -0,0 +1,422 @@ |
2969 | +#include "filehandler.h" |
2970 | +#include "secret/secretchat.h" |
2971 | +#include "secret/encrypter.h" |
2972 | + |
2973 | +Q_LOGGING_CATEGORY(TG_FILE_FILEHANDLER, "tg.file.filehandler") |
2974 | + |
2975 | +FileHandler::FileHandler(Api *api, DcProvider &dcProvider, SecretState &secretState, QObject *parent) : |
2976 | + QObject(parent), |
2977 | + mApi(api), |
2978 | + mDcProvider(dcProvider), |
2979 | + mSecretState(secretState) { |
2980 | + |
2981 | + connect(mApi, SIGNAL(uploadSaveFilePartResult(qint64,qint64,bool)), this, SLOT(onUploadSaveFilePartResult(qint64,qint64,bool))); |
2982 | + connect(mApi, SIGNAL(uploadSaveBigFilePartResult(qint64,qint64,bool)), this, SLOT(onUploadSaveFilePartResult(qint64,qint64,bool))); |
2983 | + connect(mApi, SIGNAL(uploadFile(qint64,StorageFileType,qint32,QByteArray)), this, SLOT(onUploadGetFileAnswer(qint64,StorageFileType,qint32,QByteArray))); |
2984 | + connect(mApi, SIGNAL(uploadFileError(qint64,qint32,QString)), this, SLOT(onUploadGetFileError(qint64,qint32,QString))); |
2985 | + connect(mApi, SIGNAL(messagesSentMediaStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32)), SLOT(onMessagesSendMediaStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32))); |
2986 | + connect(mApi, SIGNAL(messagesSentMediaStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), SLOT(onMessagesSendMediaStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
2987 | + connect(mApi, SIGNAL(messagesSendEncryptedFileSentEncryptedMessage(qint64,qint32)), this, SLOT(onMessagesSentEncryptedFile(qint64,qint32))); |
2988 | + connect(mApi, SIGNAL(messagesSendEncryptedFileSentEncryptedFile(qint64,qint32,EncryptedFile)), this, SLOT(onMessagesSentEncryptedFile(qint64,qint32,EncryptedFile))); |
2989 | +} |
2990 | + |
2991 | +FileHandler::~FileHandler() { |
2992 | + Q_FOREACH (UploadFile::Ptr f, mUploadsMap.values()) { |
2993 | + f.clear(); |
2994 | + } |
2995 | + Q_FOREACH (FileOperation::Ptr op, mFileOperationsMap.values()) { |
2996 | + op.clear(); |
2997 | + } |
2998 | + Q_FOREACH (DownloadFile::Ptr f, mDownloadsMap.values()) { |
2999 | + f.clear(); |
3000 | + } |
3001 | +} |
3002 | + |
3003 | +qint64 FileHandler::uploadSendFile(FileOperation &op, const QString &fileName, const QByteArray &bytes, const QByteArray &thumbnailBytes, const QString &thumbnailName) { |
3004 | + // create dedicated session to working dc for the main file |
3005 | + DC *dc = mDcProvider.getWorkingDc(); |
3006 | + Session *session = mApi->fileSession(dc); |
3007 | + UploadFile::Ptr f = UploadFile::Ptr(new UploadFile(session, UploadFile::Main, bytes, this)); |
3008 | + bool encrypted = op.opType() == FileOperation::sendEncryptedFile; |
3009 | + if (encrypted) { |
3010 | + f->setEncrypted(true); |
3011 | + f->setKey(op.key()); |
3012 | + f->setIv(op.iv()); |
3013 | + } |
3014 | + f->setName(fileName); |
3015 | + mUploadsMap.insert(f->id(), f); |
3016 | + mFileOperationsMap.insert(f->id(), FileOperation::Ptr(&op)); |
3017 | + UploadFile::Ptr firstFileToUpload = f; |
3018 | + // if exists thumbnail, create its file object and assign id to main file thumbnail_id (and viceversa) |
3019 | + // first send all thumbnail before sending main file |
3020 | + if (!thumbnailBytes.isEmpty()) { |
3021 | + // use same session for thumbnail and main file. In case a thumbnail exists, send it first |
3022 | + UploadFile::Ptr thumb = UploadFile::Ptr(new UploadFile(session, UploadFile::Thumbnail, thumbnailBytes, this)); |
3023 | + f->setRelatedFileId(thumb->id()); |
3024 | + thumb->setRelatedFileId(f->id()); |
3025 | + thumbnailName.length() > 0 ? thumb->setName(thumbnailName) : thumb->setName(fileName); |
3026 | + // insert the relationship fileId <-> thumb file |
3027 | + mUploadsMap.insert(thumb->id(), thumb); |
3028 | + firstFileToUpload = thumb; |
3029 | + } |
3030 | + |
3031 | + if (session->state() == QAbstractSocket::ConnectedState) { |
3032 | + uploadSendFileParts(*firstFileToUpload); |
3033 | + } else { |
3034 | + mInitialUploadsMap[session->sessionId()] << firstFileToUpload; |
3035 | + connect(session, SIGNAL(sessionReady(DC*)), this, SLOT(onUploadSendFileSessionCreated())); |
3036 | + session->connectToServer(); |
3037 | + } |
3038 | + |
3039 | + return f->id(); |
3040 | +} |
3041 | + |
3042 | +qint64 FileHandler::uploadSendFile(FileOperation &op, const QString &filePath, const QString &thumbnailPath) { |
3043 | + // create dedicated session to working dc for the main file |
3044 | + DC *dc = mDcProvider.getWorkingDc(); |
3045 | + Session *session = mApi->fileSession(dc); |
3046 | + UploadFile::Ptr f = UploadFile::Ptr(new UploadFile(session, UploadFile::Main, filePath, this)); |
3047 | + bool encrypted = op.opType() == FileOperation::sendEncryptedFile; |
3048 | + if (encrypted) { |
3049 | + f->setEncrypted(true); |
3050 | + f->setKey(op.key()); |
3051 | + f->setIv(op.iv()); |
3052 | + } |
3053 | + mUploadsMap.insert(f->id(), f); |
3054 | + mFileOperationsMap.insert(f->id(), FileOperation::Ptr(&op)); |
3055 | + UploadFile::Ptr firstFileToUpload = f; |
3056 | + // if exists thumbnail, create its file object and assign id to main file thumbnail_id (and viceversa) |
3057 | + // first send all thumbnail before sending main file |
3058 | + if (thumbnailPath.length() > 0) { |
3059 | + // use same session for thumbnail and main file. In case a thumbnail exists, send it first |
3060 | + UploadFile::Ptr thumb = UploadFile::Ptr(new UploadFile(session, UploadFile::Thumbnail, thumbnailPath, this)); |
3061 | + f->setRelatedFileId(thumb->id()); |
3062 | + thumb->setRelatedFileId(f->id()); |
3063 | + // insert the relationship fileId <-> thumb file |
3064 | + mUploadsMap.insert(thumb->id(), thumb); |
3065 | + firstFileToUpload = thumb; |
3066 | + } |
3067 | + |
3068 | + if (session->state() == QAbstractSocket::ConnectedState) { |
3069 | + uploadSendFileParts(*firstFileToUpload); |
3070 | + } else { |
3071 | + mInitialUploadsMap[session->sessionId()] << firstFileToUpload; |
3072 | + connect(session, SIGNAL(sessionReady(DC*)), this, SLOT(onUploadSendFileSessionCreated())); |
3073 | + session->connectToServer(); |
3074 | + } |
3075 | + |
3076 | + return f->id(); |
3077 | +} |
3078 | + |
3079 | +void FileHandler::onUploadSendFileSessionCreated() { |
3080 | + Session *session = qobject_cast<Session*>(sender()); |
3081 | + QList<UploadFile::Ptr> sessionInitialFiles = mInitialUploadsMap.take(session->sessionId()); |
3082 | + Q_FOREACH (UploadFile::Ptr f, sessionInitialFiles) { |
3083 | + uploadSendFileParts(*f); |
3084 | + } |
3085 | +} |
3086 | + |
3087 | +qint64 FileHandler::uploadSendFileParts(UploadFile &file) { |
3088 | + // depending on size use one or other api method to upload every part |
3089 | + qint32 partId = 0; |
3090 | + |
3091 | + while (file.hasMoreParts()) { |
3092 | + QByteArray bytes = file.nextPart(); |
3093 | + if (file.length() > 10 * 1024 * 1024) { |
3094 | + mApi->uploadSaveBigFilePart(file.session(), file.id(), partId++, file.nParts(), bytes); |
3095 | + } else { |
3096 | + mApi->uploadSaveFilePart(file.session(), file.id(), partId++, bytes); |
3097 | + } |
3098 | + } |
3099 | + // return file id instead of every part msg id |
3100 | + return file.id(); |
3101 | +} |
3102 | + |
3103 | +void FileHandler::onUploadSaveFilePartResult(qint64, qint64 fileId, bool) { |
3104 | + UploadFile::Ptr uploadFile = mUploadsMap.value(fileId); |
3105 | + Q_ASSERT(!uploadFile.isNull()); |
3106 | + uploadFile->increaseUploadedParts(); |
3107 | + qCDebug(TG_FILE_FILEHANDLER) << "uploaded" << uploadFile->uploadedParts() << "parts out of" << uploadFile->nParts(); |
3108 | + |
3109 | + // emit signal with upload progress |
3110 | + qint32 length = uploadFile->length(); |
3111 | + qint32 uploaded = uploadFile->uploadedParts() * uploadFile->partLength(); |
3112 | + uploaded = uploaded > length ? length : uploaded; |
3113 | + qint32 partId = uploadFile->uploadedParts() - 1; |
3114 | + Q_EMIT uploadSendFileAnswer(fileId, partId, uploaded, length); |
3115 | + |
3116 | + if (uploadFile->uploadedParts() == uploadFile->nParts()) { |
3117 | + // if finished a thumbnail, send the main file. Send media metadata if finished is the main file |
3118 | + qCDebug(TG_FILE_FILEHANDLER) << "file upload finished for fileId" << fileId; |
3119 | + if (uploadFile->fileType() == UploadFile::Thumbnail) { |
3120 | + qint64 mainFileId = uploadFile->relatedFileId(); |
3121 | + UploadFile::Ptr main = mUploadsMap.value(mainFileId); |
3122 | + Q_ASSERT(!main.isNull()); |
3123 | + uploadSendFileParts(*main); |
3124 | + } else { |
3125 | + // compose InputFile to be added to metadata |
3126 | + InputFile inputFile(InputFile::typeInputFile); |
3127 | + if (uploadFile->length() > 10 * 1024 * 1024) { |
3128 | + inputFile.setClassType(InputFile::typeInputFileBig); |
3129 | + } else { |
3130 | + inputFile.setMd5Checksum(QString(uploadFile->md5().toHex())); |
3131 | + } |
3132 | + inputFile.setId(fileId); |
3133 | + inputFile.setParts(uploadFile->nParts()); |
3134 | + inputFile.setName(uploadFile->name()); |
3135 | + |
3136 | + qint64 requestId; |
3137 | + // Read operation and execute internal api operation depending on file operation type |
3138 | + FileOperation::Ptr op = mFileOperationsMap.take(uploadFile->id()); |
3139 | + switch (op->opType()) { |
3140 | + case FileOperation::sendMedia: { |
3141 | + InputMedia metadata = op->inputMedia(); |
3142 | + metadata.setFile(inputFile); |
3143 | + // once filled input main file, check if there is a thumbnail and fill its data |
3144 | + if (uploadFile->relatedFileId()) { |
3145 | + UploadFile::Ptr thumb = mUploadsMap.take(uploadFile->relatedFileId()); |
3146 | + InputFile inputThumb(InputFile::typeInputFile); |
3147 | + if (thumb->length() > 10 * 1024 * 1024) { |
3148 | + inputThumb.setClassType(InputFile::typeInputFileBig); |
3149 | + } else { |
3150 | + inputThumb.setMd5Checksum(QString(thumb->md5().toHex())); |
3151 | + } |
3152 | + inputThumb.setId(thumb->id()); |
3153 | + inputThumb.setParts(thumb->nParts()); |
3154 | + inputThumb.setName(thumb->name()); |
3155 | + metadata.setThumb(inputThumb); |
3156 | + thumb.clear(); |
3157 | + } |
3158 | + // retrieve peer related to file, generate random id and send media metadata |
3159 | + InputPeer peer = op->peer(); |
3160 | + qint64 randomId = op->randomId(); |
3161 | + requestId = mApi->messagesSendMedia(peer, metadata, randomId); |
3162 | + break; |
3163 | + } |
3164 | + case FileOperation::editChatPhoto: { |
3165 | + InputChatPhoto metadata = op->inputChatPhoto(); |
3166 | + metadata.setFile(inputFile); |
3167 | + qint32 chatId = op->chatId(); |
3168 | + requestId = mApi->messagesEditChatPhoto(chatId, metadata); |
3169 | + break; |
3170 | + } |
3171 | + case FileOperation::uploadProfilePhoto: { |
3172 | + QString caption = op->caption(); |
3173 | + InputGeoPoint geoPoint = op->geoPoint(); |
3174 | + InputPhotoCrop crop = op->crop(); |
3175 | + requestId = mApi->photosUploadProfilePhoto(inputFile, caption, geoPoint, crop); |
3176 | + break; |
3177 | + } |
3178 | + case FileOperation::sendEncryptedFile: { |
3179 | + InputEncryptedChat inputEncryptedChat = op->inputEncryptedChat(); |
3180 | + qint64 randomId = op->randomId(); |
3181 | + DecryptedMessage decryptedMessage = op->decryptedMessage(); |
3182 | + |
3183 | + InputEncryptedFile inputEncryptedFile(InputEncryptedFile::typeInputEncryptedFileUploaded); |
3184 | + inputEncryptedFile.setId(fileId); |
3185 | + inputEncryptedFile.setParts(uploadFile->nParts()); |
3186 | + inputEncryptedFile.setMd5Checksum(QString(uploadFile->md5().toHex())); |
3187 | + |
3188 | + qint32 keyFingerprint = CryptoUtils::getInstance()->computeKeyFingerprint(op->key(), op->iv()); |
3189 | + inputEncryptedFile.setKeyFingerprint(keyFingerprint); |
3190 | + |
3191 | + SecretChat *secretChat = mSecretState.chats().value(inputEncryptedChat.chatId()); |
3192 | + QList<qint64> previousMsgs = secretChat->sequence(); |
3193 | + Encrypter encrypter; |
3194 | + encrypter.setSecretChat(secretChat); |
3195 | + QByteArray data = encrypter.generateEncryptedData(decryptedMessage); |
3196 | + requestId = mApi->messagesSendEncryptedFile(previousMsgs, inputEncryptedChat, randomId, data, inputEncryptedFile); |
3197 | + |
3198 | + secretChat->increaseOutSeqNo(); |
3199 | + secretChat->appendToSequence(randomId); |
3200 | + mSecretState.save(); |
3201 | + break; |
3202 | + } |
3203 | + } |
3204 | + //correlate response of sendmedia with file id (that will be the id value to correlate the initial request) |
3205 | + mFileIdsMap.insert(requestId, uploadFile->id()); |
3206 | + // delete main file from map after sending |
3207 | + mUploadsMap.remove(fileId); |
3208 | + // delete operation and main file pointers |
3209 | + uploadFile.clear(); |
3210 | + op.clear(); |
3211 | + } |
3212 | + } |
3213 | +} |
3214 | + |
3215 | +qint64 FileHandler::uploadGetFile(const InputFileLocation &location, qint32 fileSize, qint32 dcNum, const QByteArray &key, const QByteArray &iv) { |
3216 | + // change of dc if received a dcNum |
3217 | + DC *dc; |
3218 | + dcNum ? dc = mDcProvider.getDc(dcNum) : dc = mDcProvider.getWorkingDc(); |
3219 | + Session *session = mApi->fileSession(dc); |
3220 | + DownloadFile::Ptr f = DownloadFile::Ptr(new DownloadFile(session, location, fileSize, this)); |
3221 | + if (location.classType() == InputFileLocation::typeInputEncryptedFileLocation) { |
3222 | + f->setEncrypted(true); |
3223 | + f->setKey(key); |
3224 | + f->setIv(iv); |
3225 | + } |
3226 | + mActiveDownloadsMap.insert(f->id(), true); |
3227 | + |
3228 | + switch (session->state()) { |
3229 | + case QAbstractSocket::ConnectingState: { |
3230 | + mInitialDownloadsMap[session->sessionId()] << f; |
3231 | + break; |
3232 | + } |
3233 | + case QAbstractSocket::ConnectedState: { |
3234 | + qint64 msgId = mApi->uploadGetFile(session, f->fileLocation()); |
3235 | + mDownloadsMap.insert(msgId, f); |
3236 | + break; |
3237 | + } |
3238 | + default: { |
3239 | + QList<DownloadFile::Ptr> sessionInitialFiles; |
3240 | + sessionInitialFiles << f; |
3241 | + mInitialDownloadsMap.insert(session->sessionId(), sessionInitialFiles); |
3242 | + connect(session, SIGNAL(sessionReady(DC*)), this, SLOT(onUploadGetFileSessionCreated())); |
3243 | + session->connectToServer(); |
3244 | + break; |
3245 | + } |
3246 | + } |
3247 | + |
3248 | + // return file id as request id for apps |
3249 | + return f->id(); |
3250 | +} |
3251 | + |
3252 | +void FileHandler::onUploadGetFileSessionCreated() { |
3253 | + Session *session = qobject_cast<Session *>(sender()); |
3254 | + QList<DownloadFile::Ptr> sessionInitialFiles = mInitialDownloadsMap.take(session->sessionId()); |
3255 | + Q_FOREACH (DownloadFile::Ptr f, sessionInitialFiles) { |
3256 | + qint64 msgId = mApi->uploadGetFile(session, f->fileLocation()); |
3257 | + mDownloadsMap.insert(msgId, f); |
3258 | + } |
3259 | +} |
3260 | + |
3261 | +void FileHandler::onUploadGetFileAnswer(qint64 msgId, StorageFileType type, qint32 mtime, QByteArray bytes) { |
3262 | + DownloadFile::Ptr f = mDownloadsMap.take(msgId); |
3263 | + Q_ASSERT(!f.isNull()); |
3264 | + |
3265 | + if (mCancelDownloadsMap.take(f->id())) { |
3266 | + Q_EMIT uploadCancelFileAnswer(f->id(), true); |
3267 | + mActiveDownloadsMap.remove(f->id()); |
3268 | + f.clear(); |
3269 | + return; |
3270 | + } |
3271 | + |
3272 | + if (f->encrypted()) { |
3273 | + CryptoUtils::getInstance()->decryptFilePart(bytes, f->key(), f->iv()); |
3274 | + // if decrypted bytes are more than the last part expected ones, remove surplus |
3275 | + qint32 expectedMaxPartSize = f->expectedSize() - f->offset(); |
3276 | + if (bytes.length() > expectedMaxPartSize) { |
3277 | + bytes.truncate(expectedMaxPartSize); |
3278 | + } |
3279 | + } |
3280 | + |
3281 | + // if 'managedDownloads' flag is set, store all temporal received data and return a unique event |
3282 | + // when file downloading is finished. Emit an event for every part otherwise. |
3283 | + if (Settings::getInstance()->managedDownloads()) { |
3284 | + // partial bytes appended to DownloadFile object |
3285 | + f->appendBytes(bytes); |
3286 | + |
3287 | + qint32 expectedSize = f->expectedSize(); |
3288 | + if (expectedSize == 0 && (bytes.length() < BLOCK || bytes.length() == 0)) { |
3289 | + expectedSize = f->offset(); |
3290 | + } |
3291 | + |
3292 | + if (expectedSize == 0 || f->bytes().length() < expectedSize) { |
3293 | + qint64 newMsgId = mApi->uploadGetFile(f->session(), f->fileLocation(), f->offset(), f->partLength()); |
3294 | + mDownloadsMap.insert(newMsgId, f); |
3295 | + } else { |
3296 | + Q_EMIT uploadGetFileAnswer(f->id(), type, mtime, f->bytes(), 0, f->length(), expectedSize); //emit signal of finished |
3297 | + mActiveDownloadsMap.remove(f->id()); |
3298 | + f.clear(); |
3299 | + } |
3300 | + } else { |
3301 | + qint32 downloaded = f->partId() * f->partLength() + bytes.length(); |
3302 | + qint32 thisPartId = f->partId(); |
3303 | + qint32 expectedSize = f->expectedSize(); |
3304 | + |
3305 | + f->incrementPartId(); |
3306 | + f->setOffset(f->offset() + bytes.length()); |
3307 | + |
3308 | + if (expectedSize == 0 && (bytes.length() < BLOCK || bytes.length() == 0)) { |
3309 | + expectedSize = f->offset(); |
3310 | + } |
3311 | + |
3312 | + Q_EMIT uploadGetFileAnswer(f->id(), type, mtime, bytes, thisPartId, downloaded, expectedSize); |
3313 | + |
3314 | + if (expectedSize == 0 || f->offset() < expectedSize) { |
3315 | + qint64 newMsgId = mApi->uploadGetFile(f->session(), f->fileLocation(), f->offset(), f->partLength()); |
3316 | + mDownloadsMap.insert(newMsgId, f); |
3317 | + } else { |
3318 | + mActiveDownloadsMap.remove(f->id()); |
3319 | + f.clear(); |
3320 | + } |
3321 | + } |
3322 | +} |
3323 | + |
3324 | +void FileHandler::onUploadGetFileError(qint64 id, qint32 errorCode, const QString &errorText) { |
3325 | + // check for error and resend authCheckPhone() request |
3326 | + if (errorText.contains("_MIGRATE_")) { |
3327 | + qint32 newDc = errorText.mid(errorText.lastIndexOf("_") + 1).toInt(); |
3328 | + qCDebug(TG_FILE_FILEHANDLER) << "file migrated to dc" << newDc; |
3329 | + DC *dc = mDcProvider.getDc(newDc); |
3330 | + DownloadFile::Ptr f = mDownloadsMap.take(id); |
3331 | + // release previous session |
3332 | + f->session()->release(); |
3333 | + // get session against new dc |
3334 | + Session *newDcSession = mApi->fileSession(dc); |
3335 | + f->setSession(newDcSession); |
3336 | + |
3337 | + switch (newDcSession->state()) { |
3338 | + case QAbstractSocket::ConnectingState: { |
3339 | + mInitialDownloadsMap[newDcSession->sessionId()] << f; |
3340 | + break; |
3341 | + } |
3342 | + case QAbstractSocket::ConnectedState: { |
3343 | + qint64 msgId = mApi->uploadGetFile(newDcSession, f->fileLocation()); |
3344 | + mDownloadsMap.insert(msgId, f); |
3345 | + break; |
3346 | + } |
3347 | + default: { |
3348 | + QList<DownloadFile::Ptr> sessionInitialFiles; |
3349 | + sessionInitialFiles << f; |
3350 | + mInitialDownloadsMap.insert(newDcSession->sessionId(), sessionInitialFiles); |
3351 | + connect(newDcSession, SIGNAL(sessionReady(DC*)), this, SLOT(onUploadGetFileSessionCreated())); |
3352 | + newDcSession->connectToServer(); |
3353 | + break; |
3354 | + } |
3355 | + } |
3356 | + |
3357 | + } else { |
3358 | + Q_EMIT error(id, errorCode, errorText); |
3359 | + } |
3360 | +} |
3361 | + |
3362 | +qint64 FileHandler::uploadCancelFile(qint64 fileId) { |
3363 | + if (!mActiveDownloadsMap.value(fileId)) { |
3364 | + // return signal of cancelled file, setting the 'cancelled' flag to false, only if the file is not into active |
3365 | + // downloads. Otherwise, the signal will be emitted when received next part of the file |
3366 | + Q_EMIT uploadCancelFileAnswer(fileId, false); |
3367 | + } else { |
3368 | + mCancelDownloadsMap.insert(fileId, true); |
3369 | + } |
3370 | + return fileId; |
3371 | +} |
3372 | + |
3373 | +void FileHandler::onMessagesSendMediaStatedMessage(qint64 id, Message message, QList<Chat> chats, QList<User> users, qint32 pts, qint32 seq) { |
3374 | + QList<ContactsLink> links; |
3375 | + onMessagesSendMediaStatedMessageLink(id, message, chats, users, links, pts, seq); |
3376 | +} |
3377 | + |
3378 | +void FileHandler::onMessagesSendMediaStatedMessageLink(qint64 id, Message message, QList<Chat> chats, QList<User> users, QList<ContactsLink> links, qint32 pts, qint32 seq) { |
3379 | + //recover correlated send media request id -> fileId |
3380 | + qint64 fileId = mFileIdsMap.take(id); |
3381 | + Q_ASSERT(fileId); |
3382 | + Q_EMIT messagesSendMediaAnswer(fileId, message, chats, users, links, pts, seq); |
3383 | +} |
3384 | + |
3385 | +void FileHandler::onMessagesSentEncryptedFile(qint64 id, qint32 date, const EncryptedFile &encryptedFile) { |
3386 | + //recover correlated send media request id -> fileId |
3387 | + qint64 fileId = mFileIdsMap.take(id); |
3388 | + Q_ASSERT(fileId); |
3389 | + Q_EMIT messagesSendEncryptedFileAnswer(fileId, date, encryptedFile); |
3390 | +} |
3391 | |
3392 | === added file 'lib/file/filehandler.h' |
3393 | --- lib/file/filehandler.h 1970-01-01 00:00:00 +0000 |
3394 | +++ lib/file/filehandler.h 2015-02-24 14:12:31 +0000 |
3395 | @@ -0,0 +1,79 @@ |
3396 | +#ifndef FILEHANDLER_H |
3397 | +#define FILEHANDLER_H |
3398 | + |
3399 | +#include <QObject> |
3400 | +#include <QSharedPointer> |
3401 | +#include "uploadfile.h" |
3402 | +#include "fileoperation.h" |
3403 | +#include "downloadfile.h" |
3404 | +#include "core/dcprovider.h" |
3405 | +#include "core/api.h" |
3406 | +#include "secret/secretstate.h" |
3407 | + |
3408 | +Q_DECLARE_LOGGING_CATEGORY(TG_FILE_FILEHANDLER) |
3409 | + |
3410 | +class FileHandler : public QObject |
3411 | +{ |
3412 | + Q_OBJECT |
3413 | +public: |
3414 | + typedef QSharedPointer<FileHandler> Ptr; |
3415 | + |
3416 | + explicit FileHandler(Api* api, DcProvider &dcProvider, SecretState &secretState, QObject *parent = 0); |
3417 | + ~FileHandler(); |
3418 | + |
3419 | + qint64 uploadSendFile(FileOperation &op, const QString &fileName, const QByteArray &bytes, const QByteArray &thumbnailBytes = 0, const QString &thumbnailName = ""); |
3420 | + qint64 uploadSendFile(FileOperation &op, const QString &filePath, const QString &thumbnailPath = ""); |
3421 | + qint64 uploadGetFile(const InputFileLocation &file, qint32 fileSize, qint32 dc = 0, const QByteArray &key = QByteArray(), const QByteArray &iv = QByteArray()); |
3422 | + qint64 uploadCancelFile(qint64 fileId); |
3423 | + |
3424 | +Q_SIGNALS: |
3425 | + void uploadSendFileAnswer(qint64 fileId, qint32 partId, qint32 uploaded, qint32 totalSize); |
3426 | + void uploadGetFileAnswer(qint64 fileId, StorageFileType type, qint32 mtime, QByteArray bytes, qint32 partId, qint32 downloaded, qint32 total); |
3427 | + void uploadCancelFileAnswer(qint64 fileId, bool cancelled); |
3428 | + void error(qint64 id, qint32 errorCode, QString errorText); |
3429 | + |
3430 | + void messagesSendMediaAnswer(qint64 fileId, Message message, QList<Chat> chats, QList<User> users, QList<ContactsLink> links, qint32 pts, qint32 seq); |
3431 | + void messagesSendEncryptedFileAnswer(qint64 id, qint32 date, EncryptedFile encryptedFile = EncryptedFile()); |
3432 | + |
3433 | +private: |
3434 | + Api *mApi; |
3435 | + DcProvider &mDcProvider; |
3436 | + SecretState &mSecretState; |
3437 | + |
3438 | + /* File Sending */ |
3439 | + // fileId -> physical file details (length, bytes, parts, every part details, etc..) |
3440 | + QMap<qint64, UploadFile::Ptr> mUploadsMap; |
3441 | + // mainFileId -> operation additional data to be done with the file (peer, operation type) |
3442 | + QMap<qint64, FileOperation::Ptr> mFileOperationsMap; |
3443 | + // sessionId -> list of files waiting for session connection to be ready for being uploaded |
3444 | + QMap<qint64, QList<UploadFile::Ptr> > mInitialUploadsMap; |
3445 | + // finally, when sending media by using telegram api messagesSendMedia, we need to correlate |
3446 | + // requestId -> fileId, cos fileId is what we returned in request and the identifier we need |
3447 | + // to answer in final response |
3448 | + QMap<qint64, qint64> mFileIdsMap; |
3449 | + |
3450 | + qint64 uploadSendFileParts(UploadFile &file); |
3451 | + |
3452 | + /* File receiving */ |
3453 | + // requestId -> physical downloading file details (DownloadFile structure includes fileId) |
3454 | + QMap<qint64, DownloadFile::Ptr> mDownloadsMap; |
3455 | + // sessionId -> list of files waiting for session connection to be ready for being downloaded |
3456 | + QMap<qint64, QList<DownloadFile::Ptr> > mInitialDownloadsMap; |
3457 | + // fileId -> true if the file download is in progress. An entry does not exists for that fileId if not downloading |
3458 | + QMap<qint64, bool> mActiveDownloadsMap; |
3459 | + // fileId -> true if requested a download cancel for that fileId |
3460 | + QMap<qint64, bool> mCancelDownloadsMap; |
3461 | + |
3462 | +private Q_SLOTS: |
3463 | + void onUploadSendFileSessionCreated(); |
3464 | + void onUploadSaveFilePartResult(qint64 msgId, qint64 fileId, bool ok); |
3465 | + void onUploadGetFileSessionCreated(); |
3466 | + void onUploadGetFileAnswer(qint64 msgId, StorageFileType type, qint32 mtime, QByteArray bytes); |
3467 | + void onUploadGetFileError(qint64 id, qint32 errorCode, const QString &errorText); |
3468 | + |
3469 | + void onMessagesSendMediaStatedMessage(qint64 id, Message message, QList<Chat> chats, QList<User> users, qint32 pts, qint32 seq); |
3470 | + void onMessagesSendMediaStatedMessageLink(qint64 id, Message message, QList<Chat> chats, QList<User> users, QList<ContactsLink> links, qint32 pts, qint32 seq); |
3471 | + void onMessagesSentEncryptedFile(qint64, qint32 date, const EncryptedFile &encryptedFile = EncryptedFile()); |
3472 | +}; |
3473 | + |
3474 | +#endif // FILEHANDLER_H |
3475 | |
3476 | === added file 'lib/file/fileoperation.h' |
3477 | --- lib/file/fileoperation.h 1970-01-01 00:00:00 +0000 |
3478 | +++ lib/file/fileoperation.h 2015-02-24 14:12:31 +0000 |
3479 | @@ -0,0 +1,107 @@ |
3480 | +/* |
3481 | + * Copyright 2014 Canonical Ltd. |
3482 | + * |
3483 | + * This program is free software; you can redistribute it and/or modify |
3484 | + * it under the terms of the GNU General Public License as published by |
3485 | + * the Free Software Foundation; version 3. |
3486 | + * |
3487 | + * This program is distributed in the hope that it will be useful, |
3488 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3489 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3490 | + * GNU General Public License for more details. |
3491 | + * |
3492 | + * You should have received a copy of the GNU General Public License |
3493 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3494 | + * |
3495 | + * Authors: |
3496 | + * Roberto Mier |
3497 | + * Tiago Herrmann |
3498 | + */ |
3499 | + |
3500 | +#ifndef FILEOPERATION_H |
3501 | +#define FILEOPERATION_H |
3502 | + |
3503 | +#include "uploadfile.h" |
3504 | +#include "types/inputpeer.h" |
3505 | +#include "types/inputmedia.h" |
3506 | +#include "types/inputchatphoto.h" |
3507 | +#include <QSharedPointer> |
3508 | + |
3509 | +class FileOperation |
3510 | +{ |
3511 | +public: |
3512 | + enum OpType { |
3513 | + sendMedia, |
3514 | + editChatPhoto, |
3515 | + uploadProfilePhoto, |
3516 | + sendEncryptedFile |
3517 | + }; |
3518 | + |
3519 | + typedef QSharedPointer<FileOperation> Ptr; |
3520 | + |
3521 | + FileOperation(OpType opType) : |
3522 | + mPeer(InputPeer::typeInputPeerEmpty), |
3523 | + mInputMedia(InputMedia::typeInputMediaEmpty), |
3524 | + mRandomId(0), |
3525 | + mInputChatPhoto(InputChatPhoto::typeInputChatPhotoEmpty), |
3526 | + mGeoPoint(InputGeoPoint::typeInputGeoPointEmpty), |
3527 | + mCrop(InputPhotoCrop::typeInputPhotoCropAuto), |
3528 | + mType(opType) {} |
3529 | + |
3530 | + InputPeer peer() const { return mPeer; } |
3531 | + void setInputPeer(const InputPeer &peer) { mPeer = peer; } |
3532 | + InputMedia inputMedia() const { return mInputMedia; } |
3533 | + void setInputMedia(const InputMedia &inputMedia) { mInputMedia = inputMedia; } |
3534 | + qint64 randomId() const { return mRandomId; } |
3535 | + void setRandomId(qint64 randomId) { mRandomId = randomId; } |
3536 | + qint32 chatId() const { return mChatId; } |
3537 | + void setChatId(qint32 chatId) { mChatId = chatId; } |
3538 | + InputChatPhoto inputChatPhoto() const { return mInputChatPhoto; } |
3539 | + void setInputChatPhoto(InputChatPhoto inputChatPhoto) { mInputChatPhoto = inputChatPhoto; } |
3540 | + QString caption() const { return mCaption; } |
3541 | + void setCaption(QString caption) { mCaption = caption; } |
3542 | + InputGeoPoint geoPoint() const { return mGeoPoint; } |
3543 | + void setGeoPoint(InputGeoPoint geoPoint) { mGeoPoint = geoPoint; } |
3544 | + InputPhotoCrop crop() const { return mCrop; } |
3545 | + void setCrop(InputPhotoCrop crop) { mCrop = crop; } |
3546 | + OpType opType() const { return mType; } |
3547 | + |
3548 | + |
3549 | + void setInputEncryptedChat(const InputEncryptedChat &inputEncryptedChat) { mInputEncryptedChat = inputEncryptedChat; } |
3550 | + void setDecryptedMessage(const DecryptedMessage &decryptedMessage) { mDecryptedMessage = decryptedMessage; } |
3551 | + InputEncryptedChat inputEncryptedChat() const { return mInputEncryptedChat; } |
3552 | + DecryptedMessage decryptedMessage() const { return mDecryptedMessage; } |
3553 | + QByteArray key() const { return mKey; } |
3554 | + QByteArray iv() const { return mIv; } |
3555 | + |
3556 | + void initializeKeyAndIv() { |
3557 | + char keyData[32]; |
3558 | + Utils::randomBytes(keyData, 32); |
3559 | + mKey = QByteArray(keyData, 32); |
3560 | + char ivData[32]; |
3561 | + Utils::randomBytes(ivData, 32); |
3562 | + mIv = QByteArray(ivData, 32); |
3563 | + } |
3564 | + |
3565 | +private: |
3566 | + // sendMedia operation attributes |
3567 | + InputPeer mPeer; |
3568 | + InputMedia mInputMedia; |
3569 | + qint64 mRandomId; |
3570 | + // editChatPhoto operation attributes |
3571 | + qint32 mChatId; |
3572 | + InputChatPhoto mInputChatPhoto; |
3573 | + // uploadProfilePhoto operation attributes |
3574 | + QString mCaption; |
3575 | + InputGeoPoint mGeoPoint; |
3576 | + InputPhotoCrop mCrop; |
3577 | + OpType mType; |
3578 | + |
3579 | + InputEncryptedChat mInputEncryptedChat; |
3580 | + DecryptedMessage mDecryptedMessage; |
3581 | + //key and initialization vector for encrypted files |
3582 | + QByteArray mKey; // 32 bytes |
3583 | + QByteArray mIv; // 32 bytes |
3584 | +}; |
3585 | + |
3586 | +#endif // FILEOPERATION_H |
3587 | |
3588 | === added file 'lib/file/uploadfile.cpp' |
3589 | --- lib/file/uploadfile.cpp 1970-01-01 00:00:00 +0000 |
3590 | +++ lib/file/uploadfile.cpp 2015-02-24 14:12:31 +0000 |
3591 | @@ -0,0 +1,131 @@ |
3592 | +/* |
3593 | + * Copyright 2014 Canonical Ltd. |
3594 | + * |
3595 | + * This program is free software; you can redistribute it and/or modify |
3596 | + * it under the terms of the GNU General Public License as published by |
3597 | + * the Free Software Foundation; version 3. |
3598 | + * |
3599 | + * This program is distributed in the hope that it will be useful, |
3600 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3601 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3602 | + * GNU General Public License for more details. |
3603 | + * |
3604 | + * You should have received a copy of the GNU General Public License |
3605 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3606 | + * |
3607 | + * Authors: |
3608 | + * Roberto Mier |
3609 | + * Tiago Herrmann |
3610 | + */ |
3611 | + |
3612 | +#include "uploadfile.h" |
3613 | + |
3614 | +#include <QFileInfo> |
3615 | + |
3616 | +UploadFile::UploadFile(Session *session, UploadFile::FileType fileType, const QByteArray &buffer, QObject *parent) : |
3617 | + File(session, buffer.size(), parent), |
3618 | + mFileType(fileType), |
3619 | + mRelatedFileId(0), |
3620 | + mName(""), |
3621 | + mBytes(buffer), |
3622 | + mFilePath(""), |
3623 | + mNParts(0), |
3624 | + mCurrentPart(0), |
3625 | + mUploadedParts(0), |
3626 | + mKrypt(QCryptographicHash::Md5) |
3627 | +{ |
3628 | + calculatePartsCount(); |
3629 | +} |
3630 | + |
3631 | +UploadFile::UploadFile(Session *session, UploadFile::FileType fileType, const QString &filePath, QObject *parent) : |
3632 | + File(session, QFileInfo(filePath).size(), parent), |
3633 | + mFileType(fileType), |
3634 | + mRelatedFileId(0), |
3635 | + mName(QFileInfo(filePath).fileName()), |
3636 | + mFilePath(filePath), |
3637 | + mNParts(0), |
3638 | + mCurrentPart(0), |
3639 | + mUploadedParts(0), |
3640 | + mIODevice(filePath), |
3641 | + mKrypt(QCryptographicHash::Md5) |
3642 | +{ |
3643 | + openIODevice(); |
3644 | + calculatePartsCount(); |
3645 | +} |
3646 | + |
3647 | +UploadFile::~UploadFile() { |
3648 | +} |
3649 | + |
3650 | +void UploadFile::openIODevice() { |
3651 | + if (mIODevice.open(QIODevice::ReadOnly)) { |
3652 | + // get file size with file open |
3653 | + mLength = mIODevice.size(); |
3654 | + } else { |
3655 | + Q_EMIT fileNotFound(); |
3656 | + } |
3657 | +} |
3658 | + |
3659 | +bool UploadFile::hasMoreParts() const { |
3660 | + return mCurrentPart < mNParts; |
3661 | +} |
3662 | + |
3663 | +QByteArray UploadFile::nextPart() { |
3664 | + QByteArray partBytes(mPartLength, Qt::Uninitialized); |
3665 | + |
3666 | + //let's see if the file content is loaded or a filepath is set |
3667 | + if (!mBytes.isEmpty()) { |
3668 | + qint32 k = 0; |
3669 | + if (mCurrentPart < mNParts -1) { |
3670 | + // if not the last part |
3671 | + qint32 n = (mCurrentPart + 1) * mPartLength; |
3672 | + for (qint32 j = (mCurrentPart * mPartLength); j < n; j++) { |
3673 | + partBytes[k++] = mBytes[j]; |
3674 | + } |
3675 | + } else { |
3676 | + // if last part |
3677 | + qint32 lastPartSize = mLength % mPartLength; |
3678 | + // if not the last part |
3679 | + qint32 n = (mCurrentPart * mPartLength) + lastPartSize; |
3680 | + for (qint32 j = (mCurrentPart * mPartLength); j < n; j++) { |
3681 | + partBytes[k++] = mBytes[j]; |
3682 | + } |
3683 | + } |
3684 | + } else { |
3685 | + // in this case we're reading an open file from a local path |
3686 | + if (mIODevice.isOpen()) { |
3687 | + mIODevice.seek(mCurrentPart * mPartLength); //set offset |
3688 | + partBytes = mIODevice.read(mPartLength); |
3689 | + if (!hasMoreParts()) { |
3690 | + mIODevice.close(); |
3691 | + } |
3692 | + } else { |
3693 | + Q_EMIT fileNotOpen(); |
3694 | + } |
3695 | + } |
3696 | + mCurrentPart++; |
3697 | + |
3698 | + QByteArray processedBytes; |
3699 | + if (mEncrypted) { |
3700 | + processedBytes = CryptoUtils::getInstance()->encryptFilePart(partBytes, mKey, mIv); |
3701 | + } else { |
3702 | + processedBytes = partBytes; |
3703 | + } |
3704 | + |
3705 | + // add the new data to cryptographic hash before return it |
3706 | + mKrypt.addData(processedBytes, processedBytes.length()); |
3707 | + return processedBytes; |
3708 | +} |
3709 | + |
3710 | +void UploadFile::increaseUploadedParts() { |
3711 | + mUploadedParts++; |
3712 | +} |
3713 | + |
3714 | +QByteArray UploadFile::md5() { |
3715 | + return mKrypt.result(); |
3716 | +} |
3717 | + |
3718 | +void UploadFile::calculatePartsCount() { |
3719 | + // calculate number of parts to be uploaded |
3720 | + mNParts = mLength / mPartLength; |
3721 | + if (mNParts * mPartLength < mLength) mNParts++; |
3722 | +} |
3723 | |
3724 | === added file 'lib/file/uploadfile.h' |
3725 | --- lib/file/uploadfile.h 1970-01-01 00:00:00 +0000 |
3726 | +++ lib/file/uploadfile.h 2015-02-24 14:12:31 +0000 |
3727 | @@ -0,0 +1,80 @@ |
3728 | +/* |
3729 | + * Copyright 2014 Canonical Ltd. |
3730 | + * |
3731 | + * This program is free software; you can redistribute it and/or modify |
3732 | + * it under the terms of the GNU General Public License as published by |
3733 | + * the Free Software Foundation; version 3. |
3734 | + * |
3735 | + * This program is distributed in the hope that it will be useful, |
3736 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3737 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3738 | + * GNU General Public License for more details. |
3739 | + * |
3740 | + * You should have received a copy of the GNU General Public License |
3741 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3742 | + * |
3743 | + * Authors: |
3744 | + * Roberto Mier |
3745 | + * Tiago Herrmann |
3746 | + */ |
3747 | + |
3748 | +#ifndef UPLOADFILE_H |
3749 | +#define UPLOADFILE_H |
3750 | + |
3751 | +#include <QObject> |
3752 | +#include <QSharedPointer> |
3753 | +#include <QFile> |
3754 | +#include <QCryptographicHash> |
3755 | +#include "file.h" |
3756 | +#include "types/inputmedia.h" |
3757 | + |
3758 | +class UploadFile : public File |
3759 | +{ |
3760 | + Q_OBJECT |
3761 | +public: |
3762 | + |
3763 | + enum FileType { |
3764 | + Main, |
3765 | + Thumbnail |
3766 | + }; |
3767 | + |
3768 | + typedef QSharedPointer<UploadFile> Ptr; |
3769 | + |
3770 | + explicit UploadFile(Session *session, FileType type, const QByteArray &buffer, QObject *parent = 0); |
3771 | + explicit UploadFile(Session *session, FileType type, const QString &filePath, QObject *parent = 0); |
3772 | + ~UploadFile(); |
3773 | + |
3774 | + qint64 relatedFileId() const { return mRelatedFileId; } |
3775 | + void setRelatedFileId(qint64 relatedFileId) { mRelatedFileId = relatedFileId; } |
3776 | + QString name() const { return mName; } |
3777 | + void setName(const QString &name) { mName = name; } |
3778 | + FileType fileType() const { return mFileType; } |
3779 | + qint32 nParts() const { return mNParts; } |
3780 | + qint32 uploadedParts() const { return mUploadedParts; } |
3781 | + |
3782 | + bool hasMoreParts() const; |
3783 | + QByteArray nextPart(); |
3784 | + void increaseUploadedParts(); |
3785 | + QByteArray md5(); |
3786 | + |
3787 | +Q_SIGNALS: |
3788 | + void fileNotFound(); |
3789 | + void fileNotOpen(); |
3790 | + |
3791 | +private: |
3792 | + FileType mFileType; |
3793 | + qint64 mRelatedFileId; // if this is the main file, related file is thumbnail and viceversa |
3794 | + QString mName; |
3795 | + QByteArray mBytes; |
3796 | + QString mFilePath; |
3797 | + qint32 mNParts; |
3798 | + qint32 mCurrentPart; |
3799 | + qint32 mUploadedParts; |
3800 | + QFile mIODevice; |
3801 | + QCryptographicHash mKrypt; |
3802 | + |
3803 | + void openIODevice(); |
3804 | + void calculatePartsCount(); |
3805 | +}; |
3806 | + |
3807 | +#endif // UPLOADFILE_H |
3808 | |
3809 | === removed directory 'lib/logic' |
3810 | === removed file 'lib/logic/CMakeLists.txt' |
3811 | --- lib/logic/CMakeLists.txt 2014-07-30 23:27:10 +0000 |
3812 | +++ lib/logic/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
3813 | @@ -1,10 +0,0 @@ |
3814 | -set(LOGIC_HEADERS |
3815 | - fileoperation.h |
3816 | - downloadfile.h |
3817 | - uploadfile.h |
3818 | - file.h) |
3819 | - |
3820 | -if(NOT CLICK_MODE) |
3821 | -INSTALL(FILES ${LOGIC_HEADERS} |
3822 | - DESTINATION ${CMAKE_INSTALL_PREFIX}/include/libqtelegram/logic) |
3823 | -endif(NOT CLICK_MODE) |
3824 | |
3825 | === removed file 'lib/logic/downloadfile.cpp' |
3826 | --- lib/logic/downloadfile.cpp 2014-11-28 18:46:13 +0000 |
3827 | +++ lib/logic/downloadfile.cpp 1970-01-01 00:00:00 +0000 |
3828 | @@ -1,85 +0,0 @@ |
3829 | -/* |
3830 | - * Copyright 2014 Canonical Ltd. |
3831 | - * |
3832 | - * This program is free software; you can redistribute it and/or modify |
3833 | - * it under the terms of the GNU General Public License as published by |
3834 | - * the Free Software Foundation; version 3. |
3835 | - * |
3836 | - * This program is distributed in the hope that it will be useful, |
3837 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3838 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3839 | - * GNU General Public License for more details. |
3840 | - * |
3841 | - * You should have received a copy of the GNU General Public License |
3842 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3843 | - * |
3844 | - * Authors: |
3845 | - * Roberto Mier |
3846 | - * Tiago Herrmann |
3847 | - */ |
3848 | - |
3849 | -#include "downloadfile.h" |
3850 | - |
3851 | -DownloadFile::DownloadFile(Session *session, InputFileLocation fileLocation, qint32 expectedSize, QObject *parent) : |
3852 | - File(session, 0, parent), |
3853 | - m_fileLocation(fileLocation), |
3854 | - m_offset(0), |
3855 | - m_mtime(0), |
3856 | - m_expectedSize(expectedSize), |
3857 | - m_partId(0) { |
3858 | -} |
3859 | - |
3860 | -DownloadFile::~DownloadFile() { |
3861 | -} |
3862 | - |
3863 | -QByteArray DownloadFile::bytes() const { |
3864 | - return m_bytes; |
3865 | -} |
3866 | - |
3867 | -void DownloadFile::appendBytes(const QByteArray &bytes) { |
3868 | - m_bytes.append(bytes); |
3869 | - m_offset += bytes.length(); |
3870 | -} |
3871 | - |
3872 | -qint32 DownloadFile::offset() const { |
3873 | - return m_offset; |
3874 | -} |
3875 | - |
3876 | -void DownloadFile::setOffset(qint32 offset) { |
3877 | - m_offset = offset; |
3878 | -} |
3879 | - |
3880 | -qint32 DownloadFile::mtime() const { |
3881 | - return m_mtime; |
3882 | -} |
3883 | -void DownloadFile::setMtime(qint32 mtime) { |
3884 | - m_mtime = mtime; |
3885 | -} |
3886 | - |
3887 | -InputFileLocation DownloadFile::fileLocation() const { |
3888 | - return m_fileLocation; |
3889 | -} |
3890 | - |
3891 | -qint32 DownloadFile::expectedSize() const { |
3892 | - return m_expectedSize; |
3893 | -} |
3894 | - |
3895 | -qint32 DownloadFile::partId() const { |
3896 | - return m_partId; |
3897 | -} |
3898 | - |
3899 | -void DownloadFile::incrementPartId() { |
3900 | - m_partId++; |
3901 | -} |
3902 | - |
3903 | -bool DownloadFile::encrypted() const { |
3904 | - return mEncrypted; |
3905 | -} |
3906 | - |
3907 | -uchar *DownloadFile::key() { |
3908 | - return mKey; |
3909 | -} |
3910 | - |
3911 | -uchar *DownloadFile::iv() { |
3912 | - return mIv; |
3913 | -} |
3914 | |
3915 | === removed file 'lib/logic/downloadfile.h' |
3916 | --- lib/logic/downloadfile.h 2014-11-28 18:46:13 +0000 |
3917 | +++ lib/logic/downloadfile.h 1970-01-01 00:00:00 +0000 |
3918 | @@ -1,63 +0,0 @@ |
3919 | -/* |
3920 | - * Copyright 2014 Canonical Ltd. |
3921 | - * |
3922 | - * This program is free software; you can redistribute it and/or modify |
3923 | - * it under the terms of the GNU General Public License as published by |
3924 | - * the Free Software Foundation; version 3. |
3925 | - * |
3926 | - * This program is distributed in the hope that it will be useful, |
3927 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3928 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3929 | - * GNU General Public License for more details. |
3930 | - * |
3931 | - * You should have received a copy of the GNU General Public License |
3932 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3933 | - * |
3934 | - * Authors: |
3935 | - * Roberto Mier |
3936 | - * Tiago Herrmann |
3937 | - */ |
3938 | - |
3939 | -#ifndef DOWNLOADFILE_H |
3940 | -#define DOWNLOADFILE_H |
3941 | - |
3942 | -#include <QString> |
3943 | -#include <QByteArray> |
3944 | -#include "core/constants.h" |
3945 | -#include "types/inputfilelocation.h" |
3946 | -#include "file.h" |
3947 | -#include "core/session.h" |
3948 | - |
3949 | -class DownloadFile : public File |
3950 | -{ |
3951 | - Q_OBJECT |
3952 | -public: |
3953 | - DownloadFile(Session *session, InputFileLocation fileLocation, qint32 expectedSize, QObject *parent = 0); |
3954 | - ~DownloadFile(); |
3955 | - |
3956 | - void appendBytes(const QByteArray &bytes); |
3957 | - QByteArray bytes() const; |
3958 | - qint32 offset() const; |
3959 | - void setOffset(qint32 offset); |
3960 | - void setMtime(qint32 mtime); |
3961 | - qint32 mtime() const; |
3962 | - InputFileLocation fileLocation() const; |
3963 | - qint32 expectedSize() const ; |
3964 | - qint32 partId() const; |
3965 | - void incrementPartId(); |
3966 | - |
3967 | - bool encrypted() const; |
3968 | - uchar *key(); |
3969 | - uchar *iv(); |
3970 | - |
3971 | -private: |
3972 | - InputFileLocation m_fileLocation; |
3973 | - QString m_name; |
3974 | - QByteArray m_bytes; |
3975 | - qint32 m_offset; |
3976 | - qint32 m_mtime; |
3977 | - qint32 m_expectedSize; |
3978 | - qint32 m_partId; |
3979 | -}; |
3980 | - |
3981 | -#endif // DOWNLOADFILE_H |
3982 | |
3983 | === removed file 'lib/logic/file.h' |
3984 | --- lib/logic/file.h 2015-01-29 11:41:41 +0000 |
3985 | +++ lib/logic/file.h 1970-01-01 00:00:00 +0000 |
3986 | @@ -1,88 +0,0 @@ |
3987 | -/* |
3988 | - * Copyright 2014 Canonical Ltd. |
3989 | - * |
3990 | - * This program is free software; you can redistribute it and/or modify |
3991 | - * it under the terms of the GNU General Public License as published by |
3992 | - * the Free Software Foundation; version 3. |
3993 | - * |
3994 | - * This program is distributed in the hope that it will be useful, |
3995 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3996 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3997 | - * GNU General Public License for more details. |
3998 | - * |
3999 | - * You should have received a copy of the GNU General Public License |
4000 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4001 | - * |
4002 | - * Authors: |
4003 | - * Roberto Mier |
4004 | - * Tiago Herrmann |
4005 | - */ |
4006 | - |
4007 | -#ifndef FILE_H |
4008 | -#define FILE_H |
4009 | - |
4010 | -#include <QObject> |
4011 | -#include <QLoggingCategory> |
4012 | -#include "core/constants.h" |
4013 | -#include "core/utils.h" |
4014 | -#include "core/session.h" |
4015 | - |
4016 | -Q_DECLARE_LOGGING_CATEGORY(TG_LIB_API) |
4017 | - |
4018 | -class File : public QObject |
4019 | -{ |
4020 | - Q_OBJECT |
4021 | -public: |
4022 | - explicit File(Session *session, qint64 length, QObject *parent = 0) : |
4023 | - QObject(parent), |
4024 | - m_session(session), |
4025 | - m_length(length), |
4026 | - mPartLength(BLOCK), |
4027 | - mEncrypted(false) { |
4028 | - |
4029 | - // generate random file id |
4030 | - Utils::randomBytes(&m_id, 8); |
4031 | - |
4032 | - // calculate part length |
4033 | - // TODO Roberto: commented out this code until solving the problem with percentage when so calculated the length part |
4034 | - /* |
4035 | - int tmp = ((m_length + 2999) / 3000); |
4036 | - mPartLength = (1 << 14); |
4037 | - while (mPartLength < tmp) { |
4038 | - mPartLength *= 2; |
4039 | - } |
4040 | - if (mPartLength > (512 << 10)) { |
4041 | - qCCritical(TG_LIB_API) << "Too big file. Max supported size is" << ((512 << 10) + 1000); |
4042 | - return; |
4043 | - } |
4044 | - */ |
4045 | - } |
4046 | - ~File() { |
4047 | - if (m_session) { |
4048 | - m_session->release(); |
4049 | - } |
4050 | - } |
4051 | - |
4052 | - void setSession(Session *session) { m_session = session; } |
4053 | - Session *session() { return m_session; } |
4054 | - qint64 id() const { return m_id; } |
4055 | - qint64 length() const { return m_length; } |
4056 | - qint64 partLength() const { return mPartLength; } |
4057 | - |
4058 | - void setEncrypted(bool encrypted) { mEncrypted = encrypted; } |
4059 | - void setKey(const QByteArray &key) { memcpy(mKey, key.data(), 32); } |
4060 | - void setIv(const QByteArray &iv) { memcpy(mIv, iv.data(), 32); } |
4061 | - |
4062 | -protected: |
4063 | - Session *m_session; |
4064 | - qint64 m_id; |
4065 | - qint64 m_length; |
4066 | - qint64 mPartLength; |
4067 | - |
4068 | - bool mEncrypted; // if true, this file upload belongs to a secret chat |
4069 | - //key and initialization vector for encrypted files |
4070 | - uchar mKey[32]; // 32 bytes |
4071 | - uchar mIv[32]; // 32 bytes |
4072 | -}; |
4073 | - |
4074 | -#endif // FILE_H |
4075 | |
4076 | === removed file 'lib/logic/fileoperation.h' |
4077 | --- lib/logic/fileoperation.h 2015-01-30 08:20:13 +0000 |
4078 | +++ lib/logic/fileoperation.h 1970-01-01 00:00:00 +0000 |
4079 | @@ -1,104 +0,0 @@ |
4080 | -/* |
4081 | - * Copyright 2014 Canonical Ltd. |
4082 | - * |
4083 | - * This program is free software; you can redistribute it and/or modify |
4084 | - * it under the terms of the GNU General Public License as published by |
4085 | - * the Free Software Foundation; version 3. |
4086 | - * |
4087 | - * This program is distributed in the hope that it will be useful, |
4088 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4089 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4090 | - * GNU General Public License for more details. |
4091 | - * |
4092 | - * You should have received a copy of the GNU General Public License |
4093 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4094 | - * |
4095 | - * Authors: |
4096 | - * Roberto Mier |
4097 | - * Tiago Herrmann |
4098 | - */ |
4099 | - |
4100 | -#ifndef FILEOPERATION_H |
4101 | -#define FILEOPERATION_H |
4102 | - |
4103 | -#include "uploadfile.h" |
4104 | -#include "types/inputpeer.h" |
4105 | -#include "types/inputmedia.h" |
4106 | -#include "types/inputchatphoto.h" |
4107 | - |
4108 | -class FileOperation |
4109 | -{ |
4110 | -public: |
4111 | - enum OpType { |
4112 | - sendMedia, |
4113 | - editChatPhoto, |
4114 | - uploadProfilePhoto, |
4115 | - sendEncryptedFile |
4116 | - }; |
4117 | - |
4118 | - FileOperation(OpType opType) : |
4119 | - m_peer(InputPeer::typeInputPeerEmpty), |
4120 | - m_inputMedia(InputMedia::typeInputMediaEmpty), |
4121 | - mRandomId(0), |
4122 | - m_inputChatPhoto(InputChatPhoto::typeInputChatPhotoEmpty), |
4123 | - m_geoPoint(InputGeoPoint::typeInputGeoPointEmpty), |
4124 | - m_crop(InputPhotoCrop::typeInputPhotoCropAuto), |
4125 | - m_type(opType) {} |
4126 | - |
4127 | - InputPeer peer() const { return m_peer; } |
4128 | - void setInputPeer(const InputPeer &peer) { m_peer = peer; } |
4129 | - InputMedia inputMedia() const { return m_inputMedia; } |
4130 | - void setInputMedia(const InputMedia &inputMedia) { m_inputMedia = inputMedia; } |
4131 | - qint64 randomId() const { return mRandomId; } |
4132 | - void setRandomId(qint64 randomId) { mRandomId = randomId; } |
4133 | - qint32 chatId() const { return m_chatId; } |
4134 | - void setChatId(qint32 chatId) { m_chatId = chatId; } |
4135 | - InputChatPhoto inputChatPhoto() const { return m_inputChatPhoto; } |
4136 | - void setInputChatPhoto(InputChatPhoto inputChatPhoto) { m_inputChatPhoto = inputChatPhoto; } |
4137 | - QString caption() const { return m_caption; } |
4138 | - void setCaption(QString caption) { m_caption = caption; } |
4139 | - InputGeoPoint geoPoint() const { return m_geoPoint; } |
4140 | - void setGeoPoint(InputGeoPoint geoPoint) { m_geoPoint = geoPoint; } |
4141 | - InputPhotoCrop crop() const { return m_crop; } |
4142 | - void setCrop(InputPhotoCrop crop) { m_crop = crop; } |
4143 | - OpType opType() const { return m_type; } |
4144 | - |
4145 | - |
4146 | - void setInputEncryptedChat(const InputEncryptedChat &inputEncryptedChat) { mInputEncryptedChat = inputEncryptedChat; } |
4147 | - void setDecryptedMessage(const DecryptedMessage &decryptedMessage) { mDecryptedMessage = decryptedMessage; } |
4148 | - InputEncryptedChat inputEncryptedChat() const { return mInputEncryptedChat; } |
4149 | - DecryptedMessage decryptedMessage() const { return mDecryptedMessage; } |
4150 | - QByteArray key() const { return mKey; } |
4151 | - QByteArray iv() const { return mIv; } |
4152 | - |
4153 | - void initializeKeyAndIv() { |
4154 | - char keyData[32]; |
4155 | - Utils::randomBytes(keyData, 32); |
4156 | - mKey = QByteArray(keyData, 32); |
4157 | - char ivData[32]; |
4158 | - Utils::randomBytes(ivData, 32); |
4159 | - mIv = QByteArray(ivData, 32); |
4160 | - } |
4161 | - |
4162 | -private: |
4163 | - // sendMedia operation attributes |
4164 | - InputPeer m_peer; |
4165 | - InputMedia m_inputMedia; |
4166 | - qint64 mRandomId; |
4167 | - // editChatPhoto operation attributes |
4168 | - qint32 m_chatId; |
4169 | - InputChatPhoto m_inputChatPhoto; |
4170 | - // uploadProfilePhoto operation attributes |
4171 | - QString m_caption; |
4172 | - InputGeoPoint m_geoPoint; |
4173 | - InputPhotoCrop m_crop; |
4174 | - OpType m_type; |
4175 | - |
4176 | - InputEncryptedChat mInputEncryptedChat; |
4177 | - DecryptedMessage mDecryptedMessage; |
4178 | - //key and initialization vector for encrypted files |
4179 | - QByteArray mKey; // 32 bytes |
4180 | - QByteArray mIv; // 32 bytes |
4181 | -}; |
4182 | - |
4183 | -#endif // FILEOPERATION_H |
4184 | |
4185 | === removed file 'lib/logic/uploadfile.cpp' |
4186 | --- lib/logic/uploadfile.cpp 2015-01-28 07:57:21 +0000 |
4187 | +++ lib/logic/uploadfile.cpp 1970-01-01 00:00:00 +0000 |
4188 | @@ -1,130 +0,0 @@ |
4189 | -/* |
4190 | - * Copyright 2014 Canonical Ltd. |
4191 | - * |
4192 | - * This program is free software; you can redistribute it and/or modify |
4193 | - * it under the terms of the GNU General Public License as published by |
4194 | - * the Free Software Foundation; version 3. |
4195 | - * |
4196 | - * This program is distributed in the hope that it will be useful, |
4197 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4198 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4199 | - * GNU General Public License for more details. |
4200 | - * |
4201 | - * You should have received a copy of the GNU General Public License |
4202 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4203 | - * |
4204 | - * Authors: |
4205 | - * Roberto Mier |
4206 | - * Tiago Herrmann |
4207 | - */ |
4208 | - |
4209 | -#include "uploadfile.h" |
4210 | - |
4211 | -#include <QFileInfo> |
4212 | - |
4213 | -UploadFile::UploadFile(Session *session, UploadFile::FileType fileType, const QByteArray &buffer, QObject *parent) : |
4214 | - File(session, buffer.size(), parent), |
4215 | - m_fileType(fileType), |
4216 | - m_relatedFileId(0), |
4217 | - m_name(""), |
4218 | - m_bytes(buffer), |
4219 | - m_filePath(""), |
4220 | - m_nParts(0), |
4221 | - m_currentPart(0), |
4222 | - m_uploadedParts(0), |
4223 | - m_krypt(QCryptographicHash::Md5) |
4224 | -{ |
4225 | - // calculate number of parts to be uploaded |
4226 | - m_nParts = m_length / mPartLength; |
4227 | - if (m_nParts * mPartLength < m_length) m_nParts++; |
4228 | -} |
4229 | - |
4230 | -UploadFile::UploadFile(Session *session, UploadFile::FileType fileType, const QString &filePath, QObject *parent) : |
4231 | - File(session, QFileInfo(filePath).size(), parent), |
4232 | - m_fileType(fileType), |
4233 | - m_relatedFileId(0), |
4234 | - m_name(QFileInfo(filePath).fileName()), |
4235 | - m_filePath(filePath), |
4236 | - m_nParts(0), |
4237 | - m_currentPart(0), |
4238 | - m_uploadedParts(0), |
4239 | - m_ioDevice(filePath), |
4240 | - m_krypt(QCryptographicHash::Md5) |
4241 | -{ |
4242 | - // open file |
4243 | - openIODevice(); |
4244 | - // calculate number of parts to be uploaded |
4245 | - m_nParts = m_length / mPartLength; |
4246 | - if (m_nParts * mPartLength < m_length) m_nParts++; |
4247 | -} |
4248 | - |
4249 | -UploadFile::~UploadFile() { |
4250 | -} |
4251 | - |
4252 | -void UploadFile::openIODevice() { |
4253 | - if (m_ioDevice.open(QIODevice::ReadOnly)) { |
4254 | - // get file size with file open |
4255 | - m_length = m_ioDevice.size(); |
4256 | - } else { |
4257 | - Q_EMIT fileNotFound(); |
4258 | - } |
4259 | -} |
4260 | - |
4261 | -bool UploadFile::hasMoreParts() const { |
4262 | - return m_currentPart < m_nParts; |
4263 | -} |
4264 | - |
4265 | -QByteArray UploadFile::nextPart() { |
4266 | - QByteArray partBytes(mPartLength, Qt::Uninitialized); |
4267 | - |
4268 | - //let's see if the file content is loaded or a filepath is set |
4269 | - if (!m_bytes.isEmpty()) { |
4270 | - qint32 k = 0; |
4271 | - if (m_currentPart < m_nParts -1) { |
4272 | - // if not the last part |
4273 | - qint32 n = (m_currentPart + 1) * mPartLength; |
4274 | - for (qint32 j = (m_currentPart * mPartLength); j < n; j++) { |
4275 | - partBytes[k++] = m_bytes[j]; |
4276 | - } |
4277 | - } else { |
4278 | - // if last part |
4279 | - qint32 lastPartSize = m_length % mPartLength; |
4280 | - // if not the last part |
4281 | - qint32 n = (m_currentPart * mPartLength) + lastPartSize; |
4282 | - for (qint32 j = (m_currentPart * mPartLength); j < n; j++) { |
4283 | - partBytes[k++] = m_bytes[j]; |
4284 | - } |
4285 | - } |
4286 | - } else { |
4287 | - // in this case we're reading an open file from a local path |
4288 | - if (m_ioDevice.isOpen()) { |
4289 | - m_ioDevice.seek(m_currentPart * mPartLength); //set offset |
4290 | - partBytes = m_ioDevice.read(mPartLength); |
4291 | - if (!hasMoreParts()) { |
4292 | - m_ioDevice.close(); |
4293 | - } |
4294 | - } else { |
4295 | - Q_EMIT fileNotOpen(); |
4296 | - } |
4297 | - } |
4298 | - m_currentPart++; |
4299 | - |
4300 | - QByteArray processedBytes; |
4301 | - if (mEncrypted) { |
4302 | - processedBytes = CryptoUtils::getInstance()->encryptFilePart(partBytes, mKey, mIv); |
4303 | - } else { |
4304 | - processedBytes = partBytes; |
4305 | - } |
4306 | - |
4307 | - // add the new data to cryptographic hash before return it |
4308 | - m_krypt.addData(processedBytes, processedBytes.length()); |
4309 | - return processedBytes; |
4310 | -} |
4311 | - |
4312 | -void UploadFile::increaseUploadedParts() { |
4313 | - m_uploadedParts++; |
4314 | -} |
4315 | - |
4316 | -QByteArray UploadFile::md5() { |
4317 | - return m_krypt.result(); |
4318 | -} |
4319 | |
4320 | === removed file 'lib/logic/uploadfile.h' |
4321 | --- lib/logic/uploadfile.h 2014-11-28 18:46:13 +0000 |
4322 | +++ lib/logic/uploadfile.h 1970-01-01 00:00:00 +0000 |
4323 | @@ -1,76 +0,0 @@ |
4324 | -/* |
4325 | - * Copyright 2014 Canonical Ltd. |
4326 | - * |
4327 | - * This program is free software; you can redistribute it and/or modify |
4328 | - * it under the terms of the GNU General Public License as published by |
4329 | - * the Free Software Foundation; version 3. |
4330 | - * |
4331 | - * This program is distributed in the hope that it will be useful, |
4332 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4333 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4334 | - * GNU General Public License for more details. |
4335 | - * |
4336 | - * You should have received a copy of the GNU General Public License |
4337 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4338 | - * |
4339 | - * Authors: |
4340 | - * Roberto Mier |
4341 | - * Tiago Herrmann |
4342 | - */ |
4343 | - |
4344 | -#ifndef UPLOADFILE_H |
4345 | -#define UPLOADFILE_H |
4346 | - |
4347 | -#include <QObject> |
4348 | -#include <QFile> |
4349 | -#include <QCryptographicHash> |
4350 | -#include "file.h" |
4351 | -#include "types/inputmedia.h" |
4352 | - |
4353 | -class UploadFile : public File |
4354 | -{ |
4355 | - Q_OBJECT |
4356 | -public: |
4357 | - |
4358 | - enum FileType { |
4359 | - file, |
4360 | - thumbnail |
4361 | - }; |
4362 | - |
4363 | - explicit UploadFile(Session *session, FileType type, const QByteArray &buffer, QObject *parent = 0); |
4364 | - explicit UploadFile(Session *session, FileType type, const QString &filePath, QObject *parent = 0); |
4365 | - ~UploadFile(); |
4366 | - |
4367 | - qint64 relatedFileId() const { return m_relatedFileId; } |
4368 | - void setRelatedFileId(qint64 relatedFileId) { m_relatedFileId = relatedFileId; } |
4369 | - QString name() const { return m_name; } |
4370 | - void setName(const QString &name) { m_name = name; } |
4371 | - FileType fileType() const { return m_fileType; } |
4372 | - qint32 nParts() const { return m_nParts; } |
4373 | - qint32 uploadedParts() const { return m_uploadedParts; } |
4374 | - |
4375 | - bool hasMoreParts() const; |
4376 | - QByteArray nextPart(); |
4377 | - void increaseUploadedParts(); |
4378 | - QByteArray md5(); |
4379 | - |
4380 | -Q_SIGNALS: |
4381 | - void fileNotFound(); |
4382 | - void fileNotOpen(); |
4383 | - |
4384 | -private: |
4385 | - FileType m_fileType; |
4386 | - qint64 m_relatedFileId; // if this is the main file, related file is thumbnail and viceversa |
4387 | - QString m_name; |
4388 | - QByteArray m_bytes; |
4389 | - QString m_filePath; |
4390 | - qint32 m_nParts; |
4391 | - qint32 m_currentPart; |
4392 | - qint32 m_uploadedParts; |
4393 | - QFile m_ioDevice; |
4394 | - QCryptographicHash m_krypt; |
4395 | - |
4396 | - void openIODevice(); |
4397 | -}; |
4398 | - |
4399 | -#endif // UPLOADFILE_H |
4400 | |
4401 | === modified file 'lib/secret/CMakeLists.txt' |
4402 | --- lib/secret/CMakeLists.txt 2014-11-17 15:27:33 +0000 |
4403 | +++ lib/secret/CMakeLists.txt 2015-02-24 14:12:31 +0000 |
4404 | @@ -1,7 +1,9 @@ |
4405 | set(SECRET_HEADERS |
4406 | + decryptedmessagebuilder.h |
4407 | decrypter.h |
4408 | encrypter.h |
4409 | secretstate.h |
4410 | + secretchatmessage.h |
4411 | secretchat.h) |
4412 | |
4413 | if(NOT CLICK_MODE) |
4414 | |
4415 | === modified file 'lib/secret/decryptedmessagebuilder.cpp' |
4416 | --- lib/secret/decryptedmessagebuilder.cpp 2015-02-06 10:19:34 +0000 |
4417 | +++ lib/secret/decryptedmessagebuilder.cpp 2015-02-24 14:12:31 +0000 |
4418 | @@ -1,5 +1,5 @@ |
4419 | #include "decryptedmessagebuilder.h" |
4420 | -#include "core/utils.h" |
4421 | +#include "util/utils.h" |
4422 | |
4423 | DecryptedMessageBuilder::DecryptedMessageBuilder(qint32 layer) : mLayer(layer) { |
4424 | } |
4425 | |
4426 | === modified file 'lib/secret/decrypter.cpp' |
4427 | --- lib/secret/decrypter.cpp 2015-02-11 18:35:01 +0000 |
4428 | +++ lib/secret/decrypter.cpp 2015-02-24 14:12:31 +0000 |
4429 | @@ -16,12 +16,14 @@ |
4430 | */ |
4431 | |
4432 | #include "decrypter.h" |
4433 | -#include "core/constants.h" |
4434 | -#include "core/tlvalues.h" |
4435 | +#include "util/constants.h" |
4436 | +#include "util/tlvalues.h" |
4437 | #include "core/settings.h" |
4438 | #include <openssl/sha.h> |
4439 | #include <openssl/aes.h> |
4440 | |
4441 | +Q_LOGGING_CATEGORY(TG_SECRET_DECRYPTER, "tg.secret.decrypter") |
4442 | + |
4443 | template <typename T_> |
4444 | void do_delete(T_ buf[]) { |
4445 | delete[] buf; |
4446 | @@ -30,11 +32,11 @@ |
4447 | Decrypter::Decrypter() : |
4448 | InboundPkt(0, 0), |
4449 | mSecretChat(0) { |
4450 | - __buffer = QSharedPointer<char>(new char[PACKET_BUFFER_SIZE], do_delete<char>); |
4451 | + mBufferPtr = QSharedPointer<char>(new char[PACKET_BUFFER_SIZE], do_delete<char>); |
4452 | } |
4453 | |
4454 | Decrypter::~Decrypter() { |
4455 | - __buffer.clear(); |
4456 | + mBufferPtr.clear(); |
4457 | } |
4458 | |
4459 | void Decrypter::setSecretChat(SecretChat *secretChat) { |
4460 | @@ -49,11 +51,11 @@ |
4461 | return DecryptedMessage(); |
4462 | } |
4463 | |
4464 | - m_buffer = __buffer.data(); |
4465 | + m_buffer = mBufferPtr.data(); |
4466 | memcpy(m_buffer, bytes.data(), m_length); |
4467 | |
4468 | if (!(m_length & 15) == 8) { |
4469 | - qCWarning(TG_LIB_SECRET) << "Received packet doesn't satisfy length rule (!(length & 0xF) == 1000)"; |
4470 | + qCWarning(TG_SECRET_DECRYPTER) << "Received packet doesn't satisfy length rule (!(length & 0xF) == 1000)"; |
4471 | return DecryptedMessage(); |
4472 | } |
4473 | |
4474 | @@ -66,7 +68,7 @@ |
4475 | qint32 receivedOutSeqNoParam = -1; |
4476 | // message must be read completly regardless it belongs to a valid secret chat |
4477 | if (!mSecretChat) { |
4478 | - qCDebug(TG_LIB_SECRET) << "Received messsage to unknown chat. Dropping"; |
4479 | + qCDebug(TG_SECRET_DECRYPTER) << "Received messsage to unknown chat. Dropping"; |
4480 | processMessage = false; |
4481 | } else { |
4482 | processMessage = checkKeyFingerprints(); |
4483 | @@ -89,14 +91,14 @@ |
4484 | |
4485 | qint32 receivedInSeqNoParam = fetchInt(); |
4486 | receivedOutSeqNoParam = fetchInt(); |
4487 | - qCDebug(TG_LIB_SECRET) << "Received in_seq_no=" << receivedInSeqNoParam << "(expected" << (mSecretChat->getOutSeqNoParam() - 2) << ")"; |
4488 | - qCDebug(TG_LIB_SECRET) << "Received out_seq_no=" << receivedOutSeqNoParam << "(expected" << mSecretChat->getInSeqNoParam() << ")"; |
4489 | + qCDebug(TG_SECRET_DECRYPTER) << "Received in_seq_no=" << receivedInSeqNoParam << "(expected" << (mSecretChat->getOutSeqNoParam() - 2) << ")"; |
4490 | + qCDebug(TG_SECRET_DECRYPTER) << "Received out_seq_no=" << receivedOutSeqNoParam << "(expected" << mSecretChat->getInSeqNoParam() << ")"; |
4491 | |
4492 | qint32 ourId = Settings::getInstance()->ourId(); |
4493 | |
4494 | if ((receivedOutSeqNoParam & 1) != 1 - (mSecretChat->adminId() == ourId) || |
4495 | (receivedInSeqNoParam & 1) != (mSecretChat->adminId() == ourId)) { |
4496 | - qCWarning(TG_LIB_SECRET) << "Bad message admin"; |
4497 | + qCWarning(TG_SECRET_DECRYPTER) << "Bad message admin"; |
4498 | processMessage = false; |
4499 | } |
4500 | |
4501 | @@ -105,11 +107,11 @@ |
4502 | |
4503 | if (deflatedOutSeqNo != mSecretChat->inSeqNo()) { |
4504 | if (deflatedOutSeqNo < mSecretChat->inSeqNo()) { |
4505 | - qCWarning(TG_LIB_SECRET) << "Received out_seq_no (" << deflatedOutSeqNo |
4506 | + qCWarning(TG_SECRET_DECRYPTER) << "Received out_seq_no (" << deflatedOutSeqNo |
4507 | << ") is lower than expected (" << mSecretChat->inSeqNo() << ")"; |
4508 | processMessage = false; |
4509 | } else if (deflatedOutSeqNo > mSecretChat->inSeqNo()) { |
4510 | - qCWarning(TG_LIB_SECRET) << "Found gap since received out_seq_no (" << deflatedOutSeqNo |
4511 | + qCWarning(TG_SECRET_DECRYPTER) << "Found gap since received out_seq_no (" << deflatedOutSeqNo |
4512 | << ") is greater than expected (" << mSecretChat->inSeqNo() |
4513 | << "). Requesting intermediate messages to fill the gap"; |
4514 | processMessage = false; |
4515 | @@ -118,7 +120,7 @@ |
4516 | } |
4517 | } |
4518 | if (deflatedInSeqNo > mSecretChat->outSeqNo()) { |
4519 | - qCWarning(TG_LIB_SECRET) << "deflated received in_seq_no is bigger than our's out seq no sent in last message (out_seq_no =" |
4520 | + qCWarning(TG_SECRET_DECRYPTER) << "deflated received in_seq_no is bigger than our's out seq no sent in last message (out_seq_no =" |
4521 | << deflatedInSeqNo << ", our out_seq_no =" << mSecretChat->outSeqNo(); |
4522 | processMessage = false; |
4523 | } |
4524 | @@ -126,7 +128,7 @@ |
4525 | if (processMessage) { |
4526 | mSecretChat->setLayer(layer); |
4527 | mSecretChat->setInSeqNo(receivedOutSeqNoParam / 2 + 1); |
4528 | - qCDebug(TG_LIB_SECRET) << "Updating in_seq_no; Current values -> out_seq_no:" << mSecretChat->outSeqNo() |
4529 | + qCDebug(TG_SECRET_DECRYPTER) << "Updating in_seq_no; Current values -> out_seq_no:" << mSecretChat->outSeqNo() |
4530 | << ",in_seq_no:" << mSecretChat->inSeqNo(); |
4531 | } |
4532 | } |
4533 | @@ -147,7 +149,7 @@ |
4534 | switch (action.classType()) { |
4535 | case DecryptedMessageAction::typeDecryptedMessageActionNotifyLayer: { |
4536 | mSecretChat->setLayer(action.layer()); |
4537 | - qCDebug(TG_LIB_SECRET) << "Received layer" << action.layer() << "from peer"; |
4538 | + qCDebug(TG_SECRET_DECRYPTER) << "Received layer" << action.layer() << "from peer"; |
4539 | break; |
4540 | } |
4541 | default: |
4542 | @@ -155,7 +157,7 @@ |
4543 | //TODO Roberto: implement rest of cases |
4544 | } |
4545 | } else { |
4546 | - qCDebug(TG_LIB_SECRET) << "Received message"; |
4547 | + qCDebug(TG_SECRET_DECRYPTER) << "Received message"; |
4548 | } |
4549 | |
4550 | // append to secret chat sequence |
4551 | @@ -176,12 +178,12 @@ |
4552 | bool result = false; |
4553 | if (mSecretChat) { |
4554 | qint64 keyFingerprint = fetchLong(); |
4555 | - qCDebug(TG_LIB_SECRET) << "Received keyFingerprint" << keyFingerprint; |
4556 | - qCDebug(TG_LIB_SECRET) << "Stored keyFingerprint" << mSecretChat->keyFingerprint(); |
4557 | + qCDebug(TG_SECRET_DECRYPTER) << "Received keyFingerprint" << keyFingerprint; |
4558 | + qCDebug(TG_SECRET_DECRYPTER) << "Stored keyFingerprint" << mSecretChat->keyFingerprint(); |
4559 | if (keyFingerprint != mSecretChat->keyFingerprint()) { |
4560 | - qCWarning(TG_LIB_SECRET) << "Encrypted message with bad keyFingerprint for chat" << mSecretChat->chatId(); |
4561 | + qCWarning(TG_SECRET_DECRYPTER) << "Encrypted message with bad keyFingerprint for chat" << mSecretChat->chatId(); |
4562 | } else { |
4563 | - qCDebug(TG_LIB_SECRET) << "keyFingerprints matches!!"; |
4564 | + qCDebug(TG_SECRET_DECRYPTER) << "keyFingerprints matches!!"; |
4565 | result = true; |
4566 | } |
4567 | } |
4568 | @@ -236,21 +238,21 @@ |
4569 | |
4570 | qint32 x = prefetchInt(); |
4571 | if (x < 0 || (x & 3)) { |
4572 | - qCWarning(TG_LIB_SECRET) << "Not valid value for internal data length" << x; |
4573 | + qCWarning(TG_SECRET_DECRYPTER) << "Not valid value for internal data length" << x; |
4574 | return QByteArray(); |
4575 | } |
4576 | ASSERT(x >= 0 && !(x & 3)); |
4577 | SHA1((uchar *)m_inPtr, 4 + x, sha1a_buffer); |
4578 | |
4579 | if (memcmp(sha1a_buffer + 4, msgKey, 16)) { |
4580 | - qCWarning(TG_LIB_SECRET) << "SHA1 mismatch"; |
4581 | + qCWarning(TG_SECRET_DECRYPTER) << "SHA1 mismatch"; |
4582 | return QByteArray(); |
4583 | } |
4584 | - qCDebug(TG_LIB_SECRET) << "SHA1 checked and valid"; |
4585 | + qCDebug(TG_SECRET_DECRYPTER) << "SHA1 checked and valid"; |
4586 | |
4587 | qint32 plainDataLength = fetchInt(); |
4588 | m_inEnd = m_inPtr + plainDataLength; |
4589 | - qCDebug(TG_LIB_SECRET) << "decrypted data length" << plainDataLength; |
4590 | + qCDebug(TG_SECRET_DECRYPTER) << "decrypted data length" << plainDataLength; |
4591 | |
4592 | QByteArray plainData((char *)m_inPtr, plainDataLength); |
4593 | return plainData; |
4594 | |
4595 | === modified file 'lib/secret/decrypter.h' |
4596 | --- lib/secret/decrypter.h 2015-01-28 15:50:32 +0000 |
4597 | +++ lib/secret/decrypter.h 2015-02-24 14:12:31 +0000 |
4598 | @@ -26,7 +26,7 @@ |
4599 | #include <QSharedPointer> |
4600 | #include <QPair> |
4601 | |
4602 | -Q_DECLARE_LOGGING_CATEGORY(TG_LIB_SECRET) |
4603 | +Q_DECLARE_LOGGING_CATEGORY(TG_SECRET_DECRYPTER) |
4604 | |
4605 | class Decrypter : public QObject, public InboundPkt |
4606 | { |
4607 | @@ -44,7 +44,7 @@ |
4608 | |
4609 | protected: |
4610 | SecretChat *mSecretChat; |
4611 | - QSharedPointer<char> __buffer; |
4612 | + QSharedPointer<char> mBufferPtr; |
4613 | |
4614 | bool checkKeyFingerprints(); |
4615 | QByteArray decryptEncryptedMessage(); |
4616 | |
4617 | === modified file 'lib/secret/encrypter.cpp' |
4618 | --- lib/secret/encrypter.cpp 2015-01-30 08:20:13 +0000 |
4619 | +++ lib/secret/encrypter.cpp 2015-02-24 14:12:31 +0000 |
4620 | @@ -16,12 +16,13 @@ |
4621 | */ |
4622 | |
4623 | #include "encrypter.h" |
4624 | -#include "core/utils.h" |
4625 | +#include "util/utils.h" |
4626 | #include "openssl/sha.h" |
4627 | #include "openssl/aes.h" |
4628 | #include "decryptedmessagebuilder.h" |
4629 | +#include "util/tlvalues.h" |
4630 | |
4631 | -#include "core/tlvalues.h" |
4632 | +Q_LOGGING_CATEGORY(TG_SECRET_ENCRYPTER, "tg.secret.encrypter") |
4633 | |
4634 | Encrypter::Encrypter() : |
4635 | OutboundPkt(), |
4636 | @@ -32,7 +33,6 @@ |
4637 | mSecretChat(0) { |
4638 | } |
4639 | |
4640 | - |
4641 | void Encrypter::setSecretChat(SecretChat *secretChat) { |
4642 | mSecretChat = secretChat; |
4643 | } |
4644 | |
4645 | === modified file 'lib/secret/encrypter.h' |
4646 | --- lib/secret/encrypter.h 2015-01-30 08:20:13 +0000 |
4647 | +++ lib/secret/encrypter.h 2015-02-24 14:12:31 +0000 |
4648 | @@ -23,7 +23,7 @@ |
4649 | #include "secret/secretchat.h" |
4650 | #include <QLoggingCategory> |
4651 | |
4652 | -Q_DECLARE_LOGGING_CATEGORY(TG_LIB_SECRET) |
4653 | +Q_DECLARE_LOGGING_CATEGORY(TG_SECRET_ENCRYPTER) |
4654 | |
4655 | class Encrypter : public OutboundPkt |
4656 | { |
4657 | |
4658 | === modified file 'lib/secret/secretchat.cpp' |
4659 | --- lib/secret/secretchat.cpp 2015-02-04 15:46:54 +0000 |
4660 | +++ lib/secret/secretchat.cpp 2015-02-24 14:12:31 +0000 |
4661 | @@ -16,9 +16,11 @@ |
4662 | */ |
4663 | |
4664 | #include "secretchat.h" |
4665 | -#include "core/utils.h" |
4666 | +#include "util/utils.h" |
4667 | #include "core/settings.h" |
4668 | |
4669 | +Q_LOGGING_CATEGORY(TG_SECRET_SECRETCHAT, "tg.secret.secretchat") |
4670 | + |
4671 | SecretChat::SecretChat(QObject *parent) : |
4672 | QObject(parent), |
4673 | mState(Init), |
4674 | @@ -178,7 +180,7 @@ |
4675 | |
4676 | void SecretChat::increaseOutSeqNo() { |
4677 | mOutSeqNo++; |
4678 | - qCDebug(TG_LIB_SECRET) << "updated -> out_seq_no:" << mOutSeqNo << ",in_seq_no:" << mInSeqNo; |
4679 | + qCDebug(TG_SECRET_SECRETCHAT) << "updated -> out_seq_no:" << mOutSeqNo << ",in_seq_no:" << mInSeqNo; |
4680 | } |
4681 | |
4682 | void SecretChat::appendToSequence(qint64 msgId) { |
4683 | @@ -186,7 +188,7 @@ |
4684 | if (mSequence.size() > SEQUENCE_MAX_SIZE) { |
4685 | mSequence.removeFirst(); |
4686 | } |
4687 | - qCDebug(TG_LIB_SECRET) << "Current previous messages sequence:" << endl << mSequence; |
4688 | + qCDebug(TG_SECRET_SECRETCHAT) << "Current previous messages sequence:" << endl << mSequence; |
4689 | } |
4690 | |
4691 | QList<qint64> SecretChat::sequence() { |
4692 | |
4693 | === modified file 'lib/secret/secretchat.h' |
4694 | --- lib/secret/secretchat.h 2015-02-04 15:46:54 +0000 |
4695 | +++ lib/secret/secretchat.h 2015-02-24 14:12:31 +0000 |
4696 | @@ -31,9 +31,9 @@ |
4697 | #include "openssl/bn.h" |
4698 | #include "types/encryptedchat.h" |
4699 | #include "types/decryptedmessage.h" |
4700 | -#include "core/constants.h" |
4701 | +#include "util/constants.h" |
4702 | |
4703 | -Q_DECLARE_LOGGING_CATEGORY(TG_LIB_SECRET) |
4704 | +Q_DECLARE_LOGGING_CATEGORY(TG_SECRET_SECRETCHAT) |
4705 | |
4706 | class SecretChat : public QObject |
4707 | { |
4708 | |
4709 | === modified file 'lib/secret/secretstate.h' |
4710 | --- lib/secret/secretstate.h 2014-11-18 17:13:16 +0000 |
4711 | +++ lib/secret/secretstate.h 2015-02-24 14:12:31 +0000 |
4712 | @@ -21,7 +21,7 @@ |
4713 | #include <QObject> |
4714 | #include <QMap> |
4715 | #include <openssl/bn.h> |
4716 | -#include "core/utils.h" |
4717 | +#include "util/utils.h" |
4718 | #include "types/inputuser.h" |
4719 | #include "secretchat.h" |
4720 | |
4721 | |
4722 | === modified file 'lib/telegram.cpp' |
4723 | --- lib/telegram.cpp 2015-02-19 12:15:37 +0000 |
4724 | +++ lib/telegram.cpp 2015-02-24 14:12:31 +0000 |
4725 | @@ -35,9 +35,9 @@ |
4726 | #include <QtEndian> |
4727 | #include <QImage> |
4728 | |
4729 | -#include "core/tlvalues.h" |
4730 | +#include "util/tlvalues.h" |
4731 | |
4732 | -Q_LOGGING_CATEGORY(TG_LIB_API, "tg.lib.api") |
4733 | +Q_LOGGING_CATEGORY(TG_TELEGRAM, "tg.telegram") |
4734 | Q_LOGGING_CATEGORY(TG_LIB_SECRET, "tg.lib.secret") |
4735 | |
4736 | Telegram::Telegram(const QString &phoneNumber, const QString &configPath, const QString &publicKeyFile) : |
4737 | @@ -70,8 +70,8 @@ |
4738 | bool Telegram::sleep() { |
4739 | // sleep only if not slept and library already logged in. Returns true if sleep operations completes |
4740 | if (!mSlept && mLibraryState >= LoggedIn) { |
4741 | - if (m_api && m_api->mainSession()) { |
4742 | - m_api->mainSession()->close(); |
4743 | + if (mApi && mApi->mainSession()) { |
4744 | + mApi->mainSession()->close(); |
4745 | } |
4746 | mSlept = true; |
4747 | return true; |
4748 | @@ -82,9 +82,9 @@ |
4749 | bool Telegram::wake() { |
4750 | // wake only if slept and library already logged in. Returns true if wake operation completes |
4751 | if (mSlept && mLibraryState >= LoggedIn) { |
4752 | - connect(m_api, SIGNAL(mainSessionReady()), this, SIGNAL(woken()), Qt::UniqueConnection); |
4753 | + connect(mApi, SIGNAL(mainSessionReady()), this, SIGNAL(woken()), Qt::UniqueConnection); |
4754 | DC *dc = mDcProvider.getWorkingDc(); |
4755 | - m_api->createMainSessionToDc(dc); |
4756 | + mApi->createMainSessionToDc(dc); |
4757 | mSlept = false; |
4758 | return true; |
4759 | } |
4760 | @@ -105,21 +105,11 @@ |
4761 | } |
4762 | |
4763 | Telegram::~Telegram() { |
4764 | - // delete any remainig download files, upload files or operations |
4765 | - Q_FOREACH (UploadFile *f, mUploadsMap) { |
4766 | - if (f) delete f; |
4767 | - } |
4768 | - Q_FOREACH (const FileOperation *op, mFileOperationsMap) { |
4769 | - if (op) delete op; |
4770 | - } |
4771 | - Q_FOREACH (const DownloadFile *f, mDownloadsMap) { |
4772 | - if (f) delete f; |
4773 | - } |
4774 | } |
4775 | |
4776 | bool Telegram::isConnected() { |
4777 | - if (m_api && m_api->mainSession()) { |
4778 | - return m_api->mainSession()->state() == QAbstractSocket::ConnectedState; |
4779 | + if (mApi && mApi->mainSession()) { |
4780 | + return mApi->mainSession()->state() == QAbstractSocket::ConnectedState; |
4781 | } |
4782 | return false; |
4783 | } |
4784 | @@ -145,132 +135,132 @@ |
4785 | |
4786 | void Telegram::onDcProviderReady() { |
4787 | mLibraryState = CreatedSharedKeys; |
4788 | - m_api = mDcProvider.getApi(); |
4789 | + mApi = mDcProvider.getApi(); |
4790 | // api signal-signal and signal-slot connections |
4791 | // updates |
4792 | - connect(m_api, SIGNAL(updatesTooLong()), this, SIGNAL(updatesTooLong())); |
4793 | - connect(m_api, SIGNAL(updateShortMessage(qint32,qint32,QString,qint32,qint32,qint32)), this, SIGNAL(updateShortMessage(qint32,qint32,QString,qint32,qint32,qint32))); |
4794 | - connect(m_api, SIGNAL(updateShortChatMessage(qint32,qint32,qint32,QString,qint32,qint32,qint32)), this, SIGNAL(updateShortChatMessage(qint32,qint32,qint32,QString,qint32,qint32,qint32))); |
4795 | - connect(m_api, SIGNAL(updateShort(Update,qint32)), this, SIGNAL(updateShort(Update,qint32))); |
4796 | - connect(m_api, SIGNAL(updatesCombined(QList<Update>,QList<User>,QList<Chat>,qint32,qint32,qint32)), this, SIGNAL(updatesCombined(QList<Update>,QList<User>,QList<Chat>,qint32,qint32,qint32))); |
4797 | - connect(m_api, SIGNAL(updates(QList<Update>,QList<User>,QList<Chat>,qint32,qint32)), this, SIGNAL(updates(QList<Update>,QList<User>,QList<Chat>,qint32,qint32))); |
4798 | + connect(mApi, SIGNAL(updatesTooLong()), this, SIGNAL(updatesTooLong())); |
4799 | + connect(mApi, SIGNAL(updateShortMessage(qint32,qint32,QString,qint32,qint32,qint32)), this, SIGNAL(updateShortMessage(qint32,qint32,QString,qint32,qint32,qint32))); |
4800 | + connect(mApi, SIGNAL(updateShortChatMessage(qint32,qint32,qint32,QString,qint32,qint32,qint32)), this, SIGNAL(updateShortChatMessage(qint32,qint32,qint32,QString,qint32,qint32,qint32))); |
4801 | + connect(mApi, SIGNAL(updateShort(Update,qint32)), this, SIGNAL(updateShort(Update,qint32))); |
4802 | + connect(mApi, SIGNAL(updatesCombined(QList<Update>,QList<User>,QList<Chat>,qint32,qint32,qint32)), this, SIGNAL(updatesCombined(QList<Update>,QList<User>,QList<Chat>,qint32,qint32,qint32))); |
4803 | + connect(mApi, SIGNAL(updates(QList<Update>,QList<User>,QList<Chat>,qint32,qint32)), this, SIGNAL(updates(QList<Update>,QList<User>,QList<Chat>,qint32,qint32))); |
4804 | // errors |
4805 | - connect(m_api, SIGNAL(error(qint64,qint32,QString)), this, SLOT(onError(qint64,qint32,QString))); |
4806 | - connect(m_api, SIGNAL(errorRetry(qint64,qint32,QString)), this, SLOT(onErrorRetry(qint64,qint32,QString))); |
4807 | - connect(m_api, SIGNAL(authSignInError(qint64,qint32,QString)), this, SIGNAL(authSignInError(qint64,qint32,QString))); |
4808 | - connect(m_api, SIGNAL(authSignUpError(qint64,qint32,QString)), this, SIGNAL(authSignUpError(qint64,qint32,QString))); |
4809 | - connect(m_api, SIGNAL(uploadFileError(qint64,qint32,QString)), this, SLOT(onUploadGetFileError(qint64,qint32,QString))); |
4810 | + connect(mApi, SIGNAL(error(qint64,qint32,QString)), this, SLOT(onError(qint64,qint32,QString))); |
4811 | + connect(mApi, SIGNAL(errorRetry(qint64,qint32,QString)), this, SLOT(onErrorRetry(qint64,qint32,QString))); |
4812 | + connect(mApi, SIGNAL(authSignInError(qint64,qint32,QString)), this, SIGNAL(authSignInError(qint64,qint32,QString))); |
4813 | + connect(mApi, SIGNAL(authSignUpError(qint64,qint32,QString)), this, SIGNAL(authSignUpError(qint64,qint32,QString))); |
4814 | // positive responses |
4815 | - connect(m_api, SIGNAL(helpGetInviteTextAnswer(qint64,QString)), this, SIGNAL(helpGetInviteTextAnswer(qint64,QString))); |
4816 | - connect(m_api, SIGNAL(authCheckedPhone(qint64,bool,bool)), this, SIGNAL(authCheckPhoneAnswer(qint64,bool,bool))); |
4817 | - connect(m_api, SIGNAL(authCheckPhoneSent(qint64,QString)), this, SIGNAL(authCheckPhoneSent(qint64,QString))); |
4818 | - connect(m_api, SIGNAL(authSentCode(qint64,bool,QString,qint32,bool)), this, SLOT(onAuthSentCode(qint64,bool,QString,qint32,bool))); |
4819 | - connect(m_api, SIGNAL(authSentAppCode(qint64,bool,QString,qint32,bool)), this, SLOT(onAuthSentCode(qint64,bool,QString,qint32,bool))); |
4820 | - connect(m_api, SIGNAL(authSendSmsResult(qint64,bool)), this, SIGNAL(authSendSmsAnswer(qint64,bool))); |
4821 | - connect(m_api, SIGNAL(authSendCallResult(qint64,bool)), this, SIGNAL(authSendCallAnswer(qint64,bool))); |
4822 | - connect(m_api, SIGNAL(authSignInAuthorization(qint64,qint32,User)), this, SLOT(onUserAuthorized(qint64,qint32,User))); |
4823 | - connect(m_api, SIGNAL(authSignUpAuthorization(qint64,qint32,User)), this, SLOT(onUserAuthorized(qint64,qint32,User))); |
4824 | - connect(m_api, SIGNAL(authLogOutResult(qint64,bool)), this, SLOT(onAuthLogOutAnswer(qint64,bool))); |
4825 | - connect(m_api, SIGNAL(authSendInvitesResult(qint64,bool)), this, SIGNAL(authSendInvitesAnswer(qint64,bool))); |
4826 | - connect(m_api, SIGNAL(authResetAuthorizationsResult(qint64,bool)), this, SIGNAL(authResetAuthorizationsAnswer(qint64,bool))); |
4827 | - connect(m_api, SIGNAL(accountRegisterDeviceResult(qint64,bool)), this, SIGNAL(accountRegisterDeviceAnswer(qint64,bool))); |
4828 | - connect(m_api, SIGNAL(accountUnregisterDeviceResult(qint64,bool)), this, SIGNAL(accountUnregisterDeviceAnswer(qint64,bool))); |
4829 | - connect(m_api, SIGNAL(accountUpdateNotifySettingsResult(qint64,bool)), this, SIGNAL(accountUpdateNotifySettingsAnswer(qint64,bool))); |
4830 | - connect(m_api, SIGNAL(accountPeerNotifySettings(qint64,PeerNotifySettings)), this, SIGNAL(accountGetNotifySettingsAnswer(qint64,PeerNotifySettings))); |
4831 | - connect(m_api, SIGNAL(accountResetNotifySettingsResult(qint64,bool)), this, SIGNAL(accountResetNotifySettingsAnswer(qint64,bool))); |
4832 | - connect(m_api, SIGNAL(accountUser(qint64,User)), this, SIGNAL(accountUpdateProfileAnswer(qint64,User))); |
4833 | - connect(m_api, SIGNAL(accountUpdateStatusResult(qint64,bool)), this, SIGNAL(accountUpdateStatusAnswer(qint64,bool))); |
4834 | - connect(m_api, SIGNAL(accountGetWallPapersResult(qint64,QList<WallPaper>)), this, SIGNAL(accountGetWallPapersAnswer(qint64,QList<WallPaper>))); |
4835 | - connect(m_api, SIGNAL(photosPhoto(qint64,Photo,QList<User>)), this, SIGNAL(photosUploadProfilePhotoAnswer(qint64,Photo,QList<User>))); |
4836 | - connect(m_api, SIGNAL(photosUserProfilePhoto(qint64,UserProfilePhoto)), this, SIGNAL(photosUpdateProfilePhotoAnswer(qint64,UserProfilePhoto))); |
4837 | - connect(m_api, SIGNAL(usersGetUsersResult(qint64,QList<User>)), this, SIGNAL(usersGetUsersAnswer(qint64,QList<User>))); |
4838 | - connect(m_api, SIGNAL(userFull(qint64,User,ContactsLink,Photo,PeerNotifySettings,bool,QString,QString)), this, SIGNAL(usersGetFullUserAnswer(qint64,User,ContactsLink,Photo,PeerNotifySettings,bool,QString,QString))); |
4839 | - connect(m_api, SIGNAL(photosPhotos(qint64,QList<Photo>,QList<User>)), this, SLOT(onPhotosPhotos(qint64, QList<Photo>, QList<User>))); |
4840 | - connect(m_api, SIGNAL(photosPhotosSlice(qint64,qint32,QList<Photo>,QList<User>)), this, SIGNAL(photosGetUserPhotosAnswer(qint64,qint32,QList<Photo>,QList<User>))); |
4841 | - connect(m_api, SIGNAL(contactsGetStatusesResult(qint64,QList<ContactStatus>)), this, SIGNAL(contactsGetStatusesAnswer(qint64,QList<ContactStatus>))); |
4842 | - connect(m_api, SIGNAL(contactsContacts(qint64,QList<Contact>,QList<User>)), this, SLOT(onContactsContacts(qint64,QList<Contact>,QList<User>))); |
4843 | - connect(m_api, SIGNAL(contactsContactsNotModified(qint64)), this, SLOT(onContactsContactsNotModified(qint64))); |
4844 | - connect(m_api, SIGNAL(contactsImportedContacts(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)), this, SIGNAL(contactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>))); |
4845 | - connect(m_api, SIGNAL(contactsImportedContacts(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)), this, SLOT(onContactsImportContactsAnswer())); |
4846 | - connect(m_api, SIGNAL(contactsDeleteContactLink(qint64,ContactsMyLink,ContactsForeignLink,User)), this, SIGNAL(contactsDeleteContactAnswer(qint64,ContactsMyLink,ContactsForeignLink,User))); |
4847 | - connect(m_api, SIGNAL(contactsDeleteContactsResult(qint64,bool)), this, SIGNAL(contactsDeleteContactsAnswer(qint64,bool))); |
4848 | - connect(m_api, SIGNAL(contactsBlockResult(qint64,bool)), this, SIGNAL(contactsBlockAnswer(qint64,bool))); |
4849 | - connect(m_api, SIGNAL(contactsUnblockResult(qint64,bool)), this, SIGNAL(contactsUnblockAnswer(qint64,bool))); |
4850 | - connect(m_api, SIGNAL(contactsBlocked(qint64,QList<ContactBlocked>,QList<User>)), this, SLOT(onContactsBlocked(qint64,QList<ContactBlocked>,QList<User>))); |
4851 | - connect(m_api, SIGNAL(contactsBlockedSlice(qint64,qint32,QList<ContactBlocked>,QList<User>)), this, SIGNAL(contactsGetBlockedAnswer(qint64,qint32,QList<ContactBlocked>,QList<User>))); |
4852 | - connect(m_api, SIGNAL(messagesSentMessage(qint64,qint32,qint32,qint32,qint32)), this, SLOT(onMessagesSentMessage(qint64,qint32,qint32,qint32,qint32))); |
4853 | - connect(m_api, SIGNAL(messagesSentMessageLink(qint64,qint32,qint32,qint32,qint32,QList<ContactsLink>)), this, SIGNAL(messagesSendMessageAnswer(qint64,qint32,qint32,qint32,qint32,QList<ContactsLink>))); |
4854 | - connect(m_api, SIGNAL(messagesSentMediaStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesSendMediaStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32))); |
4855 | - connect(m_api, SIGNAL(messagesSentMediaStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SLOT(onMessagesSendMediaStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4856 | - connect(m_api, SIGNAL(messagesSetTypingResult(qint64,bool)), this, SIGNAL(messagesSetTypingAnswer(qint64,bool))); |
4857 | - connect(m_api, SIGNAL(messagesGetMessagesMessages(qint64,QList<Message>,QList<Chat>,QList<User>)), this, SLOT(onMessagesGetMessagesMessages(qint64,QList<Message>,QList<Chat>,QList<User>))); |
4858 | - connect(m_api, SIGNAL(messagesGetMessagesMessagesSlice(qint64,qint32,QList<Message>,QList<Chat>,QList<User>)), this, SIGNAL(messagesGetMessagesAnswer(qint64,qint32,QList<Message>,QList<Chat>,QList<User>))); |
4859 | - connect(m_api, SIGNAL(messagesDialogs(qint64, QList<Dialog>,QList<Message>,QList<Chat>,QList<User>)), this, SLOT(onMessagesDialogs(qint64,QList<Dialog>,QList<Message>,QList<Chat>,QList<User>))); |
4860 | - connect(m_api, SIGNAL(messagesDialogsSlice(qint64,qint32,QList<Dialog>,QList<Message>,QList<Chat>,QList<User>)), this, SIGNAL(messagesGetDialogsAnswer(qint64,qint32,QList<Dialog>,QList<Message>,QList<Chat>,QList<User>))); |
4861 | - connect(m_api, SIGNAL(messagesGetHistoryMessages(qint64,QList<Message>,QList<Chat>,QList<User>)), this, SLOT(onMessagesGetHistoryMessages(qint64,QList<Message>,QList<Chat>,QList<User>))); |
4862 | - connect(m_api, SIGNAL(messagesGetHistoryMessagesSlice(qint64,qint32,QList<Message>,QList<Chat>,QList<User>)), this, SIGNAL(messagesGetHistoryAnswer(qint64,qint32,QList<Message>,QList<Chat>,QList<User>))); |
4863 | - connect(m_api, SIGNAL(messagesSearchMessages(qint64,QList<Message>,QList<Chat>,QList<User>)), this, SLOT(onMessagesSearchMessages(qint64,QList<Message>,QList<Chat>,QList<User>))); |
4864 | - connect(m_api, SIGNAL(messagesSearchMessagesSlice(qint64,qint32,QList<Message>,QList<Chat>,QList<User>)), this, SIGNAL(messagesSearchAnswer(qint64,qint32,QList<Message>,QList<Chat>,QList<User>))); |
4865 | - connect(m_api, SIGNAL(messagesReadAffectedHistory(qint64,qint32,qint32,qint32)), this, SIGNAL(messagesReadHistoryAnswer(qint64,qint32,qint32,qint32))); |
4866 | - connect(m_api, SIGNAL(messagesReadMessageContentsResult(qint64,QList<qint32>)), this, SIGNAL(messagesReadMessageContentsAnswer(qint64,QList<qint32>))); |
4867 | - connect(m_api, SIGNAL(messagesDeleteAffectedHistory(qint64,qint32,qint32,qint32)), this, SIGNAL(messagesDeleteHistoryAnswer(qint64,qint32,qint32,qint32))); |
4868 | - connect(m_api, SIGNAL(messagesDeleteMessagesResult(qint64,QList<qint32>)), this, SIGNAL(messagesDeleteMessagesAnswer(qint64,QList<qint32>))); |
4869 | - connect(m_api, SIGNAL(messagesRestoreMessagesResult(qint64,QList<qint32>)), this, SIGNAL(messagesRestoreMessagesAnswer(qint64,QList<qint32>))); |
4870 | - connect(m_api, SIGNAL(messagesReceivedMessagesResult(qint64,QList<qint32>)), this, SIGNAL(messagesReceivedMessagesAnswer(qint64,QList<qint32>))); |
4871 | - connect(m_api, SIGNAL(messagesForwardMsgStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesForwardMsgStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32))); |
4872 | - connect(m_api, SIGNAL(messagesForwardMsgStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesForwardMessageAnswer(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4873 | - connect(m_api, SIGNAL(messagesForwardMsgsStatedMessages(qint64,QList<Message>,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesForwardMsgsStatedMessages(qint64,QList<Message>,QList<Chat>,QList<User>,qint32,qint32))); |
4874 | - connect(m_api, SIGNAL(messagesForwardMsgsStatedMessagesLinks(qint64,QList<Message>,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesForwardMessagesAnswer(qint64,QList<Message>,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4875 | - connect(m_api, SIGNAL(messagesSendBroadcastStatedMessages(qint64,QList<Message>,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesSendBroadcastStatedMessages(qint64,QList<Message>,QList<Chat>,QList<User>,qint32,qint32))); |
4876 | - connect(m_api, SIGNAL(messagesSendBroadcastStatedMessagesLinks(qint64,QList<Message>,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesSendBroadcastAnswer(qint64,QList<Message>,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4877 | - connect(m_api, SIGNAL(messagesChats(qint64,QList<Chat>,QList<User>)), this, SIGNAL(messagesGetChatsAnswer(qint64,QList<Chat>,QList<User>))); |
4878 | - connect(m_api, SIGNAL(messagesChatFull(qint64,ChatFull,QList<Chat>,QList<User>)), |
4879 | + connect(mApi, SIGNAL(helpGetInviteTextAnswer(qint64,QString)), this, SIGNAL(helpGetInviteTextAnswer(qint64,QString))); |
4880 | + connect(mApi, SIGNAL(authCheckedPhone(qint64,bool,bool)), this, SIGNAL(authCheckPhoneAnswer(qint64,bool,bool))); |
4881 | + connect(mApi, SIGNAL(authCheckPhoneSent(qint64,QString)), this, SIGNAL(authCheckPhoneSent(qint64,QString))); |
4882 | + connect(mApi, SIGNAL(authSentCode(qint64,bool,QString,qint32,bool)), this, SLOT(onAuthSentCode(qint64,bool,QString,qint32,bool))); |
4883 | + connect(mApi, SIGNAL(authSentAppCode(qint64,bool,QString,qint32,bool)), this, SLOT(onAuthSentCode(qint64,bool,QString,qint32,bool))); |
4884 | + connect(mApi, SIGNAL(authSendSmsResult(qint64,bool)), this, SIGNAL(authSendSmsAnswer(qint64,bool))); |
4885 | + connect(mApi, SIGNAL(authSendCallResult(qint64,bool)), this, SIGNAL(authSendCallAnswer(qint64,bool))); |
4886 | + connect(mApi, SIGNAL(authSignInAuthorization(qint64,qint32,User)), this, SLOT(onUserAuthorized(qint64,qint32,User))); |
4887 | + connect(mApi, SIGNAL(authSignUpAuthorization(qint64,qint32,User)), this, SLOT(onUserAuthorized(qint64,qint32,User))); |
4888 | + connect(mApi, SIGNAL(authLogOutResult(qint64,bool)), this, SLOT(onAuthLogOutAnswer(qint64,bool))); |
4889 | + connect(mApi, SIGNAL(authSendInvitesResult(qint64,bool)), this, SIGNAL(authSendInvitesAnswer(qint64,bool))); |
4890 | + connect(mApi, SIGNAL(authResetAuthorizationsResult(qint64,bool)), this, SIGNAL(authResetAuthorizationsAnswer(qint64,bool))); |
4891 | + connect(mApi, SIGNAL(accountRegisterDeviceResult(qint64,bool)), this, SIGNAL(accountRegisterDeviceAnswer(qint64,bool))); |
4892 | + connect(mApi, SIGNAL(accountUnregisterDeviceResult(qint64,bool)), this, SIGNAL(accountUnregisterDeviceAnswer(qint64,bool))); |
4893 | + connect(mApi, SIGNAL(accountUpdateNotifySettingsResult(qint64,bool)), this, SIGNAL(accountUpdateNotifySettingsAnswer(qint64,bool))); |
4894 | + connect(mApi, SIGNAL(accountPeerNotifySettings(qint64,PeerNotifySettings)), this, SIGNAL(accountGetNotifySettingsAnswer(qint64,PeerNotifySettings))); |
4895 | + connect(mApi, SIGNAL(accountResetNotifySettingsResult(qint64,bool)), this, SIGNAL(accountResetNotifySettingsAnswer(qint64,bool))); |
4896 | + connect(mApi, SIGNAL(accountUser(qint64,User)), this, SIGNAL(accountUpdateProfileAnswer(qint64,User))); |
4897 | + connect(mApi, SIGNAL(accountUpdateStatusResult(qint64,bool)), this, SIGNAL(accountUpdateStatusAnswer(qint64,bool))); |
4898 | + connect(mApi, SIGNAL(accountGetWallPapersResult(qint64,QList<WallPaper>)), this, SIGNAL(accountGetWallPapersAnswer(qint64,QList<WallPaper>))); |
4899 | + connect(mApi, SIGNAL(photosPhoto(qint64,Photo,QList<User>)), this, SIGNAL(photosUploadProfilePhotoAnswer(qint64,Photo,QList<User>))); |
4900 | + connect(mApi, SIGNAL(photosUserProfilePhoto(qint64,UserProfilePhoto)), this, SIGNAL(photosUpdateProfilePhotoAnswer(qint64,UserProfilePhoto))); |
4901 | + connect(mApi, SIGNAL(usersGetUsersResult(qint64,QList<User>)), this, SIGNAL(usersGetUsersAnswer(qint64,QList<User>))); |
4902 | + connect(mApi, SIGNAL(userFull(qint64,User,ContactsLink,Photo,PeerNotifySettings,bool,QString,QString)), this, SIGNAL(usersGetFullUserAnswer(qint64,User,ContactsLink,Photo,PeerNotifySettings,bool,QString,QString))); |
4903 | + connect(mApi, SIGNAL(photosPhotos(qint64,QList<Photo>,QList<User>)), this, SLOT(onPhotosPhotos(qint64, QList<Photo>, QList<User>))); |
4904 | + connect(mApi, SIGNAL(photosPhotosSlice(qint64,qint32,QList<Photo>,QList<User>)), this, SIGNAL(photosGetUserPhotosAnswer(qint64,qint32,QList<Photo>,QList<User>))); |
4905 | + connect(mApi, SIGNAL(contactsGetStatusesResult(qint64,QList<ContactStatus>)), this, SIGNAL(contactsGetStatusesAnswer(qint64,QList<ContactStatus>))); |
4906 | + connect(mApi, SIGNAL(contactsContacts(qint64,QList<Contact>,QList<User>)), this, SLOT(onContactsContacts(qint64,QList<Contact>,QList<User>))); |
4907 | + connect(mApi, SIGNAL(contactsContactsNotModified(qint64)), this, SLOT(onContactsContactsNotModified(qint64))); |
4908 | + connect(mApi, SIGNAL(contactsImportedContacts(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)), this, SIGNAL(contactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>))); |
4909 | + connect(mApi, SIGNAL(contactsImportedContacts(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)), this, SLOT(onContactsImportContactsAnswer())); |
4910 | + connect(mApi, SIGNAL(contactsDeleteContactLink(qint64,ContactsMyLink,ContactsForeignLink,User)), this, SIGNAL(contactsDeleteContactAnswer(qint64,ContactsMyLink,ContactsForeignLink,User))); |
4911 | + connect(mApi, SIGNAL(contactsDeleteContactsResult(qint64,bool)), this, SIGNAL(contactsDeleteContactsAnswer(qint64,bool))); |
4912 | + connect(mApi, SIGNAL(contactsBlockResult(qint64,bool)), this, SIGNAL(contactsBlockAnswer(qint64,bool))); |
4913 | + connect(mApi, SIGNAL(contactsUnblockResult(qint64,bool)), this, SIGNAL(contactsUnblockAnswer(qint64,bool))); |
4914 | + connect(mApi, SIGNAL(contactsBlocked(qint64,QList<ContactBlocked>,QList<User>)), this, SLOT(onContactsBlocked(qint64,QList<ContactBlocked>,QList<User>))); |
4915 | + connect(mApi, SIGNAL(contactsBlockedSlice(qint64,qint32,QList<ContactBlocked>,QList<User>)), this, SIGNAL(contactsGetBlockedAnswer(qint64,qint32,QList<ContactBlocked>,QList<User>))); |
4916 | + connect(mApi, SIGNAL(messagesSentMessage(qint64,qint32,qint32,qint32,qint32)), this, SLOT(onMessagesSentMessage(qint64,qint32,qint32,qint32,qint32))); |
4917 | + connect(mApi, SIGNAL(messagesSentMessageLink(qint64,qint32,qint32,qint32,qint32,QList<ContactsLink>)), this, SIGNAL(messagesSendMessageAnswer(qint64,qint32,qint32,qint32,qint32,QList<ContactsLink>))); |
4918 | + connect(mApi, SIGNAL(messagesSetTypingResult(qint64,bool)), this, SIGNAL(messagesSetTypingAnswer(qint64,bool))); |
4919 | + connect(mApi, SIGNAL(messagesGetMessagesMessages(qint64,QList<Message>,QList<Chat>,QList<User>)), this, SLOT(onMessagesGetMessagesMessages(qint64,QList<Message>,QList<Chat>,QList<User>))); |
4920 | + connect(mApi, SIGNAL(messagesGetMessagesMessagesSlice(qint64,qint32,QList<Message>,QList<Chat>,QList<User>)), this, SIGNAL(messagesGetMessagesAnswer(qint64,qint32,QList<Message>,QList<Chat>,QList<User>))); |
4921 | + connect(mApi, SIGNAL(messagesDialogs(qint64, QList<Dialog>,QList<Message>,QList<Chat>,QList<User>)), this, SLOT(onMessagesDialogs(qint64,QList<Dialog>,QList<Message>,QList<Chat>,QList<User>))); |
4922 | + connect(mApi, SIGNAL(messagesDialogsSlice(qint64,qint32,QList<Dialog>,QList<Message>,QList<Chat>,QList<User>)), this, SIGNAL(messagesGetDialogsAnswer(qint64,qint32,QList<Dialog>,QList<Message>,QList<Chat>,QList<User>))); |
4923 | + connect(mApi, SIGNAL(messagesGetHistoryMessages(qint64,QList<Message>,QList<Chat>,QList<User>)), this, SLOT(onMessagesGetHistoryMessages(qint64,QList<Message>,QList<Chat>,QList<User>))); |
4924 | + connect(mApi, SIGNAL(messagesGetHistoryMessagesSlice(qint64,qint32,QList<Message>,QList<Chat>,QList<User>)), this, SIGNAL(messagesGetHistoryAnswer(qint64,qint32,QList<Message>,QList<Chat>,QList<User>))); |
4925 | + connect(mApi, SIGNAL(messagesSearchMessages(qint64,QList<Message>,QList<Chat>,QList<User>)), this, SLOT(onMessagesSearchMessages(qint64,QList<Message>,QList<Chat>,QList<User>))); |
4926 | + connect(mApi, SIGNAL(messagesSearchMessagesSlice(qint64,qint32,QList<Message>,QList<Chat>,QList<User>)), this, SIGNAL(messagesSearchAnswer(qint64,qint32,QList<Message>,QList<Chat>,QList<User>))); |
4927 | + connect(mApi, SIGNAL(messagesReadAffectedHistory(qint64,qint32,qint32,qint32)), this, SIGNAL(messagesReadHistoryAnswer(qint64,qint32,qint32,qint32))); |
4928 | + connect(mApi, SIGNAL(messagesReadMessageContentsResult(qint64,QList<qint32>)), this, SIGNAL(messagesReadMessageContentsAnswer(qint64,QList<qint32>))); |
4929 | + connect(mApi, SIGNAL(messagesDeleteAffectedHistory(qint64,qint32,qint32,qint32)), this, SIGNAL(messagesDeleteHistoryAnswer(qint64,qint32,qint32,qint32))); |
4930 | + connect(mApi, SIGNAL(messagesDeleteMessagesResult(qint64,QList<qint32>)), this, SIGNAL(messagesDeleteMessagesAnswer(qint64,QList<qint32>))); |
4931 | + connect(mApi, SIGNAL(messagesRestoreMessagesResult(qint64,QList<qint32>)), this, SIGNAL(messagesRestoreMessagesAnswer(qint64,QList<qint32>))); |
4932 | + connect(mApi, SIGNAL(messagesReceivedMessagesResult(qint64,QList<qint32>)), this, SIGNAL(messagesReceivedMessagesAnswer(qint64,QList<qint32>))); |
4933 | + connect(mApi, SIGNAL(messagesForwardMsgStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesForwardMsgStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32))); |
4934 | + connect(mApi, SIGNAL(messagesForwardMsgStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesForwardMessageAnswer(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4935 | + connect(mApi, SIGNAL(messagesForwardMsgsStatedMessages(qint64,QList<Message>,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesForwardMsgsStatedMessages(qint64,QList<Message>,QList<Chat>,QList<User>,qint32,qint32))); |
4936 | + connect(mApi, SIGNAL(messagesForwardMsgsStatedMessagesLinks(qint64,QList<Message>,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesForwardMessagesAnswer(qint64,QList<Message>,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4937 | + connect(mApi, SIGNAL(messagesSendBroadcastStatedMessages(qint64,QList<Message>,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesSendBroadcastStatedMessages(qint64,QList<Message>,QList<Chat>,QList<User>,qint32,qint32))); |
4938 | + connect(mApi, SIGNAL(messagesSendBroadcastStatedMessagesLinks(qint64,QList<Message>,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesSendBroadcastAnswer(qint64,QList<Message>,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4939 | + connect(mApi, SIGNAL(messagesChats(qint64,QList<Chat>,QList<User>)), this, SIGNAL(messagesGetChatsAnswer(qint64,QList<Chat>,QList<User>))); |
4940 | + connect(mApi, SIGNAL(messagesChatFull(qint64,ChatFull,QList<Chat>,QList<User>)), |
4941 | this, SIGNAL(messagesGetFullChatAnswer(qint64,ChatFull,QList<Chat>,QList<User>))); |
4942 | - connect(m_api, SIGNAL(messagesEditChatTitleStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesEditChatTitleStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32))); |
4943 | - connect(m_api, SIGNAL(messagesEditChatTitleStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesEditChatTitleAnswer(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4944 | - connect(m_api, SIGNAL(messagesEditChatPhotoStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesEditChatPhotoStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32))); |
4945 | - connect(m_api, SIGNAL(messagesEditChatPhotoStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesEditChatPhotoAnswer(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4946 | - connect(m_api, SIGNAL(messagesAddChatUserStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesAddChatUserStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32))); |
4947 | - connect(m_api, SIGNAL(messagesAddChatUserStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesAddChatUserAnswer(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4948 | - connect(m_api, SIGNAL(messagesDeleteChatUserStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesDeleteChatUserStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32))); |
4949 | - connect(m_api, SIGNAL(messagesDeleteChatUserStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesDeleteChatUserAnswer(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4950 | - connect(m_api, SIGNAL(messagesCreateChatStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesCreateChatStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32))); |
4951 | - connect(m_api, SIGNAL(messagesCreateChatStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesCreateChatAnswer(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4952 | + connect(mApi, SIGNAL(messagesEditChatTitleStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesEditChatTitleStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32))); |
4953 | + connect(mApi, SIGNAL(messagesEditChatTitleStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesEditChatTitleAnswer(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4954 | + connect(mApi, SIGNAL(messagesEditChatPhotoStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesEditChatPhotoStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32))); |
4955 | + connect(mApi, SIGNAL(messagesEditChatPhotoStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesEditChatPhotoAnswer(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4956 | + connect(mApi, SIGNAL(messagesAddChatUserStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesAddChatUserStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32))); |
4957 | + connect(mApi, SIGNAL(messagesAddChatUserStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesAddChatUserAnswer(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4958 | + connect(mApi, SIGNAL(messagesDeleteChatUserStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesDeleteChatUserStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32))); |
4959 | + connect(mApi, SIGNAL(messagesDeleteChatUserStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesDeleteChatUserAnswer(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4960 | + connect(mApi, SIGNAL(messagesCreateChatStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32)), this, SLOT(onMessagesCreateChatStatedMessage(qint64,Message,QList<Chat>,QList<User>,qint32,qint32))); |
4961 | + connect(mApi, SIGNAL(messagesCreateChatStatedMessageLink(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32)), this, SIGNAL(messagesCreateChatAnswer(qint64,Message,QList<Chat>,QList<User>,QList<ContactsLink>,qint32,qint32))); |
4962 | // secret chats |
4963 | - connect(m_api, SIGNAL(messagesDhConfig(qint64,qint32,QByteArray,qint32,QByteArray)), this, SLOT(onMessagesDhConfig(qint64,qint32,QByteArray,qint32,QByteArray))); |
4964 | - connect(m_api, SIGNAL(messagesDhConfigNotModified(qint64,QByteArray)), this, SLOT(onMessagesDhConfigNotModified(qint64,QByteArray))); |
4965 | - connect(m_api, SIGNAL(messagesRequestEncryptionEncryptedChat(qint64,EncryptedChat)), this, SLOT(onMessagesRequestEncryptionEncryptedChat(qint64,EncryptedChat))); |
4966 | - connect(m_api, SIGNAL(messagesAcceptEncryptionEncryptedChat(qint64,EncryptedChat)), this, SLOT(onMessagesAcceptEncryptionEncryptedChat(qint64,EncryptedChat))); |
4967 | - connect(m_api, SIGNAL(messagesDiscardEncryptionResult(qint64,bool)), this, SLOT(onMessagesDiscardEncryptionResult(qint64,bool))); |
4968 | - connect(m_api, SIGNAL(messagesReadEncryptedHistoryResult(qint64,bool)), this, SIGNAL(messagesReadEncryptedHistoryAnswer(qint64,bool))); |
4969 | - connect(m_api, SIGNAL(messagesSendEncryptedSentEncryptedMessage(qint64,qint32)), this, SIGNAL(messagesSendEncryptedAnswer(qint64,qint32))); |
4970 | - connect(m_api, SIGNAL(messagesSendEncryptedSentEncryptedFile(qint64,qint32,EncryptedFile)), this, SIGNAL(messagesSendEncryptedAnswer(qint64,qint32,EncryptedFile))); |
4971 | - connect(m_api, SIGNAL(messagesSendEncryptedFileSentEncryptedMessage(qint64,qint32)), this, SLOT(onMessagesSentEncryptedFile(qint64,qint32))); |
4972 | - connect(m_api, SIGNAL(messagesSendEncryptedFileSentEncryptedFile(qint64,qint32,EncryptedFile)), this, SLOT(onMessagesSentEncryptedFile(qint64,qint32,EncryptedFile))); |
4973 | - connect(m_api, SIGNAL(messagesSendEncryptedServiceSentEncryptedMessage(qint64,qint32)), this, SIGNAL(messagesSendEncryptedServiceAnswer(qint64,qint32))); |
4974 | - connect(m_api, SIGNAL(messagesSendEncryptedServiceSentEncryptedFile(qint64,qint32,EncryptedFile)), this, SIGNAL(messagesSendEncryptedServiceAnswer(qint64,qint32,EncryptedFile))); |
4975 | - connect(m_api, SIGNAL(updateShort(Update,qint32)), SLOT(onUpdateShort(Update))); |
4976 | - connect(m_api, SIGNAL(updatesCombined(QList<Update>,QList<User>,QList<Chat>,qint32,qint32,qint32)), SLOT(onUpdatesCombined(QList<Update>))); |
4977 | - connect(m_api, SIGNAL(updates(QList<Update>,QList<User>,QList<Chat>,qint32,qint32)), SLOT(onUpdates(QList<Update>))); |
4978 | + connect(mApi, SIGNAL(messagesDhConfig(qint64,qint32,QByteArray,qint32,QByteArray)), this, SLOT(onMessagesDhConfig(qint64,qint32,QByteArray,qint32,QByteArray))); |
4979 | + connect(mApi, SIGNAL(messagesDhConfigNotModified(qint64,QByteArray)), this, SLOT(onMessagesDhConfigNotModified(qint64,QByteArray))); |
4980 | + connect(mApi, SIGNAL(messagesRequestEncryptionEncryptedChat(qint64,EncryptedChat)), this, SLOT(onMessagesRequestEncryptionEncryptedChat(qint64,EncryptedChat))); |
4981 | + connect(mApi, SIGNAL(messagesAcceptEncryptionEncryptedChat(qint64,EncryptedChat)), this, SLOT(onMessagesAcceptEncryptionEncryptedChat(qint64,EncryptedChat))); |
4982 | + connect(mApi, SIGNAL(messagesDiscardEncryptionResult(qint64,bool)), this, SLOT(onMessagesDiscardEncryptionResult(qint64,bool))); |
4983 | + connect(mApi, SIGNAL(messagesReadEncryptedHistoryResult(qint64,bool)), this, SIGNAL(messagesReadEncryptedHistoryAnswer(qint64,bool))); |
4984 | + connect(mApi, SIGNAL(messagesSendEncryptedSentEncryptedMessage(qint64,qint32)), this, SIGNAL(messagesSendEncryptedAnswer(qint64,qint32))); |
4985 | + connect(mApi, SIGNAL(messagesSendEncryptedSentEncryptedFile(qint64,qint32,EncryptedFile)), this, SIGNAL(messagesSendEncryptedAnswer(qint64,qint32,EncryptedFile))); |
4986 | + connect(mApi, SIGNAL(messagesSendEncryptedServiceSentEncryptedMessage(qint64,qint32)), this, SIGNAL(messagesSendEncryptedServiceAnswer(qint64,qint32))); |
4987 | + connect(mApi, SIGNAL(messagesSendEncryptedServiceSentEncryptedFile(qint64,qint32,EncryptedFile)), this, SIGNAL(messagesSendEncryptedServiceAnswer(qint64,qint32,EncryptedFile))); |
4988 | + connect(mApi, SIGNAL(updateShort(Update,qint32)), SLOT(onUpdateShort(Update))); |
4989 | + connect(mApi, SIGNAL(updatesCombined(QList<Update>,QList<User>,QList<Chat>,qint32,qint32,qint32)), SLOT(onUpdatesCombined(QList<Update>))); |
4990 | + connect(mApi, SIGNAL(updates(QList<Update>,QList<User>,QList<Chat>,qint32,qint32)), SLOT(onUpdates(QList<Update>))); |
4991 | // updates |
4992 | - connect(m_api, SIGNAL(updatesState(qint64,qint32,qint32,qint32,qint32,qint32)), this, SIGNAL(updatesGetStateAnswer(qint64,qint32,qint32,qint32,qint32,qint32))); |
4993 | - connect(m_api, SIGNAL(updatesDifferenceEmpty(qint64,qint32,qint32)), this, SIGNAL(updatesGetDifferenceAnswer(qint64,qint32,qint32))); |
4994 | - connect(m_api, SIGNAL(updatesDifference(qint64,QList<Message>,QList<EncryptedMessage>,QList<Update>,QList<Chat>,QList<User>,UpdatesState)), this, SLOT(onUpdatesDifference(qint64,QList<Message>,QList<EncryptedMessage>,QList<Update>,QList<Chat>,QList<User>,UpdatesState))); |
4995 | - connect(m_api, SIGNAL(updatesDifferenceSlice(qint64,QList<Message>,QList<EncryptedMessage>,QList<Update>,QList<Chat>,QList<User>,UpdatesState)), this, SLOT(onUpdatesDifferenceSlice(qint64,QList<Message>,QList<EncryptedMessage>,QList<Update>,QList<Chat>,QList<User>,UpdatesState))); |
4996 | - connect(m_api, SIGNAL(uploadSaveFilePartResult(qint64,qint64,bool)), this, SLOT(onUploadSaveFilePartResult(qint64,qint64,bool))); |
4997 | - connect(m_api, SIGNAL(uploadSaveBigFilePartResult(qint64,qint64,bool)), this, SLOT(onUploadSaveFilePartResult(qint64,qint64,bool))); |
4998 | - connect(m_api, SIGNAL(uploadFile(qint64,StorageFileType,qint32,QByteArray)), this, SLOT(onUploadGetFileAnswer(qint64,StorageFileType,qint32,QByteArray))); |
4999 | + connect(mApi, SIGNAL(updatesState(qint64,qint32,qint32,qint32,qint32,qint32)), this, SIGNAL(updatesGetStateAnswer(qint64,qint32,qint32,qint32,qint32,qint32))); |
5000 | + connect(mApi, SIGNAL(updatesDifferenceEmpty(qint64,qint32,qint32)), this, SIGNAL(updatesGetDifferenceAnswer(qint64,qint32,qint32))); |
It's a huge MP with a lot of noise from changed log tags, so I wouldn't be surprised if I missed something, but it looks good. I tested, and works great. Two thoughts left in-line.