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