| 6 |
| * Copyright Nikolai Kudashov, 2015-2018. |
| 7 | */ |
| 8 |
| 9 | #include <memory.h> |
| 10 | #include <arpa/inet.h> |
| 11 | #include "MTProtoScheme.h" |
| 12 | #include "ApiScheme.h" |
| 13 | #include "FileLog.h" |
| 14 | #include "ByteArray.h" |
| 15 | #include "NativeByteBuffer.h" |
| 16 | #include "BuffersStorage.h" |
| 17 | #include "ConnectionsManager.h" |
| 18 |
| 19 | TLObject *TLClassStore::TLdeserialize(NativeByteBuffer *stream, uint32_t bytes, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 20 | TLObject *object = nullptr; |
| 21 | switch (constructor) { |
| 22 | case TL_msgs_ack::constructor: |
| 23 | object = new TL_msgs_ack(); |
| 24 | break; |
| 25 | case TL_msg_container::constructor: |
| 26 | object = new TL_msg_container(); |
| 27 | break; |
| 28 | case TL_pong::constructor: |
| 29 | object = new TL_pong(); |
| 30 | break; |
| 31 | case TL_new_session_created::constructor: |
| 32 | object = new TL_new_session_created(); |
| 33 | break; |
| 34 | case MsgsStateInfo::constructor: |
| 35 | object = new MsgsStateInfo(); |
| 36 | break; |
| 37 | case TL_rpc_result::constructor: |
| 38 | object = new TL_rpc_result(); |
| 39 | ((TL_rpc_result *) object)->readParamsEx(stream, bytes, instanceNum, error); |
| 40 | return object; |
| 41 | case TL_bad_msg_notification::constructor: |
| 42 | object = new TL_bad_msg_notification(); |
| 43 | break; |
| 44 | case TL_bad_server_salt::constructor: |
| 45 | object = new TL_bad_server_salt(); |
| 46 | break; |
| 47 | case TL_msg_detailed_info::constructor: |
| 48 | object = new TL_msg_detailed_info(); |
| 49 | break; |
| 50 | case TL_msg_new_detailed_info::constructor: |
| 51 | object = new TL_msg_new_detailed_info(); |
| 52 | break; |
| 53 | case TL_gzip_packed::constructor: |
| 54 | object = new TL_gzip_packed(); |
| 55 | break; |
| 56 | case TL_error::constructor: |
| 57 | object = new TL_error(); |
| 58 | break; |
| 59 | case TL_rpc_error::constructor: |
| 60 | object = new TL_rpc_error(); |
| 61 | break; |
| 62 | case TL_rpc_req_error::constructor: |
| 63 | object = new TL_rpc_req_error(); |
| 64 | break; |
| 65 | case TL_future_salts::constructor: |
| 66 | object = new TL_future_salts(); |
| 67 | break; |
| 68 | case TL_destroy_session_ok::constructor: |
| 69 | object = new TL_destroy_session_ok(); |
| 70 | break; |
| 71 | case TL_destroy_session_none::constructor: |
| 72 | object = new TL_destroy_session_none(); |
| 73 | break; |
| 74 | case TL_updatesTooLong::constructor: |
| 75 | object = new TL_updatesTooLong(); |
| 76 | break; |
| 77 | default: |
| 78 | return nullptr; |
| 79 | } |
| 80 | object->readParams(stream, instanceNum, error); |
| 81 | return object; |
| 82 | } |
| 83 |
| 84 | TL_api_request::~TL_api_request() { |
| 85 | if (request != nullptr) { |
| 86 | request->reuse(); |
| 87 | request = nullptr; |
| 88 | } |
| 89 | } |
| 90 |
| 91 | bool TL_api_request::isNeedLayer() { |
| 92 | return true; |
| 93 | } |
| 94 |
| 95 | TLObject *TL_api_request::deserializeResponse(NativeByteBuffer *stream, uint32_t bytes, int32_t instanceNum, bool &error) { |
| 96 | TL_api_response *result = new TL_api_response(); |
| 97 | result->readParamsEx(stream, bytes, error); |
| 98 | return result; |
| 99 | } |
| 100 |
| 101 | void TL_api_request::serializeToStream(NativeByteBuffer *stream) { |
| 102 | request->rewind(); |
| 103 | stream->writeBytes(request); |
| 104 | } |
| 105 |
| 106 | void TL_api_response::readParamsEx(NativeByteBuffer *stream, uint32_t bytes, bool &error) { |
| 107 | if (bytes < 4 || stream->position() < 4 || bytes - 4 > stream->remaining()) { |
| 108 | error = true; |
| 109 | return; |
| 110 | } |
| 111 | response = std::unique_ptr<NativeByteBuffer>(new NativeByteBuffer(stream->bytes() + stream->position() - 4, bytes)); |
| 112 | stream->skip((uint32_t) (bytes - 4)); |
| 113 | } |
| 114 |
| 115 | TL_future_salt *TL_future_salt::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 116 | if (TL_future_salt::constructor != constructor) { |
| 117 | error = true; |
| 118 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_future_salt", constructor); |
| 119 | return nullptr; |
| 120 | } |
| 121 | TL_future_salt *result = new TL_future_salt(); |
| 122 | result->readParams(stream, instanceNum, error); |
| 123 | return result; |
| 124 | } |
| 125 |
| 126 | void TL_future_salt::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 127 | valid_since = stream->readInt32(&error); |
| 128 | valid_until = stream->readInt32(&error); |
| 129 | salt = stream->readInt64(&error); |
| 130 | } |
| 131 |
| 132 | TL_msgs_state_info *TL_msgs_state_info::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 133 | if (TL_msgs_state_info::constructor != constructor) { |
| 134 | error = true; |
| 135 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_msgs_state_info", constructor); |
| 136 | return nullptr; |
| 137 | } |
| 138 | TL_msgs_state_info *result = new TL_msgs_state_info(); |
| 139 | result->readParams(stream, instanceNum, error); |
| 140 | return result; |
| 141 | } |
| 142 |
| 143 | void TL_msgs_state_info::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 144 | req_msg_id = stream->readInt64(&error); |
| 145 | info = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 146 | } |
| 147 |
| 148 | void TL_msgs_state_info::serializeToStream(NativeByteBuffer *stream) { |
| 149 | stream->writeInt32(constructor); |
| 150 | stream->writeInt64(req_msg_id); |
| 151 | stream->writeByteArray(info.get()); |
| 152 | } |
| 153 |
| 154 | Server_DH_Params *Server_DH_Params::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 155 | Server_DH_Params *result = nullptr; |
| 156 | switch (constructor) { |
| 157 | case 0x79cb045d: |
| 158 | result = new TL_server_DH_params_fail(); |
| 159 | break; |
| 160 | case 0xd0e8075c: |
| 161 | result = new TL_server_DH_params_ok(); |
| 162 | break; |
| 163 | default: |
| 164 | error = true; |
| 165 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in Server_DH_Params", constructor); |
| 166 | return nullptr; |
| 167 | } |
| 168 | result->readParams(stream, instanceNum, error); |
| 169 | return result; |
| 170 | } |
| 171 |
| 172 | void TL_server_DH_params_fail::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 173 | nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 174 | server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 175 | new_nonce_hash = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 176 | } |
| 177 |
| 178 | void TL_server_DH_params_ok::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 179 | nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 180 | server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 181 | encrypted_answer = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 182 | } |
| 183 |
| 184 | TL_resPQ *TL_resPQ::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 185 | if (TL_resPQ::constructor != constructor) { |
| 186 | error = true; |
| 187 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_resPQ", constructor); |
| 188 | return nullptr; |
| 189 | } |
| 190 | TL_resPQ *result = new TL_resPQ(); |
| 191 | result->readParams(stream, instanceNum, error); |
| 192 | return result; |
| 193 | } |
| 194 |
| 195 | void TL_resPQ::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 196 | nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 197 | server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 198 | pq = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 199 | uint32_t magic = stream->readUint32(&error); |
| 200 | if (magic != 0x1cb5c415) { |
| 201 | error = true; |
| 202 | if (LOGS_ENABLED) DEBUG_FATAL("wrong Vector magic in TL_resPQ, got %x", magic); |
| 203 | return; |
| 204 | } |
| 205 | uint32_t count = stream->readUint32(&error); |
| 206 | if (error || count > (stream->limit() - stream->position()) / sizeof(int64_t)) { |
| 207 | error = true; |
| 208 | return; |
| 209 | } |
| 210 | for (uint32_t a = 0; a < count; a++) { |
| 211 | server_public_key_fingerprints.push_back(stream->readInt64(&error)); |
| 212 | } |
| 213 | } |
| 214 |
| 215 | void TL_p_q_inner_data::serializeToStream(NativeByteBuffer *stream) { |
| 216 | stream->writeInt32(constructor); |
| 217 | stream->writeByteArray(pq.get()); |
| 218 | stream->writeByteArray(p.get()); |
| 219 | stream->writeByteArray(q.get()); |
| 220 | stream->writeBytes(nonce.get()); |
| 221 | stream->writeBytes(server_nonce.get()); |
| 222 | stream->writeBytes(new_nonce.get()); |
| 223 | } |
| 224 |
| 225 | void TL_p_q_inner_data_dc::serializeToStream(NativeByteBuffer *stream) { |
| 226 | stream->writeInt32(constructor); |
| 227 | stream->writeByteArray(pq.get()); |
| 228 | stream->writeByteArray(p.get()); |
| 229 | stream->writeByteArray(q.get()); |
| 230 | stream->writeBytes(nonce.get()); |
| 231 | stream->writeBytes(server_nonce.get()); |
| 232 | stream->writeBytes(new_nonce.get()); |
| 233 | stream->writeInt32(dc); |
| 234 | } |
| 235 |
| 236 | void TL_p_q_inner_data_temp::serializeToStream(NativeByteBuffer *stream) { |
| 237 | stream->writeInt32(constructor); |
| 238 | stream->writeByteArray(pq.get()); |
| 239 | stream->writeByteArray(p.get()); |
| 240 | stream->writeByteArray(q.get()); |
| 241 | stream->writeBytes(nonce.get()); |
| 242 | stream->writeBytes(server_nonce.get()); |
| 243 | stream->writeBytes(new_nonce.get()); |
| 244 | stream->writeInt32(expires_in); |
| 245 | } |
| 246 |
| 247 | void TL_p_q_inner_data_temp_dc::serializeToStream(NativeByteBuffer *stream) { |
| 248 | stream->writeInt32(constructor); |
| 249 | stream->writeByteArray(pq.get()); |
| 250 | stream->writeByteArray(p.get()); |
| 251 | stream->writeByteArray(q.get()); |
| 252 | stream->writeBytes(nonce.get()); |
| 253 | stream->writeBytes(server_nonce.get()); |
| 254 | stream->writeBytes(new_nonce.get()); |
| 255 | stream->writeInt32(dc); |
| 256 | stream->writeInt32(expires_in); |
| 257 | } |
| 258 |
| 259 | void TL_bind_auth_key_inner::serializeToStream(NativeByteBuffer *stream) { |
| 260 | stream->writeInt32(constructor); |
| 261 | stream->writeInt64(nonce); |
| 262 | stream->writeInt64(temp_auth_key_id); |
| 263 | stream->writeInt64(perm_auth_key_id); |
| 264 | stream->writeInt64(temp_session_id); |
| 265 | stream->writeInt32(expires_at); |
| 266 | } |
| 267 |
| 268 | TL_auth_bindTempAuthKey::~TL_auth_bindTempAuthKey() { |
| 269 | if (encrypted_message != nullptr) { |
| 270 | encrypted_message->reuse(); |
| 271 | encrypted_message = nullptr; |
| 272 | } |
| 273 | } |
| 274 |
| 275 | TLObject *TL_auth_bindTempAuthKey::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 276 | return Bool::TLdeserialize(stream, constructor, instanceNum, error); |
| 277 | } |
| 278 |
| 279 | void TL_auth_bindTempAuthKey::serializeToStream(NativeByteBuffer *stream) { |
| 280 | stream->writeInt32(constructor); |
| 281 | stream->writeInt64(perm_auth_key_id); |
| 282 | stream->writeInt64(nonce); |
| 283 | stream->writeInt32(expires_at); |
| 284 | stream->writeByteArray(encrypted_message); |
| 285 | } |
| 286 |
| 287 | TLObject *TL_auth_dropTempAuthKeys::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 288 | return Bool::TLdeserialize(stream, constructor, instanceNum, error); |
| 289 | } |
| 290 |
| 291 | void TL_auth_dropTempAuthKeys::serializeToStream(NativeByteBuffer *stream) { |
| 292 | stream->writeInt32(constructor); |
| 293 | stream->writeInt32(0x1cb5c415); |
| 294 | uint32_t count = (uint32_t) except_auth_keys.size(); |
| 295 | stream->writeInt32(count); |
| 296 | for (int a = 0; a < count; a++) { |
| 297 | stream->writeInt64(except_auth_keys[a]); |
| 298 | } |
| 299 | } |
| 300 |
| 301 | TL_pong *TL_pong::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 302 | if (TL_pong::constructor != constructor) { |
| 303 | error = true; |
| 304 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_pong", constructor); |
| 305 | return nullptr; |
| 306 | } |
| 307 | TL_pong *result = new TL_pong(); |
| 308 | result->readParams(stream, instanceNum, error); |
| 309 | return result; |
| 310 | } |
| 311 |
| 312 | void TL_pong::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 313 | msg_id = stream->readInt64(&error); |
| 314 | ping_id = stream->readInt64(&error); |
| 315 | } |
| 316 |
| 317 | TL_future_salts *TL_future_salts::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 318 | if (TL_future_salts::constructor != constructor) { |
| 319 | error = true; |
| 320 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_future_salts", constructor); |
| 321 | return nullptr; |
| 322 | } |
| 323 | TL_future_salts *result = new TL_future_salts(); |
| 324 | result->readParams(stream, instanceNum, error); |
| 325 | return result; |
| 326 | } |
| 327 |
| 328 | void TL_future_salts::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 329 | req_msg_id = stream->readInt64(&error); |
| 330 | now = stream->readInt32(&error); |
| 331 | uint32_t count = stream->readUint32(&error); |
| 332 | for (uint32_t a = 0; a < count; a++) { |
| 333 | TL_future_salt *object = new TL_future_salt(); |
| 334 | object->readParams(stream, instanceNum, error); |
| 335 | if (error) { |
| 336 | return; |
| 337 | } |
| 338 | salts.push_back(std::unique_ptr<TL_future_salt>(object)); |
| 339 | } |
| 340 | } |
| 341 |
| 342 | RpcDropAnswer *RpcDropAnswer::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 343 | RpcDropAnswer *result = nullptr; |
| 344 | switch (constructor) { |
| 345 | case 0x5e2ad36e: |
| 346 | result = new TL_rpc_answer_unknown(); |
| 347 | break; |
| 348 | case 0xa43ad8b7: |
| 349 | result = new TL_rpc_answer_dropped(); |
| 350 | break; |
| 351 | case 0xcd78e586: |
| 352 | result = new TL_rpc_answer_dropped_running(); |
| 353 | break; |
| 354 | default: |
| 355 | error = true; |
| 356 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in RpcDropAnswer", constructor); |
| 357 | return nullptr; |
| 358 | } |
| 359 | result->readParams(stream, instanceNum, error); |
| 360 | return result; |
| 361 | } |
| 362 |
| 363 | void TL_rpc_answer_unknown::serializeToStream(NativeByteBuffer *stream) { |
| 364 | stream->writeInt32(constructor); |
| 365 | } |
| 366 |
| 367 | void TL_rpc_answer_dropped::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 368 | msg_id = stream->readInt64(&error); |
| 369 | seq_no = stream->readInt32(&error); |
| 370 | bytes = stream->readInt32(&error); |
| 371 | } |
| 372 |
| 373 | void TL_rpc_answer_dropped_running::serializeToStream(NativeByteBuffer *stream) { |
| 374 | stream->writeInt32(constructor); |
| 375 | } |
| 376 |
| 377 | Set_client_DH_params_answer *Set_client_DH_params_answer::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 378 | Set_client_DH_params_answer *result = nullptr; |
| 379 | switch (constructor) { |
| 380 | case 0x46dc1fb9: |
| 381 | result = new TL_dh_gen_retry(); |
| 382 | break; |
| 383 | case 0xa69dae02: |
| 384 | result = new TL_dh_gen_fail(); |
| 385 | break; |
| 386 | case 0x3bcbf734: |
| 387 | result = new TL_dh_gen_ok(); |
| 388 | break; |
| 389 | default: |
| 390 | error = true; |
| 391 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in Set_client_DH_params_answer", constructor); |
| 392 | return nullptr; |
| 393 | } |
| 394 | result->readParams(stream, instanceNum, error); |
| 395 | return result; |
| 396 | } |
| 397 |
| 398 | void TL_dh_gen_retry::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 399 | nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 400 | server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 401 | new_nonce_hash2 = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 402 | } |
| 403 |
| 404 | void TL_dh_gen_fail::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 405 | nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 406 | server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 407 | new_nonce_hash3 = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 408 | } |
| 409 |
| 410 | void TL_dh_gen_ok::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 411 | nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 412 | server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 413 | new_nonce_hash1 = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 414 | } |
| 415 |
| 416 | BadMsgNotification *BadMsgNotification::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 417 | BadMsgNotification *result = nullptr; |
| 418 | switch (constructor) { |
| 419 | case 0xa7eff811: |
| 420 | result = new TL_bad_msg_notification(); |
| 421 | break; |
| 422 | case 0xedab447b: |
| 423 | result = new TL_bad_server_salt(); |
| 424 | break; |
| 425 | default: |
| 426 | error = true; |
| 427 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in BadMsgNotification", constructor); |
| 428 | return nullptr; |
| 429 | } |
| 430 | result->readParams(stream, instanceNum, error); |
| 431 | return result; |
| 432 | } |
| 433 |
| 434 | void TL_bad_msg_notification::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 435 | bad_msg_id = stream->readInt64(&error); |
| 436 | bad_msg_seqno = stream->readInt32(&error); |
| 437 | error_code = stream->readInt32(&error); |
| 438 | } |
| 439 |
| 440 | void TL_bad_server_salt::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 441 | bad_msg_id = stream->readInt64(&error); |
| 442 | bad_msg_seqno = stream->readInt32(&error); |
| 443 | error_code = stream->readInt32(&error); |
| 444 | new_server_salt = stream->readInt64(&error); |
| 445 | } |
| 446 |
| 447 | TL_msgs_state_req *TL_msgs_state_req::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 448 | if (TL_msgs_state_req::constructor != constructor) { |
| 449 | error = true; |
| 450 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_msgs_state_req", constructor); |
| 451 | return nullptr; |
| 452 | } |
| 453 | TL_msgs_state_req *result = new TL_msgs_state_req(); |
| 454 | result->readParams(stream, instanceNum, error); |
| 455 | return result; |
| 456 | } |
| 457 |
| 458 | void TL_msgs_state_req::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 459 | uint32_t magic = stream->readUint32(&error); |
| 460 | if (magic != 0x1cb5c415) { |
| 461 | error = true; |
| 462 | if (LOGS_ENABLED) DEBUG_FATAL("wrong Vector magic in TL_msgs_state_req, got %x", magic); |
| 463 | return; |
| 464 | } |
| 465 | uint32_t count = stream->readUint32(&error); |
| 466 | if (error || count > (stream->limit() - stream->position()) / sizeof(int64_t)) { |
| 467 | error = true; |
| 468 | return; |
| 469 | } |
| 470 | for (uint32_t a = 0; a < count; a++) { |
| 471 | msg_ids.push_back(stream->readInt64(&error)); |
| 472 | } |
| 473 | } |
| 474 |
| 475 | void TL_msgs_state_req::serializeToStream(NativeByteBuffer *stream) { |
| 476 | stream->writeInt32(constructor); |
| 477 | stream->writeInt32(0x1cb5c415); |
| 478 | uint32_t count = (uint32_t) msg_ids.size(); |
| 479 | stream->writeInt32(count); |
| 480 | for (uint32_t a = 0; a < count; a++) { |
| 481 | stream->writeInt64(msg_ids[a]); |
| 482 | } |
| 483 | } |
| 484 |
| 485 | MsgDetailedInfo *MsgDetailedInfo::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 486 | MsgDetailedInfo *result = nullptr; |
| 487 | switch (constructor) { |
| 488 | case 0x809db6df: |
| 489 | result = new TL_msg_new_detailed_info(); |
| 490 | break; |
| 491 | case 0x276d3ec6: |
| 492 | result = new TL_msg_detailed_info(); |
| 493 | break; |
| 494 | default: |
| 495 | error = true; |
| 496 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in MsgDetailedInfo", constructor); |
| 497 | return nullptr; |
| 498 | } |
| 499 | result->readParams(stream, instanceNum, error); |
| 500 | return result; |
| 501 | } |
| 502 |
| 503 | void TL_msg_new_detailed_info::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 504 | answer_msg_id = stream->readInt64(&error); |
| 505 | bytes = stream->readInt32(&error); |
| 506 | status = stream->readInt32(&error); |
| 507 | } |
| 508 |
| 509 | void TL_msg_detailed_info::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 510 | msg_id = stream->readInt64(&error); |
| 511 | answer_msg_id = stream->readInt64(&error); |
| 512 | bytes = stream->readInt32(&error); |
| 513 | status = stream->readInt32(&error); |
| 514 | } |
| 515 |
| 516 | TL_msg_copy *TL_msg_copy::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 517 | if (TL_msg_copy::constructor != constructor) { |
| 518 | error = true; |
| 519 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_msg_copy", constructor); |
| 520 | return nullptr; |
| 521 | } |
| 522 | TL_msg_copy *result = new TL_msg_copy(); |
| 523 | result->readParams(stream, instanceNum, error); |
| 524 | return result; |
| 525 | } |
| 526 |
| 527 | void TL_msg_copy::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 528 | orig_message = std::unique_ptr<TL_message>(TL_message::TLdeserialize(stream, stream->readUint32(&error), instanceNum, error)); |
| 529 | } |
| 530 |
| 531 | void TL_msg_copy::serializeToStream(NativeByteBuffer *stream) { |
| 532 | stream->writeInt32(constructor); |
| 533 | orig_message->serializeToStream(stream); |
| 534 | } |
| 535 |
| 536 | TL_msgs_all_info *TL_msgs_all_info::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 537 | if (TL_msgs_all_info::constructor != constructor) { |
| 538 | error = true; |
| 539 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_msgs_all_info", constructor); |
| 540 | return nullptr; |
| 541 | } |
| 542 | TL_msgs_all_info *result = new TL_msgs_all_info(); |
| 543 | result->readParams(stream, instanceNum, error); |
| 544 | return result; |
| 545 | } |
| 546 |
| 547 | void TL_msgs_all_info::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 548 | uint32_t magic = stream->readUint32(&error); |
| 549 | if (magic != 0x1cb5c415) { |
| 550 | error = true; |
| 551 | if (LOGS_ENABLED) DEBUG_FATAL("wrong Vector magic in TL_msgs_all_info, got %x", magic); |
| 552 | return; |
| 553 | } |
| 554 | uint32_t count = stream->readUint32(&error); |
| 555 | if (error || count > (stream->limit() - stream->position()) / sizeof(int64_t)) { |
| 556 | error = true; |
| 557 | return; |
| 558 | } |
| 559 | for (uint32_t a = 0; a < count; a++) { |
| 560 | msg_ids.push_back(stream->readInt64(&error)); |
| 561 | } |
| 562 | info = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 563 | } |
| 564 |
| 565 | void TL_rpc_result::readParamsEx(NativeByteBuffer *stream, uint32_t bytes, int32_t instanceNum, bool &error) { |
| 566 | req_msg_id = stream->readInt64(&error); |
| 567 | ConnectionsManager &connectionsManager = ConnectionsManager::getInstance(instanceNum); |
| 568 | TLObject *object = connectionsManager.TLdeserialize(connectionsManager.getRequestWithMessageId(req_msg_id), bytes - 12, stream); |
| 569 | if (object != nullptr) { |
| 570 | result = std::unique_ptr<TLObject>(object); |
| 571 | } else { |
| 572 | error = true; |
| 573 | } |
| 574 | } |
| 575 |
| 576 | void TL_new_session_created::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 577 | first_msg_id = stream->readInt64(&error); |
| 578 | unique_id = stream->readInt64(&error); |
| 579 | server_salt = stream->readInt64(&error); |
| 580 | } |
| 581 |
| 582 | DestroySessionRes *DestroySessionRes::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 583 | DestroySessionRes *result = nullptr; |
| 584 | switch (constructor) { |
| 585 | case 0xe22045fc: |
| 586 | result = new TL_destroy_session_ok(); |
| 587 | break; |
| 588 | case 0x62d350c9: |
| 589 | result = new TL_destroy_session_none(); |
| 590 | break; |
| 591 | default: |
| 592 | error = true; |
| 593 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in DestroySessionRes", constructor); |
| 594 | return nullptr; |
| 595 | } |
| 596 | result->readParams(stream, instanceNum, error); |
| 597 | return result; |
| 598 | } |
| 599 |
| 600 | void TL_destroy_session_ok::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 601 | session_id = stream->readInt64(&error); |
| 602 | } |
| 603 |
| 604 | void TL_destroy_session_none::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 605 | session_id = stream->readInt64(&error); |
| 606 | } |
| 607 |
| 608 | TL_msgs_ack *TL_msgs_ack::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 609 | if (TL_msgs_ack::constructor != constructor) { |
| 610 | error = true; |
| 611 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_msgs_ack", constructor); |
| 612 | return nullptr; |
| 613 | } |
| 614 | TL_msgs_ack *result = new TL_msgs_ack(); |
| 615 | result->readParams(stream, instanceNum, error); |
| 616 | return result; |
| 617 | } |
| 618 |
| 619 | void TL_msgs_ack::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 620 | uint32_t magic = stream->readUint32(&error); |
| 621 | if (magic != 0x1cb5c415) { |
| 622 | error = true; |
| 623 | if (LOGS_ENABLED) DEBUG_FATAL("wrong Vector magic in TL_msgs_ack, got %x", magic); |
| 624 | return; |
| 625 | } |
| 626 | uint32_t count = stream->readUint32(&error); |
| 627 | if (error || count > (stream->limit() - stream->position()) / sizeof(int64_t)) { |
| 628 | error = true; |
| 629 | return; |
| 630 | } |
| 631 | for (uint32_t a = 0; a < count; a++) { |
| 632 | msg_ids.push_back(stream->readInt64(&error)); |
| 633 | } |
| 634 | } |
| 635 |
| 636 | void TL_msgs_ack::serializeToStream(NativeByteBuffer *stream) { |
| 637 | stream->writeInt32(constructor); |
| 638 | stream->writeInt32(0x1cb5c415); |
| 639 | uint32_t count = (uint32_t) msg_ids.size(); |
| 640 | stream->writeInt32(count); |
| 641 | for (uint32_t a = 0; a < count; a++) { |
| 642 | stream->writeInt64(msg_ids[a]); |
| 643 | } |
| 644 | } |
| 645 |
| 646 | TL_msg_container *TL_msg_container::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 647 | if (TL_msg_container::constructor != constructor) { |
| 648 | error = true; |
| 649 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_msg_container", constructor); |
| 650 | return nullptr; |
| 651 | } |
| 652 | TL_msg_container *result = new TL_msg_container(); |
| 653 | result->readParams(stream, instanceNum, error); |
| 654 | return result; |
| 655 | } |
| 656 |
| 657 | void TL_msg_container::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 658 | uint32_t count = stream->readUint32(&error); |
| 659 | for (uint32_t a = 0; a < count; a++) { |
| 660 | TL_message *object = new TL_message(); |
| 661 | object->readParams(stream, instanceNum, error); |
| 662 | if (error) { |
| 663 | return; |
| 664 | } |
| 665 | messages.push_back(std::unique_ptr<TL_message>(object)); |
| 666 | } |
| 667 | } |
| 668 |
| 669 | void TL_msg_container::serializeToStream(NativeByteBuffer *stream) { |
| 670 | stream->writeInt32(constructor); |
| 671 | uint32_t count = (uint32_t) messages.size(); |
| 672 | stream->writeInt32(count); |
| 673 | for (uint32_t a = 0; a < count; a++) { |
| 674 | messages[a]->serializeToStream(stream); |
| 675 | } |
| 676 | } |
| 677 |
| 678 | TL_message *TL_message::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 679 | if (TL_message::constructor != constructor) { |
| 680 | error = true; |
| 681 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_message", constructor); |
| 682 | return nullptr; |
| 683 | } |
| 684 | TL_message *result = new TL_message(); |
| 685 | result->readParams(stream, instanceNum, error); |
| 686 | return result; |
| 687 | } |
| 688 |
| 689 | void TL_message::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 690 | msg_id = stream->readInt64(&error); |
| 691 | seqno = stream->readInt32(&error); |
| 692 | bytes = stream->readInt32(&error); |
| 693 | if (error || bytes < 0 || (uint32_t) bytes > stream->remaining()) { |
| 694 | error = true; |
| 695 | return; |
| 696 | } |
| 697 | TLObject *object = ConnectionsManager::getInstance(instanceNum).TLdeserialize(nullptr, (uint32_t) bytes, stream); |
| 698 | if (object == nullptr) { |
| 699 | unparsedBody = std::unique_ptr<NativeByteBuffer>(new NativeByteBuffer(stream->bytes() + stream->position(), (uint32_t) bytes)); |
| 700 | stream->skip((uint32_t) bytes); |
| 701 | } else { |
| 702 | body = std::unique_ptr<TLObject>(object); |
| 703 | } |
| 704 | } |
| 705 |
| 706 | void TL_message::serializeToStream(NativeByteBuffer *stream) { |
| 707 | stream->writeInt64(msg_id); |
| 708 | stream->writeInt32(seqno); |
| 709 | stream->writeInt32(bytes); |
| 710 | if (outgoingBody != nullptr) { |
| 711 | outgoingBody->serializeToStream(stream); |
| 712 | } else { |
| 713 | body->serializeToStream(stream); |
| 714 | } |
| 715 | } |
| 716 |
| 717 | TL_msg_resend_req *TL_msg_resend_req::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 718 | if (TL_msg_resend_req::constructor != constructor) { |
| 719 | error = true; |
| 720 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_msg_resend_req", constructor); |
| 721 | return nullptr; |
| 722 | } |
| 723 | TL_msg_resend_req *result = new TL_msg_resend_req(); |
| 724 | result->readParams(stream, instanceNum, error); |
| 725 | return result; |
| 726 | } |
| 727 |
| 728 | void TL_msg_resend_req::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 729 | uint32_t magic = stream->readUint32(&error); |
| 730 | if (magic != 0x1cb5c415) { |
| 731 | error = true; |
| 732 | if (LOGS_ENABLED) DEBUG_FATAL("wrong Vector magic in TL_msg_resend_req, got %x", magic); |
| 733 | return; |
| 734 | } |
| 735 | uint32_t count = stream->readUint32(&error); |
| 736 | if (error || count > (stream->limit() - stream->position()) / sizeof(int64_t)) { |
| 737 | error = true; |
| 738 | return; |
| 739 | } |
| 740 | for (uint32_t a = 0; a < count; a++) { |
| 741 | msg_ids.push_back(stream->readInt64(&error)); |
| 742 | } |
| 743 | } |
| 744 |
| 745 | void TL_msg_resend_req::serializeToStream(NativeByteBuffer *stream) { |
| 746 | stream->writeInt32(constructor); |
| 747 | stream->writeInt32(0x1cb5c415); |
| 748 | uint32_t count = (uint32_t) msg_ids.size(); |
| 749 | stream->writeInt32(count); |
| 750 | for (uint32_t a = 0; a < count; a++) { |
| 751 | stream->writeInt64(msg_ids[a]); |
| 752 | } |
| 753 | } |
| 754 |
| 755 | void MsgsStateInfo::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 756 | req_msg_id = stream->readInt64(&error); |
| 757 | info = stream->readString(&error); |
| 758 | } |
| 759 |
| 760 | void TL_rpc_error::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 761 | error_code = stream->readInt32(&error); |
| 762 | error_message = stream->readString(&error); |
| 763 | } |
| 764 |
| 765 | void TL_rpc_req_error::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 766 | query_id = stream->readInt64(&error); |
| 767 | error_code = stream->readInt32(&error); |
| 768 | error_message = stream->readString(&error); |
| 769 | } |
| 770 |
| 771 | void TL_client_DH_inner_data::serializeToStream(NativeByteBuffer *stream) { |
| 772 | stream->writeInt32(constructor); |
| 773 | stream->writeBytes(nonce.get()); |
| 774 | stream->writeBytes(server_nonce.get()); |
| 775 | stream->writeInt64(retry_id); |
| 776 | stream->writeByteArray(g_b.get()); |
| 777 | } |
| 778 |
| 779 | TL_server_DH_inner_data *TL_server_DH_inner_data::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 780 | if (TL_server_DH_inner_data::constructor != constructor) { |
| 781 | error = true; |
| 782 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_server_DH_inner_data", constructor); |
| 783 | return nullptr; |
| 784 | } |
| 785 | TL_server_DH_inner_data *result = new TL_server_DH_inner_data(); |
| 786 | result->readParams(stream, instanceNum, error); |
| 787 | return result; |
| 788 | } |
| 789 |
| 790 | void TL_server_DH_inner_data::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 791 | nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 792 | server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 793 | g = stream->readUint32(&error); |
| 794 | dh_prime = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 795 | g_a = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 796 | server_time = stream->readInt32(&error); |
| 797 | } |
| 798 |
| 799 | void TL_server_DH_inner_data::serializeToStream(NativeByteBuffer *stream) { |
| 800 | stream->writeInt32(constructor); |
| 801 | stream->writeBytes(nonce.get()); |
| 802 | stream->writeBytes(server_nonce.get()); |
| 803 | stream->writeInt32(g); |
| 804 | stream->writeByteArray(dh_prime.get()); |
| 805 | stream->writeByteArray(g_a.get()); |
| 806 | stream->writeInt32(server_time); |
| 807 | } |
| 808 |
| 809 | TLObject *TL_req_pq::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 810 | return TL_resPQ::TLdeserialize(stream, constructor, instanceNum, error); |
| 811 | } |
| 812 |
| 813 | void TL_req_pq::serializeToStream(NativeByteBuffer *stream) { |
| 814 | stream->writeInt32(constructor); |
| 815 | stream->writeBytes(nonce.get()); |
| 816 | } |
| 817 |
| 818 | TLObject *TL_req_pq_multi::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 819 | return TL_resPQ::TLdeserialize(stream, constructor, instanceNum, error); |
| 820 | } |
| 821 |
| 822 | void TL_req_pq_multi::serializeToStream(NativeByteBuffer *stream) { |
| 823 | stream->writeInt32(constructor); |
| 824 | stream->writeBytes(nonce.get()); |
| 825 | } |
| 826 |
| 827 | TLObject *TL_req_DH_params::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 828 | return Server_DH_Params::TLdeserialize(stream, constructor, instanceNum, error); |
| 829 | } |
| 830 |
| 831 | void TL_req_DH_params::serializeToStream(NativeByteBuffer *stream) { |
| 832 | stream->writeInt32(constructor); |
| 833 | stream->writeBytes(nonce.get()); |
| 834 | stream->writeBytes(server_nonce.get()); |
| 835 | stream->writeByteArray(p.get()); |
| 836 | stream->writeByteArray(q.get()); |
| 837 | stream->writeInt64(public_key_fingerprint); |
| 838 | stream->writeByteArray(encrypted_data.get()); |
| 839 | } |
| 840 |
| 841 | TLObject *TL_set_client_DH_params::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 842 | return Set_client_DH_params_answer::TLdeserialize(stream, constructor, instanceNum, error); |
| 843 | } |
| 844 |
| 845 | void TL_set_client_DH_params::serializeToStream(NativeByteBuffer *stream) { |
| 846 | stream->writeInt32(constructor); |
| 847 | stream->writeBytes(nonce.get()); |
| 848 | stream->writeBytes(server_nonce.get()); |
| 849 | stream->writeByteArray(encrypted_data.get()); |
| 850 | } |
| 851 |
| 852 | TLObject *TL_rpc_drop_answer::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 853 | return RpcDropAnswer::TLdeserialize(stream, constructor, instanceNum, error); |
| 854 | } |
| 855 |
| 856 | void TL_rpc_drop_answer::serializeToStream(NativeByteBuffer *stream) { |
| 857 | stream->writeInt32(constructor); |
| 858 | stream->writeInt64(req_msg_id); |
| 859 | } |
| 860 |
| 861 | TLObject *TL_get_future_salts::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 862 | return TL_future_salts::TLdeserialize(stream, constructor, instanceNum, error); |
| 863 | } |
| 864 |
| 865 | void TL_get_future_salts::serializeToStream(NativeByteBuffer *stream) { |
| 866 | stream->writeInt32(constructor); |
| 867 | stream->writeInt32(num); |
| 868 | } |
| 869 |
| 870 | TLObject *TL_ping::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 871 | return TL_pong::TLdeserialize(stream, constructor, instanceNum, error); |
| 872 | } |
| 873 |
| 874 | void TL_ping::serializeToStream(NativeByteBuffer *stream) { |
| 875 | stream->writeInt32(constructor); |
| 876 | stream->writeInt64(ping_id); |
| 877 | } |
| 878 |
| 879 | TLObject *TL_ping_delay_disconnect::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 880 | return TL_pong::TLdeserialize(stream, constructor, instanceNum, error); |
| 881 | } |
| 882 |
| 883 | void TL_ping_delay_disconnect::serializeToStream(NativeByteBuffer *stream) { |
| 884 | stream->writeInt32(constructor); |
| 885 | stream->writeInt64(ping_id); |
| 886 | stream->writeInt32(disconnect_delay); |
| 887 | } |
| 888 |
| 889 | TLObject *TL_destroy_session::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 890 | return DestroySessionRes::TLdeserialize(stream, constructor, instanceNum, error); |
| 891 | } |
| 892 |
| 893 | void TL_destroy_session::serializeToStream(NativeByteBuffer *stream) { |
| 894 | stream->writeInt32(constructor); |
| 895 | stream->writeInt64(session_id); |
| 896 | } |
| 897 |
| 898 | TL_gzip_packed::~TL_gzip_packed() { |
| 899 | if (packed_data_to_send != nullptr) { |
| 900 | packed_data_to_send->reuse(); |
| 901 | packed_data_to_send = nullptr; |
| 902 | } |
| 903 | } |
| 904 |
| 905 | void TL_gzip_packed::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 906 | packed_data = std::unique_ptr<NativeByteBuffer>(stream->readByteBuffer(false, &error)); |
| 907 | } |
| 908 |
| 909 | void TL_gzip_packed::serializeToStream(NativeByteBuffer *stream) { |
| 910 | stream->writeInt32(constructor); |
| 911 | stream->writeByteArray(packed_data_to_send); |
| 912 | } |
| 913 |
| 914 | TL_error *TL_error::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 915 | if (TL_error::constructor != constructor) { |
| 916 | error = true; |
| 917 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_error", constructor); |
| 918 | return nullptr; |
| 919 | } |
| 920 | TL_error *result = new TL_error(); |
| 921 | result->readParams(stream, instanceNum, error); |
| 922 | return result; |
| 923 | } |
| 924 |
| 925 | void TL_error::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 926 | code = stream->readInt32(&error); |
| 927 | text = stream->readString(&error); |
| 928 | } |
| 929 |
| 930 | void TL_error::serializeToStream(NativeByteBuffer *stream) { |
| 931 | stream->writeInt32(constructor); |
| 932 | stream->writeInt32(code); |
| 933 | stream->writeString(text); |
| 934 | } |
| 935 |
| 936 | void TL_invokeAfterMsg::serializeToStream(NativeByteBuffer *stream) { |
| 937 | stream->writeInt32(constructor); |
| 938 | stream->writeInt64(msg_id); |
| 939 | if (outgoingQuery != nullptr) { |
| 940 | outgoingQuery->serializeToStream(stream); |
| 941 | } else { |
| 942 | query->serializeToStream(stream); |
| 943 | } |
| 944 | } |
| 945 |
| 946 | void invokeWithLayer::serializeToStream(NativeByteBuffer *stream) { |
| 947 | stream->writeInt32(constructor); |
| 948 | stream->writeInt32(layer); |
| 949 | query->serializeToStream(stream); |
| 950 | } |
| 951 |
| 952 | void invokeWithGooglePlayIntegrity::serializeToStream(NativeByteBuffer *stream) { |
| 953 | stream->writeInt32(constructor); |
| 954 | stream->writeString(nonce); |
| 955 | stream->writeString(token); |
| 956 | query->serializeToStream(stream); |
| 957 | } |
| 958 |
| 959 | void invokeWithReCaptcha::serializeToStream(NativeByteBuffer *stream) { |
| 960 | stream->writeInt32(constructor); |
| 961 | stream->writeString(token); |
| 962 | query->serializeToStream(stream); |
| 963 | } |
| 964 |
| 965 | void TL_inputClientProxy::serializeToStream(NativeByteBuffer *stream) { |
| 966 | stream->writeInt32(constructor); |
| 967 | stream->writeString(address); |
| 968 | stream->writeInt32(port); |
| 969 | } |
| 970 |
| 971 |
| 972 | JSONValue *JSONValue::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 973 | JSONValue *result = nullptr; |
| 974 | switch (constructor) { |
| 975 | case 0xc7345e6a: |
| 976 | result = new TL_jsonBool(); |
| 977 | break; |
| 978 | case 0x3f6d7b68: |
| 979 | result = new TL_jsonNull(); |
| 980 | break; |
| 981 | case 0xb71e767a: |
| 982 | result = new TL_jsonString(); |
| 983 | break; |
| 984 | case 0xf7444763: |
| 985 | result = new TL_jsonArray(); |
| 986 | break; |
| 987 | case 0x99c1d49d: |
| 988 | result = new TL_jsonObject(); |
| 989 | break; |
| 990 | case 0x2be0dfa4: |
| 991 | result = new TL_jsonNumber(); |
| 992 | break; |
| 993 | default: |
| 994 | error = true; |
| 995 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in JSONValue", constructor); |
| 996 | return nullptr; |
| 997 | } |
| 998 | result->readParams(stream, instanceNum, error); |
| 999 | return result; |
| 1000 | } |
| 1001 |
| 1002 | TL_jsonObjectValue *TL_jsonObjectValue::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 1003 | if (TL_jsonObjectValue::constructor != constructor) { |
| 1004 | error = true; |
| 1005 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_jsonObjectValue", constructor); |
| 1006 | return nullptr; |
| 1007 | } |
| 1008 | TL_jsonObjectValue *result = new TL_jsonObjectValue(); |
| 1009 | result->readParams(stream, instanceNum, error); |
| 1010 | return result; |
| 1011 | } |
| 1012 |
| 1013 |
| 1014 | void TL_jsonObjectValue::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 1015 | key = stream->readString(&error); |
| 1016 | value = std::unique_ptr<JSONValue>(JSONValue::TLdeserialize(stream, stream->readUint32(&error), instanceNum, error)); |
| 1017 | } |
| 1018 |
| 1019 |
| 1020 | void TL_jsonObjectValue::serializeToStream(NativeByteBuffer *stream) { |
| 1021 | stream->writeInt32(constructor); |
| 1022 | stream->writeString(key); |
| 1023 | value->serializeToStream(stream); |
| 1024 | } |
| 1025 |
| 1026 | void TL_jsonBool::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 1027 | value = stream->readBool(&error); |
| 1028 | } |
| 1029 |
| 1030 | void TL_jsonBool::serializeToStream(NativeByteBuffer *stream) { |
| 1031 | stream->writeInt32(constructor); |
| 1032 | stream->writeBool(value); |
| 1033 | } |
| 1034 |
| 1035 | void TL_jsonNull::serializeToStream(NativeByteBuffer *stream) { |
| 1036 | stream->writeInt32(constructor); |
| 1037 | } |
| 1038 |
| 1039 | void TL_jsonString::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 1040 | value = stream->readString(&error); |
| 1041 | } |
| 1042 |
| 1043 | void TL_jsonString::serializeToStream(NativeByteBuffer *stream) { |
| 1044 | stream->writeInt32(constructor); |
| 1045 | stream->writeString(value); |
| 1046 | } |
| 1047 |
| 1048 | void TL_jsonArray::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 1049 | int magic = stream->readInt32(&error); |
| 1050 | if (magic != 0x1cb5c415) { |
| 1051 | error = true; |
| 1052 | if (LOGS_ENABLED) DEBUG_FATAL("wrong Vector magic in TL_jsonArray, got %x", magic); |
| 1053 | return; |
| 1054 | } |
| 1055 | int count = stream->readInt32(&error); |
| 1056 | for (int a = 0; a < count; a++) { |
| 1057 | JSONValue *object = JSONValue::TLdeserialize(stream, stream->readUint32(&error), instanceNum, error); |
| 1058 | if (object == nullptr) { |
| 1059 | return; |
| 1060 | } |
| 1061 | value.push_back(std::unique_ptr<JSONValue>(object)); |
| 1062 | } |
| 1063 | } |
| 1064 |
| 1065 | void TL_jsonArray::serializeToStream(NativeByteBuffer *stream) { |
| 1066 | stream->writeInt32(constructor); |
| 1067 | stream->writeInt32(0x1cb5c415); |
| 1068 | uint32_t count = (uint32_t) value.size(); |
| 1069 | stream->writeInt32(count); |
| 1070 | for (int a = 0; a < count; a++) { |
| 1071 | value[a]->serializeToStream(stream); |
| 1072 | } |
| 1073 | } |
| 1074 |
| 1075 | void TL_jsonObject::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 1076 | int magic = stream->readInt32(&error); |
| 1077 | if (magic != 0x1cb5c415) { |
| 1078 | error = true; |
| 1079 | if (LOGS_ENABLED) DEBUG_FATAL("wrong Vector magic in TL_jsonObject, got %x", magic); |
| 1080 | return; |
| 1081 | } |
| 1082 | int count = stream->readInt32(&error); |
| 1083 | for (int a = 0; a < count; a++) { |
| 1084 | TL_jsonObjectValue *object = TL_jsonObjectValue::TLdeserialize(stream, stream->readUint32(&error), instanceNum, error); |
| 1085 | if (object == nullptr) { |
| 1086 | return; |
| 1087 | } |
| 1088 | value.push_back(std::unique_ptr<TL_jsonObjectValue>(object)); |
| 1089 | } |
| 1090 | } |
| 1091 |
| 1092 | void TL_jsonObject::serializeToStream(NativeByteBuffer *stream) { |
| 1093 | stream->writeInt32(constructor); |
| 1094 | stream->writeInt32(0x1cb5c415); |
| 1095 | uint32_t count = (uint32_t) value.size(); |
| 1096 | stream->writeInt32(count); |
| 1097 | for (int a = 0; a < count; a++) { |
| 1098 | value[a]->serializeToStream(stream); |
| 1099 | } |
| 1100 | } |
| 1101 |
| 1102 | void TL_jsonNumber::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 1103 | value = stream->readDouble(&error); |
| 1104 | } |
| 1105 |
| 1106 | void TL_jsonNumber::serializeToStream(NativeByteBuffer *stream) { |
| 1107 | stream->writeInt32(constructor); |
| 1108 | stream->writeDouble(value); |
| 1109 | } |
| 1110 |
| 1111 | void initConnection::serializeToStream(NativeByteBuffer *stream) { |
| 1112 | stream->writeInt32(constructor); |
| 1113 | stream->writeInt32(flags); |
| 1114 | stream->writeInt32(api_id); |
| 1115 | stream->writeString(device_model); |
| 1116 | stream->writeString(system_version); |
| 1117 | stream->writeString(app_version); |
| 1118 | stream->writeString(system_lang_code); |
| 1119 | stream->writeString(lang_pack); |
| 1120 | stream->writeString(lang_code); |
| 1121 | if ((flags & 1) != 0) { |
| 1122 | proxy->serializeToStream(stream); |
| 1123 | } |
| 1124 | if ((flags & 2) != 0) { |
| 1125 | params->serializeToStream(stream); |
| 1126 | } |
| 1127 | query->serializeToStream(stream); |
| 1128 | } |
| 1129 |
| 1130 | IpPort *IpPort::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 1131 | IpPort *result = nullptr; |
| 1132 | switch (constructor) { |
| 1133 | case 0xd433ad73: |
| 1134 | result = new TL_ipPort(); |
| 1135 | break; |
| 1136 | case 0x37982646: |
| 1137 | result = new TL_ipPortSecret(); |
| 1138 | break; |
| 1139 | default: |
| 1140 | error = true; |
| 1141 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in IpPort", constructor); |
| 1142 | return nullptr; |
| 1143 | } |
| 1144 | result->readParams(stream, instanceNum, error); |
| 1145 | return result; |
| 1146 | } |
| 1147 |
| 1148 | void TL_ipPort::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 1149 | struct in_addr ip_addr; |
| 1150 | ip_addr.s_addr = htonl(stream->readUint32(&error)); |
| 1151 | ipv4 = inet_ntoa(ip_addr); |
| 1152 | port = stream->readUint32(&error); |
| 1153 | } |
| 1154 |
| 1155 | void TL_ipPortSecret::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 1156 | struct in_addr ip_addr; |
| 1157 | ip_addr.s_addr = htonl(stream->readUint32(&error)); |
| 1158 | ipv4 = inet_ntoa(ip_addr); |
| 1159 | port = stream->readUint32(&error); |
| 1160 | secret = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 1161 | } |
| 1162 |
| 1163 | void TL_accessPointRule::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 1164 | phone_prefix_rules = stream->readString(&error); |
| 1165 | dc_id = stream->readUint32(&error); |
| 1166 | uint32_t count = stream->readUint32(&error); |
| 1167 | for (uint32_t a = 0; a < count; a++) { |
| 1168 | IpPort *object = IpPort::TLdeserialize(stream, stream->readUint32(&error), instanceNum, error); |
| 1169 | if (object == nullptr) { |
| 1170 | return; |
| 1171 | } |
| 1172 | ips.push_back(std::unique_ptr<IpPort>(object)); |
| 1173 | } |
| 1174 | } |
| 1175 |
| 1176 | TL_help_configSimple *TL_help_configSimple::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) { |
| 1177 | if (TL_help_configSimple::constructor != constructor) { |
| 1178 | error = true; |
| 1179 | if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_help_configSimple", constructor); |
| 1180 | return nullptr; |
| 1181 | } |
| 1182 | TL_help_configSimple *result = new TL_help_configSimple(); |
| 1183 | result->readParams(stream, instanceNum, error); |
| 1184 | return result; |
| 1185 | } |
| 1186 |
| 1187 | void TL_help_configSimple::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) { |
| 1188 | date = stream->readInt32(&error); |
| 1189 | expires = stream->readInt32(&error); |
| 1190 | uint32_t count = stream->readUint32(&error); |
| 1191 | for (uint32_t a = 0; a < count; a++) { |
| 1192 | TL_accessPointRule *object = new TL_accessPointRule(); |
| 1193 | object->readParams(stream, stream->readUint32(&error), error); |
| 1194 | if (error) { |
| 1195 | return; |
| 1196 | } |
| 1197 | rules.push_back(std::unique_ptr<TL_accessPointRule>(object)); |
| 1198 | } |
| 1199 | } |
| 1200 |